diff options
Diffstat (limited to 'apps/codecs')
-rw-r--r-- | apps/codecs/libm4a/demux.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/apps/codecs/libm4a/demux.c b/apps/codecs/libm4a/demux.c index 1b8deab602..cd53b12fd0 100644 --- a/apps/codecs/libm4a/demux.c +++ b/apps/codecs/libm4a/demux.c | |||
@@ -429,14 +429,14 @@ static bool read_chunk_stsc(qtmovie_t *qtmovie, size_t chunk_len) | |||
429 | 429 | ||
430 | static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) | 430 | static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) |
431 | { | 431 | { |
432 | uint32_t i, k; | 432 | uint32_t i, k, old_i; |
433 | uint32_t numentries; | 433 | uint32_t numentries; |
434 | int32_t idx = 0; | 434 | uint32_t idx = 0; |
435 | int32_t frame; | 435 | uint32_t frame; |
436 | int32_t offset; | 436 | uint32_t offset; |
437 | int32_t old_first; | 437 | uint32_t old_first; |
438 | int32_t new_first; | 438 | uint32_t new_first; |
439 | int32_t old_frame; | 439 | uint32_t old_frame; |
440 | size_t size_remaining = chunk_len - 8; | 440 | size_t size_remaining = chunk_len - 8; |
441 | 441 | ||
442 | /* version + flags */ | 442 | /* version + flags */ |
@@ -471,18 +471,25 @@ static bool read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) | |||
471 | * table. This reduces the memory consumption by a factor of 2 or even | 471 | * table. This reduces the memory consumption by a factor of 2 or even |
472 | * more. */ | 472 | * more. */ |
473 | i = 1; | 473 | i = 1; |
474 | old_i = 1; | ||
474 | frame = 0; | 475 | frame = 0; |
475 | old_frame = qtmovie->res->sample_to_chunk[0].num_samples; | ||
476 | old_first = qtmovie->res->sample_to_chunk[0].first_chunk; | 476 | old_first = qtmovie->res->sample_to_chunk[0].first_chunk; |
477 | old_frame = qtmovie->res->sample_to_chunk[0].num_samples; | ||
478 | new_first = qtmovie->res->sample_to_chunk[1].first_chunk; | ||
477 | for (k = 1; k < numentries; ++k) | 479 | for (k = 1; k < numentries; ++k) |
478 | { | 480 | { |
479 | for (; i < qtmovie->res->num_sample_to_chunks; ++i) | 481 | for (; i < qtmovie->res->num_sample_to_chunks; ++i) |
480 | { | 482 | { |
481 | old_frame = qtmovie->res->sample_to_chunk[i-1].num_samples; | 483 | if (i > old_i) |
482 | old_first = qtmovie->res->sample_to_chunk[i-1].first_chunk; | 484 | { |
483 | new_first = qtmovie->res->sample_to_chunk[i ].first_chunk; | 485 | /* Only access sample_to_chunk[] if new data is required. */ |
486 | old_first = qtmovie->res->sample_to_chunk[i-1].first_chunk; | ||
487 | old_frame = qtmovie->res->sample_to_chunk[i-1].num_samples; | ||
488 | new_first = qtmovie->res->sample_to_chunk[i ].first_chunk; | ||
489 | old_i = i; | ||
490 | } | ||
484 | 491 | ||
485 | if (qtmovie->res->sample_to_chunk[i].first_chunk > k) | 492 | if (new_first > k) |
486 | break; | 493 | break; |
487 | 494 | ||
488 | frame += (new_first - old_first) * old_frame; | 495 | frame += (new_first - old_first) * old_frame; |