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/ape.c | 70 +++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 25 deletions(-) (limited to 'lib/rbcodec/codecs/ape.c') diff --git a/lib/rbcodec/codecs/ape.c b/lib/rbcodec/codecs/ape.c index 577e7b65e2..a6c5254d45 100644 --- a/lib/rbcodec/codecs/ape.c +++ b/lib/rbcodec/codecs/ape.c @@ -155,6 +155,7 @@ enum codec_status codec_run(void) int res; int firstbyte; size_t resume_offset; + enum codec_command_action action; intptr_t param; if (codec_init()) { @@ -162,8 +163,12 @@ enum codec_status codec_run(void) return CODEC_ERROR; } + action = CODEC_ACTION_NULL; + param = 0; + /* Remember the resume position - when the codec is opened, the playback engine will reset it. */ + elapsedtime = ci->id3->elapsed; resume_offset = ci->id3->offset; ci->seek_buffer(0); @@ -213,14 +218,21 @@ enum codec_status codec_run(void) ape_resume(&ape_ctx, resume_offset, ¤tframe, &samplesdone, &samplestoskip, &firstbyte); - } else { + elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); + } + else { currentframe = 0; samplesdone = 0; samplestoskip = 0; firstbyte = 3; /* Take account of the little-endian 32-bit byte ordering */ + + if (elapsedtime) { + /* Resume by simulated seeking */ + param = elapsedtime; + action = CODEC_ACTION_SEEK_TIME; + } } - elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); ci->set_elapsed(elapsedtime); /* Initialise the buffer */ @@ -247,36 +259,44 @@ frame_start: /* Decode the frame a chunk at a time */ while (nblocks > 0) { - enum codec_command_action action = ci->get_command(¶m); + if (action == CODEC_ACTION_NULL) + action = ci->get_command(¶m); - if (action == CODEC_ACTION_HALT) - goto done; + if (action != CODEC_ACTION_NULL) { + if (action == CODEC_ACTION_HALT) + goto done; - /* Deal with any pending seek requests */ - if (action == CODEC_ACTION_SEEK_TIME) - { - if (ape_calc_seekpos(&ape_ctx, - (param/10) * (ci->id3->frequency/100), - ¤tframe, - &newfilepos, - &samplestoskip)) + /* Deal with any pending seek requests */ + if (action == CODEC_ACTION_SEEK_TIME) { - samplesdone = currentframe * ape_ctx.blocksperframe; - - /* APE's bytestream is weird... */ - firstbyte = 3 - (newfilepos & 3); - newfilepos &= ~3; - - ci->seek_buffer(newfilepos); - inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); + if (ape_calc_seekpos(&ape_ctx, + (param/10) * (ci->id3->frequency/100), + ¤tframe, + &newfilepos, + &samplestoskip)) + { + samplesdone = currentframe * ape_ctx.blocksperframe; + + /* APE's bytestream is weird... */ + firstbyte = 3 - (newfilepos & 3); + newfilepos &= ~3; + + ci->seek_buffer(newfilepos); + inbuffer = ci->request_buffer(&bytesleft, + INPUT_CHUNKSIZE); + + elapsedtime = (samplesdone*10)/ + (ape_ctx.samplerate/100); + ci->set_elapsed(elapsedtime); + ci->seek_complete(); + action = CODEC_ACTION_NULL; + goto frame_start; /* Sorry... */ + } - elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); - ci->set_elapsed(elapsedtime); ci->seek_complete(); - goto frame_start; /* Sorry... */ } - ci->seek_complete(); + action = CODEC_ACTION_NULL; } blockstodecode = MIN(BLOCKS_PER_LOOP, nblocks); -- cgit v1.2.3