Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a loop to drain buffered frames in the decoder #2002

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

wantehchang
Copy link
Collaborator

If we use a single decoder instance to decode all tiles in an image grid, it is important to endure there are no buffered frames in the decoder before decoding the next tile with the decoder.

BUG=oss-fuzz:66313

src/codec_dav1d.c Show resolved Hide resolved
if (res < 0) {
if (res != DAV1D_ERR(EAGAIN)) {
if (gotPicture) {
dav1d_picture_unref(&nextFrame);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code snippet in the documentation of dav1d_get_picture() is a bit vague so I quickly checked its implementation. It should be fine not to call dav1d_picture_unref(&bufferedFrame); here. It is also unlikely that the dav1d API changes in a way it becomes necessary. On the other hand, calling dav1d_picture_unref(&bufferedFrame); here would not hurt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into this. It is a common API design that a function outputs nothing on failure. This is why I don't call dav1d_picture_unref(&bufferedFrame) if res is negative. Because of your comment, I checked the documentation. I think we can conclude from the following that a frame is output only when res is 0:

 * @param out Output frame. The caller assumes ownership of the returned
 *            reference.
 *
 * @return
 *         0: Success, and a frame is returned.
 *  DAV1D_ERR(EAGAIN): Not enough data to output a frame. dav1d_send_data()
 *                     should be called with new input.
 *  Other negative DAV1D_ERR codes: Error during decoding or because of invalid
 *                                  passed-in arguments.

@vrabaud
Copy link
Collaborator

vrabaud commented Feb 12, 2024

I confirm this fixes the original bug.

If we use a single decoder instance to decode all tiles in an image
grid, it is important to endure there are no buffered frames in the
decoder before decoding the next tile with the decoder.

BUG=oss-fuzz:66313
@wantehchang wantehchang merged commit 75d4870 into AOMediaCodec:main Feb 13, 2024
20 checks passed
@wantehchang wantehchang deleted the dav1d-drain-decoder branch February 13, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants