Skip to contentSkip to conversation

Audio backend cleanup

PATCH Superseded Kővágó, Zoltán 6 participants 26 messages Jun 1, 2015 – Jun 2, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Audio backend cleanup

This series of patch removes the following audio backends:
esd, fmod, sdl, winwave.

It also cleans up the remaining drivers to do not use global variables where possible. This is a preparation for my GSoC project where I will enable multiple simultaneous audio backends.

Please also test the coreaudio backend, as I do not have a Mac to test it.

Patches are also available at https://github.com/DirtYiCE/qemu.git in branch audio-cleanup to simplify testing.

Please review.

Kővágó, Zoltán (12):
audio: remove esd backend
audio: remove fmod backend
audio: remove sdl backend
audio: remove winwave audio driver
audio: expose drv_opaque to init_out and init_in
alsaaudio: do not use global variables
paaudio: do not use global variables
ossaudio: do not use global variables
wavaudio: do not use global variables
dsoundaudio: do not use global variables
paaudio: fix possible resource leak
coreaudio: do not use global variables where possible

 audio/Makefile.objs     |   7 -
 audio/alsaaudio.c       | 155 ++++++-----
 audio/audio_int.h       |   8 +-
 audio/audio_template.h  |   2 +-
 audio/coreaudio.c       |  46 ++--
 audio/dsound_template.h |  24 +-
 audio/dsoundaudio.c     | 106 ++++---
 audio/esdaudio.c        | 557 -------------------------------------
 audio/fmodaudio.c       | 685 ---------------------------------------------
 audio/noaudio.c         |   6 +-
 audio/ossaudio.c        | 115 ++++----
 audio/paaudio.c         | 105 +++----
 audio/sdlaudio.c        | 458 -------------------------------
 audio/spiceaudio.c      |   9 +-
 audio/wavaudio.c        |  41 +--
 audio/winwaveaudio.c    | 717 ------------------------------------------------
 configure               |  60 +---
 17 files changed, 360 insertions(+), 2741 deletions(-)
 delete mode 100644 audio/esdaudio.c
 delete mode 100644 audio/fmodaudio.c
 delete mode 100644 audio/sdlaudio.c
 delete mode 100644 audio/winwaveaudio.c
Signature · 1 line
2.4.2
#1 lore raw

PATCH 1/12 audio: remove esd backend

ESD is no longer developed and replaced by PulseAudio.

---
 audio/Makefile.objs |   1 -
 audio/audio_int.h   |   1 -
 audio/esdaudio.c    | 557 ----------------------------------------------------
 configure           |  18 +-
 4 files changed, 6 insertions(+), 571 deletions(-)
 delete mode 100644 audio/esdaudio.c
audio/Makefile.objs +0 -1
index 26a0ac9..5573ac1 100644
@@ -6,7 +6,6 @@ common-obj-$(CONFIG_COREAUDIO) += coreaudio.o
 common-obj-$(CONFIG_ALSA) += alsaaudio.o
 common-obj-$(CONFIG_DSOUND) += dsoundaudio.o
 common-obj-$(CONFIG_FMOD) += fmodaudio.o
-common-obj-$(CONFIG_ESD) += esdaudio.o
 common-obj-$(CONFIG_PA) += paaudio.o
 common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
 common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
audio/audio_int.h +0 -1
index fd019a0..9dd6b7f 100644
@@ -210,7 +210,6 @@ extern struct audio_driver fmod_audio_driver;
 extern struct audio_driver alsa_audio_driver;
 extern struct audio_driver coreaudio_audio_driver;
 extern struct audio_driver dsound_audio_driver;
-extern struct audio_driver esd_audio_driver;
 extern struct audio_driver pa_audio_driver;
 extern struct audio_driver spice_audio_driver;
 extern struct audio_driver winwave_audio_driver;
audio/esdaudio.c deleted +0 -557

557 lines not on this page · raw message

configure +6 -12
index 4e2f78a..acd471d 100755
@@ -575,13 +575,13 @@ MINGW32*)
 GNU/kFreeBSD)
   bsd="yes"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl esd pa"
+  audio_possible_drivers="oss sdl pa"
 ;;
 FreeBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl esd pa"
+  audio_possible_drivers="oss sdl pa"
   # needed for kinfo_getvmmap(3) in libutil.h
   LIBS="-lutil $LIBS"
   netmap=""  # enable netmap autodetect
@@ -591,14 +591,14 @@ DragonFly)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl esd pa"
+  audio_possible_drivers="oss sdl pa"
   HOST_VARIANT_DIR="dragonfly"
 ;;
 NetBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl esd"
+  audio_possible_drivers="oss sdl"
   oss_lib="-lossaudio"
   HOST_VARIANT_DIR="netbsd"
 ;;
@@ -606,7 +606,7 @@ OpenBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="sdl"
-  audio_possible_drivers="sdl esd"
+  audio_possible_drivers="sdl"
   HOST_VARIANT_DIR="openbsd"
 ;;
 Darwin)
@@ -674,7 +674,7 @@ Haiku)
 ;;
 *)
   audio_drv_list="oss"
-  audio_possible_drivers="oss alsa sdl esd pa"
+  audio_possible_drivers="oss alsa sdl pa"
   linux="yes"
   linux_user="yes"
   kvm="yes"
@@ -2630,12 +2630,6 @@ for drv in $audio_drv_list; do
     libs_softmmu="$fmod_lib $libs_softmmu"
     ;;
 
-    esd)
-    audio_drv_probe $drv esd.h -lesd 'return esd_play_stream(0, 0, "", 0);'
-    libs_softmmu="-lesd $libs_softmmu"
-    audio_pt_int="yes"
-    ;;
-
     pa)
     audio_drv_probe $drv pulse/mainloop.h "-lpulse" \
         "pa_mainloop *m = 0; pa_mainloop_free (m); return 0;"
Signature · 1 line
2.4.2
#2 lore raw

PATCH 2/12 audio: remove fmod backend

In reply to Kővágó, Zoltán
---
 audio/Makefile.objs |   2 -
 audio/audio_int.h   |   1 -
 audio/fmodaudio.c   | 685 ----------------------------------------------------
 configure           |  27 +--
 4 files changed, 2 insertions(+), 713 deletions(-)
 delete mode 100644 audio/fmodaudio.c
audio/Makefile.objs +0 -2
index 5573ac1..b4c0608 100644
@@ -5,12 +5,10 @@ common-obj-$(CONFIG_SPICE) += spiceaudio.o
 common-obj-$(CONFIG_COREAUDIO) += coreaudio.o
 common-obj-$(CONFIG_ALSA) += alsaaudio.o
 common-obj-$(CONFIG_DSOUND) += dsoundaudio.o
-common-obj-$(CONFIG_FMOD) += fmodaudio.o
 common-obj-$(CONFIG_PA) += paaudio.o
 common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
 common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 common-obj-y += wavcapture.o
 
-$(obj)/audio.o $(obj)/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 sdlaudio.o-cflags := $(SDL_CFLAGS)
audio/audio_int.h +0 -1
index 9dd6b7f..7445602 100644
@@ -206,7 +206,6 @@ extern struct audio_driver no_audio_driver;
 extern struct audio_driver oss_audio_driver;
 extern struct audio_driver sdl_audio_driver;
 extern struct audio_driver wav_audio_driver;
-extern struct audio_driver fmod_audio_driver;
 extern struct audio_driver alsa_audio_driver;
 extern struct audio_driver coreaudio_audio_driver;
 extern struct audio_driver dsound_audio_driver;
audio/fmodaudio.c deleted +0 -685

685 lines not on this page · raw message

configure +2 -25
index acd471d..cdece43 100755
@@ -285,8 +285,6 @@ sysconfdir="\${prefix}/etc"
 local_statedir="\${prefix}/var"
 confsuffix="/qemu"
 slirp="yes"
-fmod_lib=""
-fmod_inc=""
 oss_lib=""
 bsd="no"
 linux="no"
@@ -569,7 +567,7 @@ CYGWIN*)
 ;;
 MINGW32*)
   mingw32="yes"
-  audio_possible_drivers="winwave dsound sdl fmod"
+  audio_possible_drivers="winwave dsound sdl"
   audio_drv_list="winwave"
 ;;
 GNU/kFreeBSD)
@@ -619,7 +617,7 @@ Darwin)
   fi
   cocoa="yes"
   audio_drv_list="coreaudio"
-  audio_possible_drivers="coreaudio sdl fmod"
+  audio_possible_drivers="coreaudio sdl"
   LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
   libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
   # Disable attempts to use ObjectiveC features in os/object.h since they
@@ -680,9 +678,6 @@ Haiku)
   kvm="yes"
   vhost_net="yes"
   vhost_scsi="yes"
-  if [ "$cpu" = "i386" -o "$cpu" = "x86_64" -o "$cpu" = "x32" ] ; then
-    audio_possible_drivers="$audio_possible_drivers fmod"
-  fi
   QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
 ;;
 esac
@@ -847,10 +842,6 @@ for opt do
   ;;
   --enable-vnc) vnc="yes"
   ;;
-  --fmod-lib=*) fmod_lib="$optarg"
-  ;;
-  --fmod-inc=*) fmod_inc="$optarg"
-  ;;
   --oss-lib=*) oss_lib="$optarg"
   ;;
   --audio-drv-list=*) audio_drv_list="$optarg"
@@ -1349,8 +1340,6 @@ Advanced options (experts only):
   --disable-guest-base     disable GUEST_BASE support
   --enable-pie             build Position Independent Executables
   --disable-pie            do not build Position Independent Executables
