[FFmpeg-cvslog] avfilter/af_aresample: Limit data per inserted packet

Michael Niedermayer git at videolan.org
Tue Nov 4 19:03:15 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Nov  4 16:01:07 2014 +0100| [09024fe681e1969cedff9cb8fcf949ac992b7c06] | committer: Michael Niedermayer

avfilter/af_aresample: Limit data per inserted packet

This avoids creating unwieldy large packets, which is allowed but
does not seem to be a good idea

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=09024fe681e1969cedff9cb8fcf949ac992b7c06
---

 libavfilter/af_aresample.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 7e9eae8..4f40602 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -41,6 +41,7 @@ typedef struct {
     struct SwrContext *swr;
     int64_t next_pts;
     int req_fullfilled;
+    int more_data;
 } AResampleContext;
 
 static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
 
     delay = swr_get_delay(aresample->swr, outlink->sample_rate);
     if (delay > 0)
-        n_out += delay;
+        n_out += FFMIN(delay, FFMAX(4096, n_out));
 
     outsamplesref = ff_get_audio_buffer(outlink, n_out);
 
@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
         return 0;
     }
 
+    aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers
+
     outsamplesref->nb_samples  = n_out;
 
     ret = ff_filter_frame(outlink, outsamplesref);
@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink)
     AVFilterLink *const inlink = outlink->src->inputs[0];
     int ret;
 
+    // First try to get data from the internal buffers
+    if (aresample->more_data) {
+        AVFrame *outsamplesref;
+
+        if (flush_frame(outlink, 0, &outsamplesref) >= 0) {
+            return ff_filter_frame(outlink, outsamplesref);
+        }
+    }
+    aresample->more_data = 0;
+
+    // Second request more data from the input
     aresample->req_fullfilled = 0;
     do{
         ret = ff_request_frame(ctx->inputs[0]);
     }while(!aresample->req_fullfilled && ret>=0);
 
+    // Third if we hit the end flush
     if (ret == AVERROR_EOF) {
         AVFrame *outsamplesref;
 



More information about the ffmpeg-cvslog mailing list