Skip to content
Permalink
Browse files
Update MediaSessionInfo media elements with a srcObject
https://bugs.webkit.org/show_bug.cgi?id=245753
rdar://problem/100477469

Reviewed by Jer Noble.

The optimization at the top of MediaElementSession::updateMediaUsageIfChanged
does not take into account media elements that have no currentSrc but do
have a srcObject. Don't exit early for such elements.

Store an additional bit of information on MediaSessionInfo to represent whether
the element has any source (currentSrc or srcObject).

* Source/WebCore/html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::hasSource const):
* Source/WebCore/html/MediaElementSession.cpp:
(WebCore::MediaElementSession::updateMediaUsageIfChanged):
* Source/WebCore/platform/graphics/MediaUsageInfo.h:
(WebCore::MediaUsageInfo::operator== const):
(WebCore::MediaUsageInfo::encode const):
(WebCore::MediaUsageInfo::decode):

Canonical link: https://commits.webkit.org/254948@main
  • Loading branch information
heycam committed Sep 28, 2022
1 parent d257ea2 commit 6cfe0a4e9efc3217d24a30f17e312b951695782b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
@@ -623,6 +623,8 @@ class HTMLMediaElement
WEBCORE_EXPORT SpeechSynthesis& speechSynthesis();
#endif

bool hasSource() const { return hasCurrentSrc() || srcObject(); }

protected:
HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
virtual ~HTMLMediaElement();
@@ -1238,10 +1238,10 @@ void MediaElementSession::updateMediaUsageIfChanged()
if (!page || page->sessionID().isEphemeral())
return;

// Bail out early if the currentSrc() is empty, and so was the previous currentSrc(), to
// avoid doing a large amount of unnecessary work below.
auto currentSrc = m_element.currentSrc();
if (currentSrc.isEmpty() && (!m_mediaUsageInfo || m_mediaUsageInfo->mediaURL.isEmpty()))
// Bail out early if the element currently has no source (currentSrc or
// srcObject) and neither did the previous state, to avoid doing a large
// amount of unnecessary work below.
if (!m_element.hasSource() && (!m_mediaUsageInfo || !m_mediaUsageInfo->hasSource))
return;

bool isOutsideOfFullscreen = false;
@@ -1255,7 +1255,8 @@ void MediaElementSession::updateMediaUsageIfChanged()
bool isPlaying = m_element.isPlaying();

MediaUsageInfo usage = {
WTFMove(currentSrc),
m_element.currentSrc(),
m_element.hasSource(),
state() == PlatformMediaSession::Playing,
canShowControlsManager(PlaybackControlsPurpose::ControlsManager),
!page->isVisibleAndActive(),
@@ -33,6 +33,7 @@ namespace WebCore {

struct MediaUsageInfo {
URL mediaURL;
bool hasSource { false };
bool isPlaying { false };
bool canShowControlsManager { false };
bool canShowNowPlayingControls { false };
@@ -70,6 +71,7 @@ struct MediaUsageInfo {
bool operator==(const MediaUsageInfo& other) const
{
return mediaURL == other.mediaURL
&& hasSource == other.hasSource
&& isPlaying == other.isPlaying
&& canShowControlsManager == other.canShowControlsManager
&& canShowNowPlayingControls == other.canShowNowPlayingControls
@@ -118,6 +120,7 @@ struct MediaUsageInfo {
template<class Encoder> inline void MediaUsageInfo::encode(Encoder& encoder) const
{
encoder << mediaURL;
encoder << hasSource;
encoder << isPlaying;
encoder << canShowControlsManager;
encoder << canShowNowPlayingControls;
@@ -160,6 +163,9 @@ template<class Decoder> inline std::optional<MediaUsageInfo> MediaUsageInfo::dec
if (!decoder.decode(info.mediaURL))
return { };

if (!decoder.decode(info.hasSource))
return { };

if (!decoder.decode(info.isPlaying))
return { };

0 comments on commit 6cfe0a4

Please sign in to comment.