1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avfilter/af_aresample: split flushing code out

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-11-04 16:00:07 +01:00
parent e4f8a973aa
commit 97da68172a

View File

@ -223,6 +223,37 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
return ret;
}
static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref_ret)
{
AVFilterContext *ctx = outlink->src;
AResampleContext *aresample = ctx->priv;
AVFilterLink *const inlink = outlink->src->inputs[0];
AVFrame *outsamplesref;
int n_out = 4096;
int64_t pts;
outsamplesref = ff_get_audio_buffer(outlink, n_out);
*outsamplesref_ret = outsamplesref;
if (!outsamplesref)
return AVERROR(ENOMEM);
pts = swr_next_pts(aresample->swr, INT64_MIN);
pts = ROUNDED_DIV(pts, inlink->sample_rate);
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, final ? NULL : (void*)outsamplesref->extended_data, 0);
if (n_out <= 0) {
av_frame_free(&outsamplesref);
return (n_out == 0) ? AVERROR_EOF : n_out;
}
outsamplesref->sample_rate = outlink->sample_rate;
outsamplesref->nb_samples = n_out;
outsamplesref->pts = pts;
return 0;
}
static int request_frame(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
@ -237,26 +268,9 @@ static int request_frame(AVFilterLink *outlink)
if (ret == AVERROR_EOF) {
AVFrame *outsamplesref;
int n_out = 4096;
int64_t pts;
outsamplesref = ff_get_audio_buffer(outlink, n_out);
if (!outsamplesref)
return AVERROR(ENOMEM);
pts = swr_next_pts(aresample->swr, INT64_MIN);
pts = ROUNDED_DIV(pts, inlink->sample_rate);
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, 0, 0);
if (n_out <= 0) {
av_frame_free(&outsamplesref);
return (n_out == 0) ? AVERROR_EOF : n_out;
}
outsamplesref->sample_rate = outlink->sample_rate;
outsamplesref->nb_samples = n_out;
outsamplesref->pts = pts;
if ((ret = flush_frame(outlink, 1, &outsamplesref)) < 0)
return ret;
return ff_filter_frame(outlink, outsamplesref);
}