From 31b712286721dd606940c7b557d03e3f714b9604 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 14 Jul 2013 07:59:39 -0400 Subject: Implement time-based resume and playback start. This complements offset-based resume and playback start funcionality. The implementation is global on both HWCODEC and SWCODEC. Basically, if either the specified elapsed or offset are non-zero, it indicates a mid-track resume. To resume by time only, set elapsed to nonzero and offset to zero. To resume by offset only, set offset to nonzero and elapsed to zero. Which one the codec uses and which has priority is up to the codec; however, using an elapsed time covers more cases: * Codecs not able to use an offset such as VGM or other atomic formats * Starting playback at a nonzero elapsed time from a source that contains no offset, such as a cuesheet The change re-versions pretty much everything from tagcache to nvram. Change-Id: Ic7aebb24e99a03ae99585c5e236eba960d163f38 Reviewed-on: http://gerrit.rockbox.org/516 Reviewed-by: Michael Sevakis Tested: Michael Sevakis --- lib/rbcodec/codecs/opus.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'lib/rbcodec/codecs/opus.c') diff --git a/lib/rbcodec/codecs/opus.c b/lib/rbcodec/codecs/opus.c index 15d96ff6fe..2c495aa8d0 100644 --- a/lib/rbcodec/codecs/opus.c +++ b/lib/rbcodec/codecs/opus.c @@ -314,6 +314,7 @@ enum codec_status codec_main(enum codec_entry_call_reason reason) enum codec_status codec_run(void) { int error = CODEC_ERROR; + enum codec_command_action action; intptr_t param; ogg_sync_state oy; ogg_page og; @@ -325,13 +326,17 @@ enum codec_status codec_run(void) OpusDecoder *st = NULL; OpusHeader header; int ret; - unsigned long strtoffset = ci->id3->offset; + unsigned long strtoffset; int skip = 0; int64_t seek_target; uint64_t granule_pos; ogg_malloc_init(); + action = CODEC_ACTION_NULL; + param = ci->id3->elapsed; + strtoffset = ci->id3->offset; + global_stack = 0; #if defined(CPU_COLDFIRE) @@ -351,28 +356,40 @@ enum codec_status codec_run(void) ci->seek_buffer(0); ci->set_elapsed(0); + if (!strtoffset && param) { + action = CODEC_ACTION_SEEK_TIME; + } + + goto next_page; + while (1) { - enum codec_command_action action = ci->get_command(¶m); + if (action == CODEC_ACTION_NULL) + action = ci->get_command(¶m); - if (action == CODEC_ACTION_HALT) - break; + if (action != CODEC_ACTION_NULL) { + if (action == CODEC_ACTION_HALT) + break; + + if (action == CODEC_ACTION_SEEK_TIME) { + if (st != NULL) { + /* calculate granule to seek to (including seek rewind) */ + seek_target = (48LL * param) + header.preskip; + skip = MIN(seek_target, SEEK_REWIND); + seek_target -= skip; - if (action == CODEC_ACTION_SEEK_TIME) { - if (st != NULL) { - /* calculate granule to seek to (including seek rewind) */ - seek_target = (48LL * param) + header.preskip; - skip = MIN(seek_target, SEEK_REWIND); - seek_target -= skip; + LOGF("Opus seek page:%lld,%lld,%ld\n", + seek_target, page_granule, (long)param); + speex_seek_page_granule(seek_target, page_granule, &oy, &os); + } - LOGF("Opus seek page:%lld,%lld,%ld\n", - seek_target, page_granule, (long)param); - speex_seek_page_granule(seek_target, page_granule, &oy, &os); + ci->set_elapsed(param); + ci->seek_complete(); } - ci->set_elapsed(param); - ci->seek_complete(); + action = CODEC_ACTION_NULL; } + next_page: /*Get the ogg buffer for writing*/ if (get_more_data(&oy) < 1) { goto done; -- cgit v1.2.3