Browse Source

lavc/packet: add API for an AVPacket-based AVContainerFifo

Anton Khirnov 11 months ago
parent
commit
2ac34d0854
4 changed files with 44 additions and 1 deletions
  1. 3 0
      doc/APIchanges
  2. 33 0
      libavcodec/packet.c
  3. 7 0
      libavcodec/packet.h
  4. 1 1
      libavcodec/version.h

+ 3 - 0
doc/APIchanges

@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-12-15 - xxxxxxxxxx - lavc 61.27.100 packet.h
+  Add av_container_fifo_alloc_avpacket().
+
 2024-12-15 - xxxxxxxxxx - lavu 59.51.100 - refstruct.h container_fifo.h
   Add a new public header refstruct.h with new API for
   reference-counted objects.

+ 33 - 0
libavcodec/packet.c

@@ -23,6 +23,7 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/avutil.h"
+#include "libavutil/container_fifo.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
@@ -752,3 +753,35 @@ void av_packet_side_data_free(AVPacketSideData **psd, int *pnb_sd)
     av_freep(psd);
     *pnb_sd = 0;
 }
+
+static void *container_packet_alloc(void *opaque)
+{
+    return av_packet_alloc();
+}
+
+static void container_packet_reset(void *opaque, void *obj)
+{
+    av_packet_unref(obj);
+}
+
+static void container_packet_free(void *opaque, void *obj)
+{
+    AVPacket *pkt = obj;
+    av_packet_free(&pkt);
+}
+
+static int container_packet_transfer(void *opaque, void *dst, void *src, unsigned flags)
+{
+    if (flags & AV_CONTAINER_FIFO_FLAG_REF)
+        return av_packet_ref(dst, src);
+
+    av_packet_move_ref(dst, src);
+    return 0;
+}
+
+AVContainerFifo *av_container_fifo_alloc_avpacket(unsigned flags)
+{
+    return av_container_fifo_alloc(NULL, container_packet_alloc,
+                                   container_packet_reset, container_packet_free,
+                                   container_packet_transfer, 0);
+}

+ 7 - 0
libavcodec/packet.h

@@ -880,6 +880,13 @@ int av_packet_make_writable(AVPacket *pkt);
  */
 void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
 
+/**
+ * Allocate an AVContainerFifo instance for AVPacket.
+ *
+ * @param flags currently unused
+ */
+struct AVContainerFifo *av_container_fifo_alloc_avpacket(unsigned flags);
+
 /**
  * @}
  */

+ 1 - 1
libavcodec/version.h

@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  26
+#define LIBAVCODEC_VERSION_MINOR  27
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \