Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 13a26d1f906516826613902bd3813f867553644b
https://github.com/WebKit/WebKit/commit/13a26d1f906516826613902bd3813f867553644b
Author: Enrique Ocaña González <[email protected]>
Date: 2026-02-12 (Thu, 12 Feb 2026)
Changed paths:
A
LayoutTests/media/media-source/media-source-samples-out-of-order-erase-last-previous-frames-expected.txt
A
LayoutTests/media/media-source/media-source-samples-out-of-order-erase-last-previous-frames.html
M Source/WebCore/platform/graphics/SourceBufferPrivate.cpp
Log Message:
-----------
[MSE] Fix sample DTS to prevent deletion of preexisting samples when PTS
doesn't conflict
https://bugs.webkit.org/show_bug.cgi?id=305208
Reviewed by Alicia Boya Garcia.
Let's consider a preexisting samples A, B, C, and a new sample N with the
following timestamps:
Decoding time Presentation time
------------- -----------------
Sample A: 827.826164000 827.826164000
Sample B: 827.826164100 827.826164100
Sample C: 827.826164200 827.826164200
Sample N: 827.826125000 827.909542000
These disparities in DTS vs. PTS offsets between samples A and B exist
because both samples come from completely different videos (eg: because
of ad insertion).
In a timeline:
DTS ···NABC·······
PTS ····ABC···N···
Judging by PTS, the samples A, B, C should remain and theoretically don't
need to be erased. However, considering DTS, the samples A, B, C have to
be erased, because the sample N would reach the video decoder earlier (by
decoding ordering) and change the state of the decoder, making it
unsuitable for samples A, B, C.
This commit tries to fix the situation by changing sample N (the new
sample) DTS to a value slightly higher than sample C DTS (that is, DTS plus
epsilon, a small value), like this:
Decoding time Presentation time
------------- -----------------
Sample A: 827.826164000 827.826164000
Sample B: 827.826164100 827.826164100
Sample C: 827.826164200 827.826164200
Sample N: *827.826164201* 827.909542000
DTS ····ABCN······
PTS ····ABC···N···
This fix avoids the deletion of samples A, B, C and the potential
problems associated with that.
A layout test has been added to show the problem and prove that the fix
solves it.
*
LayoutTests/media/media-source/media-source-samples-out-of-order-erase-last-previous-frames-expected.txt:
Added.
*
LayoutTests/media/media-source/media-source-samples-out-of-order-erase-last-previous-frames.html:
Added.
* Source/WebCore/platform/graphics/SourceBufferPrivate.cpp:
(WebCore::SourceBufferPrivate::processMediaSample): If a new sync sample is
being added and there are next samples in decode order with PTS lower than the
one of the new sample, fix the DTS of the new sample by assigning it to have a
safeDecodeTime (the DTS of the highest (by DTS order) preexisting sample, plus
epsilon), but only if that DTS wouldn't be higher than the DTS of the next
sample that should come after the new sample being added (estimated as
sample.decodeTime() + 2*duration, and keeping a safety margin).
Canonical link: https://commits.webkit.org/307359@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications