[FFmpeg-devel] [PATCH 5/5] avformat/mp3enc: use AVPacketList helper functions to queue packets

James Almer jamrial at gmail.com
Mon Mar 26 21:02:39 EEST 2018


Simplifies code.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/mp3enc.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 8479e2485b..78e231fbfd 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -369,20 +369,18 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
 static int mp3_queue_flush(AVFormatContext *s)
 {
     MP3Context *mp3 = s->priv_data;
-    AVPacketList *pktl;
+    AVPacket pkt;
     int ret = 0, write = 1;
 
     ff_id3v2_finish(&mp3->id3, s->pb, s->metadata_header_padding);
     mp3_write_xing(s);
 
-    while ((pktl = mp3->queue)) {
-        if (write && (ret = mp3_write_audio_packet(s, &pktl->pkt)) < 0)
+    while (mp3->queue) {
+        ff_packet_list_get(&mp3->queue, &mp3->queue_end, &pkt);
+        if (write && (ret = mp3_write_audio_packet(s, &pkt)) < 0)
             write = 0;
-        av_packet_unref(&pktl->pkt);
-        mp3->queue = pktl->next;
-        av_freep(&pktl);
+        av_packet_unref(&pkt);
     }
-    mp3->queue_end = NULL;
     return ret;
 }
 
@@ -514,21 +512,14 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (pkt->stream_index == mp3->audio_stream_idx) {
         if (mp3->pics_to_write) {
             /* buffer audio packets until we get all the pictures */
-            AVPacketList *pktl = av_mallocz(sizeof(*pktl));
+            int ret = ff_packet_list_put(&mp3->queue, &mp3->queue_end, pkt, 1);
 
-            if (!pktl || av_packet_ref(&pktl->pkt, pkt) < 0) {
-                av_freep(&pktl);
+            if (ret < 0) {
                 av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
                 mp3->pics_to_write = 0;
                 mp3_queue_flush(s);
                 return mp3_write_audio_packet(s, pkt);
             }
-
-            if (mp3->queue_end)
-                mp3->queue_end->next = pktl;
-            else
-                mp3->queue = pktl;
-            mp3->queue_end = pktl;
         } else
             return mp3_write_audio_packet(s, pkt);
     } else {
-- 
2.16.2



More information about the ffmpeg-devel mailing list