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/wma.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/rbcodec/codecs/wma.c') diff --git a/lib/rbcodec/codecs/wma.c b/lib/rbcodec/codecs/wma.c index 9039f81429..9a5e0c71fa 100755 --- a/lib/rbcodec/codecs/wma.c +++ b/lib/rbcodec/codecs/wma.c @@ -52,13 +52,16 @@ enum codec_status codec_run(void) int audiobufsize; int packetlength = 0; int errcount = 0; + enum codec_command_action action; intptr_t param; /* Remember the resume position - when the codec is opened, the playback engine will reset it. */ + elapsedtime = ci->id3->elapsed; resume_offset = ci->id3->offset; restart_track: + action = CODEC_ACTION_NULL; /* Proper reset of the decoder context. */ memset(&wmadec, 0, sizeof(wmadec)); @@ -78,13 +81,20 @@ restart_track: return CODEC_ERROR; } - if (resume_offset > ci->id3->first_frame_offset) + if (resume_offset > ci->id3->first_frame_offset || elapsedtime) { - /* Get start of current packet */ - int packet_offset = (resume_offset - ci->id3->first_frame_offset) - % wfx.packet_size; - ci->seek_buffer(resume_offset - packet_offset); - elapsedtime = asf_get_timestamp(&i); + if (resume_offset) { + /* Get start of current packet */ + int packet_offset = (resume_offset - + MIN(resume_offset, ci->id3->first_frame_offset)) + % wfx.packet_size; + ci->seek_buffer(resume_offset - packet_offset); + elapsedtime = asf_get_timestamp(&i); + } + else { + param = elapsedtime; + action = CODEC_ACTION_SEEK_TIME; + } } else { @@ -104,7 +114,8 @@ restart_track: /* The main decoding loop */ while (res >= 0) { - enum codec_command_action action = ci->get_command(¶m); + if (action == CODEC_ACTION_NULL) + action = ci->get_command(¶m); if (action != CODEC_ACTION_NULL) { @@ -126,6 +137,7 @@ restart_track: if (param == 0) { ci->set_elapsed(0); ci->seek_complete(); + elapsedtime = 0; goto restart_track; /* Pretend you never saw this... */ } @@ -140,6 +152,8 @@ restart_track: ci->set_elapsed(elapsedtime); ci->seek_complete(); } + + action = CODEC_ACTION_NULL; } errcount = 0; -- cgit v1.2.3