diff mbox series

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

Message ID 20201118165247.4130-16-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/aiffenc.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index 7c28109814..4fa77c21bf 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -37,7 +37,7 @@  typedef struct AIFFOutputContext {
     int64_t frames;
     int64_t ssnd;
     int audio_stream_idx;
-    PacketListEntry *pict_list, *pict_list_end;
+    AVPacketList *pict_list;
     int write_id3v2;
     int id3v2_version;
 } AIFFOutputContext;
@@ -47,10 +47,10 @@  static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff)
     int ret;
     uint64_t pos, end, size;
     ID3v2EncContext id3v2 = { 0 };
+    AVPacket pkt;
     AVIOContext *pb = s->pb;
-    PacketListEntry *pict_list = aiff->pict_list;
 
-    if (!s->metadata && !s->nb_chapters && !aiff->pict_list)
+    if (!s->metadata && !s->nb_chapters && av_packet_list_peek(aiff->pict_list, NULL, 0))
         return 0;
 
     avio_wl32(pb, MKTAG('I', 'D', '3', ' '));
@@ -59,10 +59,11 @@  static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff)
 
     ff_id3v2_start(&id3v2, pb, aiff->id3v2_version, ID3v2_DEFAULT_MAGIC);
     ff_id3v2_write_metadata(s, &id3v2);
-    while (pict_list) {
-        if ((ret = ff_id3v2_write_apic(s, &id3v2, &pict_list->pkt)) < 0)
+    while (!av_packet_list_get(aiff->pict_list, &pkt, 0)) {
+        ret = ff_id3v2_write_apic(s, &id3v2, &pkt);
+        av_packet_unref(&pkt);
+        if (ret < 0)
             return ret;
-        pict_list = pict_list->next;
     }
     ff_id3v2_finish(&id3v2, pb, s->metadata_header_padding);
 
@@ -119,6 +120,10 @@  static int aiff_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
+    aiff->pict_list = av_packet_list_alloc();
+    if (!aiff->pict_list)
+        return AVERROR(ENOMEM);
+
     par = s->streams[aiff->audio_stream_idx]->codecpar;
 
     /* First verify if format is ok */
@@ -221,8 +226,7 @@  static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
         if (s->streams[pkt->stream_index]->nb_frames >= 1)
             return 0;
 
-        return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end,
-                                  pkt, av_packet_ref, 0);
+        return av_packet_list_put(aiff->pict_list, pkt, av_packet_ref, 0);
     }
 
     return 0;
@@ -273,7 +277,7 @@  static void aiff_deinit(AVFormatContext *s)
 {
     AIFFOutputContext *aiff = s->priv_data;
 
-    avpriv_packet_list_free(&aiff->pict_list, &aiff->pict_list_end);
+    av_packet_list_free(&aiff->pict_list);
 }
 
 #define OFFSET(x) offsetof(AIFFOutputContext, x)