Skip to content

Commit

Permalink
Bug 1902115 - Update ParseVideoFrameCopyToOptions r=media-playback-re…
Browse files Browse the repository at this point in the history
…viewers,padenot

This patch updates the `ParseVideoFrameCopyToOptions` to the changes
made in WebCodecs PR 754 [1]. The changes make the caller of
`ParseVideoFrameCopyToOptions` throw a `NotSupported` error when the
given `VideoFrameCopyToOptions`'s format is invalid.

[1] w3c/webcodecs#754

Differential Revision: https://phabricator.services.mozilla.com/D213806
  • Loading branch information
ChunMinChang committed Jul 10, 2024
1 parent d81a112 commit 829a3f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 56 deletions.
27 changes: 25 additions & 2 deletions dom/media/webcodecs/VideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ static Result<CombinedBufferLayout, MediaResult> ParseVideoFrameCopyToOptions(

const Sequence<PlaneLayout>* optLayout = OptionalToPointer(aOptions.mLayout);

VideoFrame::Format format(aFormat);
if (aOptions.mFormat.WasPassed()) {
if (aOptions.mFormat.Value() != VideoPixelFormat::RGBA &&
aOptions.mFormat.Value() != VideoPixelFormat::RGBX &&
aOptions.mFormat.Value() != VideoPixelFormat::BGRA &&
aOptions.mFormat.Value() != VideoPixelFormat::BGRX) {
nsAutoCString error(dom::GetEnumString(aOptions.mFormat.Value()).get());
error.Append(" is unsupported in ParseVideoFrameCopyToOptions");
return Err(MediaResult(NS_ERROR_DOM_NOT_SUPPORTED_ERR, error));
}
format = VideoFrame::Format(aOptions.mFormat.Value());
}

return ComputeLayoutAndAllocationSize(parsedRect, aFormat, optLayout);
}

Expand Down Expand Up @@ -1744,7 +1757,12 @@ uint32_t VideoFrame::AllocationSize(const VideoFrameCopyToOptions& aOptions,
auto r = ParseVideoFrameCopyToOptions(aOptions, mVisibleRect, mCodedSize,
mResource->mFormat.ref());
if (r.isErr()) {
aRv.ThrowTypeError(r.unwrapErr().Message());
MediaResult error = r.unwrapErr();
if (error.Code() == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
aRv.ThrowNotSupportedError(error.Message());
} else {
aRv.ThrowTypeError(error.Message());
}
return 0;
}
CombinedBufferLayout layout = r.unwrap();
Expand Down Expand Up @@ -1776,7 +1794,12 @@ already_AddRefed<Promise> VideoFrame::CopyTo(
auto r = ParseVideoFrameCopyToOptions(aOptions, mVisibleRect, mCodedSize,
mResource->mFormat.ref());
if (r.isErr()) {
p->MaybeRejectWithTypeError(r.unwrapErr().Message());
MediaResult error = r.unwrapErr();
if (error.Code() == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
p->MaybeRejectWithNotSupportedError(error.Message());
} else {
p->MaybeRejectWithTypeError(error.Message());
}
return p.forget();
}
CombinedBufferLayout layout = r.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,6 @@
[Convert 4-color canvas frame to RGBX / display-p3]
expected: FAIL

[Unsupported format I420]
expected: FAIL

[Unsupported format I420P10]
expected: FAIL

[Unsupported format I420P12]
expected: FAIL

[Unsupported format I420A]
expected: FAIL

[Unsupported format I422]
expected: FAIL

[Unsupported format I422A]
expected: FAIL

[Unsupported format I444]
expected: FAIL

[Unsupported format I444A]
expected: FAIL

[Unsupported format NV12]
expected: FAIL


[videoFrame-copyTo-rgb.any.worker.html]
[Convert 4x4 null I420 frames to RGBA / srgb]
Expand Down Expand Up @@ -267,30 +240,3 @@

[Convert 4-color canvas frame to RGBX / display-p3]
expected: FAIL

[Unsupported format I420]
expected: FAIL

[Unsupported format I420P10]
expected: FAIL

[Unsupported format I420P12]
expected: FAIL

[Unsupported format I420A]
expected: FAIL

[Unsupported format I422]
expected: FAIL

[Unsupported format I422A]
expected: FAIL

[Unsupported format I444]
expected: FAIL

[Unsupported format I444A]
expected: FAIL

[Unsupported format NV12]
expected: FAIL

0 comments on commit 829a3f0

Please sign in to comment.