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