shithub: aacdec

Download patch

ref: c6320bdc10062f0fc1cedbf90fd96fd96c48ab6f
parent: 3501993184b7b711ab99d442ac651a6fb1310b6f
author: menno <menno>
date: Sun Jan 20 12:00:48 EST 2002

Changes for easier MP4 file playing

--- a/include/faad.h
+++ b/include/faad.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: faad.h,v 1.2 2002/01/19 09:39:11 menno Exp $
+** $Id: faad.h,v 1.3 2002/01/20 17:00:48 menno Exp $
 **/
 
 #ifndef __AACDEC_H__
@@ -96,6 +96,12 @@
                             unsigned char *buffer);
 
 void FAADAPI faacDecClose(faacDecHandle hDecoder);
+
+int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
+                                unsigned long *samplerate,
+                                unsigned long *channels,
+                                unsigned long *sf_index,
+                                unsigned long *object_type);
 
 #ifdef _WIN32
   #pragma pack(pop)
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,12 +16,13 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.c,v 1.5 2002/01/19 16:19:54 menno Exp $
+** $Id: decoder.c,v 1.6 2002/01/20 16:57:55 menno Exp $
 **/
 
 #include <stdlib.h>
 #include <memory.h>
 #include "decoder.h"
+#include "mp4.h"
 #include "syntax.h"
 #include "specrec.h"
 #include "data.h"
@@ -174,56 +175,6 @@
     return 0;
 }
 
