[FFmpeg-devel] [PATCH 1/3] avcodec/avpacket: add av_packet_resize()
Marton Balint
cus at passwd.hu
Fri Mar 12 00:40:20 EET 2021
On Thu, 11 Mar 2021, James Almer wrote:
> On 3/11/2021 1:11 PM, Marton Balint wrote:
>>
>>
>> On Thu, 11 Mar 2021, James Almer wrote:
>>
>>> This function acts as a replacement for both av_grow_packet() and
>>> av_shrink_packet(), the latter which is now deprecated and will be
>>> removed as
>>> it does not correctly handle non-writable packets.
>>
>> I don't think this is a good idea, av_shrink_packet cannot fail,
>> av_grow_packet can. By using the same function you are losing the
>> information if the end result should be checked or not.
>
> I'm not sure i follow. av_shrink_packet() is not being changed at all,
> just deprecated, scheduled for removal, and its use discouraged.
But why are you complicating code with mandatory return value checking?
Because as soon as a function returns an error, you have to check it, and
forward it upwards.
> Maybe i should have split this in two, one to add av_packet_resize() and
> one to deprecate av_shrink_packet(), to avoid confusion.
>
> In any case, the fact av_shrink_packet() cannot fail is the reason I'm
> getting rid of it. It's zeroing the padding without bothering to check
> if the packet is writable at all.
Add an assert to it then. Shrinking a non-writable packet seems bad API
usage anyways.
If you want to shrink a writable packet, then maybe you don't even need
zero padding, because the buffer possibly already contains some defined
value, and the main reason of zero padding is avoiding reading
uninitialized data...
Regards,
Marton
More information about the ffmpeg-devel
mailing list