From d95f15b14d5cf56af4b157423e93609003858c5e Mon Sep 17 00:00:00 2001 From: James Almer Date: Mon, 26 Mar 2018 15:02:39 -0300 Subject: avformat/mp3enc: use AVPacketList helper functions to queue packets Simplifies code. Reviewed-by: Michael Niedermayer Signed-off-by: James Almer --- libavformat/mp3enc.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 8479e2485b..dd662f5473 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, FF_PACKETLIST_FLAG_REF_PACKET); - 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 { -- cgit v1.2.3