diff options
author | Magnus Holmgren <magnushol@gmail.com> | 2009-03-08 12:48:58 +0000 |
---|---|---|
committer | Magnus Holmgren <magnushol@gmail.com> | 2009-03-08 12:48:58 +0000 |
commit | f4515c3082dd413017ae06c25d7e85b1dcee30bf (patch) | |
tree | 1154b2fd5049aa42a1fdd2047effd39e9da1ccaa /apps/codecs/vorbis.c | |
parent | 3f69bb2b1d00ccc54e2097fd9da750fcd2f7e11b (diff) | |
download | rockbox-f4515c3082dd413017ae06c25d7e85b1dcee30bf.tar.gz rockbox-f4515c3082dd413017ae06c25d7e85b1dcee30bf.zip |
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
Diffstat (limited to 'apps/codecs/vorbis.c')
-rw-r--r-- | apps/codecs/vorbis.c | 18 |
1 files changed, 16 insertions, 2 deletions
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 @@ | |||
25 | 25 | ||
26 | CODEC_HEADER | 26 | CODEC_HEADER |
27 | 27 | ||
28 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | ||
29 | #include <setjmp.h> | ||
30 | jmp_buf rb_jump_buf; | ||
31 | #endif | ||
32 | |||
28 | /* Some standard functions and variables needed by Tremor */ | 33 | /* Some standard functions and variables needed by Tremor */ |
29 | 34 | ||
30 | static size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) | 35 | 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) | |||
107 | int error; | 112 | int error; |
108 | long n; | 113 | long n; |
109 | int current_section; | 114 | int current_section; |
110 | int previous_section = -1; | 115 | int previous_section; |
111 | int eof; | 116 | int eof; |
112 | ogg_int64_t vf_offsets[2]; | 117 | ogg_int64_t vf_offsets[2]; |
113 | ogg_int64_t vf_dataoffsets; | 118 | ogg_int64_t vf_dataoffsets; |
@@ -119,6 +124,15 @@ enum codec_status codec_main(void) | |||
119 | * they should be set differently based on quality setting | 124 | * they should be set differently based on quality setting |
120 | */ | 125 | */ |
121 | 126 | ||
127 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | ||
128 | if (setjmp(rb_jump_buf) != 0) | ||
129 | { | ||
130 | /* malloc failed; skip to next track */ | ||
131 | error = CODEC_ERROR; | ||
132 | goto done; | ||
133 | } | ||
134 | #endif | ||
135 | |||
122 | /* We need to flush reserver memory every track load. */ | 136 | /* We need to flush reserver memory every track load. */ |
123 | next_track: | 137 | next_track: |
124 | if (codec_init()) { | 138 | if (codec_init()) { |
@@ -181,6 +195,7 @@ next_track: | |||
181 | ci->set_offset(ov_raw_tell(&vf)); | 195 | ci->set_offset(ov_raw_tell(&vf)); |
182 | } | 196 | } |
183 | 197 | ||
198 | previous_section = -1; | ||
184 | eof = 0; | 199 | eof = 0; |
185 | while (!eof) { | 200 | while (!eof) { |
186 | ci->yield(); | 201 | ci->yield(); |
@@ -227,7 +242,6 @@ done: | |||
227 | vf.serialnos = NULL; | 242 | vf.serialnos = NULL; |
228 | vf.pcmlengths = NULL; | 243 | vf.pcmlengths = NULL; |
229 | ov_clear(&vf); | 244 | ov_clear(&vf); |
230 | previous_section = -1; | ||
231 | goto next_track; | 245 | goto next_track; |
232 | } | 246 | } |
233 | 247 | ||