Check that channel layout is compatible with number of channels for
authorJustin Ruggles <justin.ruggles@gmail.com>
Sun, 19 Apr 2009 14:05:55 +0000 (14:05 +0000)
committerJustin Ruggles <justin.ruggles@gmail.com>
Sun, 19 Apr 2009 14:05:55 +0000 (14:05 +0000)
output audio stream.

Originally committed as revision 18621 to svn://svn.ffmpeg.org/ffmpeg/trunk

ffmpeg.c
libavcodec/audioconvert.c
libavcodec/audioconvert.h

index 200d57dfeff75ec27eff46cf03c238fb2239b97f..c050512ae2629953bcbbe9335012791cdebd622d 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3212,6 +3212,8 @@ static void new_audio_stream(AVFormatContext *oc)
         audio_enc->channels = audio_channels;
         audio_enc->sample_fmt = audio_sample_fmt;
         audio_enc->channel_layout = channel_layout;
+        if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)
+            audio_enc->channel_layout = 0;
 
         if(codec && codec->sample_fmts){
             const enum SampleFormat *p= codec->sample_fmts;
index b0a8afacb4ffe2c46e8edf8cc532e96b9c8a6356..5842801093afceec1515b8c1786965607428e616 100644 (file)
@@ -153,6 +153,15 @@ void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels,
     }
 }
 
+int avcodec_channel_layout_num_channels(int64_t channel_layout)
+{
+    int count;
+    uint64_t x = channel_layout;
+    for (count = 0; x; count++)
+        x &= x-1; // unset lowest set bit
+    return count;
+}
+
 struct AVAudioConvert {
     int in_channels, out_channels;
     int fmt_pair;
index 157bd44e21c2540124a437460e26c75937013f39..46ba3d39296c1c609ef259d0cebfa8fbb4c75ea9 100644 (file)
@@ -73,6 +73,10 @@ void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels,
  */
 int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name);
 
+/**
+ * @return the number of channels in the channel layout.
+ */
+int avcodec_channel_layout_num_channels(int64_t channel_layout);
 
 struct AVAudioConvert;
 typedef struct AVAudioConvert AVAudioConvert;