diff mbox

[v2,11/12] coreaudio: do not use global variables where possible

Message ID 932013ccc793ef14ae7f936d010d92c629eead4e.1433328036.git.DirtY.iCE.hu@gmail.com
State New
Headers show

Commit Message

=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= June 3, 2015, 10:49 a.m. UTC
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 audio/coreaudio.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

Comments

Peter Maydell June 3, 2015, 7:19 p.m. UTC | #1
On 3 June 2015 at 11:49, Kővágó, Zoltán <dirty.ice.hu@gmail.com> wrote:
> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
> ---
>  audio/coreaudio.c | 43 ++++++++++++++++++++++++-------------------
>  1 file changed, 24 insertions(+), 19 deletions(-)

> +static CoreaudioConf glob_conf = {
> +    .buffer_frames = 512,
> +    .nbuffers = 4,
> +};
> +
>  static void *coreaudio_audio_init (void)
>  {
> +    CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
> +    *conf = glob_conf;
> +
>      atexit(coreaudio_atexit);
> -    return &coreaudio_audio_init;
> +    return conf;
>  }
>
>  static void coreaudio_audio_fini (void *opaque)
>  {
> -    (void) opaque;
> +    g_free(opaque);
>  }
>
>  static struct audio_option coreaudio_options[] = {
>      {
>          .name  = "BUFFER_SIZE",
>          .tag   = AUD_OPT_INT,
> -        .valp  = &conf.buffer_frames,
> +        .valp  = &glob_conf.buffer_frames,
>          .descr = "Size of the buffer in frames"
>      },
>      {
>          .name  = "BUFFER_COUNT",
>          .tag   = AUD_OPT_INT,
> -        .valp  = &conf.nbuffers,
> +        .valp  = &glostconf.nbuffers,
>          .descr = "Number of buffers"
>      },

/Users/pm215/src/qemu/audio/coreaudio.c:529:19: error: use of
undeclared identifier 'glostconf'; did you mean 'glob_conf'?
        .valp  = &glostconf.nbuffers,
                  ^~~~~~~~~
                  glob_conf
/Users/pm215/src/qemu/audio/coreaudio.c:500:22: note: 'glob_conf' declared here
static CoreaudioConf glob_conf = {
                     ^
10 warnings and 1 error generated.

-- PMM
=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= June 3, 2015, 7:43 p.m. UTC | #2
2015-06-03 21:19 keltezéssel, Peter Maydell írta:
> On 3 June 2015 at 11:49, Kővágó, Zoltán <dirty.ice.hu@gmail.com> wrote:
>> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
>> ---
>>   audio/coreaudio.c | 43 ++++++++++++++++++++++++-------------------
>>   1 file changed, 24 insertions(+), 19 deletions(-)
>
>> +static CoreaudioConf glob_conf = {
>> +    .buffer_frames = 512,
>> +    .nbuffers = 4,
>> +};
>> +
>>   static void *coreaudio_audio_init (void)
>>   {
>> +    CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
>> +    *conf = glob_conf;
>> +
>>       atexit(coreaudio_atexit);
>> -    return &coreaudio_audio_init;
>> +    return conf;
>>   }
>>
>>   static void coreaudio_audio_fini (void *opaque)
>>   {
>> -    (void) opaque;
>> +    g_free(opaque);
>>   }
>>
>>   static struct audio_option coreaudio_options[] = {
>>       {
>>           .name  = "BUFFER_SIZE",
>>           .tag   = AUD_OPT_INT,
>> -        .valp  = &conf.buffer_frames,
>> +        .valp  = &glob_conf.buffer_frames,
>>           .descr = "Size of the buffer in frames"
>>       },
>>       {
>>           .name  = "BUFFER_COUNT",
>>           .tag   = AUD_OPT_INT,
>> -        .valp  = &conf.nbuffers,
>> +        .valp  = &glostconf.nbuffers,
>>           .descr = "Number of buffers"
>>       },
>
> /Users/pm215/src/qemu/audio/coreaudio.c:529:19: error: use of
> undeclared identifier 'glostconf'; did you mean 'glob_conf'?
>          .valp  = &glostconf.nbuffers,
>                    ^~~~~~~~~
>                    glob_conf
> /Users/pm215/src/qemu/audio/coreaudio.c:500:22: note: 'glob_conf' declared here
> static CoreaudioConf glob_conf = {
>                       ^
> 10 warnings and 1 error generated.

crap, i should used search & replace... does it work with glob_conf or 
there are other problems?

Thanks,
Zoltan
diff mbox

Patch

diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 20346bc..9f731b7 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -32,20 +32,16 @@ 
 #define AUDIO_CAP "coreaudio"
 #include "audio_int.h"
 
-struct {
+static int isAtexit;
+
+typedef struct {
     int buffer_frames;
     int nbuffers;
-    int isAtexit;
-} conf = {
-    .buffer_frames = 512,
-    .nbuffers = 4,
-    .isAtexit = 0
-};
+} CoreaudioConf;
 
 typedef struct coreaudioVoiceOut {
     HWVoiceOut hw;
     pthread_mutex_t mutex;
-    int isAtexit;
     AudioDeviceID outputDeviceID;
     UInt32 audioDevicePropertyBufferFrameSize;
     AudioStreamBasicDescription outputStreamBasicDescription;
@@ -161,7 +157,7 @@  static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
 
 static void coreaudio_atexit (void)
 {
-    conf.isAtexit = 1;
+    isAtexit = 1;
 }
 
 static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name)
@@ -296,6 +292,7 @@  static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
     int err;
     const char *typ = "playback";
     AudioValueRange frameRange;
+    CoreaudioConf *conf = drv_opaque;
 
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
@@ -337,16 +334,16 @@  static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    if (frameRange.mMinimum > conf.buffer_frames) {
+    if (frameRange.mMinimum > conf->buffer_frames) {
         core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
         dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
     }
-    else if (frameRange.mMaximum < conf.buffer_frames) {
+    else if (frameRange.mMaximum < conf->buffer_frames) {
         core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
         dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
     }
     else {
-        core->audioDevicePropertyBufferFrameSize = conf.buffer_frames;
+        core->audioDevicePropertyBufferFrameSize = conf->buffer_frames;
     }
 
     /* set Buffer Frame Size */
@@ -380,7 +377,7 @@  static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
                            "Could not get device buffer frame size\n");
         return -1;
     }
-    hw->samples = conf.nbuffers * core->audioDevicePropertyBufferFrameSize;
+    hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize;
 
     /* get StreamFormat */
     propertySize = sizeof(core->outputStreamBasicDescription);
@@ -444,7 +441,7 @@  static void coreaudio_fini_out (HWVoiceOut *hw)
     int err;
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 
-    if (!conf.isAtexit) {
+    if (!isAtexit) {
         /* stop playback */
         if (isPlaying(core->outputDeviceID)) {
             status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
@@ -487,7 +484,7 @@  static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
 
     case VOICE_DISABLE:
         /* stop playback */
-        if (!conf.isAtexit) {
+        if (!isAtexit) {
             if (isPlaying(core->outputDeviceID)) {
                 status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
                 if (status != kAudioHardwareNoError) {
@@ -500,28 +497,36 @@  static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
+static CoreaudioConf glob_conf = {
+    .buffer_frames = 512,
+    .nbuffers = 4,
+};
+
 static void *coreaudio_audio_init (void)
 {
+    CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
+    *conf = glob_conf;
+
     atexit(coreaudio_atexit);
-    return &coreaudio_audio_init;
+    return conf;
 }
 
 static void coreaudio_audio_fini (void *opaque)
 {
-    (void) opaque;
+    g_free(opaque);
 }
 
 static struct audio_option coreaudio_options[] = {
     {
         .name  = "BUFFER_SIZE",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.buffer_frames,
+        .valp  = &glob_conf.buffer_frames,
         .descr = "Size of the buffer in frames"
     },
     {
         .name  = "BUFFER_COUNT",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.nbuffers,
+        .valp  = &glostconf.nbuffers,
         .descr = "Number of buffers"
     },
     { /* End of list */ }