summaryrefslogtreecommitdiff
path: root/libavcodec/avpacket.c
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/avpacket.c
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/avpacket.c')
-rw-r--r--libavcodec/avpacket.c67
1 files changed, 67 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;