1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_MANAGER_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_MANAGER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/time/time.h" 13 #include "media/base/android/demuxer_stream_player_params.h" 14 #include "media/base/media_export.h" 15 #include "media/base/media_keys.h" 16 17 namespace content { 18 class RenderViewHost; 19 } 20 21 namespace media { 22 23 class MediaDrmBridge; 24 class MediaPlayerAndroid; 25 class MediaResourceGetter; 26 27 // This class is responsible for managing active MediaPlayerAndroid objects. 28 // Objects implementing this interface a created via 29 // MediaPlayerManager::Create(), allowing embedders to provide their 30 // implementation. 31 class MEDIA_EXPORT MediaPlayerManager { 32 public: 33 // The type of the factory function that returns a new instance of the 34 // MediaPlayerManager implementation. 35 typedef MediaPlayerManager* (*FactoryFunction)(content::RenderViewHost*); 36 37 // Allows to override the default factory function in order to provide 38 // a custom implementation to the RenderViewHost instance. 39 // Must be called from the main thread. 40 static void RegisterFactoryFunction(FactoryFunction factory_function); 41 42 // Returns a new instance of MediaPlayerManager interface implementation. 43 // The returned object is owned by the caller. Must be called on the main 44 // thread. 45 static MediaPlayerManager* Create(content::RenderViewHost* render_view_host); 46 47 virtual ~MediaPlayerManager() {} 48 49 // Called by a MediaPlayerAndroid object when it is going to decode 50 // media streams. This helps the manager object maintain an array 51 // of active MediaPlayerAndroid objects and release the resources 52 // when needed. 53 virtual void RequestMediaResources(int player_id) = 0; 54 55 // Called when a MediaPlayerAndroid object releases all its decoding 56 // resources. 57 virtual void ReleaseMediaResources(int player_id) = 0; 58 59 // Return a pointer to the MediaResourceGetter object. 60 virtual MediaResourceGetter* GetMediaResourceGetter() = 0; 61 62 // Called when time update messages need to be sent. Args: player ID, 63 // current time. 64 virtual void OnTimeUpdate(int player_id, base::TimeDelta current_time) = 0; 65 66 // Called when media metadata changed. Args: player ID, duration of the 67 // media, width, height, whether the metadata is successfully extracted. 68 virtual void OnMediaMetadataChanged( 69 int player_id, 70 base::TimeDelta duration, 71 int width, 72 int height, 73 bool success) = 0; 74 75 // Called when playback completed. Args: player ID. 76 virtual void OnPlaybackComplete(int player_id) = 0; 77 78 // Called when media download was interrupted. Args: player ID. 79 virtual void OnMediaInterrupted(int player_id) = 0; 80 81 // Called when buffering has changed. Args: player ID, percentage 82 // of the media. 83 virtual void OnBufferingUpdate(int player_id, int percentage) = 0; 84 85 // Called when seek completed. Args: player ID, current time. 86 virtual void OnSeekComplete(int player_id, base::TimeDelta current_time) = 0; 87 88 // Called when error happens. Args: player ID, error type. 89 virtual void OnError(int player_id, int error) = 0; 90 91 // Called when video size has changed. Args: player ID, width, height. 92 virtual void OnVideoSizeChanged(int player_id, int width, int height) = 0; 93 94 // Returns the player that's in the fullscreen mode currently. 95 virtual MediaPlayerAndroid* GetFullscreenPlayer() = 0; 96 97 // Returns the player with the specified id. 98 virtual MediaPlayerAndroid* GetPlayer(int player_id) = 0; 99 100 // Release all the players managed by this object. 101 virtual void DestroyAllMediaPlayers() = 0; 102 103 // Callback when DemuxerStreamPlayer wants to read data from the demuxer. 104 virtual void OnReadFromDemuxer(int player_id, 105 media::DemuxerStream::Type type) = 0; 106 107 // Called when player wants the media element to initiate a seek. 108 virtual void OnMediaSeekRequest(int player_id, base::TimeDelta time_to_seek, 109 unsigned seek_request_id) = 0; 110 111 // Called when player wants to read the config data from the demuxer. 112 virtual void OnMediaConfigRequest(int player_id) = 0; 113 114 // Get the MediaDrmBridge object for the given media key Id. 115 virtual media::MediaDrmBridge* GetDrmBridge(int media_keys_id) = 0; 116 117 // Called by the player to get a hardware protected surface. 118 virtual void OnProtectedSurfaceRequested(int player_id) = 0; 119 120 // TODO(xhwang): The following three methods needs to be decoupled from 121 // MediaPlayerManager to support the W3C Working Draft version of the EME 122 // spec. 123 124 // Called when MediaDrmBridge wants to send a KeyAdded. 125 virtual void OnKeyAdded(int media_keys_id, 126 const std::string& session_id) = 0; 127 128 // Called when MediaDrmBridge wants to send a KeyError. 129 virtual void OnKeyError(int media_keys_id, 130 const std::string& session_id, 131 media::MediaKeys::KeyError error_code, 132 int system_code) = 0; 133 134 // Called when MediaDrmBridge wants to send a KeyMessage. 135 virtual void OnKeyMessage(int media_keys_id, 136 const std::string& session_id, 137 const std::vector<uint8>& message, 138 const std::string& destination_url) = 0; 139 }; 140 141 } // namespace media 142 143 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_MANAGER_H_ 144