[FFmpeg-devel] [PATCH 08/18] avformat: port AVFormatInternal->parse_queue to the new packet list API

James Almer jamrial at gmail.com
Wed Nov 18 18:52:37 EET 2020


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/internal.h |  3 +--
 libavformat/options.c  |  5 ++++-
 libavformat/utils.c    | 35 ++++++++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index a0649956e8..749e387931 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -89,8 +89,7 @@ struct AVFormatInternal {
     /**
      * Packets split by the parser get queued here.
      */
-    struct PacketListEntry *parse_queue;
-    struct PacketListEntry *parse_queue_end;
+    struct AVPacketList *parse_queue;
     /**
      * Remaining size available for raw_packet_buffer, in bytes.
      */
diff --git a/libavformat/options.c b/libavformat/options.c
index ee7a533aa0..a400419917 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -220,10 +220,13 @@ AVFormatContext *avformat_alloc_context(void)
         av_free(ic);
         return NULL;
     }
+    internal->parse_queue = av_packet_list_alloc();
     internal->packet_buffer = av_packet_list_alloc();
     internal->raw_packet_buffer = av_packet_list_alloc();
-    if (!internal->packet_buffer ||
+    if (!internal->parse_queue ||
+        !internal->packet_buffer ||
         !internal->raw_packet_buffer) {
+        av_packet_list_free(&internal->parse_queue);
         av_packet_list_free(&internal->packet_buffer);
         av_packet_list_free(&internal->raw_packet_buffer);
         av_free(internal);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 02c0ead44b..59979fb469 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1013,14 +1013,16 @@ static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, PacketLis
 {
 #if FF_API_PACKET_LIST
     struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer;
+    struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue;
 #else
     AVPacketList *packet_buffer = s->internal->packet_buffer;
+    AVPacketList *parse_queue = s->internal->parse_queue;
 #endif
 
     if (pktl->next)
         return pktl->next;
     if (pktl == packet_buffer->tail)
-        return s->internal->parse_queue;
+        return parse_queue->head;
     return NULL;
 }
 
@@ -1102,12 +1104,14 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
     AVStream *st       = s->streams[stream_index];
 #if FF_API_PACKET_LIST
     struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer;
+    struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue;
 #else
     AVPacketList *packet_buffer = s->internal->packet_buffer;
+    AVPacketList *parse_queue = s->internal->parse_queue;
 #endif
     PacketListEntry *pktl = packet_buffer->head ?
                             packet_buffer->head :
-                            s->internal->parse_queue;
+                            parse_queue->head;
     PacketListEntry *pktl_it;
 
     uint64_t shift;
@@ -1160,12 +1164,14 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st,
 {
 #if FF_API_PACKET_LIST
     struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer;
+    struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue;
 #else
     AVPacketList *packet_buffer = s->internal->packet_buffer;
+    AVPacketList *parse_queue = s->internal->parse_queue;
 #endif
     PacketListEntry *pktl = packet_buffer->head ?
                             packet_buffer->head :
-                            s->internal->parse_queue;
+                            parse_queue->head;
     int64_t cur_dts    = RELATIVE_TS_BASE;
 
     if (st->first_dts != AV_NOPTS_VALUE) {
@@ -1193,7 +1199,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st,
         }
         pktl          = packet_buffer->head ?
                         packet_buffer->head :
-                        s->internal->parse_queue;
+                        parse_queue->head;
         st->first_dts = cur_dts;
     } else if (st->cur_dts != RELATIVE_TS_BASE)
         return;
@@ -1230,8 +1236,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
                        st->codecpar->codec_id != AV_CODEC_ID_HEVC;
 #if FF_API_PACKET_LIST
     struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer;
+    struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue;
 #else
     AVPacketList *packet_buffer = s->internal->packet_buffer;
+    AVPacketList *parse_queue = s->internal->parse_queue;
 #endif
 
     if (s->flags & AVFMT_FLAG_NOFILLIN)
@@ -1310,7 +1318,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
         }
     }
 
-    if (pkt->duration > 0 && (packet_buffer->head || s->internal->parse_queue))
+    if (pkt->duration > 0 && (packet_buffer->head || parse_queue->head))
         update_initial_durations(s, st, pkt->stream_index, pkt->duration);
 
     /* Correct timestamps with byte offset if demuxers only have timestamps
@@ -1511,8 +1519,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
 
         compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts);
 
-        ret = avpriv_packet_list_put(&s->internal->parse_queue,
-                                 &s->internal->parse_queue_end,
+        ret = av_packet_list_put(s->internal->parse_queue,
                                  &out_pkt, NULL, 0);
         if (ret < 0) {
             av_packet_unref(&out_pkt);
@@ -1540,8 +1547,13 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, i, got_packet = 0;
     AVDictionary *metadata = NULL;
+#if FF_API_PACKET_LIST
+    struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue;
+#else
+    AVPacketList *parse_queue = s->internal->parse_queue;
+#endif
 
-    while (!got_packet && !s->internal->parse_queue) {
+    while (!got_packet && !parse_queue->head) {
         AVStream *st;
 
         /* read next packet */
@@ -1662,8 +1674,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    if (!got_packet && s->internal->parse_queue)
-        ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt);
+    if (!got_packet && parse_queue->head)
+        ret = av_packet_list_get(s->internal->parse_queue, pkt, 0);
 
     if (ret >= 0) {
         AVStream *st = s->streams[pkt->stream_index];
@@ -1843,7 +1855,7 @@ static void flush_packet_queue(AVFormatContext *s)
 {
     if (!s->internal)
         return;
-    avpriv_packet_list_free(&s->internal->parse_queue,       &s->internal->parse_queue_end);
+    av_packet_list_flush(s->internal->parse_queue);
     av_packet_list_flush(s->internal->packet_buffer);
     av_packet_list_flush(s->internal->raw_packet_buffer);
 
@@ -4472,6 +4484,7 @@ void avformat_free_context(AVFormatContext *s)
     av_dict_free(&s->internal->id3v2_meta);
     av_freep(&s->streams);
     flush_packet_queue(s);
+    av_packet_list_free(&s->internal->parse_queue);
     av_packet_list_free(&s->internal->packet_buffer);
     av_packet_list_free(&s->internal->raw_packet_buffer);
     av_freep(&s->internal);
-- 
2.29.2



More information about the ffmpeg-devel mailing list