[BugFix] Playback.c OOM with large voice file

with our large voice file being loaded in its entirety to the buffer
there isn't enough room to allocate the required pcm buffer
well prior to this patch we looked for 1k free to allow the talk buffer
to be given away
well the pcm buffer expects something like 5-600 kb on the clipzip
and there is 1k allocatable but not 300 more

so instead get the required pcm buffer size and check against that

Change-Id: I40a056e4170c37bc3429f0cb37af221ae7f812e5
This commit is contained in:
William Wilgus 2024-09-24 03:14:49 -04:00 committed by Solomon Peachy
parent c3f51b5fe9
commit f0c208554c
3 changed files with 8 additions and 1 deletions

View file

@ -580,6 +580,12 @@ static void init_buffer_state(void)
chunk_transidx = INVALID_BUF_INDEX; chunk_transidx = INVALID_BUF_INDEX;
} }
/* call prior to init to get bytes required */
size_t pcmbuf_size_reqd(void)
{
return get_next_required_pcmbuf_chunks() * PCMBUF_CHUNK_SIZE;
}
/* Initialize the PCM buffer. The structure looks like this: /* Initialize the PCM buffer. The structure looks like this:
* ...|---------PCMBUF---------|GUARDBUF|DESCS| */ * ...|---------PCMBUF---------|GUARDBUF|DESCS| */
size_t pcmbuf_init(void *bufend) size_t pcmbuf_init(void *bufend)

View file

@ -28,6 +28,7 @@ void *pcmbuf_request_buffer(int *count);
void pcmbuf_write_complete(int count, unsigned long elapsed, off_t offset); void pcmbuf_write_complete(int count, unsigned long elapsed, off_t offset);
/* Init */ /* Init */
size_t pcmbuf_size_reqd(void);
size_t pcmbuf_init(void *bufend); size_t pcmbuf_init(void *bufend);
/* Playback */ /* Playback */

View file

@ -1040,7 +1040,7 @@ static void audio_reset_buffer(void)
core_free(audiobuf_handle); core_free(audiobuf_handle);
audiobuf_handle = 0; audiobuf_handle = 0;
} }
if (core_allocatable() < (1 << 10)) if (core_allocatable() < pcmbuf_size_reqd())
talk_buffer_set_policy(TALK_BUFFER_LOOSE); /* back off voice buffer */ talk_buffer_set_policy(TALK_BUFFER_LOOSE); /* back off voice buffer */
audiobuf_handle = core_alloc_maximum(&filebuflen, &ops); audiobuf_handle = core_alloc_maximum(&filebuflen, &ops);