| 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/media_player_bridge.h" | 29 #include "media/base/android/media_player_bridge.h" |
| 29 #include "media/base/android/media_source_player.h" | 30 #include "media/base/android/media_source_player.h" |
| 30 #include "media/base/cdm_factory.h" | 31 #include "media/base/cdm_factory.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), |
| 131 fullscreen_player_id_(-1), | 132 fullscreen_player_id_(-1), |
| 132 fullscreen_player_is_released_(false), | 133 fullscreen_player_is_released_(false), |
| 133 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 134 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), |
| 134 weak_ptr_factory_(this) { | 135 weak_ptr_factory_(this) { |
| 135 } | 136 } |
| 136 | 137 |
| 137 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 138 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
| 138 | 139 |
| 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() { | 140 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
| 170 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 141 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 171 if (player) { | 142 if (player) { |
| 172 if (fullscreen_player_is_released_) { | 143 if (fullscreen_player_is_released_) { |
| 173 video_view_->OpenVideo(); | 144 video_view_->OpenVideo(); |
| 174 fullscreen_player_is_released_ = false; | 145 fullscreen_player_is_released_ = false; |
| 175 } | 146 } |
| 176 player->Start(); | 147 player->Start(); |
| 177 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 148 Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), |
| 178 routing_id(), fullscreen_player_id_)); | 149 fullscreen_player_id_)); |
| 179 } | 150 } |
| 180 } | 151 } |
| 181 | 152 |
| 182 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 153 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
| 183 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 154 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 184 if (player) { | 155 if (player) { |
| 185 player->Pause(true); | 156 player->Pause(true); |
| 186 Send(new MediaPlayerMsg_DidMediaPlayerPause( | 157 Send(new MediaPlayerMsg_DidMediaPlayerPause(RoutingID(), |
| 187 routing_id(), fullscreen_player_id_)); | 158 fullscreen_player_id_)); |
| 188 } | 159 } |
| 189 } | 160 } |
| 190 | 161 |
| 191 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { | 162 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { |
| 192 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 163 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 193 if (player) { | 164 if (player) { |
| 194 // TODO(kbalazs): if |fullscreen_player_is_released_| is true | 165 // TODO(kbalazs): if |fullscreen_player_is_released_| is true |
| 195 // at this point, player->GetCurrentTime() will be wrong until | 166 // at this point, player->GetCurrentTime() will be wrong until |
| 196 // FullscreenPlayerPlay (http://crbug.com/322798). | 167 // FullscreenPlayerPlay (http://crbug.com/322798). |
| 197 OnSeekRequest(fullscreen_player_id_, | 168 OnSeekRequest(fullscreen_player_id_, |
| 198 base::TimeDelta::FromMilliseconds(msec)); | 169 base::TimeDelta::FromMilliseconds(msec)); |
| 199 } | 170 } |
| 200 } | 171 } |
| 201 | 172 |
| 202 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { | 173 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { |
| 203 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 174 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 switches::kDisableOverlayFullscreenVideoSubtitle)) { | 175 switches::kDisableOverlayFullscreenVideoSubtitle)) { |
| 205 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) | 176 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) |
| 206 delegate->ToggleFullscreenModeForTab(web_contents_, false); | 177 delegate->ToggleFullscreenModeForTab(web_contents_, false); |
| 207 if (RenderWidgetHostViewAndroid* view_android = | 178 if (RenderWidgetHostViewAndroid* view_android = |
| 208 static_cast<RenderWidgetHostViewAndroid*>( | 179 static_cast<RenderWidgetHostViewAndroid*>( |
| 209 web_contents_->GetRenderWidgetHostView())) { | 180 web_contents_->GetRenderWidgetHostView())) { |
| 210 view_android->SetOverlayVideoMode(false); | 181 view_android->SetOverlayVideoMode(false); |
| 211 } | 182 } |
| 212 } | 183 } |
| 213 | 184 |
| 214 Send(new MediaPlayerMsg_DidExitFullscreen( | 185 Send( |
| 215 routing_id(), fullscreen_player_id_)); | 186 new MediaPlayerMsg_DidExitFullscreen(RoutingID(), fullscreen_player_id_)); |
| 216 video_view_.reset(); | 187 video_view_.reset(); |
| 217 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 188 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 218 fullscreen_player_id_ = -1; | 189 fullscreen_player_id_ = -1; |
| 219 if (!player) | 190 if (!player) |
| 220 return; | 191 return; |
| 221 if (release_media_player) | 192 if (release_media_player) |
| 222 ReleaseFullscreenPlayer(player); | 193 ReleaseFullscreenPlayer(player); |
| 223 else | 194 else |
| 224 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 195 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 225 } | 196 } |
| 226 | 197 |
| 227 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, | 198 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, |
| 228 base::TimeDelta current_time) { | 199 base::TimeDelta current_time) { |
| 229 Send(new MediaPlayerMsg_MediaTimeUpdate( | 200 Send( |
| 230 routing_id(), player_id, current_time)); | 201 new MediaPlayerMsg_MediaTimeUpdate(RoutingID(), player_id, current_time)); |
| 231 } | 202 } |
| 232 | 203 |
| 233 void BrowserMediaPlayerManager::SetVideoSurface( | 204 void BrowserMediaPlayerManager::SetVideoSurface( |
| 234 gfx::ScopedJavaSurface surface) { | 205 gfx::ScopedJavaSurface surface) { |
| 235 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 206 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 236 if (!player) | 207 if (!player) |
| 237 return; | 208 return; |
| 238 | 209 |
| 239 bool empty_surface = surface.IsEmpty(); | 210 bool empty_surface = surface.IsEmpty(); |
| 240 player->SetVideoSurface(surface.Pass()); | 211 player->SetVideoSurface(surface.Pass()); |
| 241 if (empty_surface) | 212 if (empty_surface) |
| 242 return; | 213 return; |
| 243 | 214 |
| 244 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id(), | 215 Send(new MediaPlayerMsg_DidEnterFullscreen(RoutingID(), player->player_id())); |
| 245 player->player_id())); | |
| 246 if (CommandLine::ForCurrentProcess()->HasSwitch( | 216 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 247 switches::kDisableOverlayFullscreenVideoSubtitle)) { | 217 switches::kDisableOverlayFullscreenVideoSubtitle)) { |
| 248 return; | 218 return; |
| 249 } | 219 } |
| 250 if (RenderWidgetHostViewAndroid* view_android = | 220 if (RenderWidgetHostViewAndroid* view_android = |
| 251 static_cast<RenderWidgetHostViewAndroid*>( | 221 static_cast<RenderWidgetHostViewAndroid*>( |
| 252 web_contents_->GetRenderWidgetHostView())) { | 222 web_contents_->GetRenderWidgetHostView())) { |
| 253 view_android->SetOverlayVideoMode(true); | 223 view_android->SetOverlayVideoMode(true); |
| 254 } | 224 } |
| 255 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) | 225 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) |
| 256 delegate->ToggleFullscreenModeForTab(web_contents_, true); | 226 delegate->ToggleFullscreenModeForTab(web_contents_, true); |
| 257 } | 227 } |
| 258 | 228 |
| 259 void BrowserMediaPlayerManager::OnMediaMetadataChanged( | 229 void BrowserMediaPlayerManager::OnMediaMetadataChanged( |
| 260 int player_id, base::TimeDelta duration, int width, int height, | 230 int player_id, base::TimeDelta duration, int width, int height, |
| 261 bool success) { | 231 bool success) { |
| 262 Send(new MediaPlayerMsg_MediaMetadataChanged( | 232 Send(new MediaPlayerMsg_MediaMetadataChanged( |
| 263 routing_id(), player_id, duration, width, height, success)); | 233 RoutingID(), player_id, duration, width, height, success)); |
| 264 if (fullscreen_player_id_ == player_id) | 234 if (fullscreen_player_id_ == player_id) |
| 265 video_view_->UpdateMediaMetadata(); | 235 video_view_->UpdateMediaMetadata(); |
| 266 } | 236 } |
| 267 | 237 |
| 268 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) { | 238 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) { |
| 269 Send(new MediaPlayerMsg_MediaPlaybackCompleted(routing_id(), player_id)); | 239 Send(new MediaPlayerMsg_MediaPlaybackCompleted(RoutingID(), player_id)); |
| 270 if (fullscreen_player_id_ == player_id) | 240 if (fullscreen_player_id_ == player_id) |
| 271 video_view_->OnPlaybackComplete(); | 241 video_view_->OnPlaybackComplete(); |
| 272 } | 242 } |
| 273 | 243 |
| 274 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) { | 244 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) { |
| 275 // Tell WebKit that the audio should be paused, then release all resources | 245 // Tell WebKit that the audio should be paused, then release all resources |
| 276 Send(new MediaPlayerMsg_MediaPlayerReleased(routing_id(), player_id)); | 246 Send(new MediaPlayerMsg_MediaPlayerReleased(RoutingID(), player_id)); |
| 277 OnReleaseResources(player_id); | 247 OnReleaseResources(player_id); |
| 278 } | 248 } |
| 279 | 249 |
| 280 void BrowserMediaPlayerManager::OnBufferingUpdate( | 250 void BrowserMediaPlayerManager::OnBufferingUpdate( |
| 281 int player_id, int percentage) { | 251 int player_id, int percentage) { |
| 282 Send(new MediaPlayerMsg_MediaBufferingUpdate( | 252 Send(new MediaPlayerMsg_MediaBufferingUpdate( |
| 283 routing_id(), player_id, percentage)); | 253 RoutingID(), player_id, percentage)); |
| 284 if (fullscreen_player_id_ == player_id) | 254 if (fullscreen_player_id_ == player_id) |
| 285 video_view_->OnBufferingUpdate(percentage); | 255 video_view_->OnBufferingUpdate(percentage); |
| 286 } | 256 } |
| 287 | 257 |
| 288 void BrowserMediaPlayerManager::OnSeekRequest( | 258 void BrowserMediaPlayerManager::OnSeekRequest( |
| 289 int player_id, | 259 int player_id, |
| 290 const base::TimeDelta& time_to_seek) { | 260 const base::TimeDelta& time_to_seek) { |
| 291 Send(new MediaPlayerMsg_SeekRequest(routing_id(), player_id, time_to_seek)); | 261 Send(new MediaPlayerMsg_SeekRequest(RoutingID(), player_id, time_to_seek)); |
| 262 } |
| 263 |
| 264 void BrowserMediaPlayerManager::PauseVideo() { |
| 265 Send(new MediaPlayerMsg_PauseVideo(RoutingID())); |
| 292 } | 266 } |
| 293 | 267 |
| 294 void BrowserMediaPlayerManager::OnSeekComplete( | 268 void BrowserMediaPlayerManager::OnSeekComplete( |
| 295 int player_id, | 269 int player_id, |
| 296 const base::TimeDelta& current_time) { | 270 const base::TimeDelta& current_time) { |
| 297 Send(new MediaPlayerMsg_SeekCompleted(routing_id(), player_id, current_time)); | 271 Send(new MediaPlayerMsg_SeekCompleted(RoutingID(), player_id, current_time)); |
| 298 } | 272 } |
| 299 | 273 |
| 300 void BrowserMediaPlayerManager::OnError(int player_id, int error) { | 274 void BrowserMediaPlayerManager::OnError(int player_id, int error) { |
| 301 Send(new MediaPlayerMsg_MediaError(routing_id(), player_id, error)); | 275 Send(new MediaPlayerMsg_MediaError(RoutingID(), player_id, error)); |
| 302 if (fullscreen_player_id_ == player_id) | 276 if (fullscreen_player_id_ == player_id) |
| 303 video_view_->OnMediaPlayerError(error); | 277 video_view_->OnMediaPlayerError(error); |
| 304 } | 278 } |
| 305 | 279 |
| 306 void BrowserMediaPlayerManager::OnVideoSizeChanged( | 280 void BrowserMediaPlayerManager::OnVideoSizeChanged( |
| 307 int player_id, int width, int height) { | 281 int player_id, int width, int height) { |
| 308 Send(new MediaPlayerMsg_MediaVideoSizeChanged(routing_id(), player_id, | 282 Send(new MediaPlayerMsg_MediaVideoSizeChanged(RoutingID(), player_id, |
| 309 width, height)); | 283 width, height)); |
| 310 if (fullscreen_player_id_ == player_id) | 284 if (fullscreen_player_id_ == player_id) |
| 311 video_view_->OnVideoSizeChanged(width, height); | 285 video_view_->OnVideoSizeChanged(width, height); |
| 312 } | 286 } |
| 313 | 287 |
| 314 media::MediaResourceGetter* | 288 media::MediaResourceGetter* |
| 315 BrowserMediaPlayerManager::GetMediaResourceGetter() { | 289 BrowserMediaPlayerManager::GetMediaResourceGetter() { |
| 316 if (!media_resource_getter_.get()) { | 290 if (!media_resource_getter_.get()) { |
| 317 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); | 291 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); |
| 318 BrowserContext* context = host->GetBrowserContext(); | 292 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); | 340 OnError(player_id, MediaPlayerAndroid::MEDIA_ERROR_DECODE); |
| 367 return; | 341 return; |
| 368 } | 342 } |
| 369 | 343 |
| 370 // Send an IPC to the render process to request the video element to enter | 344 // Send an IPC to the render process to request the video element to enter |
| 371 // fullscreen. OnEnterFullscreen() will be called later on success. | 345 // fullscreen. OnEnterFullscreen() will be called later on success. |
| 372 // This guarantees the fullscreen video will be rendered correctly. | 346 // This guarantees the fullscreen video will be rendered correctly. |
| 373 // TODO(qinmin): make this flag default on android. | 347 // TODO(qinmin): make this flag default on android. |
| 374 if (CommandLine::ForCurrentProcess()->HasSwitch( | 348 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 375 switches::kDisableGestureRequirementForMediaFullscreen)) { | 349 switches::kDisableGestureRequirementForMediaFullscreen)) { |
| 376 Send(new MediaPlayerMsg_RequestFullscreen(routing_id(), player_id)); | 350 Send(new MediaPlayerMsg_RequestFullscreen(RoutingID(), player_id)); |
| 377 } | 351 } |
| 378 } | 352 } |
| 379 | 353 |
| 380 // The following 5 functions are EME MediaKeySession events. | 354 // The following 5 functions are EME MediaKeySession events. |
| 381 | 355 |
| 382 void BrowserMediaPlayerManager::OnSessionCreated( | 356 void BrowserMediaPlayerManager::OnSessionCreated( |
| 383 int cdm_id, | 357 int cdm_id, |
| 384 uint32 session_id, | 358 uint32 session_id, |
| 385 const std::string& web_session_id) { | 359 const std::string& web_session_id) { |
| 386 Send(new CdmMsg_SessionCreated( | 360 Send(new CdmMsg_SessionCreated( |
| 387 routing_id(), cdm_id, session_id, web_session_id)); | 361 RoutingID(), cdm_id, session_id, web_session_id)); |
| 388 } | 362 } |
| 389 | 363 |
| 390 void BrowserMediaPlayerManager::OnSessionMessage( | 364 void BrowserMediaPlayerManager::OnSessionMessage( |
| 391 int cdm_id, | 365 int cdm_id, |
| 392 uint32 session_id, | 366 uint32 session_id, |
| 393 const std::vector<uint8>& message, | 367 const std::vector<uint8>& message, |
| 394 const std::string& destination_url) { | 368 const std::string& destination_url) { |
| 395 GURL destination_gurl(destination_url); | 369 GURL destination_gurl(destination_url); |
| 396 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { | 370 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) { |
| 397 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | 371 DLOG(WARNING) << "SessionMessage destination_url is invalid : " |
| 398 << destination_gurl.possibly_invalid_spec(); | 372 << destination_gurl.possibly_invalid_spec(); |
| 399 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 373 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
| 400 } | 374 } |
| 401 | 375 |
| 402 Send(new CdmMsg_SessionMessage( | 376 Send(new CdmMsg_SessionMessage( |
| 403 routing_id(), cdm_id, session_id, message, destination_gurl)); | 377 RoutingID(), cdm_id, session_id, message, destination_gurl)); |
| 404 } | 378 } |
| 405 | 379 |
| 406 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) { | 380 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) { |
| 407 Send(new CdmMsg_SessionReady(routing_id(), cdm_id, session_id)); | 381 Send(new CdmMsg_SessionReady(RoutingID(), cdm_id, session_id)); |
| 408 } | 382 } |
| 409 | 383 |
| 410 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) { | 384 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) { |
| 411 Send(new CdmMsg_SessionClosed(routing_id(), cdm_id, session_id)); | 385 Send(new CdmMsg_SessionClosed(RoutingID(), cdm_id, session_id)); |
| 412 } | 386 } |
| 413 | 387 |
| 414 void BrowserMediaPlayerManager::OnSessionError( | 388 void BrowserMediaPlayerManager::OnSessionError( |
| 415 int cdm_id, | 389 int cdm_id, |
| 416 uint32 session_id, | 390 uint32 session_id, |
| 417 media::MediaKeys::KeyError error_code, | 391 media::MediaKeys::KeyError error_code, |
| 418 uint32 system_code) { | 392 uint32 system_code) { |
| 419 Send(new CdmMsg_SessionError( | 393 Send(new CdmMsg_SessionError( |
| 420 routing_id(), cdm_id, session_id, error_code, system_code)); | 394 RoutingID(), cdm_id, session_id, error_code, system_code)); |
| 421 } | 395 } |
| 422 | 396 |
| 423 #if defined(VIDEO_HOLE) | 397 #if defined(VIDEO_HOLE) |
| 424 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, | 398 void BrowserMediaPlayerManager::AttachExternalVideoSurface(int player_id, |
| 425 jobject surface) { | 399 jobject surface) { |
| 426 MediaPlayerAndroid* player = GetPlayer(player_id); | 400 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 427 if (player) { | 401 if (player) { |
| 428 player->SetVideoSurface( | 402 player->SetVideoSurface( |
| 429 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); | 403 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); |
| 430 } | 404 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 if (!j_content_video_view.is_null()) { | 468 if (!j_content_video_view.is_null()) { |
| 495 fullscreen_player_id_ = player_id; | 469 fullscreen_player_id_ = player_id; |
| 496 return; | 470 return; |
| 497 } | 471 } |
| 498 } | 472 } |
| 499 | 473 |
| 500 // Force the second video to exit fullscreen. | 474 // Force the second video to exit fullscreen. |
| 501 // TODO(qinmin): There is no need to send DidEnterFullscreen message. | 475 // TODO(qinmin): There is no need to send DidEnterFullscreen message. |
| 502 // However, if we don't send the message, page layers will not be | 476 // However, if we don't send the message, page layers will not be |
| 503 // correctly restored. http:crbug.com/367346. | 477 // correctly restored. http:crbug.com/367346. |
| 504 Send(new MediaPlayerMsg_DidEnterFullscreen(routing_id(), player_id)); | 478 Send(new MediaPlayerMsg_DidEnterFullscreen(RoutingID(), player_id)); |
| 505 Send(new MediaPlayerMsg_DidExitFullscreen(routing_id(), player_id)); | 479 Send(new MediaPlayerMsg_DidExitFullscreen(RoutingID(), player_id)); |
| 506 video_view_.reset(); | 480 video_view_.reset(); |
| 507 } | 481 } |
| 508 | 482 |
| 509 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 483 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
| 510 if (fullscreen_player_id_ == player_id) { | 484 if (fullscreen_player_id_ == player_id) { |
| 511 MediaPlayerAndroid* player = GetPlayer(player_id); | 485 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 512 if (player) | 486 if (player) |
| 513 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 487 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 514 video_view_->OnExitFullscreen(); | 488 video_view_->OnExitFullscreen(); |
| 515 } | 489 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 // Do now support setting one CDM on multiple players. | 800 // Do now support setting one CDM on multiple players. |
| 827 | 801 |
| 828 if (ContainsKey(cdm_to_player_map_, cdm_id)) { | 802 if (ContainsKey(cdm_to_player_map_, cdm_id)) { |
| 829 DVLOG(1) << "CDM is already set on another player."; | 803 DVLOG(1) << "CDM is already set on another player."; |
| 830 return; | 804 return; |
| 831 } | 805 } |
| 832 | 806 |
| 833 cdm_to_player_map_[cdm_id] = player_id; | 807 cdm_to_player_map_[cdm_id] = player_id; |
| 834 } | 808 } |
| 835 | 809 |
| 810 int BrowserMediaPlayerManager::RoutingID() { |
| 811 return render_frame_host_->GetRoutingID(); |
| 812 } |
| 813 |
| 814 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) { |
| 815 return render_frame_host_->Send(msg); |
| 816 } |
| 817 |
| 836 void BrowserMediaPlayerManager::CreateSessionIfPermitted( | 818 void BrowserMediaPlayerManager::CreateSessionIfPermitted( |
| 837 int cdm_id, | 819 int cdm_id, |
| 838 uint32 session_id, | 820 uint32 session_id, |
| 839 const std::string& content_type, | 821 const std::string& content_type, |
| 840 const std::vector<uint8>& init_data, | 822 const std::vector<uint8>& init_data, |
| 841 bool permitted) { | 823 bool permitted) { |
| 842 if (!permitted) { | 824 if (!permitted) { |
| 843 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 825 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 844 return; | 826 return; |
| 845 } | 827 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 875 } | 857 } |
| 876 | 858 |
| 877 // Number of active players are less than the threshold, do nothing. | 859 // Number of active players are less than the threshold, do nothing. |
| 878 if (num_active_player < kMediaPlayerThreshold) | 860 if (num_active_player < kMediaPlayerThreshold) |
| 879 return; | 861 return; |
| 880 | 862 |
| 881 for (it = players_.begin(); it != players_.end(); ++it) { | 863 for (it = players_.begin(); it != players_.end(); ++it) { |
| 882 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && | 864 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && |
| 883 fullscreen_player_id_ != (*it)->player_id()) { | 865 fullscreen_player_id_ != (*it)->player_id()) { |
| 884 (*it)->Release(); | 866 (*it)->Release(); |
| 885 Send(new MediaPlayerMsg_MediaPlayerReleased( | 867 Send(new MediaPlayerMsg_MediaPlayerReleased(RoutingID(), |
| 886 routing_id(), (*it)->player_id())); | 868 (*it)->player_id())); |
| 887 } | 869 } |
| 888 } | 870 } |
| 889 } | 871 } |
| 890 | 872 |
| 891 void BrowserMediaPlayerManager::OnMediaResourcesReleased(int player_id) { | 873 void BrowserMediaPlayerManager::OnMediaResourcesReleased(int player_id) { |
| 892 #if defined(VIDEO_HOLE) | 874 #if defined(VIDEO_HOLE) |
| 893 MediaPlayerAndroid* player = GetPlayer(player_id); | 875 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 894 if (player && player->IsSurfaceInUse()) | 876 if (player && player->IsSurfaceInUse()) |
| 895 return; | 877 return; |
| 896 if (external_video_surface_container_) | 878 if (external_video_surface_container_) |
| 897 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 879 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
| 898 #endif // defined(VIDEO_HOLE) | 880 #endif // defined(VIDEO_HOLE) |
| 899 } | 881 } |
| 900 | 882 |
| 901 } // namespace content | 883 } // namespace content |
| OLD | NEW |