diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-11-04 16:01:07 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-11-04 17:17:24 +0100 |
commit | 09024fe681e1969cedff9cb8fcf949ac992b7c06 (patch) | |
tree | 0f60e7bd13ecefe913387b2ec38831f03b9cc7a6 /libavfilter/af_aresample.c | |
parent | 97da68172aa7a72a032a3eff87984f891cbc50b8 (diff) |
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@gmx.at>
Diffstat (limited to 'libavfilter/af_aresample.c')
-rw-r--r-- | libavfilter/af_aresample.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index 7e9eae8071..4f40602038 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; |