summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-03-16 22:35:54 +0100
committerThomas Martitz <kugel@rockbox.org>2013-04-01 11:26:12 +0200
commit9f242e7be4f301e965d0bf35908a9bcaacdfdcae (patch)
tree55952fcaa07f6cdb0657f255c6cbf28cbd2c2c95 /firmware/target/hosted/android
parent9add11d79a5e1516908a4935a3e538880ff38378 (diff)
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 <Dominik.Riebeling@gmail.com> Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Diffstat (limited to 'firmware/target/hosted/android')
-rw-r--r--firmware/target/hosted/android/pcm-android.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
index 0428e5f541..0608e971a7 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)
{