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 3674 7b597182d06b
parent 3673 c9d5bd1b4e18
child 3675 e86edac50872
Minor cleanups in PulseAudio code, to keep this 80-column-friendly.
src/audio/pulseaudio/SDL_pulseaudio.c
--- a/src/audio/pulseaudio/SDL_pulseaudio.c	Sun Jan 17 06:43:28 2010 +0000
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Sun Jan 17 06:51:31 2010 +0000
@@ -212,14 +212,16 @@
 static void
 PULSEAUDIO_WaitDevice(_THIS)
 {
+    struct SDL_PrivateAudioData *h = this->hidden;
+
     while(1) {
-        if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
-            PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
-            PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
+        if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
+            PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
+            PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
             this->enabled = 0;
             return;
         }
-        if (PULSEAUDIO_pa_stream_writable_size(this->hidden->stream) >= this->hidden->mixlen) {
+        if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= h->mixlen) {
             return;
         }
     }
@@ -229,8 +231,8 @@
 PULSEAUDIO_PlayDevice(_THIS)
 {
     /* Write the audio data */
-    if (PULSEAUDIO_pa_stream_write(this->hidden->stream, this->hidden->mixbuf,
-                                   this->hidden->mixlen, NULL, 0LL,
+    struct SDL_PrivateAudioData *h = this->hidden;
+    if (PULSEAUDIO_pa_stream_write(h->stream, h->mixbuf, h->mixlen, NULL, 0LL,
                                    PA_SEEK_RELATIVE) < 0) {
         this->enabled = 0;
     }
@@ -245,17 +247,18 @@
 static void
 PULSEAUDIO_WaitDone(_THIS)
 {
+    struct SDL_PrivateAudioData *h = this->hidden;
     pa_operation *o;
 
-    o = PULSEAUDIO_pa_stream_drain(this->hidden->stream, stream_drain_complete, NULL);
+    o = PULSEAUDIO_pa_stream_drain(h->stream, stream_drain_complete, NULL);
     if (!o) {
         return;
     }
 
     while (PULSEAUDIO_pa_operation_get_state(o) != PA_OPERATION_DONE) {
-        if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
-            PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
-            PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
+        if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
+            PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
+            PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
             PULSEAUDIO_pa_operation_cancel(o);
             break;
         }
@@ -336,6 +339,7 @@
 static int
 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 {
+    struct SDL_PrivateAudioData *h = NULL;
     Uint16 test_format = 0;
     pa_sample_spec paspec;
     pa_buffer_attr paattr;
@@ -351,6 +355,7 @@
         return 0;
     }
     SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+    h = this->hidden;
 
     paspec.format = PA_SAMPLE_INVALID;
 
@@ -392,31 +397,32 @@
     SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate mixing buffer */
-    this->hidden->mixlen = this->spec.size;
-    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
-    if (this->hidden->mixbuf == NULL) {
+    h->mixlen = this->spec.size;
+    h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
+    if (h->mixbuf == NULL) {
         PULSEAUDIO_CloseDevice(this);
         SDL_OutOfMemory();
         return 0;
     }
-    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+    SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
 
     paspec.channels = this->spec.channels;
     paspec.rate = this->spec.freq;
 
     /* Reduced prebuffering compared to the defaults. */
 #ifdef PA_STREAM_ADJUST_LATENCY
-    paattr.tlength = this->hidden->mixlen * 4; /* 2x original requested bufsize */
+    /* 2x original requested bufsize */
+    paattr.tlength = h->mixlen * 4;
     paattr.prebuf = -1;
     paattr.maxlength = -1;
-    /* -1 can lead to pa_stream_writable_size() >= this->hidden->mixlen never being true */
-    paattr.minreq = this->hidden->mixlen;
+    /* -1 can lead to pa_stream_writable_size() >= mixlen never being true */
+    paattr.minreq = h->mixlen;
     flags = PA_STREAM_ADJUST_LATENCY;
 #else
-    paattr.tlength = this->hidden->mixlen*2;
-    paattr.prebuf = this->hidden->mixlen*2;
-    paattr.maxlength = this->hidden->mixlen*2;
-    paattr.minreq = this->hidden->mixlen;
+    paattr.tlength = h->mixlen*2;
+    paattr.prebuf = h->mixlen*2;
+    paattr.maxlength = h->mixlen*2;
+    paattr.minreq = h->mixlen;
 #endif
 
     /* The SDL ALSA output hints us that we use Windows' channel mapping */
@@ -425,33 +431,34 @@
                                         PA_CHANNEL_MAP_WAVEEX);
 
     /* Set up a new main loop */
-    if (!(this->hidden->mainloop = PULSEAUDIO_pa_mainloop_new())) {
+    if (!(h->mainloop = PULSEAUDIO_pa_mainloop_new())) {
         PULSEAUDIO_CloseDevice(this);
         SDL_SetError("pa_mainloop_new() failed");
         return 0;
     }
 
-    this->hidden->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(this->hidden->mainloop);
-    if (!(this->hidden->context = PULSEAUDIO_pa_context_new(this->hidden->mainloop_api, get_progname()))) {
+    h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop);
+    h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, get_progname());
+    if (!h->context) {
         PULSEAUDIO_CloseDevice(this);
         SDL_SetError("pa_context_new() failed");
         return 0;
     }
 
     /* Connect to the PulseAudio server */
-    if (PULSEAUDIO_pa_context_connect(this->hidden->context, NULL, 0, NULL) < 0) {
+    if (PULSEAUDIO_pa_context_connect(h->context, NULL, 0, NULL) < 0) {
         PULSEAUDIO_CloseDevice(this);
         SDL_SetError("Could not setup connection to PulseAudio");
         return 0;
     }
 
     do {
-        if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
+        if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
             PULSEAUDIO_CloseDevice(this);
             SDL_SetError("pa_mainloop_iterate() failed");
             return 0;
         }
-        state = PULSEAUDIO_pa_context_get_state(this->hidden->context);
+        state = PULSEAUDIO_pa_context_get_state(h->context);
         if (!PA_CONTEXT_IS_GOOD(state)) {
             PULSEAUDIO_CloseDevice(this);
             SDL_SetError("Could not connect to PulseAudio");
@@ -459,20 +466,20 @@
         }
     } while (state != PA_CONTEXT_READY);
 
-    this->hidden->stream = PULSEAUDIO_pa_stream_new(
-        this->hidden->context,
+    h->stream = PULSEAUDIO_pa_stream_new(
+        h->context,
         "Simple DirectMedia Layer", /* stream description */
         &paspec,    /* sample format spec */
         &pacmap     /* channel map */
         );
 
-    if (this->hidden->stream == NULL) {
+    if (h->stream == NULL) {
         PULSEAUDIO_CloseDevice(this);
         SDL_SetError("Could not set up PulseAudio stream");
         return 0;
     }
 
-    if (PULSEAUDIO_pa_stream_connect_playback(this->hidden->stream, NULL, &paattr, flags,
+    if (PULSEAUDIO_pa_stream_connect_playback(h->stream, NULL, &paattr, flags,
             NULL, NULL) < 0) {
         PULSEAUDIO_CloseDevice(this);
         SDL_SetError("Could not connect PulseAudio stream");
@@ -480,12 +487,12 @@
     }
 
     do {
-        if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
+        if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
             PULSEAUDIO_CloseDevice(this);
             SDL_SetError("pa_mainloop_iterate() failed");
             return 0;
         }
-        state = PULSEAUDIO_pa_stream_get_state(this->hidden->stream);
+        state = PULSEAUDIO_pa_stream_get_state(h->stream);
         if (!PA_STREAM_IS_GOOD(state)) {
             PULSEAUDIO_CloseDevice(this);
             SDL_SetError("Could not create to PulseAudio stream");