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

Side by Side Diff: content/browser/media/session/media_session_controller.cc

Issue 1996043002: Split MediaContentType and AudioFocusType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Mounir's comments Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/session/media_session_controller.h" 5 #include "content/browser/media/session/media_session_controller.h"
6 6
7 #include "content/browser/media/media_web_contents_observer.h" 7 #include "content/browser/media/media_web_contents_observer.h"
8 #include "content/browser/media/session/media_session.h" 8 #include "content/browser/media/session/media_session.h"
9 #include "content/common/media/media_player_delegate_messages.h" 9 #include "content/common/media/media_player_delegate_messages.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
12 #include "media/base/media_content_type.h"
12 13
13 namespace content { 14 namespace content {
14 15
15 MediaSessionController::MediaSessionController( 16 MediaSessionController::MediaSessionController(
16 const WebContentsObserver::MediaPlayerId& id, 17 const WebContentsObserver::MediaPlayerId& id,
17 MediaWebContentsObserver* media_web_contents_observer) 18 MediaWebContentsObserver* media_web_contents_observer)
18 : id_(id), 19 : id_(id),
19 media_web_contents_observer_(media_web_contents_observer), 20 media_web_contents_observer_(media_web_contents_observer),
20 media_session_( 21 media_session_(
21 MediaSession::Get(media_web_contents_observer_->web_contents())) {} 22 MediaSession::Get(media_web_contents_observer_->web_contents())) {}
22 23
23 MediaSessionController::~MediaSessionController() { 24 MediaSessionController::~MediaSessionController() {
24 if (!has_session_) 25 if (!has_session_)
25 return; 26 return;
26 media_session_->RemovePlayer(this, player_id_); 27 media_session_->RemovePlayer(this, player_id_);
27 } 28 }
28 29
29 bool MediaSessionController::Initialize(bool has_audio, 30 bool MediaSessionController::Initialize(
30 bool is_remote, 31 bool has_audio,
31 base::TimeDelta duration) { 32 bool is_remote,
33 media::MediaContentType media_content_type) {
32 // Don't generate a new id if one has already been set. 34 // Don't generate a new id if one has already been set.
33 if (!has_session_) { 35 if (!has_session_) {
34 // These objects are only created on the UI thread, so this is safe. 36 // These objects are only created on the UI thread, so this is safe.
35 DCHECK_CURRENTLY_ON(BrowserThread::UI); 37 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 static uint32_t player_id = 0; 38 static uint32_t player_id = 0;
37 player_id_ = static_cast<int>(player_id++); 39 player_id_ = static_cast<int>(player_id++);
38 } else { 40 } else {
39 // WebMediaPlayerAndroid does not have an accurate sense of audio presence, 41 // WebMediaPlayerAndroid does not have an accurate sense of audio presence,
40 // only the MediaPlayerManager does, so WMPA never reports audio unless it's 42 // only the MediaPlayerManager does, so WMPA never reports audio unless it's
41 // sure (no video stream). This leads to issues when Initialize() is called 43 // sure (no video stream). This leads to issues when Initialize() is called
(...skipping 11 matching lines...) Expand all
53 // Don't bother with a MediaSession for remote players or without audio. If 55 // Don't bother with a MediaSession for remote players or without audio. If
54 // we already have a session from a previous call, release it. 56 // we already have a session from a previous call, release it.
55 if (!has_audio || is_remote) { 57 if (!has_audio || is_remote) {
56 if (has_session_) { 58 if (has_session_) {
57 has_session_ = false; 59 has_session_ = false;
58 media_session_->RemovePlayer(this, player_id_); 60 media_session_->RemovePlayer(this, player_id_);
59 } 61 }
60 return true; 62 return true;
61 } 63 }
62 64
63 const MediaSession::Type media_session_type =
64 (duration.is_zero() ||
65 duration > base::TimeDelta::FromSeconds(kMinimumDurationForContentSecs))
66 ? MediaSession::Type::Content
67 : MediaSession::Type::Transient;
68
69 // If a session can't be created, force a pause immediately. Attempt to add a 65 // If a session can't be created, force a pause immediately. Attempt to add a
70 // session even if we already have one. MediaSession expects AddPlayer() to 66 // session even if we already have one. MediaSession expects AddPlayer() to
71 // be called after OnPlaybackPaused() to reactivate the session. 67 // be called after OnPlaybackPaused() to reactivate the session.
72 if (!media_session_->AddPlayer(this, player_id_, media_session_type)) { 68 if (!media_session_->AddPlayer(this, player_id_, media_content_type)) {
73 OnSuspend(player_id_); 69 OnSuspend(player_id_);
74 return false; 70 return false;
75 } 71 }
76 72
77 has_session_ = true; 73 has_session_ = true;
78 return true; 74 return true;
79 } 75 }
80 76
81 void MediaSessionController::OnSuspend(int player_id) { 77 void MediaSessionController::OnSuspend(int player_id) {
82 DCHECK_EQ(player_id_, player_id); 78 DCHECK_EQ(player_id_, player_id);
(...skipping 16 matching lines...) Expand all
99 } 95 }
100 96
101 void MediaSessionController::OnPlaybackPaused() { 97 void MediaSessionController::OnPlaybackPaused() {
102 // We check for suspension here since the renderer may issue its own pause 98 // We check for suspension here since the renderer may issue its own pause
103 // in response to or while a pause from the browser is in flight. 99 // in response to or while a pause from the browser is in flight.
104 if (!media_session_->IsSuspended()) 100 if (!media_session_->IsSuspended())
105 media_session_->OnPlayerPaused(this, player_id_); 101 media_session_->OnPlayerPaused(this, player_id_);
106 } 102 }
107 103
108 } // namespace content 104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698