From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2H4L-0001vX-GK for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2H4I-0004eW-Qj for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41258) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2H4I-0004eE-JI for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:42 -0400 From: Gerd Hoffmann Date: Tue, 9 Jun 2015 12:47:27 +0200 Message-Id: <1433846851-20552-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1433846851-20552-1-git-send-email-kraxel@redhat.com> References: <1433846851-20552-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 08/12] wavaudio: do not use global variables List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Vassili Karpov (malc)" , Gerd Hoffmann , =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= From: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n Signed-off-by: Gerd Hoffmann --- audio/wavaudio.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/audio/wavaudio.c b/audio/wavaudio.c index 09083da..c586020 100644 --- a/audio/wavaudio.c +++ b/audio/wavaudio.c @@ -36,15 +36,10 @@ typedef struct WAVVoiceOut { int total_samples; } WAVVoiceOut; =20 -static struct { +typedef struct { struct audsettings settings; const char *wav_path; -} conf =3D { - .settings.freq =3D 44100, - .settings.nchannels =3D 2, - .settings.fmt =3D AUD_FMT_S16, - .wav_path =3D "qemu.wav" -}; +} WAVConf; =20 static int wav_run_out (HWVoiceOut *hw, int live) { @@ -116,7 +111,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audset= tings *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 =3D conf.settings; + WAVConf *conf =3D drv_opaque; + struct audsettings wav_as =3D conf->settings; =20 stereo =3D wav_as.nchannels =3D=3D 2; switch (wav_as.fmt) { @@ -154,10 +150,10 @@ static int wav_init_out(HWVoiceOut *hw, struct auds= ettings *as, le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4); le_store (hdr + 32, 1 << (bits16 + stereo), 2); =20 - wav->f =3D fopen (conf.wav_path, "wb"); + wav->f =3D 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 =3D NULL; return -1; @@ -225,40 +221,49 @@ static int wav_ctl_out (HWVoiceOut *hw, int cmd, ..= .) return 0; } =20 +static WAVConf glob_conf =3D { + .settings.freq =3D 44100, + .settings.nchannels =3D 2, + .settings.fmt =3D AUD_FMT_S16, + .wav_path =3D "qemu.wav" +}; + static void *wav_audio_init (void) { - return &conf; + WAVConf *conf =3D g_malloc(sizeof(WAVConf)); + *conf =3D glob_conf; + return conf; } =20 static void wav_audio_fini (void *opaque) { - (void) opaque; ldebug ("wav_fini"); + g_free(opaque); } =20 static struct audio_option wav_options[] =3D { { .name =3D "FREQUENCY", .tag =3D AUD_OPT_INT, - .valp =3D &conf.settings.freq, + .valp =3D &glob_conf.settings.freq, .descr =3D "Frequency" }, { .name =3D "FORMAT", .tag =3D AUD_OPT_FMT, - .valp =3D &conf.settings.fmt, + .valp =3D &glob_conf.settings.fmt, .descr =3D "Format" }, { .name =3D "DAC_FIXED_CHANNELS", .tag =3D AUD_OPT_INT, - .valp =3D &conf.settings.nchannels, + .valp =3D &glob_conf.settings.nchannels, .descr =3D "Number of channels (1 - mono, 2 - stereo)" }, { .name =3D "PATH", .tag =3D AUD_OPT_STR, - .valp =3D &conf.wav_path, + .valp =3D &glob_conf.wav_path, .descr =3D "Path to wave file" }, { /* End of list */ } --=20 1.8.3.1