hwcodec: fix shrink_callback resuming playback wrongly, and add checks

if the voice is bigger than the audiobuffer. NOTE: This is the case on the sim
so voice doesn't appear to work currently on hwcodec. Someone needs to verify
on a real target.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30910 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-11-06 12:01:43 +00:00
parent 7baa450738
commit ca2b82b755

View file

@ -516,7 +516,7 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize);
static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
{ {
long offset = audio_current_track()->offset; long offset = audio_current_track()->offset;
int status = audio_status(); bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY;
/* TODO: Do it without stopping playback, if possible */ /* TODO: Do it without stopping playback, if possible */
/* don't call audio_hard_stop() as it frees this handle */ /* don't call audio_hard_stop() as it frees this handle */
if (thread_self() == audio_thread_id) if (thread_self() == audio_thread_id)
@ -542,7 +542,7 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s
audio_reset_buffer_noalloc(start + wanted_size, size); audio_reset_buffer_noalloc(start + wanted_size, size);
break; break;
} }
if (!(status & AUDIO_STATUS_PAUSE)) if (playing)
{ /* safe to call even from the audio thread (due to queue_post()) */ { /* safe to call even from the audio thread (due to queue_post()) */
audio_play(offset); audio_play(offset);
} }
@ -555,6 +555,17 @@ static struct buflib_callbacks ops = {
.shrink_callback = shrink_callback, .shrink_callback = shrink_callback,
}; };
static size_t audio_talkbuf_init(char *bufstart)
{
size_t ret = talkbuf_init(bufstart);
if (bufstart > (size_t)audiobuflen) /* does the voice even fit? */
{
talk_buffer_steal();
return 0;
}
return ret;
}
unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
{ {
(void)talk_buf; /* always grab the voice buffer for now */ (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)
mpeg_audiobuf = core_get_data(audiobuf_handle); mpeg_audiobuf = core_get_data(audiobuf_handle);
/* tell talk about the new buffer, don't re-enable just yet because the /* tell talk about the new buffer, don't re-enable just yet because the
* buffer is stolen */ * buffer is stolen */
talkbuf_init(mpeg_audiobuf); audio_talkbuf_init(mpeg_audiobuf);
return mpeg_audiobuf; return mpeg_audiobuf;
} }
@ -2749,7 +2760,7 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize)
mpeg_audiobuf = SKIPBYTES(mpeg_audiobuf, sizeof(struct cuesheet)); mpeg_audiobuf = SKIPBYTES(mpeg_audiobuf, sizeof(struct cuesheet));
audiobuflen -= sizeof(struct cuesheet); audiobuflen -= sizeof(struct cuesheet);
} }
talkbuf_init(mpeg_audiobuf); audio_talkbuf_init(mpeg_audiobuf);
} }
static void audio_reset_buffer(void) static void audio_reset_buffer(void)
@ -2819,7 +2830,7 @@ void audio_stop(void)
playing = false; playing = false;
#endif /* SIMULATOR */ #endif /* SIMULATOR */
/* give voice our entire buffer */ /* give voice our entire buffer */
talkbuf_init(mpeg_audiobuf); audio_talkbuf_init(mpeg_audiobuf);
} }
/* dummy */ /* dummy */