[FFmpeg-cvslog] swr: add swr_drop_output()

Michael Niedermayer git at videolan.org
Sat May 19 19:28:56 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat May 19 18:42:11 2012 +0200| [f88f705abcb925cede3ffa392156489956e8c0b9] | committer: Michael Niedermayer

swr: add swr_drop_output()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f88f705abcb925cede3ffa392156489956e8c0b9
---

 libswresample/swresample.c          |   31 +++++++++++++++++++++++++++++++
 libswresample/swresample.h          |    7 ++++++-
 libswresample/swresample_internal.h |    1 +
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 086c421..83bec20 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 61ac2d4..e027f56 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 15687f7..30ab6cd 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



More information about the ffmpeg-cvslog mailing list