diff mbox series

[FFmpeg-devel,16/18] avformat/matroskadec: port to the new packet list API

Message ID 20201118165247.4130-17-jamrial@gmail.com
State New
Headers show
Series AVPacketList public API | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

James Almer Nov. 18, 2020, 4:52 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 0970e1d1ef..4be31daa93 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -366,8 +366,7 @@  typedef struct MatroskaDemuxContext {
     int64_t segment_start;
 
     /* the packet queue */
-    PacketListEntry *queue;
-    PacketListEntry *queue_end;
+    AVPacketList *queue;
 
     int done;
 
@@ -2872,6 +2871,10 @@  static int matroska_read_header(AVFormatContext *s)
     }
     ebml_free(ebml_syntax, &ebml);
 
+    matroska->queue = av_packet_list_alloc();
+    if (!matroska->queue)
+        return AVERROR(ENOMEM);
+
     /* The next thing is a segment. */
     pos = avio_tell(matroska->ctx->pb);
     res = ebml_parse(matroska, matroska_segments, matroska);
@@ -2988,11 +2991,10 @@  fail:
 static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
                                    AVPacket *pkt)
 {
-    if (matroska->queue) {
+    if (!av_packet_list_get(matroska->queue, pkt, 0)) {
         MatroskaTrack *tracks = matroska->tracks.elem;
         MatroskaTrack *track;
 
-        avpriv_packet_list_get(&matroska->queue, &matroska->queue_end, pkt);
         track = &tracks[pkt->stream_index];
         if (track->has_palette) {
             uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
@@ -3014,7 +3016,7 @@  static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
  */
 static void matroska_clear_queue(MatroskaDemuxContext *matroska)
 {
-    avpriv_packet_list_free(&matroska->queue, &matroska->queue_end);
+    av_packet_list_flush(matroska->queue);
 }
 
 static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
@@ -3180,7 +3182,7 @@  static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,
         track->audio.buf_timecode = AV_NOPTS_VALUE;
         pkt->pos                  = pos;
         pkt->stream_index         = st->index;
-        ret = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0);
+        ret = av_packet_list_put(matroska->queue, pkt, NULL, 0);
         if (ret < 0) {
             av_packet_unref(pkt);
             return AVERROR(ENOMEM);
@@ -3402,7 +3404,7 @@  static int matroska_parse_webvtt(MatroskaDemuxContext *matroska,
     pkt->duration = duration;
     pkt->pos = pos;
 
-    err = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0);
+    err = av_packet_list_put(matroska->queue, pkt, NULL, 0);
     if (err < 0) {
         av_packet_unref(pkt);
         return AVERROR(ENOMEM);
@@ -3513,7 +3515,7 @@  FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-    res = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0);
+    res = av_packet_list_put(matroska->queue, pkt, NULL, 0);
     if (res < 0) {
         av_packet_unref(pkt);
         return AVERROR(ENOMEM);
@@ -3823,6 +3825,7 @@  static int matroska_read_close(AVFormatContext *s)
     int n;
 
     matroska_clear_queue(matroska);
+    av_packet_list_free(&matroska->queue);
 
     for (n = 0; n < matroska->tracks.nb_elem; n++)
         if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
@@ -3886,8 +3889,8 @@  static int webm_clusters_start_with_keyframe(AVFormatContext *s)
     before_pos = avio_tell(s->pb);
     while (1) {
         uint64_t cluster_id, cluster_length;
-        int read;
-        AVPacket *pkt;
+        int read, flags;
+        AVPacket pkt;
         avio_seek(s->pb, cluster_pos, SEEK_SET);
         // read cluster id and length
         read = ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id, 1);
@@ -3900,13 +3903,15 @@  static int webm_clusters_start_with_keyframe(AVFormatContext *s)
         matroska_reset_status(matroska, 0, cluster_pos);
         matroska_clear_queue(matroska);
         if (matroska_parse_cluster(matroska) < 0 ||
-            !matroska->queue) {
+            av_packet_list_peek(matroska->queue, NULL, 0)) {
             break;
         }
-        pkt = &matroska->queue->pkt;
+        av_packet_list_peek(matroska->queue, &pkt, 0);
+        flags = pkt.flags;
+        av_packet_unref(&pkt);
         // 4 + read is the length of the cluster id and the cluster length field.
         cluster_pos += 4 + read + cluster_length;
-        if (!(pkt->flags & AV_PKT_FLAG_KEY)) {
+        if (!(flags & AV_PKT_FLAG_KEY)) {
             rv = 0;
             break;
         }