Commit 97da6817 authored by Michael Niedermayer's avatar Michael Niedermayer

avfilter/af_aresample: split flushing code out

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent e4f8a973
...@@ -223,31 +223,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) ...@@ -223,31 +223,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
return ret; return ret;
} }
static int request_frame(AVFilterLink *outlink) static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref_ret)
{ {
AVFilterContext *ctx = outlink->src; AVFilterContext *ctx = outlink->src;
AResampleContext *aresample = ctx->priv; AResampleContext *aresample = ctx->priv;
AVFilterLink *const inlink = outlink->src->inputs[0]; AVFilterLink *const inlink = outlink->src->inputs[0];
int ret;
aresample->req_fullfilled = 0;
do{
ret = ff_request_frame(ctx->inputs[0]);
}while(!aresample->req_fullfilled && ret>=0);
if (ret == AVERROR_EOF) {
AVFrame *outsamplesref; AVFrame *outsamplesref;
int n_out = 4096; int n_out = 4096;
int64_t pts; int64_t pts;
outsamplesref = ff_get_audio_buffer(outlink, n_out); outsamplesref = ff_get_audio_buffer(outlink, n_out);
*outsamplesref_ret = outsamplesref;
if (!outsamplesref) if (!outsamplesref)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pts = swr_next_pts(aresample->swr, INT64_MIN); pts = swr_next_pts(aresample->swr, INT64_MIN);
pts = ROUNDED_DIV(pts, inlink->sample_rate); pts = ROUNDED_DIV(pts, inlink->sample_rate);
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, 0, 0); n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, final ? NULL : (void*)outsamplesref->extended_data, 0);
if (n_out <= 0) { if (n_out <= 0) {
av_frame_free(&outsamplesref); av_frame_free(&outsamplesref);
return (n_out == 0) ? AVERROR_EOF : n_out; return (n_out == 0) ? AVERROR_EOF : n_out;
...@@ -258,6 +251,27 @@ static int request_frame(AVFilterLink *outlink) ...@@ -258,6 +251,27 @@ static int request_frame(AVFilterLink *outlink)
outsamplesref->pts = pts; outsamplesref->pts = pts;
return 0;
}
static int request_frame(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AResampleContext *aresample = ctx->priv;
AVFilterLink *const inlink = outlink->src->inputs[0];
int ret;
aresample->req_fullfilled = 0;
do{
ret = ff_request_frame(ctx->inputs[0]);
}while(!aresample->req_fullfilled && ret>=0);
if (ret == AVERROR_EOF) {
AVFrame *outsamplesref;
if ((ret = flush_frame(outlink, 1, &outsamplesref)) < 0)
return ret;
return ff_filter_frame(outlink, outsamplesref); return ff_filter_frame(outlink, outsamplesref);
} }
return ret; return ret;
......
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