1
0
Fork 0
forked from len0rd/rockbox

Codecs: mp4: Fix seek in very large files

Samples count requires 64 bit

Change-Id: Ia54be57d7d15b3db19dbc29ff8a06671594abb4b
This commit is contained in:
roman.artiukhin 2023-09-05 01:19:38 +03:00 committed by Solomon Peachy
parent d2f7777f7a
commit 27aa95afcb
4 changed files with 11 additions and 10 deletions

View file

@ -56,7 +56,7 @@ enum codec_status codec_run(void)
size_t n; size_t n;
demux_res_t demux_res; demux_res_t demux_res;
stream_t input_stream; stream_t input_stream;
uint32_t sound_samples_done; uint64_t sound_samples_done;
uint32_t elapsed_time; uint32_t elapsed_time;
int file_offset; int file_offset;
int framelength; int framelength;
@ -172,7 +172,7 @@ enum codec_status codec_run(void)
* m4a_seek and the resulting sound_samples_done must be expanded * m4a_seek and the resulting sound_samples_done must be expanded
* by a factor 2. This is done via using sbr_fac. */ * by a factor 2. This is done via using sbr_fac. */
if (m4a_seek(&demux_res, &input_stream, if (m4a_seek(&demux_res, &input_stream,
(param/10/sbr_fac)*(ci->id3->frequency/100), (uint64_t) param * ci->id3->frequency / sbr_fac / 1000ULL,
&sound_samples_done, (int*) &i)) { &sound_samples_done, (int*) &i)) {
sound_samples_done *= sbr_fac; sound_samples_done *= sbr_fac;
elapsed_time = sound_samples_done * 1000LL / ci->id3->frequency; elapsed_time = sound_samples_done * 1000LL / ci->id3->frequency;

View file

@ -55,7 +55,7 @@ enum codec_status codec_run(void)
size_t n; size_t n;
demux_res_t demux_res; demux_res_t demux_res;
stream_t input_stream; stream_t input_stream;
uint32_t samplesdone; uint64_t samplesdone;
int samplesdecoded; int samplesdecoded;
unsigned int i; unsigned int i;
unsigned char* buffer; unsigned char* buffer;

View file

@ -137,13 +137,14 @@ int m4a_check_sample_offset(demux_res_t *demux_res, uint32_t frame, uint32_t *st
/* Seek to desired sound sample location. Return 1 on success (and modify /* Seek to desired sound sample location. Return 1 on success (and modify
* sound_samples_done and current_sample), 0 if failed. */ * sound_samples_done and current_sample), 0 if failed. */
unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream, unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
uint32_t sound_sample_loc, uint32_t* sound_samples_done, uint64_t sound_sample_loc, uint64_t* sound_samples_done,
int* current_sample) int* current_sample)
{ {
uint32_t i, sample_i, sound_sample_i; uint32_t i, sample_i;
uint32_t time, time_cnt, time_dur; uint32_t time, time_cnt, time_dur;
uint32_t chunk, chunk_first_sample; uint32_t chunk, chunk_first_sample;
uint32_t offset; uint32_t offset;
uint64_t sound_sample_i;
time_to_sample_t *tts_tab = demux_res->time_to_sample; time_to_sample_t *tts_tab = demux_res->time_to_sample;
sample_offset_t *tco_tab = demux_res->lookup_table; sample_offset_t *tco_tab = demux_res->lookup_table;
uint32_t *tsz_tab = demux_res->sample_byte_sizes; uint32_t *tsz_tab = demux_res->sample_byte_sizes;
@ -208,7 +209,7 @@ unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
DEBUGF("seek chunk=%lu, sample=%lu, soundsample=%lu, offset=%lu\n", DEBUGF("seek chunk=%lu, sample=%lu, soundsample=%lu, offset=%lu\n",
(unsigned long)chunk, (unsigned long)chunk_first_sample, (unsigned long)chunk, (unsigned long)chunk_first_sample,
(unsigned long)sound_sample_i, (unsigned long)offset); sound_sample_i, (unsigned long)offset);
if (tsz_tab) { if (tsz_tab) {
/* We have a sample-to-bytes table available so we can do accurate /* We have a sample-to-bytes table available so we can do accurate
@ -260,13 +261,13 @@ unsigned int m4a_seek(demux_res_t* demux_res, stream_t* stream,
* calculate the sound_samples_done value. * calculate the sound_samples_done value.
*/ */
unsigned int m4a_seek_raw(demux_res_t* demux_res, stream_t* stream, unsigned int m4a_seek_raw(demux_res_t* demux_res, stream_t* stream,
uint32_t file_loc, uint32_t* sound_samples_done, uint32_t file_loc, uint64_t* sound_samples_done,
int* current_sample) int* current_sample)
{ {
uint32_t i; uint32_t i;
uint32_t chunk_sample = 0; uint32_t chunk_sample = 0;
uint32_t total_samples = 0; uint32_t total_samples = 0;
uint32_t new_sound_sample = 0; uint64_t new_sound_sample = 0;
uint32_t tmp_dur; uint32_t tmp_dur;
uint32_t tmp_cnt; uint32_t tmp_cnt;
uint32_t new_pos; uint32_t new_pos;

View file

@ -130,10 +130,10 @@ int stream_eof(stream_t *stream);
void stream_create(stream_t *stream,struct codec_api* ci); void stream_create(stream_t *stream,struct codec_api* ci);
unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample); unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample);
unsigned int m4a_seek (demux_res_t* demux_res, stream_t* stream, unsigned int m4a_seek (demux_res_t* demux_res, stream_t* stream,
uint32_t sound_sample_loc, uint32_t* sound_samples_done, uint64_t sound_sample_loc, uint64_t* sound_samples_done,
int* current_sample); int* current_sample);
unsigned int m4a_seek_raw (demux_res_t* demux_res, stream_t* stream, unsigned int m4a_seek_raw (demux_res_t* demux_res, stream_t* stream,
uint32_t file_loc, uint32_t* sound_samples_done, int* current_sample); uint32_t file_loc, uint64_t* sound_samples_done, int* current_sample);
int m4a_check_sample_offset(demux_res_t *demux_res, uint32_t frame, uint32_t *start); int m4a_check_sample_offset(demux_res_t *demux_res, uint32_t frame, uint32_t *start);
#endif /* STREAM_H */ #endif /* STREAM_H */