---
libavcodec/avcodec.h | 34 +++++++++++++++++++++++++++++++
libavcodec/avpacket.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f7312ed..f0f0a34 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3296,6 +3296,40 @@ 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
+ *
+ * @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 argument must point to an initialized AVPacket.
+ *
+ * @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.
+ *
+ * @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 fad801c..419ca62 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -367,3 +367,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;
+}
--
1.8.2.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel