| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "content/browser/android/content_video_view.h" | 18 #include "content/browser/android/content_video_view.h" |
| 19 #include "content/common/content_export.h" |
| 19 #include "content/common/media/cdm_messages_enums.h" | 20 #include "content/common/media/cdm_messages_enums.h" |
| 20 #include "content/common/media/media_player_messages_enums_android.h" | 21 #include "content/common/media/media_player_messages_enums_android.h" |
| 21 #include "content/public/browser/web_contents_observer.h" | 22 #include "ipc/ipc_message.h" |
| 22 #include "media/base/android/media_player_android.h" | 23 #include "media/base/android/media_player_android.h" |
| 23 #include "media/base/android/media_player_manager.h" | 24 #include "media/base/android/media_player_manager.h" |
| 24 #include "ui/gfx/rect_f.h" | 25 #include "ui/gfx/rect_f.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 namespace media { | 28 namespace media { |
| 28 class DemuxerAndroid; | 29 class DemuxerAndroid; |
| 29 class MediaKeys; | 30 class MediaKeys; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 class BrowserDemuxerAndroid; | 34 class BrowserDemuxerAndroid; |
| 34 class ContentViewCoreImpl; | 35 class ContentViewCoreImpl; |
| 35 class ExternalVideoSurfaceContainer; | 36 class ExternalVideoSurfaceContainer; |
| 37 class RenderFrameHost; |
| 36 class WebContents; | 38 class WebContents; |
| 37 | 39 |
| 38 // This class manages all the MediaPlayerAndroid and CDM objects. | 40 // This class manages all the MediaPlayerAndroid and CDM objects. |
| 39 // It receives control operations from the the render process, and forwards | 41 // It receives control operations from the the render process, and forwards |
| 40 // them to corresponding MediaPlayerAndroid or CDM object. Callbacks from | 42 // them to corresponding MediaPlayerAndroid or CDM object. Callbacks from |
| 41 // MediaPlayerAndroid and CDM objects are converted to IPCs and then sent to | 43 // MediaPlayerAndroid and CDM objects are converted to IPCs and then sent to |
| 42 // the render process. | 44 // the render process. |
| 43 class CONTENT_EXPORT BrowserMediaPlayerManager | 45 class CONTENT_EXPORT BrowserMediaPlayerManager |
| 44 : public WebContentsObserver, | 46 : public media::MediaPlayerManager { |
| 45 public media::MediaPlayerManager { | |
| 46 public: | 47 public: |
| 47 // Permits embedders to provide an extended version of the class. | 48 // Permits embedders to provide an extended version of the class. |
| 48 typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*); | 49 typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*); |
| 49 static void RegisterFactory(Factory factory); | 50 static void RegisterFactory(Factory factory); |
| 50 | 51 |
| 51 // Returns a new instance using the registered factory if available. | 52 // Returns a new instance using the registered factory if available. |
| 52 static BrowserMediaPlayerManager* Create(RenderViewHost* rvh); | 53 static BrowserMediaPlayerManager* Create(RenderFrameHost* rfh); |
| 53 | 54 |
| 54 ContentViewCoreImpl* GetContentViewCore() const; | 55 ContentViewCoreImpl* GetContentViewCore() const; |
| 55 | 56 |
| 56 virtual ~BrowserMediaPlayerManager(); | 57 virtual ~BrowserMediaPlayerManager(); |
| 57 | 58 |
| 58 // WebContentsObserver overrides. | |
| 59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 60 | |
| 61 // Fullscreen video playback controls. | 59 // Fullscreen video playback controls. |
| 62 virtual void FullscreenPlayerPlay(); | 60 virtual void FullscreenPlayerPlay(); |
| 63 virtual void FullscreenPlayerPause(); | 61 virtual void FullscreenPlayerPause(); |
| 64 virtual void FullscreenPlayerSeek(int msec); | 62 virtual void FullscreenPlayerSeek(int msec); |
| 65 virtual void ExitFullscreen(bool release_media_player); | 63 virtual void ExitFullscreen(bool release_media_player); |
| 66 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface); | 64 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface); |
| 67 | 65 |
| 68 // Called when browser player wants the renderer media element to seek. | 66 // Called when browser player wants the renderer media element to seek. |
| 69 // Any actual seek started by renderer will be handled by browser in OnSeek(). | 67 // Any actual seek started by renderer will be handled by browser in OnSeek(). |
| 70 void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek); | 68 void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek); |
| 71 | 69 |
| 70 // Pauses all video players manages by this class. |
| 71 void PauseVideo(); |
| 72 |
| 72 // media::MediaPlayerManager overrides. | 73 // media::MediaPlayerManager overrides. |
| 73 virtual void OnTimeUpdate( | 74 virtual void OnTimeUpdate( |
| 74 int player_id, base::TimeDelta current_time) OVERRIDE; | 75 int player_id, base::TimeDelta current_time) OVERRIDE; |
| 75 virtual void OnMediaMetadataChanged( | 76 virtual void OnMediaMetadataChanged( |
| 76 int player_id, | 77 int player_id, |
| 77 base::TimeDelta duration, | 78 base::TimeDelta duration, |
| 78 int width, | 79 int width, |
| 79 int height, | 80 int height, |
| 80 bool success) OVERRIDE; | 81 bool success) OVERRIDE; |
| 81 virtual void OnPlaybackComplete(int player_id) OVERRIDE; | 82 virtual void OnPlaybackComplete(int player_id) OVERRIDE; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 106 uint32 session_id, | 107 uint32 session_id, |
| 107 media::MediaKeys::KeyError error_code, | 108 media::MediaKeys::KeyError error_code, |
| 108 uint32 system_code) OVERRIDE; | 109 uint32 system_code) OVERRIDE; |
| 109 | 110 |
| 110 #if defined(VIDEO_HOLE) | 111 #if defined(VIDEO_HOLE) |
| 111 void AttachExternalVideoSurface(int player_id, jobject surface); | 112 void AttachExternalVideoSurface(int player_id, jobject surface); |
| 112 void DetachExternalVideoSurface(int player_id); | 113 void DetachExternalVideoSurface(int player_id); |
| 113 void OnFrameInfoUpdated(); | 114 void OnFrameInfoUpdated(); |
| 114 #endif // defined(VIDEO_HOLE) | 115 #endif // defined(VIDEO_HOLE) |
| 115 | 116 |
| 116 protected: | |
| 117 // Clients must use Create() or subclass constructor. | |
| 118 explicit BrowserMediaPlayerManager(RenderViewHost* render_view_host); | |
| 119 | |
| 120 // Message handlers. | 117 // Message handlers. |
| 121 virtual void OnEnterFullscreen(int player_id); | 118 virtual void OnEnterFullscreen(int player_id); |
| 122 virtual void OnExitFullscreen(int player_id); | 119 virtual void OnExitFullscreen(int player_id); |
| 123 virtual void OnInitialize( | 120 virtual void OnInitialize( |
| 124 MediaPlayerHostMsg_Initialize_Type type, | 121 MediaPlayerHostMsg_Initialize_Type type, |
| 125 int player_id, | 122 int player_id, |
| 126 const GURL& url, | 123 const GURL& url, |
| 127 const GURL& first_party_for_cookies, | 124 const GURL& first_party_for_cookies, |
| 128 int demuxer_client_id); | 125 int demuxer_client_id); |
| 129 virtual void OnStart(int player_id); | 126 virtual void OnStart(int player_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 void OnCreateSession(int cdm_id, | 137 void OnCreateSession(int cdm_id, |
| 141 uint32 session_id, | 138 uint32 session_id, |
| 142 CdmHostMsg_CreateSession_ContentType content_type, | 139 CdmHostMsg_CreateSession_ContentType content_type, |
| 143 const std::vector<uint8>& init_data); | 140 const std::vector<uint8>& init_data); |
| 144 void OnUpdateSession(int cdm_id, | 141 void OnUpdateSession(int cdm_id, |
| 145 uint32 session_id, | 142 uint32 session_id, |
| 146 const std::vector<uint8>& response); | 143 const std::vector<uint8>& response); |
| 147 void OnReleaseSession(int cdm_id, uint32 session_id); | 144 void OnReleaseSession(int cdm_id, uint32 session_id); |
| 148 void OnSetCdm(int player_id, int cdm_id); | 145 void OnSetCdm(int player_id, int cdm_id); |
| 149 void OnDestroyCdm(int cdm_id); | 146 void OnDestroyCdm(int cdm_id); |
| 147 #if defined(VIDEO_HOLE) |
| 148 void OnNotifyExternalSurface( |
| 149 int player_id, bool is_request, const gfx::RectF& rect); |
| 150 #endif // defined(VIDEO_HOLE) |
| 151 |
| 152 protected: |
| 153 // Clients must use Create() or subclass constructor. |
| 154 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); |
| 155 |
| 156 WebContents* web_contents() const { return web_contents_; } |
| 150 | 157 |
| 151 // Cancels all pending session creations associated with |cdm_id|. | 158 // Cancels all pending session creations associated with |cdm_id|. |
| 152 void CancelAllPendingSessionCreations(int cdm_id); | 159 void CancelAllPendingSessionCreations(int cdm_id); |
| 153 | 160 |
| 154 // Adds a given player to the list. | 161 // Adds a given player to the list. |
| 155 void AddPlayer(media::MediaPlayerAndroid* player); | 162 void AddPlayer(media::MediaPlayerAndroid* player); |
| 156 | 163 |
| 157 // Removes the player with the specified id. | 164 // Removes the player with the specified id. |
| 158 void RemovePlayer(int player_id); | 165 void RemovePlayer(int player_id); |
| 159 | 166 |
| 160 // Replaces a player with the specified id with a given MediaPlayerAndroid | 167 // Replaces a player with the specified id with a given MediaPlayerAndroid |
| 161 // object. This will also return the original MediaPlayerAndroid object that | 168 // object. This will also return the original MediaPlayerAndroid object that |
| 162 // was replaced. | 169 // was replaced. |
| 163 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 170 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
| 164 int player_id, | 171 int player_id, |
| 165 media::MediaPlayerAndroid* player); | 172 media::MediaPlayerAndroid* player); |
| 166 | 173 |
| 167 // Adds a new CDM identified by |cdm_id| for the given |key_system| and | 174 // Adds a new CDM identified by |cdm_id| for the given |key_system| and |
| 168 // |security_origin|. | 175 // |security_origin|. |
| 169 void AddCdm(int cdm_id, | 176 void AddCdm(int cdm_id, |
| 170 const std::string& key_system, | 177 const std::string& key_system, |
| 171 const GURL& security_origin); | 178 const GURL& security_origin); |
| 172 | 179 |
| 173 // Removes the CDM with the specified id. | 180 // Removes the CDM with the specified id. |
| 174 void RemoveCdm(int cdm_id); | 181 void RemoveCdm(int cdm_id); |
| 175 | 182 |
| 183 int RoutingID(); |
| 184 |
| 185 // Helper function to send messages to RenderFrameObserver. |
| 186 bool Send(IPC::Message* msg); |
| 187 |
| 176 private: | 188 private: |
| 177 // If |permitted| is false, it does nothing but send | 189 // If |permitted| is false, it does nothing but send |
| 178 // |CdmMsg_SessionError| IPC message. | 190 // |CdmMsg_SessionError| IPC message. |
| 179 // The primary use case is infobar permission callback, i.e., when infobar | 191 // The primary use case is infobar permission callback, i.e., when infobar |
| 180 // can decide user's intention either from interacting with the actual info | 192 // can decide user's intention either from interacting with the actual info |
| 181 // bar or from the saved preference. | 193 // bar or from the saved preference. |
| 182 void CreateSessionIfPermitted(int cdm_id, | 194 void CreateSessionIfPermitted(int cdm_id, |
| 183 uint32 session_id, | 195 uint32 session_id, |
| 184 const std::string& content_type, | 196 const std::string& content_type, |
| 185 const std::vector<uint8>& init_data, | 197 const std::vector<uint8>& init_data, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 201 // of active MediaPlayerAndroid objects and release the resources | 213 // of active MediaPlayerAndroid objects and release the resources |
| 202 // when needed. Currently we only count video resources as they are | 214 // when needed. Currently we only count video resources as they are |
| 203 // constrained by hardware and memory limits. | 215 // constrained by hardware and memory limits. |
| 204 virtual void OnMediaResourcesRequested(int player_id); | 216 virtual void OnMediaResourcesRequested(int player_id); |
| 205 | 217 |
| 206 // Similar to the above call, MediaPlayerAndroid must call this method when | 218 // Similar to the above call, MediaPlayerAndroid must call this method when |
| 207 // releasing all the decoding resources. | 219 // releasing all the decoding resources. |
| 208 virtual void OnMediaResourcesReleased(int player_id); | 220 virtual void OnMediaResourcesReleased(int player_id); |
| 209 | 221 |
| 210 #if defined(VIDEO_HOLE) | 222 #if defined(VIDEO_HOLE) |
| 211 void OnNotifyExternalSurface( | |
| 212 int player_id, bool is_request, const gfx::RectF& rect); | |
| 213 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); | 223 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); |
| 214 #endif // defined(VIDEO_HOLE) | 224 #endif // defined(VIDEO_HOLE) |
| 215 | 225 |
| 226 RenderFrameHost* const render_frame_host_; |
| 227 |
| 216 // An array of managed players. | 228 // An array of managed players. |
| 217 ScopedVector<media::MediaPlayerAndroid> players_; | 229 ScopedVector<media::MediaPlayerAndroid> players_; |
| 218 | 230 |
| 219 // A map from CDM IDs to managed CDMs. | 231 // A map from CDM IDs to managed CDMs. |
| 220 typedef std::map<int, media::MediaKeys*> CdmMap; | 232 typedef std::map<int, media::MediaKeys*> CdmMap; |
| 221 CdmMap cdm_map_; | 233 CdmMap cdm_map_; |
| 222 | 234 |
| 223 // Map from CDM ID to MediaPlayerAndroid player ID to indicate that | 235 // Map from CDM ID to MediaPlayerAndroid player ID to indicate that |
| 224 // the CDM is set on the MediaPlayerAndroid object. | 236 // the CDM is set on the MediaPlayerAndroid object. |
| 225 // TODO(xhwang): Register a callback in the CDM to resume playback so that we | 237 // TODO(xhwang): Register a callback in the CDM to resume playback so that we |
| (...skipping 11 matching lines...) Expand all Loading... |
| 237 #if defined(VIDEO_HOLE) | 249 #if defined(VIDEO_HOLE) |
| 238 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; | 250 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; |
| 239 #endif | 251 #endif |
| 240 | 252 |
| 241 // Player ID of the fullscreen media player. | 253 // Player ID of the fullscreen media player. |
| 242 int fullscreen_player_id_; | 254 int fullscreen_player_id_; |
| 243 | 255 |
| 244 // Whether the fullscreen player has been Release()-d. | 256 // Whether the fullscreen player has been Release()-d. |
| 245 bool fullscreen_player_is_released_; | 257 bool fullscreen_player_is_released_; |
| 246 | 258 |
| 247 WebContents* web_contents_; | 259 WebContents* const web_contents_; |
| 248 | 260 |
| 249 // Object for retrieving resources media players. | 261 // Object for retrieving resources media players. |
| 250 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 262 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
| 251 | 263 |
| 252 // NOTE: Weak pointers must be invalidated before all other member variables. | 264 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 253 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 265 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
| 254 | 266 |
| 255 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 267 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
| 256 }; | 268 }; |
| 257 | 269 |
| 258 } // namespace content | 270 } // namespace content |
| 259 | 271 |
| 260 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 272 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
| OLD | NEW |