From 00cae86754ef93fd4fff8d33424ea6304b126a32 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 21 Jan 2013 00:52:14 +0100 Subject: [PATCH] swr: support first_pts Trolled-by: Daemon404 Signed-off-by: Michael Niedermayer --- libswresample/swresample.c | 11 ++++++++++- libswresample/swresample_internal.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libswresample/swresample.c b/libswresample/swresample.c index ad33467e2a..3387ea3860 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -108,6 +108,8 @@ static const AVOption options[]={ , OFFSET(max_soft_compensation),AV_OPT_TYPE_FLOAT ,{.dbl=0 }, INT_MIN, INT_MAX , PARAM }, {"async" , "simplified 1 parameter audio timestamp matching, 0(disabled), 1(filling and trimming), >1(maximum stretch/squeeze in samples per second)" , OFFSET(async) , AV_OPT_TYPE_FLOAT ,{.dbl=0 }, INT_MIN, INT_MAX , PARAM }, +{"first_pts" , "Assume the first pts should be this value (in samples)." + , OFFSET(firstpts_in_samples), AV_OPT_TYPE_INT64 ,{.i64=AV_NOPTS_VALUE }, INT64_MIN,INT64_MAX, PARAM }, { "matrix_encoding" , "set matrixed stereo encoding" , OFFSET(matrix_encoding), AV_OPT_TYPE_INT ,{.i64 = AV_MATRIX_ENCODING_NONE}, AV_MATRIX_ENCODING_NONE, AV_MATRIX_ENCODING_NB-1, PARAM, "matrix_encoding" }, { "none", "select none", 0, AV_OPT_TYPE_CONST, { .i64 = AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" }, @@ -296,6 +298,13 @@ av_cold int swr_init(struct SwrContext *s){ set_audiodata_fmt(&s-> in, s-> in_sample_fmt); set_audiodata_fmt(&s->out, s->out_sample_fmt); + if (s->firstpts_in_samples != AV_NOPTS_VALUE) { + if (!s->async && s->min_compensation >= FLT_MAX/2) + s->async = 1; + s->firstpts = + s->outpts = s->firstpts_in_samples * s->out_sample_rate; + } + if (s->async) { if (s->min_compensation >= FLT_MAX/2) s->min_compensation = 0.001; @@ -877,7 +886,7 @@ int64_t swr_next_pts(struct SwrContext *s, int64_t pts){ double fdelta = delta /(double)(s->in_sample_rate * (int64_t)s->out_sample_rate); if(fabs(fdelta) > s->min_compensation) { - if(!s->outpts || fabs(fdelta) > s->min_hard_compensation){ + if(s->outpts == s->firstpts || fabs(fdelta) > s->min_hard_compensation){ int ret; if(delta > 0) ret = swr_inject_silence(s, delta / s->out_sample_rate); else ret = swr_drop_output (s, -delta / s-> in_sample_rate); diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index be332d0039..3f8090481b 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -102,6 +102,7 @@ struct SwrContext { float soft_compensation_duration; ///< swr duration over which soft compensation is applied float max_soft_compensation; ///< swr maximum soft compensation in seconds over soft_compensation_duration float async; ///< swr simple 1 parameter async, similar to ffmpegs -async + int64_t firstpts_in_samples; ///< swr first pts in samples int resample_first; ///< 1 if resampling must come first, 0 if rematrixing int rematrix; ///< flag to indicate if rematrixing is needed (basically if input and output layouts mismatch) @@ -120,6 +121,7 @@ struct SwrContext { int resample_in_constraint; ///< 1 if the input end was reach before the output end, 0 otherwise int flushed; ///< 1 if data is to be flushed and no further input is expected int64_t outpts; ///< output PTS + int64_t firstpts; ///< first PTS int drop_output; ///< number of output samples to drop struct AudioConvert *in_convert; ///< input conversion context