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/media/cdm_messages_enums.h" | 19 #include "content/common/media/cdm_messages_enums.h" |
20 #include "content/common/media/media_player_messages_enums_android.h" | 20 #include "content/common/media/media_player_messages_enums_android.h" |
21 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
22 #include "media/base/android/media_player_android.h" | 22 #include "media/base/android/media_player_android.h" |
23 #include "media/base/android/media_player_manager.h" | 23 #include "media/base/android/media_player_manager.h" |
24 #include "ui/gfx/rect_f.h" | 24 #include "ui/gfx/rect_f.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
27 namespace media { | 27 namespace media { |
28 class DemuxerAndroid; | 28 class DemuxerAndroid; |
29 class MediaDrmBridge; | 29 class MediaKeys; |
30 } | 30 } |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 class BrowserDemuxerAndroid; | 33 class BrowserDemuxerAndroid; |
34 class ContentViewCoreImpl; | 34 class ContentViewCoreImpl; |
35 class ExternalVideoSurfaceContainer; | 35 class ExternalVideoSurfaceContainer; |
36 class WebContents; | 36 class WebContents; |
37 | 37 |
38 // This class manages all the MediaPlayerAndroid objects. It receives | 38 // This class manages all the MediaPlayerAndroid and CDM objects. |
39 // control operations from the the render process, and forwards | 39 // It receives control operations from the the render process, and forwards |
40 // them to corresponding MediaPlayerAndroid object. Callbacks from | 40 // them to corresponding MediaPlayerAndroid or CDM object. Callbacks from |
41 // MediaPlayerAndroid objects are converted to IPCs and then sent to the | 41 // MediaPlayerAndroid and CDM objects are converted to IPCs and then sent to |
42 // render process. | 42 // the render process. |
43 class CONTENT_EXPORT BrowserMediaPlayerManager | 43 class CONTENT_EXPORT BrowserMediaPlayerManager |
44 : public WebContentsObserver, | 44 : public WebContentsObserver, |
45 public media::MediaPlayerManager { | 45 public media::MediaPlayerManager { |
46 public: | 46 public: |
47 // Permits embedders to provide an extended version of the class. | 47 // Permits embedders to provide an extended version of the class. |
48 typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*); | 48 typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*); |
49 static void RegisterFactory(Factory factory); | 49 static void RegisterFactory(Factory factory); |
50 | 50 |
51 // Returns a new instance using the registered factory if available. | 51 // Returns a new instance using the registered factory if available. |
52 static BrowserMediaPlayerManager* Create(RenderViewHost* rvh); | 52 static BrowserMediaPlayerManager* Create(RenderViewHost* rvh); |
(...skipping 30 matching lines...) Expand all Loading... | |
83 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE; | 83 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE; |
84 virtual void OnSeekComplete( | 84 virtual void OnSeekComplete( |
85 int player_id, | 85 int player_id, |
86 const base::TimeDelta& current_time) OVERRIDE; | 86 const base::TimeDelta& current_time) OVERRIDE; |
87 virtual void OnError(int player_id, int error) OVERRIDE; | 87 virtual void OnError(int player_id, int error) OVERRIDE; |
88 virtual void OnVideoSizeChanged( | 88 virtual void OnVideoSizeChanged( |
89 int player_id, int width, int height) OVERRIDE; | 89 int player_id, int width, int height) OVERRIDE; |
90 virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE; | 90 virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE; |
91 virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE; | 91 virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE; |
92 virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE; | 92 virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE; |
93 virtual media::MediaDrmBridge* GetDrmBridge(int cdm_id) OVERRIDE; | 93 virtual media::MediaKeys* GetCdm(int cdm_id) OVERRIDE; |
94 virtual void DestroyAllMediaPlayers() OVERRIDE; | 94 virtual void DestroyAllMediaPlayers() OVERRIDE; |
95 virtual void RequestFullScreen(int player_id) OVERRIDE; | 95 virtual void RequestFullScreen(int player_id) OVERRIDE; |
96 virtual void OnSessionCreated(int cdm_id, | 96 virtual void OnSessionCreated(int cdm_id, |
97 uint32 session_id, | 97 uint32 session_id, |
98 const std::string& web_session_id) OVERRIDE; | 98 const std::string& web_session_id) OVERRIDE; |
99 virtual void OnSessionMessage(int cdm_id, | 99 virtual void OnSessionMessage(int cdm_id, |
100 uint32 session_id, | 100 uint32 session_id, |
101 const std::vector<uint8>& message, | 101 const std::vector<uint8>& message, |
102 const GURL& destination_url) OVERRIDE; | 102 const std::string& destination_url) OVERRIDE; |
ddorwin
2014/05/13 00:59:38
Why the change?
Should we pass GURLs around as muc
xhwang
2014/05/14 16:42:06
std::string is used in media_keys.h. Filed a bug a
| |
103 virtual void OnSessionReady(int cdm_id, uint32 session_id) OVERRIDE; | 103 virtual void OnSessionReady(int cdm_id, uint32 session_id) OVERRIDE; |
104 virtual void OnSessionClosed(int cdm_id, uint32 session_id) OVERRIDE; | 104 virtual void OnSessionClosed(int cdm_id, uint32 session_id) OVERRIDE; |
105 virtual void OnSessionError(int cdm_id, | 105 virtual void OnSessionError(int cdm_id, |
106 uint32 session_id, | 106 uint32 session_id, |
107 media::MediaKeys::KeyError error_code, | 107 media::MediaKeys::KeyError error_code, |
108 uint32 system_code) OVERRIDE; | 108 uint32 system_code) OVERRIDE; |
109 | 109 |
110 #if defined(VIDEO_HOLE) | 110 #if defined(VIDEO_HOLE) |
111 void AttachExternalVideoSurface(int player_id, jobject surface); | 111 void AttachExternalVideoSurface(int player_id, jobject surface); |
112 void DetachExternalVideoSurface(int player_id); | 112 void DetachExternalVideoSurface(int player_id); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // Removes the player with the specified id. | 157 // Removes the player with the specified id. |
158 void RemovePlayer(int player_id); | 158 void RemovePlayer(int player_id); |
159 | 159 |
160 // Replaces a player with the specified id with a given MediaPlayerAndroid | 160 // Replaces a player with the specified id with a given MediaPlayerAndroid |
161 // object. This will also return the original MediaPlayerAndroid object that | 161 // object. This will also return the original MediaPlayerAndroid object that |
162 // was replaced. | 162 // was replaced. |
163 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 163 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
164 int player_id, | 164 int player_id, |
165 media::MediaPlayerAndroid* player); | 165 media::MediaPlayerAndroid* player); |
166 | 166 |
167 // Adds a new MediaDrmBridge for the given |key_system|, |cdm_id|, and | 167 // Adds a new CDM for the given |key_system|, |cdm_id|, and |security_origin|. |
ddorwin
2014/05/13 00:59:38
Would it be more accurate to say this?
// Adds a n
xhwang
2014/05/14 16:42:06
Done.
| |
168 // |frame_url|. | 168 void AddCdm(int cdm_id, |
169 void AddDrmBridge(int cdm_id, | 169 const std::string& key_system, |
170 const std::string& key_system, | 170 const GURL& security_origin); |
171 const GURL& frame_url); | |
172 | 171 |
173 // Removes the DRM bridge with the specified id. | 172 // Removes the CDM with the specified id. |
174 void RemoveDrmBridge(int cdm_id); | 173 void RemoveCdm(int cdm_id); |
175 | 174 |
176 private: | 175 private: |
177 // If |permitted| is false, it does nothing but send | 176 // If |permitted| is false, it does nothing but send |
178 // |CdmMsg_SessionError| IPC message. | 177 // |CdmMsg_SessionError| IPC message. |
179 // The primary use case is infobar permission callback, i.e., when infobar | 178 // 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 | 179 // can decide user's intention either from interacting with the actual info |
181 // bar or from the saved preference. | 180 // bar or from the saved preference. |
182 void CreateSessionIfPermitted(int cdm_id, | 181 void CreateSessionIfPermitted(int cdm_id, |
183 uint32 session_id, | 182 uint32 session_id, |
184 const std::string& content_type, | 183 const std::string& content_type, |
(...skipping 24 matching lines...) Expand all Loading... | |
209 | 208 |
210 #if defined(VIDEO_HOLE) | 209 #if defined(VIDEO_HOLE) |
211 void OnNotifyExternalSurface( | 210 void OnNotifyExternalSurface( |
212 int player_id, bool is_request, const gfx::RectF& rect); | 211 int player_id, bool is_request, const gfx::RectF& rect); |
213 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); | 212 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); |
214 #endif // defined(VIDEO_HOLE) | 213 #endif // defined(VIDEO_HOLE) |
215 | 214 |
216 // An array of managed players. | 215 // An array of managed players. |
217 ScopedVector<media::MediaPlayerAndroid> players_; | 216 ScopedVector<media::MediaPlayerAndroid> players_; |
218 | 217 |
219 // An array of managed media DRM bridges. | 218 // A map from CDM IDs to managed CDMs. |
220 ScopedVector<media::MediaDrmBridge> drm_bridges_; | 219 typedef std::map<int, media::MediaKeys*> CdmMap; |
220 CdmMap cdm_map_; | |
221 | 221 |
222 // Map from DrmBridge cdm_id to MediaPlayerAndroid player_id to indicate that | 222 // Map from CDM ID to MediaPlayerAndroid player ID to indicate that |
223 // the DrmBridge is set on the MediaPlayerAndroid object. | 223 // the CDM is set on the MediaPlayerAndroid object. |
224 typedef std::map<int, int> DrmBridgePlayerMap; | 224 typedef std::map<int, int> CdmToPlayerMap; |
225 DrmBridgePlayerMap drm_bridge_player_map_; | 225 CdmToPlayerMap cdm_to_player_map_; |
226 | |
227 // Map from CDM ID to CDM's security origin. | |
ddorwin
2014/05/13 00:59:38
Why doesn't the CDM object maintain this? Should w
xhwang
2014/05/14 16:42:06
Because most CDM objects are not interested in thi
| |
228 std::map<int, GURL> security_origin_map_; | |
ddorwin
2014/05/13 00:59:38
cdm_...
xhwang
2014/05/14 16:42:06
Done.
| |
226 | 229 |
227 // The fullscreen video view object or NULL if video is not played in | 230 // The fullscreen video view object or NULL if video is not played in |
228 // fullscreen. | 231 // fullscreen. |
229 scoped_ptr<ContentVideoView> video_view_; | 232 scoped_ptr<ContentVideoView> video_view_; |
230 | 233 |
231 #if defined(VIDEO_HOLE) | 234 #if defined(VIDEO_HOLE) |
232 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; | 235 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; |
233 #endif | 236 #endif |
234 | 237 |
235 // Player ID of the fullscreen media player. | 238 // Player ID of the fullscreen media player. |
236 int fullscreen_player_id_; | 239 int fullscreen_player_id_; |
237 | 240 |
238 // Whether the fullscreen player has been Release()-d. | 241 // Whether the fullscreen player has been Release()-d. |
239 bool fullscreen_player_is_released_; | 242 bool fullscreen_player_is_released_; |
240 | 243 |
241 WebContents* web_contents_; | 244 WebContents* web_contents_; |
242 | 245 |
243 // Object for retrieving resources media players. | 246 // Object for retrieving resources media players. |
244 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 247 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
245 | 248 |
246 // NOTE: Weak pointers must be invalidated before all other member variables. | 249 // NOTE: Weak pointers must be invalidated before all other member variables. |
247 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 250 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
248 | 251 |
249 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 252 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
250 }; | 253 }; |
251 | 254 |
252 } // namespace content | 255 } // namespace content |
253 | 256 |
254 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 257 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |