Fix I420 rescaling on Mac
Categories
(Core :: Audio/Video: Web Codecs, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox139 | --- | fixed |
People
(Reporter: chunmin, Assigned: chunmin)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 20 external files, 2 obsolete files)
|
4.73 KB,
text/html
|
Details |
The I420-related WPT in video-encoder-rescaling.https.any.js, which was introduced in Bug 1921623, currently fails on Mac. We need to fix it.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
•
|
||
Here is a visual test page. It takes a photo (via WebRTC video stream), encodes it with a different size, and then decodes it. Currently, the image will duplicate in the destination canvas.
Here is a backup test page hosted on github.
| Assignee | ||
Comment 2•1 year ago
•
|
||
From the test page here, it demonstrates that encoding a resized image in RGBX format is okay, while in I420 is not. In addition, this test page shows that drawing a videoframe, which creates from a video element, into a canvas with different size is okay. Hence, the problem must reside in the Mac encoder rather than rendering. I am going to fix this shortly.
| Assignee | ||
Comment 3•1 year ago
|
||
I guess the CVPixelBufferRef used for the Mac's encoder input should contain the resized data. A resizing approach for I420 was implemented in bug 1921623 for the Windows encoder, where I420 data is scaled if needed before being passed to the underlying encoder.
Refactoring the resizing logic into a separate function that returns a scaled/resized buffer and calling it accordingly should work for both Windows and Mac scenarios.
| Assignee | ||
Comment 4•1 year ago
•
|
||
(In reply to C.M.Chang[:chunmin] from comment #3)
I guess the
CVPixelBufferRefused for the Mac's encoder input should contain the resized data. A resizing approach for I420 was implemented in bug 1921623 for the Windows encoder, where I420 data is scaled if needed before being passed to the underlying encoder.
It turns out to be a wrong guess. It looks like the mac's encoder can automatically resize the image if needed.
The real problem is that the pixel format for our YUV input is wrong. The pixel format is converted from mConfig.mSourcePixelFormat, while mConfig.mSourcePixelFormat is set to BGRA by default and never being updated.
Changing the pixel type we used in CreateCVPixelBuffer and BuildSourceImageBufferAttributes to YUV420 fixed the problem (If these two formats don't match each other, kVTPixelTransferNotSupportedErr will be thown).
However, since the input format is unknown when the WebCodecs's encoder is initialized (that's why we have a default guess), setting a nullptr as the sourceImageBufferAttributes to VTCompressionSessionCreate is a way to go. The drawback is that it could increase the chance that we'll have to copy image data, according to the developer document. The alternative is to re-initialize the encoder if the input format changes or differs from the expected one.
I am going to go with the more straightforward approach first, and then see if we need to go the alternative one.
| Assignee | ||
Comment 5•1 year ago
|
||
| Assignee | ||
Comment 6•1 year ago
|
||
Depends on D241513
| Assignee | ||
Comment 7•1 year ago
|
||
Depends on D241514
| Assignee | ||
Comment 8•1 year ago
|
||
Depends on D241515
| Assignee | ||
Comment 9•1 year ago
|
||
Depends on D241516
| Assignee | ||
Comment 10•1 year ago
|
||
Depends on D241517
| Assignee | ||
Comment 11•1 year ago
|
||
Depends on D241518
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Comment 12•1 year ago
|
||
This patch restores pixel format initialization during the configuration
stage, which was removed in D241516, and introduces a mechanism to
reinitialize the format during encoding if the format changes.
Previously, to allow flexibility in pixel formats for encoding requests,
the encoder was initialized without a preset pixel format. This also
eliminated the creation of a pixel buffer pool for source frames,
reducing unnecessary image copies.
To strike a balance, this patch reintroduces pixel format initialization
while still allowing updates when the input image format differs from
the expected format. This ensures better performance while maintaining
flexibility.
Depends on D241537
| Assignee | ||
Comment 13•1 year ago
|
||
This patch automatically selects the encoder pixel format based on the
intended use case.
- For real-time applications, the format defaults to YUV420, as it's the
most commonly used format for video conferencing. - For other use cases, the format is set to BGRA, which is the preferred
format in Gecko.
Depends on D241898
| Assignee | ||
Comment 14•1 year ago
|
||
Depends on D241899
| Assignee | ||
Comment 15•1 year ago
|
||
Depends on D241515
| Assignee | ||
Comment 16•1 year ago
|
||
mInited is never being set to true in the first place [1], so this
patch sets it to true once initialization succeeds. Additionally,
assertions that guarantees the initialization are added for the
operations called only after successful initialization.
[1] https://hg.mozilla.org/mozilla-central/rev/b86195e2307a
Depends on D242244
| Assignee | ||
Comment 17•1 year ago
|
||
Depends on D242245
| Assignee | ||
Comment 18•1 year ago
|
||
Previously, the mInited is used to ensure the success of
initialization since having mSession doesn't guarantee that. The
initialization continues after creating mSession. However, as long as
mSession is torn down safely when initialization fails, it can be a
singal of initialization success, and a replacement of mInit.
Depends on D242246
| Assignee | ||
Comment 19•1 year ago
|
||
Depends on D242247
| Assignee | ||
Comment 20•1 year ago
|
||
Depends on D242248
| Assignee | ||
Comment 21•1 year ago
|
||
Depends on D242249
Updated•1 year ago
|
Comment 22•1 year ago
|
||
Comment on attachment 9472564 [details]
Bug 1934976 - Reintroduce format initialization with dynamic reconfiguration
Revision D241898 was moved to bug 1955153. Setting attachment 9472564 [details] to obsolete.
Comment 23•1 year ago
|
||
Comment on attachment 9472565 [details]
Bug 1934976 - Default pixel format selection based on use case
Revision D241899 was moved to bug 1955153. Setting attachment 9472565 [details] to obsolete.
Updated•1 year ago
|
| Assignee | ||
Comment 24•1 year ago
|
||
Depends on D241537
| Assignee | ||
Comment 25•1 year ago
|
||
| Assignee | ||
Comment 26•1 year ago
|
||
Depends on D243033
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Comment 27•1 year ago
|
||
| Assignee | ||
Comment 28•1 year ago
|
||
Updated•1 year ago
|
Comment 29•1 year ago
|
||
Comment 30•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/c9eb32edfb6c
https://hg.mozilla.org/mozilla-central/rev/f3ff68ce51d7
https://hg.mozilla.org/mozilla-central/rev/ebb683c5f76a
https://hg.mozilla.org/mozilla-central/rev/c775f915768b
https://hg.mozilla.org/mozilla-central/rev/234305a93fb8
https://hg.mozilla.org/mozilla-central/rev/6cdb9725cb0b
https://hg.mozilla.org/mozilla-central/rev/d518c76574b6
https://hg.mozilla.org/mozilla-central/rev/f09899753b4c
https://hg.mozilla.org/mozilla-central/rev/dd315e8f4c0d
https://hg.mozilla.org/mozilla-central/rev/422f9fd66a21
https://hg.mozilla.org/mozilla-central/rev/12b77d56d968
https://hg.mozilla.org/mozilla-central/rev/2727becd865d
https://hg.mozilla.org/mozilla-central/rev/270ae400212f
https://hg.mozilla.org/mozilla-central/rev/f6e96227dec9
https://hg.mozilla.org/mozilla-central/rev/6d13925d71d1
https://hg.mozilla.org/mozilla-central/rev/4e8cca45d1f8
https://hg.mozilla.org/mozilla-central/rev/19a3a04306fb
https://hg.mozilla.org/mozilla-central/rev/4ce8e9c60315
https://hg.mozilla.org/mozilla-central/rev/f1d77d732ffa
https://hg.mozilla.org/mozilla-central/rev/116962bc2aa2
Updated•1 year ago
|
Description
•