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 | 11 ++++++++++-
 media/blink/webmediaplayer_impl.h  |  2 ++
 2 files changed, 12 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
@@ -948,6 +948,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());
@@ -3113,7 +3119,10 @@ bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
   // If suspending background video, pause any video that's not remoted or
   // not unlocked to play in the background.
   if (IsBackgroundSuspendEnabled(this)) {
-    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 defined(OS_ANDROID)
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
@@ -141,6 +141,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.11.0

