summaryrefslogtreecommitdiff
path: root/apps/mpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mpeg.c')
-rw-r--r--apps/mpeg.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/apps/mpeg.c b/apps/mpeg.c
index 9048226133..428f758f83 100644
--- a/apps/mpeg.c
+++ b/apps/mpeg.c
@@ -516,7 +516,7 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize);
516static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) 516static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
517{ 517{
518 long offset = audio_current_track()->offset; 518 long offset = audio_current_track()->offset;
519 int status = audio_status(); 519 bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY;
520 /* TODO: Do it without stopping playback, if possible */ 520 /* TODO: Do it without stopping playback, if possible */
521 /* don't call audio_hard_stop() as it frees this handle */ 521 /* don't call audio_hard_stop() as it frees this handle */
522 if (thread_self() == audio_thread_id) 522 if (thread_self() == audio_thread_id)
@@ -542,7 +542,7 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s
542 audio_reset_buffer_noalloc(start + wanted_size, size); 542 audio_reset_buffer_noalloc(start + wanted_size, size);
543 break; 543 break;
544 } 544 }
545 if (!(status & AUDIO_STATUS_PAUSE)) 545 if (playing)
546 { /* safe to call even from the audio thread (due to queue_post()) */ 546 { /* safe to call even from the audio thread (due to queue_post()) */
547 audio_play(offset); 547 audio_play(offset);
548 } 548 }
@@ -555,6 +555,17 @@ static struct buflib_callbacks ops = {
555 .shrink_callback = shrink_callback, 555 .shrink_callback = shrink_callback,
556}; 556};
557 557
558static size_t audio_talkbuf_init(char *bufstart)
559{
560 size_t ret = talkbuf_init(bufstart);
561 if (bufstart > (size_t)audiobuflen) /* does the voice even fit? */
562 {
563 talk_buffer_steal();
564 return 0;
565 }
566 return ret;
567}
568
558unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) 569unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
559{ 570{
560 (void)talk_buf; /* always grab the voice buffer for now */ 571 (void)talk_buf; /* always grab the voice buffer for now */
@@ -577,7 +588,7 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
577 mpeg_audiobuf = core_get_data(audiobuf_handle); 588 mpeg_audiobuf = core_get_data(audiobuf_handle);
578 /* tell talk about the new buffer, don't re-enable just yet because the 589 /* tell talk about the new buffer, don't re-enable just yet because the
579 * buffer is stolen */ 590 * buffer is stolen */
580 talkbuf_init(mpeg_audiobuf); 591 audio_talkbuf_init(mpeg_audiobuf);
581 592
582 return mpeg_audiobuf; 593 return mpeg_audiobuf;
583} 594}
@@ -2749,7 +2760,7 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize)
2749 mpeg_audiobuf = SKIPBYTES(mpeg_audiobuf, sizeof(struct cuesheet)); 2760 mpeg_audiobuf = SKIPBYTES(mpeg_audiobuf, sizeof(struct cuesheet));
2750 audiobuflen -= sizeof(struct cuesheet); 2761 audiobuflen -= sizeof(struct cuesheet);
2751 } 2762 }
2752 talkbuf_init(mpeg_audiobuf); 2763 audio_talkbuf_init(mpeg_audiobuf);
2753} 2764}
2754 2765
2755static void audio_reset_buffer(void) 2766static void audio_reset_buffer(void)
@@ -2819,7 +2830,7 @@ void audio_stop(void)
2819 playing = false; 2830 playing = false;
2820#endif /* SIMULATOR */ 2831#endif /* SIMULATOR */
2821 /* give voice our entire buffer */ 2832 /* give voice our entire buffer */
2822 talkbuf_init(mpeg_audiobuf); 2833 audio_talkbuf_init(mpeg_audiobuf);
2823} 2834}
2824 2835
2825/* dummy */ 2836/* dummy */