summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2020-08-17 12:03:50 -0300
committerJames Almer <jamrial@gmail.com>2020-09-15 09:53:39 -0300
commit8a81820624ada4d339aeb2150ad5c2b36b12860c (patch)
treee282bffaec65e0cd54c523b5e88610ad4f901b5f /libavcodec
parentfda5363c80bd09066d69fb9bd365c9114b8d08f3 (diff)
avcodec/packet: move AVPacketList definition and function helpers over from libavformat
And replace the flags parameter with a function callback that can be used to copy the contents of the packet (e.g, av_packet_ref and av_packet_copy_props). Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avpacket.c67
-rw-r--r--libavcodec/packet.h5
-rw-r--r--libavcodec/packet_internal.h42
3 files changed, 114 insertions, 0 deletions
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 4801163227..e4ba403cf6 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -726,6 +726,73 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
}
+int avpriv_packet_list_put(AVPacketList **packet_buffer,
+ AVPacketList **plast_pktl,
+ AVPacket *pkt,
+ int (*copy)(AVPacket *dst, const AVPacket *src),
+ int flags)
+{
+ AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
+ int ret;
+
+ if (!pktl)
+ return AVERROR(ENOMEM);
+
+ if (copy) {
+ ret = copy(&pktl->pkt, pkt);
+ if (ret < 0) {
+ av_free(pktl);
+ return ret;
+ }
+ } else {
+ ret = av_packet_make_refcounted(pkt);
+ if (ret < 0) {
+ av_free(pktl);
+ return ret;
+ }
+ av_packet_move_ref(&pktl->pkt, pkt);
+ }
+
+ if (*packet_buffer)
+ (*plast_pktl)->next = pktl;
+ else
+ *packet_buffer = pktl;
+
+ /* Add the packet in the buffered packet list. */
+ *plast_pktl = pktl;
+ return 0;
+}
+
+int avpriv_packet_list_get(AVPacketList **pkt_buffer,
+ AVPacketList **pkt_buffer_end,
+ AVPacket *pkt)
+{
+ AVPacketList *pktl;
+ if (!*pkt_buffer)
+ return AVERROR(EAGAIN);
+ pktl = *pkt_buffer;
+ *pkt = pktl->pkt;
+ *pkt_buffer = pktl->next;
+ if (!pktl->next)
+ *pkt_buffer_end = NULL;
+ av_freep(&pktl);
+ return 0;
+}
+
+void avpriv_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
+{
+ AVPacketList *tmp = *pkt_buf;
+
+ while (tmp) {
+ AVPacketList *pktl = tmp;
+ tmp = pktl->next;
+ av_packet_unref(&pktl->pkt);
+ av_freep(&pktl);
+ }
+ *pkt_buf = NULL;
+ *pkt_buf_end = NULL;
+}
+
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
{
uint8_t *side_data;
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 0a19a0eff3..b9d4c9c2c8 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -393,6 +393,11 @@ typedef struct AVPacket {
#endif
} AVPacket;
+typedef struct AVPacketList {
+ AVPacket pkt;
+ struct AVPacketList *next;
+} AVPacketList;
+
#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
/**
diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h
index cdb9a27f2f..832ddb4a61 100644
--- a/libavcodec/packet_internal.h
+++ b/libavcodec/packet_internal.h
@@ -23,6 +23,48 @@
#include "packet.h"
+
+/**
+ * Append an AVPacket to the list.
+ *
+ * @param head List head element
+ * @param tail List tail element
+ * @param pkt The packet being appended. The data described in it will
+ * be made reference counted if it isn't already.
+ * @param copy A callback to copy the contents of the packet to the list.
+ May be null, in which case the packet's reference will be
+ moved to the list.
+ * @return 0 on success, negative AVERROR value on failure. On failure,
+ the packet and the list are unchanged.
+ */
+int avpriv_packet_list_put(AVPacketList **head, AVPacketList **tail,
+ AVPacket *pkt,
+ int (*copy)(AVPacket *dst, const AVPacket *src),
+ int flags);
+
+/**
+ * Remove the oldest AVPacket in the list and return it.
+ *
+ * @note The pkt will be overwritten completely on success. The caller
+ * owns the packet and must unref it by itself.
+ *
+ * @param head List head element
+ * @param tail List tail element
+ * @param pkt Pointer to an AVPacket struct
+ * @return 0 on success, and a packet is returned. AVERROR(EAGAIN) if
+ * the list was empty.
+ */
+int avpriv_packet_list_get(AVPacketList **head, AVPacketList **tail,
+ AVPacket *pkt);
+
+/**
+ * Wipe the list and unref all the packets in it.
+ *
+ * @param head List head element
+ * @param tail List tail element
+ */
+void avpriv_packet_list_free(AVPacketList **head, AVPacketList **tail);
+
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp);