diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2011-04-27 03:08:23 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2011-04-27 03:08:23 +0000 |
commit | c537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch) | |
tree | 7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/speex.c | |
parent | dcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff) | |
download | rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip |
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/speex.c')
-rw-r--r-- | apps/codecs/speex.c | 61 |
1 files changed, 23 insertions, 38 deletions
diff --git a/apps/codecs/speex.c b/apps/codecs/speex.c index 7a1efa9753..e394efc3d5 100644 --- a/apps/codecs/speex.c +++ b/apps/codecs/speex.c | |||
@@ -367,11 +367,12 @@ static void *process_header(spx_ogg_packet *op, | |||
367 | return st; | 367 | return st; |
368 | } | 368 | } |
369 | 369 | ||
370 | /* this is the codec entry point */ | 370 | /* this is called for each file to process */ |
371 | enum codec_status codec_main(void) | 371 | enum codec_status codec_run(void) |
372 | { | 372 | { |
373 | int error = CODEC_ERROR; | ||
374 | |||
373 | SpeexBits bits; | 375 | SpeexBits bits; |
374 | int error; | ||
375 | int eof = 0; | 376 | int eof = 0; |
376 | spx_ogg_sync_state oy; | 377 | spx_ogg_sync_state oy; |
377 | spx_ogg_page og; | 378 | spx_ogg_page og; |
@@ -383,7 +384,7 @@ enum codec_status codec_main(void) | |||
383 | int eos = 0; | 384 | int eos = 0; |
384 | SpeexStereoState *stereo; | 385 | SpeexStereoState *stereo; |
385 | int channels = -1; | 386 | int channels = -1; |
386 | int rate = 0, samplerate = 0; | 387 | int samplerate = 0; |
387 | int extra_headers = 0; | 388 | int extra_headers = 0; |
388 | int stream_init = 0; | 389 | int stream_init = 0; |
389 | int page_nb_packets, frame_size, packet_count = 0; | 390 | int page_nb_packets, frame_size, packet_count = 0; |
@@ -392,26 +393,22 @@ enum codec_status codec_main(void) | |||
392 | unsigned long strtoffset = 0; | 393 | unsigned long strtoffset = 0; |
393 | void *st = NULL; | 394 | void *st = NULL; |
394 | int j = 0; | 395 | int j = 0; |
396 | intptr_t param; | ||
395 | 397 | ||
396 | memset(&bits, 0, sizeof(bits)); | 398 | memset(&bits, 0, sizeof(bits)); |
397 | memset(&oy, 0, sizeof(oy)); | 399 | memset(&oy, 0, sizeof(oy)); |
398 | 400 | ||
399 | /* Ogg handling still uses mallocs, so reset the malloc buffer per track */ | 401 | /* Ogg handling still uses mallocs, so reset the malloc buffer per track */ |
400 | next_track: | ||
401 | error = CODEC_OK; | ||
402 | |||
403 | if (codec_init()) { | 402 | if (codec_init()) { |
404 | error = CODEC_ERROR; | ||
405 | goto exit; | 403 | goto exit; |
406 | } | 404 | } |
407 | 405 | ||
406 | ci->seek_buffer(0); | ||
407 | |||
408 | stereo = speex_stereo_state_init(); | 408 | stereo = speex_stereo_state_init(); |
409 | spx_ogg_sync_init(&oy); | 409 | spx_ogg_sync_init(&oy); |
410 | spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); | 410 | spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); |
411 | 411 | ||
412 | if (codec_wait_taginfo() != 0) | ||
413 | goto done; | ||
414 | |||
415 | strtoffset = ci->id3->offset; | 412 | strtoffset = ci->id3->offset; |
416 | 413 | ||
417 | samplerate = ci->id3->frequency; | 414 | samplerate = ci->id3->frequency; |
@@ -419,30 +416,32 @@ next_track: | |||
419 | 416 | ||
420 | eof = 0; | 417 | eof = 0; |
421 | while (!eof) { | 418 | while (!eof) { |
422 | ci->yield(); | 419 | enum codec_command_action action = ci->get_command(¶m); |
423 | if (ci->stop_codec || ci->new_track) | 420 | |
421 | if (action == CODEC_ACTION_HALT) | ||
424 | break; | 422 | break; |
425 | 423 | ||
426 | /*seek (seeks to the page before the position) */ | 424 | /*seek (seeks to the page before the position) */ |
427 | if (ci->seek_time) { | 425 | if (action == CODEC_ACTION_SEEK_TIME) { |
428 | if(samplerate!=0&&packet_count>1){ | 426 | if(samplerate!=0&&packet_count>1){ |
429 | LOGF("Speex seek page:%lld,%lld,%ld,%lld,%d\n", | 427 | LOGF("Speex seek page:%lld,%lld,%ld,%lld,%d\n", |
430 | ((spx_int64_t)ci->seek_time/1000) * | 428 | ((spx_int64_t)param/1000) * |
431 | (spx_int64_t)samplerate, | 429 | (spx_int64_t)samplerate, |
432 | page_granule, ci->seek_time, | 430 | page_granule, param, |
433 | (page_granule/samplerate)*1000, samplerate); | 431 | (page_granule/samplerate)*1000, samplerate); |
434 | 432 | ||
435 | speex_seek_page_granule(((spx_int64_t)ci->seek_time/1000) * | 433 | speex_seek_page_granule(((spx_int64_t)param/1000) * |
436 | (spx_int64_t)samplerate, | 434 | (spx_int64_t)samplerate, |
437 | page_granule, &oy, headerssize); | 435 | page_granule, &oy, headerssize); |
438 | ci->seek_complete(); | ||
439 | } | 436 | } |
437 | |||
438 | ci->set_elapsed(param); | ||
439 | ci->seek_complete(); | ||
440 | } | 440 | } |
441 | 441 | ||
442 | next_page: | 442 | next_page: |
443 | /*Get the ogg buffer for writing*/ | 443 | /*Get the ogg buffer for writing*/ |
444 | if(get_more_data(&oy)<1){/*read error*/ | 444 | if(get_more_data(&oy)<1){/*read error*/ |
445 | error=CODEC_ERROR; | ||
446 | goto done; | 445 | goto done; |
447 | } | 446 | } |
448 | 447 | ||
@@ -477,8 +476,7 @@ next_page: | |||
477 | nframes=1; | 476 | nframes=1; |
478 | 477 | ||
479 | if (!st){ | 478 | if (!st){ |
480 | error=CODEC_ERROR; | 479 | goto done; |
481 | goto exit; | ||
482 | } | 480 | } |
483 | 481 | ||
484 | ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); | 482 | ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); |
@@ -557,31 +555,18 @@ next_page: | |||
557 | } | 555 | } |
558 | 556 | ||
559 | done: | 557 | done: |
560 | if (ci->request_next_track()) { | 558 | /* Clean things up for the next track */ |
561 | 559 | speex_bits_destroy(&bits); | |
562 | /* Clean things up for the next track */ | ||
563 | 560 | ||
561 | if (st) | ||
564 | if (st) | 562 | if (st) |
565 | speex_decoder_destroy(st); | 563 | speex_decoder_destroy(st); |
566 | 564 | ||
567 | if (stream_init == 1) | ||
568 | spx_ogg_stream_reset(&os); | ||
569 | |||
570 | spx_ogg_sync_reset(&oy); | ||
571 | |||
572 | cur_granule = stream_init = rate = samplerate = headerssize | ||
573 | = packet_count = eos = 0; | ||
574 | |||
575 | goto next_track; | ||
576 | } | ||
577 | |||
578 | exit: | ||
579 | speex_bits_destroy(&bits); | ||
580 | |||
581 | if (stream_init) | 565 | if (stream_init) |
582 | spx_ogg_stream_destroy(&os); | 566 | spx_ogg_stream_destroy(&os); |
583 | 567 | ||
584 | spx_ogg_sync_destroy(&oy); | 568 | spx_ogg_sync_destroy(&oy); |
585 | 569 | ||
570 | exit: | ||
586 | return error; | 571 | return error; |
587 | } | 572 | } |