From 1c59b101df15a7a14b7be787045ae88306672f9f Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Tue, 8 May 2007 22:56:12 +0000 Subject: [PATCH] SWCODEC Playback: Seriously mess with it and get rid of (at least some ;) race conditions. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13361 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 3 +++ apps/playback.c | 60 ++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index ddfddc5ec7..f16a620d04 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -112,11 +112,14 @@ void fade(bool fade_in) sleep(1); } audio_pause(); + +#if CONFIG_CODEC != SWCODEC #ifndef SIMULATOR /* let audio thread run and wait for the mas to run out of data */ while (!mp3_pause_done()) #endif sleep(HZ/10); +#endif /* reset volume to what it was before the fade */ sound_set_volume(global_settings.volume); diff --git a/apps/playback.c b/apps/playback.c index bdbb765e0f..7345ef1400 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -138,7 +138,7 @@ enum { Q_AUDIO_FLUSH, Q_AUDIO_TRACK_CHANGED, Q_AUDIO_DIR_SKIP, - Q_AUDIO_NEW_PLAYLIST, + Q_AUDIO_UNUSED_0, /* Free. Previously Q_AUDIO_NEW_PLAYLIST */ Q_AUDIO_POSTINIT, Q_AUDIO_FILL_BUFFER, #if MEM > 8 @@ -400,11 +400,6 @@ bool mp3_is_playing(void) return voice_is_playing; } -bool mp3_pause_done(void) -{ - return pcm_is_paused(); -} - void mpeg_id3_options(bool _v1first) { v1first = _v1first; @@ -673,22 +668,9 @@ void audio_play(long offset) #endif /* Start playback */ - if (playing && offset <= 0) - { - LOGFQUEUE("audio > audio Q_AUDIO_NEW_PLAYLIST"); - queue_post(&audio_queue, Q_AUDIO_NEW_PLAYLIST, 0); - } - else - { - LOGFQUEUE("audio > audio Q_AUDIO_STOP"); - queue_post(&audio_queue, Q_AUDIO_STOP, 0); - LOGFQUEUE("audio > audio Q_AUDIO_PLAY"); - queue_post(&audio_queue, Q_AUDIO_PLAY, offset); - } - - /* Don't return until playback has actually started */ - while (!playing) - yield(); + LOGFQUEUE("audio >| audio Q_AUDIO_PLAY: %l", offset); + /* Don't return until playback has actually stopped */ + queue_send(&audio_queue, Q_AUDIO_PLAY, offset); } void audio_stop(void) @@ -701,14 +683,16 @@ void audio_stop(void) void audio_pause(void) { - LOGFQUEUE("audio > audio Q_AUDIO_PAUSE"); - queue_post(&audio_queue, Q_AUDIO_PAUSE, true); + LOGFQUEUE("audio >| audio Q_AUDIO_PAUSE"); + /* Don't return until playback has actually paused */ + queue_send(&audio_queue, Q_AUDIO_PAUSE, true); } void audio_resume(void) { - LOGFQUEUE("audio > audio Q_AUDIO_PAUSE resume"); - queue_post(&audio_queue, Q_AUDIO_PAUSE, false); + LOGFQUEUE("audio >| audio Q_AUDIO_PAUSE resume"); + /* Don't return until playback has actually resumed */ + queue_send(&audio_queue, Q_AUDIO_PAUSE, false); } void audio_next(void) @@ -3342,13 +3326,14 @@ static void audio_play_start(size_t offset) #endif /* Wait for any previously playing audio to flush - TODO: Not necessary? */ + paused = false; audio_stop_codec_flush(); track_changed = true; playlist_end = false; playing = true; - paused = false; + ci.new_track = 0; ci.seek_time = 0; wps_offset = 0; @@ -3368,6 +3353,9 @@ static void audio_play_start(size_t offset) last_peek_offset = -1; + /* Officially playing */ + queue_reply(&audio_queue, 1); + audio_fill_file_buffer(true, false, offset); } @@ -3420,6 +3408,10 @@ static void audio_new_playlist(void) /* Signal the codec to initiate a track change forward */ new_playlist = true; ci.new_track = 1; + + /* Officially playing */ + queue_reply(&audio_queue, 1); + audio_fill_file_buffer(false, true, 0); } @@ -3635,8 +3627,13 @@ static void audio_thread(void) case Q_AUDIO_PLAY: LOGFQUEUE("audio < Q_AUDIO_PLAY"); - audio_clear_track_entries(false); - audio_play_start((size_t)ev.data); + if (playing && ev.data <= 0) + audio_new_playlist(); + else + { + audio_stop_playback(); + audio_play_start((size_t)ev.data); + } break ; case Q_AUDIO_STOP: @@ -3690,11 +3687,6 @@ static void audio_thread(void) audio_initiate_dir_change(ev.data); break; - case Q_AUDIO_NEW_PLAYLIST: - LOGFQUEUE("audio < Q_AUDIO_NEW_PLAYLIST"); - audio_new_playlist(); - break; - case Q_AUDIO_FLUSH: LOGFQUEUE("audio < Q_AUDIO_FLUSH"); audio_invalidate_tracks();