bromite/build/patches/Allow-playing-audio-in-background.patch
2021-01-26 01:12:38 +01:00

53 lines
2.1 KiB
Diff

From: AlexeyBarabash <alexey@brave.com>
Date: Thu, 2 Nov 2017 18:21:16 +0200
Subject: Allow playing audio in background
---
media/blink/webmediaplayer_impl.cc | 12 +++++++++++-
media/blink/webmediaplayer_impl.h | 2 ++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -1096,6 +1096,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(
const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds) {
DCHECK(main_task_runner_->BelongsToCurrentThread());
@@ -3548,7 +3554,11 @@ bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const {
// 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())
+
+ //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())
return false;
if (using_media_player_renderer_ &&
diff --git a/media/blink/webmediaplayer_impl.h b/media/blink/webmediaplayer_impl.h
--- a/media/blink/webmediaplayer_impl.h
+++ b/media/blink/webmediaplayer_impl.h
@@ -155,6 +155,8 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// True if the loaded media has a playable video/audio track.
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(
const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds)
--
2.17.1