---
 libavcodec/avcodec.h   | 41 +++++++++++++++++++++++++++++++++++++
 libavcodec/avpacket.c  | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/avformat.h |  6 ------
 3 files changed, 96 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 96683b0..98948d2 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -977,6 +977,11 @@ typedef struct AVPacket {
 #define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe
 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
 
+typedef struct AVPacketList {
+    AVPacket pkt;
+    struct AVPacketList *next;
+} AVPacketList;
+
 enum AVSideDataParamChangeFlags {
     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
@@ -3291,6 +3296,42 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src);
 int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
 
 /**
+ * Append an AVPacket to the list creating a new reference
+ * to it.
+ *
+ * @param head List head
+ * @param tail List tail
+ * @param pkt  The packet being appended
+ * @return < 0 on failure and 0 on success.
+ */
+int av_packet_list_put(AVPacketList **head, AVPacketList **tail,
+                       AVPacket *pkt);
+
+/**
+ * Remove the oldest AVPacket in the list and return it.
+ *
+ * @note The pkt will be overwritten completely. The caller
+ *       owns the packet and must unref it by itself.
+ *
+ * @see av_packet_unref av_packet_ref
+ *
+ * @param head List head.
+ * @param tail List tail.
+ * @param pkt  Pointer to an initialized AVPacket struct
+ * @return < 0 on failure and 0 on success.
+ */
+int av_packet_list_get(AVPacketList **head, AVPacketList **tail,
+                       AVPacket *pkt);
+
+/**
+ * Wipe the list and unref all the packets in it.
+ *
+ * @param head List head.
+ * @param tail List tail.
+ */
+void av_packet_list_free(AVPacketList **head, AVPacketList **tail);
+
+/**
  * @}
  */
 
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 79123b1..86d9bc1 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -380,3 +380,58 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src)
     *dst = *src;
     av_init_packet(src);
 }
+
+int av_packet_list_put(AVPacketList **head, AVPacketList **tail,
+                       AVPacket *pkt)
+{
+    AVPacketList *pl = av_mallocz(sizeof(AVPacketList));
+    int ret;
+
+    if (!pl)
+        return AVERROR(ENOMEM);
+
+    if ((ret = av_packet_ref(&pl->pkt, pkt)) < 0) {
+        av_free(pl);
+        return ret;
+    }
+
+    if (*head)
+        (*tail)->next = pl;
+    else
+        *head = pl;
+
+    *tail = pl;
+
+    return 0;
+}
+
+int av_packet_list_get(AVPacketList **head, AVPacketList **tail,
+                       AVPacket *pkt)
+{
+    AVPacketList *pl = *head;
+    if (!pl)
+        return AVERROR_EOF;
+
+    av_packet_move_ref(pkt, &pl->pkt);
+
+    *head = pl->next;
+
+    if (!pl->next)
+        tail = NULL;
+
+    av_free(pl);
+
+    return 0;
+}
+
+void av_packet_list_free(AVPacketList **head, AVPacketList **tail)
+{
+    AVPacketList *pl;
+
+    while (pl = *head) {
+        *head = pl->next;
+        av_packet_unref(&pl->pkt);
+        av_free(pl);
+    }
+    *tail = NULL;
+}
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 5d224c4..0f1e14a 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1042,12 +1042,6 @@ typedef struct AVFormatContext {
 
 } AVFormatContext;
 
-typedef struct AVPacketList {
-    AVPacket pkt;
-    struct AVPacketList *next;
-} AVPacketList;
-
-
 /**
  * @defgroup lavf_core Core functions
  * @ingroup libavf
-- 
1.8.3.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to