From f88f705abcb925cede3ffa392156489956e8c0b9 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 19 May 2012 18:42:11 +0200 Subject: swr: add swr_drop_output() Signed-off-by: Michael Niedermayer --- libswresample/swresample.c | 31 +++++++++++++++++++++++++++++++ libswresample/swresample.h | 7 ++++++- libswresample/swresample_internal.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'libswresample') diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 086c421bad..83bec202eb 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -596,6 +596,27 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun AudioData * in= &s->in; AudioData *out= &s->out; + if(s->drop_output > 0){ + int ret; + AudioData tmp = s->out; + uint8_t *tmp_arg[SWR_CH_MAX]; + tmp.count = 0; + tmp.data = NULL; + if((ret=realloc_audio(&tmp, s->drop_output))<0) + return ret; + + reversefill_audiodata(&tmp, tmp_arg); + s->drop_output *= -1; //FIXME find a less hackish solution + ret = swr_convert(s, tmp_arg, -s->drop_output, in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesnt matter + s->drop_output *= -1; + if(ret>0) + s->drop_output -= ret; + + av_freep(&tmp.data); + if(s->drop_output || !out_arg) + return 0; + } + if(!in_arg){ if(s->in_buffer_count){ if (s->resample && !s->flushed) { @@ -676,6 +697,16 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun } } +int swr_drop_output(struct SwrContext *s, int count){ + s->drop_output += count; + + if(s->drop_output <= 0) + return 0; + + av_log(s, AV_LOG_VERBOSE, "discarding %d audio samples\n", count); + return swr_convert(s, NULL, s->drop_output, NULL, 0); +} + int swr_inject_silence(struct SwrContext *s, int count){ int ret, i; AudioData silence = s->out; diff --git a/libswresample/swresample.h b/libswresample/swresample.h index 61ac2d4317..e027f5619c 100644 --- a/libswresample/swresample.h +++ b/libswresample/swresample.h @@ -30,7 +30,7 @@ #include "libavutil/samplefmt.h" #define LIBSWRESAMPLE_VERSION_MAJOR 0 -#define LIBSWRESAMPLE_VERSION_MINOR 13 +#define LIBSWRESAMPLE_VERSION_MINOR 14 #define LIBSWRESAMPLE_VERSION_MICRO 100 #define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \ @@ -158,6 +158,11 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); */ int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride); +/** + * Drops the specified number of output samples. + */ +int swr_drop_output(struct SwrContext *s, int count); + /** * Injects the specified number of silence samples. */ diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index 15687f7865..30ab6cd1a1 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -77,6 +77,7 @@ struct SwrContext { int in_buffer_count; ///< cached buffer length 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 + int drop_output; ///< number of output samples to drop struct AudioConvert *in_convert; ///< input conversion context struct AudioConvert *out_convert; ///< output conversion context -- cgit v1.2.3