changeset 5304:6175c9cfab11

Support for decoder specific config from mp4 header for AAC decoder.
author atmos4
date Sun, 24 Mar 2002 03:08:20 +0000
parents 534f16f50c17
children 77ac28af44ec
files dec_audio.c
diffstat 1 files changed, 45 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/dec_audio.c	Sun Mar 24 03:07:18 2002 +0000
+++ b/dec_audio.c	Sun Mar 24 03:08:20 2002 +0000
@@ -842,42 +842,54 @@
   faacDecConfigurationPtr faac_conf;
   faac_hdec = faacDecOpen();
 
+  if(faac_buffer == NULL)
+    faac_buffer = (unsigned char*)calloc(1,FAAD_BUFFLEN);
+  demux_read_data(sh_audio->ds, faac_buffer, FAAD_BUFFLEN);
+
+  // If we don't get the ES descriptor, try manual config
+  if(!sh_audio->codecdata_len) {
 #if 1
-  /* Set the default object type and samplerate */
-  /* This is useful for RAW AAC files */
-  faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
-  if(sh_audio->samplerate)
-    faac_conf->defSampleRate = sh_audio->samplerate;
-   /* XXX: FAAD support FLOAT output, how do we handle
-    * that (FAAD_FMT_FLOAT)? ::atmos
-    */
-  if(sh_audio->samplesize)
-    switch(sh_audio->samplesize){
-      case 1: // 8Bit
-	mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: 8Bit samplesize not supported by FAAD, assuming 16Bit!\n");
-      default:
-      case 2: // 16Bit
-	faac_conf->outputFormat = FAAD_FMT_16BIT;
-	break;
-      case 3: // 24Bit
-	faac_conf->outputFormat = FAAD_FMT_24BIT;
-	break;
-      case 4: // 32Bit
-	faac_conf->outputFormat = FAAD_FMT_32BIT;
-	break;
-    }
-  //faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
+    /* Set the default object type and samplerate */
+    /* This is useful for RAW AAC files */
+    faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
+    if(sh_audio->samplerate)
+      faac_conf->defSampleRate = sh_audio->samplerate;
+    /* XXX: FAAD support FLOAT output, how do we handle
+      * that (FAAD_FMT_FLOAT)? ::atmos
+      */
+    if(sh_audio->samplesize)
+      switch(sh_audio->samplesize){
+	case 1: // 8Bit
+	  mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: 8Bit samplesize not supported by FAAD, assuming 16Bit!\n");
+	default:
+	case 2: // 16Bit
+	  faac_conf->outputFormat = FAAD_FMT_16BIT;
+	  break;
+	case 3: // 24Bit
+	  faac_conf->outputFormat = FAAD_FMT_24BIT;
+	  break;
+	case 4: // 32Bit
+	  faac_conf->outputFormat = FAAD_FMT_32BIT;
+	  break;
+      }
+    //faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
 
-  faacDecSetConfiguration(faac_hdec, faac_conf);
+    faacDecSetConfiguration(faac_hdec, faac_conf);
 #endif
 
-  if(faac_buffer == NULL)
-    faac_buffer = (unsigned char*)malloc(FAAD_BUFFLEN);
-  memset(faac_buffer, 0, FAAD_BUFFLEN);
-  demux_read_data(sh_audio->ds, faac_buffer, FAAD_BUFFLEN);
+    /* init the codec */
+    faac_bytesconsumed = faacDecInit(faac_hdec, faac_buffer,
+       &faac_samplerate, &faac_channels);
 
-  /* init the codec */
-  if((faac_bytesconsumed = faacDecInit(faac_hdec, faac_buffer, &faac_samplerate, &faac_channels)) < 0) {
+  } else { // We have ES DS in codecdata
+    /*int i;
+    for(i = 0; i < sh_audio->codecdata_len; i++)
+      printf("codecdata_dump %d: 0x%02X\n", i, sh_audio->codecdata[i]);*/
+
+    faac_bytesconsumed = faacDecInit2(faac_hdec, sh_audio->codecdata,
+       sh_audio->codecdata_len,	&faac_samplerate, &faac_channels);
+  }
+  if(faac_bytesconsumed < 0) {
     mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Failed to initialize the decoder!\n"); // XXX: deal with cleanup!
     faacDecClose(faac_hdec);
     free(faac_buffer);
@@ -890,9 +902,9 @@
     sh_audio->samplerate = faac_samplerate;
     if(!sh_audio->i_bps) {
       mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: compressed input bitrate missing, assuming 128kbit/s!\n");
-      sh_audio->i_bps = 128*1000/8; // XXX: HACK!!! There's currently no way to get bitrate from libfaad2! ::atmos
+      sh_audio->i_bps = 128*1000/8; // XXX: HACK!!! ::atmos
     } else 
-      mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s rate from MP4 header!\n",sh_audio->i_bps*8/1000);
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s bitrate from MP4 header!\n",sh_audio->i_bps*8/1000);
   }  
 	    
 } break;