| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "content/browser/media/session/media_session.h" |
| 6 | 6 |
| 7 #include "content/browser/media/session/audio_focus_delegate.h" | 7 #include "content/browser/media/session/audio_focus_delegate.h" |
| 8 #include "content/browser/media/session/media_session_player_observer.h" | 8 #include "content/browser/media/session/media_session_player_observer.h" |
| 9 #include "content/browser/media/session/media_session_service_impl.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/browser/web_contents_delegate.h" | 12 #include "content/public/browser/web_contents_delegate.h" |
| 12 #include "media/base/media_content_type.h" | 13 #include "media/base/media_content_type.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const double kDefaultVolumeMultiplier = 1.0; | 19 const double kDefaultVolumeMultiplier = 1.0; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 // TODO(zqzhang): refactor MediaSession, maybe move the interface used to talk | 67 // TODO(zqzhang): refactor MediaSession, maybe move the interface used to talk |
| 67 // with AudioFocusManager out to a seperate class. The AudioFocusManager unit | 68 // with AudioFocusManager out to a seperate class. The AudioFocusManager unit |
| 68 // tests then could mock the interface and abandon audio focus when | 69 // tests then could mock the interface and abandon audio focus when |
| 69 // WebContents is destroyed. See https://crbug.com/651069 | 70 // WebContents is destroyed. See https://crbug.com/651069 |
| 70 players_.clear(); | 71 players_.clear(); |
| 71 pepper_players_.clear(); | 72 pepper_players_.clear(); |
| 72 AbandonSystemAudioFocusIfNeeded(); | 73 AbandonSystemAudioFocusIfNeeded(); |
| 73 } | 74 } |
| 74 | 75 |
| 76 void MediaSession::SetMediaSessionService(MediaSessionServiceImpl* service) { |
| 77 service_ = service; |
| 78 } |
| 79 |
| 75 void MediaSession::SetMetadata(const base::Optional<MediaMetadata>& metadata) { | 80 void MediaSession::SetMetadata(const base::Optional<MediaMetadata>& metadata) { |
| 76 metadata_ = metadata; | 81 metadata_ = metadata; |
| 77 static_cast<WebContentsImpl*>(web_contents()) | 82 static_cast<WebContentsImpl*>(web_contents()) |
| 78 ->OnMediaSessionMetadataChanged(); | 83 ->OnMediaSessionMetadataChanged(); |
| 79 } | 84 } |
| 80 | 85 |
| 81 bool MediaSession::AddPlayer(MediaSessionPlayerObserver* observer, | 86 bool MediaSession::AddPlayer(MediaSessionPlayerObserver* observer, |
| 82 int player_id, | 87 int player_id, |
| 83 media::MediaContentType media_content_type) { | 88 media::MediaContentType media_content_type) { |
| 84 if (media_content_type == media::MediaContentType::Uncontrollable) | 89 if (media_content_type == media::MediaContentType::Uncontrollable) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 232 |
| 228 if (audio_focus_state_ != State::SUSPENDED) | 233 if (audio_focus_state_ != State::SUSPENDED) |
| 229 OnSuspendInternal(suspend_type, State::SUSPENDED); | 234 OnSuspendInternal(suspend_type, State::SUSPENDED); |
| 230 | 235 |
| 231 DCHECK(audio_focus_state_ == State::SUSPENDED); | 236 DCHECK(audio_focus_state_ == State::SUSPENDED); |
| 232 players_.clear(); | 237 players_.clear(); |
| 233 | 238 |
| 234 AbandonSystemAudioFocusIfNeeded(); | 239 AbandonSystemAudioFocusIfNeeded(); |
| 235 } | 240 } |
| 236 | 241 |
| 242 void MediaSession::OnMediaSessionEnabledAction( |
| 243 blink::mojom::MediaSessionAction action) { |
| 244 static_cast<WebContentsImpl*>(web_contents()) |
| 245 ->OnMediaSessionEnabledAction(action); |
| 246 } |
| 247 |
| 248 void MediaSession::OnMediaSessionDisabledAction( |
| 249 blink::mojom::MediaSessionAction action) { |
| 250 static_cast<WebContentsImpl*>(web_contents()) |
| 251 ->OnMediaSessionDisabledAction(action); |
| 252 } |
| 253 |
| 254 void MediaSession::DidReceiveAction(blink::mojom::MediaSessionAction action) { |
| 255 if (service_) |
| 256 service_->GetClient()->DidReceiveAction(action); |
| 257 } |
| 258 |
| 237 void MediaSession::StartDucking() { | 259 void MediaSession::StartDucking() { |
| 238 if (is_ducking_) | 260 if (is_ducking_) |
| 239 return; | 261 return; |
| 240 is_ducking_ = true; | 262 is_ducking_ = true; |
| 241 UpdateVolumeMultiplier(); | 263 UpdateVolumeMultiplier(); |
| 242 } | 264 } |
| 243 | 265 |
| 244 void MediaSession::StopDucking() { | 266 void MediaSession::StopDucking() { |
| 245 if (!is_ducking_) | 267 if (!is_ducking_) |
| 246 return; | 268 return; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 it.observer->OnSetVolumeMultiplier(it.player_id, GetVolumeMultiplier()); | 394 it.observer->OnSetVolumeMultiplier(it.player_id, GetVolumeMultiplier()); |
| 373 | 395 |
| 374 UpdateWebContents(); | 396 UpdateWebContents(); |
| 375 } | 397 } |
| 376 | 398 |
| 377 MediaSession::MediaSession(WebContents* web_contents) | 399 MediaSession::MediaSession(WebContents* web_contents) |
| 378 : WebContentsObserver(web_contents), | 400 : WebContentsObserver(web_contents), |
| 379 audio_focus_state_(State::INACTIVE), | 401 audio_focus_state_(State::INACTIVE), |
| 380 audio_focus_type_( | 402 audio_focus_type_( |
| 381 AudioFocusManager::AudioFocusType::GainTransientMayDuck), | 403 AudioFocusManager::AudioFocusType::GainTransientMayDuck), |
| 382 is_ducking_(false) {} | 404 is_ducking_(false), |
| 405 service_(nullptr) {} |
| 383 | 406 |
| 384 void MediaSession::Initialize() { | 407 void MediaSession::Initialize() { |
| 385 delegate_ = AudioFocusDelegate::Create(this); | 408 delegate_ = AudioFocusDelegate::Create(this); |
| 386 } | 409 } |
| 387 | 410 |
| 388 bool MediaSession::RequestSystemAudioFocus( | 411 bool MediaSession::RequestSystemAudioFocus( |
| 389 AudioFocusManager::AudioFocusType audio_focus_type) { | 412 AudioFocusManager::AudioFocusType audio_focus_type) { |
| 390 bool result = delegate_->RequestAudioFocus(audio_focus_type); | 413 bool result = delegate_->RequestAudioFocus(audio_focus_type); |
| 391 uma_helper_.RecordRequestAudioFocusResult(result); | 414 uma_helper_.RecordRequestAudioFocusResult(result); |
| 392 | 415 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 DCHECK(success); | 461 DCHECK(success); |
| 439 | 462 |
| 440 pepper_players_.insert(PlayerIdentifier(observer, player_id)); | 463 pepper_players_.insert(PlayerIdentifier(observer, player_id)); |
| 441 | 464 |
| 442 observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier()); | 465 observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier()); |
| 443 | 466 |
| 444 return true; | 467 return true; |
| 445 } | 468 } |
| 446 | 469 |
| 447 } // namespace content | 470 } // namespace content |
| OLD | NEW |