···400400 }
401401 else
402402 {
403403- DEBUGF("stsz too large, ignoring it\n");
403403+ qtmovie->res->sample_byte_sizes_offset = stream_tell(qtmovie->stream);
404404+ DEBUGF("stsz too large: %u, save sample_byte_sizes_offset\n", numsizes);
404405 }
405406406407 if (size_remaining)
···479480 {
480481 DEBUGF("stco too large to allocate lookup_table[]\n");
481482 return false;
483483+ }
484484+485485+ // Reading sample_byte_sizes data on seek can lead to additional re-buffering.
486486+ // So skip it if we have good enough seek accuracy via lookup_table (3000 ms)
487487+ if (qtmovie->res->sample_byte_sizes_offset && ci->id3->length / fit_numentries <= 3000)
488488+ {
489489+ qtmovie->res->sample_byte_sizes_offset = 0;
490490+ DEBUGF("lookup_table seek accuracy %ld ms, ignoring sample_byte_sizes_offset \n", ci->id3->length / fit_numentries);
482491 }
483492484493 /* Build up lookup table. The lookup table contains the sample index and
+14-5
lib/rbcodec/codecs/libm4a/m4a.c
···211211 sound_sample_i += time_cnt * time_dur;
212212 }
213213214214- DEBUGF("seek chunk=%lu, sample=%lu, soundsample=%lu, offset=%lu\n",
215215- (unsigned long)chunk, (unsigned long)chunk_first_sample,
216216- sound_sample_i, (unsigned long)offset);
214214+ if (demux_res->sample_byte_sizes_offset)
215215+ {
216216+ stream->ci->seek_buffer(demux_res->sample_byte_sizes_offset + chunk_first_sample * 4);
217217+ }
217218218218- if (tsz_tab) {
219219+ if (tsz_tab || demux_res->sample_byte_sizes_offset)
220220+ {
219221 /* We have a sample-to-bytes table available so we can do accurate
220222 * seeking. Move one sample at a time and update the file offset and
221223 * PCM sample offset as we go. */
···229231 time_dur = tts_tab[time].sample_duration;
230232 }
231233232232- offset += tsz_tab[i];
234234+ offset += tsz_tab ? tsz_tab[i] : stream_read_uint32(stream);
233235 sound_sample_i += time_dur;
234236 time_cnt--;
235237 }
···238240 * start of a chunk, which is often much lower resolution. */
239241 sample_i = chunk_first_sample;
240242 }
243243+244244+ DEBUGF("seek chunk=%lu, chunk_first_sample=%lu, sample_i=%u, soundsample=%lu, offset=%lu\n",
245245+ (unsigned long)chunk,
246246+ (unsigned long)chunk_first_sample,
247247+ sample_i,
248248+ (unsigned long)sound_sample_i,
249249+ (unsigned long)offset);
241250242251 if (stream->ci->seek_buffer(offset))
243252 {