summaryrefslogtreecommitdiff
path: root/apps/codecs/vorbis.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/vorbis.c')
-rw-r--r--apps/codecs/vorbis.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c
index 0a36a37c8b..e02d459262 100644
--- a/apps/codecs/vorbis.c
+++ b/apps/codecs/vorbis.c
@@ -104,14 +104,25 @@ static bool vorbis_set_codec_parameters(OggVorbis_File *vf)
104} 104}
105 105
106/* this is the codec entry point */ 106/* this is the codec entry point */
107enum codec_status codec_main(void) 107enum codec_status codec_main(enum codec_entry_call_reason reason)
108{
109 if (reason == CODEC_LOAD) {
110 if (codec_init())
111 return CODEC_ERROR;
112 ci->configure(DSP_SET_SAMPLE_DEPTH, 24);
113 }
114
115 return CODEC_OK;
116}
117
118/* this is called for each file to process */
119enum codec_status codec_run(void)
108{ 120{
109 ov_callbacks callbacks; 121 ov_callbacks callbacks;
110 OggVorbis_File vf; 122 OggVorbis_File vf;
111 ogg_int32_t **pcm; 123 ogg_int32_t **pcm;
112 124
113 bool initialized = false; /* First init done? */ 125 int error = CODEC_ERROR;
114 int error;
115 long n; 126 long n;
116 int current_section; 127 int current_section;
117 int previous_section; 128 int previous_section;
@@ -120,36 +131,24 @@ enum codec_status codec_main(void)
120 ogg_int64_t vf_dataoffsets; 131 ogg_int64_t vf_dataoffsets;
121 ogg_uint32_t vf_serialnos; 132 ogg_uint32_t vf_serialnos;
122 ogg_int64_t vf_pcmlengths[2]; 133 ogg_int64_t vf_pcmlengths[2];
123 134 intptr_t param;
124 ci->configure(DSP_SET_SAMPLE_DEPTH, 24);
125
126 if (codec_init()) {
127 error = CODEC_ERROR;
128 goto exit;
129 }
130 135
131#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) 136#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS)
132 if (setjmp(rb_jump_buf) != 0) { 137 if (setjmp(rb_jump_buf) != 0) {
133 /* malloc failed; skip to next track */ 138 /* malloc failed; finish with this track */
134 error = CODEC_ERROR;
135 goto done; 139 goto done;
136 } 140 }
137#endif 141#endif
138
139next_track:
140 error = CODEC_OK;
141
142 ogg_malloc_init(); 142 ogg_malloc_init();
143 143
144 if (codec_wait_taginfo() != 0)
145 goto done;
146
147 /* Create a decoder instance */ 144 /* Create a decoder instance */
148 callbacks.read_func = read_handler; 145 callbacks.read_func = read_handler;
149 callbacks.seek_func = initial_seek_handler; 146 callbacks.seek_func = initial_seek_handler;
150 callbacks.tell_func = tell_handler; 147 callbacks.tell_func = tell_handler;
151 callbacks.close_func = close_handler; 148 callbacks.close_func = close_handler;
152 149
150 ci->seek_buffer(0);
151
153 /* Open a non-seekable stream */ 152 /* Open a non-seekable stream */
154 error = ov_open_callbacks(ci, &vf, NULL, 0, callbacks); 153 error = ov_open_callbacks(ci, &vf, NULL, 0, callbacks);
155 154
@@ -186,15 +185,13 @@ next_track:
186 vf.end = ci->id3->filesize; 185 vf.end = ci->id3->filesize;
187 vf.ready_state = OPENED; 186 vf.ready_state = OPENED;
188 vf.links = 1; 187 vf.links = 1;
189 initialized = true;
190 } else { 188 } else {
191 DEBUGF("Vorbis: ov_open failed: %d\n", error); 189 DEBUGF("Vorbis: ov_open failed: %d\n", error);
192 error = CODEC_ERROR;
193 goto done; 190 goto done;
194 } 191 }
195 192
196 if (ci->id3->offset) { 193 if (ci->id3->offset) {
197 ci->advance_buffer(ci->id3->offset); 194 ci->seek_buffer(ci->id3->offset);
198 ov_raw_seek(&vf, ci->id3->offset); 195 ov_raw_seek(&vf, ci->id3->offset);
199 ci->set_elapsed(ov_time_tell(&vf)); 196 ci->set_elapsed(ov_time_tell(&vf));
200 ci->set_offset(ov_raw_tell(&vf)); 197 ci->set_offset(ov_raw_tell(&vf));
@@ -203,14 +200,17 @@ next_track:
203 previous_section = -1; 200 previous_section = -1;
204 eof = 0; 201 eof = 0;
205 while (!eof) { 202 while (!eof) {
206 ci->yield(); 203 enum codec_command_action action = ci->get_command(&param);
207 if (ci->stop_codec || ci->new_track) 204
205 if (action == CODEC_ACTION_HALT)
208 break; 206 break;
209 207
210 if (ci->seek_time) { 208 if (action == CODEC_ACTION_SEEK_TIME) {
211 if (ov_time_seek(&vf, ci->seek_time - 1)) { 209 if (ov_time_seek(&vf, param)) {
212 //ci->logf("ov_time_seek failed"); 210 //ci->logf("ov_time_seek failed");
213 } 211 }
212
213 ci->set_elapsed(ov_time_tell(&vf));
214 ci->seek_complete(); 214 ci->seek_complete();
215 } 215 }
216 216
@@ -220,7 +220,6 @@ next_track:
220 /* Change DSP and buffer settings for this bitstream */ 220 /* Change DSP and buffer settings for this bitstream */
221 if (current_section != previous_section) { 221 if (current_section != previous_section) {
222 if (!vorbis_set_codec_parameters(&vf)) { 222 if (!vorbis_set_codec_parameters(&vf)) {
223 error = CODEC_ERROR;
224 goto done; 223 goto done;
225 } else { 224 } else {
226 previous_section = current_section; 225 previous_section = current_section;
@@ -238,6 +237,7 @@ next_track:
238 } 237 }
239 } 238 }
240 239
240 error = CODEC_OK;
241done: 241done:
242#if 0 /* defined(SIMULATOR) */ 242#if 0 /* defined(SIMULATOR) */
243 { 243 {
@@ -249,18 +249,12 @@ done:
249#endif 249#endif
250 ogg_malloc_destroy(); 250 ogg_malloc_destroy();
251 251
252 if (ci->request_next_track()) { 252 /* Clean things up for the next track */
253 if (!initialized) 253 vf.dataoffsets = NULL;
254 goto next_track; 254 vf.offsets = NULL;
255 /* Clean things up for the next track */ 255 vf.serialnos = NULL;
256 vf.dataoffsets = NULL; 256 vf.pcmlengths = NULL;
257 vf.offsets = NULL; 257 ov_clear(&vf);
258 vf.serialnos = NULL; 258
259 vf.pcmlengths = NULL;
260 ov_clear(&vf);
261 goto next_track;
262 }
263
264exit:
265 return error; 259 return error;
266} 260}