diff options
Diffstat (limited to 'apps/codecs/au.c')
-rw-r--r-- | apps/codecs/au.c | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/apps/codecs/au.c b/apps/codecs/au.c index 3f9436c9e7..e06f931cf9 100644 --- a/apps/codecs/au.c +++ b/apps/codecs/au.c | |||
@@ -106,9 +106,19 @@ static int convert_au_format(unsigned int encoding, struct pcm_format *fmt) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | /* this is the codec entry point */ | 108 | /* this is the codec entry point */ |
109 | enum codec_status codec_main(void) | 109 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
110 | { | ||
111 | if (reason == CODEC_LOAD) { | ||
112 | /* Generic codec initialisation */ | ||
113 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); | ||
114 | } | ||
115 | |||
116 | return CODEC_OK; | ||
117 | } | ||
118 | |||
119 | /* this is called for each file to process */ | ||
120 | enum codec_status codec_run(void) | ||
110 | { | 121 | { |
111 | int status; | ||
112 | struct pcm_format format; | 122 | struct pcm_format format; |
113 | uint32_t bytesdone, decodedsamples; | 123 | uint32_t bytesdone, decodedsamples; |
114 | size_t n; | 124 | size_t n; |
@@ -119,22 +129,13 @@ enum codec_status codec_main(void) | |||
119 | off_t firstblockposn; /* position of the first block in file */ | 129 | off_t firstblockposn; /* position of the first block in file */ |
120 | const struct pcm_codec *codec; | 130 | const struct pcm_codec *codec; |
121 | int offset = 0; | 131 | int offset = 0; |
122 | 132 | intptr_t param; | |
123 | /* Generic codec initialisation */ | 133 | |
124 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); | ||
125 | |||
126 | next_track: | ||
127 | status = CODEC_OK; | ||
128 | |||
129 | if (codec_init()) { | 134 | if (codec_init()) { |
130 | DEBUGF("codec_init() error\n"); | 135 | DEBUGF("codec_init() error\n"); |
131 | status = CODEC_ERROR; | 136 | return CODEC_ERROR; |
132 | goto exit; | ||
133 | } | 137 | } |
134 | 138 | ||
135 | if (codec_wait_taginfo() != 0) | ||
136 | goto done; | ||
137 | |||
138 | codec_set_replaygain(ci->id3); | 139 | codec_set_replaygain(ci->id3); |
139 | 140 | ||
140 | /* Need to save offset for later use (cleared indirectly by advance_buffer) */ | 141 | /* Need to save offset for later use (cleared indirectly by advance_buffer) */ |
@@ -145,6 +146,7 @@ next_track: | |||
145 | format.is_little_endian = false; | 146 | format.is_little_endian = false; |
146 | 147 | ||
147 | /* set format */ | 148 | /* set format */ |
149 | ci->seek_buffer(0); | ||
148 | buf = ci->request_buffer(&n, 24); | 150 | buf = ci->request_buffer(&n, 24); |
149 | if (n < 24 || (memcmp(buf, ".snd", 4) != 0)) | 151 | if (n < 24 || (memcmp(buf, ".snd", 4) != 0)) |
150 | { | 152 | { |
@@ -170,8 +172,7 @@ next_track: | |||
170 | if (offset < 24) | 172 | if (offset < 24) |
171 | { | 173 | { |
172 | DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset); | 174 | DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset); |
173 | status = CODEC_ERROR; | 175 | return CODEC_ERROR; |
174 | goto done; | ||
175 | } | 176 | } |
176 | /* data size */ | 177 | /* data size */ |
177 | format.numbytes = get_be32(buf + 8); | 178 | format.numbytes = get_be32(buf + 8); |
@@ -182,8 +183,7 @@ next_track: | |||
182 | if (format.formattag == AU_FORMAT_UNSUPPORT) | 183 | if (format.formattag == AU_FORMAT_UNSUPPORT) |
183 | { | 184 | { |
184 | DEBUGF("CODEC_ERROR: sun audio unsupport format: %d\n", get_be32(buf + 12)); | 185 | DEBUGF("CODEC_ERROR: sun audio unsupport format: %d\n", get_be32(buf + 12)); |
185 | status = CODEC_ERROR; | 186 | return CODEC_ERROR; |
186 | goto done; | ||
187 | } | 187 | } |
188 | /* skip sample rate */ | 188 | /* skip sample rate */ |
189 | format.channels = get_be32(buf + 20); | 189 | format.channels = get_be32(buf + 20); |
@@ -202,20 +202,17 @@ next_track: | |||
202 | if (!codec) | 202 | if (!codec) |
203 | { | 203 | { |
204 | DEBUGF("CODEC_ERROR: unsupport sun audio format: %x\n", (int)format.formattag); | 204 | DEBUGF("CODEC_ERROR: unsupport sun audio format: %x\n", (int)format.formattag); |
205 | status = CODEC_ERROR; | 205 | return CODEC_ERROR; |
206 | goto done; | ||
207 | } | 206 | } |
208 | 207 | ||
209 | if (!codec->set_format(&format)) | 208 | if (!codec->set_format(&format)) |
210 | { | 209 | { |
211 | status = CODEC_ERROR; | 210 | return CODEC_ERROR; |
212 | goto done; | ||
213 | } | 211 | } |
214 | 212 | ||
215 | if (format.numbytes == 0) { | 213 | if (format.numbytes == 0) { |
216 | DEBUGF("CODEC_ERROR: data size is 0\n"); | 214 | DEBUGF("CODEC_ERROR: data size is 0\n"); |
217 | status = CODEC_ERROR; | 215 | return CODEC_ERROR; |
218 | goto done; | ||
219 | } | 216 | } |
220 | 217 | ||
221 | /* check chunksize */ | 218 | /* check chunksize */ |
@@ -225,8 +222,7 @@ next_track: | |||
225 | if (format.chunksize == 0) | 222 | if (format.chunksize == 0) |
226 | { | 223 | { |
227 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); | 224 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); |
228 | status = CODEC_ERROR; | 225 | return CODEC_ERROR; |
229 | goto done; | ||
230 | } | 226 | } |
231 | 227 | ||
232 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); | 228 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); |
@@ -236,8 +232,7 @@ next_track: | |||
236 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | 232 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); |
237 | } else { | 233 | } else { |
238 | DEBUGF("CODEC_ERROR: more than 2 channels\n"); | 234 | DEBUGF("CODEC_ERROR: more than 2 channels\n"); |
239 | status = CODEC_ERROR; | 235 | return CODEC_ERROR; |
240 | goto done; | ||
241 | } | 236 | } |
242 | 237 | ||
243 | /* make sure we're at the correct offset */ | 238 | /* make sure we're at the correct offset */ |
@@ -253,7 +248,6 @@ next_track: | |||
253 | bytesdone = newpos->pos; | 248 | bytesdone = newpos->pos; |
254 | decodedsamples = newpos->samples; | 249 | decodedsamples = newpos->samples; |
255 | } | 250 | } |
256 | ci->seek_complete(); | ||
257 | } else { | 251 | } else { |
258 | /* already where we need to be */ | 252 | /* already where we need to be */ |
259 | bytesdone = 0; | 253 | bytesdone = 0; |
@@ -263,22 +257,29 @@ next_track: | |||
263 | endofstream = 0; | 257 | endofstream = 0; |
264 | 258 | ||
265 | while (!endofstream) { | 259 | while (!endofstream) { |
266 | ci->yield(); | 260 | enum codec_command_action action = ci->get_command(¶m); |
267 | if (ci->stop_codec || ci->new_track) { | 261 | |
262 | if (action == CODEC_ACTION_HALT) | ||
268 | break; | 263 | break; |
269 | } | ||
270 | 264 | ||
271 | if (ci->seek_time) { | 265 | if (action == CODEC_ACTION_SEEK_TIME) { |
272 | /* 3rd args(read_buffer) is unnecessary in the format which Sun Audio supports. */ | 266 | /* 3rd args(read_buffer) is unnecessary in the format which Sun Audio supports. */ |
273 | struct pcm_pos *newpos = codec->get_seek_pos(ci->seek_time, PCM_SEEK_TIME, NULL); | 267 | struct pcm_pos *newpos = codec->get_seek_pos(param, PCM_SEEK_TIME, NULL); |
274 | 268 | ||
275 | if (newpos->pos > format.numbytes) | 269 | if (newpos->pos > format.numbytes) |
270 | { | ||
271 | ci->set_elapsed(ci->id3->length); | ||
272 | ci->seek_complete(); | ||
276 | break; | 273 | break; |
274 | } | ||
275 | |||
277 | if (ci->seek_buffer(firstblockposn + newpos->pos)) | 276 | if (ci->seek_buffer(firstblockposn + newpos->pos)) |
278 | { | 277 | { |
279 | bytesdone = newpos->pos; | 278 | bytesdone = newpos->pos; |
280 | decodedsamples = newpos->samples; | 279 | decodedsamples = newpos->samples; |
281 | } | 280 | } |
281 | |||
282 | ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); | ||
282 | ci->seek_complete(); | 283 | ci->seek_complete(); |
283 | } | 284 | } |
284 | 285 | ||
@@ -290,11 +291,10 @@ next_track: | |||
290 | endofstream = 1; | 291 | endofstream = 1; |
291 | } | 292 | } |
292 | 293 | ||
293 | status = codec->decode(aubuf, n, samples, &bufcount); | 294 | if (codec->decode(aubuf, n, samples, &bufcount) == CODEC_ERROR) |
294 | if (status == CODEC_ERROR) | ||
295 | { | 295 | { |
296 | DEBUGF("codec error\n"); | 296 | DEBUGF("codec error\n"); |
297 | goto done; | 297 | return CODEC_ERROR; |
298 | } | 298 | } |
299 | 299 | ||
300 | ci->pcmbuf_insert(samples, NULL, bufcount); | 300 | ci->pcmbuf_insert(samples, NULL, bufcount); |
@@ -308,9 +308,5 @@ next_track: | |||
308 | } | 308 | } |
309 | 309 | ||
310 | done: | 310 | done: |
311 | if (ci->request_next_track()) | 311 | return CODEC_OK; |
312 | goto next_track; | ||
313 | |||
314 | exit: | ||
315 | return status; | ||
316 | } | 312 | } |