summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/raac.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-07-14 07:59:39 -0400
committerMichael Sevakis <jethead71@rockbox.org>2014-03-10 04:12:30 +0100
commit31b712286721dd606940c7b557d03e3f714b9604 (patch)
tree8c4a4cc32e9000ea721ebb23aa3c0129ca97bf53 /lib/rbcodec/codecs/raac.c
parentdda54b85daa83b7803b4fb189ab45859f96ff3f9 (diff)
downloadrockbox-31b712286721dd606940c7b557d03e3f714b9604.tar.gz
rockbox-31b712286721dd606940c7b557d03e3f714b9604.zip
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 <jethead71@rockbox.org> Tested: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/raac.c')
-rw-r--r--lib/rbcodec/codecs/raac.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/rbcodec/codecs/raac.c b/lib/rbcodec/codecs/raac.c
index 523560b63e..d2d3531028 100644
--- a/lib/rbcodec/codecs/raac.c
+++ b/lib/rbcodec/codecs/raac.c
@@ -63,14 +63,16 @@ enum codec_status codec_run(void)
63 unsigned char c = 0; /* channels */ 63 unsigned char c = 0; /* channels */
64 int playback_on = -1; 64 int playback_on = -1;
65 size_t resume_offset; 65 size_t resume_offset;
66 enum codec_command_action action;
66 intptr_t param; 67 intptr_t param;
67 enum codec_command_action action = CODEC_ACTION_NULL;
68 68
69 if (codec_init()) { 69 if (codec_init()) {
70 DEBUGF("FAAD: Codec init error\n"); 70 DEBUGF("FAAD: Codec init error\n");
71 return CODEC_ERROR; 71 return CODEC_ERROR;
72 } 72 }
73 73
74 action = CODEC_ACTION_NULL;
75 param = ci->id3->elapsed;
74 resume_offset = ci->id3->offset; 76 resume_offset = ci->id3->offset;
75 77
76 ci->memset(&rmctx,0,sizeof(RMContext)); 78 ci->memset(&rmctx,0,sizeof(RMContext));
@@ -104,15 +106,21 @@ enum codec_status codec_run(void)
104 } 106 }
105 107
106 /* check for a mid-track resume and force a seek time accordingly */ 108 /* check for a mid-track resume and force a seek time accordingly */
107 if(resume_offset > rmctx.data_offset + DATA_HEADER_SIZE) { 109 if (resume_offset) {
108 resume_offset -= rmctx.data_offset + DATA_HEADER_SIZE; 110 resume_offset -= MIN(resume_offset, rmctx.data_offset + DATA_HEADER_SIZE);
109 /* put number of subpackets to skip in resume_offset */ 111 /* put number of subpackets to skip in resume_offset */
110 resume_offset /= (rmctx.block_align + PACKET_HEADER_SIZE); 112 resume_offset /= (rmctx.block_align + PACKET_HEADER_SIZE);
111 param = (int)resume_offset * ((rmctx.block_align * 8 * 1000)/rmctx.bit_rate); 113 param = (int)resume_offset * ((rmctx.block_align * 8 * 1000)/rmctx.bit_rate);
114 }
115
116 if (param > 0) {
112 action = CODEC_ACTION_SEEK_TIME; 117 action = CODEC_ACTION_SEEK_TIME;
113 } 118 }
114 ci->set_elapsed(0); 119 else {
115 ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE); 120 /* Seek to the first packet */
121 ci->set_elapsed(0);
122 ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE);
123 }
116 124
117 /* The main decoding loop */ 125 /* The main decoding loop */
118 while (1) { 126 while (1) {
@@ -124,7 +132,7 @@ enum codec_status codec_run(void)
124 132
125 if (action == CODEC_ACTION_SEEK_TIME) { 133 if (action == CODEC_ACTION_SEEK_TIME) {
126 /* Do not allow seeking beyond the file's length */ 134 /* Do not allow seeking beyond the file's length */
127 if ((unsigned) param > ci->id3->length) { 135 if ((unsigned long)param > ci->id3->length) {
128 ci->set_elapsed(ci->id3->length); 136 ci->set_elapsed(ci->id3->length);
129 ci->seek_complete(); 137 ci->seek_complete();
130 break; 138 break;
@@ -164,6 +172,7 @@ enum codec_status codec_run(void)
164 172
165 ci->advance_buffer(pkt.length); 173 ci->advance_buffer(pkt.length);
166 } 174 }
175
167 ci->seek_buffer(pkt_offset + rmctx.data_offset + DATA_HEADER_SIZE); 176 ci->seek_buffer(pkt_offset + rmctx.data_offset + DATA_HEADER_SIZE);
168 buffer = ci->request_buffer(&n,rmctx.audio_framesize + 1000); 177 buffer = ci->request_buffer(&n,rmctx.audio_framesize + 1000);
169 NeAACDecPostSeekReset(decoder, decoder->frame); 178 NeAACDecPostSeekReset(decoder, decoder->frame);