diff options
Diffstat (limited to 'apps/codecs/smaf.c')
-rw-r--r-- | apps/codecs/smaf.c | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/apps/codecs/smaf.c b/apps/codecs/smaf.c index 3e8a41387d..9211daa9aa 100644 --- a/apps/codecs/smaf.c +++ b/apps/codecs/smaf.c | |||
@@ -332,9 +332,20 @@ static uint8_t *read_buffer(size_t *realsize) | |||
332 | return buffer; | 332 | return buffer; |
333 | } | 333 | } |
334 | 334 | ||
335 | enum codec_status codec_main(void) | 335 | /* this is the codec entry point */ |
336 | enum codec_status codec_main(enum codec_entry_call_reason reason) | ||
337 | { | ||
338 | if (reason == CODEC_LOAD) { | ||
339 | /* Generic codec initialisation */ | ||
340 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); | ||
341 | } | ||
342 | |||
343 | return CODEC_OK; | ||
344 | } | ||
345 | |||
346 | /* this is called for each file to process */ | ||
347 | enum codec_status codec_run(void) | ||
336 | { | 348 | { |
337 | int status; | ||
338 | uint32_t decodedsamples; | 349 | uint32_t decodedsamples; |
339 | size_t n; | 350 | size_t n; |
340 | int bufcount; | 351 | int bufcount; |
@@ -342,20 +353,10 @@ enum codec_status codec_main(void) | |||
342 | uint8_t *smafbuf; | 353 | uint8_t *smafbuf; |
343 | off_t firstblockposn; /* position of the first block in file */ | 354 | off_t firstblockposn; /* position of the first block in file */ |
344 | const struct pcm_codec *codec; | 355 | const struct pcm_codec *codec; |
345 | 356 | intptr_t param; | |
346 | /* Generic codec initialisation */ | ||
347 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); | ||
348 | 357 | ||
349 | next_track: | 358 | if (codec_init()) |
350 | status = CODEC_OK; | 359 | return CODEC_ERROR; |
351 | |||
352 | if (codec_init()) { | ||
353 | status = CODEC_ERROR; | ||
354 | goto exit; | ||
355 | } | ||
356 | |||
357 | if (codec_wait_taginfo() != 0) | ||
358 | goto done; | ||
359 | 360 | ||
360 | codec_set_replaygain(ci->id3); | 361 | codec_set_replaygain(ci->id3); |
361 | 362 | ||
@@ -365,24 +366,22 @@ next_track: | |||
365 | decodedsamples = 0; | 366 | decodedsamples = 0; |
366 | codec = 0; | 367 | codec = 0; |
367 | 368 | ||
369 | ci->seek_buffer(0); | ||
368 | if (!parse_header(&format, &firstblockposn)) | 370 | if (!parse_header(&format, &firstblockposn)) |
369 | { | 371 | { |
370 | status = CODEC_ERROR; | 372 | return CODEC_ERROR; |
371 | goto done; | ||
372 | } | 373 | } |
373 | 374 | ||
374 | codec = get_codec(format.formattag); | 375 | codec = get_codec(format.formattag); |
375 | if (codec == 0) | 376 | if (codec == 0) |
376 | { | 377 | { |
377 | DEBUGF("CODEC_ERROR: unsupport audio format: 0x%x\n", (int)format.formattag); | 378 | DEBUGF("CODEC_ERROR: unsupport audio format: 0x%x\n", (int)format.formattag); |
378 | status = CODEC_ERROR; | 379 | return CODEC_ERROR; |
379 | goto done; | ||
380 | } | 380 | } |
381 | 381 | ||
382 | if (!codec->set_format(&format)) | 382 | if (!codec->set_format(&format)) |
383 | { | 383 | { |
384 | status = CODEC_ERROR; | 384 | return CODEC_ERROR; |
385 | goto done; | ||
386 | } | 385 | } |
387 | 386 | ||
388 | /* check chunksize */ | 387 | /* check chunksize */ |
@@ -392,8 +391,7 @@ next_track: | |||
392 | if (format.chunksize == 0) | 391 | if (format.chunksize == 0) |
393 | { | 392 | { |
394 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); | 393 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); |
395 | status = CODEC_ERROR; | 394 | return CODEC_ERROR; |
396 | goto done; | ||
397 | } | 395 | } |
398 | 396 | ||
399 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); | 397 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); |
@@ -404,12 +402,10 @@ next_track: | |||
404 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | 402 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); |
405 | } else { | 403 | } else { |
406 | DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); | 404 | DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); |
407 | status = CODEC_ERROR; | 405 | return CODEC_ERROR; |
408 | goto done; | ||
409 | } | 406 | } |
410 | 407 | ||
411 | ci->seek_buffer(firstblockposn); | 408 | ci->seek_buffer(firstblockposn); |
412 | ci->seek_complete(); | ||
413 | 409 | ||
414 | /* make sure we're at the correct offset */ | 410 | /* make sure we're at the correct offset */ |
415 | if (bytesdone > (uint32_t) firstblockposn) | 411 | if (bytesdone > (uint32_t) firstblockposn) |
@@ -419,13 +415,13 @@ next_track: | |||
419 | PCM_SEEK_POS, &read_buffer); | 415 | PCM_SEEK_POS, &read_buffer); |
420 | 416 | ||
421 | if (newpos->pos > format.numbytes) | 417 | if (newpos->pos > format.numbytes) |
422 | goto done; | 418 | return CODEC_OK; |
419 | |||
423 | if (ci->seek_buffer(firstblockposn + newpos->pos)) | 420 | if (ci->seek_buffer(firstblockposn + newpos->pos)) |
424 | { | 421 | { |
425 | bytesdone = newpos->pos; | 422 | bytesdone = newpos->pos; |
426 | decodedsamples = newpos->samples; | 423 | decodedsamples = newpos->samples; |
427 | } | 424 | } |
428 | ci->seek_complete(); | ||
429 | } | 425 | } |
430 | else | 426 | else |
431 | { | 427 | { |
@@ -437,23 +433,32 @@ next_track: | |||
437 | endofstream = 0; | 433 | endofstream = 0; |
438 | 434 | ||
439 | while (!endofstream) { | 435 | while (!endofstream) { |
440 | ci->yield(); | 436 | enum codec_command_action action = ci->get_command(¶m); |
441 | if (ci->stop_codec || ci->new_track) | 437 | |
438 | if (action == CODEC_ACTION_HALT) | ||
442 | break; | 439 | break; |
443 | 440 | ||
444 | if (ci->seek_time) { | 441 | if (action == CODEC_ACTION_SEEK_TIME) { |
445 | struct pcm_pos *newpos = codec->get_seek_pos(ci->seek_time, PCM_SEEK_TIME, | 442 | struct pcm_pos *newpos = codec->get_seek_pos(param, PCM_SEEK_TIME, |
446 | &read_buffer); | 443 | &read_buffer); |
447 | 444 | ||
448 | if (newpos->pos > format.numbytes) | 445 | if (newpos->pos > format.numbytes) |
446 | { | ||
447 | ci->set_elapsed(ci->id3->length); | ||
448 | ci->seek_complete(); | ||
449 | break; | 449 | break; |
450 | } | ||
451 | |||
450 | if (ci->seek_buffer(firstblockposn + newpos->pos)) | 452 | if (ci->seek_buffer(firstblockposn + newpos->pos)) |
451 | { | 453 | { |
452 | bytesdone = newpos->pos; | 454 | bytesdone = newpos->pos; |
453 | decodedsamples = newpos->samples; | 455 | decodedsamples = newpos->samples; |
454 | } | 456 | } |
457 | |||
458 | ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); | ||
455 | ci->seek_complete(); | 459 | ci->seek_complete(); |
456 | } | 460 | } |
461 | |||
457 | smafbuf = (uint8_t *)ci->request_buffer(&n, format.chunksize); | 462 | smafbuf = (uint8_t *)ci->request_buffer(&n, format.chunksize); |
458 | 463 | ||
459 | if (n == 0) | 464 | if (n == 0) |
@@ -464,11 +469,10 @@ next_track: | |||
464 | endofstream = 1; | 469 | endofstream = 1; |
465 | } | 470 | } |
466 | 471 | ||
467 | status = codec->decode(smafbuf, n, samples, &bufcount); | 472 | if (codec->decode(smafbuf, n, samples, &bufcount) == CODEC_ERROR) |
468 | if (status == CODEC_ERROR) | ||
469 | { | 473 | { |
470 | DEBUGF("codec error\n"); | 474 | DEBUGF("codec error\n"); |
471 | goto done; | 475 | return CODEC_ERROR; |
472 | } | 476 | } |
473 | 477 | ||
474 | ci->pcmbuf_insert(samples, NULL, bufcount); | 478 | ci->pcmbuf_insert(samples, NULL, bufcount); |
@@ -482,11 +486,5 @@ next_track: | |||
482 | ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); | 486 | ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); |
483 | } | 487 | } |
484 | 488 | ||
485 | done: | 489 | return CODEC_OK; |
486 | if (ci->request_next_track()) | ||
487 | goto next_track; | ||
488 | |||
489 | exit: | ||
490 | return status; | ||
491 | } | 490 | } |
492 | |||