Browse code

swr: add swr_inject_silence()

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

Michael Niedermayer authored on 2012/05/20 01:39:12
Showing 2 changed files
... ...
@@ -676,3 +676,27 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
676 676
     }
677 677
 }
678 678
 
679
+int swr_inject_silence(struct SwrContext *s, int count){
680
+    int ret, i;
681
+    AudioData silence = s->out;
682
+    uint8_t *tmp_arg[SWR_CH_MAX];
683
+
684
+    if(count <= 0)
685
+        return 0;
686
+
687
+    silence.count = 0;
688
+    silence.data  = NULL;
689
+    if((ret=realloc_audio(&silence, count))<0)
690
+        return ret;
691
+
692
+    if(silence.planar) for(i=0; i<silence.ch_count; i++) {
693
+        memset(silence.ch[i], silence.bps==1 ? 0x80 : 0, count*silence.bps);
694
+    } else
695
+        memset(silence.ch[0], silence.bps==1 ? 0x80 : 0, count*silence.bps*silence.ch_count);
696
+
697
+    reversefill_audiodata(&silence, tmp_arg);
698
+    av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
699
+    ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
700
+    av_freep(&silence.data);
701
+    return ret;
702
+}
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/samplefmt.h"
31 31
 
32 32
 #define LIBSWRESAMPLE_VERSION_MAJOR 0
33
-#define LIBSWRESAMPLE_VERSION_MINOR 12
33
+#define LIBSWRESAMPLE_VERSION_MINOR 13
34 34
 #define LIBSWRESAMPLE_VERSION_MICRO 100
35 35
 
36 36
 #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);
159 159
 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
160 160
 
161 161
 /**
162
+ * Injects the specified number of silence samples.
163
+ */
164
+int swr_inject_silence(struct SwrContext *s, int count);
165
+
166
+/**
162 167
  * Gets the delay the next input sample will experience relative to the next output sample.
163 168
  *
164 169
  * Swresample can buffer data if more input has been provided than available