diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/menus/main_menu.c | 4 | ||||
-rw-r--r-- | apps/mpeg.c | 29 | ||||
-rw-r--r-- | apps/playback.c | 19 |
3 files changed, 38 insertions, 14 deletions
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index 8053bf0cf8..bb8ea276fb 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c | |||
@@ -179,7 +179,7 @@ static const char* info_getname(int selected_item, void *data, | |||
179 | 179 | ||
180 | case INFO_BUFFER: /* buffer */ | 180 | case INFO_BUFFER: /* buffer */ |
181 | { | 181 | { |
182 | long kib = audio_buffer_available() / 1024; /* to KiB */ | 182 | long kib = audio_buffer_size() / 1024; /* to KiB */ |
183 | output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); | 183 | output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); |
184 | snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); | 184 | snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); |
185 | } | 185 | } |
@@ -261,7 +261,7 @@ static int info_speak_item(int selected_item, void * data) | |||
261 | case INFO_BUFFER: /* buffer */ | 261 | case INFO_BUFFER: /* buffer */ |
262 | { | 262 | { |
263 | talk_id(LANG_BUFFER_STAT, false); | 263 | talk_id(LANG_BUFFER_STAT, false); |
264 | long kib = audio_buffer_available() / 1024; /* to KiB */ | 264 | long kib = audio_buffer_size() / 1024; /* to KiB */ |
265 | output_dyn_value(NULL, 0, kib, kbyte_units, true); | 265 | output_dyn_value(NULL, 0, kib, kbyte_units, true); |
266 | break; | 266 | break; |
267 | } | 267 | } |
diff --git a/apps/mpeg.c b/apps/mpeg.c index ae33ccc1bf..698695b72d 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c | |||
@@ -151,7 +151,7 @@ static bool paused; /* playback is paused */ | |||
151 | static int audiobuf_handle; /* handle to the audio buffer */ | 151 | static int audiobuf_handle; /* handle to the audio buffer */ |
152 | static char* mpeg_audiobuf; /* poiunter to the audio buffer */ | 152 | static char* mpeg_audiobuf; /* poiunter to the audio buffer */ |
153 | static long audiobuflen; /* length of the audio buffer */ | 153 | static long audiobuflen; /* length of the audio buffer */ |
154 | 154 | #define AUDIO_BUFFER_RESERVE (256*1024) | |
155 | #ifdef SIMULATOR | 155 | #ifdef SIMULATOR |
156 | static char mpeg_stack[DEFAULT_STACK_SIZE]; | 156 | static char mpeg_stack[DEFAULT_STACK_SIZE]; |
157 | static struct mp3entry taginfo; | 157 | static struct mp3entry taginfo; |
@@ -515,9 +515,16 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize); | |||
515 | /* Buffer must not move. */ | 515 | /* Buffer must not move. */ |
516 | static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) | 516 | static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) |
517 | { | 517 | { |
518 | long offset = audio_current_track()->offset; | 518 | ssize_t extradata_size = old_size - audiobuflen; |
519 | bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY; | 519 | /* check what buflib requests */ |
520 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | ||
521 | ssize_t size = (ssize_t)old_size - wanted_size; | ||
522 | /* keep at least 256K for the buffering */ | ||
523 | if ((size - extradata_size) < AUDIO_BUFFER_RESERVE) | ||
524 | return BUFLIB_CB_CANNOT_SHRINK; | ||
520 | /* TODO: Do it without stopping playback, if possible */ | 525 | /* TODO: Do it without stopping playback, if possible */ |
526 | bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY; | ||
527 | long offset = audio_current_track()->offset; | ||
521 | /* don't call audio_hard_stop() as it frees this handle */ | 528 | /* don't call audio_hard_stop() as it frees this handle */ |
522 | if (thread_self() == audio_thread_id) | 529 | if (thread_self() == audio_thread_id) |
523 | { /* inline case MPEG_STOP (audio_stop()) response | 530 | { /* inline case MPEG_STOP (audio_stop()) response |
@@ -528,9 +535,6 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s | |||
528 | audio_stop(); | 535 | audio_stop(); |
529 | talk_buffer_steal(); /* we obtain control over the buffer */ | 536 | talk_buffer_steal(); /* we obtain control over the buffer */ |
530 | 537 | ||
531 | /* we should be free to change the buffer now */ | ||
532 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | ||
533 | ssize_t size = (ssize_t)old_size - wanted_size; | ||
534 | switch (hints & BUFLIB_SHRINK_POS_MASK) | 538 | switch (hints & BUFLIB_SHRINK_POS_MASK) |
535 | { | 539 | { |
536 | case BUFLIB_SHRINK_POS_BACK: | 540 | case BUFLIB_SHRINK_POS_BACK: |
@@ -2742,11 +2746,20 @@ void audio_set_recording_options(struct audio_recording_options *options) | |||
2742 | #endif /* SIMULATOR */ | 2746 | #endif /* SIMULATOR */ |
2743 | #endif /* CONFIG_CODEC == MAS3587F */ | 2747 | #endif /* CONFIG_CODEC == MAS3587F */ |
2744 | 2748 | ||
2745 | size_t audio_buffer_available(void) | 2749 | size_t audio_buffer_size(void) |
2746 | { | 2750 | { |
2747 | if (audiobuf_handle > 0) | 2751 | if (audiobuf_handle > 0) |
2748 | return audiobuflen; | 2752 | return audiobuflen; |
2749 | return core_available(); | 2753 | return 0; |
2754 | } | ||
2755 | |||
2756 | size_t audio_buffer_available(void) | ||
2757 | { | ||
2758 | size_t size = 0; | ||
2759 | size_t core_size = core_available(); | ||
2760 | if (audiobuf_handle > 0) | ||
2761 | return audiobuflen - AUDIO_BUFFER_RESERVE - 128; | ||
2762 | return MAX(core_size, size); | ||
2750 | } | 2763 | } |
2751 | 2764 | ||
2752 | static void audio_reset_buffer_noalloc(void* buf, size_t bufsize) | 2765 | static void audio_reset_buffer_noalloc(void* buf, size_t bufsize) |
diff --git a/apps/playback.c b/apps/playback.c index a245091d91..d591998bec 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -733,13 +733,24 @@ static void scratch_mem_init(void *mem) | |||
733 | } | 733 | } |
734 | 734 | ||
735 | static int audiobuf_handle; | 735 | static int audiobuf_handle; |
736 | #define AUDIO_BUFFER_RESERVE (256*1024) | ||
736 | static size_t filebuflen; | 737 | static size_t filebuflen; |
737 | 738 | ||
739 | |||
740 | size_t audio_buffer_size(void) | ||
741 | { | ||
742 | if (audiobuf_handle > 0) | ||
743 | return filebuflen - AUDIO_BUFFER_RESERVE; | ||
744 | return 0; | ||
745 | } | ||
746 | |||
738 | size_t audio_buffer_available(void) | 747 | size_t audio_buffer_available(void) |
739 | { | 748 | { |
740 | if (audiobuf_handle > 0) /* if allocated return what we got */ | 749 | size_t size = 0; |
741 | return filebuflen; | 750 | size_t core_size = core_available(); |
742 | return core_available(); | 751 | if (audiobuf_handle > 0) /* if allocated return what we can give */ |
752 | size = filebuflen - AUDIO_BUFFER_RESERVE - 128; | ||
753 | return MAX(core_size, size); | ||
743 | } | 754 | } |
744 | 755 | ||
745 | /* Set up the audio buffer for playback | 756 | /* Set up the audio buffer for playback |
@@ -840,7 +851,7 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s | |||
840 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | 851 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); |
841 | ssize_t size = (ssize_t)old_size - wanted_size; | 852 | ssize_t size = (ssize_t)old_size - wanted_size; |
842 | /* keep at least 256K for the buffering */ | 853 | /* keep at least 256K for the buffering */ |
843 | if ((size - extradata_size) < 256*1024) | 854 | if ((size - extradata_size) < AUDIO_BUFFER_RESERVE) |
844 | return BUFLIB_CB_CANNOT_SHRINK; | 855 | return BUFLIB_CB_CANNOT_SHRINK; |
845 | 856 | ||
846 | 857 | ||