[FFmpeg-devel] [PATCH] use NULL instead of av_destruct_packet_nofree

Reimar Döffinger Reimar.Doeffinger
Sat Apr 11 11:09:01 CEST 2009


Hello,
this should resolve issues caused by non-working function pointer
comparisons on MinGW.
The checks still stay there to maintain API/ABI compatibility.
There is still a ABI issue, since binaries compiled against older
header versions but using newer libs will not set pkt->data or
pkt->size to 0 anymore during destruct for the default "nofree"
packets.
There is still a pkt->destruct == av_destruct_packet in
libavformat/utils.c, but I think this will only lead to worse
performance and thus can be ignored (though I still think
it is an ugly optimization hack, it may well be possible to
share packets with pkt->destruct != av_destruct_packet
without fully duplicating them).
In addition I am also a bit irritated as to why libavformat/utils.c
set pkt->duration and pkt->destruct, those should have been set
like this already during init_packet.
-------------- next part --------------
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h	(revision 18412)
+++ libavcodec/avcodec.h	(working copy)
@@ -2630,7 +2630,10 @@
 
 /* packet functions */
 
-void av_destruct_packet_nofree(AVPacket *pkt);
+/**
+ * @deprecated use NULL instead
+ */
+attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
 
 /**
  * Default packet destructor.
@@ -2675,8 +2678,9 @@
  */
 static inline void av_free_packet(AVPacket *pkt)
 {
-    if (pkt && pkt->destruct) {
-        pkt->destruct(pkt);
+    if (pkt) {
+        if (pkt->destruct) pkt->destruct(pkt);
+        pkt->data = NULL; pkt->size = 0;
     }
 }
 
Index: libavcodec/avpacket.c
===================================================================
--- libavcodec/avpacket.c	(revision 18412)
+++ libavcodec/avpacket.c	(working copy)
@@ -42,7 +42,7 @@
     pkt->convergence_duration = 0;
     pkt->flags = 0;
     pkt->stream_index = 0;
-    pkt->destruct= av_destruct_packet_nofree;
+    pkt->destruct= NULL;
 }
 
 int av_new_packet(AVPacket *pkt, int size)
Index: libavformat/utils.c
===================================================================
--- libavformat/utils.c	(revision 18412)
+++ libavformat/utils.c	(working copy)
@@ -923,7 +923,7 @@
                     pkt->pts = st->parser->pts;
                     pkt->dts = st->parser->dts;
                     pkt->pos = st->parser->pos;
-                    pkt->destruct = av_destruct_packet_nofree;
+                    pkt->destruct = NULL;
                     compute_pkt_fields(s, st, st->parser, pkt);
 
                     if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){



More information about the ffmpeg-devel mailing list