ref: f5944cbe42a23d36ac58d45b2d0abfd670bf1afe
parent: 9f3c31d25eb3a94eb25aa9a6345a7dfa7b939dbc
author: menno <menno>
date: Thu Dec 5 14:28:22 EST 2002
Linux and DRM fixes
--- a/libfaad/Makefile.am
+++ b/libfaad/Makefile.am
@@ -7,14 +7,15 @@
error.c filtbank.c \
ic_predict.c is.c lt_predict.c mdct.c mp4.c ms.c output.c pns.c \
pulse.c specrec.c syntax.c tns.c hcr.c \
-rvlc.c ssr.c \
+rvlc.c ssr.c ssr_fb.c ssr_ipqf.c common.c \
hcb_1.c hcb_2.c hcb_3.c hcb_4.c hcb_5.c hcb_6.c hcb_7.c hcb_8.c \
hcb_9.c hcb_10.c hcb_11.c hcb_sf.c
-libfaad_la_INCLUDES = analysis.h bits.h cfft.h data.h decoder.h dither.h \
-drc.h error.h \
-filtbank.h huffman.h ic_predict.h is.h kbd_win.h lt_predict.h mdct.h mp4.h \
-ms.h output.h pns.h pulse.h rvlc.h ssr.h \
-specrec.h syntax.h tns.h codebook/hcb.h
+libfaad_la_INCLUDES = analysis.h bits.h cfft.h cfft_tab.h common.h \
+data.h decoder.h dither.h drc.h error.h fixed.h filtbank.h \
+huffman.h ic_predict.h iq_table.h is.h kbd_win.h lt_predict.h mdct.h mp4.h \
+ms.h output.h pns.h pulse.h rvlc.h sine_win.h ssr.h ssr_fb.h ssr_ipqf.h\
+ssr_win.h specrec.h syntax.h tns.h codebook/hcb.h
+
CFLAGS = -O2
--- a/libfaad/common.h
+++ b/libfaad/common.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: common.h,v 1.26 2002/11/28 18:48:29 menno Exp $
+** $Id: common.h,v 1.27 2002/12/05 19:28:22 menno Exp $
**/
#ifndef __COMMON_H__
@@ -26,15 +26,7 @@
extern "C" {
#endif
-#ifdef LINUX
-#define INLINE inline
-#else
-#ifdef _WIN32
#define INLINE __inline
-#else
-#define INLINE
-#endif
-#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
@@ -92,17 +84,46 @@
typedef __int32 int32_t;
typedef __int16 int16_t;
typedef __int8 int8_t;
-#ifndef FIXED_POINT
typedef float float32_t;
-#endif
-#elif defined(LINUX) || defined(DJGPP)
+#else
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
-#if defined(LINUX)
-#include <stdint.h>
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
#else
+# if HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+# include <stdint.h>
+# else
+/* we need these... */
typedef unsigned long long uint64_t;
typedef unsigned long uint32_t;
typedef unsigned short uint16_t;
@@ -111,16 +132,30 @@
typedef long int32_t;
typedef short int16_t;
typedef char int8_t;
-#ifndef FIXED_POINT
-typedef float float32_t;
+# endif
#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
#endif
+#ifndef HAVE_FLOAT32_T
+typedef float float32_t;
+#endif
-#else /* Some other OS */
+#if STDC_HEADERS
+# include <string.h>
+#else
+# if !HAVE_STRCHR
+# define strchr index
+# define strrchr rindex
+# endif
+char *strchr(), *strrchr();
+# if !HAVE_MEMCPY
+# define memcpy(d, s, n) bcopy((s), (d), (n))
+# define memmove(d, s, n) bcopy((s), (d), (n))
+# endif
+#endif
-#include <inttypes.h>
-
#endif
/* FIXED_POINT doesn't work with MAIN and SSR yet */
@@ -132,7 +167,11 @@
#if defined(FIXED_POINT)
- #include <math.h>
+ #ifdef HAS_MATHF_H
+ #include <mathf.h>
+ #else
+ #include <math.h>
+ #endif
#include "fixed.h"
@@ -177,6 +216,7 @@
#ifdef HAVE_SINF
# define sin sinf
+#error
#endif
#ifdef HAVE_COSF
# define cos cosf
@@ -184,13 +224,13 @@
#ifdef HAVE_LOGF
# define log logf
#endif
-#ifdef HAVE_POWF
-# define pow powf
+#ifdef HAVE_EXPF
+# define exp expf
#endif
#ifdef HAVE_FLOORF
# define floor floorf
#endif
-#ifdef HAVE_FLOORF
+#ifdef HAVE_CEILF
# define ceil ceilf
#endif
#ifdef HAVE_SQRTF
@@ -208,9 +248,6 @@
/* common functions */
uint32_t int_log2(uint32_t val);
-int8_t can_decode_ot(uint8_t object_type);
-uint8_t get_sr_index(uint32_t samplerate);
-uint32_t random_int(void);
#ifndef M_PI
#define M_PI 3.14159265358979323846f
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.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: decoder.c,v 1.42 2002/12/05 18:01:49 menno Exp $
+** $Id: decoder.c,v 1.43 2002/12/05 19:28:22 menno Exp $
**/
#include "common.h"
@@ -40,8 +40,10 @@
#include "error.h"
#include "output.h"
#include "dither.h"
+#ifdef SSR_DEC
#include "ssr.h"
#include "ssr_fb.h"
+#endif
#ifdef ANALYSIS
uint16_t dbg_count;
@@ -114,15 +116,6 @@
faacDecConfigurationPtr config)
{
hDecoder->config.defObjectType = config->defObjectType;
-#ifdef DRM
- if (config->defObjectType == DRM_ER_LC)
- {
- hDecoder->aacSectionDataResilienceFlag = 1; /* VCB11 */
- hDecoder->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
- hDecoder->aacSpectralDataResilienceFlag = 1; /* HCR */
- hDecoder->frameLength = 960;
- }
-#endif
hDecoder->config.defSampleRate = config->defSampleRate;
hDecoder->config.outputFormat = config->outputFormat;
@@ -148,9 +141,6 @@
{
faad_initbits(&ld, buffer, buffer_size);
-#ifdef DRM
- if (hDecoder->object_type != DRM_ER_LC)
-#endif
/* Check if an ADIF header is present */
if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
(buffer[2] == 'I') && (buffer[3] == 'F'))
@@ -186,9 +176,11 @@
hDecoder->channelConfiguration = *channels;
/* must be done before frameLength is divided by 2 for LD */
+#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
else
+#endif
hDecoder->fb = filter_bank_init(hDecoder->frameLength);
#ifdef LD_DEC
@@ -249,9 +241,11 @@
hDecoder->frameLength = 960;
/* must be done before frameLength is divided by 2 for LD */
+#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
else
+#endif
hDecoder->fb = filter_bank_init(hDecoder->frameLength);
#ifdef LD_DEC
@@ -267,6 +261,32 @@
return 0;
}
+int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate,
+ uint8_t channels)
+{
+ /* Special object type defined for DRM */
+ hDecoder->config.defObjectType = DRM_ER_LC;
+
+ hDecoder->config.defSampleRate = samplerate;
+ hDecoder->aacSectionDataResilienceFlag = 1; /* VCB11 */
+ hDecoder->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
+ hDecoder->aacSpectralDataResilienceFlag = 1; /* HCR */
+ hDecoder->frameLength = 960;
+ hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
+ hDecoder->object_type = hDecoder->config.defObjectType;
+ hDecoder->channelConfiguration = channels;
+
+ /* must be done before frameLength is divided by 2 for LD */
+ hDecoder->fb = filter_bank_init(hDecoder->frameLength);
+
+#ifndef FIXED_POINT
+ if (hDecoder->config.outputFormat >= 5)
+ Init_Dither(16, hDecoder->config.outputFormat - 5);
+#endif
+
+ return 0;
+}
+
void FAADAPI faacDecClose(faacDecHandle hDecoder)
{
uint8_t i;
@@ -285,9 +305,11 @@
#endif
}
+#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
ssr_filter_bank_end(hDecoder->fb);
else
+#endif
filter_bank_end(hDecoder->fb);
drc_end(hDecoder->drc);
@@ -357,6 +379,14 @@
/* initialize the bitstream */
faad_initbits(ld, buffer, buffer_size);
+
+#ifdef DRM
+ if (object_type == DRM_ER_LC)
+ {
+ faad_getbits(ld, 8
+ DEBUGVAR(1,1,"faacDecDecode(): skip CRC"));
+ }
+#endif
if (hDecoder->adts_header_present)
{
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.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: decoder.h,v 1.18 2002/11/28 18:48:30 menno Exp $
+** $Id: decoder.h,v 1.19 2002/12/05 19:28:22 menno Exp $
**/
#ifndef __DECODER_H__
@@ -75,6 +75,10 @@
int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
uint32_t SizeOfDecoderSpecificInfo,
uint32_t *samplerate, uint8_t *channels);
+
+/* Init the library for DRM */
+int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate,
+ uint8_t channels);
void FAADAPI faacDecClose(faacDecHandle hDecoder);
--- a/libfaad/dither.c
+++ b/libfaad/dither.c
@@ -6,7 +6,7 @@
* random functions for dithering.
*
* last modified:
- * $Id: dither.c,v 1.6 2002/11/08 13:12:32 menno Exp $
+ * $Id: dither.c,v 1.7 2002/12/05 19:28:22 menno Exp $
*/
#include "common.h"
@@ -14,6 +14,7 @@
#include <string.h>
#include "dither.h"
+#include "common.h"
double
--- a/libfaad/hcr.c
+++ b/libfaad/hcr.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: hcr.c,v 1.1 2002/11/28 18:48:30 menno Exp $
+** $Id: hcr.c,v 1.2 2002/12/05 19:28:22 menno Exp $
**/
#include "common.h"
@@ -400,7 +400,8 @@
/* if we have a corrupted bitstream this can happen... */
if ((ics->length_of_longest_codeword == 0) ||
(ics->length_of_reordered_spectral_data <
- ics->length_of_longest_codeword))
+ ics->length_of_longest_codeword) ||
+ (ics->max_sfb == 0))
{
return 10; /* this is not good... */
}
--- a/libfaad/libfaad.vcproj
+++ b/libfaad/libfaad.vcproj
@@ -33,13 +33,15 @@
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
- CompileAs="0">
+ CompileAs="0"
+ AdditionalOptions="">
<IntelOptions
Optimization="0"
MinimalRebuild="1"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
- AllOptions="/c /I "fftw" /ZI /nologo /W3 /Od /D "_DEBUG" /D "WIN32" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /YX"StdAfx.h" /Fp".\Debug/libfaad.pch" /Fo".\Debug/" /Fd".\Debug/" /Gd"/>
+ AllOptions="/c /I "fftw" /ZI /nologo /W3 /Od /D "_DEBUG" /D "WIN32" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /YX"StdAfx.h" /Fp".\Debug/libfaad.pch" /Fo".\Debug/" /Fd".\Debug/" /Gd"
+ MSOriginalAdditionalOptions=""/>
</Tool>
<Tool
Name="VCCustomBuildTool"/>
@@ -46,9 +48,11 @@
<Tool
Name="VCLibrarianTool"
OutputFile=".\Debug\libfaad.lib"
- SuppressStartupBanner="TRUE">
+ SuppressStartupBanner="TRUE"
+ AdditionalOptions="">
<IntelOptions
- AllOptions="/OUT:".\Debug\libfaad.lib" /NOLOGO"/>
+ AllOptions="/OUT:".\Debug\libfaad.lib" /NOLOGO"
+ MSOriginalAdditionalOptions=""/>
</Tool>
<Tool
Name="VCMIDLTool"/>
@@ -95,7 +99,8 @@
WarningLevel="3"
SuppressStartupBanner="TRUE"
Detect64BitPortabilityProblems="FALSE"
- CompileAs="0">
+ CompileAs="0"
+ AdditionalOptions="">
<IntelOptions
Optimization="2"
GlobalOptimizations="0"
@@ -111,7 +116,8 @@
RuntimeLibrary="0"
BufferSecurityCheck="1"
FunctionLevelLinking="1"
- AllOptions="/c /nologo /W3 /O2 /Ob1 /Oi /Ot /Oy /G6 /D "NDEBUG" /D "WIN32" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /D "_MBCS" /GF /FD /EHsc /MT /GS /Gy /YX"StdAfx.h" /Fp".\Release/libfaad.pch" /Fo".\Release/" /Fd".\Release/" /Gd"/>
+ AllOptions="/c /nologo /W3 /O2 /Ob1 /Oi /Ot /Oy /G6 /D "NDEBUG" /D "WIN32" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /D "_MBCS" /GF /FD /EHsc /MT /GS /Gy /YX"StdAfx.h" /Fp".\Release/libfaad.pch" /Fo".\Release/" /Fd".\Release/" /Gd"
+ MSOriginalAdditionalOptions=""/>
</Tool>
<Tool
Name="VCCustomBuildTool"/>
@@ -118,9 +124,11 @@
<Tool
Name="VCLibrarianTool"
OutputFile=".\Release\libfaad.lib"
- SuppressStartupBanner="TRUE">
+ SuppressStartupBanner="TRUE"
+ AdditionalOptions="">
<IntelOptions
- AllOptions="/OUT:".\Release\libfaad.lib" /NOLOGO"/>
+ AllOptions="/OUT:".\Release\libfaad.lib" /NOLOGO"
+ MSOriginalAdditionalOptions=""/>
</Tool>
<Tool
Name="VCMIDLTool"/>
--- a/libfaad/rvlc.c
+++ b/libfaad/rvlc.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: rvlc.c,v 1.1 2002/11/28 18:48:30 menno Exp $
+** $Id: rvlc.c,v 1.2 2002/12/05 19:28:22 menno Exp $
**/
/* RVLC scalefactor decoding
@@ -435,9 +435,9 @@
i = h->len;
if (direction > 0)
- cw = faad_getbits(ld_sf, i);
+ cw = faad_getbits(ld_sf, i DEBUGVAR(1,0,""));
else
- cw = faad_getbits_rev(ld_sf, i);
+ cw = faad_getbits_rev(ld_sf, i DEBUGVAR(1,0,""));
while ((cw != h->cw)
&& (i < 10))
@@ -447,9 +447,9 @@
i += j;
cw <<= j;
if (direction > 0)
- cw |= faad_getbits(ld_sf, j);
+ cw |= faad_getbits(ld_sf, j DEBUGVAR(1,0,""));
else
- cw |= faad_getbits_rev(ld_sf, j);
+ cw |= faad_getbits_rev(ld_sf, j DEBUGVAR(1,0,""));
}
index = h->index;
@@ -499,9 +499,9 @@
i += j;
cw <<= j;
if (direction > 0)
- cw |= faad_getbits(ld, j);
+ cw |= faad_getbits(ld, j DEBUGVAR(1,0,""));
else
- cw |= faad_getbits_rev(ld, j);
+ cw |= faad_getbits_rev(ld, j DEBUGVAR(1,0,""));
}
return h->index;
--- 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.33 2002/12/05 18:01:57 menno Exp $
+** $Id: syntax.c,v 1.34 2002/12/05 19:28:22 menno Exp $
**/
/*
@@ -542,13 +542,41 @@
int16_t *spec_data)
{
ic_stream *ics = &(sce->ics1);
-
#ifdef DRM
- if (object_type != DRM_ER_LC)
+ uint8_t result;
+
+ if (hDecoder->object_type != DRM_ER_LC)
#endif
sce->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
DEBUGVAR(1,38,"single_lfe_channel_element(): element_instance_tag"));
+#ifdef DRM
+ if (hDecoder->object_type == DRM_ER_LC)
+ {
+ individual_channel_stream(hDecoder, sce, ld, ics, 0, spec_data);
+
+ if (ics->tns_data_present)
+ tns_data(ics, &(ics->tns), ld);
+
+ if ((result = faad_check_CRC( ld )) > 0)
+ return result;
+
+ /* error resilient spectral data decoding */
+ if ((result = reordered_spectral_data(hDecoder, ics, ld, spec_data)) > 0)
+ return result;
+
+ /* pulse coding reconstruction */
+ if (ics->pulse_data_present)
+ {
+ if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
+ pulse_decode(ics, spec_data);
+ else
+ return 2; /* pulse coding not allowed for short blocks */
+ }
+ return 0;
+ } else
+#endif
+
return individual_channel_stream(hDecoder, sce, ld, ics, 0, spec_data);
}
@@ -562,7 +590,7 @@
ic_stream *ics2 = &(cpe->ics2);
#ifdef DRM
- if (object_type != DRM_ER_LC)
+ if (hDecoder->object_type != DRM_ER_LC)
#endif
cpe->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
DEBUGVAR(1,39,"channel_pair_element(): element_instance_tag"));
@@ -629,6 +657,44 @@
return result;
}
+#ifdef DRM
+ if (hDecoder->object_type == DRM_ER_LC)
+ {
+ if (ics1->tns_data_present)
+ tns_data(ics1, &(ics1->tns), ld);
+
+ if (ics1->tns_data_present)
+ tns_data(ics2, &(ics2->tns), ld);
+
+ if ((result = faad_check_CRC( ld )) > 0)
+ {
+ printf("CRC wrong!\n");
+ return result;
+ }
+ /* error resilient spectral data decoding */
+ if ((result = reordered_spectral_data(hDecoder, ics1, ld, spec_data1)) > 0)
+ return result;
+ if ((result = reordered_spectral_data(hDecoder, ics2, ld, spec_data2)) > 0)
+ return result;
+ /* pulse coding reconstruction */
+ if (ics1->pulse_data_present)
+ {
+ if (ics1->window_sequence != EIGHT_SHORT_SEQUENCE)
+ pulse_decode(ics1, spec_data1);
+ else
+ return 2; /* pulse coding not allowed for short blocks */
+ }
+ if (ics2->pulse_data_present)
+ {
+ if (ics2->window_sequence != EIGHT_SHORT_SEQUENCE)
+ pulse_decode(ics2, spec_data2);
+ else
+ return 2; /* pulse coding not allowed for short blocks */
+ }
+ return 0;
+ } else
+#endif
+
return 0;
}
@@ -925,7 +991,10 @@
DEBUGVAR(1,70,"individual_channel_stream(): gain_control_data_present"))) & 1)
{
#ifdef SSR_DEC
- gain_control_data(ld, ics);
+ if (hDecoder->object_type != SSR)
+ return 1;
+ else
+ gain_control_data(ld, ics);
#else
return 1;
#endif
@@ -935,6 +1004,16 @@
#ifdef ERROR_RESILIENCE
if (hDecoder->aacSpectralDataResilienceFlag)
{
+#if 0
+ if (hDecoder->channelConfiguration == 2)
+ {
+ if (ics->length_of_reordered_spectral_data > 6144)
+ ics->length_of_reordered_spectral_data = 6144;
+ } else {
+ if (ics->length_of_reordered_spectral_data > 12288)
+ ics->length_of_reordered_spectral_data = 12288;
+ }
+#endif
ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data"));
/* TODO: test for >6144/12288, see page 143 */
@@ -950,6 +1029,11 @@
if ((result = rvlc_decode_scale_factors(ics, ld)) > 0)
return result;
}
+
+#ifdef DRM
+ if (hDecoder->object_type == DRM_ER_LC)
+ return 0;
+#endif
if (hDecoder->object_type >= ER_OBJECT_START)
{