]> git.sesse.net Git - ffmpeg/commitdiff
avpacket: Deprecate av_dup_packet
authorLuca Barbato <lu_zero@gentoo.org>
Fri, 23 Oct 2015 09:11:33 +0000 (11:11 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Mon, 26 Oct 2015 17:00:55 +0000 (18:00 +0100)
As documented, `av_dup_packet` is broken by design, `av_packet_ref`
matches the AVFrame ref-counted API and can be safely used instead.

doc/APIchanges
libavcodec/avcodec.h
libavcodec/avpacket.c
libavformat/matroskaenc.c
libavformat/mux.c

index 590f192a4688380ef26b35450940c1be27b2ff52..0c5d141101c8e3eb7a6a5b9c9097665223f813a4 100644 (file)
@@ -13,9 +13,11 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
-2015-xx-xx - xxxxxxx - lavc 57.7.0 - avcodec.h
-  Deprecate av_free_packet(). Use av_packet_unref() as replacement,
-  it resets the packet in a more consistent way.
+2015-xx-xx - lavc 57.7.0 - avcodec.h
+  xxxxxx - Deprecate av_free_packet(). Use av_packet_unref() as replacement,
+           it resets the packet in a more consistent way.
+  xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases.
+           Use av_packet_ref() to make a non-refcounted AVPacket refcounted.
 
 2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h
   Add data and linesize array to AVSubtitleRect, to be used instead of
index dfd18ba866628e1e362395bc158bb3abd7173c2f..9eaa2c6ffb1309aab2b90b316665d927fe0da1b6 100644 (file)
@@ -3476,12 +3476,15 @@ int av_grow_packet(AVPacket *pkt, int grow_by);
  */
 int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
 
+#if FF_API_AVPACKET_OLD_API
 /**
  * @warning This is a hack - the packet memory allocation stuff is broken. The
  * packet is allocated if it was not really allocated.
+ *
+ * @deprecated Use av_packet_ref
  */
+attribute_deprecated
 int av_dup_packet(AVPacket *pkt);
-#if FF_API_AVPACKET_OLD_API
 /**
  * Free a packet.
  *
index eaea061c5434ad5d423e5d6be61290042a9482a0..cec5bf89c31aff6c6838f371fca4a2170cb8ec7a 100644 (file)
@@ -128,6 +128,8 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
     return 0;
 }
 
+#if FF_API_AVPACKET_OLD_API
+FF_DISABLE_DEPRECATION_WARNINGS
 #define ALLOC_MALLOC(data, size) data = av_malloc(size)
 #define ALLOC_BUF(data, size)                \
 do {                                         \
@@ -187,6 +189,8 @@ failed_alloc:
     av_packet_unref(pkt);
     return AVERROR(ENOMEM);
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 void av_packet_free_side_data(AVPacket *pkt)
 {
index f1bd2726729699d5f301cdd00dcb59ce90c1db9b..baffd54340f04e4a175faac43ddb696a593dd842 100644 (file)
@@ -1608,12 +1608,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
     // buffer an audio packet to ensure the packet containing the video
     // keyframe's timecode is contained in the same cluster for WebM
     if (codec_type == AVMEDIA_TYPE_AUDIO) {
-        mkv->cur_audio_pkt = *pkt;
-        if (pkt->buf) {
-            mkv->cur_audio_pkt.buf = av_buffer_ref(pkt->buf);
-            ret = mkv->cur_audio_pkt.buf ? 0 : AVERROR(ENOMEM);
-        } else
-            ret = av_dup_packet(&mkv->cur_audio_pkt);
+        ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
     } else
         ret = mkv_write_packet_internal(s, pkt);
     return ret;
index e86d202713f3ff0434ed77accaa4ac46ff3fec54..4a81e36af56f57886e4cca7327aa76b729b01027 100644 (file)
@@ -416,12 +416,8 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
     this_pktl      = av_mallocz(sizeof(AVPacketList));
     if (!this_pktl)
         return AVERROR(ENOMEM);
-    this_pktl->pkt = *pkt;
-    pkt->buf       = NULL;
-    pkt->side_data = NULL;
-    pkt->side_data_elems = 0;
-    // Duplicate the packet if it uses non-allocated memory
-    if ((ret = av_dup_packet(&this_pktl->pkt)) < 0) {
+
+    if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) {
         av_free(this_pktl);
         return ret;
     }
@@ -450,6 +446,8 @@ next_non_null:
     s->streams[pkt->stream_index]->last_in_packet_buffer =
         *next_point                                      = this_pktl;
 
+    av_packet_unref(pkt);
+
     return 0;
 }