[FFmpeg-devel] [RFC] avcodec/avcodec.h: Add encryption info side data
Jacob Trimble
modmaker at google.com
Wed Dec 6 02:36:24 EET 2017
On Tue, Dec 5, 2017 at 3:25 PM, Derek Buitenhuis
<derek.buitenhuis at gmail.com> wrote:
> On 12/5/2017 11:00 PM, Jacob Trimble wrote:
>> Also, can I use the flexible array member feature, it was introduced
>> in C99? Would a 0-length array be better?
>
> No, I don't think this would be OK inside a public header, unfortunately.
Would a 0-length array work? Otherwise I would need to have it be a
1-length array and have to account for that when calculating the size
to allocate; it would also require a comment to ignore the size of the
array.
The reason I want it to be an array is because I want a variable
number of elements, but I want the data contained in the struct.
Since this will be extra data, AFAIK it will only be free()'d, so I
can't use pointers or it will leak.
Another alternative would be to still malloc more than needed and have
the memory past the struct be the array. That seems like a hack, but
would allow a simple free(). For example:
info = malloc(sizeof(AVPacketEncryptionInfo) +
sizeof(AVPacketSubsampleInfo) * num_subsamples);
info.subsamples = (uint8_t*)info + sizeof(AVPacketEncryptionInfo);
More information about the ffmpeg-devel
mailing list