Commit 7093e215 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '6b15874f'

* commit '6b15874f':
  af_resample: do not touch the timestamps if we are not resampling
Merged-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parents 2dbaec69 6b15874f
...@@ -40,6 +40,7 @@ typedef struct ResampleContext { ...@@ -40,6 +40,7 @@ typedef struct ResampleContext {
AVAudioResampleContext *avr; AVAudioResampleContext *avr;
AVDictionary *options; AVDictionary *options;
int resampling;
int64_t next_pts; int64_t next_pts;
int64_t next_in_pts; int64_t next_in_pts;
...@@ -117,6 +118,8 @@ static int config_output(AVFilterLink *outlink) ...@@ -117,6 +118,8 @@ static int config_output(AVFilterLink *outlink)
char buf1[64], buf2[64]; char buf1[64], buf2[64];
int ret; int ret;
int64_t resampling_forced;
if (s->avr) { if (s->avr) {
avresample_close(s->avr); avresample_close(s->avr);
avresample_free(&s->avr); avresample_free(&s->avr);
...@@ -155,9 +158,15 @@ static int config_output(AVFilterLink *outlink) ...@@ -155,9 +158,15 @@ static int config_output(AVFilterLink *outlink)
if ((ret = avresample_open(s->avr)) < 0) if ((ret = avresample_open(s->avr)) < 0)
return ret; return ret;
outlink->time_base = (AVRational){ 1, outlink->sample_rate }; av_opt_get_int(s->avr, "force_resampling", 0, &resampling_forced);
s->next_pts = AV_NOPTS_VALUE; s->resampling = resampling_forced || (inlink->sample_rate != outlink->sample_rate);
s->next_in_pts = AV_NOPTS_VALUE;
if (s->resampling) {
outlink->time_base = (AVRational){ 1, outlink->sample_rate };
s->next_pts = AV_NOPTS_VALUE;
s->next_in_pts = AV_NOPTS_VALUE;
} else
outlink->time_base = inlink->time_base;
av_get_channel_layout_string(buf1, sizeof(buf1), av_get_channel_layout_string(buf1, sizeof(buf1),
-1, inlink ->channel_layout); -1, inlink ->channel_layout);
...@@ -240,7 +249,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -240,7 +249,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
av_assert0(!avresample_available(s->avr)); av_assert0(!avresample_available(s->avr));
if (s->next_pts == AV_NOPTS_VALUE) { if (s->resampling && s->next_pts == AV_NOPTS_VALUE) {
if (in->pts == AV_NOPTS_VALUE) { if (in->pts == AV_NOPTS_VALUE) {
av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, " av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, "
"assuming 0.\n"); "assuming 0.\n");
...@@ -259,22 +268,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -259,22 +268,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
goto fail; goto fail;
} }
out->sample_rate = outlink->sample_rate; if (s->resampling) {
/* Only convert in->pts if there is a discontinuous jump. out->sample_rate = outlink->sample_rate;
This ensures that out->pts tracks the number of samples actually /* Only convert in->pts if there is a discontinuous jump.
output by the resampler in the absence of such a jump. This ensures that out->pts tracks the number of samples actually
Otherwise, the rounding in av_rescale_q() and av_rescale() output by the resampler in the absence of such a jump.
causes off-by-1 errors. */ Otherwise, the rounding in av_rescale_q() and av_rescale()
if (in->pts != AV_NOPTS_VALUE && in->pts != s->next_in_pts) { causes off-by-1 errors. */
out->pts = av_rescale_q(in->pts, inlink->time_base, if (in->pts != AV_NOPTS_VALUE && in->pts != s->next_in_pts) {
outlink->time_base) - out->pts = av_rescale_q(in->pts, inlink->time_base,
av_rescale(delay, outlink->sample_rate, outlink->time_base) -
inlink->sample_rate); av_rescale(delay, outlink->sample_rate,
inlink->sample_rate);
} else
out->pts = s->next_pts;
s->next_pts = out->pts + out->nb_samples;
s->next_in_pts = in->pts + in->nb_samples;
} else } else
out->pts = s->next_pts; out->pts = in->pts;
s->next_pts = out->pts + out->nb_samples;
s->next_in_pts = in->pts + in->nb_samples;
ret = ff_filter_frame(outlink, out); ret = ff_filter_frame(outlink, out);
s->got_output = 1; s->got_output = 1;
......
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