[FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: switch to new FIFO API

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jan 24 16:46:05 EET 2022


From: Anton Khirnov <anton at khirnov.net>

---
 libavformat/swfenc.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 1fd2ad81a3..9eb22ee9b3 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -38,7 +38,7 @@ typedef struct SWFEncContext {
     int swf_frame_number;
     int video_frame_number;
     int tag;
-    AVFifoBuffer *audio_fifo;
+    AVFifo *audio_fifo;
     AVCodecParameters *audio_par, *video_par;
     AVStream *video_st;
 } SWFEncContext;
@@ -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 */
@@ -535,7 +541,7 @@ static void swf_deinit(AVFormatContext *s)
 {
     SWFEncContext *swf = s->priv_data;
 
-    av_fifo_freep(&swf->audio_fifo);
+    av_fifo_freep2(&swf->audio_fifo);
 }
 
 #if CONFIG_SWF_MUXER
-- 
2.32.0



More information about the ffmpeg-devel mailing list