-  --fmod-lib               path to FMOD library
-  --fmod-inc               path to FMOD includes
   --oss-lib                path to OSS library
   --cpu=CPU                Build for host CPU [$cpu]
   --disable-uuid           disable uuid support
@@ -2621,15 +2610,6 @@ for drv in $audio_drv_list; do
     libs_softmmu="-lasound $libs_softmmu"
     ;;
 
-    fmod)
-    if test -z $fmod_lib || test -z $fmod_inc; then
-        error_exit "You must specify path to FMOD library and headers" \
-            "Example: --fmod-inc=/path/include/fmod --fmod-lib=/path/lib/libfmod-3.74.so"
-    fi
-    audio_drv_probe $drv fmod.h $fmod_lib "return FSOUND_GetVersion();" "-I $fmod_inc"
-    libs_softmmu="$fmod_lib $libs_softmmu"
-    ;;
-
     pa)
     audio_drv_probe $drv pulse/mainloop.h "-lpulse" \
         "pa_mainloop *m = 0; pa_mainloop_free (m); return 0;"
@@ -4621,9 +4601,6 @@ echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
 for drv in $audio_drv_list; do
     def=CONFIG_`echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]'`
     echo "$def=y" >> $config_host_mak
-    if test "$drv" = "fmod"; then
-        echo "FMOD_CFLAGS=-I$fmod_inc" >> $config_host_mak
-    fi
 done
 if test "$audio_pt_int" = "yes" ; then
   echo "CONFIG_AUDIO_PT_INT=y" >> $config_host_mak
Signature · 1 line
2.4.2
#3 lore raw

PATCH 3/12 audio: remove sdl backend

In reply to Kővágó, Zoltán

It's broken and we have native drivers for almost all platforms.

---
 audio/Makefile.objs |   3 -
 audio/audio_int.h   |   1 -
 audio/sdlaudio.c    | 458 ----------------------------------------------------
 configure           |  24 ++-
 4 files changed, 11 insertions(+), 475 deletions(-)
 delete mode 100644 audio/sdlaudio.c
audio/Makefile.objs +0 -3
index b4c0608..3c84972 100644
@@ -1,5 +1,4 @@
 common-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
-common-obj-$(CONFIG_SDL) += sdlaudio.o
 common-obj-$(CONFIG_OSS) += ossaudio.o
 common-obj-$(CONFIG_SPICE) += spiceaudio.o
 common-obj-$(CONFIG_COREAUDIO) += coreaudio.o
@@ -10,5 +9,3 @@ common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
 common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 common-obj-y += wavcapture.o
-
-sdlaudio.o-cflags := $(SDL_CFLAGS)
audio/audio_int.h +0 -1
index 7445602..d593879 100644
@@ -204,7 +204,6 @@ struct AudioState {
 
 extern struct audio_driver no_audio_driver;
 extern struct audio_driver oss_audio_driver;
-extern struct audio_driver sdl_audio_driver;
 extern struct audio_driver wav_audio_driver;
 extern struct audio_driver alsa_audio_driver;
 extern struct audio_driver coreaudio_audio_driver;
audio/sdlaudio.c deleted +0 -458

458 lines not on this page · raw message

configure +11 -13
index cdece43..154ecbe 100755
@@ -562,24 +562,24 @@ case $targetos in
 CYGWIN*)
   mingw32="yes"
   QEMU_CFLAGS="-mno-cygwin $QEMU_CFLAGS"
-  audio_possible_drivers="winwave sdl"
+  audio_possible_drivers="winwave"
   audio_drv_list="winwave"
 ;;
 MINGW32*)
   mingw32="yes"
-  audio_possible_drivers="winwave dsound sdl"
+  audio_possible_drivers="winwave dsound"
   audio_drv_list="winwave"
 ;;
 GNU/kFreeBSD)
   bsd="yes"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl pa"
+  audio_possible_drivers="oss pa"
 ;;
 FreeBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl pa"
+  audio_possible_drivers="oss pa"
   # needed for kinfo_getvmmap(3) in libutil.h
   LIBS="-lutil $LIBS"
   netmap=""  # enable netmap autodetect
@@ -589,22 +589,20 @@ DragonFly)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl pa"
+  audio_possible_drivers="oss pa"
   HOST_VARIANT_DIR="dragonfly"
 ;;
 NetBSD)
   bsd="yes"
   make="${MAKE-gmake}"
   audio_drv_list="oss"
-  audio_possible_drivers="oss sdl"
+  audio_possible_drivers="oss"
   oss_lib="-lossaudio"
   HOST_VARIANT_DIR="netbsd"
 ;;
 OpenBSD)
   bsd="yes"
   make="${MAKE-gmake}"
-  audio_drv_list="sdl"
-  audio_possible_drivers="sdl"
   HOST_VARIANT_DIR="openbsd"
 ;;
 Darwin)
@@ -617,7 +615,7 @@ Darwin)
   fi
   cocoa="yes"
   audio_drv_list="coreaudio"
-  audio_possible_drivers="coreaudio sdl"
+  audio_possible_drivers="coreaudio"
   LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
   libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
   # Disable attempts to use ObjectiveC features in os/object.h since they
@@ -651,7 +649,7 @@ SunOS)
   if test -f /usr/include/sys/soundcard.h ; then
     audio_drv_list="oss"
   fi
-  audio_possible_drivers="oss sdl"
+  audio_possible_drivers="oss"
 # needed for CMSG_ macros in sys/socket.h
   QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
 # needed for TIOCWIN* defines in termios.h
@@ -672,7 +670,7 @@ Haiku)
 ;;
 *)
   audio_drv_list="oss"
-  audio_possible_drivers="oss alsa sdl pa"
+  audio_possible_drivers="oss alsa pa"
   linux="yes"
   linux_user="yes"
   kvm="yes"
@@ -2630,8 +2628,8 @@ for drv in $audio_drv_list; do
       libs_softmmu="$oss_lib $libs_softmmu"
     ;;
 
-    sdl|wav)
-    # XXX: Probes for CoreAudio, DirectSound, SDL(?)
+    wav)
+    # XXX: Probes for CoreAudio, DirectSound
     ;;
 
     winwave)
Signature · 1 line
2.4.2
#4 lore raw

PATCH 4/12 audio: remove winwave audio driver

In reply to Kővágó, Zoltán

DirectSound should be a superior choice on Windows.

---
 audio/Makefile.objs  |   1 -
 audio/audio_int.h    |   1 -
 audio/winwaveaudio.c | 717 ---------------------------------------------------
 configure            |  11 +-
 4 files changed, 2 insertions(+), 728 deletions(-)
 delete mode 100644 audio/winwaveaudio.c
audio/Makefile.objs +0 -1
index 3c84972..89b61e1 100644
@@ -5,7 +5,6 @@ common-obj-$(CONFIG_COREAUDIO) += coreaudio.o
 common-obj-$(CONFIG_ALSA) += alsaaudio.o
 common-obj-$(CONFIG_DSOUND) += dsoundaudio.o
 common-obj-$(CONFIG_PA) += paaudio.o
-common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
 common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 common-obj-y += wavcapture.o
audio/audio_int.h +0 -1
index d593879..92a2f3c 100644
@@ -210,7 +210,6 @@ extern struct audio_driver coreaudio_audio_driver;
 extern struct audio_driver dsound_audio_driver;
 extern struct audio_driver pa_audio_driver;
 extern struct audio_driver spice_audio_driver;
-extern struct audio_driver winwave_audio_driver;
 extern const struct mixeng_volume nominal_volume;
 
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
audio/winwaveaudio.c deleted +0 -717

717 lines not on this page · raw message

configure +2 -9
index 154ecbe..b2eddc1 100755
@@ -562,13 +562,11 @@ case $targetos in
 CYGWIN*)
   mingw32="yes"
   QEMU_CFLAGS="-mno-cygwin $QEMU_CFLAGS"
-  audio_possible_drivers="winwave"
-  audio_drv_list="winwave"
 ;;
 MINGW32*)
   mingw32="yes"
-  audio_possible_drivers="winwave dsound"
-  audio_drv_list="winwave"
+  audio_possible_drivers="dsound"
+  audio_drv_list="dsound"
 ;;
 GNU/kFreeBSD)
   bsd="yes"
@@ -2632,11 +2630,6 @@ for drv in $audio_drv_list; do
     # XXX: Probes for CoreAudio, DirectSound
     ;;
 
-    winwave)
-      libs_softmmu="-lwinmm $libs_softmmu"
-      audio_win_int="yes"
-    ;;
-
     *)
     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
         error_exit "Unknown driver '$drv' selected" \
Signature · 1 line
2.4.2
#5 lore raw

PATCH 5/12 audio: expose drv_opaque to init_out and init_in

In reply to Kővágó, Zoltán

Currently the opaque pointer returned by audio_driver's init is only exposed to the driver's fini, but not to audio_pcm_ops. This way if someone wants to share a variable with the driver and the pcm, he must use global variables. This patch fixes it by adding a third parameter to audio_pcm_op's init_out and init_in.

---
 audio/alsaaudio.c       | 9 +++++++--
 audio/audio_int.h       | 4 ++--
 audio/audio_template.h  | 2 +-
 audio/coreaudio.c       | 5 ++++-
 audio/dsound_template.h | 6 ++++--
 audio/noaudio.c         | 6 ++++--
 audio/ossaudio.c        | 9 +++++++--
 audio/paaudio.c         | 9 +++++++--
 audio/spiceaudio.c      | 9 +++++++--
 audio/wavaudio.c        | 4 +++-
 10 files changed, 46 insertions(+), 17 deletions(-)
