Commit 09024fe6 authored by Michael Niedermayer's avatar 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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 97da6817
...@@ -41,6 +41,7 @@ typedef struct { ...@@ -41,6 +41,7 @@ typedef struct {
struct SwrContext *swr; struct SwrContext *swr;
int64_t next_pts; int64_t next_pts;
int req_fullfilled; int req_fullfilled;
int more_data;
} AResampleContext; } AResampleContext;
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
...@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) ...@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
delay = swr_get_delay(aresample->swr, outlink->sample_rate); delay = swr_get_delay(aresample->swr, outlink->sample_rate);
if (delay > 0) if (delay > 0)
n_out += delay; n_out += FFMIN(delay, FFMAX(4096, n_out));
outsamplesref = ff_get_audio_buffer(outlink, n_out); outsamplesref = ff_get_audio_buffer(outlink, n_out);
...@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) ...@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
return 0; 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; outsamplesref->nb_samples = n_out;
ret = ff_filter_frame(outlink, outsamplesref); ret = ff_filter_frame(outlink, outsamplesref);
...@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink) ...@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink)
AVFilterLink *const inlink = outlink->src->inputs[0]; AVFilterLink *const inlink = outlink->src->inputs[0];
int ret; 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; aresample->req_fullfilled = 0;
do{ do{
ret = ff_request_frame(ctx->inputs[0]); ret = ff_request_frame(ctx->inputs[0]);
}while(!aresample->req_fullfilled && ret>=0); }while(!aresample->req_fullfilled && ret>=0);
// Third if we hit the end flush
if (ret == AVERROR_EOF) { if (ret == AVERROR_EOF) {
AVFrame *outsamplesref; AVFrame *outsamplesref;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment