summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroman.artiukhin <bahusdrive@gmail.com>2023-08-30 22:02:25 +0300
committerSolomon Peachy <pizza@shaftnet.org>2023-09-06 16:49:30 -0400
commit2c6dfd06a68a84c214350ac8be84cabdf501fb33 (patch)
treeb01ebcd8cc8ac9c53a0016cbb9afdeb5752924c0
parenta190d0ca9c286478d1c36cb30fa6c2515aaa4f9d (diff)
downloadrockbox-2c6dfd06a68a84c214350ac8be84cabdf501fb33.tar.gz
rockbox-2c6dfd06a68a84c214350ac8be84cabdf501fb33.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.c35
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)
468 468
469 numentries = stream_read_uint32(qtmovie->stream); 469 numentries = stream_read_uint32(qtmovie->stream);
470 size_remaining -= 4; 470 size_remaining -= 4;
471 471
472 qtmovie->res->num_lookup_table = numentries; 472 uint8_t accuracy_divider = 1;
473 qtmovie->res->lookup_table = malloc(numentries * sizeof(*qtmovie->res->lookup_table)); 473 uint32_t fit_numentries = numentries;
474 while (true)
475 {
476 qtmovie->res->lookup_table = malloc(fit_numentries * sizeof(*qtmovie->res->lookup_table));
477
478 if (qtmovie->res->lookup_table)
479 {
480 break;
481 }
482 else
483 {
484 // we failed to alloc memory for lookup table, so reduce seek accuracy and try again
485 fit_numentries = numentries / ++accuracy_divider;
486 }
487 }
488 DEBUGF("lookup_table numentries %d, fit_numentries %d\n", numentries, fit_numentries);
489 qtmovie->res->num_lookup_table = fit_numentries;
474 490
475 if (!qtmovie->res->lookup_table) 491 if (!qtmovie->res->lookup_table)
476 { 492 {
@@ -518,11 +534,14 @@ static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len)
518 frame += (new_first - old_first) * old_frame; 534 frame += (new_first - old_first) * old_frame;
519 } 535 }
520 frame += (k - old_first) * old_frame; 536 frame += (k - old_first) * old_frame;
521 537
522 qtmovie->res->lookup_table[idx].sample = frame; 538 if ((k-1) % accuracy_divider == 0)
523 qtmovie->res->lookup_table[idx].offset = offset; 539 {
524 idx++; 540 qtmovie->res->lookup_table[idx].sample = frame;
525 541 qtmovie->res->lookup_table[idx].offset = offset;
542 idx++;
543 }
544
526 frame -= (k - old_first) * old_frame; 545 frame -= (k - old_first) * old_frame;
527 546
528 offset = stream_read_uint32(qtmovie->stream); 547 offset = stream_read_uint32(qtmovie->stream);