Advertisement
Guest User

Untitled

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