-
-static unsigned long ObjectTypesTable[32] = {0, 1, 1, 1, 1, };
-
-int parse_audio_decoder_specific_info(faacDecHandle hDecoder,
-                                      unsigned char *pBuffer,
-                                      unsigned long *samplerate,
-                                      unsigned long *channels)
-{
-    bitfile ld;
-    unsigned long ObjectTypeIndex, SamplingFrequencyIndex,
-        ChannelsConfiguration;
-
-    faad_initbits(&ld, pBuffer);
-    faad_byte_align(&ld);
-
-    ObjectTypeIndex = faad_getbits(&ld, 5
-        DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
-
-    SamplingFrequencyIndex = faad_getbits(&ld, 4
-        DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
-
-    ChannelsConfiguration = faad_getbits(&ld, 4
-        DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
-
-    if (ObjectTypesTable[ObjectTypeIndex] != 1)
-    {
-        return -1;
-    }
-
-    *samplerate = sample_rates[SamplingFrequencyIndex];
-    if (*samplerate == 0)
-    {
-        return -2;
-    }
-
-    *channels = ChannelsConfiguration;
-
-    hDecoder->sf_index = SamplingFrequencyIndex;
-    hDecoder->object_type = ObjectTypeIndex - 1;
-
-    if(ChannelsConfiguration > 7)
-    {
-        return -3;
-    }
-
-    /* get GASpecificConfig */
-
-    return 0;
-}
-
 /* Init the library using a DecoderSpecificInfo */
 int FAADAPI faacDecInit2(faacDecHandle hDecoder, unsigned char *pBuffer,
                          unsigned long SizeOfDecoderSpecificInfo,
@@ -243,8 +194,9 @@
         return -1;
     }
 
-    rc = parse_audio_decoder_specific_info(hDecoder, pBuffer,
-        samplerate, channels);
+    rc = AudioSpecificConfig(pBuffer, samplerate, channels,
+        &hDecoder->sf_index, &hDecoder->object_type);
+    hDecoder->object_type--; /* For AAC differs from MPEG-4 */
     if (rc != 0)
     {
         return rc;
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -129,6 +129,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\mp4.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ms.c
 # End Source File
 # Begin Source File
@@ -210,6 +214,10 @@
 # Begin Source File
 
 SOURCE=.\mdct.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4.h
 # End Source File
 # Begin Source File
 
--- /dev/null
+++ b/libfaad/mp4.c
@@ -1,0 +1,105 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**  
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+** 
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+** 
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: mp4.c,v 1.1 2002/01/20 16:57:55 menno Exp $
+**/
+
+#include "bits.h"
+#include "mp4.h"
+#include "data.h"
+#include "syntax.h"
+
+/* defines if an object type can be decoded by this library or not */
+static unsigned long ObjectTypesTable[32] = {
+    0, /* NULL */
+    1, /* AAC Main */
+    1, /* AAC LC */
+    0, /* AAC SSR */
+    1, /* AAC LTP */
+    0, /* Reserved */
+    0, /* AAC Scalable */
+    0, /* TwinVQ */
+    0, /* CELP */
+    0, /* HVXC */
+    0, /* Reserved */
+    0, /* Reserved */
+    0, /* TTSI */
+    0, /* Main synthetic */
+    0, /* Wavetable synthesis */
+    0, /* General MIDI */
+    0  /* Algorithmic Synthesis and Audio FX */
+};
+
+/* Table 1.6.1 */
+int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
+                                unsigned long *samplerate,
+                                unsigned long *channels,
+                                unsigned long *sf_index,
+                                unsigned long *object_type)
+{
+    bitfile ld;
+    unsigned long ObjectTypeIndex, SamplingFrequencyIndex,
+        ChannelsConfiguration;
+
+    faad_initbits(&ld, pBuffer);
+    faad_byte_align(&ld);
+
+    ObjectTypeIndex = faad_getbits(&ld, 5
+        DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
+
+    SamplingFrequencyIndex = faad_getbits(&ld, 4
+        DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
+
+    ChannelsConfiguration = faad_getbits(&ld, 4
+        DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
+
+    *samplerate = sample_rates[SamplingFrequencyIndex];
+
+    *channels = ChannelsConfiguration;
+
+    *sf_index = SamplingFrequencyIndex;
+    *object_type = ObjectTypeIndex;
+
+
+    if (ObjectTypesTable[ObjectTypeIndex] != 1)
+    {
+        return -1;
+    }
+
+    if (*samplerate == 0)
+    {
+        return -2;
+    }
+
+    if(ChannelsConfiguration > 7)
+    {
+        return -3;
+    }
+
+    /* get GASpecificConfig */
+    if (ObjectTypeIndex == 1 || ObjectTypeIndex == 2 ||
+        ObjectTypeIndex == 3 || ObjectTypeIndex == 4 ||
+        ObjectTypeIndex == 6 || ObjectTypeIndex == 7 )
+    {
+        return GASpecificConfig(&ld, channels);
+    } else {
+        return -4;
+    }
+
+    return 0;
+}
--- /dev/null
+++ b/libfaad/mp4.h
@@ -1,0 +1,40 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**  
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+** 
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+** 
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: mp4.h,v 1.1 2002/01/20 16:57:55 menno Exp $
+**/
+
+#ifndef __MP4_H__
+#define __MP4_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "decoder.h"
+
+int FAADAPI AudioSpecificConfig(unsigned char *pBuffer,
+                                unsigned long *samplerate,
+                                unsigned long *channels,
+                                unsigned long *sf_index,
+                                unsigned long *object_type);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.c,v 1.3 2002/01/19 16:19:54 menno Exp $
+** $Id: syntax.c,v 1.4 2002/01/20 16:57:55 menno Exp $
 **/
 
 /*
@@ -38,6 +38,43 @@
 #include "debug.h"
 
 
+/* Table 4.4.1 */
+int GASpecificConfig(bitfile *ld, unsigned long *channelConfiguration)
+{
+    int frameLengthFlag, dependsOnCoreCoder, coreCoderDelay;
+    int extensionFlag;
+    program_config pce;
+
+    /* 1024 or 960 */
+    frameLengthFlag = faad_get1bit(ld
+        DEBUGVAR(1,138,"GASpecificConfig(): FrameLengthFlag"));
+
+    dependsOnCoreCoder = faad_get1bit(ld
+        DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder"));
+    if (dependsOnCoreCoder == 1)
+    {
+        coreCoderDelay = faad_getbits(ld, 14
+            DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay"));
+    }
+
+    extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag"));
+    if (*channelConfiguration == 0)
+    {
+        program_config_element(&pce, ld);
+        *channelConfiguration = pce.channels;
+
+        if (pce.num_valid_cc_elements)
+            return -3;
+    }
+
+    if (extensionFlag == 1)
+    {
+        /* defined in mpeg4 phase 2 */
+    }
+
+    return 0;
+}
+
 /* Table 4.4.2 */
 /* An MPEG-4 Audio decoder is only required to follow the Program
    Configuration Element in GASpecificConfig(). The decoder shall ignore
@@ -149,7 +186,9 @@
 
     for (i = 0; i < pce->num_valid_cc_elements; i++)
     {
-        /* have to count these as channels too?? */
+        /* have to count these as channels too?? (1 or 2) */
+        pce->channels += 2;
+
         pce->cc_element_is_ind_sw[i] = faad_get1bit(ld
             DEBUGVAR(1,34,"program_config_element(): cc_element_is_ind_sw"));
         pce->valid_cc_element_tag_select[i] = faad_getbits(ld, 4
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.h,v 1.2 2002/01/19 09:39:41 menno Exp $
+** $Id: syntax.h,v 1.3 2002/01/20 16:57:55 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -256,6 +256,7 @@
     ic_stream ics2;
 } element; /* syntax element (SCE, CPE, LFE) */
 
+int GASpecificConfig(bitfile *ld, unsigned long *channelConfiguration);
 int single_lfe_channel_element(element *sce, bitfile *ld, short *spec_data,
                                int sf_index, int object_type);
 int channel_pair_element(element *cpe, bitfile *ld, short *spec_data1,