[FFmpeg-devel] [PATCH 3/7] avutil/frame: add a param change side data type

Nicolas George george at nsup.org
Wed Jan 22 22:18:41 EET 2025


James Almer (12025-01-22):
> Ok, will implement a new struct.

Thanks.

I think this code would work:

typedef struct AVSideDataParamChange
    …
    intmax_t end_padding;
} AVSideDataSomethingType;

static const AVSideDataParamChange default = { ... };


    AVSideDataParamChange pc;
    av_assert0(sd->size > sizeof(pc.end_padding));
    size_t s = FFMIN(sd->size - sizeof(pc.end_padding), sizeof(pc));
    memcpy(&pc, sd->data, s);
    memcpy((char *)&pc + s, (char *)&default + s, sizeof(pc) - s);

After this code, pc contains the fields from the side data if they are
present in the version known by the caller and the fields from default
otherwise.

I am rather sure this is valid C unless there we add a field with
individual size greater than end_padding, hence intmax_t.

If I can at some time start spending efforts on FFmpeg again, I intend
to use this pattern on things that need to be lightweight (no dynamic
allocations) but extensible.

Regards,

-- 
  Nicolas George


More information about the ffmpeg-devel mailing list