Bug 180197 - [GStreamer] Ensure SleepDisabler is not held by pages in page cache
Summary: [GStreamer] Ensure SleepDisabler is not held by pages in page cache
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: Other
Hardware: PC Linux
: P2 Normal
Assignee: Philippe Normand
URL:
Keywords: InRadar
Depends on:
Blocks: 181432 181471
  Show dependency treegraph
 
Reported: 2017-11-30 07:20 PST by Michael Catanzaro
Modified: 2018-01-22 07:20 PST (History)
7 users (show)

See Also:


Attachments
Patch (11.46 KB, patch)
2018-01-09 04:47 PST, Philippe Normand
no flags Details | Formatted Diff | Diff
Patch (2.29 KB, patch)
2018-01-09 05:09 PST, Philippe Normand
eric.carlson: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2017-11-30 07:20:34 PST
After implementing PAL::SleepDisabler for GTK in bug #178485, I decided to try removing the early return at the top of HTMLMediaElement::shouldDisableSleep for non-Cocoa ports, hoping that HTMLMediaElement would create a SleepDisabler during video playback and destroy it at the end of video playback, to keep the display from turning off when a video is playing. I tested it on youtube.com and noticed the following unexpected behavior:

 (1) When playing a video on YouTube, no SleepDisabler is initially created during normal video playback, so the display will turn off undesirably.
 (2) But a SleepDisabler *is* created when pressing the browser's Back button during video playback.
 (3) The SleepDisabler is then only destroyed when (a) closing the browser tab that had been displaying YouTube, or (b) when pressing Forward to bring back the original YouTube page.

So I think monitor sleep is disabled when the YouTube page is in the page cache, and not reenabled until the page exits the page cache. That's not good! I wonder if this is a GTK-specific problem, or if it's also broken on macOS and iOS.
Comment 1 youenn fablet 2017-12-12 18:20:20 PST
> So I think monitor sleep is disabled when the YouTube page is in the page
> cache, and not reenabled until the page exits the page cache. That's not
> good! I wonder if this is a GTK-specific problem, or if it's also broken on
> macOS and iOS.

This works as expected in macOS and iOS for YouTube so there might be something specific to GTK.
Maybe some debugging would help here to know why there is no SleepDisabler in the first place when clicking play/pause...
Comment 2 Philippe Normand 2018-01-09 02:50:44 PST
Michael can you upload your patch? Did you implement MediaPlayerPrivate::setShouldDisableSleep() too?
Comment 3 Philippe Normand 2018-01-09 03:31:41 PST
The problem seems to be with that line for the GStreamer ports:

bool shouldBeAbleToSleep = !hasVideo() || !hasAudio();

the value is true, so that's why no sleep disabler is created. This is likely an issue with the GStreamer backend. I suspect the pipeline is not fully built when this code is called.
Comment 4 Philippe Normand 2018-01-09 04:47:05 PST
Created attachment 330811 [details]
Patch
Comment 5 Carlos Garcia Campos 2018-01-09 04:58:06 PST
Comment on attachment 330811 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330811&action=review

> Source/WebCore/ChangeLog:13
> +        The sleep disabler is now checked again whenever the media player
> +        playback state or other charasteristic has changed in the media
> +        engine. On GStreamer backend side we now properly emit playback
> +        state changes and characteristic updates to the client when the
> +        pipeline state changes and when audio/video tracks changes are
> +        detected.

The GST part is related but independent, right? I would split the patch.
Comment 6 Philippe Normand 2018-01-09 05:09:40 PST
Created attachment 330812 [details]
Patch
Comment 7 Philippe Normand 2018-01-09 05:57:41 PST
Hi Eric, can you please review this patch?
Comment 8 Philippe Normand 2018-01-09 06:44:31 PST
Committed r226630: <https://trac.webkit.org/changeset/226630>
Comment 9 Radar WebKit Bug Importer 2018-01-09 06:46:20 PST
<rdar://problem/36374983>
Comment 10 Michael Catanzaro 2018-01-09 08:04:30 PST
Note this change does more than indicated by the commit message: media playback now (hopefully) causes sleep to be disabled for the first time. That is great! Thanks!
Comment 11 Michael Catanzaro 2018-01-22 07:20:06 PST
This has uncovered a bug in GNOME: https://bugzilla.gnome.org/show_bug.cgi?id=705942#c12

WebKit is now doing the right thing, so I don't suggest we change anything.