Android/openslES: move a few static variables to SDL_PrivateAudioData structure
authorSylvain Becker <sylvain.becker@gmail.com>
Mon, 14 Jan 2019 10:58:57 +0100
changeset 125402660c01ff7da
parent 12539 e7282e21da92
child 12541 f0b89ca0ad7d
Android/openslES: move a few static variables to SDL_PrivateAudioData structure
src/audio/openslES/SDL_openslES.c
src/audio/openslES/SDL_openslES.h
     1.1 --- a/src/audio/openslES/SDL_openslES.c	Mon Jan 14 10:16:26 2019 +0100
     1.2 +++ b/src/audio/openslES/SDL_openslES.c	Mon Jan 14 10:58:57 2019 +0100
     1.3 @@ -26,7 +26,7 @@
     1.4  #include "../SDL_audio_c.h"
     1.5  #include "SDL_openslES.h"
     1.6  
     1.7 -// for native audio
     1.8 +/* for native audio */
     1.9  #include <SLES/OpenSLES.h>
    1.10  #include <SLES/OpenSLES_Android.h>
    1.11  
    1.12 @@ -34,58 +34,47 @@
    1.13  
    1.14  #define LOG_TAG "SDL_openslES"
    1.15  
    1.16 -//#define LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
    1.17 -//#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
    1.18 -//#define LOGI(...) do {} while (0)
    1.19 -//#define LOGE(...) do {} while (0)
    1.20 +/*#define LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
    1.21 +/*#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
    1.22 +/*#define LOGI(...) do {} while (0) */
    1.23 +/*#define LOGE(...) do {} while (0) */
    1.24  #define LOGI(...)
    1.25  #define LOGE(...)
    1.26  
    1.27 -// engine interfaces
    1.28 +/* engine interfaces */
    1.29  static SLObjectItf engineObject = NULL;
    1.30  static SLEngineItf engineEngine;
    1.31  
    1.32 -// output mix interfaces
    1.33 +/* output mix interfaces */
    1.34  static SLObjectItf outputMixObject = NULL;
    1.35 -//static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
    1.36 +// static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
    1.37  
    1.38 -// aux effect on the output mix, used by the buffer queue player
    1.39 -// static const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
    1.40 +/* aux effect on the output mix, used by the buffer queue player */
    1.41 +/* static const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR; */
    1.42  
    1.43 -// buffer queue player interfaces
    1.44 +/* buffer queue player interfaces */
    1.45  static SLObjectItf                   bqPlayerObject = NULL;
    1.46  static SLPlayItf                     bqPlayerPlay;
    1.47  static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
    1.48 -//static SLEffectSendItf          bqPlayerEffectSend;
    1.49 +/*static SLEffectSendItf          bqPlayerEffectSend; */
    1.50  static SLMuteSoloItf                 bqPlayerMuteSolo;
    1.51  static SLVolumeItf                   bqPlayerVolume;
    1.52  
    1.53  #if 0
    1.54 -// recorder interfaces TODO
    1.55 +/* recorder interfaces TODO */
    1.56  static SLObjectItf                   recorderObject = NULL;
    1.57  static SLRecordItf                   recorderRecord;
    1.58  static SLAndroidSimpleBufferQueueItf recorderBufferQueue;
    1.59  #endif
    1.60  
    1.61 -// pointer and size of the next player buffer to enqueue, and number of remaining buffers
    1.62 +/* pointer and size of the next player buffer to enqueue, and number of remaining buffers */
    1.63  #if 0
    1.64  static short      *nextBuffer;
    1.65  static unsigned    nextSize;
    1.66  static int         nextCount;
    1.67  #endif
    1.68  
    1.69 -#define NUM_BUFFERS 2           /* -- Don't lower this! */
    1.70 -
    1.71 -static Uint8   *mixbuff               = NULL;
    1.72 -static int      next_buffer           = 0;
    1.73 -static Uint8   *pmixbuff[NUM_BUFFERS];
    1.74 -
    1.75 -static SDL_sem *playsem               = NULL;
    1.76 -#if 0
    1.77 -static SDL_sem *recsem                = NULL;
    1.78 -#endif
    1.79 -
    1.80 -//static SDL_AudioDevice* audioDevice = NULL;
    1.81 +// static SDL_AudioDevice* audioDevice = NULL;
    1.82  
    1.83  #if 0
    1.84  static const char *sldevaudiorecorderstr = "SLES Audio Recorder";
    1.85 @@ -104,16 +93,16 @@
    1.86  }
    1.87  #endif
    1.88  
    1.89 -static void openslES_DestroyEngine(void);
    1.90 +static void openslES_DestroyEngine();
    1.91  
    1.92  static int
    1.93 -openslES_CreateEngine(void)
    1.94 +openslES_CreateEngine()
    1.95  {
    1.96      SLresult result;
    1.97  
    1.98      LOGI("openSLES_CreateEngine()");
    1.99  
   1.100 -    // create engine
   1.101 +    /* create engine */
   1.102      result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
   1.103      if (SL_RESULT_SUCCESS != result) {
   1.104          LOGE("slCreateEngine failed");
   1.105 @@ -122,7 +111,7 @@
   1.106  
   1.107      LOGI("slCreateEngine OK");
   1.108  
   1.109 -    // realize the engine
   1.110 +    /* realize the engine */
   1.111      result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
   1.112      if (SL_RESULT_SUCCESS != result) {
   1.113          LOGE("RealizeEngine failed");
   1.114 @@ -131,7 +120,7 @@
   1.115  
   1.116      LOGI("RealizeEngine OK");
   1.117  
   1.118 -    // get the engine interface, which is needed in order to create other objects
   1.119 +    /* get the engine interface, which is needed in order to create other objects */
   1.120      result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
   1.121      if (SL_RESULT_SUCCESS != result) {
   1.122          LOGE("EngineGetInterface failed");
   1.123 @@ -140,9 +129,9 @@
   1.124  
   1.125      LOGI("EngineGetInterface OK");
   1.126  
   1.127 -    // create output mix, with environmental reverb specified as a non-required interface
   1.128 -    // const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
   1.129 -    // const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.130 +    /* create output mix, with environmental reverb specified as a non-required interface */
   1.131 +    /* const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB }; */
   1.132 +    /* const SLboolean req[1] = { SL_BOOLEAN_FALSE }; */
   1.133  
   1.134      const SLInterfaceID ids[1] = { SL_IID_VOLUME };
   1.135      const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.136 @@ -154,7 +143,7 @@
   1.137      }
   1.138      LOGI("CreateOutputMix OK");
   1.139  
   1.140 -    // realize the output mix
   1.141 +    /* realize the output mix */
   1.142      result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
   1.143      if (SL_RESULT_SUCCESS != result) {
   1.144          LOGE("RealizeOutputMix failed");
   1.145 @@ -167,23 +156,24 @@
   1.146      return 0;
   1.147  }
   1.148  
   1.149 -static void openslES_DestroyPCMPlayer(void);
   1.150 -static void openslES_DestroyPCMRecorder(void);
   1.151 +static void openslES_DestroyPCMPlayer(_THIS);
   1.152 +static void openslES_DestroyPCMRecorder(_THIS);
   1.153  
   1.154 -static void openslES_DestroyEngine(void)
   1.155 +static void openslES_DestroyEngine()
   1.156  {
   1.157      LOGI("openslES_DestroyEngine()");
   1.158 -    openslES_DestroyPCMPlayer();
   1.159 -    openslES_DestroyPCMRecorder();
   1.160 +   
   1.161 +//        openslES_DestroyPCMPlayer(this);
   1.162 +//    openslES_DestroyPCMRecorder(this);
   1.163  
   1.164 -    // destroy output mix object, and invalidate all associated interfaces
   1.165 +    /* destroy output mix object, and invalidate all associated interfaces */
   1.166      if (outputMixObject != NULL) {
   1.167          (*outputMixObject)->Destroy(outputMixObject);
   1.168          outputMixObject = NULL;
   1.169 -        // outputMixEnvironmentalReverb = NULL;
   1.170 +        /* outputMixEnvironmentalReverb = NULL; */
   1.171      }
   1.172  
   1.173 -    // destroy engine object, and invalidate all associated interfaces
   1.174 +    /* destroy engine object, and invalidate all associated interfaces */
   1.175      if (engineObject != NULL) {
   1.176          (*engineObject)->Destroy(engineObject);
   1.177          engineObject = NULL;
   1.178 @@ -193,56 +183,63 @@
   1.179      return;
   1.180  }
   1.181  
   1.182 -// this callback handler is called every time a buffer finishes playing
   1.183 +/* this callback handler is called every time a buffer finishes playing */
   1.184  static void
   1.185  bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
   1.186  {
   1.187 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context;
   1.188      static int t = 0;
   1.189  
   1.190 -    // assert(bq == bqPlayerBufferQueue);
   1.191 -    // assert(NULL == context);
   1.192 +    /* assert(bq == bqPlayerBufferQueue); */
   1.193 +    /* assert(NULL == context); */
   1.194  
   1.195 -    // for streaming playback, replace this test by logic to find and fill the next buffer
   1.196 +    /* for streaming playback, replace this test by logic to find and fill the next buffer */
   1.197  #if 0
   1.198      if (--nextCount > 0 && NULL != nextBuffer && 0 != nextSize)
   1.199      {
   1.200          SLresult result;
   1.201  
   1.202 -        // enqueue another buffer
   1.203 +        /* enqueue another buffer */
   1.204          result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize);
   1.205 -        // the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
   1.206 -        // which for this code example would indicate a programming error
   1.207 +        /* the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT, */
   1.208 +        /* which for this code example would indicate a programming error */
   1.209          assert(SL_RESULT_SUCCESS == result);
   1.210          (void) result;
   1.211      }
   1.212  #endif
   1.213      LOGI("SLES: Playback Callmeback %u", t++);
   1.214 -    SDL_SemPost(playsem);
   1.215 +    SDL_SemPost(audiodata->playsem);
   1.216      return;
   1.217  }
   1.218  
   1.219  static int
   1.220  openslES_CreatePCMRecorder(_THIS)
   1.221  {
   1.222 +/*    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; */
   1.223 +
   1.224      LOGE("openslES_CreatePCMRecorder not implimented yet!");
   1.225      return SDL_SetError("openslES_CreatePCMRecorder not implimented yet!");
   1.226  }
   1.227  
   1.228  static void
   1.229 -openslES_DestroyPCMRecorder(void)
   1.230 +openslES_DestroyPCMRecorder(_THIS)
   1.231  {
   1.232 +/*    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; */
   1.233 +
   1.234      return;
   1.235  }
   1.236  
   1.237  static int
   1.238  openslES_CreatePCMPlayer(_THIS)
   1.239  {
   1.240 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
   1.241 +
   1.242      SLDataFormat_PCM format_pcm;
   1.243  
   1.244      SLresult result;
   1.245      int i;
   1.246  
   1.247 -    /*
   1.248 +#if 0
   1.249        SDL_AudioFormat test_format;
   1.250        test_format = SDL_FirstAudioFormat( this->spec.format );
   1.251  
   1.252 @@ -255,28 +252,28 @@
   1.253        }
   1.254  
   1.255        if ( test_format == 0 ) {
   1.256 -          // Didn't find a compatible format :
   1.257 +          /* Didn't find a compatible format : */
   1.258            LOGI( "No compatible audio format!" );
   1.259            return SDL_SetError("No compatible audio format!");
   1.260        }
   1.261  
   1.262        this->spec.format = test_format;
   1.263 -    */
   1.264 +#endif
   1.265  
   1.266 -    // Update the fragment size as size in bytes
   1.267 +    /* Update the fragment size as size in bytes */
   1.268      SDL_CalculateAudioSpec(&this->spec);
   1.269  
   1.270      LOGI("Try to open %u hz %u bit chan %u %s samples %u",
   1.271            this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
   1.272            this->spec.channels, (test_format & 0x1000) ? "BE" : "LE", this->spec.samples);
   1.273  
   1.274 -    // configure audio source
   1.275 +    /* configure audio source */
   1.276      SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 };
   1.277 -    // SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS };
   1.278 +    /* SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS }; */
   1.279  
   1.280      format_pcm.formatType    = SL_DATAFORMAT_PCM;
   1.281      format_pcm.numChannels   = this->spec.channels;
   1.282 -    format_pcm.samplesPerSec = this->spec.freq * 1000;  // / kilo Hz to milli Hz
   1.283 +    format_pcm.samplesPerSec = this->spec.freq * 1000;  /* / kilo Hz to milli Hz */
   1.284      format_pcm.bitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
   1.285      format_pcm.containerSize = SDL_AUDIO_BITSIZE(this->spec.format);
   1.286  
   1.287 @@ -323,11 +320,11 @@
   1.288  
   1.289      SLDataSource audioSrc = { &loc_bufq, &format_pcm };
   1.290  
   1.291 -    // configure audio sink
   1.292 +    /* configure audio sink */
   1.293      SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, outputMixObject };
   1.294      SLDataSink audioSnk = { &loc_outmix, NULL };
   1.295  
   1.296 -    // create audio player
   1.297 +    /* create audio player */
   1.298      const SLInterfaceID ids[2] = {
   1.299          SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
   1.300          SL_IID_VOLUME
   1.301 @@ -344,36 +341,37 @@
   1.302          goto failed;
   1.303      }
   1.304  
   1.305 -    // realize the player
   1.306 +    /* realize the player */
   1.307      result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
   1.308      if (SL_RESULT_SUCCESS != result) {
   1.309          LOGE("RealizeAudioPlayer failed");
   1.310          goto failed;
   1.311      }
   1.312  
   1.313 -    // get the play interface
   1.314 +    /* get the play interface */
   1.315      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
   1.316      if (SL_RESULT_SUCCESS != result) {
   1.317          LOGE("SL_IID_PLAY interface get failed");
   1.318          goto failed;
   1.319      }
   1.320  
   1.321 -    // get the buffer queue interface
   1.322 +    /* get the buffer queue interface */
   1.323      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue);
   1.324      if (SL_RESULT_SUCCESS != result) {
   1.325          LOGE("SL_IID_BUFFERQUEUE interface get failed");
   1.326          goto failed;
   1.327      }
   1.328  
   1.329 -    // register callback on the buffer queue
   1.330 -    result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);
   1.331 +    /* register callback on the buffer queue */
   1.332 +    /* context is '(SDL_PrivateAudioData *)this->hidden' */
   1.333 +    result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, this->hidden);
   1.334      if (SL_RESULT_SUCCESS != result) {
   1.335          LOGE("RegisterCallback failed");
   1.336          goto failed;
   1.337      }
   1.338  
   1.339  #if 0
   1.340 -    // get the effect send interface
   1.341 +    /* get the effect send interface */
   1.342      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend);
   1.343      if (SL_RESULT_SUCCESS != result)
   1.344      {
   1.345 @@ -383,21 +381,21 @@
   1.346      }
   1.347  #endif
   1.348  
   1.349 -#if 0   // mute/solo is not supported for sources that are known to be mono, as this is
   1.350 -    // get the mute/solo interface
   1.351 +#if 0   /* mute/solo is not supported for sources that are known to be mono, as this is */
   1.352 +    /* get the mute/solo interface */
   1.353      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_MUTESOLO, &bqPlayerMuteSolo);
   1.354      assert(SL_RESULT_SUCCESS == result);
   1.355      (void) result;
   1.356  #endif
   1.357  
   1.358 -    // get the volume interface
   1.359 +    /* get the volume interface */
   1.360      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume);
   1.361      if (SL_RESULT_SUCCESS != result) {
   1.362          LOGE("SL_IID_VOLUME interface get failed");
   1.363 -        // goto failed;
   1.364 +        /* goto failed; */
   1.365      }
   1.366  
   1.367 -    // set the player's state to playing
   1.368 +    /* set the player's state to playing */
   1.369      result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
   1.370      if (SL_RESULT_SUCCESS != result) {
   1.371          LOGE("Play set state failed");
   1.372 @@ -405,36 +403,38 @@
   1.373      }
   1.374  
   1.375      /* Create the audio buffer semaphore */
   1.376 -    playsem = SDL_CreateSemaphore(NUM_BUFFERS - 1);
   1.377 -    if (!playsem) {
   1.378 +    audiodata->playsem = SDL_CreateSemaphore(NUM_BUFFERS - 1);
   1.379 +    if (!audiodata->playsem) {
   1.380          LOGE("cannot create Semaphore!");
   1.381          goto failed;
   1.382      }
   1.383  
   1.384      /* Create the sound buffers */
   1.385 -    mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
   1.386 -    if (mixbuff == NULL) {
   1.387 +    audiodata->mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
   1.388 +    if (audiodata->mixbuff == NULL) {
   1.389          LOGE("mixbuffer allocate - out of memory");
   1.390          goto failed;
   1.391      }
   1.392  
   1.393      for (i = 0; i < NUM_BUFFERS; i++) {
   1.394 -        pmixbuff[i] = mixbuff + i * this->spec.size;
   1.395 +        audiodata->pmixbuff[i] = audiodata->mixbuff + i * this->spec.size;
   1.396      }
   1.397  
   1.398      return 0;
   1.399  
   1.400  failed:
   1.401  
   1.402 -    openslES_DestroyPCMPlayer();
   1.403 +    openslES_DestroyPCMPlayer(this);
   1.404  
   1.405      return SDL_SetError("Open device failed!");
   1.406  }
   1.407  
   1.408  static void
   1.409 -openslES_DestroyPCMPlayer(void)
   1.410 +openslES_DestroyPCMPlayer(_THIS)
   1.411  {
   1.412 -    // destroy buffer queue audio player object, and invalidate all associated interfaces
   1.413 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
   1.414 +
   1.415 +    /* destroy buffer queue audio player object, and invalidate all associated interfaces */
   1.416      if (bqPlayerObject != NULL) {
   1.417  
   1.418          (*bqPlayerObject)->Destroy(bqPlayerObject);
   1.419 @@ -442,18 +442,18 @@
   1.420          bqPlayerObject = NULL;
   1.421          bqPlayerPlay = NULL;
   1.422          bqPlayerBufferQueue = NULL;
   1.423 -        // bqPlayerEffectSend = NULL;
   1.424 +        /* bqPlayerEffectSend = NULL; */
   1.425          bqPlayerMuteSolo = NULL;
   1.426          bqPlayerVolume = NULL;
   1.427      }
   1.428  
   1.429 -    if (playsem) {
   1.430 -        SDL_DestroySemaphore(playsem);
   1.431 -        playsem = NULL;
   1.432 +    if (audiodata->playsem) {
   1.433 +        SDL_DestroySemaphore(audiodata->playsem);
   1.434 +        audiodata->playsem = NULL;
   1.435      }
   1.436  
   1.437 -    if (mixbuff) {
   1.438 -        SDL_free(mixbuff);
   1.439 +    if (audiodata->mixbuff) {
   1.440 +        SDL_free(audiodata->mixbuff);
   1.441      }
   1.442  
   1.443      return;
   1.444 @@ -479,15 +479,16 @@
   1.445  static void
   1.446  openslES_CloseDevice(_THIS)
   1.447  {
   1.448 +    /* struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden; */
   1.449 +
   1.450      if (this->iscapture) {
   1.451          LOGI("openslES_CloseDevice( ) for capture");
   1.452 -        openslES_DestroyPCMRecorder();
   1.453 +        openslES_DestroyPCMRecorder(this);
   1.454      } else {
   1.455          LOGI("openslES_CloseDevice( ) for playing");
   1.456 -        SDL_Log("openslES_CloseDevice( ) for playing");
   1.457 -        openslES_DestroyPCMPlayer();
   1.458 +        openslES_DestroyPCMPlayer(this);
   1.459      }
   1.460 -
   1.461 +    
   1.462      SDL_free(this->hidden);
   1.463  
   1.464      return;
   1.465 @@ -496,51 +497,56 @@
   1.466  static void
   1.467  openslES_WaitDevice(_THIS)
   1.468  {
   1.469 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
   1.470 +
   1.471      LOGI("openslES_WaitDevice( )");
   1.472  
   1.473      /* Wait for an audio chunk to finish */
   1.474 -    // WaitForSingleObject(this->hidden->audio_sem, INFINITE);
   1.475 -    SDL_SemWait(playsem);
   1.476 +    /* WaitForSingleObject(this->hidden->audio_sem, INFINITE); */
   1.477 +    SDL_SemWait(audiodata->playsem);
   1.478  
   1.479      return;
   1.480  }
   1.481  
   1.482 -///           n   playn sem
   1.483 -// getbuf     0   -     1
   1.484 -// fill buff  0   -     1
   1.485 -// play       0 - 0     1
   1.486 -// wait       1   0     0
   1.487 -// getbuf     1   0     0
   1.488 -// fill buff  1   0     0
   1.489 -// play       0   0     0
   1.490 -// wait
   1.491 -//
   1.492 -// okay..
   1.493 +/*/           n   playn sem */
   1.494 +/* getbuf     0   -     1 */
   1.495 +/* fill buff  0   -     1 */
   1.496 +/* play       0 - 0     1 */
   1.497 +/* wait       1   0     0 */
   1.498 +/* getbuf     1   0     0 */
   1.499 +/* fill buff  1   0     0 */
   1.500 +/* play       0   0     0 */
   1.501 +/* wait */
   1.502 +/* */
   1.503 +/* okay.. */
   1.504  
   1.505  static Uint8 *
   1.506  openslES_GetDeviceBuf(_THIS)
   1.507  {
   1.508 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
   1.509 +
   1.510      LOGI("openslES_GetDeviceBuf( )");
   1.511 -    return pmixbuff[next_buffer];
   1.512 +    return audiodata->pmixbuff[audiodata->next_buffer];
   1.513  }
   1.514  
   1.515  static void
   1.516  openslES_PlayDevice(_THIS)
   1.517  {
   1.518 +    struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
   1.519      SLresult result;
   1.520  
   1.521      LOGI("======openslES_PlayDevice( )======");
   1.522      /* Queue it up */
   1.523  
   1.524 -    result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, pmixbuff[next_buffer], this->spec.size);
   1.525 +    result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, audiodata->pmixbuff[audiodata->next_buffer], this->spec.size);
   1.526      if (SL_RESULT_SUCCESS != result) {
   1.527 -        // just puk here
   1.528 -        // next !
   1.529 +        /* just puk here */
   1.530 +        /* next ! */
   1.531      }
   1.532  
   1.533 -    next_buffer++;
   1.534 -    if (next_buffer >= NUM_BUFFERS) {
   1.535 -        next_buffer = 0;
   1.536 +    audiodata->next_buffer++;
   1.537 +    if (audiodata->next_buffer >= NUM_BUFFERS) {
   1.538 +        audiodata->next_buffer = 0;
   1.539      }
   1.540  
   1.541      return;
   1.542 @@ -558,7 +564,7 @@
   1.543      LOGI("openslES_Init() - set pointers");
   1.544  
   1.545      /* Set the function pointers */
   1.546 -    // impl->DetectDevices = openslES_DetectDevices;
   1.547 +    /* impl->DetectDevices = openslES_DetectDevices; */
   1.548      impl->OpenDevice    = openslES_OpenDevice;
   1.549      impl->CloseDevice   = openslES_CloseDevice;
   1.550      impl->PlayDevice    = openslES_PlayDevice;
   1.551 @@ -569,7 +575,7 @@
   1.552      /* and the capabilities */
   1.553      impl->HasCaptureSupport             = 0;        /* TODO */
   1.554      impl->OnlyHasDefaultOutputDevice    = 1;
   1.555 -    // impl->OnlyHasDefaultInputDevice  = 1;
   1.556 +    /* impl->OnlyHasDefaultInputDevice  = 1; */
   1.557  
   1.558      LOGI("openslES_Init() - succes");
   1.559  
     2.1 --- a/src/audio/openslES/SDL_openslES.h	Mon Jan 14 10:16:26 2019 +0100
     2.2 +++ b/src/audio/openslES/SDL_openslES.h	Mon Jan 14 10:58:57 2019 +0100
     2.3 @@ -28,13 +28,18 @@
     2.4  /* Hidden "this" pointer for the audio functions */
     2.5  #define _THIS   SDL_AudioDevice *this
     2.6  
     2.7 +#define NUM_BUFFERS 2           /* -- Don't lower this! */
     2.8 +
     2.9  struct SDL_PrivateAudioData
    2.10  {
    2.11      /* The file descriptor for the audio device */
    2.12 -    Uint8 *mixbuf;
    2.13 -    Uint32 mixlen;
    2.14 -    Uint32 write_delay;
    2.15 -    Uint32 initial_calls;
    2.16 +    Uint8   *mixbuff;
    2.17 +    int      next_buffer;
    2.18 +    Uint8   *pmixbuff[NUM_BUFFERS];
    2.19 +    SDL_sem *playsem;
    2.20 +#if 0
    2.21 +    SDL_sem *recsem;
    2.22 +#endif
    2.23  };
    2.24  
    2.25  #endif /* _SDL_openslesaudio_h */