shithub: aacdec

Download patch

ref: 9c1ab867b5933d0d87412f814957e01771ddbae1
parent: 27191ef56ec52ba2688d941198aca82588904274
author: menno <menno>
date: Tue Sep 23 04:12:29 EDT 2003

Can now optionally read old ADTS headers with the option -t
together with -a you can now convert old ADTS files to new ADTS files :)

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: main.c,v 1.47 2003/09/22 20:05:31 menno Exp $
+** $Id: main.c,v 1.48 2003/09/23 08:12:29 menno Exp $
 **/
 
 #ifdef _WIN32
@@ -259,16 +259,17 @@
 	return 16 - 1;
 }
 
-unsigned char *MakeAdtsHeader(int *dataSize, faacDecFrameInfo *hInfo)
+unsigned char *MakeAdtsHeader(int *dataSize, faacDecFrameInfo *hInfo, int old_format)
 {
     unsigned char *data;
     int profile = (hInfo->object_type - 1) & 0x3;
     int sr_index = ((hInfo->sbr == SBR_UPSAMPLED) || (hInfo->sbr == NO_SBR_UPSAMPLED)) ?
         FindAdtsSRIndex(hInfo->samplerate / 2) : FindAdtsSRIndex(hInfo->samplerate);
-    int framesize = 7 + hInfo->bytesconsumed;
+    int skip = (old_format) ? 8 : 7;
+    int framesize = skip + hInfo->bytesconsumed;
 
     if (hInfo->header_type == ADTS)
-        framesize -= 7;
+        framesize -= skip;
 
     *dataSize = 7;
 
@@ -303,28 +304,6 @@
     /* 2b: num_raw_data_blocks */
 
     return data;
-
-#if 0
-    // build adts header
-    adts.PutBits(0xFFF, 12);		// syncword
-    adts.PutBits(isMpeg2, 1);		// id
-    adts.PutBits(0, 2);				// layer
-    adts.PutBits(1, 1);				// protection_absent
-    adts.PutBits(profile, 2);		// profile
-    adts.PutBits(
-        MP4AV_AdtsFindSamplingRateIndex(samplingFrequency),
-        4);							// sampling_frequency_index
-    adts.PutBits(0, 1);				// private
-    adts.PutBits(channels, 3);		// channel_configuration
-    adts.PutBits(0, 1);				// original
-    adts.PutBits(0, 1);				// home
-
-    adts.PutBits(0, 1);				// copyright_id
-    adts.PutBits(0, 1);				// copyright_id_start
-    adts.PutBits(*pAdtsDataLength, 13);	// aac_frame_length
-    adts.PutBits(0x7FF, 11);		// adts_buffer_fullness
-    adts.PutBits(0, 2);				// num_raw_data_blocks
-#endif
 }
 
 /* globals */
@@ -349,6 +328,7 @@
     fprintf(stdout, " -h    Shows this help screen.\n");
     fprintf(stdout, " -i    Shows info about the input file.\n");
     fprintf(stdout, " -a X  Write MPEG-4 AAC ADTS output file.\n");
+    fprintf(stdout, " -t    Assume old ADTS format.\n");
     fprintf(stdout, " -o X  Set output filename.\n");
     fprintf(stdout, " -f X  Set output format. Valid values for X are:\n");
     fprintf(stdout, "        1:  Microsoft WAV format (default).\n");
@@ -373,16 +353,17 @@
     fprintf(stdout, " -w    Write output to stdio instead of a file.\n");
     fprintf(stdout, " -g    Disable gapless decoding.\n");
     fprintf(stdout, "Example:\n");
-    fprintf(stdout, "       faad infile.aac\n");
-    fprintf(stdout, "       faad infile.mp4\n");
-    fprintf(stdout, "       faad -o outfile.wav infile.aac\n");
-    fprintf(stdout, "       faad -w infile.aac > outfile.wav\n");
+    fprintf(stdout, "       %s infile.aac\n", progName);
+    fprintf(stdout, "       %s infile.mp4\n", progName);
+    fprintf(stdout, "       %s -o outfile.wav infile.aac\n", progName);
+    fprintf(stdout, "       %s -w infile.aac > outfile.wav\n", progName);
+    fprintf(stdout, "       %s -a outfile.aac infile.aac\n", progName);
     return;
 }
 
 int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_stdout,
                   int def_srate, int object_type, int outputFormat, int fileType,