audio/alsaaudio.c +7 -2
index 74ead97..eb33bff 100644
@@ -819,7 +819,8 @@ static void alsa_fini_out (HWVoiceOut *hw)
     alsa->pcm_buf = NULL;
 }
 
-static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
+                         void *drv_opaque)
 {
     ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
     struct alsa_params_req req;
@@ -827,6 +828,8 @@ static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
     snd_pcm_t *handle;
     struct audsettings obt_as;
 
+    (void) drv_opaque;
+
     req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
@@ -928,7 +931,7 @@ static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return -1;
 }
 
-static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as)
+static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
     struct alsa_params_req req;
@@ -936,6 +939,8 @@ static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as)
     snd_pcm_t *handle;
     struct audsettings obt_as;
 
+    (void) drv_opaque;
+
     req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
audio/audio_int.h +2 -2
index 92a2f3c..a3efe7b 100644
@@ -156,13 +156,13 @@ struct audio_driver {
 };
 
 struct audio_pcm_ops {
-    int  (*init_out)(HWVoiceOut *hw, struct audsettings *as);
+    int  (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_out)(HWVoiceOut *hw);
     int  (*run_out) (HWVoiceOut *hw, int live);
     int  (*write)   (SWVoiceOut *sw, void *buf, int size);
     int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
 
-    int  (*init_in) (HWVoiceIn *hw, struct audsettings *as);
+    int  (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_in) (HWVoiceIn *hw);
     int  (*run_in)  (HWVoiceIn *hw);
     int  (*read)    (SWVoiceIn *sw, void *buf, int size);
audio/audio_template.h +1 -1
index 584e536..f716d97 100644
@@ -262,7 +262,7 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
 #ifdef DAC
     QLIST_INIT (&hw->cap_head);
 #endif
-    if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
+    if (glue (hw->pcm_ops->init_, TYPE) (hw, as, s->drv_opaque)) {
         goto err0;
     }
 
audio/coreaudio.c +4 -1
index 5964c62..f38fd82 100644
@@ -287,7 +287,8 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
     return audio_pcm_sw_write (sw, buf, len);
 }
 
-static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
+                              void *drv_opaque)
 {
     OSStatus status;
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
@@ -296,6 +297,8 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
     const char *typ = "playback";
     AudioValueRange frameRange;
 
+    (void) drv_opaque;
+
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
     if (err) {
audio/dsound_template.h +4 -2
index 8b37d16..98276fb 100644
@@ -174,9 +174,11 @@ static void dsound_fini_out (HWVoiceOut *hw)
 }
 
 #ifdef DSBTYPE_IN
-static int dsound_init_in (HWVoiceIn *hw, struct audsettings *as)
+static int dsound_init_in(HWVoiceIn *hw, struct audsettings *as,
+                          void *drv_opaque)
 #else
-static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
+                           void *drv_opaque)
 #endif
 {
     int err;
audio/noaudio.c +4 -2
index cb38662..dd1a87a 100644
@@ -63,8 +63,9 @@ static int no_write (SWVoiceOut *sw, void *buf, int len)
     return audio_pcm_sw_write (sw, buf, len);
 }
 
-static int no_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
 {
+    (void) drv_opaque;
     audio_pcm_init_info (&hw->info, as);
     hw->samples = 1024;
     return 0;
@@ -82,8 +83,9 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
-static int no_init_in (HWVoiceIn *hw, struct audsettings *as)
+static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
+    (void) drv_opaque;
     audio_pcm_init_info (&hw->info, as);
     hw->samples = 1024;
     return 0;
audio/ossaudio.c +7 -2
index 4db2ca6..80ac610 100644
@@ -510,7 +510,8 @@ static void oss_fini_out (HWVoiceOut *hw)
     }
 }
 
-static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
+                        void *drv_opaque)
 {
     OSSVoiceOut *oss = (OSSVoiceOut *) hw;
     struct oss_params req, obt;
@@ -520,6 +521,8 @@ static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
     audfmt_e effective_fmt;
     struct audsettings obt_as;
 
+    (void) drv_opaque;
+
     oss->fd = -1;
 
     req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
@@ -676,7 +679,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
-static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
+static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     OSSVoiceIn *oss = (OSSVoiceIn *) hw;
     struct oss_params req, obt;
@@ -686,6 +689,8 @@ static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
     audfmt_e effective_fmt;
     struct audsettings obt_as;
 
+    (void) drv_opaque;
+
     oss->fd = -1;
 
     req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
audio/paaudio.c +7 -2
index 90ff245..11c2d29 100644
@@ -534,7 +534,8 @@ fail:
     return NULL;
 }
 
-static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
+                        void *drv_opaque)
 {
     int error;
     static pa_sample_spec ss;
@@ -542,6 +543,8 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
     struct audsettings obt_as = *as;
     PAVoiceOut *pa = (PAVoiceOut *) hw;
 
+    (void) drv_opaque;
+
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
     ss.rate = as->freq;
@@ -601,13 +604,15 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
     return -1;
 }
 
-static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as)
+static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     int error;
     static pa_sample_spec ss;
     struct audsettings obt_as = *as;
     PAVoiceIn *pa = (PAVoiceIn *) hw;
 
+    (void) drv_opaque;
+
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
     ss.rate = as->freq;
audio/spiceaudio.c +7 -2
index 7b79bed..78ca04c 100644
@@ -115,11 +115,14 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
 
 /* playback */
 
-static int line_out_init (HWVoiceOut *hw, struct audsettings *as)
+static int line_out_init(HWVoiceOut *hw, struct audsettings *as,
+                         void *drv_opaque)
 {
     SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
     struct audsettings settings;
 
+    (void) drv_opaque;
+
 #if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3
     settings.freq       = spice_server_get_best_playback_rate(NULL);
 #else
@@ -243,11 +246,13 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...)
 
 /* record */
 
-static int line_in_init (HWVoiceIn *hw, struct audsettings *as)
+static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
     struct audsettings settings;
 
+    (void) drv_opaque;
+
 #if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3
     settings.freq       = spice_server_get_best_record_rate(NULL);
 #else
audio/wavaudio.c +3 -1
index 6846a1a..5132aed 100644
@@ -105,7 +105,8 @@ static void le_store (uint8_t *buf, uint32_t val, int len)
     }
 }
 
