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

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: 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_(-1), 129 fullscreen_player_id_(-1),
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 244 }
241 245
242 void BrowserMediaPlayerManager::OnVideoSizeChanged( 246 void BrowserMediaPlayerManager::OnVideoSizeChanged(
243 int player_id, int width, int height) { 247 int player_id, int width, int height) {
244 Send(new MediaPlayerMsg_MediaVideoSizeChanged(RoutingID(), player_id, 248 Send(new MediaPlayerMsg_MediaVideoSizeChanged(RoutingID(), player_id,
245 width, height)); 249 width, height));
246 if (fullscreen_player_id_ == player_id) 250 if (fullscreen_player_id_ == player_id)
247 video_view_->OnVideoSizeChanged(width, height); 251 video_view_->OnVideoSizeChanged(width, height);
248 } 252 }
249 253
254 void BrowserMediaPlayerManager::OnAudibleStateChanged(
255 int player_id, bool is_audible) {
256 audio_monitor_->OnAudibleStateChanged(
257 render_frame_host_, player_id, is_audible);
258 }
259
250 media::MediaResourceGetter* 260 media::MediaResourceGetter*
251 BrowserMediaPlayerManager::GetMediaResourceGetter() { 261 BrowserMediaPlayerManager::GetMediaResourceGetter() {
252 if (!media_resource_getter_.get()) { 262 if (!media_resource_getter_.get()) {
253 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); 263 RenderProcessHost* host = web_contents()->GetRenderProcessHost();
254 BrowserContext* context = host->GetBrowserContext(); 264 BrowserContext* context = host->GetBrowserContext();
255 StoragePartition* partition = host->GetStoragePartition(); 265 StoragePartition* partition = host->GetStoragePartition();
256 storage::FileSystemContext* file_system_context = 266 storage::FileSystemContext* file_system_context =
257 partition ? partition->GetFileSystemContext() : NULL; 267 partition ? partition->GetFileSystemContext() : NULL;
258 // Eventually this needs to be fixed to pass the correct frame rather 268 // Eventually this needs to be fixed to pass the correct frame rather
259 // than just using the main frame. 269 // than just using the main frame.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 DCHECK(!GetPlayer(player->player_id())); 511 DCHECK(!GetPlayer(player->player_id()));
502 players_.push_back(player); 512 players_.push_back(player);
503 } 513 }
504 514
505 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { 515 void BrowserMediaPlayerManager::RemovePlayer(int player_id) {
506 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 516 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
507 it != players_.end(); ++it) { 517 it != players_.end(); ++it) {
508 if ((*it)->player_id() == player_id) { 518 if ((*it)->player_id() == player_id) {
509 ReleaseMediaResources(player_id); 519 ReleaseMediaResources(player_id);
510 players_.erase(it); 520 players_.erase(it);
521 audio_monitor_->RemovePlayer(render_frame_host_, player_id);
511 break; 522 break;
512 } 523 }
513 } 524 }
514 } 525 }
515 526
516 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( 527 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer(
517 int player_id, media::MediaPlayerAndroid* player) { 528 int player_id, media::MediaPlayerAndroid* player) {
518 media::MediaPlayerAndroid* previous_player = NULL; 529 media::MediaPlayerAndroid* previous_player = NULL;
519 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 530 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
520 it != players_.end(); ++it) { 531 it != players_.end(); ++it) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 587 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
577 #endif // defined(VIDEO_HOLE) 588 #endif // defined(VIDEO_HOLE)
578 } 589 }
579 590
580 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 591 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
581 player->Release(); 592 player->Release();
582 ReleaseMediaResources(player->player_id()); 593 ReleaseMediaResources(player->player_id());
583 } 594 }
584 595
585 } // namespace content 596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698