aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-03-26 15:02:39 -0300
committerJames Almer <jamrial@gmail.com>2018-04-04 00:15:39 -0300
commitd95f15b14d5cf56af4b157423e93609003858c5e (patch)
treeab9e1bb33676bce6991e4c7d4ed2b71224cdb999 /libavformat
parent15ca8311e68d0a88117bce7e22f4bb423737e3d9 (diff)
downloadffmpeg-d95f15b14d5cf56af4b157423e93609003858c5e.tar.gz
avformat/mp3enc: use AVPacketList helper functions to queue packets
Simplifies code. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mp3enc.c23
1 files changed, 7 insertions, 16 deletions
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 {