]> git.sesse.net Git - ffmpeg/commitdiff
avpacket: Provide an alloc and a free function for the struct
authorLuca Barbato <lu_zero@gentoo.org>
Fri, 23 Oct 2015 09:11:34 +0000 (11:11 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Mon, 26 Oct 2015 17:00:55 +0000 (18:00 +0100)
Pave the way for having the size of the AVPacket struct not part
of the ABI.

doc/APIchanges
libavcodec/avcodec.h
libavcodec/avpacket.c

index 0c5d141101c8e3eb7a6a5b9c9097665223f813a4..d301bd5fac9a0fcec4f5ba0851a3851164fcdf6e 100644 (file)
@@ -12,12 +12,15 @@ libavutil:     2015-08-28
 
 
 API changes, most recent first:
+2015-xx-xx - xxxxxxx - lavc 57.6.0 - avcodec.h
 
 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.
+  xxxxxx - Add av_packet_alloc(), av_packet_clone(), av_packet_free().
+           They match the AVFrame functions with the same name.
 
 2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h
   Add data and linesize array to AVSubtitleRect, to be used instead of
index 9eaa2c6ffb1309aab2b90b316665d927fe0da1b6..b47aafaac3a80441b3c78353e3e775e2e10ede91 100644 (file)
@@ -3425,6 +3425,40 @@ void avsubtitle_free(AVSubtitle *sub);
  * @{
  */
 
+/**
+ * Allocate an AVPacket and set its fields to default values.  The resulting
+ * struct must be freed using av_packet_free().
+ *
+ * @return An AVPacket filled with default values or NULL on failure.
+ *
+ * @note this only allocates the AVPacket itself, not the data buffers. Those
+ * must be allocated through other means such as av_new_packet.
+ *
+ * @see av_new_packet
+ */
+AVPacket *av_packet_alloc(void);
+
+/**
+ * Create a new packet that references the same data as src.
+ *
+ * This is a shortcut for av_packet_alloc()+av_packet_ref().
+ *
+ * @return newly created AVPacket on success, NULL on error.
+ *
+ * @see av_packet_alloc
+ * @see av_packet_ref
+ */
+AVPacket *av_packet_clone(AVPacket *src);
+
+/**
+ * Free the packet, if the packet is reference counted, it will be
+ * unreferenced first.
+ *
+ * @param packet packet to be freed. The pointer will be set to NULL.
+ * @note passing NULL is a no-op.
+ */
+void av_packet_free(AVPacket **pkt);
+
 /**
  * Initialize optional fields of a packet with default values.
  *
index cec5bf89c31aff6c6838f371fca4a2170cb8ec7a..a6eb24178507671d801b2921bd1532d3a8cd6d3b 100644 (file)
@@ -46,6 +46,26 @@ FF_ENABLE_DEPRECATION_WARNINGS
     pkt->side_data_elems      = 0;
 }
 
+AVPacket *av_packet_alloc(void)
+{
+    AVPacket *pkt = av_mallocz(sizeof(AVPacket));
+    if (!pkt)
+        return pkt;
+
+    av_packet_unref(pkt);
+
+    return pkt;
+}
+
+void av_packet_free(AVPacket **pkt)
+{
+    if (!pkt || !*pkt)
+        return;
+
+    av_packet_unref(*pkt);
+    av_freep(pkt);
+}
+
 static int packet_alloc(AVBufferRef **buf, int size)
 {
     int ret;
@@ -343,6 +363,19 @@ fail:
     return ret;
 }
 
+AVPacket *av_packet_clone(AVPacket *src)
+{
+    AVPacket *ret = av_packet_alloc();
+
+    if (!ret)
+        return ret;
+
+    if (av_packet_ref(ret, src))
+        av_packet_free(&ret);
+
+    return ret;
+}
+
 void av_packet_move_ref(AVPacket *dst, AVPacket *src)
 {
     *dst = *src;