summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libm4a/m4a.c
diff options
context:
space:
mode:
authorroman.artiukhin <bahusdrive@gmail.com>2023-09-05 00:45:32 +0300
committerroman.artiukhin <bahusdrive@gmail.com>2023-09-20 11:43:39 +0300
commit57409f52d5da3665a91c6cf2cbcef86ea1004ccf (patch)
tree7de9c0af2c15a7a6b5d6b36493e545b658d8a5cc /lib/rbcodec/codecs/libm4a/m4a.c
parente01055a287500d8cc90cda3b4816d3dc2f07bde4 (diff)
downloadrockbox-57409f52d5da3665a91c6cf2cbcef86ea1004ccf.tar.gz
rockbox-57409f52d5da3665a91c6cf2cbcef86ea1004ccf.zip
Codecs: mp4: Accurate seek in large files with small lookup_table
Read sample_byte_sizes table on demand when it can't be cached Change-Id: I2191be63ceebfd8b16e1e973e13c5b51986b6564
Diffstat (limited to 'lib/rbcodec/codecs/libm4a/m4a.c')
-rw-r--r--lib/rbcodec/codecs/libm4a/m4a.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/rbcodec/codecs/libm4a/m4a.c b/lib/rbcodec/codecs/libm4a/m4a.c
index 295c39c5ff..b63b8bad2c 100644
--- a/lib/rbcodec/codecs/libm4a/m4a.c
+++ b/lib/rbcodec/codecs/libm4a/m4a.c
@@ -211,11 +211,13 @@ unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
211 sound_sample_i += time_cnt * time_dur; 211 sound_sample_i += time_cnt * time_dur;
212 } 212 }
213 213
214 DEBUGF("seek chunk=%lu, sample=%lu, soundsample=%lu, offset=%lu\n", 214 if (demux_res->sample_byte_sizes_offset)
215 (unsigned long)chunk, (unsigned long)chunk_first_sample, 215 {
216 sound_sample_i, (unsigned long)offset); 216 stream->ci->seek_buffer(demux_res->sample_byte_sizes_offset + chunk_first_sample * 4);
217 }
217 218
218 if (tsz_tab) { 219 if (tsz_tab || demux_res->sample_byte_sizes_offset)
220 {
219 /* We have a sample-to-bytes table available so we can do accurate 221 /* We have a sample-to-bytes table available so we can do accurate
220 * seeking. Move one sample at a time and update the file offset and 222 * seeking. Move one sample at a time and update the file offset and
221 * PCM sample offset as we go. */ 223 * PCM sample offset as we go. */
@@ -229,7 +231,7 @@ unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
229 time_dur = tts_tab[time].sample_duration; 231 time_dur = tts_tab[time].sample_duration;
230 } 232 }
231 233
232 offset += tsz_tab[i]; 234 offset += tsz_tab ? tsz_tab[i] : stream_read_uint32(stream);
233 sound_sample_i += time_dur; 235 sound_sample_i += time_dur;
234 time_cnt--; 236 time_cnt--;
235 } 237 }
@@ -239,6 +241,13 @@ unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
239 sample_i = chunk_first_sample; 241 sample_i = chunk_first_sample;
240 } 242 }
241 243
244 DEBUGF("seek chunk=%lu, chunk_first_sample=%lu, sample_i=%u, soundsample=%lu, offset=%lu\n",
245 (unsigned long)chunk,
246 (unsigned long)chunk_first_sample,
247 sample_i,
248 (unsigned long)sound_sample_i,
249 (unsigned long)offset);
250
242 if (stream->ci->seek_buffer(offset)) 251 if (stream->ci->seek_buffer(offset))
243 { 252 {
244 *sound_samples_done = sound_sample_i; 253 *sound_samples_done = sound_sample_i;