[FFmpeg-devel] [PATCH 02/42] avcodec/refstruct: Add simple API for refcounted objects

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Oct 6 23:50:51 EEST 2023


Nicolas George:
> Andreas Rheinhardt (12023-10-06):
>> Do you mean a template that generates functions like
>>
>> HEVCVPS *ff_hevc_vps_ref(HEVCVPS *vps)
>> {
>>     return ff_refstruct_ref(vps);
>> }
>>
>> automatically?
> 
> Yes, but better, directly:
> 
> void ff_hevc_vps_unref(HEVCVPS *vps)
> {
>     if (atomic_fetch_sub_explicit(&(*vps)->AVRC_FIELD, 1, memory_order_acq_rel) == 1) {
>         AVRC_FREE(*vps);
>         *vps = NULL;
>     }
> }
> 
> Apart from the type safety, I see a significant benefit in having the
> free function hard-coded in the unref function rather than having to
> spare a pointer for it.
> 

And as I have already explained, I do not think that this benefit is
significant and you have provided no evidence (i.e. an example) that it
is so. Additionally, the flexibility provided by function pointers is
useful for stuff like CBS.

- Andreas



More information about the ffmpeg-devel mailing list