Skip to content

Commit

Permalink
[sailfishos][media] Ensure audio continues when screen is locked. Fix…
Browse files Browse the repository at this point in the history
…es JB#51747

This rationalises two previous commits from sailfishos-esr52,
integrating the functionality of the NemoResourceHandler class into
MediaDecoder.

This is needed so that the "media-decoder-info" notifications are sent
out when certain types of media are started/stopped and to signal
whether the media contains audio and/or video.

An additional change ensures media is started/stopped with the
Thaw/Freeze of docuemnts (switching the check from visible status to
hidden status).

The previous relevant commits:-

commit 9e2dc6c
Author: Oleg <romaxa@gmail.com>
Date:   Thu Oct 30 23:54:05 2014 -0700

    [sailfishos][media] Add NemoResourceHandler

    Original SHA1: b318b3c

    Signed-off-by: Raine Makelainen <raine.makelainen@jolla.com>

commit 50fc4fa
Author: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Date:   Thu Nov 29 17:20:06 2018 +1000

    [sailfishos][media] Update media resource state when the playing
state changes for any reason. Fixes JB#42900
  • Loading branch information
llewelld committed Nov 3, 2020
1 parent 3c06a99 commit 36518d5
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
125 changes: 125 additions & 0 deletions rpm/0045-sailfishos-media-Ensure-audio-continues-when-screen-.patch
@@ -0,0 +1,125 @@
From 234f3bce084b90dc233afd8bdc3e003135ed06ea Mon Sep 17 00:00:00 2001
From: David Llewellyn-Jones <david.llewellyn-jones@jolla.com>
Date: Thu, 29 Oct 2020 15:20:18 +0200
Subject: [PATCH] [sailfishos][media] Ensure audio continues when screen is
locked. Contributes to JB#51747

This rationalises two previous commits from sailfishos-esr52,
integrating the functionality of the NemoResourceHandler class into
MediaDecoder.

This is needed so that the "media-decoder-info" notifications are sent
out when certain types of media are started/stopped and to signal
whether the media contains audio and/or video.

An additional change ensures media is started/stopped with the
Thaw/Freeze of docuemnts (switching the check from visible status to
hidden status).

The previous relevant commits:-

commit 9e2dc6c89b83a623ad27ac14edc501585ef8ecd9
Author: Oleg <romaxa@gmail.com>
Date: Thu Oct 30 23:54:05 2014 -0700

[sailfishos][media] Add NemoResourceHandler

Original SHA1: b318b3c9f723544c32895a8a4c49d7f44b6752be

Signed-off-by: Raine Makelainen <raine.makelainen@jolla.com>

commit 50fc4fac5ed1433acb0dff6e23dc3055f76c3226
Author: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Date: Thu Nov 29 17:20:06 2018 +1000

[sailfishos][media] Update media resource state when the playing
state changes for any reason. Fixes JB#42900
---
dom/html/HTMLMediaElement.cpp | 4 ++--
dom/media/MediaDecoder.cpp | 27 +++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index ce5decf5c073..a6dfb1eca5ac 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -6046,7 +6046,7 @@ void HTMLMediaElement::NotifyOwnerDocumentActivityChanged() {
}

bool pauseElement = ShouldElementBePaused();
- SuspendOrResumeElement(pauseElement, !IsActive());
+ SuspendOrResumeElement(pauseElement, IsHidden());

// If the owning document has become inactive we should shutdown the CDM.
if (!OwnerDoc()->IsCurrentActiveDocument() && mMediaKeys) {
@@ -6869,7 +6869,7 @@ void HTMLMediaElement::NotifyAudioPlaybackChanged(

bool HTMLMediaElement::ShouldElementBePaused() {
// Bfcached page or inactive document.
- if (!IsActive()) {
+ if (IsHidden()) {
return true;
}

diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp
index 9cc84e1e371b..8b1c9603c1d8 100644
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -29,6 +29,10 @@
#include "nsIObserver.h"
#include "nsPrintfCString.h"
#include "nsTArray.h"
+#include "nsThreadUtils.h"
+#include "mozilla/Services.h"
+#include "nsIObserverService.h"
+#include "nsString.h"
#include <algorithm>
#include <limits>

@@ -77,6 +81,14 @@ static const char* ToPlayStateStr(MediaDecoder::PlayState aState) {
return "UNKNOWN";
}

+static void SendMediaDecoderInfo(const nsString& aData) {
+ MOZ_ASSERT(NS_IsMainThread());
+ nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+ if (obs) {
+ obs->NotifyObservers(nullptr, "media-decoder-info", aData.get());
+ }
+}
+
class MediaMemoryTracker : public nsIMemoryReporter {
virtual ~MediaMemoryTracker();

@@ -564,6 +576,11 @@ void MediaDecoder::MetadataLoaded(
aInfo->mAudio.mChannels, aInfo->mAudio.mRate, aInfo->HasAudio(),
aInfo->HasVideo());

+ nsString data;
+ data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"meta\", \"a\" : %i, \"v\" : %i }",
+ this, aInfo->HasAudio(), aInfo->HasVideo());
+ SendMediaDecoderInfo(data);
+
mMediaSeekable = aInfo->mMediaSeekable;
mMediaSeekableOnlyInBufferedRanges =
aInfo->mMediaSeekableOnlyInBufferedRanges;
@@ -754,6 +771,16 @@ void MediaDecoder::ChangeState(PlayState aState) {
MOZ_ASSERT(!IsShutdown(), "SHUTDOWN is the final state.");
AbstractThread::AutoEnter context(AbstractMainThread());

+ if (mPlayState != aState) {
+ nsString data;
+ if (aState == PLAY_STATE_PLAYING) {
+ data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"play\" }", this);
+ } else {
+ data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"pause\" }", this);
+ }
+ SendMediaDecoderInfo(data);
+ }
+
if (mNextState == aState) {
mNextState = PLAY_STATE_PAUSED;
}
--
2.26.2

1 change: 1 addition & 0 deletions rpm/xulrunner-qt5.spec
Expand Up @@ -87,6 +87,7 @@ Patch41: 0041-sailfishos-gecko-Include-XUL-videocontrols-reflow-co.patch
Patch42: 0042-sailfishos-gecko-Adjust-audio-control-dimensions.-Co.patch
Patch43: 0043-sailfishos-gecko-Prioritize-loading-of-extension-ver.patch
Patch44: 0044-sailfishos-gecko-Apply-UA-override-for-window.naviga.patch
Patch45: 0045-sailfishos-media-Ensure-audio-continues-when-screen-.patch

BuildRequires: rust
BuildRequires: rust-std-static
Expand Down

0 comments on commit 36518d5

Please sign in to comment.