Commit 5bf59dc8 authored by conrad's avatar conrad
Browse files

speex.c: handle remaining malloc/realloc errors, propagate to decode.c

Towards Mozilla bug 468293

git-svn-id: http://svn.annodex.net/libfishsound/trunk@3853 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 3c28f71e
......@@ -79,7 +79,9 @@ typedef int (*FishSoundDecoded_FloatIlv) (FishSound * fsound, float ** pcm,
* \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE)
* \param decoded The callback to call
* \param user_data Arbitrary user data to pass to the callback
* \returns 0 on success, -1 on failure
* \retval 0 Success
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/
int fish_sound_set_decoded_float (FishSound * fsound,
FishSoundDecoded_Float decoded,
......@@ -91,7 +93,9 @@ int fish_sound_set_decoded_float (FishSound * fsound,
* \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE)
* \param decoded The callback to call
* \param user_data Arbitrary user data to pass to the callback
* \returns 0 on success, -1 on failure
* \retval 0 Success
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/
int fish_sound_set_decoded_float_ilv (FishSound * fsound,
FishSoundDecoded_FloatIlv decoded,
......@@ -113,6 +117,7 @@ int fish_sound_set_decoded_float_ilv (FishSound * fsound,
* callback returning FISH_SOUND_STOP_ERR before any input bytes were consumed.
* This will occur when PCM is decoded from previously buffered input, and
* stopping is immediately requested.
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/
long fish_sound_decode (FishSound * fsound, unsigned char * buf, long bytes);
......
......@@ -58,7 +58,7 @@ int fish_sound_set_decoded_float (FishSound * fsound,
{
int ret = 0;
if (fsound == NULL) return -1;
if (fsound == NULL) return FISH_SOUND_ERR_BAD;
#if FS_DECODE
ret = fs_decode_update (fsound, 0);
......@@ -80,7 +80,7 @@ int fish_sound_set_decoded_float_ilv (FishSound * fsound,
{
int ret = 0;
if (fsound == NULL) return -1;
if (fsound == NULL) return FISH_SOUND_ERR_BAD;
#if FS_DECODE
ret = fs_decode_update (fsound, 1);
......@@ -101,7 +101,7 @@ fish_sound_decode (FishSound * fsound, unsigned char * buf, long bytes)
{
int format;
if (fsound == NULL) return -1;
if (fsound == NULL) return FISH_SOUND_ERR_BAD;
#if FS_DECODE
if (fsound->info.format == FISH_SOUND_UNKNOWN) {
......
......@@ -291,12 +291,24 @@ fs_speex_decode (FishSound * fsound, unsigned char * buf, long bytes)
fsound->info.channels = channels;
fss->ipcm = fs_malloc (sizeof (float) * fss->frame_size * channels);
if (fss->ipcm == NULL) {
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
if (channels == 1) {
fss->pcm[0] = fss->ipcm;
} else if (channels == 2) {
fss->pcm[0] = fs_malloc (sizeof (float) * fss->frame_size);
if (fss->pcm[0] == NULL) {
fs_free (fss->ipcm);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
fss->pcm[1] = fs_malloc (sizeof (float) * fss->frame_size);
if (fss->pcm[1] == NULL) {
fs_free (fss->pcm[0]);
fs_free (fss->ipcm);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
}
if (fss->nframes == 0) fss->nframes = 1;
......@@ -617,7 +629,7 @@ fs_speex_update (FishSound * fsound, int interleave)
ipcm_new = (float *)fs_realloc (fss->ipcm,
pcm_size * fss->frame_size * fsound->info.channels);
if (ipcm_new == NULL) return -1;
if (ipcm_new == NULL) return FISH_SOUND_ERR_OUT_OF_MEMORY;
fss->ipcm = ipcm_new;
......@@ -636,13 +648,13 @@ fs_speex_update (FishSound * fsound, int interleave)
} else if (fsound->info.channels == 2) {
pcm0 = fs_realloc (fss->pcm[0], pcm_size * fss->frame_size);
if (pcm0 == NULL) {
return -1;
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
pcm1 = fs_realloc (fss->pcm[1], pcm_size * fss->frame_size);
if (pcm1 == NULL) {
fs_free (pcm0);
return -1;
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
fss->pcm[0] = pcm0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment