Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: content/browser/media/android/browser_media_player_manager.cc

Issue 1308983005: NOT FOR LANDING Implement WebMediaSession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add forward declaration Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "content/browser/frame_host/render_frame_host_impl.h" 10 #include "content/browser/frame_host/render_frame_host_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/browser_media_session_manager.h"
12 #include "content/browser/media/android/media_resource_getter_impl.h" 13 #include "content/browser/media/android/media_resource_getter_impl.h"
13 #include "content/browser/media/android/media_session.h" 14 #include "content/browser/media/android/media_session.h"
14 #include "content/browser/media/android/media_throttler.h" 15 #include "content/browser/media/android/media_throttler.h"
15 #include "content/browser/media/android/media_web_contents_observer_android.h" 16 #include "content/browser/media/android/media_web_contents_observer_android.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 17 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/web_contents/web_contents_impl.h" 18 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/common/media/media_player_messages_android.h" 19 #include "content/common/media/media_player_messages_android.h"
19 #include "content/public/browser/android/external_video_surface_container.h" 20 #include "content/public/browser/android/external_video_surface_container.h"
20 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #endif 140 #endif
140 141
141 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( 142 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer(
142 const MediaPlayerHostMsg_Initialize_Params& media_player_params, 143 const MediaPlayerHostMsg_Initialize_Params& media_player_params,
143 bool hide_url_log, 144 bool hide_url_log,
144 BrowserDemuxerAndroid* demuxer) { 145 BrowserDemuxerAndroid* demuxer) {
145 switch (media_player_params.type) { 146 switch (media_player_params.type) {
146 case MEDIA_PLAYER_TYPE_URL: { 147 case MEDIA_PLAYER_TYPE_URL: {
147 const std::string user_agent = GetContentClient()->GetUserAgent(); 148 const std::string user_agent = GetContentClient()->GetUserAgent();
148 MediaPlayerBridge* media_player_bridge = new MediaPlayerBridge( 149 MediaPlayerBridge* media_player_bridge = new MediaPlayerBridge(
149 media_player_params.player_id, 150 media_player_params.player_id, media_player_params.url,
150 media_player_params.url, 151 media_player_params.first_party_for_cookies, user_agent, hide_url_log,
151 media_player_params.first_party_for_cookies,
152 user_agent,
153 hide_url_log,
154 this, 152 this,
155 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased, 153 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased,
156 weak_ptr_factory_.GetWeakPtr()), 154 weak_ptr_factory_.GetWeakPtr()),
157 media_player_params.frame_url, 155 media_player_params.frame_url, media_player_params.allow_credentials,
158 media_player_params.allow_credentials); 156 media_player_params.session_id);
159 bool should_block = false; 157 bool should_block = false;
160 bool extract_metadata = 158 bool extract_metadata =
161 // Initialize the player will cause MediaMetadataExtractor to decode 159 // Initialize the player will cause MediaMetadataExtractor to decode
162 // small chunks of data. 160 // small chunks of data.
163 RequestDecoderResources(media_player_params.player_id, true); 161 RequestDecoderResources(media_player_params.player_id, true);
164 #if !defined(USE_AURA) 162 #if !defined(USE_AURA)
165 ContentViewCoreImpl* content_view_core_impl = 163 ContentViewCoreImpl* content_view_core_impl =
166 static_cast<ContentViewCoreImpl*>( 164 static_cast<ContentViewCoreImpl*>(
167 ContentViewCore::FromWebContents(web_contents_)); 165 ContentViewCore::FromWebContents(web_contents_));
168 if (!content_view_core_impl) { 166 if (!content_view_core_impl) {
(...skipping 12 matching lines...) Expand all
181 0, 0, false); 179 0, 0, false);
182 } else if (!should_block) { 180 } else if (!should_block) {
183 media_player_bridge->Initialize(); 181 media_player_bridge->Initialize();
184 } 182 }
185 return media_player_bridge; 183 return media_player_bridge;
186 } 184 }
187 185
188 case MEDIA_PLAYER_TYPE_MEDIA_SOURCE: { 186 case MEDIA_PLAYER_TYPE_MEDIA_SOURCE: {
189 if (media::UseMediaThreadForMediaPlayback()) { 187 if (media::UseMediaThreadForMediaPlayback()) {
190 return new MediaCodecPlayer( 188 return new MediaCodecPlayer(
191 media_player_params.player_id, 189 media_player_params.player_id, weak_ptr_factory_.GetWeakPtr(),
192 weak_ptr_factory_.GetWeakPtr(),
193 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased, 190 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased,
194 weak_ptr_factory_.GetWeakPtr()), 191 weak_ptr_factory_.GetWeakPtr()),
195 demuxer->CreateDemuxer(media_player_params.demuxer_client_id), 192 demuxer->CreateDemuxer(media_player_params.demuxer_client_id),
196 media_player_params.frame_url); 193 media_player_params.frame_url, media_player_params.session_id);
197 } else { 194 } else {
198 return new MediaSourcePlayer( 195 return new MediaSourcePlayer(
199 media_player_params.player_id, 196 media_player_params.player_id, this,
200 this,
201 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased, 197 base::Bind(&BrowserMediaPlayerManager::OnDecoderResourcesReleased,
202 weak_ptr_factory_.GetWeakPtr()), 198 weak_ptr_factory_.GetWeakPtr()),
203 demuxer->CreateDemuxer(media_player_params.demuxer_client_id), 199 demuxer->CreateDemuxer(media_player_params.demuxer_client_id),
204 media_player_params.frame_url); 200 media_player_params.frame_url, media_player_params.session_id);
205 } 201 }
206 } 202 }
207 } 203 }
208 204
209 NOTREACHED(); 205 NOTREACHED();
210 return NULL; 206 return NULL;
211 } 207 }
212 208
213 BrowserMediaPlayerManager::BrowserMediaPlayerManager( 209 BrowserMediaPlayerManager::BrowserMediaPlayerManager(
214 RenderFrameHost* render_frame_host) 210 RenderFrameHost* render_frame_host)
215 : render_frame_host_(render_frame_host), 211 : render_frame_host_(render_frame_host),
216 fullscreen_player_id_(kInvalidMediaPlayerId), 212 fullscreen_player_id_(kInvalidMediaPlayerId),
217 fullscreen_player_is_released_(false), 213 fullscreen_player_is_released_(false),
218 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), 214 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)),
219 weak_ptr_factory_(this) { 215 weak_ptr_factory_(this) {
220 } 216 }
221 217
222 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() { 218 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {
223 // During the tear down process, OnDestroyPlayer() may or may not be called 219 // During the tear down process, OnDestroyPlayer() may or may not be called
224 // (e.g. the WebContents may be destroyed before the render process). So 220 // (e.g. the WebContents may be destroyed before the render process). So
225 // we cannot DCHECK(players_.empty()) here. Instead, all media players in 221 // we cannot DCHECK(players_.empty()) here. Instead, all media players in
226 // |players_| will be destroyed here because |player_| is a ScopedVector. 222 // |players_| will be destroyed here because |player_| is a ScopedVector.
227 223
228 for (MediaPlayerAndroid* player : players_) 224 for (MediaPlayerAndroid* player : players_)
229 player->DeleteOnCorrectThread(); 225 player->DeleteOnCorrectThread();
230 226
231 MediaSession::Get(web_contents())->RemovePlayers(this); 227 GetMediaSessionManager()->RemovePlayers(this);
232 players_.weak_clear(); 228 players_.weak_clear();
233 } 229 }
234 230
235 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { 231 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) {
236 #if defined(USE_AURA) 232 #if defined(USE_AURA)
237 // TODO(crbug.com/548024) 233 // TODO(crbug.com/548024)
238 NOTIMPLEMENTED(); 234 NOTIMPLEMENTED();
239 #else 235 #else
240 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) 236 if (WebContentsDelegate* delegate = web_contents_->GetDelegate())
241 delegate->ExitFullscreenModeForTab(web_contents_); 237 delegate->ExitFullscreenModeForTab(web_contents_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 int player_id, base::TimeDelta duration, int width, int height, 293 int player_id, base::TimeDelta duration, int width, int height,
298 bool success) { 294 bool success) {
299 Send(new MediaPlayerMsg_MediaMetadataChanged( 295 Send(new MediaPlayerMsg_MediaMetadataChanged(
300 RoutingID(), player_id, duration, width, height, success)); 296 RoutingID(), player_id, duration, width, height, success));
301 if (fullscreen_player_id_ == player_id) 297 if (fullscreen_player_id_ == player_id)
302 video_view_->UpdateMediaMetadata(); 298 video_view_->UpdateMediaMetadata();
303 } 299 }
304 300
305 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) { 301 void BrowserMediaPlayerManager::OnPlaybackComplete(int player_id) {
306 Send(new MediaPlayerMsg_MediaPlaybackCompleted(RoutingID(), player_id)); 302 Send(new MediaPlayerMsg_MediaPlaybackCompleted(RoutingID(), player_id));
307 MediaSession::Get(web_contents())->RemovePlayer(this, player_id); 303 GetMediaSessionManager()->RemovePlayer(this, player_id);
308 304
309 if (fullscreen_player_id_ == player_id) 305 if (fullscreen_player_id_ == player_id)
310 video_view_->OnPlaybackComplete(); 306 video_view_->OnPlaybackComplete();
311 } 307 }
312 308
313 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) { 309 void BrowserMediaPlayerManager::OnMediaInterrupted(int player_id) {
314 // Tell WebKit that the audio should be paused, then release all resources 310 // Tell WebKit that the audio should be paused, then release all resources
315 Send(new MediaPlayerMsg_MediaPlayerReleased(RoutingID(), player_id)); 311 Send(new MediaPlayerMsg_MediaPlayerReleased(RoutingID(), player_id));
316 MediaSession::Get(web_contents())->RemovePlayer(this, player_id); 312 MediaSession::Get(web_contents())->RemovePlayer(this, player_id);
317 ReleaseResources(player_id); 313 ReleaseResources(player_id);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 bool has_audio) { 402 bool has_audio) {
407 if (!has_audio) 403 if (!has_audio)
408 return true; 404 return true;
409 405
410 MediaSession::Type media_session_type = 406 MediaSession::Type media_session_type =
411 duration == base::TimeDelta() || 407 duration == base::TimeDelta() ||
412 duration.InSeconds() > kMinimumDurationForContentInSeconds 408 duration.InSeconds() > kMinimumDurationForContentInSeconds
413 ? MediaSession::Type::Content 409 ? MediaSession::Type::Content
414 : MediaSession::Type::Transient; 410 : MediaSession::Type::Transient;
415 411
416 bool succeeded = MediaSession::Get(web_contents())->AddPlayer( 412 MediaPlayerAndroid* player = GetPlayer(player_id);
417 this, player_id, media_session_type); 413 DCHECK(player);
414
415 MediaSession* media_session =
416 GetMediaSessionManager()->GetSession(player->session_id());
417 // Implicit activation of media session unless already activated
418 bool succeeded =
419 media_session->AddPlayer(this, player_id, media_session_type);
418 if (!succeeded) 420 if (!succeeded)
419 Send(new MediaPlayerMsg_DidMediaPlayerPause(RoutingID(), player_id)); 421 Send(new MediaPlayerMsg_DidMediaPlayerPause(RoutingID(), player_id));
420 return succeeded; 422 return succeeded;
421 } 423 }
422 424
423 void BrowserMediaPlayerManager::OnSuspend(int player_id) { 425 void BrowserMediaPlayerManager::OnSuspend(int player_id) {
424 MediaPlayerAndroid* player = GetPlayer(player_id); 426 MediaPlayerAndroid* player = GetPlayer(player_id);
425 DCHECK(player); 427 DCHECK(player);
426 428
427 player->Pause(true); 429 player->Pause(true);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 598 }
597 599
598 void BrowserMediaPlayerManager::OnPause( 600 void BrowserMediaPlayerManager::OnPause(
599 int player_id, 601 int player_id,
600 bool is_media_related_action) { 602 bool is_media_related_action) {
601 MediaPlayerAndroid* player = GetPlayer(player_id); 603 MediaPlayerAndroid* player = GetPlayer(player_id);
602 if (player) 604 if (player)
603 player->Pause(is_media_related_action); 605 player->Pause(is_media_related_action);
604 606
605 if (is_media_related_action) 607 if (is_media_related_action)
606 MediaSession::Get(web_contents())->OnPlayerPaused(this, player_id); 608 GetMediaSessionManager()->OnPlayerPaused(this, player_id);
607 } 609 }
608 610
609 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { 611 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) {
610 MediaPlayerAndroid* player = GetPlayer(player_id); 612 MediaPlayerAndroid* player = GetPlayer(player_id);
611 if (player) 613 if (player)
612 player->SetVolume(volume); 614 player->SetVolume(volume);
613 } 615 }
614 616
615 void BrowserMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) { 617 void BrowserMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) {
616 // To be overridden by subclasses. 618 // To be overridden by subclasses.
617 } 619 }
618 620
619 void BrowserMediaPlayerManager::OnSuspendAndReleaseResources(int player_id) { 621 void BrowserMediaPlayerManager::OnSuspendAndReleaseResources(int player_id) {
620 MediaSession::Get(web_contents())->RemovePlayer(this, player_id); 622 GetMediaSessionManager()->RemovePlayer(this, player_id);
621 ReleaseResources(player_id); 623 ReleaseResources(player_id);
622 } 624 }
623 625
624 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { 626 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) {
625 DestroyPlayer(player_id); 627 DestroyPlayer(player_id);
626 if (fullscreen_player_id_ == player_id) 628 if (fullscreen_player_id_ == player_id)
627 fullscreen_player_id_ = kInvalidMediaPlayerId; 629 fullscreen_player_id_ = kInvalidMediaPlayerId;
628 } 630 }
629 631
630 void BrowserMediaPlayerManager::OnRequestRemotePlayback(int /* player_id */) { 632 void BrowserMediaPlayerManager::OnRequestRemotePlayback(int /* player_id */) {
(...skipping 12 matching lines...) Expand all
643 645
644 void BrowserMediaPlayerManager::DestroyPlayer(int player_id) { 646 void BrowserMediaPlayerManager::DestroyPlayer(int player_id) {
645 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 647 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
646 it != players_.end(); ++it) { 648 it != players_.end(); ++it) {
647 if ((*it)->player_id() == player_id) { 649 if ((*it)->player_id() == player_id) {
648 #if defined(VIDEO_HOLE) 650 #if defined(VIDEO_HOLE)
649 ReleaseExternalSurface(player_id); 651 ReleaseExternalSurface(player_id);
650 #endif 652 #endif
651 (*it)->DeleteOnCorrectThread(); 653 (*it)->DeleteOnCorrectThread();
652 players_.weak_erase(it); 654 players_.weak_erase(it);
653 MediaSession::Get(web_contents())->RemovePlayer(this, player_id); 655 GetMediaSessionManager()->RemovePlayer(this, player_id);
654 break; 656 break;
655 } 657 }
656 } 658 }
657 active_players_.erase(player_id); 659 active_players_.erase(player_id);
658 } 660 }
659 661
660 void BrowserMediaPlayerManager::ReleaseResources(int player_id) { 662 void BrowserMediaPlayerManager::ReleaseResources(int player_id) {
661 MediaPlayerAndroid* player = GetPlayer(player_id); 663 MediaPlayerAndroid* player = GetPlayer(player_id);
662 if (player) 664 if (player)
663 ReleasePlayer(player); 665 ReleasePlayer(player);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 MediaPlayerAndroid* player = GetPlayer(player_id); 764 MediaPlayerAndroid* player = GetPlayer(player_id);
763 if (!player) 765 if (!player)
764 return; 766 return;
765 player->Start(); 767 player->Start();
766 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) { 768 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) {
767 video_view_->OpenVideo(); 769 video_view_->OpenVideo();
768 fullscreen_player_is_released_ = false; 770 fullscreen_player_is_released_ = false;
769 } 771 }
770 } 772 }
771 773
774 BrowserMediaSessionManager*
775 BrowserMediaPlayerManager::GetMediaSessionManager() {
776 return MediaWebContentsObserverAndroid::FromWebContents(web_contents())
777 ->GetMediaSessionManager(render_frame_host_);
778 }
779
772 } // namespace content 780 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698