summaryrefslogtreecommitdiff
path: root/apps/talk.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-01-26 19:14:47 +0100
committerThomas Martitz <kugel@rockbox.org>2014-01-26 19:14:47 +0100
commit543027564cc72ba3effa8d7b00f380b6dafd8494 (patch)
treeb40fd12e8d3cace2c0e687fc4b7898f97765c38c /apps/talk.c
parent9892b39567d9a0e27ea530d36c1b8decb3489b4a (diff)
downloadrockbox-543027564cc72ba3effa8d7b00f380b6dafd8494.tar.gz
rockbox-543027564cc72ba3effa8d7b00f380b6dafd8494.zip
hwcodec/talk.c: Give the thumbnail buffer regardless of the talk buffer policy.
When the policy is not set, it'll by default not give the clip buffer away. Callers of core_alloc_maximum() suffer from this. However, the thumbnail buffer can be easily freed when needed because nothing needs to be reloaded from disk when it is reallocated (thumbnail clips are loaded on demand, when in the file browser). Do this to give core_alloc_maximum() callers a better chance to succeed with the default talk buffer policy. Change-Id: I8c0da29c520612ca903f6c930bd7c74ae97eca3b
Diffstat (limited to 'apps/talk.c')
-rw-r--r--apps/talk.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/apps/talk.c b/apps/talk.c
index 8979952103..3f8a7f3f60 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -208,31 +208,47 @@ static int move_callback(int handle, void *current, void *new)
208 return BUFLIB_CB_OK; 208 return BUFLIB_CB_OK;
209} 209}
210 210
211static int shrink_callback(int handle, unsigned hints, void *start, size_t old_size) 211static int clip_shrink_callback(int handle, unsigned hints, void *start, size_t old_size)
212{ 212{
213 (void)start;(void)old_size; 213 (void)start;(void)old_size;
214 int *h;
215 if (handle == talk_handle)
216 h = &talk_handle;
217 else // if (handle == thumb_handle)
218 h = &thumb_handle;
219 214
220 if (LIKELY(!talk_handle_locked) 215 if (LIKELY(!talk_handle_locked)
221 && give_buffer_away 216 && give_buffer_away
222 && (hints & BUFLIB_SHRINK_POS_MASK) == BUFLIB_SHRINK_POS_MASK) 217 && (hints & BUFLIB_SHRINK_POS_MASK) == BUFLIB_SHRINK_POS_MASK)
223 { 218 {
224 *h = core_free(handle); 219 talk_handle = core_free(handle);
225 return BUFLIB_CB_OK; 220 return BUFLIB_CB_OK;
226 } 221 }
227 return BUFLIB_CB_CANNOT_SHRINK; 222 return BUFLIB_CB_CANNOT_SHRINK;
228} 223}
229 224
230static struct buflib_callbacks talk_ops = { 225static int thumb_shrink_callback(int handle, unsigned hints, void *start, size_t old_size)
226{
227 (void)start;(void)old_size;(void)hints;
228
229 /* be generous about the thumbnail buffer unless currently used */
230 if (LIKELY(!talk_handle_locked) && thumbnail_buf_used == 0)
231 {
232 thumb_handle = core_free(handle);
233 return BUFLIB_CB_OK;
234 }
235 return BUFLIB_CB_CANNOT_SHRINK;
236}
237
238static struct buflib_callbacks clip_ops = {
231 .move_callback = move_callback, 239 .move_callback = move_callback,
232#if CONFIG_CODEC != SWCODEC 240#if CONFIG_CODEC != SWCODEC
233 .sync_callback = sync_callback, 241 .sync_callback = sync_callback,
234#endif 242#endif
235 .shrink_callback = shrink_callback, 243 .shrink_callback = clip_shrink_callback,
244};
245
246static struct buflib_callbacks thumb_ops = {
247 .move_callback = move_callback,
248#if CONFIG_CODEC != SWCODEC
249 .sync_callback = sync_callback,
250#endif
251 .shrink_callback = thumb_shrink_callback,
236}; 252};
237 253
238 254
@@ -458,7 +474,7 @@ static bool load_data(int fd, ssize_t size_to_read)
458 if (size_to_read < 0) 474 if (size_to_read < 0)
459 return false; 475 return false;
460 476
461 talk_handle = core_alloc_ex("voice data", size_to_read, &talk_ops); 477 talk_handle = core_alloc_ex("voice data", size_to_read, &clip_ops);
462 if (talk_handle < 0) 478 if (talk_handle < 0)
463 return false; 479 return false;
464 480
@@ -484,16 +500,16 @@ static bool alloc_thumbnail_buf(void)
484 /* try to allocate the max. first, and take whatever we can get if that 500 /* try to allocate the max. first, and take whatever we can get if that
485 * fails */ 501 * fails */
486 size = MAX_THUMBNAIL_BUFSIZE; 502 size = MAX_THUMBNAIL_BUFSIZE;
487 handle = core_alloc_ex("voice thumb", MAX_THUMBNAIL_BUFSIZE, &talk_ops); 503 handle = core_alloc_ex("voice thumb", MAX_THUMBNAIL_BUFSIZE, &thumb_ops);
488 if (handle < 0) 504 if (handle < 0)
489 { 505 {
490 size = core_allocatable(); 506 size = core_allocatable();
491 handle = core_alloc_ex("voice thumb", size, &talk_ops); 507 handle = core_alloc_ex("voice thumb", size, &thumb_ops);
492 } 508 }
493#else 509#else
494 /* on HWCODEC, just use the rest of the remaining buffer, 510 /* on HWCODEC, just use the rest of the remaining buffer,
495 * normal playback cannot happen anyway */ 511 * normal playback cannot happen anyway */
496 handle = core_alloc_maximum("voice thumb", &size, &talk_ops); 512 handle = core_alloc_maximum("voice thumb", &size, &thumb_ops);
497#endif 513#endif
498 thumb_handle = handle; 514 thumb_handle = handle;
499 size_for_thumbnail = (handle > 0) ? size : 0; 515 size_for_thumbnail = (handle > 0) ? size : 0;
@@ -530,7 +546,7 @@ static bool load_voicefile_data(int fd, size_t max_size)
530#ifdef TALK_PARTIAL_LOAD 546#ifdef TALK_PARTIAL_LOAD
531 (void)fd; 547 (void)fd;
532 /* just allocate, populate on an as-needed basis later */ 548 /* just allocate, populate on an as-needed basis later */
533 talk_handle = core_alloc_ex("voice data", max_size, &talk_ops); 549 talk_handle = core_alloc_ex("voice data", max_size, &clip_ops);
534 if (talk_handle < 0) 550 if (talk_handle < 0)
535 goto load_err_free; 551 goto load_err_free;
536#else 552#else
@@ -875,11 +891,6 @@ bool talk_voice_required(void)
875/* somebody else claims the mp3 buffer, e.g. for regular play/record */ 891/* somebody else claims the mp3 buffer, e.g. for regular play/record */
876void talk_buffer_set_policy(int policy) 892void talk_buffer_set_policy(int policy)
877{ 893{
878#if CONFIG_CODEC != SWCODEC
879 /* always grab the voice buffer for now */
880 (void) policy;
881 give_buffer_away = true;
882#else
883 switch(policy) 894 switch(policy)
884 { 895 {
885 case TALK_BUFFER_DEFAULT: 896 case TALK_BUFFER_DEFAULT:
@@ -887,7 +898,6 @@ void talk_buffer_set_policy(int policy)
887 case TALK_BUFFER_LOOSE: give_buffer_away = true; break; 898 case TALK_BUFFER_LOOSE: give_buffer_away = true; break;
888 default: DEBUGF("Ignoring unknown policy\n"); break; 899 default: DEBUGF("Ignoring unknown policy\n"); break;
889 } 900 }
890#endif
891} 901}
892 902
893/* play a voice ID from voicefile */ 903/* play a voice ID from voicefile */