Browse code

Add silence support for AV_SAMPLE_FMT_U8.

Signed-off-by: Anton Khirnov <anton@khirnov.net>

Alex Converse authored on 2011/04/05 08:07:23
Showing 1 changed files
... ...
@@ -1390,6 +1390,14 @@ static void print_report(AVFormatContext **output_files,
1390 1390
     }
1391 1391
 }
1392 1392
 
1393
+static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size)
1394
+{
1395
+    int fill_char = 0x00;
1396
+    if (sample_fmt == AV_SAMPLE_FMT_U8)
1397
+        fill_char = 0x80;
1398
+    memset(buf, fill_char, size);
1399
+}
1400
+
1393 1401
 /* pkt = NULL means EOF (needed to flush decoder buffers) */
1394 1402
 static int output_packet(AVInputStream *ist, int ist_index,
1395 1403
                          AVOutputStream **ost_table, int nb_ostreams,
... ...
@@ -1732,7 +1740,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
1732 1732
                                     int frame_bytes = enc->frame_size*osize*enc->channels;
1733 1733
                                     if (allocated_audio_buf_size < frame_bytes)
1734 1734
                                         ffmpeg_exit(1);
1735
-                                    memset(audio_buf+fifo_bytes, 0, frame_bytes - fifo_bytes);
1735
+                                    generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
1736 1736
                                 }
1737 1737
 
1738 1738
                                 ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);