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> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
14 #include "base/callback.h" | 9 #include "base/callback.h" |
15 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
17 #include "base/time/time.h" | 12 #include "base/time/time.h" |
18 #include "content/browser/android/content_video_view.h" | 13 #include "content/browser/android/content_video_view.h" |
19 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
20 #include "content/common/media/cdm_messages_enums.h" | |
21 #include "content/common/media/media_player_messages_enums_android.h" | 15 #include "content/common/media/media_player_messages_enums_android.h" |
22 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
23 #include "media/base/android/media_player_android.h" | 17 #include "media/base/android/media_player_android.h" |
24 #include "media/base/android/media_player_manager.h" | 18 #include "media/base/android/media_player_manager.h" |
25 #include "media/base/media_keys.h" | |
26 #include "ui/gfx/rect_f.h" | 19 #include "ui/gfx/rect_f.h" |
27 #include "url/gurl.h" | 20 #include "url/gurl.h" |
28 | 21 |
29 namespace media { | 22 namespace media { |
30 class BrowserCdm; | |
31 class DemuxerAndroid; | 23 class DemuxerAndroid; |
32 } | 24 } |
33 | 25 |
34 namespace content { | 26 namespace content { |
35 class BrowserDemuxerAndroid; | 27 class BrowserDemuxerAndroid; |
36 class ContentViewCoreImpl; | 28 class ContentViewCoreImpl; |
37 class ExternalVideoSurfaceContainer; | 29 class ExternalVideoSurfaceContainer; |
38 class RenderFrameHost; | 30 class RenderFrameHost; |
39 class WebContents; | 31 class WebContents; |
40 | 32 |
41 // This class manages all the MediaPlayerAndroid and CDM objects. | 33 // This class manages all the MediaPlayerAndroid objects. |
42 // It receives control operations from the the render process, and forwards | 34 // It receives control operations from the the render process, and forwards |
43 // them to corresponding MediaPlayerAndroid or CDM object. Callbacks from | 35 // them to corresponding MediaPlayerAndroid object. Callbacks from |
44 // MediaPlayerAndroid and CDM objects are converted to IPCs and then sent to | 36 // MediaPlayerAndroid objects are converted to IPCs and then sent to the render |
45 // the render process. | 37 // process. |
46 class CONTENT_EXPORT BrowserMediaPlayerManager | 38 class CONTENT_EXPORT BrowserMediaPlayerManager |
47 : public media::MediaPlayerManager { | 39 : public media::MediaPlayerManager { |
48 public: | 40 public: |
49 // Permits embedders to provide an extended version of the class. | 41 // Permits embedders to provide an extended version of the class. |
50 typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*); | 42 typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*); |
51 static void RegisterFactory(Factory factory); | 43 static void RegisterFactory(Factory factory); |
52 | 44 |
53 // Returns a new instance using the registered factory if available. | 45 // Returns a new instance using the registered factory if available. |
54 static BrowserMediaPlayerManager* Create(RenderFrameHost* rfh); | 46 static BrowserMediaPlayerManager* Create(RenderFrameHost* rfh); |
55 | 47 |
(...skipping 29 matching lines...) Expand all Loading... |
85 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE; | 77 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE; |
86 virtual void OnSeekComplete( | 78 virtual void OnSeekComplete( |
87 int player_id, | 79 int player_id, |
88 const base::TimeDelta& current_time) OVERRIDE; | 80 const base::TimeDelta& current_time) OVERRIDE; |
89 virtual void OnError(int player_id, int error) OVERRIDE; | 81 virtual void OnError(int player_id, int error) OVERRIDE; |
90 virtual void OnVideoSizeChanged( | 82 virtual void OnVideoSizeChanged( |
91 int player_id, int width, int height) OVERRIDE; | 83 int player_id, int width, int height) OVERRIDE; |
92 virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE; | 84 virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE; |
93 virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE; | 85 virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE; |
94 virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE; | 86 virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE; |
95 virtual media::BrowserCdm* GetCdm(int cdm_id) OVERRIDE; | |
96 virtual void DestroyAllMediaPlayers() OVERRIDE; | 87 virtual void DestroyAllMediaPlayers() OVERRIDE; |
97 virtual void RequestFullScreen(int player_id) OVERRIDE; | 88 virtual void RequestFullScreen(int player_id) OVERRIDE; |
98 virtual void OnSessionCreated(int cdm_id, | |
99 uint32 session_id, | |
100 const std::string& web_session_id) OVERRIDE; | |
101 virtual void OnSessionMessage(int cdm_id, | |
102 uint32 session_id, | |
103 const std::vector<uint8>& message, | |
104 const GURL& destination_url) OVERRIDE; | |
105 virtual void OnSessionReady(int cdm_id, uint32 session_id) OVERRIDE; | |
106 virtual void OnSessionClosed(int cdm_id, uint32 session_id) OVERRIDE; | |
107 virtual void OnSessionError(int cdm_id, | |
108 uint32 session_id, | |
109 media::MediaKeys::KeyError error_code, | |
110 uint32 system_code) OVERRIDE; | |
111 | 89 |
112 #if defined(VIDEO_HOLE) | 90 #if defined(VIDEO_HOLE) |
113 void AttachExternalVideoSurface(int player_id, jobject surface); | 91 void AttachExternalVideoSurface(int player_id, jobject surface); |
114 void DetachExternalVideoSurface(int player_id); | 92 void DetachExternalVideoSurface(int player_id); |
115 void OnFrameInfoUpdated(); | 93 void OnFrameInfoUpdated(); |
116 #endif // defined(VIDEO_HOLE) | 94 #endif // defined(VIDEO_HOLE) |
117 | 95 |
118 // Message handlers. | 96 // Message handlers. |
119 virtual void OnEnterFullscreen(int player_id); | 97 virtual void OnEnterFullscreen(int player_id); |
120 virtual void OnExitFullscreen(int player_id); | 98 virtual void OnExitFullscreen(int player_id); |
121 virtual void OnInitialize( | 99 virtual void OnInitialize( |
122 MediaPlayerHostMsg_Initialize_Type type, | 100 MediaPlayerHostMsg_Initialize_Type type, |
123 int player_id, | 101 int player_id, |
124 const GURL& url, | 102 const GURL& url, |
125 const GURL& first_party_for_cookies, | 103 const GURL& first_party_for_cookies, |
126 int demuxer_client_id); | 104 int demuxer_client_id); |
127 virtual void OnStart(int player_id); | 105 virtual void OnStart(int player_id); |
128 virtual void OnSeek(int player_id, const base::TimeDelta& time); | 106 virtual void OnSeek(int player_id, const base::TimeDelta& time); |
129 virtual void OnPause(int player_id, bool is_media_related_action); | 107 virtual void OnPause(int player_id, bool is_media_related_action); |
130 virtual void OnSetVolume(int player_id, double volume); | 108 virtual void OnSetVolume(int player_id, double volume); |
131 virtual void OnSetPoster(int player_id, const GURL& poster); | 109 virtual void OnSetPoster(int player_id, const GURL& poster); |
132 virtual void OnReleaseResources(int player_id); | 110 virtual void OnReleaseResources(int player_id); |
133 virtual void OnDestroyPlayer(int player_id); | 111 virtual void OnDestroyPlayer(int player_id); |
134 virtual void ReleaseFullscreenPlayer(media::MediaPlayerAndroid* player); | 112 virtual void ReleaseFullscreenPlayer(media::MediaPlayerAndroid* player); |
135 void OnInitializeCdm(int cdm_id, | |
136 const std::string& key_system, | |
137 const GURL& frame_url); | |
138 void OnCreateSession(int cdm_id, | |
139 uint32 session_id, | |
140 CdmHostMsg_CreateSession_ContentType content_type, | |
141 const std::vector<uint8>& init_data); | |
142 void OnUpdateSession(int cdm_id, | |
143 uint32 session_id, | |
144 const std::vector<uint8>& response); | |
145 void OnReleaseSession(int cdm_id, uint32 session_id); | |
146 void OnSetCdm(int player_id, int cdm_id); | |
147 void OnDestroyCdm(int cdm_id); | |
148 #if defined(VIDEO_HOLE) | 113 #if defined(VIDEO_HOLE) |
149 void OnNotifyExternalSurface( | 114 void OnNotifyExternalSurface( |
150 int player_id, bool is_request, const gfx::RectF& rect); | 115 int player_id, bool is_request, const gfx::RectF& rect); |
151 #endif // defined(VIDEO_HOLE) | 116 #endif // defined(VIDEO_HOLE) |
152 | 117 |
153 protected: | 118 protected: |
154 // Clients must use Create() or subclass constructor. | 119 // Clients must use Create() or subclass constructor. |
155 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); | 120 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); |
156 | 121 |
157 WebContents* web_contents() const { return web_contents_; } | 122 WebContents* web_contents() const { return web_contents_; } |
158 | 123 |
159 // Cancels all pending session creations associated with |cdm_id|. | |
160 void CancelAllPendingSessionCreations(int cdm_id); | |
161 | |
162 // Adds a given player to the list. | 124 // Adds a given player to the list. |
163 void AddPlayer(media::MediaPlayerAndroid* player); | 125 void AddPlayer(media::MediaPlayerAndroid* player); |
164 | 126 |
165 // Removes the player with the specified id. | 127 // Removes the player with the specified id. |
166 void RemovePlayer(int player_id); | 128 void RemovePlayer(int player_id); |
167 | 129 |
168 // Replaces a player with the specified id with a given MediaPlayerAndroid | 130 // Replaces a player with the specified id with a given MediaPlayerAndroid |
169 // object. This will also return the original MediaPlayerAndroid object that | 131 // object. This will also return the original MediaPlayerAndroid object that |
170 // was replaced. | 132 // was replaced. |
171 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 133 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
172 int player_id, | 134 int player_id, |
173 media::MediaPlayerAndroid* player); | 135 media::MediaPlayerAndroid* player); |
174 | 136 |
175 // Adds a new CDM identified by |cdm_id| for the given |key_system| and | |
176 // |security_origin|. | |
177 void AddCdm(int cdm_id, | |
178 const std::string& key_system, | |
179 const GURL& security_origin); | |
180 | |
181 // Removes the CDM with the specified id. | |
182 void RemoveCdm(int cdm_id); | |
183 | |
184 int RoutingID(); | 137 int RoutingID(); |
185 | 138 |
186 // Helper function to send messages to RenderFrameObserver. | 139 // Helper function to send messages to RenderFrameObserver. |
187 bool Send(IPC::Message* msg); | 140 bool Send(IPC::Message* msg); |
188 | 141 |
189 private: | 142 private: |
190 // If |permitted| is false, it does nothing but send | |
191 // |CdmMsg_SessionError| IPC message. | |
192 // The primary use case is infobar permission callback, i.e., when infobar | |
193 // can decide user's intention either from interacting with the actual info | |
194 // bar or from the saved preference. | |
195 void CreateSessionIfPermitted(int cdm_id, | |
196 uint32 session_id, | |
197 const std::string& content_type, | |
198 const std::vector<uint8>& init_data, | |
199 bool permitted); | |
200 | |
201 // Constructs a MediaPlayerAndroid object. | 143 // Constructs a MediaPlayerAndroid object. |
202 media::MediaPlayerAndroid* CreateMediaPlayer( | 144 media::MediaPlayerAndroid* CreateMediaPlayer( |
203 MediaPlayerHostMsg_Initialize_Type type, | 145 MediaPlayerHostMsg_Initialize_Type type, |
204 int player_id, | 146 int player_id, |
205 const GURL& url, | 147 const GURL& url, |
206 const GURL& first_party_for_cookies, | 148 const GURL& first_party_for_cookies, |
207 int demuxer_client_id, | 149 int demuxer_client_id, |
208 bool hide_url_log, | 150 bool hide_url_log, |
209 media::MediaPlayerManager* manager, | 151 media::MediaPlayerManager* manager, |
210 BrowserDemuxerAndroid* demuxer); | 152 BrowserDemuxerAndroid* demuxer); |
(...skipping 11 matching lines...) Expand all Loading... |
222 | 164 |
223 #if defined(VIDEO_HOLE) | 165 #if defined(VIDEO_HOLE) |
224 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); | 166 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); |
225 #endif // defined(VIDEO_HOLE) | 167 #endif // defined(VIDEO_HOLE) |
226 | 168 |
227 RenderFrameHost* const render_frame_host_; | 169 RenderFrameHost* const render_frame_host_; |
228 | 170 |
229 // An array of managed players. | 171 // An array of managed players. |
230 ScopedVector<media::MediaPlayerAndroid> players_; | 172 ScopedVector<media::MediaPlayerAndroid> players_; |
231 | 173 |
232 // A map from CDM IDs to managed CDMs. | |
233 typedef std::map<int, media::BrowserCdm*> CdmMap; | |
234 CdmMap cdm_map_; | |
235 | |
236 // Map from CDM ID to CDM's security origin. | |
237 std::map<int, GURL> cdm_security_origin_map_; | |
238 | |
239 // The fullscreen video view object or NULL if video is not played in | 174 // The fullscreen video view object or NULL if video is not played in |
240 // fullscreen. | 175 // fullscreen. |
241 scoped_ptr<ContentVideoView> video_view_; | 176 scoped_ptr<ContentVideoView> video_view_; |
242 | 177 |
243 #if defined(VIDEO_HOLE) | 178 #if defined(VIDEO_HOLE) |
244 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; | 179 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; |
245 #endif | 180 #endif |
246 | 181 |
247 // Player ID of the fullscreen media player. | 182 // Player ID of the fullscreen media player. |
248 int fullscreen_player_id_; | 183 int fullscreen_player_id_; |
249 | 184 |
250 // Whether the fullscreen player has been Release()-d. | 185 // Whether the fullscreen player has been Release()-d. |
251 bool fullscreen_player_is_released_; | 186 bool fullscreen_player_is_released_; |
252 | 187 |
253 WebContents* const web_contents_; | 188 WebContents* const web_contents_; |
254 | 189 |
255 // Object for retrieving resources media players. | 190 // Object for retrieving resources media players. |
256 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 191 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
257 | 192 |
258 // NOTE: Weak pointers must be invalidated before all other member variables. | 193 // NOTE: Weak pointers must be invalidated before all other member variables. |
259 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 194 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
260 | 195 |
261 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 196 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
262 }; | 197 }; |
263 | 198 |
264 } // namespace content | 199 } // namespace content |
265 | 200 |
266 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 201 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |