Skip to content

Commit ce067d8

Browse files
committed
Bug 1902115 - Update ParseVideoFrameCopyToOptions r=media-playback-reviewers,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
1 parent cffcd47 commit ce067d8

File tree

2 files changed

+25
-56
lines changed

2 files changed

+25
-56
lines changed

dom/media/webcodecs/VideoFrame.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,19 @@ static Result<CombinedBufferLayout, MediaResult> ParseVideoFrameCopyToOptions(
608608

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

611+
VideoFrame::Format format(aFormat);
612+
if (aOptions.mFormat.WasPassed()) {
613+
if (aOptions.mFormat.Value() != VideoPixelFormat::RGBA &&
614+
aOptions.mFormat.Value() != VideoPixelFormat::RGBX &&
615+
aOptions.mFormat.Value() != VideoPixelFormat::BGRA &&
616+
aOptions.mFormat.Value() != VideoPixelFormat::BGRX) {
617+
nsAutoCString error(dom::GetEnumString(aOptions.mFormat.Value()).get());
618+
error.Append(" is unsupported in ParseVideoFrameCopyToOptions");
619+
return Err(MediaResult(NS_ERROR_DOM_NOT_SUPPORTED_ERR, error));
620+
}
621+
format = VideoFrame::Format(aOptions.mFormat.Value());
622+
}
623+
611624
return ComputeLayoutAndAllocationSize(parsedRect, aFormat, optLayout);
612625
}
613626

@@ -1744,7 +1757,12 @@ uint32_t VideoFrame::AllocationSize(const VideoFrameCopyToOptions& aOptions,
17441757
auto r = ParseVideoFrameCopyToOptions(aOptions, mVisibleRect, mCodedSize,
17451758
mResource->mFormat.ref());
17461759
if (r.isErr()) {
1747-
aRv.ThrowTypeError(r.unwrapErr().Message());
1760+
MediaResult error = r.unwrapErr();
1761+
if (error.Code() == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
1762+
aRv.ThrowNotSupportedError(error.Message());
1763+
} else {
1764+
aRv.ThrowTypeError(error.Message());
1765+
}
17481766
return 0;
17491767
}
17501768
CombinedBufferLayout layout = r.unwrap();
@@ -1776,7 +1794,12 @@ already_AddRefed<Promise> VideoFrame::CopyTo(
17761794
auto r = ParseVideoFrameCopyToOptions(aOptions, mVisibleRect, mCodedSize,
17771795
mResource->mFormat.ref());
17781796
if (r.isErr()) {
1779-
p->MaybeRejectWithTypeError(r.unwrapErr().Message());
1797+
MediaResult error = r.unwrapErr();
1798+
if (error.Code() == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
1799+
p->MaybeRejectWithNotSupportedError(error.Message());
1800+
} else {
1801+
p->MaybeRejectWithTypeError(error.Message());
1802+
}
17801803
return p.forget();
17811804
}
17821805
CombinedBufferLayout layout = r.unwrap();

testing/web-platform/meta/webcodecs/videoFrame-copyTo-rgb.any.js.ini

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -119,33 +119,6 @@
119119
[Convert 4-color canvas frame to RGBX / display-p3]
120120
expected: FAIL
121121

122-
[Unsupported format I420]
123-
expected: FAIL
124-
125-
[Unsupported format I420P10]
126-
expected: FAIL
127-
128-
[Unsupported format I420P12]
129-
expected: FAIL
130-
131-
[Unsupported format I420A]
132-
expected: FAIL
133-
134-
[Unsupported format I422]
135-
expected: FAIL
136-
137-
[Unsupported format I422A]
138-
expected: FAIL
139-
140-
[Unsupported format I444]
141-
expected: FAIL
142-
143-
[Unsupported format I444A]
144-
expected: FAIL
145-
146-
[Unsupported format NV12]
147-
expected: FAIL
148-
149122

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

268241
[Convert 4-color canvas frame to RGBX / display-p3]
269242
expected: FAIL
270-
271-
[Unsupported format I420]
272-
expected: FAIL
273-
274-
[Unsupported format I420P10]
275-
expected: FAIL
276-
277-
[Unsupported format I420P12]
278-
expected: FAIL
279-
280-
[Unsupported format I420A]
281-
expected: FAIL
282-
283-
[Unsupported format I422]
284-
expected: FAIL
285-
286-
[Unsupported format I422A]
287-
expected: FAIL
288-
289-
[Unsupported format I444]
290-
expected: FAIL
291-
292-
[Unsupported format I444A]
293-
expected: FAIL
294-
295-
[Unsupported format NV12]
296-
expected: FAIL

0 commit comments

Comments
 (0)