forked from len0rd/rockbox
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
This commit is contained in:
parent
78b0f94c76
commit
03e23d1113
7 changed files with 66 additions and 35 deletions
|
|
@ -346,6 +346,11 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
|
||||||
hDecoder->time_out[i] = s_time_buf_2048[i];
|
hDecoder->time_out[i] = s_time_buf_2048[i];
|
||||||
#else
|
#else
|
||||||
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
|
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
|
#endif
|
||||||
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
|
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
|
||||||
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
|
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];
|
hDecoder->time_out[i] = s_time_buf_2048[i];
|
||||||
#else
|
#else
|
||||||
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
|
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
|
#endif
|
||||||
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
|
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
|
||||||
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
|
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ char *err_msg[] = {
|
||||||
"Unexpected fill element with SBR data",
|
"Unexpected fill element with SBR data",
|
||||||
"Not all elements were provided with SBR data",
|
"Not all elements were provided with SBR data",
|
||||||
"LTP decoding not available",
|
"LTP decoding not available",
|
||||||
"Output data buffer too small"
|
"Output data buffer too small",
|
||||||
|
"Could not allocate enough memory"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,8 @@ typedef struct
|
||||||
|
|
||||||
|
|
||||||
/* static variables */
|
/* static variables */
|
||||||
#ifdef FAAD_STATIC_ALLOC
|
|
||||||
static hyb_info s_hyb_info;
|
static hyb_info s_hyb_info;
|
||||||
static ps_info s_ps_info;
|
static ps_info s_ps_info;
|
||||||
#endif
|
|
||||||
|
|
||||||
/* static function declarations */
|
/* static function declarations */
|
||||||
static void ps_data_decode(ps_info *ps);
|
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()
|
static hyb_info *hybrid_init()
|
||||||
{
|
{
|
||||||
#ifdef FAAD_STATIC_ALLOC
|
|
||||||
hyb_info *hyb = &s_hyb_info;
|
hyb_info *hyb = &s_hyb_info;
|
||||||
#else
|
|
||||||
hyb_info *hyb = (hyb_info*)faad_malloc(sizeof(hyb_info));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hyb->resolution34[0] = 12;
|
hyb->resolution34[0] = 12;
|
||||||
hyb->resolution34[1] = 8;
|
hyb->resolution34[1] = 8;
|
||||||
|
|
@ -1826,11 +1820,7 @@ ps_info *ps_init(uint8_t sr_index)
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint8_t short_delay_band;
|
uint8_t short_delay_band;
|
||||||
|
|
||||||
#ifdef FAAD_STATIC_ALLOC
|
|
||||||
ps_info *ps = &s_ps_info;
|
ps_info *ps = &s_ps_info;
|
||||||
#else
|
|
||||||
ps_info *ps = (ps_info*)faad_malloc(sizeof(ps_info));
|
|
||||||
#endif
|
|
||||||
memset(ps, 0, sizeof(ps_info));
|
memset(ps, 0, sizeof(ps_info));
|
||||||
|
|
||||||
(void)sr_index;
|
(void)sr_index;
|
||||||
|
|
|
||||||
|
|
@ -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,
|
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
|
||||||
uint32_t sample_rate, uint8_t downSampledSBR
|
uint32_t sample_rate, uint8_t downSampledSBR,
|
||||||
#ifdef DRM
|
uint8_t IsDRM)
|
||||||
, uint8_t IsDRM
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
(void)downSampledSBR;
|
(void)downSampledSBR;
|
||||||
|
#ifndef DRM
|
||||||
|
(void)IsDRM;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Allocate sbr_info. */
|
/* Allocate sbr_info. */
|
||||||
#if defined(FAAD_STATIC_ALLOC)
|
#if defined(FAAD_STATIC_ALLOC)
|
||||||
sbr_info *sbr = &s_sbr[id_ele];
|
sbr_info *sbr = &s_sbr[id_ele];
|
||||||
#else
|
#else
|
||||||
(void)id_ele;
|
(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
|
#endif
|
||||||
memset(sbr, 0, sizeof(sbr_info));
|
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)
|
#if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM)
|
||||||
p_XLR = &s_XLR;
|
p_XLR = &s_XLR;
|
||||||
#else
|
#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
|
#endif
|
||||||
memset(p_XLR, 0, sizeof(XLR_t));
|
memset(p_XLR, 0, sizeof(XLR_t));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,11 +222,8 @@ typedef struct
|
||||||
} sbr_info;
|
} sbr_info;
|
||||||
|
|
||||||
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
|
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
|
||||||
uint32_t sample_rate, uint8_t downSampledSBR
|
uint32_t sample_rate, uint8_t downSampledSBR,
|
||||||
#ifdef DRM
|
uint8_t IsDRM);
|
||||||
, uint8_t IsDRM
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
|
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
|
||||||
const uint8_t just_seeked, const uint8_t downSampledSBR);
|
const uint8_t just_seeked, const uint8_t downSampledSBR);
|
||||||
|
|
|
||||||
|
|
@ -808,11 +808,14 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
|
||||||
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
|
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
|
||||||
hDecoder->element_id[ele], ele,
|
hDecoder->element_id[ele], ele,
|
||||||
2*get_sample_rate(hDecoder->sf_index),
|
2*get_sample_rate(hDecoder->sf_index),
|
||||||
hDecoder->downSampledSBR
|
hDecoder->downSampledSBR, 0);
|
||||||
#ifdef DRM
|
#ifndef FAAD_STATIC_ALLOC
|
||||||
, 0
|
if (hDecoder->sbr[ele] == NULL)
|
||||||
|
{
|
||||||
|
/* could not allocate memory */
|
||||||
|
return 28;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
|
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->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
|
||||||
hDecoder->element_id[ele], ele,
|
hDecoder->element_id[ele], ele,
|
||||||
2*get_sample_rate(hDecoder->sf_index),
|
2*get_sample_rate(hDecoder->sf_index),
|
||||||
hDecoder->downSampledSBR
|
hDecoder->downSampledSBR, 0);
|
||||||
#ifdef DRM
|
#ifndef FAAD_STATIC_ALLOC
|
||||||
, 0
|
if (hDecoder->sbr[ele] == NULL)
|
||||||
|
{
|
||||||
|
/* could not allocate memory */
|
||||||
|
return 28;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
|
if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
|
||||||
|
|
|
||||||
|
|
@ -1031,11 +1031,14 @@ static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc
|
||||||
hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
|
hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
|
||||||
hDecoder->element_id[sbr_ele], sbr_ele,
|
hDecoder->element_id[sbr_ele], sbr_ele,
|
||||||
2*get_sample_rate(hDecoder->sf_index),
|
2*get_sample_rate(hDecoder->sf_index),
|
||||||
hDecoder->downSampledSBR
|
hDecoder->downSampledSBR, 0);
|
||||||
#ifdef DRM
|
#ifndef FAAD_STATIC_ALLOC
|
||||||
, 0
|
if (hDecoder->sbr[sbr_ele] == NULL)
|
||||||
|
{
|
||||||
|
/* could not allocate memory */
|
||||||
|
return 28;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hDecoder->sbr_present_flag = 1;
|
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],
|
hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
|
||||||
2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
|
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 */
|
/* Reverse bit reading of SBR data in DRM audio frame */
|
||||||
revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t));
|
revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t));
|
||||||
|
if (revbuffer == NULL)
|
||||||
|
{
|
||||||
|
/* could not allocate memory */
|
||||||
|
hInfo->error = 28;
|
||||||
|
return;
|
||||||
|
}
|
||||||
prevbufstart = revbuffer;
|
prevbufstart = revbuffer;
|
||||||
pbufend = &buffer[buffer_size - 1];
|
pbufend = &buffer[buffer_size - 1];
|
||||||
for (i = 0; i < buffer_size; i++)
|
for (i = 0; i < buffer_size; i++)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue