OSDN Git Service

add downmixing support to libfaad decoder
authorJustin Ruggles <justin.ruggles@gmail.com>
Sat, 5 Jan 2008 21:08:20 +0000 (21:08 +0000)
committerJustin Ruggles <justin.ruggles@gmail.com>
Sat, 5 Jan 2008 21:08:20 +0000 (21:08 +0000)
Originally committed as revision 11422 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/aac_ac3_parser.c
libavcodec/libfaad.c

index 8a83aae..999a189 100644 (file)
@@ -60,11 +60,12 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
                     s->frame_size = len;
                     /* update codec info */
                     avctx->sample_rate = sample_rate;
-                    /* allow downmixing to mono or stereo for AC3 */
+                    /* allow downmixing to stereo (or mono for AC3) */
                     if(avctx->request_channels > 0 &&
                             avctx->request_channels < channels &&
-                            avctx->request_channels <= 2 &&
-                            avctx->codec_id == CODEC_ID_AC3) {
+                            (avctx->request_channels <= 2 ||
+                            (avctx->request_channels == 1 &&
+                            avctx->codec_id == CODEC_ID_AC3))) {
                         avctx->channels = avctx->request_channels;
                     } else {
                         avctx->channels = channels;
index 8c265e3..6de8084 100644 (file)
@@ -101,6 +101,21 @@ static const unsigned long faac_srates[] =
     24000, 22050, 16000, 12000, 11025, 8000
 };
 
+static void channel_setup(AVCodecContext *avctx)
+{
+#ifdef FAAD2_VERSION
+    FAACContext *s = avctx->priv_data;
+    if (avctx->request_channels > 0 && avctx->request_channels == 2 &&
+            avctx->request_channels < avctx->channels) {
+        faacDecConfigurationPtr faac_cfg;
+        avctx->channels = 2;
+        faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
+        faac_cfg->downMatrix = 1;
+        s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
+    }
+#endif
+}
+
 static int faac_init_mp4(AVCodecContext *avctx)
 {
     FAACContext *s = avctx->priv_data;
@@ -123,6 +138,7 @@ static int faac_init_mp4(AVCodecContext *avctx)
         } else {
             avctx->sample_rate = samplerate;
             avctx->channels = channels;
+            channel_setup(avctx);
             s->init = 1;
         }
     }
@@ -170,6 +186,7 @@ static int faac_decode_frame(AVCodecContext *avctx,
         }
         avctx->sample_rate = srate;
         avctx->channels = channels;
+        channel_setup(avctx);
         s->init = 1;
     }
 
@@ -308,6 +325,9 @@ static int faac_decode_init(AVCodecContext *avctx)
 
     faac_init_mp4(avctx);
 
+    if(!s->init && avctx->channels > 0)
+        channel_setup(avctx);
+
     return 0;
 }