diff options
author | roman.artiukhin <bahusdrive@gmail.com> | 2023-08-30 22:02:25 +0300 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2023-09-06 16:49:30 -0400 |
commit | 2c6dfd06a68a84c214350ac8be84cabdf501fb33 (patch) | |
tree | b01ebcd8cc8ac9c53a0016cbb9afdeb5752924c0 | |
parent | a190d0ca9c286478d1c36cb30fa6c2515aaa4f9d (diff) | |
download | rockbox-2c6dfd06a6.tar.gz rockbox-2c6dfd06a6.zip |
Codecs: mp4: Improve support for long files
Reduce lookup_table (seek accuracy) till it fits on device
Fixes FS#13049
Change-Id: I934de500a4383e17b82821afa2e0396a27061707
-rw-r--r-- | lib/rbcodec/codecs/libm4a/demux.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/rbcodec/codecs/libm4a/demux.c b/lib/rbcodec/codecs/libm4a/demux.c index 11534da366..ae3c34fde4 100644 --- a/lib/rbcodec/codecs/libm4a/demux.c +++ b/lib/rbcodec/codecs/libm4a/demux.c @@ -468,9 +468,25 @@ static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) numentries = stream_read_uint32(qtmovie->stream); size_remaining -= 4; - - qtmovie->res->num_lookup_table = numentries; - qtmovie->res->lookup_table = malloc(numentries * sizeof(*qtmovie->res->lookup_table)); + + uint8_t accuracy_divider = 1; + uint32_t fit_numentries = numentries; + while (true) + { + qtmovie->res->lookup_table = malloc(fit_numentries * sizeof(*qtmovie->res->lookup_table)); + + if (qtmovie->res->lookup_table) + { + break; + } + else + { + // we failed to alloc memory for lookup table, so reduce seek accuracy and try again + fit_numentries = numentries / ++accuracy_divider; + } + } + DEBUGF("lookup_table numentries %d, fit_numentries %d\n", numentries, fit_numentries); + qtmovie->res->num_lookup_table = fit_numentries; if (!qtmovie->res->lookup_table) { @@ -518,11 +534,14 @@ static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) frame += (new_first - old_first) * old_frame; } frame += (k - old_first) * old_frame; - - qtmovie->res->lookup_table[idx].sample = frame; - qtmovie->res->lookup_table[idx].offset = offset; - idx++; - + + if ((k-1) % accuracy_divider == 0) + { + qtmovie->res->lookup_table[idx].sample = frame; + qtmovie->res->lookup_table[idx].offset = offset; + idx++; + } + frame -= (k - old_first) * old_frame; offset = stream_read_uint32(qtmovie->stream); |