Chromium Code Reviews| 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); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 uint32 session_id, | 104 uint32 session_id, |
| 107 media::MediaKeys::KeyError error_code, | 105 media::MediaKeys::KeyError error_code, |
| 108 uint32 system_code) OVERRIDE; | 106 uint32 system_code) OVERRIDE; |
| 109 | 107 |
| 110 #if defined(VIDEO_HOLE) | 108 #if defined(VIDEO_HOLE) |
| 111 void AttachExternalVideoSurface(int player_id, jobject surface); | 109 void AttachExternalVideoSurface(int player_id, jobject surface); |
| 112 void DetachExternalVideoSurface(int player_id); | 110 void DetachExternalVideoSurface(int player_id); |
| 113 void OnFrameInfoUpdated(); | 111 void OnFrameInfoUpdated(); |
| 114 #endif // defined(VIDEO_HOLE) | 112 #endif // defined(VIDEO_HOLE) |
| 115 | 113 |
| 116 protected: | |
| 117 // Clients must use Create() or subclass constructor. | |
| 118 explicit BrowserMediaPlayerManager(RenderViewHost* render_view_host); | |
| 119 | |
| 120 // Message handlers. | 114 // Message handlers. |
| 121 virtual void OnEnterFullscreen(int player_id); | 115 virtual void OnEnterFullscreen(int player_id); |
| 122 virtual void OnExitFullscreen(int player_id); | 116 virtual void OnExitFullscreen(int player_id); |
| 123 virtual void OnInitialize( | 117 virtual void OnInitialize( |
| 124 MediaPlayerHostMsg_Initialize_Type type, | 118 MediaPlayerHostMsg_Initialize_Type type, |
| 125 int player_id, | 119 int player_id, |
| 126 const GURL& url, | 120 const GURL& url, |
| 127 const GURL& first_party_for_cookies, | 121 const GURL& first_party_for_cookies, |
| 128 int demuxer_client_id); | 122 int demuxer_client_id); |
| 129 virtual void OnStart(int player_id); | 123 virtual void OnStart(int player_id); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 141 uint32 session_id, | 135 uint32 session_id, |
| 142 CdmHostMsg_CreateSession_ContentType content_type, | 136 CdmHostMsg_CreateSession_ContentType content_type, |
| 143 const std::vector<uint8>& init_data); | 137 const std::vector<uint8>& init_data); |
| 144 void OnUpdateSession(int cdm_id, | 138 void OnUpdateSession(int cdm_id, |
| 145 uint32 session_id, | 139 uint32 session_id, |
| 146 const std::vector<uint8>& response); | 140 const std::vector<uint8>& response); |
| 147 void OnReleaseSession(int cdm_id, uint32 session_id); | 141 void OnReleaseSession(int cdm_id, uint32 session_id); |
| 148 void OnSetCdm(int player_id, int cdm_id); | 142 void OnSetCdm(int player_id, int cdm_id); |
| 149 void OnDestroyCdm(int cdm_id); | 143 void OnDestroyCdm(int cdm_id); |
| 150 | 144 |
| 145 protected: | |
| 146 // Clients must use Create() or subclass constructor. | |
| 147 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); | |
| 148 | |
| 149 WebContents* web_contents() const { return web_contents_; } | |
| 150 | |
| 151 int routing_id() const { return routing_id_; } | |
| 152 | |
| 151 // Cancels all pending session creations associated with |cdm_id|. | 153 // Cancels all pending session creations associated with |cdm_id|. |
| 152 void CancelAllPendingSessionCreations(int cdm_id); | 154 void CancelAllPendingSessionCreations(int cdm_id); |
| 153 | 155 |
| 154 // Adds a given player to the list. | 156 // Adds a given player to the list. |
| 155 void AddPlayer(media::MediaPlayerAndroid* player); | 157 void AddPlayer(media::MediaPlayerAndroid* player); |
| 156 | 158 |
| 157 // Removes the player with the specified id. | 159 // Removes the player with the specified id. |
| 158 void RemovePlayer(int player_id); | 160 void RemovePlayer(int player_id); |
| 159 | 161 |
| 160 // Replaces a player with the specified id with a given MediaPlayerAndroid | 162 // Replaces a player with the specified id with a given MediaPlayerAndroid |
| 161 // object. This will also return the original MediaPlayerAndroid object that | 163 // object. This will also return the original MediaPlayerAndroid object that |
| 162 // was replaced. | 164 // was replaced. |
| 163 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 165 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
| 164 int player_id, | 166 int player_id, |
| 165 media::MediaPlayerAndroid* player); | 167 media::MediaPlayerAndroid* player); |
| 166 | 168 |
| 167 // Adds a new CDM for the given |key_system|, |cdm_id|, and |security_origin|. | 169 // Adds a new CDM for the given |key_system|, |cdm_id|, and |security_origin|. |
| 168 void AddCdm(int cdm_id, | 170 void AddCdm(int cdm_id, |
| 169 const std::string& key_system, | 171 const std::string& key_system, |
| 170 const GURL& security_origin); | 172 const GURL& security_origin); |
| 171 | 173 |
| 172 // Removes the CDM with the specified id. | 174 // Removes the CDM with the specified id. |
| 173 void RemoveCdm(int cdm_id); | 175 void RemoveCdm(int cdm_id); |
| 174 | 176 |
| 177 // Helper function to send messages to RenderFrameObserver. | |
| 178 bool Send(IPC::Message* msg); | |
| 179 | |
| 175 private: | 180 private: |
| 176 // If |permitted| is false, it does nothing but send | 181 // If |permitted| is false, it does nothing but send |
| 177 // |CdmMsg_SessionError| IPC message. | 182 // |CdmMsg_SessionError| IPC message. |
| 178 // The primary use case is infobar permission callback, i.e., when infobar | 183 // The primary use case is infobar permission callback, i.e., when infobar |
| 179 // can decide user's intention either from interacting with the actual info | 184 // can decide user's intention either from interacting with the actual info |
| 180 // bar or from the saved preference. | 185 // bar or from the saved preference. |
| 181 void CreateSessionIfPermitted(int cdm_id, | 186 void CreateSessionIfPermitted(int cdm_id, |
| 182 uint32 session_id, | 187 uint32 session_id, |
| 183 const std::string& content_type, | 188 const std::string& content_type, |
| 184 const std::vector<uint8>& init_data, | 189 const std::vector<uint8>& init_data, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 205 // Similar to the above call, MediaPlayerAndroid must call this method when | 210 // Similar to the above call, MediaPlayerAndroid must call this method when |
| 206 // releasing all the decoding resources. | 211 // releasing all the decoding resources. |
| 207 virtual void OnMediaResourcesReleased(int player_id); | 212 virtual void OnMediaResourcesReleased(int player_id); |
| 208 | 213 |
| 209 #if defined(VIDEO_HOLE) | 214 #if defined(VIDEO_HOLE) |
| 210 void OnNotifyExternalSurface( | 215 void OnNotifyExternalSurface( |
| 211 int player_id, bool is_request, const gfx::RectF& rect); | 216 int player_id, bool is_request, const gfx::RectF& rect); |
| 212 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); | 217 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); |
| 213 #endif // defined(VIDEO_HOLE) | 218 #endif // defined(VIDEO_HOLE) |
| 214 | 219 |
| 220 RenderFrameHost* const render_frame_host_; | |
| 221 const int routing_id_; | |
|
jam
2014/05/20 00:34:49
nit: this is redundant since you can always get it
xhwang
2014/05/22 19:06:00
Done.
| |
| 222 | |
| 215 // An array of managed players. | 223 // An array of managed players. |
| 216 ScopedVector<media::MediaPlayerAndroid> players_; | 224 ScopedVector<media::MediaPlayerAndroid> players_; |
| 217 | 225 |
| 218 // A map from CDM IDs to managed CDMs. | 226 // A map from CDM IDs to managed CDMs. |
| 219 typedef std::map<int, media::MediaKeys*> CdmMap; | 227 typedef std::map<int, media::MediaKeys*> CdmMap; |
| 220 CdmMap cdm_map_; | 228 CdmMap cdm_map_; |
| 221 | 229 |
| 222 // Map from CDM ID to MediaPlayerAndroid player ID to indicate that | 230 // Map from CDM ID to MediaPlayerAndroid player ID to indicate that |
| 223 // the CDM is set on the MediaPlayerAndroid object. | 231 // the CDM is set on the MediaPlayerAndroid object. |
| 224 typedef std::map<int, int> CdmToPlayerMap; | 232 typedef std::map<int, int> CdmToPlayerMap; |
| 225 CdmToPlayerMap cdm_to_player_map_; | 233 CdmToPlayerMap cdm_to_player_map_; |
| 226 | 234 |
| 227 // Map from CDM ID to CDM's security origin. | 235 // Map from CDM ID to CDM's security origin. |
| 228 std::map<int, GURL> security_origin_map_; | 236 std::map<int, GURL> security_origin_map_; |
| 229 | 237 |
| 230 // The fullscreen video view object or NULL if video is not played in | 238 // The fullscreen video view object or NULL if video is not played in |
| 231 // fullscreen. | 239 // fullscreen. |
| 232 scoped_ptr<ContentVideoView> video_view_; | 240 scoped_ptr<ContentVideoView> video_view_; |
| 233 | 241 |
| 234 #if defined(VIDEO_HOLE) | 242 #if defined(VIDEO_HOLE) |
| 235 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; | 243 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; |
| 236 #endif | 244 #endif |
| 237 | 245 |
| 238 // Player ID of the fullscreen media player. | 246 // Player ID of the fullscreen media player. |
| 239 int fullscreen_player_id_; | 247 int fullscreen_player_id_; |
| 240 | 248 |
| 241 // Whether the fullscreen player has been Release()-d. | 249 // Whether the fullscreen player has been Release()-d. |
| 242 bool fullscreen_player_is_released_; | 250 bool fullscreen_player_is_released_; |
| 243 | 251 |
| 244 WebContents* web_contents_; | 252 WebContents* const web_contents_; |
| 245 | 253 |
| 246 // Object for retrieving resources media players. | 254 // Object for retrieving resources media players. |
| 247 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 255 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
| 248 | 256 |
| 249 // NOTE: Weak pointers must be invalidated before all other member variables. | 257 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 250 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 258 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
| 251 | 259 |
| 252 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 260 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
| 253 }; | 261 }; |
| 254 | 262 |
| 255 } // namespace content | 263 } // namespace content |
| 256 | 264 |
| 257 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 265 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
| OLD | NEW |