mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-03-28 12:32:17 +02:00
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>
This commit is contained in:
parent
15ca8311e6
commit
d95f15b14d
@ -369,20 +369,18 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
static int mp3_queue_flush(AVFormatContext *s)
|
static int mp3_queue_flush(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
MP3Context *mp3 = s->priv_data;
|
MP3Context *mp3 = s->priv_data;
|
||||||
AVPacketList *pktl;
|
AVPacket pkt;
|
||||||
int ret = 0, write = 1;
|
int ret = 0, write = 1;
|
||||||
|
|
||||||
ff_id3v2_finish(&mp3->id3, s->pb, s->metadata_header_padding);
|
ff_id3v2_finish(&mp3->id3, s->pb, s->metadata_header_padding);
|
||||||
mp3_write_xing(s);
|
mp3_write_xing(s);
|
||||||
|
|
||||||
while ((pktl = mp3->queue)) {
|
while (mp3->queue) {
|
||||||
if (write && (ret = mp3_write_audio_packet(s, &pktl->pkt)) < 0)
|
ff_packet_list_get(&mp3->queue, &mp3->queue_end, &pkt);
|
||||||
|
if (write && (ret = mp3_write_audio_packet(s, &pkt)) < 0)
|
||||||
write = 0;
|
write = 0;
|
||||||
av_packet_unref(&pktl->pkt);
|
av_packet_unref(&pkt);
|
||||||
mp3->queue = pktl->next;
|
|
||||||
av_freep(&pktl);
|
|
||||||
}
|
}
|
||||||
mp3->queue_end = NULL;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,21 +512,14 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
if (pkt->stream_index == mp3->audio_stream_idx) {
|
if (pkt->stream_index == mp3->audio_stream_idx) {
|
||||||
if (mp3->pics_to_write) {
|
if (mp3->pics_to_write) {
|
||||||
/* buffer audio packets until we get all the pictures */
|
/* 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) {
|
if (ret < 0) {
|
||||||
av_freep(&pktl);
|
|
||||||
av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
|
av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
|
||||||
mp3->pics_to_write = 0;
|
mp3->pics_to_write = 0;
|
||||||
mp3_queue_flush(s);
|
mp3_queue_flush(s);
|
||||||
return mp3_write_audio_packet(s, pkt);
|
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
|
} else
|
||||||
return mp3_write_audio_packet(s, pkt);
|
return mp3_write_audio_packet(s, pkt);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user