Minor cleanups in PulseAudio code, to keep this 80-column-friendly.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 17 Jan 2010 06:51:31 +0000
changeset 36747b597182d06b
parent 3673 c9d5bd1b4e18
child 3675 e86edac50872
Minor cleanups in PulseAudio code, to keep this 80-column-friendly.
src/audio/pulseaudio/SDL_pulseaudio.c
     1.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Sun Jan 17 06:43:28 2010 +0000
     1.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Sun Jan 17 06:51:31 2010 +0000
     1.3 @@ -212,14 +212,16 @@
     1.4  static void
     1.5  PULSEAUDIO_WaitDevice(_THIS)
     1.6  {
     1.7 +    struct SDL_PrivateAudioData *h = this->hidden;
     1.8 +
     1.9      while(1) {
    1.10 -        if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
    1.11 -            PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
    1.12 -            PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
    1.13 +        if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
    1.14 +            PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
    1.15 +            PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
    1.16              this->enabled = 0;
    1.17              return;
    1.18          }
    1.19 -        if (PULSEAUDIO_pa_stream_writable_size(this->hidden->stream) >= this->hidden->mixlen) {
    1.20 +        if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= h->mixlen) {
    1.21              return;
    1.22          }
    1.23      }
    1.24 @@ -229,8 +231,8 @@
    1.25  PULSEAUDIO_PlayDevice(_THIS)
    1.26  {
    1.27      /* Write the audio data */
    1.28 -    if (PULSEAUDIO_pa_stream_write(this->hidden->stream, this->hidden->mixbuf,
    1.29 -                                   this->hidden->mixlen, NULL, 0LL,
    1.30 +    struct SDL_PrivateAudioData *h = this->hidden;
    1.31 +    if (PULSEAUDIO_pa_stream_write(h->stream, h->mixbuf, h->mixlen, NULL, 0LL,
    1.32                                     PA_SEEK_RELATIVE) < 0) {
    1.33          this->enabled = 0;
    1.34      }
    1.35 @@ -245,17 +247,18 @@
    1.36  static void
    1.37  PULSEAUDIO_WaitDone(_THIS)
    1.38  {
    1.39 +    struct SDL_PrivateAudioData *h = this->hidden;
    1.40      pa_operation *o;
    1.41  
    1.42 -    o = PULSEAUDIO_pa_stream_drain(this->hidden->stream, stream_drain_complete, NULL);
    1.43 +    o = PULSEAUDIO_pa_stream_drain(h->stream, stream_drain_complete, NULL);
    1.44      if (!o) {
    1.45          return;
    1.46      }
    1.47  
    1.48      while (PULSEAUDIO_pa_operation_get_state(o) != PA_OPERATION_DONE) {
    1.49 -        if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
    1.50 -            PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
    1.51 -            PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
    1.52 +        if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
    1.53 +            PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
    1.54 +            PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
    1.55              PULSEAUDIO_pa_operation_cancel(o);
    1.56              break;
    1.57          }
    1.58 @@ -336,6 +339,7 @@
    1.59  static int
    1.60  PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
    1.61  {
    1.62 +    struct SDL_PrivateAudioData *h = NULL;
    1.63      Uint16 test_format = 0;
    1.64      pa_sample_spec paspec;
    1.65      pa_buffer_attr paattr;
    1.66 @@ -351,6 +355,7 @@
    1.67          return 0;
    1.68      }
    1.69      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.70 +    h = this->hidden;
    1.71  
    1.72      paspec.format = PA_SAMPLE_INVALID;
    1.73  
    1.74 @@ -392,31 +397,32 @@
    1.75      SDL_CalculateAudioSpec(&this->spec);
    1.76  
    1.77      /* Allocate mixing buffer */
    1.78 -    this->hidden->mixlen = this->spec.size;
    1.79 -    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
    1.80 -    if (this->hidden->mixbuf == NULL) {
    1.81 +    h->mixlen = this->spec.size;
    1.82 +    h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
    1.83 +    if (h->mixbuf == NULL) {
    1.84          PULSEAUDIO_CloseDevice(this);
    1.85          SDL_OutOfMemory();
    1.86          return 0;
    1.87      }
    1.88 -    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
    1.89 +    SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
    1.90  
    1.91      paspec.channels = this->spec.channels;
    1.92      paspec.rate = this->spec.freq;
    1.93  
    1.94      /* Reduced prebuffering compared to the defaults. */
    1.95  #ifdef PA_STREAM_ADJUST_LATENCY
    1.96 -    paattr.tlength = this->hidden->mixlen * 4; /* 2x original requested bufsize */
    1.97 +    /* 2x original requested bufsize */
    1.98 +    paattr.tlength = h->mixlen * 4;
    1.99      paattr.prebuf = -1;
   1.100      paattr.maxlength = -1;
   1.101 -    /* -1 can lead to pa_stream_writable_size() >= this->hidden->mixlen never being true */
   1.102 -    paattr.minreq = this->hidden->mixlen;
   1.103 +    /* -1 can lead to pa_stream_writable_size() >= mixlen never being true */
   1.104 +    paattr.minreq = h->mixlen;
   1.105      flags = PA_STREAM_ADJUST_LATENCY;
   1.106  #else
   1.107 -    paattr.tlength = this->hidden->mixlen*2;
   1.108 -    paattr.prebuf = this->hidden->mixlen*2;
   1.109 -    paattr.maxlength = this->hidden->mixlen*2;
   1.110 -    paattr.minreq = this->hidden->mixlen;
   1.111 +    paattr.tlength = h->mixlen*2;
   1.112 +    paattr.prebuf = h->mixlen*2;
   1.113 +    paattr.maxlength = h->mixlen*2;
   1.114 +    paattr.minreq = h->mixlen;
   1.115  #endif
   1.116  
   1.117      /* The SDL ALSA output hints us that we use Windows' channel mapping */
   1.118 @@ -425,33 +431,34 @@
   1.119                                          PA_CHANNEL_MAP_WAVEEX);
   1.120  
   1.121      /* Set up a new main loop */
   1.122 -    if (!(this->hidden->mainloop = PULSEAUDIO_pa_mainloop_new())) {
   1.123 +    if (!(h->mainloop = PULSEAUDIO_pa_mainloop_new())) {
   1.124          PULSEAUDIO_CloseDevice(this);
   1.125          SDL_SetError("pa_mainloop_new() failed");
   1.126          return 0;
   1.127      }
   1.128  
   1.129 -    this->hidden->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(this->hidden->mainloop);
   1.130 -    if (!(this->hidden->context = PULSEAUDIO_pa_context_new(this->hidden->mainloop_api, get_progname()))) {
   1.131 +    h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop);
   1.132 +    h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, get_progname());
   1.133 +    if (!h->context) {
   1.134          PULSEAUDIO_CloseDevice(this);
   1.135          SDL_SetError("pa_context_new() failed");
   1.136          return 0;
   1.137      }
   1.138  
   1.139      /* Connect to the PulseAudio server */
   1.140 -    if (PULSEAUDIO_pa_context_connect(this->hidden->context, NULL, 0, NULL) < 0) {
   1.141 +    if (PULSEAUDIO_pa_context_connect(h->context, NULL, 0, NULL) < 0) {
   1.142          PULSEAUDIO_CloseDevice(this);
   1.143          SDL_SetError("Could not setup connection to PulseAudio");
   1.144          return 0;
   1.145      }
   1.146  
   1.147      do {
   1.148 -        if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
   1.149 +        if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
   1.150              PULSEAUDIO_CloseDevice(this);
   1.151              SDL_SetError("pa_mainloop_iterate() failed");
   1.152              return 0;
   1.153          }
   1.154 -        state = PULSEAUDIO_pa_context_get_state(this->hidden->context);
   1.155 +        state = PULSEAUDIO_pa_context_get_state(h->context);
   1.156          if (!PA_CONTEXT_IS_GOOD(state)) {
   1.157              PULSEAUDIO_CloseDevice(this);
   1.158              SDL_SetError("Could not connect to PulseAudio");
   1.159 @@ -459,20 +466,20 @@
   1.160          }
   1.161      } while (state != PA_CONTEXT_READY);
   1.162  
   1.163 -    this->hidden->stream = PULSEAUDIO_pa_stream_new(
   1.164 -        this->hidden->context,
   1.165 +    h->stream = PULSEAUDIO_pa_stream_new(
   1.166 +        h->context,
   1.167          "Simple DirectMedia Layer", /* stream description */
   1.168          &paspec,    /* sample format spec */
   1.169          &pacmap     /* channel map */
   1.170          );
   1.171  
   1.172 -    if (this->hidden->stream == NULL) {
   1.173 +    if (h->stream == NULL) {
   1.174          PULSEAUDIO_CloseDevice(this);
   1.175          SDL_SetError("Could not set up PulseAudio stream");
   1.176          return 0;
   1.177      }
   1.178  
   1.179 -    if (PULSEAUDIO_pa_stream_connect_playback(this->hidden->stream, NULL, &paattr, flags,
   1.180 +    if (PULSEAUDIO_pa_stream_connect_playback(h->stream, NULL, &paattr, flags,
   1.181              NULL, NULL) < 0) {
   1.182          PULSEAUDIO_CloseDevice(this);
   1.183          SDL_SetError("Could not connect PulseAudio stream");
   1.184 @@ -480,12 +487,12 @@
   1.185      }
   1.186  
   1.187      do {
   1.188 -        if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
   1.189 +        if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
   1.190              PULSEAUDIO_CloseDevice(this);
   1.191              SDL_SetError("pa_mainloop_iterate() failed");
   1.192              return 0;
   1.193          }
   1.194 -        state = PULSEAUDIO_pa_stream_get_state(this->hidden->stream);
   1.195 +        state = PULSEAUDIO_pa_stream_get_state(h->stream);
   1.196          if (!PA_STREAM_IS_GOOD(state)) {
   1.197              PULSEAUDIO_CloseDevice(this);
   1.198              SDL_SetError("Could not create to PulseAudio stream");