Advertisement
Guest User

Untitled

a guest
May 31st, 2011
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.81 KB | None | 0 0
  1. diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
  2. index ae8e9a2..b763337 100644
  3. --- a/firmware/target/hosted/android/pcm-android.c
  4. +++ b/firmware/target/hosted/android/pcm-android.c
  5. @@ -23,6 +23,7 @@
  6.  #include <stdbool.h>
  7.  #define _SYSTEM_WITH_JNI /* for getJavaEnvironment */
  8.  #include <system.h>
  9. +#include <pthread.h>
  10.  #include "debug.h"
  11.  #include "pcm.h"
  12.  
  13. @@ -31,6 +32,8 @@ extern JNIEnv *env_ptr;
  14.  /* infos about our pcm chunks */
  15.  static size_t  pcm_data_size;
  16.  static char   *pcm_data_start;
  17. +static int     audio_locked = 0;
  18. +static pthread_mutex_t audio_lock_mutex = PTHREAD_MUTEX_INITIALIZER;
  19.  
  20.  /* cache frequently called methods */
  21.  static jmethodID play_pause_method;
  22. @@ -41,6 +44,20 @@ static jobject   RockboxPCM_instance;
  23.  
  24.  
  25.  /*
  26. + * mutex lock/unlock wrappers neatness' sake
  27. + */
  28. +static inline void lock_audio(void)
  29. +{
  30. +    pthread_mutex_lock(&audio_lock_mutex);
  31. +}
  32. +
  33. +static inline void unlock_audio(void)
  34. +{
  35. +    pthread_mutex_unlock(&audio_lock_mutex);
  36. +}
  37. +
  38. +
  39. +/*
  40.   * transfer our raw data into a java array
  41.   *
  42.   * a bit of a monster functions, but it should cover all cases to overcome
  43. @@ -57,6 +74,8 @@ Java_org_rockbox_RockboxPCM_pcmSamplesToByteArray(JNIEnv *env,
  44.                                                    jobject this,
  45.                                                    jbyteArray arr)
  46.  {
  47. +    lock_audio();
  48. +
  49.      (void)this;
  50.      size_t len;
  51.      size_t array_size = (*env)->GetArrayLength(env, arr);
  52. @@ -76,6 +95,7 @@ Java_org_rockbox_RockboxPCM_pcmSamplesToByteArray(JNIEnv *env,
  53.          if (pcm_data_size == 0)
  54.          {
  55.              DEBUGF("out of data\n");
  56. +            unlock_audio();
  57.              return;
  58.          }
  59.          if (remaining > pcm_data_size)
  60. @@ -90,19 +110,26 @@ Java_org_rockbox_RockboxPCM_pcmSamplesToByteArray(JNIEnv *env,
  61.              goto retry;
  62.          }
  63.          else
  64. +        {
  65.              (*env)->SetByteArrayRegion(env, arr, offset, remaining, pcm_data_start);
  66. +        }
  67.          len = remaining;
  68.      }
  69.      pcm_data_start += len;
  70.      pcm_data_size -= len;
  71. +    unlock_audio();
  72.  }
  73.  
  74.  void pcm_play_lock(void)
  75.  {
  76. +    if (++audio_locked == 1)
  77. +        lock_audio();
  78.  }
  79.  
  80.  void pcm_play_unlock(void)
  81.  {
  82. +    if (--audio_locked == 0)
  83. +        unlock_audio();
  84.  }
  85.  
  86.  void pcm_dma_apply_settings(void)
  87. @@ -168,8 +195,6 @@ void pcm_play_dma_init(void)
  88.      play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V");
  89.      set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V");
  90.      stop_method       = e->GetMethodID(env_ptr, RockboxPCM_class, "stop", "()V");
  91. -    /* get initial pcm data, if any */
  92. -    pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size);
  93.  }
  94.  
  95.  void pcm_postinit(void)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement