From 9f242e7be4f301e965d0bf35908a9bcaacdfdcae Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sat, 16 Mar 2013 22:35:54 +0100 Subject: android: Rewrite PCM playback without OnPlaybackPositionUpdateListener. The old way actually mis-used the API (I misunderstood the docs) because it specified the marker position as a "low buffer watermark" but instead of a future playback head position. The replacement is a simple thread that writes the data regardless of the filling level of the buffer (write() will just block) and polls the playback state periodically. Change-Id: If29237cee4ce78dc42f5a8320878bab0cafe78f7 Reviewed-on: http://gerrit.rockbox.org/422 Tested-by: Dominik Riebeling Reviewed-by: Thomas Martitz --- firmware/target/hosted/android/pcm-android.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'firmware/target/hosted/android') diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index 0428e5f..0608e97 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c @@ -58,7 +58,6 @@ static inline void unlock_audio(void) pthread_mutex_unlock(&audio_lock_mutex); } - /* * write pcm samples to the hardware. Calls AudioTrack.write directly (which * is usually a blocking call) @@ -93,18 +92,23 @@ Java_org_rockbox_RockboxPCM_nativeWrite(JNIEnv *env, jobject this, (*env)->SetByteArrayRegion(env, temp_array, 0, transfer_size, (jbyte*)pcm_data_start); - ret = (*env)->CallIntMethod(env, this, write_method, - temp_array, 0, transfer_size); - if (new_buffer) { new_buffer = false; pcm_play_dma_status_callback(PCM_DMAST_STARTED); - - /* NOTE: might need to release the mutex and sleep here if the - buffer is shorter than the required buffer (like pcm-sdl.c) to - have the mixer clocked at a regular interval */ } + /* SetByteArrayRegion copies, which enables us to unlock audio. This + * is good because the below write() call almost certainly block. + * This allows the mixer to be clocked at a regular interval which vastly + * improves responsiveness when pausing/stopping playback */ + unlock_audio(); + ret = (*env)->CallIntMethod(env, this, write_method, + temp_array, 0, transfer_size); + lock_audio(); + + /* check if still playing. might have changed during the write() call */ + if (!pcm_is_playing()) + break; if (ret < 0) { -- cgit v1.1