Commit 9ab27c48 authored by Chris Cunningham's avatar Chris Cunningham Committed by moz-wptsync-bot
Browse files

Bug 1721762 [wpt PR 29742] - Mostly fix VideoFrame construction / copyTo w/...

Bug 1721762 [wpt PR 29742] - Mostly fix VideoFrame construction / copyTo w/ SharedArrayBuffer, a=testonly

Automatic update from web-platform-tests
Mostly fix VideoFrame construction / copyTo w/ SharedArrayBuffer

This doesn't allow for direct use of SharedArrayBuffer, but users may
instead use ArrayBufferViews (e.g. Uint8Arrays) backed by a
SharedArrayBuffer (which most would probably have done anyway).

The proper fixed is blocked on https://crbug.com/1088107

Bug: 1231806, 1088107

Change-Id: I806bf8051b9e535dfc6be7f214a1a8f2f16ce798
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3044523


Auto-Submit: Chrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#904632}

--

wpt-commits: c7e97b04c736e1bfb1ad45642b06f1800a98a672
wpt-pr: 29742
parent 9b2d9e38
Loading
Loading
Loading
Loading
+6 −34
Original line number Diff line number Diff line
// META: global=window,dedicatedworker
// META: script=/webcodecs/utils.js
// META: script=/webcodecs/videoFrame-utils.js

test(t => {
  let image = makeImageBitmap(32, 16);
@@ -152,41 +153,12 @@ test(t => {
}, 'Test invalid buffer constructed VideoFrames');

test(t => {
  let fmt = 'I420';
  let vfInit = {format: fmt, timestamp: 1234, codedWidth: 4, codedHeight: 2};
  let data = new Uint8Array([
    1, 2, 3, 4, 5, 6, 7, 8,  // y
    1, 2,                    // u
    1, 2,                    // v
  ]);
  let frame = new VideoFrame(data, vfInit);
  assert_equals(frame.format, fmt, 'plane format');
  assert_equals(frame.colorSpace.primaries, 'bt709', 'color primaries');
  assert_equals(frame.colorSpace.transfer, 'bt709', 'color transfer');
  assert_equals(frame.colorSpace.matrix, 'bt709', 'color matrix');
  assert_false(frame.colorSpace.fullRange, 'color range');
  frame.close();
  testBufferConstructedI420Frame('Uint8Array(ArrayBuffer)');
}, 'Test Uint8Array(ArrayBuffer) constructed I420 VideoFrame');

  let y = {offset: 0, stride: 4};
  let u = {offset: 8, stride: 2};
  let v = {offset: 10, stride: 2};

  assert_throws_js(TypeError, () => {
    let y = {offset: 0, stride: 1};
    let frame = new VideoFrame(data, {...vfInit, layout: [y, u, v]});
  }, 'y stride too small');
  assert_throws_js(TypeError, () => {
    let u = {offset: 8, stride: 1};
    let frame = new VideoFrame(data, {...vfInit, layout: [y, u, v]});
  }, 'u stride too small');
  assert_throws_js(TypeError, () => {
    let v = {offset: 10, stride: 1};
    let frame = new VideoFrame(data, {...vfInit, layout: [y, u, v]});
  }, 'v stride too small');
  assert_throws_js(TypeError, () => {
    let frame = new VideoFrame(data.slice(0, 8), vfInit);
  }, 'data too small');
}, 'Test buffer constructed I420 VideoFrame');
test(t => {
  testBufferConstructedI420Frame('ArrayBuffer');
}, 'Test ArrayBuffer constructed I420 VideoFrame');

