Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: cab391584f801d18cde18093204d9b980964ca80
https://github.com/WebKit/WebKit/commit/cab391584f801d18cde18093204d9b980964ca80
Author: Jean-Yves Avenard <[email protected]>
Date: 2026-08-26 (Wed, 26 Aug 2026)
Changed paths:
A
LayoutTests/media/media-source/media-managedmse-no-streaming-toggle-at-end-expected.txt
A
LayoutTests/media/media-source/media-managedmse-no-streaming-toggle-at-end.html
M Source/WebCore/Modules/mediasource/ManagedMediaSource.cpp
M Source/WebCore/html/HTMLMediaElement.cpp
M Source/WebKit/NetworkProcess/NetworkProcess.cpp
M Source/WebKit/NetworkProcess/NetworkProcess.h
Log Message:
-----------
[MSE] Seeking to the end of a HTMLMediaElement backed by a MediaSource will
unnecessarily fire an ended event
https://bugs.webkit.org/show_bug.cgi?id=322488
rdar://185145277
Reviewed by Jer Noble.
When a player seeked to a MediaSource video's duration in repetition, the
`ended` event would have been fired
again even if it had been fired before and currentTime didn't change.
That's because while HTMLMediaElement::seekTask has a shortcut to detect a seek
to the same currentTime
and just fire the `seeked` event, when a MediaSource is in use this shortcut is
bypassed
and so we start a fullseek.
When timechanged is called again by the MediaPlayer, we compare the currentTime
with the duration
and if equal we fired the `ended` event.
Additionally, with ManagedMediaSource, following 312694@main , we call
MediaSource::monitorSourceBuffers()
again, which at the start of a seek cause the ManagedMedaSource.streaming
attribute to become true
and at the end to be false, and so startstreaming/endstreaming would have too
been fired.
Any calls to monitorSourceBuffers() at end-of-stream would have produced that
pair of events to be fired
(312694@main only made it obvious)
We now add an early exit in ManagedMedaSource::monitorSourceBuffers() if the
MediaSource is ended and
currentTime >= duration, we call setStreaming(false) and return. Nothing will
call setStreaming(true)
again.
To prevent the redundant, and incorrect ended event, we only clear
m_sentEndEvent if the MediaSource
isn't ended and we aren't seeking to duration()
Fly-by: we limit the system notifications about streaming activity to once per
10s only.
- First call ever (m_notifiedMediaStreamingActivity unset) posts immediately
— no startup delay.
- A call matching the currently published state clears any pending change and
returns; nothing is posted.
- A change within 10s of the last post is stored in
m_pendingMediaStreamingActivity and a single dispatchAfter is armed for the
remainder of the window.
Further toggles overwrite the pending value without arming more work.
- When the window closes, the flush re-enters notifyMediaStreamingActivity
with the pending value, which then either posts it or drops it if it equals
what's already published.
Test added: media/media-source/media-managedmse-no-streaming-toggle-at-end.html
*
LayoutTests/media/media-source/media-managedmse-no-streaming-toggle-at-end-expected.txt:
Added.
*
LayoutTests/media/media-source/media-managedmse-no-streaming-toggle-at-end.html:
Added.
* Source/WebCore/Modules/mediasource/ManagedMediaSource.cpp:
(WebCore::ManagedMediaSource::monitorSourceBuffers):
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::seekTask):
* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::notifyMediaStreamingActivity):
* Source/WebKit/NetworkProcess/NetworkProcess.h:
Canonical link: https://commits.webkit.org/319847@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications