Skip to content

Commit

Permalink
WebCodecsVideoFrame::create from another WebCodecsVideoFrame is not c…
Browse files Browse the repository at this point in the history
…orrect with regards to timestamp

rdar://127474678
https://bugs.webkit.org/show_bug.cgi?id=273775

Reviewed by Jean-Yves Avenard.

Make sure to clone in case of a different timestamp to keep WebCodecsVideoFrame and VideoFrame timestamps the same.

* LayoutTests/http/wpt/webcodecs/videoFrame-clone-timestamp-expected.txt: Added.
* LayoutTests/http/wpt/webcodecs/videoFrame-clone-timestamp.html: Added.
* Source/WebCore/Modules/webcodecs/WebCodecsVideoFrame.cpp:
(WebCore::WebCodecsVideoFrame::create):

Canonical link: https://commits.webkit.org/278454@main
  • Loading branch information
youennf committed May 7, 2024
1 parent 3121737 commit bbf537e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS VideoFrame timestamp should remain consistent when serialized

34 changes: 34 additions & 0 deletions LayoutTests/http/wpt/webcodecs/videoFrame-clone-timestamp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<header>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</header>
<body>
<script>

function makeOffscreenCanvas(width, height, timestamp) {
let canvas = new OffscreenCanvas(width, height);
let ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgba(50, 100, 150, 255)';
ctx.fillRect(0, 0, width, height);
return new VideoFrame(canvas, { timestamp, duration : 10 });
}

promise_test(async t => {
const frame1 = makeOffscreenCanvas(10, 10, 10);
t.add_cleanup(() => frame1.close());

const frame2 = new VideoFrame(frame1, { timestamp: 100 });
t.add_cleanup(() => frame2.close());

const frame3 = new VideoFrame(frame1);
t.add_cleanup(() => frame3.close());

assert_equals(frame1.timestamp, 10);
assert_equals(frame2.timestamp, 100);
assert_equals(frame3.timestamp, 10);
}, "VideoFrame timestamp should remain consistent when serialized");
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/webcodecs/WebCodecsVideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ ExceptionOr<Ref<WebCodecsVideoFrame>> WebCodecsVideoFrame::create(ScriptExecutio
{
if (initFrame->isDetached())
return Exception { ExceptionCode::InvalidStateError, "VideoFrame is detached"_s };
return initializeFrameFromOtherFrame(context, WTFMove(initFrame), WTFMove(init), VideoFrame::ShouldCloneWithDifferentTimestamp::No);
return initializeFrameFromOtherFrame(context, WTFMove(initFrame), WTFMove(init), VideoFrame::ShouldCloneWithDifferentTimestamp::Yes);
}

static std::optional<Exception> validateI420Sizes(const WebCodecsVideoFrame::BufferInit& init)
Expand Down

0 comments on commit bbf537e

Please sign in to comment.