-                  int downMatrix, int infoOnly, int adts_out)
+                  int downMatrix, int infoOnly, int adts_out, int old_format)
 {
     int tagsize;
     unsigned long samplerate;
@@ -471,6 +452,7 @@
     config->defObjectType = object_type;
     config->outputFormat = outputFormat;
     config->downMatrix = downMatrix;
+    config->useOldADTSFormat = old_format;
     faacDecSetConfiguration(hDecoder, config);
 
     /* get AAC infos for printing */
@@ -556,7 +538,8 @@
 
         if (adts_out == 1)
         {
-            adtsData = MakeAdtsHeader(&adtsDataSize, &frameInfo);
+            int skip = (old_format) ? 8 : 7;
+            adtsData = MakeAdtsHeader(&adtsDataSize, &frameInfo, old_format);
 
             /* write the adts header */
             fwrite(adtsData, 1, adtsDataSize, adtsFile);
@@ -563,7 +546,7 @@
 
             /* write the frame data */
             if (frameInfo.header_type == ADTS)
-                fwrite(b.buffer + 7, 1, frameInfo.bytesconsumed - 7, adtsFile);
+                fwrite(b.buffer + skip, 1, frameInfo.bytesconsumed - skip, adtsFile);
             else
                 fwrite(b.buffer, 1, frameInfo.bytesconsumed, adtsFile);
         }
@@ -838,7 +821,7 @@
 
         if (adts_out == 1)
         {
-            adtsData = MakeAdtsHeader(&adtsDataSize, &frameInfo);
+            adtsData = MakeAdtsHeader(&adtsDataSize, &frameInfo, 0);
 
             /* write the adts header */
             fwrite(adtsData, 1, adtsDataSize, adtsFile);
@@ -953,6 +936,7 @@
     int outputFormat = FAAD_FMT_16BIT;
     int outfile_set = 0;
     int adts_out = 0;
+    int old_format = 0;
     int showHelp = 0;
     int mp4file = 0;
     int noGapless = 0;
@@ -991,6 +975,7 @@
         static struct option long_options[] = {
             { "outfile",    0, 0, 'o' },
             { "adtsout",    0, 0, 'a' },
+            { "oldformat",  0, 0, 't' },
             { "format",     0, 0, 'f' },
             { "bits",       0, 0, 'b' },
             { "samplerate", 0, 0, 's' },
@@ -1002,7 +987,7 @@
             { "help",       0, 0, 'h' }
         };
 
-        c = getopt_long(argc, argv, "o:a:s:f:b:l:wgdhi",
+        c = getopt_long(argc, argv, "o:a:s:f:b:l:wgdhit",
             long_options, &option_index);
 
         if (c == -1)
@@ -1081,6 +1066,9 @@
                 }
             }
             break;
+        case 't':
+            old_format = 1;
+            break;
         case 'd':
             downMatrix = 1;
             break;
@@ -1145,7 +1133,8 @@
             outputFormat, format, downMatrix, noGapless, infoOnly, adts_out);
     } else {
         result = decodeAACfile(aacFileName, audioFileName, adtsFileName, writeToStdio,
-            def_srate, object_type, outputFormat, format, downMatrix, infoOnly, adts_out);
+            def_srate, object_type, outputFormat, format, downMatrix, infoOnly, adts_out,
+            old_format);
     }
 
 
--- a/include/faad.h
+++ b/include/faad.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: faad.h,v 1.31 2003/09/22 20:05:31 menno Exp $
+** $Id: faad.h,v 1.32 2003/09/23 08:12:29 menno Exp $
 **/
 
 #ifndef __AACDEC_H__
@@ -140,6 +140,7 @@
     unsigned long defSampleRate;
     unsigned char outputFormat;
     unsigned char downMatrix;
+    unsigned char useOldADTSFormat;
 } faacDecConfiguration, *faacDecConfigurationPtr;
 
 typedef struct faacDecFrameInfo
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: decoder.c,v 1.69 2003/09/22 20:05:32 menno Exp $
+** $Id: decoder.c,v 1.70 2003/09/23 08:12:29 menno Exp $
 **/
 
 #include "common.h"
@@ -245,6 +245,7 @@
         } else if (faad_showbits(&ld, 12) == 0xfff) {
             hDecoder->adts_header_present = 1;
 
+            adts.old_format = hDecoder->config.useOldADTSFormat;
             adts_frame(&adts, &ld);
 
             hDecoder->sf_index = adts.sf_index;
@@ -807,6 +808,7 @@
 
     if (hDecoder->adts_header_present)
     {
+        adts.old_format = hDecoder->config.useOldADTSFormat;
         if ((hInfo->error = adts_frame(&adts, ld)) > 0)
             goto error;
 
--- a/libfaad/structs.h
+++ b/libfaad/structs.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: structs.h,v 1.15 2003/09/22 20:05:32 menno Exp $
+** $Id: structs.h,v 1.16 2003/09/23 08:12:29 menno Exp $
 **/
 
 #ifndef __STRUCTS_H__
@@ -160,6 +160,9 @@
     uint16_t adts_buffer_fullness;
     uint8_t no_raw_data_blocks_in_frame;
     uint16_t crc_check;
+
+    /* control param */
+    uint8_t old_format;
 } adts_header;
 
 typedef struct
@@ -327,6 +330,7 @@
     uint32_t defSampleRate;
     uint8_t outputFormat;
     uint8_t downMatrix;
+    uint8_t useOldADTSFormat;
 } faacDecConfiguration, *faacDecConfigurationPtr;
 
 typedef struct faacDecFrameInfo
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: syntax.c,v 1.53 2003/09/10 12:25:54 menno Exp $
+** $Id: syntax.c,v 1.54 2003/09/23 08:12:29 menno Exp $
 **/
 
 /*
@@ -1878,13 +1878,16 @@
         DEBUGVAR(1,126,"adts_fixed_header(): original"));
     adts->home = faad_get1bit(ld
         DEBUGVAR(1,127,"adts_fixed_header(): home"));
-/* Removed in corrigendum 14496-3:2002
-    if (adts->id == 0)
+
+    if (adts->old_format == 1)
     {
-        adts->emphasis = (uint8_t)faad_getbits(ld, 2
-            DEBUGVAR(1,128,"adts_fixed_header(): emphasis"));
+        /* Removed in corrigendum 14496-3:2002 */
+        if (adts->id == 0)
+        {
+            adts->emphasis = (uint8_t)faad_getbits(ld, 2
+                DEBUGVAR(1,128,"adts_fixed_header(): emphasis"));
+        }
     }
-*/
 
     return 0;
 }