65 lines
3.0 KiB
Diff
65 lines
3.0 KiB
Diff
From: AlexeyBarabash <alexey@brave.com>
|
|
Date: Thu, 2 Nov 2017 18:21:16 +0200
|
|
Subject: Allow playing audio in background
|
|
|
|
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
|
---
|
|
.../renderer/render_frame_media_playback_options.cc | 1 +
|
|
.../renderer/platform/media/web_media_player_impl.cc | 11 ++++++++++-
|
|
.../renderer/platform/media/web_media_player_impl.h | 3 +++
|
|
3 files changed, 14 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/content/public/renderer/render_frame_media_playback_options.cc b/content/public/renderer/render_frame_media_playback_options.cc
|
|
--- a/content/public/renderer/render_frame_media_playback_options.cc
|
|
+++ b/content/public/renderer/render_frame_media_playback_options.cc
|
|
@@ -14,6 +14,7 @@
|
|
|
|
namespace content {
|
|
bool IsBackgroundMediaSuspendEnabled() {
|
|
+ if ((true)) return false;
|
|
#if BUILDFLAG(IS_ANDROID)
|
|
// For Android devices, do not suspend background media for devices with large
|
|
// displays. Exception is for Webview.
|
|
diff --git a/third_party/blink/renderer/platform/media/web_media_player_impl.cc b/third_party/blink/renderer/platform/media/web_media_player_impl.cc
|
|
--- a/third_party/blink/renderer/platform/media/web_media_player_impl.cc
|
|
+++ b/third_party/blink/renderer/platform/media/web_media_player_impl.cc
|
|
@@ -1348,6 +1348,12 @@ bool WebMediaPlayerImpl::HasAudio() const {
|
|
return pipeline_metadata_.has_audio;
|
|
}
|
|
|
|
+bool WebMediaPlayerImpl::HasVideoNonEmptySize() const {
|
|
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
|
|
+
|
|
+ return pipeline_metadata_.has_video && pipeline_metadata_.natural_size.width() != 0 && pipeline_metadata_.natural_size.height() != 0;
|
|
+}
|
|
+
|
|
void WebMediaPlayerImpl::EnabledAudioTracksChanged(
|
|
std::optional<WebMediaPlayer::TrackId> enabled_track_id) {
|
|
DCHECK(main_task_runner_->BelongsToCurrentThread());
|
|
@@ -3745,7 +3751,10 @@ bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const {
|
|
|
|
const bool preserve_audio = HasUnmutedAudio() || audio_source_provider_->IsAudioBeingCaptured();
|
|
// Audio only stream is allowed to play when in background.
|
|
- if (!HasVideo() && preserve_audio)
|
|
+ //pipeline_metadata_.has_video is true for MediaPlayerRenderer,
|
|
+ //see media/base/pipeline_metadata.h. This is a workaround to allow audio
|
|
+ //streams be played in background.
|
|
+ if (!HasVideoNonEmptySize() && preserve_audio)
|
|
return false;
|
|
|
|
// Video PiP is the only exception when background video playback is disabled.
|
|
diff --git a/third_party/blink/renderer/platform/media/web_media_player_impl.h b/third_party/blink/renderer/platform/media/web_media_player_impl.h
|
|
--- a/third_party/blink/renderer/platform/media/web_media_player_impl.h
|
|
+++ b/third_party/blink/renderer/platform/media/web_media_player_impl.h
|
|
@@ -214,6 +214,9 @@ class PLATFORM_EXPORT WebMediaPlayerImpl
|
|
bool HasVideo() const override;
|
|
bool HasAudio() const override;
|
|
|
|
+ // True is has video and it's frame size is not zero
|
|
+ bool HasVideoNonEmptySize() const;
|
|
+
|
|
void EnabledAudioTracksChanged(
|
|
std::optional<WebMediaPlayer::TrackId> enabled_track_id) override;
|
|
void SelectedVideoTrackChanged(
|
|
--
|