[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init
From: |
Kővágó, Zoltán |
Subject: |
[Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init_in |
Date: |
Mon, 1 Jun 2015 15:23:43 +0200 |
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.
Signed-off-by: Kővágó, Zoltán <address@hidden>
---
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(-)
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 74ead97..eb33bff 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -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;
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 92a2f3c..a3efe7b 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -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);
diff --git a/audio/audio_template.h b/audio/audio_template.h
index 584e536..f716d97 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -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;
}
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 5964c62..f38fd82 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -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) {
diff --git a/audio/dsound_template.h b/audio/dsound_template.h
index 8b37d16..98276fb 100644
--- a/audio/dsound_template.h
+++ b/audio/dsound_template.h
@@ -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;
diff --git a/audio/noaudio.c b/audio/noaudio.c
index cb38662..dd1a87a 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -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;
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 4db2ca6..80ac610 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -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);
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 90ff245..11c2d29 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -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;
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index 7b79bed..78ca04c 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -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
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index 6846a1a..5132aed 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -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) {
--
2.4.2
- [Qemu-devel] [PATCH 00/12] Audio backend cleanup, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 03/12] audio: remove sdl backend, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 06/12] alsaaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 07/12] paaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 02/12] audio: remove fmod backend, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 08/12] ossaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 04/12] audio: remove winwave audio driver, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 09/12] wavaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01