[FFmpeg-cvslog] swr: add swr_inject_silence()

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:39:12 2012 +0200| [7a59964ba9c2e39ccf500ae3e57e77abc9afdfa2] | committer: Michael Niedermayer

swr: add swr_inject_silence()

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

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

 libswresample/swresample.c |   24 ++++++++++++++++++++++++
 libswresample/swresample.h |    7 ++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 4718ce8..086c421 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -676,3 +676,27 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
     }
 }
 
+int swr_inject_silence(struct SwrContext *s, int count){
+    int ret, i;
+    AudioData silence = s->out;
+    uint8_t *tmp_arg[SWR_CH_MAX];
+
+    if(count <= 0)
+        return 0;
+
+    silence.count = 0;
+    silence.data  = NULL;
+    if((ret=realloc_audio(&silence, count))<0)
+        return ret;
+
+    if(silence.planar) for(i=0; i<silence.ch_count; i++) {
+        memset(silence.ch[i], silence.bps==1 ? 0x80 : 0, count*silence.bps);
+    } else
+        memset(silence.ch[0], silence.bps==1 ? 0x80 : 0, count*silence.bps*silence.ch_count);
+
+    reversefill_audiodata(&silence, tmp_arg);
+    av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
+    ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
+    av_freep(&silence.data);
+    return ret;
+}
diff --git a/libswresample/swresample.h b/libswresample/swresample.h
index 43112f9..61ac2d4 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 12
+#define LIBSWRESAMPLE_VERSION_MINOR 13
 #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);
 
 /**
+ * Injects the specified number of silence samples.
+ */
+int swr_inject_silence(struct SwrContext *s, int count);
+
+/**
  * Gets the delay the next input sample will experience relative to the next output sample.
  *
  * Swresample can buffer data if more input has been provided than available



More information about the ffmpeg-cvslog mailing list