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 #include "content/browser/media/android/browser_media_player_manager.h" | 5 #include "content/browser/media/android/browser_media_player_manager.h" |
6 | 6 |
7 #include "base/android/scoped_java_ref.h" | 7 #include "base/android/scoped_java_ref.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
11 #include "content/browser/media/android/browser_demuxer_android.h" | 11 #include "content/browser/media/android/browser_demuxer_android.h" |
12 #include "content/browser/media/android/media_resource_getter_impl.h" | 12 #include "content/browser/media/android/media_resource_getter_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/web_contents/web_contents_view_android.h" | 14 #include "content/browser/web_contents/web_contents_view_android.h" |
15 #include "content/common/media/cdm_messages.h" | 15 #include "content/common/media/cdm_messages.h" |
16 #include "content/common/media/media_player_messages_android.h" | 16 #include "content/common/media/media_player_messages_android.h" |
17 #include "content/public/browser/android/content_view_core.h" | 17 #include "content/public/browser/android/content_view_core.h" |
18 #include "content/public/browser/android/external_video_surface_container.h" | 18 #include "content/public/browser/android/external_video_surface_container.h" |
19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/render_frame_host.h" |
21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
26 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
28 #include "media/base/android/cdm_factory.h" | 29 #include "media/base/android/cdm_factory.h" |
29 #include "media/base/android/media_player_bridge.h" | 30 #include "media/base/android/media_player_bridge.h" |
30 #include "media/base/android/media_source_player.h" | 31 #include "media/base/android/media_source_player.h" |
(...skipping 20 matching lines...) Expand all Loading... |
51 | 52 |
52 static BrowserMediaPlayerManager::Factory g_factory = NULL; | 53 static BrowserMediaPlayerManager::Factory g_factory = NULL; |
53 | 54 |
54 // static | 55 // static |
55 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) { | 56 void BrowserMediaPlayerManager::RegisterFactory(Factory factory) { |
56 g_factory = factory; | 57 g_factory = factory; |
57 } | 58 } |
58 | 59 |
59 // static | 60 // static |
60 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( | 61 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( |
61 RenderViewHost* rvh) { | 62 RenderFrameHost* rfh) { |
62 if (g_factory) | 63 if (g_factory) |
63 return g_factory(rvh); | 64 return g_factory(rfh); |
64 return new BrowserMediaPlayerManager(rvh); | 65 return new BrowserMediaPlayerManager(rfh); |
65 } | 66 } |
66 | 67 |
67 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const { | 68 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const { |
68 return ContentViewCoreImpl::FromWebContents(web_contents()); | 69 return ContentViewCoreImpl::FromWebContents(web_contents()); |
69 } | 70 } |
70 | 71 |
71 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( | 72 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( |
72 MediaPlayerHostMsg_Initialize_Type type, | 73 MediaPlayerHostMsg_Initialize_Type type, |
73 int player_id, | 74 int player_id, |
74 const GURL& url, | 75 const GURL& url, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 weak_ptr_factory_.GetWeakPtr()), | 120 weak_ptr_factory_.GetWeakPtr()), |
120 demuxer->CreateDemuxer(demuxer_client_id)); | 121 demuxer->CreateDemuxer(demuxer_client_id)); |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 NOTREACHED(); | 125 NOTREACHED(); |
125 return NULL; | 126 return NULL; |
126 } | 127 } |
127 | 128 |
128 BrowserMediaPlayerManager::BrowserMediaPlayerManager( | 129 BrowserMediaPlayerManager::BrowserMediaPlayerManager( |
129 RenderViewHost* render_view_host) | 130 RenderFrameHost* render_frame_host) |
130 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 131 : render_frame_host_(render_frame_host), |
| 132 routing_id_(render_frame_host->GetRoutingID()), |
131 fullscreen_player_id_(-1), | 133 fullscreen_player_id_(-1), |
132 fullscreen_player_is_released_(false), | 134 fullscreen_player_is_released_(false), |
133 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 135 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), |
134 weak_ptr_factory_(this) { | 136 weak_ptr_factory_(this) { |
135 } | 137 } |
136 | 138 |
137 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 139 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
138 | 140 |
139 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { | |
140 bool handled = true; | |
141 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) | |
142 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) | |
143 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_ExitFullscreen, OnExitFullscreen) | |
144 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Initialize, OnInitialize) | |
145 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Start, OnStart) | |
146 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Seek, OnSeek) | |
147 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Pause, OnPause) | |
148 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetVolume, OnSetVolume) | |
149 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetPoster, OnSetPoster) | |
150 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Release, OnReleaseResources) | |
151 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyMediaPlayer, OnDestroyPlayer) | |
152 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyAllMediaPlayers, | |
153 DestroyAllMediaPlayers) | |
154 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetCdm, OnSetCdm) | |
155 IPC_MESSAGE_HANDLER(CdmHostMsg_InitializeCdm, OnInitializeCdm) | |
156 IPC_MESSAGE_HANDLER(CdmHostMsg_CreateSession, OnCreateSession) | |
157 IPC_MESSAGE_HANDLER(CdmHostMsg_UpdateSession, OnUpdateSession) | |
158 IPC_MESSAGE_HANDLER(CdmHostMsg_ReleaseSession, OnReleaseSession) | |
159 IPC_MESSAGE_HANDLER(CdmHostMsg_DestroyCdm, OnDestroyCdm) | |
160 #if defined(VIDEO_HOLE) | |
161 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_NotifyExternalSurface, | |
162 OnNotifyExternalSurface) | |
163 #endif // defined(VIDEO_HOLE) | |
164 IPC_MESSAGE_UNHANDLED(handled = false) | |
165 IPC_END_MESSAGE_MAP() | |
166 return handled; | |
167 } | |
168 | |
169 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 141 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
170 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 142 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
171 if (player) { | 143 if (player) { |
172 if (fullscreen_player_is_released_) { | 144 if (fullscreen_player_is_released_) { |
173 video_view_->OpenVideo(); | 145 video_view_->OpenVideo(); |
174 fullscreen_player_is_released_ = false; | 146 fullscreen_player_is_released_ = false; |
175 } | 147 } |
176 player->Start(); | 148 player->Start(); |
177 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 149 Send(new MediaPlayerMsg_DidMediaPlayerPlay(routing_id_, |
178 routing_id(), fullscreen_player_id_)); | 150 fullscreen_player_id_)); |
179 } | 151 } |
180 } | 152 } |
181 | 153 |
182 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 154 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
183 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 155 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
184 if (player) { | 156 if (player) { |
185 player->Pause(true); | 157 player->Pause(true); |
186 Send(new MediaPlayerMsg_DidMediaPlayerPause( | 158 Send(new MediaPlayerMsg_DidMediaPlayerPause(routing_id_, |
187 routing_id(), fullscreen_player_id_)); | 159 fullscreen_player_id_)); |
188 } | 160 } |
189 } | 161 } |
190 | 162 |
191 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { | 163 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { |
192 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 164 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
193 if (player) { | 165 if (player) { |
194 // TODO(kbalazs): if |fullscreen_player_is_released_| is true | 166 // TODO(kbalazs): if |fullscreen_player_is_released_| is true |
195 // at this point, player->GetCurrentTime() will be wrong until | 167 // at this point, player->GetCurrentTime() will be wrong until |
196 // FullscreenPlayerPlay (http://crbug.com/322798). | 168 // FullscreenPlayerPlay (http://crbug.com/322798). |
197 OnSeekRequest(fullscreen_player_id_, | 169 OnSeekRequest(fullscreen_player_id_, |
198 base::TimeDelta::FromMilliseconds(msec)); | 170 base::TimeDelta::FromMilliseconds(msec)); |
199 } | 171 } |
200 } | 172 } |
201 | 173 |
202 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { | 174 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { |
203 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 175 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
204 switches::kDisableOverlayFullscreenVideoSubtitle)) { | 176 switches::kDisableOverlayFullscreenVideoSubtitle)) { |
205 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) | 177 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) |
206 delegate->ToggleFullscreenModeForTab(web_contents_, false); | 178 delegate->ToggleFullscreenModeForTab(web_contents_, false); |
207 if (RenderWidgetHostViewAndroid* view_android = | 179 if (RenderWidgetHostViewAndroid* view_android = |
208 static_cast<RenderWidgetHostViewAndroid*>( | 180 static_cast<RenderWidgetHostViewAndroid*>( |
209 web_contents_->GetRenderWidgetHostView())) { | 181 web_contents_->GetRenderWidgetHostView())) { |
210 view_android->SetOverlayVideoMode(false); | 182 view_android->SetOverlayVideoMode(false); |
211 } | 183 } |
212 } | 184 } |
213 | 185 |
214 Send(new MediaPlayerMsg_DidExitFullscreen( | 186 Send( |
215 routing_id(), fullscreen_player_id_)); | 187 new MediaPlayerMsg_DidExitFullscreen(routing_id_, fullscreen_player_id_)); |
216 video_view_.reset(); | 188 video_view_.reset(); |
217 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 189 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
218 fullscreen_player_id_ = -1; | 190 fullscreen_player_id_ = -1; |
219 if (!player) | 191 if (!player) |
220 return; | 192 return; |
221 if (release_media_player) | 193 if (release_media_player) |
222 ReleaseFullscreenPlayer(player); | 194 ReleaseFullscreenPlayer(player); |
223 else | 195 else |
224 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 196 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
225 } | 197 } |
226 | 198 |
227 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, | 199 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, |
228 base::TimeDelta current_time) { | 200 base::TimeDelta current_time) { |
229 Send(new MediaPlayerMsg_MediaTimeUpdate( | 201 Send( |
230 routing_id(), player_id, current_time)); | 202 new MediaPlayerMsg_MediaTimeUpdate(routing_id_, player_id, current_time)); |
231 } | 203 } |
232 | 204 |
233 void BrowserMediaPlayerManager::SetVideoSurface( | 205 void BrowserMediaPlayerManager::SetVideoSurface( |
234 gfx::ScopedJavaSurface surface) { | 206 gfx::ScopedJavaSurface surface) { |
235 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 207 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
236 if (!player) | 208 if (!player) |
237 return; | 209 return; |
238 | 210 |
239 bool empty_surface = surface.IsEmpty(); | 211 bool empty_surface = surface.IsEmpty(); |
240 player->SetVideoSurface(surface.Pass()); | 212 player->SetVideoSurface(surface.Pass()); |
241 if (empty_surface) | 213 if (empty_surface) |
242 return; | 214 return; |
243 | 215 |
244 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id(), | 216 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id_, player->player_id())); |
245 player->player_id())); | |
246 if (CommandLine::ForCurrentProcess()->HasSwitch( | 217 if (CommandLine::ForCurrentProcess()->HasSwitch( |
247 switches::kDisableOverlayFullscreenVideoSubtitle)) { | 218 switches::kDisableOverlayFullscreenVideoSubtitle)) { |
248 return; | 219 return; |
249 } | 220 } |
250 if (RenderWidgetHostViewAndroid* view_android = | 221 if (RenderWidgetHostViewAndroid* view_android = |
251 static_cast<RenderWidgetHostViewAndroid*>( | 222 static_cast<RenderWidgetHostViewAndroid*>( |
252 web_contents_->GetRenderWidgetHostView())) { | 223 web_contents_->GetRenderWidgetHostView())) { |
253 view_android->SetOverlayVideoMode(true); | 224 view_android->SetOverlayVideoMode(true); |
254 } | 225 } |
255 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) | 226 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) |
256 delegate->ToggleFullscreenModeForTab(web_contents_, true); | 227 delegate->ToggleFullscreenModeForTab(web_contents_, true); |
257 } | 228 } |
258 | 229 |
259 void BrowserMediaPlayerManager::OnMediaMetadataChanged( | 230 void BrowserMediaPlayerManager::OnMediaMetadataChanged( |
260 int player_id, base::TimeDelta duration, int width, int height, | 231 int player_id, base::TimeDelta duration, int width, int height, |
261 bool success) { | 232 bool success) { |
262 Send(new MediaPlayerMsg_MediaMetadataChanged( | 233 Send(new MediaPlayerMsg_MediaMetadataChanged( |
263 routing_id(), player_id, duration, width, height, success)); | 234 routing_id_, player_id, duration, width, height, success)); |
264 if (fullscreen_player_id_ == player_id) | 235 if (fullscreen_player_id_ == player_id) |
265 video_view_->UpdateMediaMetadata(); | 236 video_view_->UpdateMediaMetadata(); |
266 } | 237 } |
267 | 238 |
268 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) { | 239 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) { |
269 Send(new MediaPlayerMsg_MediaPlaybackCompleted(routing_id(), player_id)); | 240 Send(new MediaPlayerMsg_MediaPlaybackCompleted(routing_id_, player_id)); |
270 if (fullscreen_player_id_ == player_id) | 241 if (fullscreen_player_id_ == player_id) |
271 video_view_->OnPlaybackComplete(); | 242 video_view_->OnPlaybackComplete(); |
272 } | 243 } |
273 | 244 |
274 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) { | 245 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) { |
275 // Tell WebKit that the audio should be paused, then release all resources | 246 // Tell WebKit that the audio should be paused, then release all resources |
276 Send(new MediaPlayerMsg_MediaPlayerReleased(routing_id(), player_id)); | 247 Send(new MediaPlayerMsg_MediaPlayerReleased(routing_id_, player_id)); |
277 OnReleaseResources(player_id); | 248 OnReleaseResources(player_id); |
278 } | 249 } |
279 | 250 |
280 void BrowserMediaPlayerManager::OnBufferingUpdate( | 251 void BrowserMediaPlayerManager::OnBufferingUpdate( |
281 int player_id, int percentage) { | 252 int player_id, int percentage) { |
282 Send(new MediaPlayerMsg_MediaBufferingUpdate( | 253 Send(new MediaPlayerMsg_MediaBufferingUpdate( |
283 routing_id(), player_id, percentage)); | 254 routing_id_, player_id, percentage)); |
284 if (fullscreen_player_id_ == player_id) | 255 if (fullscreen_player_id_ == player_id) |
285 video_view_->OnBufferingUpdate(percentage); | 256 video_view_->OnBufferingUpdate(percentage); |
286 } | 257 } |
287 | 258 |
288 void BrowserMediaPlayerManager::OnSeekRequest( | 259 void BrowserMediaPlayerManager::OnSeekRequest( |
289 int player_id, | 260 int player_id, |
290 const base::TimeDelta& time_to_seek) { | 261 const base::TimeDelta& time_to_seek) { |
291 Send(new MediaPlayerMsg_SeekRequest(routing_id(), player_id, time_to_seek)); | 262 Send(new MediaPlayerMsg_SeekRequest(routing_id_, player_id, time_to_seek)); |
292 } | 263 } |
293 | 264 |
294 void BrowserMediaPlayerManager::OnSeekComplete( | 265 void BrowserMediaPlayerManager::OnSeekComplete( |
295 int player_id, | 266 int player_id, |
296 const base::TimeDelta& current_time) { | 267 const base::TimeDelta& current_time) { |
297 Send(new MediaPlayerMsg_SeekCompleted(routing_id(), player_id, current_time)); | 268 Send(new MediaPlayerMsg_SeekCompleted(routing_id_, player_id, current_time)); |
298 } | 269 } |
299 | 270 |
300 void BrowserMediaPlayerManager::OnError(int player_id, int error) { | 271 void BrowserMediaPlayerManager::OnError(int player_id, int error) { |
301 Send(new MediaPlayerMsg_MediaError(routing_id(), player_id, error)); | 272 Send(new MediaPlayerMsg_MediaError(routing_id_, player_id, error)); |
302 if (fullscreen_player_id_ == player_id) | 273 if (fullscreen_player_id_ == player_id) |
303 video_view_->OnMediaPlayerError(error); | 274 video_view_->OnMediaPlayerError(error); |
304 } | 275 } |
305 | 276 |
306 void BrowserMediaPlayerManager::OnVideoSizeChanged( | 277 void BrowserMediaPlayerManager::OnVideoSizeChanged( |
307 int player_id, int width, int height) { | 278 int player_id, int width, int height) { |
308 Send(new MediaPlayerMsg_MediaVideoSizeChanged(routing_id(), player_id, | 279 Send(new MediaPlayerMsg_MediaVideoSizeChanged(routing_id_, player_id, |
309 width, height)); | 280 width, height)); |
310 if (fullscreen_player_id_ == player_id) | 281 if (fullscreen_player_id_ == player_id) |
311 video_view_->OnVideoSizeChanged(width, height); | 282 video_view_->OnVideoSizeChanged(width, height); |
312 } | 283 } |
313 | 284 |
314 media::MediaResourceGetter* | 285 media::MediaResourceGetter* |
315 BrowserMediaPlayerManager::GetMediaResourceGetter() { | 286 BrowserMediaPlayerManager::GetMediaResourceGetter() { |
316 if (!media_resource_getter_.get()) { | 287 if (!media_resource_getter_.get()) { |
317 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); | 288 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); |
318 BrowserContext* context = host->GetBrowserContext(); | 289 BrowserContext* context = host->GetBrowserContext(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 OnError(player_id, MediaPlayerAndroid::MEDIA_ERROR_DECODE); | 337 OnError(player_id, MediaPlayerAndroid::MEDIA_ERROR_DECODE); |
367 return; | 338 return; |
368 } | 339 } |
369 | 340 |
370 // Send an IPC to the render process to request the video element to enter | 341 // Send an IPC to the render process to request the video element to enter |
371 // fullscreen. OnEnterFullscreen() will be called later on success. | 342 // fullscreen. OnEnterFullscreen() will be called later on success. |
372 // This guarantees the fullscreen video will be rendered correctly. | 343 // This guarantees the fullscreen video will be rendered correctly. |
373 // TODO(qinmin): make this flag default on android. | 344 // TODO(qinmin): make this flag default on android. |
374 if (CommandLine::ForCurrentProcess()->HasSwitch( | 345 if (CommandLine::ForCurrentProcess()->HasSwitch( |
375 switches::kDisableGestureRequirementForMediaFullscreen)) { | 346 switches::kDisableGestureRequirementForMediaFullscreen)) { |
376 Send(new MediaPlayerMsg_RequestFullscreen(routing_id(), player_id)); | 347 Send(new MediaPlayerMsg_RequestFullscreen(routing_id_, player_id)); |
377 } | 348 } |
378 } | 349 } |
379 | 350 |
380 // The following 5 functions are EME MediaKeySession events. | 351 // The following 5 functions are EME MediaKeySession events. |
381 | 352 |
382 void BrowserMediaPlayerManager::OnSessionCreated( | 353 void BrowserMediaPlayerManager::OnSessionCreated( |
383 int cdm_id, | 354 int cdm_id, |
384 uint32 session_id, | 355 uint32 session_id, |
385 const std::string& web_session_id) { | 356 const std::string& web_session_id) { |
386 Send(new CdmMsg_SessionCreated( | 357 Send(new CdmMsg_SessionCreated( |
387 routing_id(), cdm_id, session_id, web_session_id)); | 358 routing_id_, cdm_id, session_id, web_session_id)); |
388 } | 359 } |
389 | 360 |
390 void BrowserMediaPlayerManager::OnSessionMessage( | 361 void BrowserMediaPlayerManager::OnSessionMessage( |
391 int cdm_id, | 362 int cdm_id, |
392 uint32 session_id, | 363 uint32 session_id, |
393 const std::vector<uint8>& message, | 364 const std::vector<uint8>& message, |
394 const std::string& destination_url) { | 365 const std::string& destination_url) { |
395 GURL destination_gurl(destination_url); | 366 GURL destination_gurl(destination_url); |
396 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { | 367 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { |
397 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | 368 DLOG(WARNING) << "SessionMessage destination_url is invalid : " |
398 << destination_gurl.possibly_invalid_spec(); | 369 << destination_gurl.possibly_invalid_spec(); |
399 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 370 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
400 } | 371 } |
401 | 372 |
402 Send(new CdmMsg_SessionMessage( | 373 Send(new CdmMsg_SessionMessage( |
403 routing_id(), cdm_id, session_id, message, destination_gurl)); | 374 routing_id_, cdm_id, session_id, message, destination_gurl)); |
404 } | 375 } |
405 | 376 |
406 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) { | 377 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) { |
407 Send(new CdmMsg_SessionReady(routing_id(), cdm_id, session_id)); | 378 Send(new CdmMsg_SessionReady(routing_id_, cdm_id, session_id)); |
408 } | 379 } |
409 | 380 |
410 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) { | 381 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) { |
411 Send(new CdmMsg_SessionClosed(routing_id(), cdm_id, session_id)); | 382 Send(new CdmMsg_SessionClosed(routing_id_, cdm_id, session_id)); |
412 } | 383 } |
413 | 384 |
414 void BrowserMediaPlayerManager::OnSessionError( | 385 void BrowserMediaPlayerManager::OnSessionError( |
415 int cdm_id, | 386 int cdm_id, |
416 uint32 session_id, | 387 uint32 session_id, |
417 media::MediaKeys::KeyError error_code, | 388 media::MediaKeys::KeyError error_code, |
418 uint32 system_code) { | 389 uint32 system_code) { |
419 Send(new CdmMsg_SessionError( | 390 Send(new CdmMsg_SessionError( |
420 routing_id(), cdm_id, session_id, error_code, system_code)); | 391 routing_id_, cdm_id, session_id, error_code, system_code)); |
421 } | 392 } |
422 | 393 |
423 #if defined(VIDEO_HOLE) | 394 #if defined(VIDEO_HOLE) |
424 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, | 395 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, |
425 jobject surface) { | 396 jobject surface) { |
426 MediaPlayerAndroid* player = GetPlayer(player_id); | 397 MediaPlayerAndroid* player = GetPlayer(player_id); |
427 if (player) { | 398 if (player) { |
428 player->SetVideoSurface( | 399 player->SetVideoSurface( |
429 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); | 400 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); |
430 } | 401 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 if (!j_content_video_view.is_null()) { | 465 if (!j_content_video_view.is_null()) { |
495 fullscreen_player_id_ = player_id; | 466 fullscreen_player_id_ = player_id; |
496 return; | 467 return; |
497 } | 468 } |
498 } | 469 } |
499 | 470 |
500 // Force the second video to exit fullscreen. | 471 // Force the second video to exit fullscreen. |
501 // TODO(qinmin): There is no need to send DidEnterFullscreen message. | 472 // TODO(qinmin): There is no need to send DidEnterFullscreen message. |
502 // However, if we don't send the message, page layers will not be | 473 // However, if we don't send the message, page layers will not be |
503 // correctly restored. http:crbug.com/367346. | 474 // correctly restored. http:crbug.com/367346. |
504 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id(), player_id)); | 475 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id_, player_id)); |
505 Send(new MediaPlayerMsg_DidExitFullscreen(routing_id(), player_id)); | 476 Send(new MediaPlayerMsg_DidExitFullscreen(routing_id_, player_id)); |
506 video_view_.reset(); | 477 video_view_.reset(); |
507 } | 478 } |
508 | 479 |
509 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 480 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
510 if (fullscreen_player_id_ == player_id) { | 481 if (fullscreen_player_id_ == player_id) { |
511 MediaPlayerAndroid* player = GetPlayer(player_id); | 482 MediaPlayerAndroid* player = GetPlayer(player_id); |
512 if (player) | 483 if (player) |
513 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 484 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
514 video_view_->OnExitFullscreen(); | 485 video_view_->OnExitFullscreen(); |
515 } | 486 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 783 } |
813 | 784 |
814 // TODO(qinmin): add the logic to decide whether we should create the | 785 // TODO(qinmin): add the logic to decide whether we should create the |
815 // fullscreen surface for EME lv1. | 786 // fullscreen surface for EME lv1. |
816 player->SetCdm(cdm); | 787 player->SetCdm(cdm); |
817 // Do now support setting one CDM on multiple players. | 788 // Do now support setting one CDM on multiple players. |
818 DCHECK(!ContainsKey(cdm_to_player_map_, cdm_id)); | 789 DCHECK(!ContainsKey(cdm_to_player_map_, cdm_id)); |
819 cdm_to_player_map_[cdm_id] = player_id; | 790 cdm_to_player_map_[cdm_id] = player_id; |
820 } | 791 } |
821 | 792 |
| 793 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) { |
| 794 return render_frame_host_->Send(msg); |
| 795 } |
| 796 |
822 void BrowserMediaPlayerManager::CreateSessionIfPermitted( | 797 void BrowserMediaPlayerManager::CreateSessionIfPermitted( |
823 int cdm_id, | 798 int cdm_id, |
824 uint32 session_id, | 799 uint32 session_id, |
825 const std::string& content_type, | 800 const std::string& content_type, |
826 const std::vector<uint8>& init_data, | 801 const std::vector<uint8>& init_data, |
827 bool permitted) { | 802 bool permitted) { |
828 if (!permitted) { | 803 if (!permitted) { |
829 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 804 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
830 return; | 805 return; |
831 } | 806 } |
(...skipping 30 matching lines...) Expand all Loading... |
862 } | 837 } |
863 | 838 |
864 // Number of active players are less than the threshold, do nothing. | 839 // Number of active players are less than the threshold, do nothing. |
865 if (num_active_player < kMediaPlayerThreshold) | 840 if (num_active_player < kMediaPlayerThreshold) |
866 return; | 841 return; |
867 | 842 |
868 for (it = players_.begin(); it != players_.end(); ++it) { | 843 for (it = players_.begin(); it != players_.end(); ++it) { |
869 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && | 844 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && |
870 fullscreen_player_id_ != (*it)->player_id()) { | 845 fullscreen_player_id_ != (*it)->player_id()) { |
871 (*it)->Release(); | 846 (*it)->Release(); |
872 Send(new MediaPlayerMsg_MediaPlayerReleased( | 847 Send(new MediaPlayerMsg_MediaPlayerReleased(routing_id_, |
873 routing_id(), (*it)->player_id())); | 848 (*it)->player_id())); |
874 } | 849 } |
875 } | 850 } |
876 } | 851 } |
877 | 852 |
878 void BrowserMediaPlayerManager::OnMediaResourcesReleased(int player_id) { | 853 void BrowserMediaPlayerManager::OnMediaResourcesReleased(int player_id) { |
879 #if defined(VIDEO_HOLE) | 854 #if defined(VIDEO_HOLE) |
880 MediaPlayerAndroid* player = GetPlayer(player_id); | 855 MediaPlayerAndroid* player = GetPlayer(player_id); |
881 if (player && player->IsSurfaceInUse()) | 856 if (player && player->IsSurfaceInUse()) |
882 return; | 857 return; |
883 if (external_video_surface_container_) | 858 if (external_video_surface_container_) |
884 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 859 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
885 #endif // defined(VIDEO_HOLE) | 860 #endif // defined(VIDEO_HOLE) |
886 } | 861 } |
887 | 862 |
888 } // namespace content | 863 } // namespace content |
OLD | NEW |