[FFmpeg-devel] [PATCH 25/35] lavf/swfenc: switch to new FIFO API
Anton Khirnov
anton at khirnov.net
Tue Jan 11 22:46:00 EET 2022
---
libavformat/swfenc.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 1fd2ad81a3..ca9a358ccc 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -211,7 +211,7 @@ static int swf_write_header(AVFormatContext *s)
}
if (par->codec_id == AV_CODEC_ID_MP3) {
swf->audio_par = par;
- swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE);
+ swf->audio_fifo = av_fifo_alloc2(AUDIO_FIFO_SIZE, 1, 0);
if (!swf->audio_fifo)
return AVERROR(ENOMEM);
} else {
@@ -362,6 +362,12 @@ static int swf_write_header(AVFormatContext *s)
return 0;
}
+static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
+{
+ avio_write(opaque, buf, *nb_elems);
+ return 0;
+}
+
static int swf_write_video(AVFormatContext *s,
AVCodecParameters *par, const uint8_t *buf, int size, unsigned pkt_flags)
{
@@ -454,12 +460,12 @@ static int swf_write_video(AVFormatContext *s,
swf->swf_frame_number++;
/* streaming sound always should be placed just before showframe tags */
- if (swf->audio_par && av_fifo_size(swf->audio_fifo)) {
- int frame_size = av_fifo_size(swf->audio_fifo);
+ if (swf->audio_par && av_fifo_can_read(swf->audio_fifo)) {
+ size_t frame_size = av_fifo_can_read(swf->audio_fifo);
put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
avio_wl16(pb, swf->sound_samples);
avio_wl16(pb, 0); // seek samples
- av_fifo_generic_read(swf->audio_fifo, pb, frame_size, (void*)avio_write);
+ av_fifo_read_to_cb(swf->audio_fifo, fifo_avio_wrapper, pb, &frame_size);
put_swf_end_tag(s);
/* update FIFO */
@@ -482,12 +488,12 @@ static int swf_write_audio(AVFormatContext *s,
if (swf->swf_frame_number == 16000)
av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
- if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) {
+ if (av_fifo_can_write(swf->audio_fifo) < size) {
av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
return -1;
}
- av_fifo_generic_write(swf->audio_fifo, buf, size, NULL);
+ av_fifo_write(swf->audio_fifo, buf, size);
swf->sound_samples += av_get_audio_frame_duration2(par, size);
/* if audio only stream make sure we add swf frames */
--
2.33.0
More information about the ffmpeg-devel
mailing list