diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-10 19:04:24 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-10 19:04:24 +0000 |
commit | 03e23d111385161afc917abe21b19cf8761e0440 (patch) | |
tree | 8c0b71ce052e9f410ee08bb80f932363b3d5d45c | |
parent | 78b0f94c76e7d176bf24ab2c9a49f67b32537cc2 (diff) | |
download | rockbox-03e23d111385161afc917abe21b19cf8761e0440.tar.gz rockbox-03e23d111385161afc917abe21b19cf8761e0440.zip |
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
-rw-r--r-- | apps/codecs/libfaad/decoder.c | 10 | ||||
-rw-r--r-- | apps/codecs/libfaad/error.c | 3 | ||||
-rw-r--r-- | apps/codecs/libfaad/ps_dec.c | 10 | ||||
-rw-r--r-- | apps/codecs/libfaad/sbr_dec.c | 24 | ||||
-rw-r--r-- | apps/codecs/libfaad/sbr_dec.h | 7 | ||||
-rw-r--r-- | apps/codecs/libfaad/specrec.c | 22 | ||||
-rw-r--r-- | apps/codecs/libfaad/syntax.c | 25 |
7 files changed, 66 insertions, 35 deletions
diff --git a/apps/codecs/libfaad/decoder.c b/apps/codecs/libfaad/decoder.c index 05d788597e..caedda7f55 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, | |||
346 | hDecoder->time_out[i] = s_time_buf_2048[i]; | 346 | hDecoder->time_out[i] = s_time_buf_2048[i]; |
347 | #else | 347 | #else |
348 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); | 348 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); |
349 | if (hDecoder->time_out[i] == NULL) | ||
350 | { | ||
351 | /* could not allocate memory */ | ||
352 | return -1; | ||
353 | } | ||
349 | #endif | 354 | #endif |
350 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); | 355 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); |
351 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | 356 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; |
@@ -469,6 +474,11 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer, | |||
469 | hDecoder->time_out[i] = s_time_buf_2048[i]; | 474 | hDecoder->time_out[i] = s_time_buf_2048[i]; |
470 | #else | 475 | #else |
471 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); | 476 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); |
477 | if (hDecoder->time_out[i] == NULL) | ||
478 | { | ||
479 | /* could not allocate memory */ | ||
480 | return -1; | ||
481 | } | ||
472 | #endif | 482 | #endif |
473 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); | 483 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); |
474 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | 484 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; |
diff --git a/apps/codecs/libfaad/error.c b/apps/codecs/libfaad/error.c index 8cfd761754..ff2f9c3d13 100644 --- a/apps/codecs/libfaad/error.c +++ b/apps/codecs/libfaad/error.c | |||
@@ -56,6 +56,7 @@ char *err_msg[] = { | |||
56 | "Unexpected fill element with SBR data", | 56 | "Unexpected fill element with SBR data", |
57 | "Not all elements were provided with SBR data", | 57 | "Not all elements were provided with SBR data", |
58 | "LTP decoding not available", | 58 | "LTP decoding not available", |
59 | "Output data buffer too small" | 59 | "Output data buffer too small", |
60 | "Could not allocate enough memory" | ||
60 | }; | 61 | }; |
61 | 62 | ||
diff --git a/apps/codecs/libfaad/ps_dec.c b/apps/codecs/libfaad/ps_dec.c index 335dac7b1c..2c7e5fdf47 100644 --- a/apps/codecs/libfaad/ps_dec.c +++ b/apps/codecs/libfaad/ps_dec.c | |||
@@ -159,10 +159,8 @@ typedef struct | |||
159 | 159 | ||
160 | 160 | ||
161 | /* static variables */ | 161 | /* static variables */ |
162 | #ifdef FAAD_STATIC_ALLOC | ||
163 | static hyb_info s_hyb_info; | 162 | static hyb_info s_hyb_info; |
164 | static ps_info s_ps_info; | 163 | static ps_info s_ps_info; |
165 | #endif | ||
166 | 164 | ||
167 | /* static function declarations */ | 165 | /* static function declarations */ |
168 | static void ps_data_decode(ps_info *ps); | 166 | static void ps_data_decode(ps_info *ps); |
@@ -204,11 +202,7 @@ static void ps_mix_phase(ps_info *ps, | |||
204 | 202 | ||
205 | static hyb_info *hybrid_init() | 203 | static hyb_info *hybrid_init() |
206 | { | 204 | { |
207 | #ifdef FAAD_STATIC_ALLOC | ||
208 | hyb_info *hyb = &s_hyb_info; | 205 | hyb_info *hyb = &s_hyb_info; |
209 | #else | ||
210 | hyb_info *hyb = (hyb_info*)faad_malloc(sizeof(hyb_info)); | ||
211 | #endif | ||
212 | 206 | ||
213 | hyb->resolution34[0] = 12; | 207 | hyb->resolution34[0] = 12; |
214 | hyb->resolution34[1] = 8; | 208 | hyb->resolution34[1] = 8; |
@@ -1826,11 +1820,7 @@ ps_info *ps_init(uint8_t sr_index) | |||
1826 | uint8_t i; | 1820 | uint8_t i; |
1827 | uint8_t short_delay_band; | 1821 | uint8_t short_delay_band; |
1828 | 1822 | ||
1829 | #ifdef FAAD_STATIC_ALLOC | ||
1830 | ps_info *ps = &s_ps_info; | 1823 | ps_info *ps = &s_ps_info; |
1831 | #else | ||
1832 | ps_info *ps = (ps_info*)faad_malloc(sizeof(ps_info)); | ||
1833 | #endif | ||
1834 | memset(ps, 0, sizeof(ps_info)); | 1824 | memset(ps, 0, sizeof(ps_info)); |
1835 | 1825 | ||
1836 | (void)sr_index; | 1826 | (void)sr_index; |
diff --git a/apps/codecs/libfaad/sbr_dec.c b/apps/codecs/libfaad/sbr_dec.c index 7f6a9bbffe..678ebfe520 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); | |||
73 | 73 | ||
74 | 74 | ||
75 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, | 75 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, |
76 | uint32_t sample_rate, uint8_t downSampledSBR | 76 | uint32_t sample_rate, uint8_t downSampledSBR, |
77 | #ifdef DRM | 77 | uint8_t IsDRM) |
78 | , uint8_t IsDRM | ||
79 | #endif | ||
80 | ) | ||
81 | { | 78 | { |
82 | (void)downSampledSBR; | 79 | (void)downSampledSBR; |
80 | #ifndef DRM | ||
81 | (void)IsDRM; | ||
82 | #endif | ||
83 | 83 | ||
84 | /* Allocate sbr_info. */ | 84 | /* Allocate sbr_info. */ |
85 | #if defined(FAAD_STATIC_ALLOC) | 85 | #if defined(FAAD_STATIC_ALLOC) |
86 | sbr_info *sbr = &s_sbr[id_ele]; | 86 | sbr_info *sbr = &s_sbr[id_ele]; |
87 | #else | 87 | #else |
88 | (void)id_ele; | 88 | (void)id_ele; |
89 | sbr_info *sbr =(sbr_info*)faad_malloc(sizeof(sbr_info)); | 89 | sbr_info *sbr = (sbr_info*)faad_malloc(sizeof(sbr_info)); |
90 | if (sbr == NULL) | ||
91 | { | ||
92 | /* could not allocate memory */ | ||
93 | return NULL; | ||
94 | } | ||
90 | #endif | 95 | #endif |
91 | memset(sbr, 0, sizeof(sbr_info)); | 96 | memset(sbr, 0, sizeof(sbr_info)); |
92 | 97 | ||
@@ -95,7 +100,12 @@ sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, | |||
95 | #if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM) | 100 | #if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM) |
96 | p_XLR = &s_XLR; | 101 | p_XLR = &s_XLR; |
97 | #else | 102 | #else |
98 | p_XLR =(XLR_t*)faad_malloc(sizeof(XLR_t)); | 103 | p_XLR = (XLR_t*)faad_malloc(sizeof(XLR_t)); |
104 | if (p_XLR == NULL) | ||
105 | { | ||
106 | /* could not allocate memory */ | ||
107 | return NULL; | ||
108 | } | ||
99 | #endif | 109 | #endif |
100 | memset(p_XLR, 0, sizeof(XLR_t)); | 110 | memset(p_XLR, 0, sizeof(XLR_t)); |
101 | 111 | ||
diff --git a/apps/codecs/libfaad/sbr_dec.h b/apps/codecs/libfaad/sbr_dec.h index 81dac32946..1a1f5b9b32 100644 --- a/apps/codecs/libfaad/sbr_dec.h +++ b/apps/codecs/libfaad/sbr_dec.h | |||
@@ -222,11 +222,8 @@ typedef struct | |||
222 | } sbr_info; | 222 | } sbr_info; |
223 | 223 | ||
224 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, | 224 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, |
225 | uint32_t sample_rate, uint8_t downSampledSBR | 225 | uint32_t sample_rate, uint8_t downSampledSBR, |
226 | #ifdef DRM | 226 | uint8_t IsDRM); |
227 | , uint8_t IsDRM | ||
228 | #endif | ||
229 | ); | ||
230 | 227 | ||
231 | uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan, | 228 | uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan, |
232 | const uint8_t just_seeked, const uint8_t downSampledSBR); | 229 | const uint8_t just_seeked, const uint8_t downSampledSBR); |
diff --git a/apps/codecs/libfaad/specrec.c b/apps/codecs/libfaad/specrec.c index b5c8305237..200239bddc 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, | |||
808 | hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | 808 | hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, |
809 | hDecoder->element_id[ele], ele, | 809 | hDecoder->element_id[ele], ele, |
810 | 2*get_sample_rate(hDecoder->sf_index), | 810 | 2*get_sample_rate(hDecoder->sf_index), |
811 | hDecoder->downSampledSBR | 811 | hDecoder->downSampledSBR, 0); |
812 | #ifdef DRM | 812 | #ifndef FAAD_STATIC_ALLOC |
813 | , 0 | 813 | if (hDecoder->sbr[ele] == NULL) |
814 | { | ||
815 | /* could not allocate memory */ | ||
816 | return 28; | ||
817 | } | ||
814 | #endif | 818 | #endif |
815 | ); | ||
816 | } | 819 | } |
817 | 820 | ||
818 | if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) | 821 | if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) |
@@ -1058,11 +1061,14 @@ uint8_t reconstruct_channel_pair(NeAACDecHandle hDecoder, ic_stream *ics1, ic_st | |||
1058 | hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | 1061 | hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, |
1059 | hDecoder->element_id[ele], ele, | 1062 | hDecoder->element_id[ele], ele, |
1060 | 2*get_sample_rate(hDecoder->sf_index), | 1063 | 2*get_sample_rate(hDecoder->sf_index), |
1061 | hDecoder->downSampledSBR | 1064 | hDecoder->downSampledSBR, 0); |
1062 | #ifdef DRM | 1065 | #ifndef FAAD_STATIC_ALLOC |
1063 | , 0 | 1066 | if (hDecoder->sbr[ele] == NULL) |
1067 | { | ||
1068 | /* could not allocate memory */ | ||
1069 | return 28; | ||
1070 | } | ||
1064 | #endif | 1071 | #endif |
1065 | ); | ||
1066 | } | 1072 | } |
1067 | 1073 | ||
1068 | if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) | 1074 | if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) |
diff --git a/apps/codecs/libfaad/syntax.c b/apps/codecs/libfaad/syntax.c index 4c7baab274..af1a50f4d8 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 | |||
1031 | hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength, | 1031 | hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength, |
1032 | hDecoder->element_id[sbr_ele], sbr_ele, | 1032 | hDecoder->element_id[sbr_ele], sbr_ele, |
1033 | 2*get_sample_rate(hDecoder->sf_index), | 1033 | 2*get_sample_rate(hDecoder->sf_index), |
1034 | hDecoder->downSampledSBR | 1034 | hDecoder->downSampledSBR, 0); |
1035 | #ifdef DRM | 1035 | #ifndef FAAD_STATIC_ALLOC |
1036 | , 0 | 1036 | if (hDecoder->sbr[sbr_ele] == NULL) |
1037 | { | ||
1038 | /* could not allocate memory */ | ||
1039 | return 28; | ||
1040 | } | ||
1037 | #endif | 1041 | #endif |
1038 | ); | ||
1039 | } | 1042 | } |
1040 | 1043 | ||
1041 | hDecoder->sbr_present_flag = 1; | 1044 | hDecoder->sbr_present_flag = 1; |
@@ -1249,10 +1252,24 @@ void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo | |||
1249 | { | 1252 | { |
1250 | hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0], | 1253 | hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0], |
1251 | 2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1); | 1254 | 2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1); |
1255 | #ifndef FAAD_STATIC_ALLOC | ||
1256 | if (hDecoder->sbr[0] == NULL) | ||
1257 | { | ||
1258 | /* could not allocate memory */ | ||
1259 | hInfo->error = 28; | ||
1260 | return; | ||
1261 | } | ||
1262 | #endif | ||
1252 | } | 1263 | } |
1253 | 1264 | ||
1254 | /* Reverse bit reading of SBR data in DRM audio frame */ | 1265 | /* Reverse bit reading of SBR data in DRM audio frame */ |
1255 | revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t)); | 1266 | revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t)); |
1267 | if (revbuffer == NULL) | ||
1268 | { | ||
1269 | /* could not allocate memory */ | ||
1270 | hInfo->error = 28; | ||
1271 | return; | ||
1272 | } | ||
1256 | prevbufstart = revbuffer; | 1273 | prevbufstart = revbuffer; |
1257 | pbufend = &buffer[buffer_size - 1]; | 1274 | pbufend = &buffer[buffer_size - 1]; |
1258 | for (i = 0; i < buffer_size; i++) | 1275 | for (i = 0; i < buffer_size; i++) |