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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/android/content_view_core_impl.h" | 8 #include "content/browser/android/content_view_core_impl.h" |
9 #include "content/browser/media/android/browser_demuxer_android.h" | 9 #include "content/browser/media/android/browser_demuxer_android.h" |
10 #include "content/browser/media/android/media_resource_getter_impl.h" | 10 #include "content/browser/media/android/media_resource_getter_impl.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 109 |
110 NOTREACHED(); | 110 NOTREACHED(); |
111 return NULL; | 111 return NULL; |
112 } | 112 } |
113 | 113 |
114 BrowserMediaPlayerManager::BrowserMediaPlayerManager( | 114 BrowserMediaPlayerManager::BrowserMediaPlayerManager( |
115 RenderViewHost* render_view_host) | 115 RenderViewHost* render_view_host) |
116 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 116 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), |
117 fullscreen_player_id_(-1), | 117 fullscreen_player_id_(-1), |
118 pending_fullscreen_player_id_(-1), | 118 pending_fullscreen_player_id_(-1), |
119 fullscreen_player_is_released_(false), | |
119 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 120 web_contents_(WebContents::FromRenderViewHost(render_view_host)), |
120 weak_ptr_factory_(this) { | 121 weak_ptr_factory_(this) { |
121 } | 122 } |
122 | 123 |
123 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 124 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
124 | 125 |
125 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { | 126 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { |
126 bool handled = true; | 127 bool handled = true; |
127 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) | 128 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) |
128 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) | 129 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) |
(...skipping 19 matching lines...) Expand all Loading... | |
148 OnNotifyExternalSurface) | 149 OnNotifyExternalSurface) |
149 #endif // defined(VIDEO_HOLE) | 150 #endif // defined(VIDEO_HOLE) |
150 IPC_MESSAGE_UNHANDLED(handled = false) | 151 IPC_MESSAGE_UNHANDLED(handled = false) |
151 IPC_END_MESSAGE_MAP() | 152 IPC_END_MESSAGE_MAP() |
152 return handled; | 153 return handled; |
153 } | 154 } |
154 | 155 |
155 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 156 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
156 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 157 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
157 if (player) { | 158 if (player) { |
159 if (fullscreen_player_is_released_) { | |
160 video_view_->OpenVideo(); | |
161 fullscreen_player_is_released_ = false; | |
162 } | |
158 player->Start(); | 163 player->Start(); |
159 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 164 Send(new MediaPlayerMsg_DidMediaPlayerPlay( |
160 routing_id(), fullscreen_player_id_)); | 165 routing_id(), fullscreen_player_id_)); |
161 } | 166 } |
162 } | 167 } |
163 | 168 |
164 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 169 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
165 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 170 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
166 if (player) { | 171 if (player) { |
167 player->Pause(true); | 172 player->Pause(true); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 204 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
200 fullscreen_player_id_ = -1; | 205 fullscreen_player_id_ = -1; |
201 if (!player) | 206 if (!player) |
202 return; | 207 return; |
203 if (release_media_player) | 208 if (release_media_player) |
204 player->Release(); | 209 player->Release(); |
205 else | 210 else |
206 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 211 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
207 } | 212 } |
208 | 213 |
209 void BrowserMediaPlayerManager::SuspendFullscreen() { | |
210 MediaPlayerAndroid* player = GetFullscreenPlayer(); | |
211 if (player) | |
212 player->SetVideoSurface(gfx::ScopedJavaSurface()); | |
213 } | |
214 | |
215 void BrowserMediaPlayerManager::ResumeFullscreen( | |
216 gfx::ScopedJavaSurface surface) { | |
217 MediaPlayerAndroid* player = GetFullscreenPlayer(); | |
218 if (player) | |
219 player->SetVideoSurface(surface.Pass()); | |
220 } | |
221 | |
222 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, | 214 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, |
223 base::TimeDelta current_time) { | 215 base::TimeDelta current_time) { |
224 Send(new MediaPlayerMsg_MediaTimeUpdate( | 216 Send(new MediaPlayerMsg_MediaTimeUpdate( |
225 routing_id(), player_id, current_time)); | 217 routing_id(), player_id, current_time)); |
226 } | 218 } |
227 | 219 |
228 void BrowserMediaPlayerManager::SetVideoSurface( | 220 void BrowserMediaPlayerManager::SetVideoSurface( |
229 gfx::ScopedJavaSurface surface) { | 221 gfx::ScopedJavaSurface surface) { |
230 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 222 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
231 if (!player) | 223 if (!player) |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 return; | 491 return; |
500 } | 492 } |
501 | 493 |
502 if (video_view_.get()) { | 494 if (video_view_.get()) { |
503 fullscreen_player_id_ = player_id; | 495 fullscreen_player_id_ = player_id; |
504 video_view_->OpenVideo(); | 496 video_view_->OpenVideo(); |
505 } else if (!ContentVideoView::GetInstance()) { | 497 } else if (!ContentVideoView::GetInstance()) { |
506 // In Android WebView, two ContentViewCores could both try to enter | 498 // In Android WebView, two ContentViewCores could both try to enter |
507 // fullscreen video, we just ignore the second one. | 499 // fullscreen video, we just ignore the second one. |
508 fullscreen_player_id_ = player_id; | 500 fullscreen_player_id_ = player_id; |
509 video_view_.reset(new ContentVideoView(this)); | 501 video_view_.reset(new ContentVideoView(this)); |
bulach
2014/02/13 12:02:44
ditto..
| |
510 } | 502 } |
511 } | 503 } |
512 | 504 |
513 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 505 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
514 if (fullscreen_player_id_ == player_id) { | 506 if (fullscreen_player_id_ == player_id) { |
515 MediaPlayerAndroid* player = GetPlayer(player_id); | 507 MediaPlayerAndroid* player = GetPlayer(player_id); |
516 if (player) | 508 if (player) |
517 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 509 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
518 video_view_->OnExitFullscreen(); | 510 video_view_->OnExitFullscreen(); |
519 } | 511 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 556 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
565 MediaPlayerAndroid* player = GetPlayer(player_id); | 557 MediaPlayerAndroid* player = GetPlayer(player_id); |
566 if (player) | 558 if (player) |
567 player->SetVolume(volume); | 559 player->SetVolume(volume); |
568 } | 560 } |
569 | 561 |
570 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 562 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
571 MediaPlayerAndroid* player = GetPlayer(player_id); | 563 MediaPlayerAndroid* player = GetPlayer(player_id); |
572 if (player) | 564 if (player) |
573 player->Release(); | 565 player->Release(); |
566 if (player_id == fullscreen_player_id_) | |
567 fullscreen_player_is_released_ = true; | |
574 | 568 |
575 #if defined(VIDEO_HOLE) | 569 #if defined(VIDEO_HOLE) |
576 WebContentsViewAndroid* view = | 570 WebContentsViewAndroid* view = |
577 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 571 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
578 if (view) | 572 if (view) |
579 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | 573 view->NotifyExternalSurface(player_id, false, gfx::RectF()); |
580 #endif // defined(VIDEO_HOLE) | 574 #endif // defined(VIDEO_HOLE) |
581 } | 575 } |
582 | 576 |
583 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 577 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 if (pending_fullscreen_player_id_ != media_keys_id) | 839 if (pending_fullscreen_player_id_ != media_keys_id) |
846 return; | 840 return; |
847 | 841 |
848 pending_fullscreen_player_id_ = -1; | 842 pending_fullscreen_player_id_ = -1; |
849 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 843 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
850 if (player->IsPlaying()) | 844 if (player->IsPlaying()) |
851 OnProtectedSurfaceRequested(media_keys_id); | 845 OnProtectedSurfaceRequested(media_keys_id); |
852 } | 846 } |
853 | 847 |
854 } // namespace content | 848 } // namespace content |
OLD | NEW |