diff options
Diffstat (limited to 'apps/mpeg.c')
-rw-r--r-- | apps/mpeg.c | 29 |
1 files changed, 21 insertions, 8 deletions
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) |