diff options
-rw-r--r-- | apps/mpeg.c | 3 | ||||
-rw-r--r-- | apps/talk.c | 50 |
2 files changed, 32 insertions, 21 deletions
diff --git a/apps/mpeg.c b/apps/mpeg.c index 08e8e4cf51..bfe3d6d54f 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c | |||
@@ -2989,7 +2989,6 @@ void audio_init(void) | |||
2989 | { | 2989 | { |
2990 | mpeg_errno = 0; | 2990 | mpeg_errno = 0; |
2991 | 2991 | ||
2992 | talk_init(); | ||
2993 | audio_reset_buffer(); | 2992 | audio_reset_buffer(); |
2994 | 2993 | ||
2995 | #ifndef SIMULATOR | 2994 | #ifndef SIMULATOR |
@@ -3009,6 +3008,8 @@ void audio_init(void) | |||
3009 | or_b(0x08, &PADRH); | 3008 | or_b(0x08, &PADRH); |
3010 | #endif /* CONFIG_CODEC == MAS3587F */ | 3009 | #endif /* CONFIG_CODEC == MAS3587F */ |
3011 | 3010 | ||
3011 | talk_init(); | ||
3012 | |||
3012 | #ifdef DEBUG | 3013 | #ifdef DEBUG |
3013 | #ifndef SIMULATOR | 3014 | #ifndef SIMULATOR |
3014 | dbg_timer_start(); | 3015 | dbg_timer_start(); |
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 | ||
211 | static int shrink_callback(int handle, unsigned hints, void *start, size_t old_size) | 211 | static 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 | ||
230 | static struct buflib_callbacks talk_ops = { | 225 | static 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 | |||
238 | static 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 | |||
246 | static 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 */ |
876 | void talk_buffer_set_policy(int policy) | 892 | void 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 */ |