[FFmpeg-devel] [PATCH] avpacket: do not copy data when buf ref is available.

Clément Bœsch ubitux at gmail.com
Tue Mar 12 08:13:38 CET 2013


This at least fixes issues with lavf/subtitles.
---
 libavcodec/avpacket.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 16496e2..57e4204 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -184,7 +184,10 @@ static int copy_packet_data(AVPacket *pkt, AVPacket *src)
 {
     pkt->data      = NULL;
     pkt->side_data = NULL;
-    DUP_DATA(pkt->data, src->data, pkt->size, 1, ALLOC_BUF);
+    if (pkt->buf)
+        pkt->data = pkt->buf->data;
+    else
+        DUP_DATA(pkt->data, src->data, pkt->size, 1, ALLOC_BUF);
 #if FF_API_DESTRUCT_PACKET
     pkt->destruct = dummy_destruct_packet;
 #endif
@@ -228,7 +231,12 @@ int av_dup_packet(AVPacket *pkt)
 int av_copy_packet(AVPacket *dst, AVPacket *src)
 {
     *dst = *src;
-    dst->buf = av_buffer_ref(src->buf);
+    if (dst->buf) {
+        AVBufferRef *ref = av_buffer_ref(src->buf);
+        if (!ref)
+            return AVERROR(ENOMEM);
+        dst->buf = ref;
+    }
     return copy_packet_data(dst, src);
 }
 
-- 
1.8.1.5



More information about the ffmpeg-devel mailing list