diff options
Diffstat (limited to 'apps/codecs/vorbis.c')
-rw-r--r-- | apps/codecs/vorbis.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index f14aeead84..7e078139ce 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c | |||
@@ -22,10 +22,13 @@ | |||
22 | #include "codeclib.h" | 22 | #include "codeclib.h" |
23 | #include "libtremor/ivorbisfile.h" | 23 | #include "libtremor/ivorbisfile.h" |
24 | #include "libtremor/ogg.h" | 24 | #include "libtremor/ogg.h" |
25 | #ifdef SIMULATOR | ||
26 | #include "lib/tlsf/src/tlsf.h" | ||
27 | #endif | ||
25 | 28 | ||
26 | CODEC_HEADER | 29 | CODEC_HEADER |
27 | 30 | ||
28 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | 31 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) |
29 | #include <setjmp.h> | 32 | #include <setjmp.h> |
30 | jmp_buf rb_jump_buf; | 33 | jmp_buf rb_jump_buf; |
31 | #endif | 34 | #endif |
@@ -76,8 +79,7 @@ static long tell_handler(void *datasource) | |||
76 | } | 79 | } |
77 | 80 | ||
78 | /* This sets the DSP parameters based on the current logical bitstream | 81 | /* This sets the DSP parameters based on the current logical bitstream |
79 | * (sampling rate, number of channels, etc). It also tries to guess | 82 | * (sampling rate, number of channels, etc). |
80 | * reasonable buffer parameters based on the current quality setting. | ||
81 | */ | 83 | */ |
82 | static bool vorbis_set_codec_parameters(OggVorbis_File *vf) | 84 | static bool vorbis_set_codec_parameters(OggVorbis_File *vf) |
83 | { | 85 | { |
@@ -86,7 +88,6 @@ static bool vorbis_set_codec_parameters(OggVorbis_File *vf) | |||
86 | vi = ov_info(vf, -1); | 88 | vi = ov_info(vf, -1); |
87 | 89 | ||
88 | if (vi == NULL) { | 90 | if (vi == NULL) { |
89 | //ci->splash(HZ*2, "Vorbis Error"); | ||
90 | return false; | 91 | return false; |
91 | } | 92 | } |
92 | 93 | ||
@@ -120,27 +121,23 @@ enum codec_status codec_main(void) | |||
120 | ogg_int64_t vf_pcmlengths[2]; | 121 | ogg_int64_t vf_pcmlengths[2]; |
121 | 122 | ||
122 | ci->configure(DSP_SET_SAMPLE_DEPTH, 24); | 123 | ci->configure(DSP_SET_SAMPLE_DEPTH, 24); |
123 | /* Note: These are sane defaults for these values. Perhaps | ||
124 | * they should be set differently based on quality setting | ||
125 | */ | ||
126 | 124 | ||
127 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | 125 | if (codec_init()) { |
128 | if (setjmp(rb_jump_buf) != 0) | 126 | error = CODEC_ERROR; |
129 | { | 127 | goto exit; |
128 | } | ||
129 | |||
130 | ogg_malloc_init(); | ||
131 | |||
132 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) | ||
133 | if (setjmp(rb_jump_buf) != 0) { | ||
130 | /* malloc failed; skip to next track */ | 134 | /* malloc failed; skip to next track */ |
131 | error = CODEC_ERROR; | 135 | error = CODEC_ERROR; |
132 | goto done; | 136 | goto done; |
133 | } | 137 | } |
134 | #endif | 138 | #endif |
135 | 139 | ||
136 | /* We need to flush reserver memory every track load. */ | ||
137 | next_track: | 140 | next_track: |
138 | if (codec_init()) { | ||
139 | error = CODEC_ERROR; | ||
140 | goto exit; | ||
141 | } | ||
142 | ogg_malloc_init(); | ||
143 | |||
144 | while (!*ci->taginfo_ready && !ci->stop_codec) | 141 | while (!*ci->taginfo_ready && !ci->stop_codec) |
145 | ci->sleep(1); | 142 | ci->sleep(1); |
146 | 143 | ||
@@ -166,6 +163,10 @@ next_track: | |||
166 | * get here. | 163 | * get here. |
167 | */ | 164 | */ |
168 | if (!error) { | 165 | if (!error) { |
166 | ogg_free(vf.offsets); | ||
167 | ogg_free(vf.dataoffsets); | ||
168 | ogg_free(vf.serialnos); | ||
169 | |||
169 | vf.offsets = vf_offsets; | 170 | vf.offsets = vf_offsets; |
170 | vf.dataoffsets = &vf_dataoffsets; | 171 | vf.dataoffsets = &vf_dataoffsets; |
171 | vf.serialnos = &vf_serialnos; | 172 | vf.serialnos = &vf_serialnos; |
@@ -183,7 +184,7 @@ next_track: | |||
183 | vf.ready_state = OPENED; | 184 | vf.ready_state = OPENED; |
184 | vf.links = 1; | 185 | vf.links = 1; |
185 | } else { | 186 | } else { |
186 | //ci->logf("ov_open: %d", error); | 187 | DEBUGF("Vorbis: ov_open failed: %d", error); |
187 | error = CODEC_ERROR; | 188 | error = CODEC_ERROR; |
188 | goto done; | 189 | goto done; |
189 | } | 190 | } |
@@ -225,7 +226,7 @@ next_track: | |||
225 | if (n == 0) { | 226 | if (n == 0) { |
226 | eof = 1; | 227 | eof = 1; |
227 | } else if (n < 0) { | 228 | } else if (n < 0) { |
228 | DEBUGF("Error decoding frame\n"); | 229 | DEBUGF("Vorbis: Error decoding frame\n"); |
229 | } else { | 230 | } else { |
230 | ci->pcmbuf_insert(pcm[0], pcm[1], n); | 231 | ci->pcmbuf_insert(pcm[0], pcm[1], n); |
231 | ci->set_offset(ov_raw_tell(&vf)); | 232 | ci->set_offset(ov_raw_tell(&vf)); |
@@ -235,6 +236,15 @@ next_track: | |||
235 | error = CODEC_OK; | 236 | error = CODEC_OK; |
236 | 237 | ||
237 | done: | 238 | done: |
239 | #if 0 /* defined(SIMULATOR) */ | ||
240 | { | ||
241 | size_t bufsize; | ||
242 | void* buf = ci->codec_get_buffer(&bufsize); | ||
243 | |||
244 | DEBUGF("Vorbis: Memory max: %u\n", get_max_size(buf)); | ||
245 | } | ||
246 | #endif | ||
247 | |||
238 | if (ci->request_next_track()) { | 248 | if (ci->request_next_track()) { |
239 | /* Clean things up for the next track */ | 249 | /* Clean things up for the next track */ |
240 | vf.dataoffsets = NULL; | 250 | vf.dataoffsets = NULL; |
@@ -246,6 +256,6 @@ done: | |||
246 | } | 256 | } |
247 | 257 | ||
248 | exit: | 258 | exit: |
259 | ogg_malloc_destroy(); | ||
249 | return error; | 260 | return error; |
250 | } | 261 | } |
251 | |||