Skip to content

Replace RGBImagePtr by RGBImageCleanup#3048

Merged
wantehchang merged 4 commits intoAOMediaCodec:mainfrom
vrabaud:main
Feb 27, 2026
Merged

Replace RGBImagePtr by RGBImageCleanup#3048
wantehchang merged 4 commits intoAOMediaCodec:mainfrom
vrabaud:main

Conversation

@vrabaud
Copy link
Contributor

@vrabaud vrabaud commented Feb 19, 2026

Although RGBImagePtr, defined using std::unique_ptr, is correct, it is
confusing because it does not free the avifRGBImage struct. Since the
avifRGBImage struct is intended to be allocated on the stack, we should
not address this by forcing the users of RGBImagePtr to allocate
avifRGBImage from the heap.

Replace RGBImagePtr by RGBImageCleanup, which is modeled after
absl::Cleanup and is a lightweight cleanup object whose destructor
calls avifRGBImageFreePixels() on the associated avifRGBImage struct.

@vrabaud vrabaud requested a review from wantehchang February 19, 2026 13:28
@vrabaud vrabaud force-pushed the main branch 4 times, most recently from 831c5e3 to 2e74fb1 Compare February 19, 2026 14:28
@vrabaud vrabaud changed the title Fix RGBImagePtr Replace RGBImagePtr by RGBImageCleanup Feb 19, 2026
Copy link
Collaborator

@wantehchang wantehchang left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks. I suggest some changes.

@wantehchang wantehchang added this to the v1.4.0 milestone Feb 27, 2026
@wantehchang
Copy link
Collaborator

Maryla: Since I edited this PR, could you please review it? Thanks.

// Automatically cleans the ressources of the avifRGBImage.
// To use when RGBImage actually owns the pixels. RGBImage can also be used as a view, in which case it does not own the pixels.
using RGBImagePtr = std::unique_ptr<avifRGBImage, UniquePtrDeleter>;
class RGBImageCleanup
Copy link
Collaborator

Choose a reason for hiding this comment

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

Vignesh: Please review. This is modeled after absl::MakeCleanup. Thanks!

@vigneshvg
Copy link
Contributor

Since the new class is only to be used when the buffers are owned by the underlying pointer, can you please clarify a bit more in the commit message as to how the new class is different from the old unique_ptr wrapper?

Could one not use the existing unique_ptr wrapper the same way?

@wantehchang
Copy link
Collaborator

wantehchang commented Feb 27, 2026

Vignesh: I added a commit message in #3048 (comment).

The existing unique_ptr wrapper (RGBImagePtr) is equivalent in functionality to the new RGBImageCleanup, so one can view this PR as only making the code less confusing. The existing unique_ptr wrapper is confusing because users expect unique_ptr to delete the struct that the pointer points to, but RGBImagePtr only frees the pixels buffer and does not free the avifRGBImage struct.

@wantehchang wantehchang merged commit 319b91e into AOMediaCodec:main Feb 27, 2026
25 checks passed
@FooIbar FooIbar mentioned this pull request Feb 28, 2026
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.

3 participants