summaryrefslogtreecommitdiff
path: root/apps/codecs/libfaad
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-05-10 19:04:24 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-05-10 19:04:24 +0000
commit03e23d111385161afc917abe21b19cf8761e0440 (patch)
tree8c0b71ce052e9f410ee08bb80f932363b3d5d45c /apps/codecs/libfaad
parent78b0f94c76e7d176bf24ab2c9a49f67b32537cc2 (diff)
downloadrockbox-03e23d111385161afc917abe21b19cf8761e0440.zip
rockbox-03e23d111385161afc917abe21b19cf8761e0440.tar.gz
rockbox-03e23d111385161afc917abe21b19cf8761e0440.tar.bz2
rockbox-03e23d111385161afc917abe21b19cf8761e0440.tar.xz
Implement error handling for libfaad's memory allocation. Do not allocate PS related types dynamically anymore to minimize code changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29854 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libfaad')
-rw-r--r--apps/codecs/libfaad/decoder.c10
-rw-r--r--apps/codecs/libfaad/error.c3
-rw-r--r--apps/codecs/libfaad/ps_dec.c10
-rw-r--r--apps/codecs/libfaad/sbr_dec.c24
-rw-r--r--apps/codecs/libfaad/sbr_dec.h7
-rw-r--r--apps/codecs/libfaad/specrec.c22
-rw-r--r--apps/codecs/libfaad/syntax.c25
7 files changed, 66 insertions, 35 deletions
diff --git a/apps/codecs/libfaad/decoder.c b/apps/codecs/libfaad/decoder.c
index 05d7885..caedda7 100644
--- a/apps/codecs/libfaad/decoder.c
+++ b/apps/codecs/libfaad/decoder.c
@@ -346,6 +346,11 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
hDecoder->time_out[i] = s_time_buf_2048[i];
#else
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
+ if (hDecoder->time_out[i] == NULL)
+ {
+ /* could not allocate memory */
+ return -1;
+ }
#endif
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
@@ -469,6 +474,11 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer,
hDecoder->time_out[i] = s_time_buf_2048[i];
#else
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
+ if (hDecoder->time_out[i] == NULL)
+ {
+ /* could not allocate memory */
+ return -1;
+ }
#endif
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
diff --git a/apps/codecs/libfaad/error.c b/apps/codecs/libfaad/error.c
index 8cfd761..ff2f9c3 100644
--- a/apps/codecs/libfaad/error.c
+++ b/apps/codecs/libfaad/error.c
@@ -56,6 +56,7 @@ char *err_msg[] = {
"Unexpected fill element with SBR data",
"Not all elements were provided with SBR data",
"LTP decoding not available",
- "Output data buffer too small"
+ "Output data buffer too small",
+ "Could not allocate enough memory"
};
diff --git a/apps/codecs/libfaad/ps_dec.c b/apps/codecs/libfaad/ps_dec.c
index 335dac7..2c7e5fd 100644
--- a/apps/codecs/libfaad/ps_dec.c
+++ b/apps/codecs/libfaad/ps_dec.c
@@ -159,10 +159,8 @@ typedef struct
/* static variables */
-#ifdef FAAD_STATIC_ALLOC
static hyb_info s_hyb_info;
static ps_info s_ps_info;
-#endif
/* static function declarations */
static void ps_data_decode(ps_info *ps);
@@ -204,11 +202,7 @@ static void ps_mix_phase(ps_info *ps,
static hyb_info *hybrid_init()
{
-#ifdef FAAD_STATIC_ALLOC
hyb_info *hyb = &s_hyb_info;
-#else
- hyb_info *hyb = (hyb_info*)faad_malloc(sizeof(hyb_info));
-#endif
hyb->resolution34[0] = 12;
hyb->resolution34[1] = 8;
@@ -1826,11 +1820,7 @@ ps_info *ps_init(uint8_t sr_index)
uint8_t i;
uint8_t short_delay_band;
-#ifdef FAAD_STATIC_ALLOC
ps_info *ps = &s_ps_info;
-#else
- ps_info *ps = (ps_info*)faad_malloc(sizeof(ps_info));
-#endif
memset(ps, 0, sizeof(ps_info));
(void)sr_index;
diff --git a/apps/codecs/libfaad/sbr_dec.c b/apps/codecs/libfaad/sbr_dec.c
index 7f6a9bb..678ebfe 100644
--- a/apps/codecs/libfaad/sbr_dec.c
+++ b/apps/codecs/libfaad/sbr_dec.c
@@ -73,20 +73,25 @@ static void sbr_save_matrix(sbr_info *sbr, uint8_t ch);
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
- uint32_t sample_rate, uint8_t downSampledSBR
-#ifdef DRM
- , uint8_t IsDRM
-#endif
- )
+ uint32_t sample_rate, uint8_t downSampledSBR,
+ uint8_t IsDRM)
{
(void)downSampledSBR;
+#ifndef DRM
+ (void)IsDRM;
+#endif
/* Allocate sbr_info. */
#if defined(FAAD_STATIC_ALLOC)
sbr_info *sbr = &s_sbr[id_ele];
#else
(void)id_ele;
- sbr_info *sbr =(sbr_info*)faad_malloc(sizeof(sbr_info));
+ sbr_info *sbr = (sbr_info*)faad_malloc(sizeof(sbr_info));
+ if (sbr == NULL)
+ {
+ /* could not allocate memory */
+ return NULL;
+ }
#endif
memset(sbr, 0, sizeof(sbr_info));
@@ -95,7 +100,12 @@ sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
#if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM)
p_XLR = &s_XLR;
#else
- p_XLR =(XLR_t*)faad_malloc(sizeof(XLR_t));
+ p_XLR = (XLR_t*)faad_malloc(sizeof(XLR_t));
+ if (p_XLR == NULL)
+ {
+ /* could not allocate memory */
+ return NULL;
+ }
#endif
memset(p_XLR, 0, sizeof(XLR_t));
diff --git a/apps/codecs/libfaad/sbr_dec.h b/apps/codecs/libfaad/sbr_dec.h
index 81dac32..1a1f5b9 100644
--- a/apps/codecs/libfaad/sbr_dec.h
+++ b/apps/codecs/libfaad/sbr_dec.h
@@ -222,11 +222,8 @@ typedef struct
} sbr_info;
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
- uint32_t sample_rate, uint8_t downSampledSBR
-#ifdef DRM
- , uint8_t IsDRM
-#endif
- );
+ uint32_t sample_rate, uint8_t downSampledSBR,
+ uint8_t IsDRM);
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
const uint8_t just_seeked, const uint8_t downSampledSBR);
diff --git a/apps/codecs/libfaad/specrec.c b/apps/codecs/libfaad/specrec.c
index b5c8305..200239b 100644
--- a/apps/codecs/libfaad/specrec.c
+++ b/apps/codecs/libfaad/specrec.c
@@ -808,11 +808,14 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], ele,
2*get_sample_rate(hDecoder->sf_index),
- hDecoder->downSampledSBR
-#ifdef DRM
- , 0
+ hDecoder->downSampledSBR, 0);
+#ifndef FAAD_STATIC_ALLOC
+ if (hDecoder->sbr[ele] == NULL)
+ {
+ /* could not allocate memory */
+ return 28;
+ }
#endif
- );
}
if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
@@ -1058,11 +1061,14 @@ uint8_t reconstruct_channel_pair(NeAACDecHandle hDecoder, ic_stream *ics1, ic_st
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], ele,
2*get_sample_rate(hDecoder->sf_index),
- hDecoder->downSampledSBR
-#ifdef DRM
- , 0
+ hDecoder->downSampledSBR, 0);
+#ifndef FAAD_STATIC_ALLOC
+ if (hDecoder->sbr[ele] == NULL)
+ {
+ /* could not allocate memory */
+ return 28;
+ }
#endif
- );
}
if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
diff --git a/apps/codecs/libfaad/syntax.c b/apps/codecs/libfaad/syntax.c
index 4c7baab..af1a50f 100644
--- a/apps/codecs/libfaad/syntax.c
+++ b/apps/codecs/libfaad/syntax.c
@@ -1031,11 +1031,14 @@ static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc
hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[sbr_ele], sbr_ele,
2*get_sample_rate(hDecoder->sf_index),
- hDecoder->downSampledSBR
-#ifdef DRM
- , 0
+ hDecoder->downSampledSBR, 0);
+#ifndef FAAD_STATIC_ALLOC
+ if (hDecoder->sbr[sbr_ele] == NULL)
+ {
+ /* could not allocate memory */
+ return 28;
+ }
#endif
- );
}
hDecoder->sbr_present_flag = 1;
@@ -1249,10 +1252,24 @@ void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo
{
hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
+#ifndef FAAD_STATIC_ALLOC
+ if (hDecoder->sbr[0] == NULL)
+ {
+ /* could not allocate memory */
+ hInfo->error = 28;
+ return;
+ }
+#endif
}
/* Reverse bit reading of SBR data in DRM audio frame */
revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t));
+ if (revbuffer == NULL)
+ {
+ /* could not allocate memory */
+ hInfo->error = 28;
+ return;
+ }
prevbufstart = revbuffer;
pbufend = &buffer[buffer_size - 1];
for (i = 0; i < buffer_size; i++)