summaryrefslogtreecommitdiff
path: root/libswresample
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-05-19 18:42:11 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-05-19 19:23:37 +0200
commitf88f705abcb925cede3ffa392156489956e8c0b9 (patch)
treeda7bcc4cd973091499328a25df51c76a643d8359 /libswresample
parent7a59964ba9c2e39ccf500ae3e57e77abc9afdfa2 (diff)
swr: add swr_drop_output()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample')
-rw-r--r--libswresample/swresample.c31
-rw-r--r--libswresample/swresample.h7
-rw-r--r--libswresample/swresample_internal.h1
3 files changed, 38 insertions, 1 deletions
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, \
@@ -159,6 +159,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.
*/
int swr_inject_silence(struct SwrContext *s, int count);
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