diff options
Diffstat (limited to 'apps/codecs/flac.c')
-rw-r--r-- | apps/codecs/flac.c | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index 89d14b98a7..a5521b584f 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c | |||
@@ -418,40 +418,40 @@ static bool flac_seek_offset(FLACContext* fc, uint32_t offset) { | |||
418 | } | 418 | } |
419 | 419 | ||
420 | /* this is the codec entry point */ | 420 | /* this is the codec entry point */ |
421 | enum codec_status codec_main(void) | 421 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
422 | { | ||
423 | if (reason == CODEC_LOAD) { | ||
424 | /* Generic codec initialisation */ | ||
425 | ci->configure(DSP_SET_SAMPLE_DEPTH, FLAC_OUTPUT_DEPTH-1); | ||
426 | } | ||
427 | |||
428 | return CODEC_OK; | ||
429 | } | ||
430 | |||
431 | /* this is called for each file to process */ | ||
432 | enum codec_status codec_run(void) | ||
422 | { | 433 | { |
423 | int8_t *buf; | 434 | int8_t *buf; |
424 | FLACContext fc; | 435 | FLACContext fc; |
425 | uint32_t samplesdone = 0; | 436 | uint32_t samplesdone; |
426 | uint32_t elapsedtime; | 437 | uint32_t elapsedtime; |
427 | size_t bytesleft; | 438 | size_t bytesleft; |
428 | int consumed; | 439 | int consumed; |
429 | int res; | 440 | int res; |
430 | int frame; | 441 | int frame; |
431 | int retval; | 442 | intptr_t param; |
432 | |||
433 | /* Generic codec initialisation */ | ||
434 | ci->configure(DSP_SET_SAMPLE_DEPTH, FLAC_OUTPUT_DEPTH-1); | ||
435 | 443 | ||
436 | next_track: | ||
437 | retval = CODEC_OK; | ||
438 | |||
439 | if (codec_init()) { | 444 | if (codec_init()) { |
440 | LOGF("FLAC: Error initialising codec\n"); | 445 | LOGF("FLAC: Error initialising codec\n"); |
441 | retval = CODEC_ERROR; | 446 | return CODEC_ERROR; |
442 | goto exit; | ||
443 | } | 447 | } |
444 | 448 | ||
445 | if (codec_wait_taginfo() != 0) | ||
446 | goto done; | ||
447 | |||
448 | /* Need to save offset for later use (cleared indirectly by flac_init) */ | 449 | /* Need to save offset for later use (cleared indirectly by flac_init) */ |
449 | samplesdone = ci->id3->offset; | 450 | samplesdone = ci->id3->offset; |
450 | 451 | ||
451 | if (!flac_init(&fc,ci->id3->first_frame_offset)) { | 452 | if (!flac_init(&fc,ci->id3->first_frame_offset)) { |
452 | LOGF("FLAC: Error initialising codec\n"); | 453 | LOGF("FLAC: Error initialising codec\n"); |
453 | retval = CODEC_ERROR; | 454 | return CODEC_ERROR; |
454 | goto done; | ||
455 | } | 455 | } |
456 | 456 | ||
457 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); | 457 | ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); |
@@ -459,35 +459,34 @@ next_track: | |||
459 | STEREO_MONO : STEREO_NONINTERLEAVED); | 459 | STEREO_MONO : STEREO_NONINTERLEAVED); |
460 | codec_set_replaygain(ci->id3); | 460 | codec_set_replaygain(ci->id3); |
461 | 461 | ||
462 | if (samplesdone) { | 462 | flac_seek_offset(&fc, samplesdone); |
463 | flac_seek_offset(&fc, samplesdone); | 463 | samplesdone=0; |
464 | samplesdone=0; | ||
465 | } | ||
466 | 464 | ||
467 | /* The main decoding loop */ | 465 | /* The main decoding loop */ |
468 | frame=0; | 466 | frame=0; |
469 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); | 467 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); |
470 | while (bytesleft) { | 468 | while (bytesleft) { |
471 | ci->yield(); | 469 | enum codec_command_action action = ci->get_command(¶m); |
472 | if (ci->stop_codec || ci->new_track) { | 470 | |
471 | if (action == CODEC_ACTION_HALT) | ||
473 | break; | 472 | break; |
474 | } | ||
475 | 473 | ||
476 | /* Deal with any pending seek requests */ | 474 | /* Deal with any pending seek requests */ |
477 | if (ci->seek_time) { | 475 | if (action == CODEC_ACTION_SEEK_TIME) { |
478 | if (flac_seek(&fc,(uint32_t)(((uint64_t)(ci->seek_time-1) | 476 | if (flac_seek(&fc,(uint32_t)(((uint64_t)param |
479 | *ci->id3->frequency)/1000))) { | 477 | *ci->id3->frequency)/1000))) { |
480 | /* Refill the input buffer */ | 478 | /* Refill the input buffer */ |
481 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); | 479 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); |
482 | } | 480 | } |
481 | |||
482 | ci->set_elapsed(param); | ||
483 | ci->seek_complete(); | 483 | ci->seek_complete(); |
484 | } | 484 | } |
485 | 485 | ||
486 | if((res=flac_decode_frame(&fc,decoded0,decoded1,buf, | 486 | if((res=flac_decode_frame(&fc,decoded0,decoded1,buf, |
487 | bytesleft,ci->yield)) < 0) { | 487 | bytesleft,ci->yield)) < 0) { |
488 | LOGF("FLAC: Frame %d, error %d\n",frame,res); | 488 | LOGF("FLAC: Frame %d, error %d\n",frame,res); |
489 | retval = CODEC_ERROR; | 489 | return CODEC_ERROR; |
490 | goto done; | ||
491 | } | 490 | } |
492 | consumed=fc.gb.index/8; | 491 | consumed=fc.gb.index/8; |
493 | frame++; | 492 | frame++; |
@@ -507,14 +506,7 @@ next_track: | |||
507 | 506 | ||
508 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); | 507 | buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); |
509 | } | 508 | } |
510 | retval = CODEC_OK; | ||
511 | 509 | ||
512 | done: | ||
513 | LOGF("FLAC: Decoded %lu samples\n",(unsigned long)samplesdone); | 510 | LOGF("FLAC: Decoded %lu samples\n",(unsigned long)samplesdone); |
514 | 511 | return CODEC_OK; | |
515 | if (ci->request_next_track()) | ||
516 | goto next_track; | ||
517 | |||
518 | exit: | ||
519 | return retval; | ||
520 | } | 512 | } |