From f4515c3082dd413017ae06c25d7e85b1dcee30bf Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Sun, 8 Mar 2009 12:48:58 +0000 Subject: Add setjmp/longjmp for ARM and ColdFire to the codec lib, and use it in the Vorbis codec to better handle out of memory conditions (to exit rather than crash; the AAC codec could use it too). setjmp/longjmp comes from newlib 1.17.0 with a few minor changes (combine parts of some files, remove support for some architectures, change some ifdef's). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20235 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/vorbis.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'apps/codecs/vorbis.c') diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index 74d582ebb3..f14aeead84 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -25,6 +25,11 @@ CODEC_HEADER +#if defined(CPU_ARM) || defined(CPU_COLDFIRE) +#include +jmp_buf rb_jump_buf; +#endif + /* Some standard functions and variables needed by Tremor */ static size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) @@ -107,7 +112,7 @@ enum codec_status codec_main(void) int error; long n; int current_section; - int previous_section = -1; + int previous_section; int eof; ogg_int64_t vf_offsets[2]; ogg_int64_t vf_dataoffsets; @@ -119,6 +124,15 @@ enum codec_status codec_main(void) * they should be set differently based on quality setting */ +#if defined(CPU_ARM) || defined(CPU_COLDFIRE) + if (setjmp(rb_jump_buf) != 0) + { + /* malloc failed; skip to next track */ + error = CODEC_ERROR; + goto done; + } +#endif + /* We need to flush reserver memory every track load. */ next_track: if (codec_init()) { @@ -181,6 +195,7 @@ next_track: ci->set_offset(ov_raw_tell(&vf)); } + previous_section = -1; eof = 0; while (!eof) { ci->yield(); @@ -227,7 +242,6 @@ done: vf.serialnos = NULL; vf.pcmlengths = NULL; ov_clear(&vf); - previous_section = -1; goto next_track; } -- cgit v1.2.3