Skip to content

Commit

Permalink
v109 Allow playing audio in background
Browse files Browse the repository at this point in the history
  • Loading branch information
uazo committed Jan 6, 2023
1 parent 029f26f commit 0e90d1a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions build/patches/Allow-playing-audio-in-background.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Subject: Allow playing audio in background

License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
.../renderer/platform/media/web_media_player_impl.cc | 12 +++++++++++-
.../renderer/platform/media/web_media_player_impl.h | 3 +++
2 files changed, 14 insertions(+), 1 deletion(-)
.../renderer/platform/media/web_media_player_impl.cc | 11 ++++++++++-
.../renderer/platform/media/web_media_player_impl.h | 3 +++
2 files changed, 13 insertions(+), 1 deletion(-)

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
@@ -1226,6 +1226,12 @@ bool WebMediaPlayerImpl::HasAudio() const {
@@ -1237,6 +1237,12 @@ bool WebMediaPlayerImpl::HasAudio() const {
return pipeline_metadata_.has_audio;
}

Expand All @@ -24,23 +24,22 @@ diff --git a/third_party/blink/renderer/platform/media/web_media_player_impl.cc
void WebMediaPlayerImpl::EnabledAudioTracksChanged(
const WebVector<WebMediaPlayer::TrackId>& enabledTrackIds) {
DCHECK(main_task_runner_->BelongsToCurrentThread());
@@ -3627,7 +3633,11 @@ bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const {
@@ -3662,7 +3668,10 @@ bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const {
: HasAudio();

// Audio only stream is allowed to play when in background.
// TODO: We should check IsBackgroundOptimizationCandidate here. But we need
// to move the logic of checking video frames out of that function.
- if (!HasVideo())
+
- 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())
+ if (!HasVideoNonEmptySize() && preserve_audio)
return false;

if (using_media_player_renderer_ &&
// MediaPlayer always signals audio and video, so use an empty natural size to
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
@@ -195,6 +195,9 @@ class PLATFORM_EXPORT WebMediaPlayerImpl
@@ -197,6 +197,9 @@ class PLATFORM_EXPORT WebMediaPlayerImpl
bool HasVideo() const override;
bool HasAudio() const override;

Expand Down

0 comments on commit 0e90d1a

Please sign in to comment.