Skip to content

Commit

Permalink
REGRESSION (271514@main): MSE Live playback fails on umediaserver.net
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266385
rdar://119615258

Reviewed by Jer Noble.

Changes in 271514@main exposed an underlying existing issue. The MediaSource's duration was initialised to NaN
but the GPU process one was initialised to 0. Following 271514@main the inital value would be identical.

If the media source duration was set prior any sourcebuffer being created, we wouldn't set the SourceBuffer
initial duration, and the step `If the media segment contains data beyond the current duration, then run the duration change algorithm with new duration set to the maximum of the current duration and the [[group end timestamp]].`
would always be skipped.

We set the initial duration to the sourceBuffer when created.

Add tests.

* LayoutTests/media/media-source/media-source-append-buffer-durationchange-expected.txt: Added.
* LayoutTests/media/media-source/media-source-append-buffer-durationchange.html: Added.
* Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
(WebCore::MediaSourcePrivateAVFObjC::addSourceBuffer):
* Source/WebCore/platform/graphics/gstreamer/mse/MediaSourcePrivateGStreamer.cpp:
(WebCore::MediaSourcePrivateGStreamer::addSourceBuffer):
* Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp:
(WebCore::MockMediaSourcePrivate::addSourceBuffer):

Canonical link: https://commits.webkit.org/272025@main
  • Loading branch information
jyavenard committed Dec 14, 2023
1 parent c68a38f commit 9f3ddc1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

RUN(video.src = URL.createObjectURL(source))
EVENT(sourceopen)
RUN(source.duration = 0)
RUN(sourceBuffer = source.addSourceBuffer("video/mock; codecs=mock"))
RUN(sourceBuffer.appendBuffer(initSegment))
EXPECTED (sourceBuffer.updating == 'true') OK
EVENT(updateend)
EXPECTED (source.duration == '0') OK
EXPECTED (sourceBuffer.updating == 'false') OK
RUN(sourceBuffer.appendBuffer(mediaSegment))
EVENT(durationchange)
EVENT(updateend)
EXPECTED (source.duration == '16') OK
END OF TEST

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<title>mock-media-source</title>
<script src="mock-media-source.js"></script>
<script src="../video-test.js"></script>
<script>
var source;
var sourceBuffer;
var initSegment;
var mediaSegment;

if (window.internals)
internals.initializeMockMediaSource();

function runTest() {
findMediaElement();

source = new MediaSource();
waitForEventOn(source, 'sourceopen', sourceOpen);
run('video.src = URL.createObjectURL(source)');
}

async function sourceOpen() {
run('source.duration = 0');
run('sourceBuffer = source.addSourceBuffer("video/mock; codecs=mock")');

initSegment = makeAInit(100, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]);
run('sourceBuffer.appendBuffer(initSegment)');
testExpected('sourceBuffer.updating', true);
await Promise.all([ waitForEvent(sourceBuffer, 'update'), waitFor(sourceBuffer, 'updateend') ]);
testExpected('source.duration', 0);
testExpected('sourceBuffer.updating', false);
mediaSegment = concatenateSamples([
makeASample(0, 0, 1, 1, 1, SAMPLE_FLAG.SYNC, 0)
, makeASample(1, 1, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(2, 2, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(3, 3, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(4, 4, 1, 1, 1, SAMPLE_FLAG.SYNC, 0)
, makeASample(5, 5, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(6, 6, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(7, 7, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(8, 8, 1, 1, 1, SAMPLE_FLAG.SYNC, 0)
, makeASample(9, 9, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(10, 10, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(11, 11, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(12, 12, 1, 1, 1, SAMPLE_FLAG.SYNC, 0)
, makeASample(13, 13, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(14, 14, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
, makeASample(15, 15, 1, 1, 1, SAMPLE_FLAG.NONE, 0)
]);
run('sourceBuffer.appendBuffer(mediaSegment)');
await Promise.all([ waitForEvent(sourceBuffer, 'update'), waitFor(sourceBuffer, 'updateend'), waitFor(video, 'durationchange') ]);
testExpected('source.duration', 16);
endTest();
}

</script>
</head>
<body onload="runTest()">
<video></video>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
newSourceBuffer->setCDMInstance(m_cdmInstance.get());
#endif
outPrivate = newSourceBuffer.copyRef();
newSourceBuffer->setMediaSourceDuration(duration());
m_sourceBuffers.append(WTFMove(newSourceBuffer));

return AddStatus::Ok;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ MediaSourcePrivateGStreamer::AddStatus MediaSourcePrivateGStreamer::addSourceBuf

m_sourceBuffers.append(SourceBufferPrivateGStreamer::create(*this, contentType, m_playerPrivate));
sourceBufferPrivate = m_sourceBuffers.last();
sourceBufferPrivate->setMediaSourceDuration(duration());
return MediaSourcePrivateGStreamer::AddStatus::Ok;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ MediaSourcePrivate::AddStatus MockMediaSourcePrivate::addSourceBuffer(const Cont

m_sourceBuffers.append(MockSourceBufferPrivate::create(*this));
outPrivate = m_sourceBuffers.last();
outPrivate->setMediaSourceDuration(duration());

return AddStatus::Ok;
}
Expand Down

0 comments on commit 9f3ddc1

Please sign in to comment.