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

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

Issue 896673003: Propagate audible state from player to the containing tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed MediaSourcePlayerTest compilation. Created 5 years, 10 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 "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 "content/browser/android/audio_monitor_android.h"
9 #include "content/browser/android/content_view_core_impl.h" 10 #include "content/browser/android/content_view_core_impl.h"
10 #include "content/browser/media/android/browser_demuxer_android.h" 11 #include "content/browser/media/android/browser_demuxer_android.h"
11 #include "content/browser/media/android/media_resource_getter_impl.h" 12 #include "content/browser/media/android/media_resource_getter_impl.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/web_contents/web_contents_view_android.h" 14 #include "content/browser/web_contents/web_contents_view_android.h"
14 #include "content/common/media/media_player_messages_android.h" 15 #include "content/common/media/media_player_messages_android.h"
15 #include "content/public/browser/android/content_view_core.h" 16 #include "content/public/browser/android/content_view_core.h"
16 #include "content/public/browser/android/external_video_surface_container.h" 17 #include "content/public/browser/android/external_video_surface_container.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/content_browser_client.h" 19 #include "content/public/browser/content_browser_client.h"
(...skipping 30 matching lines...) Expand all
49 } 50 }
50 51
51 // static 52 // static
52 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( 53 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
53 media::MediaUrlInterceptor* media_url_interceptor) { 54 media::MediaUrlInterceptor* media_url_interceptor) {
54 media_url_interceptor_ = media_url_interceptor; 55 media_url_interceptor_ = media_url_interceptor;
55 } 56 }
56 57
57 // static 58 // static
58 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( 59 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create(
59 RenderFrameHost* rfh) { 60 RenderFrameHost* rfh,
61 AudioMonitorAndroid* audio_monitor) {
60 if (g_factory) 62 if (g_factory)
61 return g_factory(rfh); 63 return g_factory(rfh, audio_monitor);
62 return new BrowserMediaPlayerManager(rfh); 64 return new BrowserMediaPlayerManager(rfh, audio_monitor);
63 } 65 }
64 66
65 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const { 67 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const {
66 return ContentViewCoreImpl::FromWebContents(web_contents()); 68 return ContentViewCoreImpl::FromWebContents(web_contents());
67 } 69 }
68 70
69 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( 71 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer(
70 const MediaPlayerHostMsg_Initialize_Params& media_player_params, 72 const MediaPlayerHostMsg_Initialize_Params& media_player_params,
71 bool hide_url_log, 73 bool hide_url_log,
72 MediaPlayerManager* manager, 74 MediaPlayerManager* manager,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 demuxer->CreateDemuxer(media_player_params.demuxer_client_id), 115 demuxer->CreateDemuxer(media_player_params.demuxer_client_id),
114 media_player_params.frame_url); 116 media_player_params.frame_url);
115 } 117 }
116 } 118 }
117 119
118 NOTREACHED(); 120 NOTREACHED();
119 return NULL; 121 return NULL;
120 } 122 }
121 123
122 BrowserMediaPlayerManager::BrowserMediaPlayerManager( 124 BrowserMediaPlayerManager::BrowserMediaPlayerManager(
123 RenderFrameHost* render_frame_host) 125 RenderFrameHost* render_frame_host,
126 AudioMonitorAndroid* audio_monitor)
124 : render_frame_host_(render_frame_host), 127 : render_frame_host_(render_frame_host),
128 audio_monitor_(audio_monitor),
125 fullscreen_player_id_(kInvalidMediaPlayerId), 129 fullscreen_player_id_(kInvalidMediaPlayerId),
126 fullscreen_player_is_released_(false), 130 fullscreen_player_is_released_(false),
127 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), 131 web_contents_(WebContents::FromRenderFrameHost(render_frame_host)),
128 weak_ptr_factory_(this) { 132 weak_ptr_factory_(this) {
129 } 133 }
130 134
131 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() { 135 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {
132 // During the tear down process, OnDestroyPlayer() may or may not be called 136 // During the tear down process, OnDestroyPlayer() may or may not be called
133 // (e.g. the WebContents may be destroyed before the render process). So 137 // (e.g. the WebContents may be destroyed before the render process). So
134 // we cannot DCHECK(players_.empty()) here. Instead, all media players in 138 // we cannot DCHECK(players_.empty()) here. Instead, all media players in
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 248 }
245 249
246 void BrowserMediaPlayerManager::OnVideoSizeChanged( 250 void BrowserMediaPlayerManager::OnVideoSizeChanged(
247 int player_id, int width, int height) { 251 int player_id, int width, int height) {
248 Send(new MediaPlayerMsg_MediaVideoSizeChanged(RoutingID(), player_id, 252 Send(new MediaPlayerMsg_MediaVideoSizeChanged(RoutingID(), player_id,
249 width, height)); 253 width, height));
250 if (fullscreen_player_id_ == player_id) 254 if (fullscreen_player_id_ == player_id)
251 video_view_->OnVideoSizeChanged(width, height); 255 video_view_->OnVideoSizeChanged(width, height);
252 } 256 }
253 257
258 void BrowserMediaPlayerManager::OnAudibleStateChanged(
259 int player_id, bool is_audible) {
260 audio_monitor_->OnAudibleStateChanged(
261 render_frame_host_, player_id, is_audible);
262 }
263
254 media::MediaResourceGetter* 264 media::MediaResourceGetter*
255 BrowserMediaPlayerManager::GetMediaResourceGetter() { 265 BrowserMediaPlayerManager::GetMediaResourceGetter() {
256 if (!media_resource_getter_.get()) { 266 if (!media_resource_getter_.get()) {
257 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); 267 RenderProcessHost* host = web_contents()->GetRenderProcessHost();
258 BrowserContext* context = host->GetBrowserContext(); 268 BrowserContext* context = host->GetBrowserContext();
259 StoragePartition* partition = host->GetStoragePartition(); 269 StoragePartition* partition = host->GetStoragePartition();
260 storage::FileSystemContext* file_system_context = 270 storage::FileSystemContext* file_system_context =
261 partition ? partition->GetFileSystemContext() : NULL; 271 partition ? partition->GetFileSystemContext() : NULL;
262 // Eventually this needs to be fixed to pass the correct frame rather 272 // Eventually this needs to be fixed to pass the correct frame rather
263 // than just using the main frame. 273 // than just using the main frame.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 DCHECK(!GetPlayer(player->player_id())); 518 DCHECK(!GetPlayer(player->player_id()));
509 players_.push_back(player); 519 players_.push_back(player);
510 } 520 }
511 521
512 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { 522 void BrowserMediaPlayerManager::RemovePlayer(int player_id) {
513 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 523 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
514 it != players_.end(); ++it) { 524 it != players_.end(); ++it) {
515 if ((*it)->player_id() == player_id) { 525 if ((*it)->player_id() == player_id) {
516 ReleaseMediaResources(player_id); 526 ReleaseMediaResources(player_id);
517 players_.erase(it); 527 players_.erase(it);
528 audio_monitor_->RemovePlayer(render_frame_host_, player_id);
518 break; 529 break;
519 } 530 }
520 } 531 }
521 } 532 }
522 533
523 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( 534 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer(
524 int player_id, media::MediaPlayerAndroid* player) { 535 int player_id, media::MediaPlayerAndroid* player) {
525 media::MediaPlayerAndroid* previous_player = NULL; 536 media::MediaPlayerAndroid* previous_player = NULL;
526 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 537 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
527 it != players_.end(); ++it) { 538 it != players_.end(); ++it) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 594 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
584 #endif // defined(VIDEO_HOLE) 595 #endif // defined(VIDEO_HOLE)
585 } 596 }
586 597
587 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 598 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
588 player->Release(); 599 player->Release();
589 ReleaseMediaResources(player->player_id()); 600 ReleaseMediaResources(player->player_id());
590 } 601 }
591 602
592 } // namespace content 603 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698