test(t => {
  let fmt = 'I420';
+12 −0
Original line number Diff line number Diff line
// META: global=window,dedicatedworker
// META: script=/webcodecs/utils.js
// META: script=/webcodecs/videoFrame-utils.js

// TODO(crbug.com/1231806): Enable this test once direct SAB usage is supported.
// test(t => {
//   testBufferConstructedI420Frame('SharedArrayBuffer');
// }, 'Test SharedArrayBuffer constructed I420 VideoFrame');

test(t => {
  testBufferConstructedI420Frame('Uint8Array(SharedArrayBuffer)');
}, 'Test Uint8Array(SharedArrayBuffer) constructed I420 VideoFrame');
+3 −0
Original line number Diff line number Diff line
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
+9 −52
Original line number Diff line number Diff line
// META: global=window,dedicatedworker

function makeI420_4x2() {
  const data = new Uint8Array([
      1, 2, 3, 4,  // y
      5, 6, 7, 8,
      9, 10,       // u
      11, 12,      // v
  ]);
  const init = {
      format: 'I420',
      timestamp: 0,
      codedWidth: 4,
      codedHeight: 2,
  };
  return new VideoFrame(data, init);
}
// META: script=/webcodecs/videoFrame-utils.js

function makeRGBA_2x2() {
  const data = new Uint8Array([
@@ -30,24 +15,6 @@ function makeRGBA_2x2() {
  return new VideoFrame(data, init);
}

function assert_buffer_equals(actual, expected) {
  assert_true(actual instanceof Uint8Array, 'actual instanceof Uint8Array');
  assert_true(expected instanceof Uint8Array, 'buffer instanceof Uint8Array');
  assert_equals(actual.length, expected.length, 'buffer length');
  for (let i = 0; i < actual.length; i++) {
    if (actual[i] != expected[i]) {
      assert_equals(actual[i], expected[i], 'buffer contents at index ' + i);
    }
  }
}

function assert_layout_equals(actual, expected) {
  assert_equals(actual.length, expected.length, 'layout planes');
  for (let i = 0; i < actual.length; i++) {
    assert_object_equals(actual[i], expected[i], 'plane ' + i + ' layout');
  }
}

promise_test(async t => {
  const frame = makeI420_4x2();
  frame.close();
@@ -59,24 +26,14 @@ promise_test(async t => {
}, 'Test closed frame.');

promise_test(async t => {
  const frame = makeI420_4x2();
  const expectedLayout = [
      {offset: 0, stride: 4},
      {offset: 8, stride: 2},
      {offset: 10, stride: 2},
  ];
  const expectedData = new Uint8Array([
      1, 2, 3, 4,  // y
      5, 6, 7, 8,
      9, 10,       // u
      11, 12       // v
  ]);
  assert_equals(frame.allocationSize(), expectedData.length, 'allocationSize()');
  const data = new Uint8Array(expectedData.length);
  const layout = await frame.copyTo(data);
  assert_layout_equals(layout, expectedLayout);
  assert_buffer_equals(data, expectedData);
}, 'Test I420 frame.');
  const destination = new ArrayBuffer(I420_DATA.length);
  await testI420_4x2_copyTo(destination);
}, 'Test copying I420 frame to a non-shared ArrayBuffer');

promise_test(async t => {
  const destination = new Uint8Array(I420_DATA.length);
  await testI420_4x2_copyTo(destination);
}, 'Test copying I420 frame to a non-shared ArrayBufferView');

promise_test(async t => {
  const frame = makeRGBA_2x2();
+19 −0
Original line number Diff line number Diff line
// META: global=window,dedicatedworker
// META: script=/webcodecs/videoFrame-utils.js

// TODO(crbug.com/1231806): Enable this test once direct SAB usage is supported.
// promise_test(async t => {
//   // *.headers file should ensure we sesrve COOP and COEP headers.
//   assert_true(self.crossOriginIsolated,
//     "Cross origin isolation is required to construct SharedArrayBuffer");
//   const destination = new SharedArrayBuffer(I420_DATA.length);
//   await testI420_4x2_copyTo(destination);
// }, 'Test copying I420 frame to SharedArrayBuffer.');

promise_test(async t => {
  // *.headers file should ensure we sesrve COOP and COEP headers.
  assert_true(self.crossOriginIsolated,
    "Cross origin isolation is required to construct SharedArrayBuffer");
  const destination = new Uint8Array(new SharedArrayBuffer(I420_DATA.length));
  await testI420_4x2_copyTo(destination);
}, 'Test copying I420 frame to shared ArrayBufferView.');
Loading