[FFmpeg-devel] [PATCH] avcodec/avpacket: ensure the packet is writable in av_shrink_packet()

James Almer jamrial at gmail.com
Sat Mar 24 23:11:53 EET 2018


Signed-off-by: James Almer <jamrial at gmail.com>
---
This is a good time to deprecate this function and introduce a
replacement using the correct av_packet namespace and this time
returning an int.
What would be better

int av_packet_shrink(AVPacket *pkt, int size);

Or

int av_packet_resize(AVPacket *pkt, int size);

The latter would be a combination of both the current shrink and grow
functions.

 libavcodec/avpacket.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 0693ca6f62..7faa082395 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -100,9 +100,12 @@ int av_new_packet(AVPacket *pkt, int size)
 
 void av_shrink_packet(AVPacket *pkt, int size)
 {
+    int packet_is_writable;
     if (pkt->size <= size)
         return;
     pkt->size = size;
+    packet_is_writable = !av_packet_make_writable(pkt);
+    av_assert0(packet_is_writable);
     memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 }
 
-- 
2.16.2



More information about the ffmpeg-devel mailing list