-static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,
+                        void *drv_opaque)
 {
     WAVVoiceOut *wav = (WAVVoiceOut *) hw;
     int bits16 = 0, stereo = 0;
@@ -118,6 +119,7 @@ static int wav_init_out (HWVoiceOut *hw, struct audsettings *as)
     struct audsettings wav_as = conf.settings;
 
     (void) as;
+    (void) drv_opaque;
 
     stereo = wav_as.nchannels == 2;
     switch (wav_as.fmt) {
Signature · 1 line
2.4.2
#6 lore raw

Re: [Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init_in

Hi,

audio/alsaaudio.c static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as) · line 832

Quoted 12 lines
audio/alsaaudio.c +4 -1
-static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
+                         void *drv_opaque)
 {
     ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
     struct alsa_params_req req;
@@ -827,6 +828,8 @@ static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
     snd_pcm_t *handle;
     struct audsettings obt_as;
 
+    (void) drv_opaque;
+

What is the reason for this?

cheers,
Gerd

#7 lore raw

Re: [Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init_in

2015-06-02 09:56 keltezéssel, Gerd Hoffmann írta:

Quoted 10 lines
Quoted 10 lines
audio/alsaaudio.c +2 -1
-static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
+                         void *drv_opaque)
  {
      ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
      struct alsa_params_req req;
@@ -827,6 +828,8 @@ static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
      snd_pcm_t *handle;
      struct audsettings obt_as;
 
Quoted 4 lines

Review static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as) · line 832

Quoted 2 lines
(quoted diff) +2 -0
+    (void) drv_opaque;
+

What is the reason for this?

To silence compiler warnings about unused variables. I've seen it around different places in the code. But if they are just historic remains, I'll remove them.

Thanks,
Zoltan

#8 lore raw

Re: [Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init_in

Quoted 11 lines · Kővágó Zoltán

2015-06-02 09:56 keltezéssel, Gerd Hoffmann írta:

Quoted 10 lines
Quoted 10 lines
audio/alsaaudio.c +2 -1
-static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
+static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
+                         void *drv_opaque)
  {
      ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
      struct alsa_params_req req;
@@ -827,6 +828,8 @@ static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
      snd_pcm_t *handle;
      struct audsettings obt_as;
 
Quoted 6 lines
Quoted 4 lines

Review static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as) · line 832

Quoted 2 lines
(quoted diff) +2 -0
+    (void) drv_opaque;
+

What is the reason for this?

To silence compiler warnings about unused variables.

That should not happen for parameters (only for local variables).

Quoted 3 lines

I've seen it around
different places in the code. But if they are just historic remains, I'll remove them.

Yes, please.

thanks,
Gerd

#9 lore raw

PATCH 6/12 alsaaudio: do not use global variables

In reply to Kővágó, Zoltán
---
 audio/alsaaudio.c | 154 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 82 insertions(+), 72 deletions(-)
audio/alsaaudio.c +82 -72
index eb33bff..d7e181b 100644
@@ -33,9 +33,29 @@
 #define AUDIO_CAP "alsa"
 #include "audio_int.h"
 
+typedef struct ALSAConf {
+    int size_in_usec_in;
+    int size_in_usec_out;
+    const char *pcm_name_in;
+    const char *pcm_name_out;
+    unsigned int buffer_size_in;
+    unsigned int period_size_in;
+    unsigned int buffer_size_out;
+    unsigned int period_size_out;
+    unsigned int threshold;
+
+    int buffer_size_in_overridden;
+    int period_size_in_overridden;
+
+    int buffer_size_out_overridden;
+    int period_size_out_overridden;
+    int verbose;
+} ALSAConf;
+
 struct pollhlp {
     snd_pcm_t *handle;
     struct pollfd *pfds;
+    ALSAConf *conf;
     int count;
     int mask;
 };
@@ -56,30 +76,6 @@ typedef struct ALSAVoiceIn {
     struct pollhlp pollhlp;
 } ALSAVoiceIn;
 
-static struct {
-    int size_in_usec_in;
-    int size_in_usec_out;
-    const char *pcm_name_in;
-    const char *pcm_name_out;
-    unsigned int buffer_size_in;
-    unsigned int period_size_in;
-    unsigned int buffer_size_out;
-    unsigned int period_size_out;
-    unsigned int threshold;
-
-    int buffer_size_in_overridden;
-    int period_size_in_overridden;
-
-    int buffer_size_out_overridden;
-    int period_size_out_overridden;
-    int verbose;
-} conf = {
-    .buffer_size_out = 4096,
-    .period_size_out = 1024,
-    .pcm_name_out = "default",
-    .pcm_name_in = "default",
-};
-
 struct alsa_params_req {
     int freq;
     snd_pcm_format_t fmt;
@@ -184,6 +180,7 @@ static void alsa_poll_handler (void *opaque)
     snd_pcm_state_t state;
     struct pollhlp *hlp = opaque;
     unsigned short revents;
+    ALSAConf *conf = hlp->conf;
 
     count = poll (hlp->pfds, hlp->count, 0);
     if (count < 0) {
@@ -205,7 +202,7 @@ static void alsa_poll_handler (void *opaque)
     }
 
     if (!(revents & hlp->mask)) {
-        if (conf.verbose) {
+        if (conf->verbose) {
             dolog ("revents = %d\n", revents);
         }
         return;
@@ -242,6 +239,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
 {
     int i, count, err;
     struct pollfd *pfds;
+    ALSAConf *conf = hlp->conf;
 
     count = snd_pcm_poll_descriptors_count (handle);
     if (count <= 0) {
@@ -270,13 +268,13 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
                                        NULL, hlp);
         }
         if (pfds[i].events & POLLOUT) {
-            if (conf.verbose) {
+            if (conf->verbose) {
                 dolog ("POLLOUT %d %d\n", i, pfds[i].fd);
             }
             err = qemu_set_fd_handler (pfds[i].fd, NULL,
                                        alsa_poll_handler, hlp);
         }
-        if (conf.verbose) {
+        if (conf->verbose) {
             dolog ("Set handler events=%#x index=%d fd=%d err=%d\n",
                    pfds[i].events, i, pfds[i].fd, err);
         }
@@ -476,14 +474,15 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
 }
 
 static int alsa_open (int in, struct alsa_params_req *req,
-                      struct alsa_params_obt *obt, snd_pcm_t **handlep)
+                      struct alsa_params_obt *obt, snd_pcm_t **handlep,
+                      ALSAConf *conf)
 {
     snd_pcm_t *handle;
     snd_pcm_hw_params_t *hw_params;
     int err;
     int size_in_usec;
     unsigned int freq, nchannels;
-    const char *pcm_name = in ? conf.pcm_name_in : conf.pcm_name_out;
+    const char *pcm_name = in ? conf->pcm_name_in : conf->pcm_name_out;
     snd_pcm_uframes_t obt_buffer_size;
     const char *typ = in ? "ADC" : "DAC";
     snd_pcm_format_t obtfmt;
@@ -522,7 +521,7 @@ static int alsa_open (int in, struct alsa_params_req *req,
     }
 
     err = snd_pcm_hw_params_set_format (handle, hw_params, req->fmt);
-    if (err < 0 && conf.verbose) {
+    if (err < 0 && conf->verbose) {
         alsa_logerr2 (err, typ, "Failed to set format %d\n", req->fmt);
     }
 
@@ -654,7 +653,7 @@ static int alsa_open (int in, struct alsa_params_req *req,
         goto err;
     }
 
-    if (!in && conf.threshold) {
+    if (!in && conf->threshold) {
         snd_pcm_uframes_t threshold;
         int bytes_per_sec;
 
@@ -676,7 +675,7 @@ static int alsa_open (int in, struct alsa_params_req *req,
             break;
         }
 
-        threshold = (conf.threshold * bytes_per_sec) / 1000;
+        threshold = (conf->threshold * bytes_per_sec) / 1000;
         alsa_set_threshold (handle, threshold);
     }
 
@@ -686,7 +685,7 @@ static int alsa_open (int in, struct alsa_params_req *req,
 
     *handlep = handle;
 
-    if (conf.verbose &&
+    if (conf->verbose &&
         (obtfmt != req->fmt ||
          obt->nchannels != req->nchannels ||
          obt->freq != req->freq)) {
@@ -729,6 +728,7 @@ static snd_pcm_sframes_t alsa_get_avail (snd_pcm_t *handle)
 static void alsa_write_pending (ALSAVoiceOut *alsa)
 {
     HWVoiceOut *hw = &alsa->hw;
+    ALSAConf *conf = alsa->pollhlp.conf;
 
     while (alsa->pending) {
         int left_till_end_samples = hw->samples - alsa->wpos;
@@ -743,7 +743,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
             if (written <= 0) {
                 switch (written) {
                 case 0:
-                    if (conf.verbose) {
+                    if (conf->verbose) {
                         dolog ("Failed to write %d frames (wrote zero)\n", len);
                     }
                     return;
@@ -754,7 +754,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
                                      len);
                         return;
                     }
-                    if (conf.verbose) {
+                    if (conf->verbose) {
                         dolog ("Recovering from playback xrun\n");
                     }
                     continue;
@@ -767,7 +767,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
                                      len);
                         return;
                     }
-                    if (conf.verbose) {
+                    if (conf->verbose) {
                         dolog ("Resuming suspended output stream\n");
                     }
                     continue;
@@ -827,20 +827,19 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
     struct alsa_params_obt obt;
     snd_pcm_t *handle;
     struct audsettings obt_as;
-
-    (void) drv_opaque;
+    ALSAConf *conf = drv_opaque;
 
     req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
-    req.period_size = conf.period_size_out;
-    req.buffer_size = conf.buffer_size_out;
-    req.size_in_usec = conf.size_in_usec_out;
+    req.period_size = conf->period_size_out;
+    req.buffer_size = conf->buffer_size_out;
+    req.size_in_usec = conf->size_in_usec_out;
     req.override_mask =
-        (conf.period_size_out_overridden ? 1 : 0) |
-        (conf.buffer_size_out_overridden ? 2 : 0);
+        (conf->period_size_out_overridden ? 1 : 0) |
+        (conf->buffer_size_out_overridden ? 2 : 0);
 
-    if (alsa_open (0, &req, &obt, &handle)) {
+    if (alsa_open (0, &req, &obt, &handle, conf)) {
         return -1;
     }
 
@@ -861,6 +860,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
     }
 
     alsa->handle = handle;
+    alsa->pollhlp.conf = conf;
     return 0;
 }
 
@@ -938,20 +938,19 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     struct alsa_params_obt obt;
     snd_pcm_t *handle;
     struct audsettings obt_as;
-
-    (void) drv_opaque;
+    ALSAConf *conf = drv_opaque;
 
     req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
-    req.period_size = conf.period_size_in;
-    req.buffer_size = conf.buffer_size_in;
-    req.size_in_usec = conf.size_in_usec_in;
+    req.period_size = conf->period_size_in;
+    req.buffer_size = conf->buffer_size_in;
+    req.size_in_usec = conf->size_in_usec_in;
     req.override_mask =
-        (conf.period_size_in_overridden ? 1 : 0) |
-        (conf.buffer_size_in_overridden ? 2 : 0);
+        (conf->period_size_in_overridden ? 1 : 0) |
+        (conf->buffer_size_in_overridden ? 2 : 0);
 
-    if (alsa_open (1, &req, &obt, &handle)) {
+    if (alsa_open (1, &req, &obt, &handle, conf)) {
         return -1;
     }
 
@@ -972,6 +971,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     }
 
     alsa->handle = handle;
+    alsa->pollhlp.conf = conf;
     return 0;
 }
 
@@ -1002,6 +1002,7 @@ static int alsa_run_in (HWVoiceIn *hw)
     };
     snd_pcm_sframes_t avail;
     snd_pcm_uframes_t read_samples = 0;
+    ALSAConf *conf = alsa->pollhlp.conf;
 
     if (!dead) {
         return 0;
@@ -1027,12 +1028,12 @@ static int alsa_run_in (HWVoiceIn *hw)
                 dolog ("Failed to resume suspended input stream\n");
                 return 0;
             }
-            if (conf.verbose) {
+            if (conf->verbose) {
                 dolog ("Resuming suspended input stream\n");
             }
             break;
         default:
-            if (conf.verbose) {
+            if (conf->verbose) {
                 dolog ("No frames available and ALSA state is %d\n", state);
             }
             return 0;
@@ -1069,7 +1070,7 @@ static int alsa_run_in (HWVoiceIn *hw)
             if (nread <= 0) {
                 switch (nread) {
                 case 0:
-                    if (conf.verbose) {
+                    if (conf->verbose) {
                         dolog ("Failed to read %ld frames (read zero)\n", len);
                     }
                     goto exit;
@@ -1079,7 +1080,7 @@ static int alsa_run_in (HWVoiceIn *hw)
                         alsa_logerr (nread, "Failed to read %ld frames\n", len);
                         goto exit;
                     }
-                    if (conf.verbose) {
+                    if (conf->verbose) {
                         dolog ("Recovering from capture xrun\n");
                     }
                     continue;
@@ -1153,80 +1154,89 @@ static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
     return -1;
 }
 
+static ALSAConf glob_conf = {
+    .buffer_size_out = 4096,
+    .period_size_out = 1024,
+    .pcm_name_out = "default",
+    .pcm_name_in = "default",
+};
+
 static void *alsa_audio_init (void)
 {
-    return &conf;
+    ALSAConf *conf = g_malloc(sizeof(ALSAConf));
+    *conf = glob_conf;
+    return conf;
 }
 
 static void alsa_audio_fini (void *opaque)
 {
-    (void) opaque;
+    g_free(opaque);
 }
 
 static struct audio_option alsa_options[] = {
     {
         .name        = "DAC_SIZE_IN_USEC",
         .tag         = AUD_OPT_BOOL,
-        .valp        = &conf.size_in_usec_out,
+        .valp        = &glob_conf.size_in_usec_out,
         .descr       = "DAC period/buffer size in microseconds (otherwise in frames)"
     },
     {
         .name        = "DAC_PERIOD_SIZE",
         .tag         = AUD_OPT_INT,
-        .valp        = &conf.period_size_out,
+        .valp        = &glob_conf.period_size_out,
         .descr       = "DAC period size (0 to go with system default)",
-        .overriddenp = &conf.period_size_out_overridden
+        .overriddenp = &glob_conf.period_size_out_overridden
     },
     {
         .name        = "DAC_BUFFER_SIZE",
         .tag         = AUD_OPT_INT,
-        .valp        = &conf.buffer_size_out,
+        .valp        = &glob_conf.buffer_size_out,
         .descr       = "DAC buffer size (0 to go with system default)",
-        .overriddenp = &conf.buffer_size_out_overridden
+        .overriddenp = &glob_conf.buffer_size_out_overridden
     },
     {
         .name        = "ADC_SIZE_IN_USEC",
         .tag         = AUD_OPT_BOOL,
-        .valp        = &conf.size_in_usec_in,
+        .valp        = &glob_conf.size_in_usec_in,
         .descr       =
         "ADC period/buffer size in microseconds (otherwise in frames)"
     },
     {
         .name        = "ADC_PERIOD_SIZE",
         .tag         = AUD_OPT_INT,
-        .valp        = &conf.period_size_in,
+        .valp        = &glob_conf.period_size_in,
         .descr       = "ADC period size (0 to go with system default)",
-        .overriddenp = &conf.period_size_in_overridden
+        .overriddenp = &glob_conf.period_size_in_overridden
     },
     {
         .name        = "ADC_BUFFER_SIZE",
         .tag         = AUD_OPT_INT,
-        .valp        = &conf.buffer_size_in,
+        .valp        = &glob_conf.buffer_size_in,
         .descr       = "ADC buffer size (0 to go with system default)",
-        .overriddenp = &conf.buffer_size_in_overridden
+        .overriddenp = &glob_conf.buffer_size_in_overridden
     },
     {
         .name        = "THRESHOLD",
         .tag         = AUD_OPT_INT,
-        .valp        = &conf.threshold,
+        .valp        = &glob_conf.threshold,
         .descr       = "(undocumented)"
     },
     {
         .name        = "DAC_DEV",
         .tag         = AUD_OPT_STR,
-        .valp        = &conf.pcm_name_out,
+        .valp        = &glob_conf.pcm_name_out,
         .descr       = "DAC device name (for instance dmix)"
     },
     {
         .name        = "ADC_DEV",
         .tag         = AUD_OPT_STR,
-        .valp        = &conf.pcm_name_in,
+        .valp        = &glob_conf.pcm_name_in,
         .descr       = "ADC device name"
     },
     {
         .name        = "VERBOSE",
         .tag         = AUD_OPT_BOOL,
-        .valp        = &conf.verbose,
+        .valp        = &glob_conf.verbose,
         .descr       = "Behave in a more verbose way"
     },
     { /* End of list */ }
Signature · 1 line
2.4.2
#10 lore raw

PATCH 7/12 paaudio: do not use global variables

In reply to Kővágó, Zoltán
---
 audio/paaudio.c | 102 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 52 insertions(+), 50 deletions(-)
audio/paaudio.c +52 -50
index 11c2d29..35e8887 100644
@@ -9,6 +9,19 @@
 #include "audio_pt_int.h"
 
 typedef struct {
+    int samples;
+    char *server;
+    char *sink;
+    char *source;
+} PAConf;
+
+typedef struct {
+    PAConf conf;
+    pa_threaded_mainloop *mainloop;
+    pa_context *context;
+} paaudio;
+
+typedef struct {
     HWVoiceOut hw;
     int done;
     int live;
@@ -17,6 +30,7 @@ typedef struct {
     pa_stream *stream;
     void *pcm_buf;
     struct audio_pt pt;
+    paaudio *g;
 } PAVoiceOut;
 
 typedef struct {
@@ -30,21 +44,9 @@ typedef struct {
     struct audio_pt pt;
     const void *read_data;
     size_t read_index, read_length;
+    paaudio *g;
 } PAVoiceIn;
 
-typedef struct {
-    int samples;
-    char *server;
-    char *sink;
-    char *source;
-    pa_threaded_mainloop *mainloop;
-    pa_context *context;
-} paaudio;
-
-static paaudio glob_paaudio = {
-    .samples = 4096,
-};
-
 static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
 {
     va_list ap;
@@ -106,7 +108,7 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
 
 static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = p->g;
 
     pa_threaded_mainloop_lock (g->mainloop);
 
@@ -160,7 +162,7 @@ unlock_and_fail:
 
 static int qpa_simple_write (PAVoiceOut *p, const void *data, size_t length, int *rerror)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = p->g;
 
     pa_threaded_mainloop_lock (g->mainloop);
 
@@ -222,7 +224,7 @@ static void *qpa_thread_out (void *arg)
             }
         }
 
-        decr = to_mix = audio_MIN (pa->live, glob_paaudio.samples >> 2);
+        decr = to_mix = audio_MIN (pa->live, pa->g->conf.samples >> 2);
         rpos = pa->rpos;
 
         if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) {
@@ -314,7 +316,7 @@ static void *qpa_thread_in (void *arg)
             }
         }
 
-        incr = to_grab = audio_MIN (pa->dead, glob_paaudio.samples >> 2);
+        incr = to_grab = audio_MIN (pa->dead, pa->g->conf.samples >> 2);
         wpos = pa->wpos;
 
         if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) {
@@ -430,7 +432,7 @@ static audfmt_e pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
 
 static void context_state_cb (pa_context *c, void *userdata)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = userdata;
 
     switch (pa_context_get_state(c)) {
     case PA_CONTEXT_READY:
@@ -449,7 +451,7 @@ static void context_state_cb (pa_context *c, void *userdata)
 
 static void stream_state_cb (pa_stream *s, void * userdata)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = userdata;
 
     switch (pa_stream_get_state (s)) {
 
@@ -467,23 +469,21 @@ static void stream_state_cb (pa_stream *s, void * userdata)
 
 static void stream_request_cb (pa_stream *s, size_t length, void *userdata)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = userdata;
 
     pa_threaded_mainloop_signal (g->mainloop, 0);
 }
 
 static pa_stream *qpa_simple_new (
-        const char *server,
+        paaudio *g,
         const char *name,
         pa_stream_direction_t dir,
         const char *dev,
-        const char *stream_name,
         const pa_sample_spec *ss,
         const pa_channel_map *map,
         const pa_buffer_attr *attr,
         int *rerror)
 {
-    paaudio *g = &glob_paaudio;
     int r;
     pa_stream *stream;
 
@@ -538,12 +538,11 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
                         void *drv_opaque)
 {
     int error;
-    static pa_sample_spec ss;
-    static pa_buffer_attr ba;
+    pa_sample_spec ss;
+    pa_buffer_attr ba;
     struct audsettings obt_as = *as;
     PAVoiceOut *pa = (PAVoiceOut *) hw;
-
-    (void) drv_opaque;
+    paaudio *g = pa->g = drv_opaque;
 
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
@@ -561,11 +560,10 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
     obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
 
     pa->stream = qpa_simple_new (
-        glob_paaudio.server,
+        g,
         "qemu",
         PA_STREAM_PLAYBACK,
-        glob_paaudio.sink,
-        "pcm.playback",
+        g->conf.sink,
         &ss,
         NULL,                   /* channel map */
         &ba,                    /* buffering attributes */
@@ -577,7 +575,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
     }
 
     audio_pcm_init_info (&hw->info, &obt_as);
-    hw->samples = glob_paaudio.samples;
+    hw->samples = g->conf.samples;
     pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
     pa->rpos = hw->rpos;
     if (!pa->pcm_buf) {
@@ -607,11 +605,10 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
 static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     int error;
-    static pa_sample_spec ss;
+    pa_sample_spec ss;
     struct audsettings obt_as = *as;
     PAVoiceIn *pa = (PAVoiceIn *) hw;
-
-    (void) drv_opaque;
+    paaudio *g = pa->g = drv_opaque;
 
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
@@ -620,11 +617,10 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
 
     pa->stream = qpa_simple_new (
-        glob_paaudio.server,
+        g,
         "qemu",
         PA_STREAM_RECORD,
-        glob_paaudio.source,
-        "pcm.capture",
+        g->conf.source,
         &ss,
         NULL,                   /* channel map */
         NULL,                   /* buffering attributes */
@@ -636,7 +632,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     }
 
     audio_pcm_init_info (&hw->info, &obt_as);
-    hw->samples = glob_paaudio.samples;
+    hw->samples = g->conf.samples;
     pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
     pa->wpos = hw->wpos;
     if (!pa->pcm_buf) {
@@ -708,7 +704,7 @@ static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
     PAVoiceOut *pa = (PAVoiceOut *) hw;
     pa_operation *op;
     pa_cvolume v;
-    paaudio *g = &glob_paaudio;
+    paaudio *g = pa->g;
 
 #ifdef PA_CHECK_VERSION    /* macro is present in 0.9.16+ */
     pa_cvolume_init (&v);  /* function is present in 0.9.13+ */
@@ -760,7 +756,7 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
     PAVoiceIn *pa = (PAVoiceIn *) hw;
     pa_operation *op;
     pa_cvolume v;
-    paaudio *g = &glob_paaudio;
+    paaudio *g = pa->g;
 
 #ifdef PA_CHECK_VERSION
     pa_cvolume_init (&v);
@@ -810,23 +806,29 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
 }
 
 /* common */
+static PAConf glob_conf = {
+    .samples = 4096,
+};
+
 static void *qpa_audio_init (void)
 {
-    paaudio *g = &glob_paaudio;
+    paaudio *g = g_malloc(sizeof(paaudio));
+    g->conf = glob_conf;
 
     g->mainloop = pa_threaded_mainloop_new ();
     if (!g->mainloop) {
         goto fail;
     }
 
-    g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop), glob_paaudio.server);
+    g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop),
+                                 g->conf.server);
     if (!g->context) {
         goto fail;
     }
 
     pa_context_set_state_callback (g->context, context_state_cb, g);
 
-    if (pa_context_connect (g->context, glob_paaudio.server, 0, NULL) < 0) {
+    if (pa_context_connect (g->context, g->conf.server, 0, NULL) < 0) {
         qpa_logerr (pa_context_errno (g->context),
                     "pa_context_connect() failed\n");
         goto fail;
@@ -859,12 +861,13 @@ static void *qpa_audio_init (void)
 
     pa_threaded_mainloop_unlock (g->mainloop);
 
-    return &glob_paaudio;
+    return g;
 
 unlock_and_fail:
     pa_threaded_mainloop_unlock (g->mainloop);
 fail:
     AUD_log (AUDIO_CAP, "Failed to initialize PA context");
+    g_free(g);
     return NULL;
 }
 
@@ -879,39 +882,38 @@ static void qpa_audio_fini (void *opaque)
     if (g->context) {
         pa_context_disconnect (g->context);
         pa_context_unref (g->context);
-        g->context = NULL;
     }
 
     if (g->mainloop) {
         pa_threaded_mainloop_free (g->mainloop);
     }
 
-    g->mainloop = NULL;
+    g_free(g);
 }
 
 struct audio_option qpa_options[] = {
     {
         .name  = "SAMPLES",
         .tag   = AUD_OPT_INT,
-        .valp  = &glob_paaudio.samples,
+        .valp  = &glob_conf.samples,
         .descr = "buffer size in samples"
     },
     {
         .name  = "SERVER",
         .tag   = AUD_OPT_STR,
-        .valp  = &glob_paaudio.server,
+        .valp  = &glob_conf.server,
         .descr = "server address"
     },
     {
         .name  = "SINK",
         .tag   = AUD_OPT_STR,
-        .valp  = &glob_paaudio.sink,
+        .valp  = &glob_conf.sink,
         .descr = "sink device name"
     },
     {
         .name  = "SOURCE",
         .tag   = AUD_OPT_STR,
-        .valp  = &glob_paaudio.source,
+        .valp  = &glob_conf.source,
         .descr = "source device name"
     },
     { /* End of list */ }
Signature · 1 line
2.4.2
#11 lore raw

PATCH 8/12 ossaudio: do not use global variables

In reply to Kővágó, Zoltán
---
 audio/ossaudio.c | 114 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 61 insertions(+), 53 deletions(-)
audio/ossaudio.c +61 -53
index 80ac610..d247969 100644
@@ -38,6 +38,17 @@
 #define USE_DSP_POLICY
 #endif
 
+typedef struct OSSConf {
+    int try_mmap;
+    int nfrags;
+    int fragsize;
+    const char *devpath_out;
+    const char *devpath_in;
+    int debug;
+    int exclusive;
+    int policy;
+} OSSConf;
+
 typedef struct OSSVoiceOut {
     HWVoiceOut hw;
     void *pcm_buf;
@@ -47,6 +58,7 @@ typedef struct OSSVoiceOut {
     int fragsize;
     int mmapped;
     int pending;
+    OSSConf *conf;
 } OSSVoiceOut;
 
 typedef struct OSSVoiceIn {
@@ -55,28 +67,9 @@ typedef struct OSSVoiceIn {
     int fd;
     int nfrags;
     int fragsize;
+    OSSConf *conf;
 } OSSVoiceIn;
 
-static struct {
-    int try_mmap;
-    int nfrags;
-    int fragsize;
-    const char *devpath_out;
-    const char *devpath_in;
-    int debug;
-    int exclusive;
-    int policy;
-} conf = {
-    .try_mmap = 0,
-    .nfrags = 4,
-    .fragsize = 4096,
-    .devpath_out = "/dev/dsp",
-    .devpath_in = "/dev/dsp",
-    .debug = 0,
-    .exclusive = 0,
-    .policy = 5
-};
-
 struct oss_params {
     int freq;
     audfmt_e fmt;
@@ -272,18 +265,18 @@ static int oss_get_version (int fd, int *version, const char *typ)
 #endif
 
 static int oss_open (int in, struct oss_params *req,
-                     struct oss_params *obt, int *pfd)
+                     struct oss_params *obt, int *pfd, OSSConf* conf)
 {
     int fd;
-    int oflags = conf.exclusive ? O_EXCL : 0;
+    int oflags = conf->exclusive ? O_EXCL : 0;
     audio_buf_info abinfo;
     int fmt, freq, nchannels;
     int setfragment = 1;
-    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
+    const char *dspname = in ? conf->devpath_in : conf->devpath_out;
     const char *typ = in ? "ADC" : "DAC";
 
     /* Kludge needed to have working mmap on Linux */
-    oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
+    oflags |= conf->try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
 
     fd = open (dspname, oflags | O_NONBLOCK);
     if (-1 == fd) {
@@ -317,20 +310,20 @@ static int oss_open (int in, struct oss_params *req,
     }
 
 #ifdef USE_DSP_POLICY
-    if (conf.policy >= 0) {
+    if (conf->policy >= 0) {
         int version;
 
         if (!oss_get_version (fd, &version, typ)) {
-            if (conf.debug) {
+            if (conf->debug) {
                 dolog ("OSS version = %#x\n", version);
             }
 
             if (version >= 0x040000) {
-                int policy = conf.policy;
+                int policy = conf->policy;
                 if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
                     oss_logerr2 (errno, typ,
                                  "Failed to set timing policy to %d\n",
-                                 conf.policy);
+                                 conf->policy);
                     goto err;
                 }
                 setfragment = 0;
@@ -434,6 +427,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
     struct audio_buf_info abinfo;
     struct count_info cntinfo;
     int bufsize;
+    OSSConf *conf = oss->conf;
 
     bufsize = hw->samples << hw->info.shift;
 
@@ -458,7 +452,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
         }
 
         if (abinfo.bytes > bufsize) {
-            if (conf.debug) {
+            if (conf->debug) {
                 dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
                        "please report your OS/audio hw to [email protected]\n",
                        abinfo.bytes, bufsize);
@@ -467,7 +461,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
         }
 
         if (abinfo.bytes < 0) {
-            if (conf.debug) {
+            if (conf->debug) {
                 dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
                        abinfo.bytes, bufsize);
             }
@@ -520,18 +514,17 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
     int fd;
     audfmt_e effective_fmt;
     struct audsettings obt_as;
-
-    (void) drv_opaque;
+    OSSConf *conf = drv_opaque;
 
     oss->fd = -1;
 
     req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
-    req.fragsize = conf.fragsize;
-    req.nfrags = conf.nfrags;
+    req.fragsize = conf->fragsize;
+    req.nfrags = conf->nfrags;
 
-    if (oss_open (0, &req, &obt, &fd)) {
+    if (oss_open (0, &req, &obt, &fd, conf)) {
         return -1;
     }
 
@@ -558,7 +551,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
     hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
 
     oss->mmapped = 0;
-    if (conf.try_mmap) {
+    if (conf->try_mmap) {
         oss->pcm_buf = mmap (
             NULL,
             hw->samples << hw->info.shift,
@@ -618,6 +611,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
     }
 
     oss->fd = fd;
+    oss->conf = conf;
     return 0;
 }
 
@@ -688,17 +682,16 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     int fd;
     audfmt_e effective_fmt;
     struct audsettings obt_as;
-
-    (void) drv_opaque;
+    OSSConf *conf = drv_opaque;
 
     oss->fd = -1;
 
     req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
-    req.fragsize = conf.fragsize;
-    req.nfrags = conf.nfrags;
-    if (oss_open (1, &req, &obt, &fd)) {
+    req.fragsize = conf->fragsize;
+    req.nfrags = conf->nfrags;
+    if (oss_open (1, &req, &obt, &fd, conf)) {
         return -1;
     }
 
@@ -732,6 +725,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     }
 
     oss->fd = fd;
+    oss->conf = conf;
     return 0;
 }
 
@@ -850,69 +844,83 @@ static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
     return 0;
 }
 
+static OSSConf glob_conf = {
+    .try_mmap = 0,
+    .nfrags = 4,
+    .fragsize = 4096,
+    .devpath_out = "/dev/dsp",
+    .devpath_in = "/dev/dsp",
+    .debug = 0,
+    .exclusive = 0,
+    .policy = 5
+};
+
 static void *oss_audio_init (void)
 {
-    if (access(conf.devpath_in, R_OK | W_OK) < 0 ||
-        access(conf.devpath_out, R_OK | W_OK) < 0) {
+    OSSConf *conf = g_malloc(sizeof(OSSConf));
+    *conf = glob_conf;
+
+    if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
+        access(conf->devpath_out, R_OK | W_OK) < 0) {
         return NULL;
     }
-    return &conf;
+    return conf;
 }
 
 static void oss_audio_fini (void *opaque)
 {
-    (void) opaque;
+    g_free(opaque);
 }
 
 static struct audio_option oss_options[] = {
     {
         .name  = "FRAGSIZE",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.fragsize,
+        .valp  = &glob_conf.fragsize,
         .descr = "Fragment size in bytes"
     },
     {
         .name  = "NFRAGS",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.nfrags,
+        .valp  = &glob_conf.nfrags,
         .descr = "Number of fragments"
     },
     {
         .name  = "MMAP",
         .tag   = AUD_OPT_BOOL,
-        .valp  = &conf.try_mmap,
+        .valp  = &glob_conf.try_mmap,
         .descr = "Try using memory mapped access"
     },
     {
         .name  = "DAC_DEV",
         .tag   = AUD_OPT_STR,
-        .valp  = &conf.devpath_out,
+        .valp  = &glob_conf.devpath_out,
         .descr = "Path to DAC device"
     },
     {
         .name  = "ADC_DEV",
         .tag   = AUD_OPT_STR,
-        .valp  = &conf.devpath_in,
+        .valp  = &glob_conf.devpath_in,
         .descr = "Path to ADC device"
     },
     {
         .name  = "EXCLUSIVE",
         .tag   = AUD_OPT_BOOL,
-        .valp  = &conf.exclusive,
+        .valp  = &glob_conf.exclusive,
         .descr = "Open device in exclusive mode (vmix wont work)"
     },
 #ifdef USE_DSP_POLICY
     {
         .name  = "POLICY",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.policy,
+        .valp  = &glob_conf.policy,
         .descr = "Set the timing policy of the device, -1 to use fragment mode",
     },
 #endif
     {
         .name  = "DEBUG",
         .tag   = AUD_OPT_BOOL,
-        .valp  = &conf.debug,
+        .valp  = &glob_conf.debug,
         .descr = "Turn on some debugging messages"
     },
     { /* End of list */ }
Signature · 1 line
2.4.2
#12 lore raw

PATCH 9/12 wavaudio: do not use global variables

In reply to Kővágó, Zoltán
---
 audio/wavaudio.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
audio/wavaudio.c +21 -16
index 5132aed..8acea8f 100644
@@ -36,15 +36,10 @@ typedef struct WAVVoiceOut {
     int total_samples;
 } WAVVoiceOut;
 
-static struct {
+typedef struct {
     struct audsettings settings;
     const char *wav_path;
-} conf = {
-    .settings.freq      = 44100,
-    .settings.nchannels = 2,
-    .settings.fmt       = AUD_FMT_S16,
-    .wav_path           = "qemu.wav"
-};
+} WAVConf;
 
 static int wav_run_out (HWVoiceOut *hw, int live)
 {
@@ -116,7 +111,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,
         0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
         0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
     };
-    struct audsettings wav_as = conf.settings;
+    WAVConf *conf = drv_opaque;
+    struct audsettings wav_as = conf->settings;
 
     (void) as;
     (void) drv_opaque;
@@ -157,10 +153,10 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,
     le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4);
     le_store (hdr + 32, 1 << (bits16 + stereo), 2);
 
-    wav->f = fopen (conf.wav_path, "wb");
+    wav->f = fopen (conf->wav_path, "wb");
     if (!wav->f) {
         dolog ("Failed to open wave file `%s'\nReason: %s\n",
-               conf.wav_path, strerror (errno));
+               conf->wav_path, strerror (errno));
         g_free (wav->pcm_buf);
         wav->pcm_buf = NULL;
         return -1;
@@ -228,40 +224,49 @@ static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
+static WAVConf glob_conf = {
+    .settings.freq      = 44100,
+    .settings.nchannels = 2,
+    .settings.fmt       = AUD_FMT_S16,
+    .wav_path           = "qemu.wav"
+};
+
 static void *wav_audio_init (void)
 {
-    return &conf;
+    WAVConf *conf = g_malloc(sizeof(WAVConf));
+    *conf = glob_conf;
+    return conf;
 }
 
 static void wav_audio_fini (void *opaque)
 {
-    (void) opaque;
     ldebug ("wav_fini");
+    g_free(opaque);
 }
 
 static struct audio_option wav_options[] = {
     {
         .name  = "FREQUENCY",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.settings.freq,
+        .valp  = &glob_conf.settings.freq,
         .descr = "Frequency"
     },
     {
         .name  = "FORMAT",
         .tag   = AUD_OPT_FMT,
-        .valp  = &conf.settings.fmt,
+        .valp  = &glob_conf.settings.fmt,
         .descr = "Format"
     },
     {
         .name  = "DAC_FIXED_CHANNELS",
         .tag   = AUD_OPT_INT,
-        .valp  = &conf.settings.nchannels,
+        .valp  = &glob_conf.settings.nchannels,
         .descr = "Number of channels (1 - mono, 2 - stereo)"
     },
     {
         .name  = "PATH",
         .tag   = AUD_OPT_STR,
-        .valp  = &conf.wav_path,
+        .valp  = &glob_conf.wav_path,
         .descr = "Path to wave file"
     },
     { /* End of list */ }
Signature · 1 line
2.4.2
#13 lore raw

PATCH 10/12 dsoundaudio: do not use global variables

In reply to Kővágó, Zoltán
---
 audio/dsound_template.h |  18 ++++----
 audio/dsoundaudio.c     | 106 ++++++++++++++++++++++++++++--------------------
 2 files changed, 74 insertions(+), 50 deletions(-)
audio/dsound_template.h +11 -7
index 98276fb..85ba858 100644
@@ -67,7 +67,8 @@ static int glue (dsound_lock_, TYPE) (
     LPVOID *p2p,
     DWORD *blen1p,
     DWORD *blen2p,
-    int entire
+    int entire,
+    dsound *s
     )
 {
     HRESULT hr;
@@ -75,13 +76,14 @@ static int glue (dsound_lock_, TYPE) (
     LPVOID p1 = NULL, p2 = NULL;
     DWORD blen1 = 0, blen2 = 0;
     DWORD flag;
+    DSoundConf *conf = &s->conf;
 
 #ifdef DSBTYPE_IN
     flag = entire ? DSCBLOCK_ENTIREBUFFER : 0;
 #else
     flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
 #endif
-    for (i = 0; i < conf.lock_retries; ++i) {
+    for (i = 0; i < conf->lock_retries; ++i) {
         hr = glue (IFACE, _Lock) (
             buf,
             pos,
@@ -96,7 +98,7 @@ static int glue (dsound_lock_, TYPE) (
         if (FAILED (hr)) {
 #ifndef DSBTYPE_IN
             if (hr == DSERR_BUFFERLOST) {
-                if (glue (dsound_restore_, TYPE) (buf)) {
+                if (glue (dsound_restore_, TYPE) (buf, s)) {
                     dsound_logerr (hr, "Could not lock " NAME "\n");
                     goto fail;
                 }
@@ -110,7 +112,7 @@ static int glue (dsound_lock_, TYPE) (
         break;
     }
 
-    if (i == conf.lock_retries) {
+    if (i == conf->lock_retries) {
         dolog ("%d attempts to lock " NAME " failed\n", i);
         goto fail;
     }
@@ -183,9 +185,10 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 {
     int err;
     HRESULT hr;
-    dsound *s = &glob_dsound;
+    dsound *s = drv_opaque;
     WAVEFORMATEX wfx;
     struct audsettings obt_as;
+    DSoundConf *conf = &s->conf;
 #ifdef DSBTYPE_IN
     const char *typ = "ADC";
     DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
@@ -212,7 +215,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
     bd.dwSize = sizeof (bd);
     bd.lpwfxFormat = &wfx;
 #ifdef DSBTYPE_IN
-    bd.dwBufferBytes = conf.bufsize_in;
+    bd.dwBufferBytes = conf->bufsize_in;
     hr = IDirectSoundCapture_CreateCaptureBuffer (
         s->dsound_capture,
         &bd,
@@ -221,7 +224,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
         );
 #else
     bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
-    bd.dwBufferBytes = conf.bufsize_out;
+    bd.dwBufferBytes = conf->bufsize_out;
     hr = IDirectSound_CreateSoundBuffer (
         s->dsound,
         &bd,
@@ -271,6 +274,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
             );
     }
     hw->samples = bc.dwBufferBytes >> hw->info.shift;
+    ds->s = s;
 
 #ifdef DEBUG_DSOUND
     dolog ("caps %ld, desc %ld\n",
audio/dsoundaudio.c +63 -43

347 lines not on this page · raw message

Signature · 1 line
2.4.2
#14 lore raw

PATCH 11/12 paaudio: fix possible resource leak

In reply to Kővágó, Zoltán

qpa_audio_init did not clean up resources properly if the initialization failed. This hopefully fixes it.

---
 audio/paaudio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
audio/paaudio.c +5 -1
index 35e8887..fea6071 100644
@@ -47,6 +47,8 @@ typedef struct {
     paaudio *g;
 } PAVoiceIn;
 
+static void qpa_audio_fini(void *opaque);
+
 static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
 {
     va_list ap;
@@ -814,6 +816,8 @@ static void *qpa_audio_init (void)
 {
     paaudio *g = g_malloc(sizeof(paaudio));
     g->conf = glob_conf;
+    g->mainloop = NULL;
+    g->context = NULL;
 
     g->mainloop = pa_threaded_mainloop_new ();
     if (!g->mainloop) {
@@ -867,7 +871,7 @@ unlock_and_fail:
     pa_threaded_mainloop_unlock (g->mainloop);
 fail:
     AUD_log (AUDIO_CAP, "Failed to initialize PA context");
-    g_free(g);
+    qpa_audio_fini(g);
     return NULL;
 }
 
Signature · 1 line
2.4.2
#15 lore raw

PATCH 12/12 coreaudio: do not use global variables where possible

In reply to Kővágó, Zoltán
---
 audio/coreaudio.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)
audio/coreaudio.c +24 -21
index f38fd82..6dfd63e 100644
@@ -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,8 +292,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
     int err;
     const char *typ = "playback";
     AudioValueRange frameRange;
-
-    (void) drv_opaque;
+    CoreaudioConf *conf = drv_opaque;
 
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
@@ -339,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 */
@@ -382,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);
@@ -446,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);
@@ -489,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) {
@@ -502,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  = &glob_conf.nbuffers,
         .descr = "Number of buffers"
     },
     { /* End of list */ }
Signature · 1 line
2.4.2
#16 lore raw
In reply to Kővágó, Zoltán
Quoted 2 lines · Zoltán

This series of patch removes the following audio backends:
esd, fmod, sdl, winwave.

Why do you remove sdl backend?

This is my preferred backend so far, it works better than all other backends available to me...

Thanks,

/mjt

#17 lore raw

2015-06-01 15:38 keltezéssel, Michael Tokarev írta:

Quoted 8 lines
Quoted 2 lines · Zoltán

This series of patch removes the following audio backends:
esd, fmod, sdl, winwave.

Why do you remove sdl backend?

This is my preferred backend so far, it works better than all other backends available to me...

I'm removing it because it's broken (see http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg02198.html for an example), and nobody had an objection about removing sdl when I asked it on the list about a week ago (http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg04116.html).

Thanks,
Zoltan

#18 lore raw
In reply to Michael Tokarev
Quoted 8 lines · Michael Tokarev
Quoted 2 lines · Zoltán

This series of patch removes the following audio backends:
esd, fmod, sdl, winwave.

Why do you remove sdl backend?

This is my preferred backend so far, it works better than all other backends available to me...

What other backends can you use? What are the problems? Do you use sdl audio together with sdl ui?

cheers,
Gerd

#19 lore raw
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Michael Tokarev
Quoted 2 lines · Zoltán

This series of patch removes the following audio backends:
esd, fmod, sdl, winwave.

Quoted 7 lines
Quoted 4 lines

Why do you remove sdl backend?

This is my preferred backend so far, it works better than all other backends available to me...

What other backends can you use? What are the problems? Do you use sdl audio together with sdl ui?

I haven't had a chance to check, planned to do that today morning but had some other things to do. Will check asap.

Yes, I use sdl audio with sdl ui, sdl1 version (since sdl2 had its shortcomings in qemu, not all functionality worked).

I also tried alsa, oss and pa, with these audio was more distorted than with sdl. Sdl version sounds cleanly, while alsa and pa, at least in the past, and at least if memory serves me right, sounded like a if a good portion of noize has been mixed in with sound, or like when sound is with quick monmentary drops which happens at high frequency (maybe 200Hz).

SDL audio has been the default in Debian for at least two debian releases because of that, we explicitly used --audio-drv-list=sdl,... to list sdl first. Now we have pa first, but I don't really remember why we changed it.

But I have QEMU_AUDIO_DRV=sdl in my ~/.profile for a very long time. Not that I use audio all the time, only rarely, but I never had any issues especially with sdl (this is ofcourse NOT to say that there are no probs in there :)

Thanks,

/mjt

#20 lore raw

Hi,

Quoted 3 lines

Yes, I use sdl audio with sdl ui, sdl1 version (since sdl2 had its shortcomings in qemu, not all functionality worked).

Does it work equally well with the gtk ui?

Possibly it makes sense to use keep sdl audio and default to it only in case sdl ui is active (simliar to how spice audio is handled).

Quoted 7 lines

I also tried alsa, oss and pa, with these audio was more distorted than with sdl. Sdl version sounds cleanly, while alsa and pa, at least in the past, and at least if memory serves me right, sounded like a if a good portion of noize has been mixed in with sound, or like when sound is with quick monmentary drops which happens at high frequency (maybe 200Hz).

Buffer overruns and underruns maybe? Possibly this is simply due to different default values for sound buffer sizes.

Quoted 4 lines

SDL audio has been the default in Debian for at least two debian releases because of that, we explicitly used --audio-drv-list=sdl,... to list sdl first. Now we have pa first, but I don't really remember why we changed it.

Useful data point. sdl state can't be that bad if it was default in debian until recently ...

cheers,
Gerd

#21 lore raw
Quoted 7 lines · Gerd Hoffmann
Quoted 4 lines

SDL audio has been the default in Debian for at least two debian releases because of that, we explicitly used --audio-drv-list=sdl,... to list sdl first. Now we have pa first, but I don't really remember why we changed it.

Useful data point. sdl state can't be that bad if it was default in debian until recently ...

I guess the breakage is only for SDL 2 then.

Paolo

#22 lore raw
In reply to Michael Tokarev
Quoted 8 lines · Michael Tokarev

I also tried alsa, oss and pa, with these audio was more distorted than with sdl. Sdl version sounds cleanly, while alsa and pa, at least in the past, and at least if memory serves me right, sounded like a if a good portion of noize has been mixed in with sound, or like when sound is with quick monmentary drops which happens at high frequency (maybe 200Hz).

Quoted 4 lines

SDL audio has been the default in Debian for at least two debian releases because of that, we explicitly used --audio-drv-list=sdl,... to list sdl first. Now we have pa first, but I don't really remember why we changed it.

I think the important thing here is to avoid ever using any of the audio subsystems' back-compatibility layers. For instance PA can provide an alsa-compatible interface, but if you use it you've just added an extra layer of buffering (and a random thread) to your system. So at a distro I would expect there to be a "this is the standard audio subsystem" distro-wide decision, and the QEMU packages would then follow that.

thanks
-- PMM

#23 lore raw
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Michael Tokarev

SDL audio has been the default in Debian for at least two debian releases because of that, we explicitly used --audio-drv-list=sdl,... to list sdl first. Now we have pa first, but I don't really remember why we changed it.

Quoted 8 lines

I think the important thing here is to avoid ever using any of the audio subsystems' back-compatibility layers. For instance PA can provide an alsa-compatible interface, but if you use it you've just added an extra layer of buffering (and a random thread) to your system. So at a distro I would expect there to be a "this is the standard audio subsystem" distro-wide decision, and the QEMU packages would then follow that.

Yes, that's true. As long as the native version actually works. As I said before, initially it didn't, and sdl was the only driver that worked. Maybe in 0.12, maybe even before, I don't remember anymore, but the fact remains, in our testing only sdl was more or less adequate, maybe due to pure luck or phase of moon. Later native drivers started working, so we started using native driver which is default to the OS, which is pulseaudio (installed on all desktop environments) or, failing that, alsa (native to linux).

Thanks,

/mjt

#24 lore raw
Quoted 9 lines · Michael Tokarev

Yes, that's true. As long as the native version actually works. As I said before, initially it didn't, and sdl was the only driver that worked. Maybe in 0.12, maybe even before, I don't remember anymore, but the fact remains, in our testing only sdl was more or less adequate, maybe due to pure luck or phase of moon. Later native drivers started working, so we started using native driver which is default to the OS, which is pulseaudio (installed on all desktop environments) or, failing that, alsa (native to linux).

Btw, please consider that ports to new host platforms really benefit from SDL for those things. For example we've been using SDL for the Haiku port until last year:

http://bb.haikuports.org/haikuports/commits/df441da15a7c4a5583f6460de2ca1d570d0caee1

All other backends are either *nix only like OSS (Haiku has an OSS port but only uses its drivers, the API is not made public), or even Linux-only like PA or ALSA. There are more OSes out there than just GNU/Linux :p

It's already hard enough to get stuff upstream into QEMU, having to write native audio and graphics backends before things get usable won't help at all.

François.

#25 lore raw
Quoted 18 lines · François Revol
Quoted 9 lines · Michael Tokarev

Yes, that's true. As long as the native version actually works. As I said before, initially it didn't, and sdl was the only driver that worked. Maybe in 0.12, maybe even before, I don't remember anymore, but the fact remains, in our testing only sdl was more or less adequate, maybe due to pure luck or phase of moon. Later native drivers started working, so we started using native driver which is default to the OS, which is pulseaudio (installed on all desktop environments) or, failing that, alsa (native to linux).

Btw, please consider that ports to new host platforms really benefit from SDL for those things. For example we've been using SDL for the Haiku port until last year:

http://bb.haikuports.org/haikuports/commits/df441da15a7c4a5583f6460de2ca1d570d0caee1

Quoted 8 lines

All other backends are either *nix only like OSS (Haiku has an OSS port but only uses its drivers, the API is not made public), or even Linux-only like PA or ALSA. There are more OSes out there than just GNU/Linux :p

It's already hard enough to get stuff upstream into QEMU, having to write native audio and graphics backends before things get usable won't help at all.

Ok, makes sense.

I think we should keep sdl audio then and only drop the other three (esd, fmod, winwave).

cheers,
Gerd