From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2H4M-0001va-0u for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2H4I-0004ee-TR for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2H4I-0004eF-JC for qemu-devel@nongnu.org; Tue, 09 Jun 2015 06:47:42 -0400 From: Gerd Hoffmann Date: Tue, 9 Jun 2015 12:47:26 +0200 Message-Id: <1433846851-20552-8-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 07/12] ossaudio: 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/ossaudio.c | 110 ++++++++++++++++++++++++++++++-------------------= ------ 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/audio/ossaudio.c b/audio/ossaudio.c index 069ff60..d247969 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -38,6 +38,17 @@ #define USE_DSP_POLICY #endif =20 +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; =20 typedef struct OSSVoiceIn { @@ -55,28 +67,9 @@ typedef struct OSSVoiceIn { int fd; int nfrags; int fragsize; + OSSConf *conf; } OSSVoiceIn; =20 -static struct { - int try_mmap; - int nfrags; - int fragsize; - const char *devpath_out; - const char *devpath_in; - int debug; - int exclusive; - int policy; -} conf =3D { - .try_mmap =3D 0, - .nfrags =3D 4, - .fragsize =3D 4096, - .devpath_out =3D "/dev/dsp", - .devpath_in =3D "/dev/dsp", - .debug =3D 0, - .exclusive =3D 0, - .policy =3D 5 -}; - struct oss_params { int freq; audfmt_e fmt; @@ -272,18 +265,18 @@ static int oss_get_version (int fd, int *version, c= onst char *typ) #endif =20 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 =3D conf.exclusive ? O_EXCL : 0; + int oflags =3D conf->exclusive ? O_EXCL : 0; audio_buf_info abinfo; int fmt, freq, nchannels; int setfragment =3D 1; - const char *dspname =3D in ? conf.devpath_in : conf.devpath_out; + const char *dspname =3D in ? conf->devpath_in : conf->devpath_out; const char *typ =3D in ? "ADC" : "DAC"; =20 /* Kludge needed to have working mmap on Linux */ - oflags |=3D conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY); + oflags |=3D conf->try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY); =20 fd =3D open (dspname, oflags | O_NONBLOCK); if (-1 =3D=3D fd) { @@ -317,20 +310,20 @@ static int oss_open (int in, struct oss_params *req= , } =20 #ifdef USE_DSP_POLICY - if (conf.policy >=3D 0) { + if (conf->policy >=3D 0) { int version; =20 if (!oss_get_version (fd, &version, typ)) { - if (conf.debug) { + if (conf->debug) { dolog ("OSS version =3D %#x\n", version); } =20 if (version >=3D 0x040000) { - int policy =3D conf.policy; + int policy =3D 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 =3D 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 =3D oss->conf; =20 bufsize =3D hw->samples << hw->info.shift; =20 @@ -458,7 +452,7 @@ static int oss_run_out (HWVoiceOut *hw, int live) } =20 if (abinfo.bytes > bufsize) { - if (conf.debug) { + if (conf->debug) { dolog ("warning: Invalid available size, size=3D%d bufsi= ze=3D%d\n" "please report your OS/audio hw to av1474@comtv.r= u\n", abinfo.bytes, bufsize); @@ -467,7 +461,7 @@ static int oss_run_out (HWVoiceOut *hw, int live) } =20 if (abinfo.bytes < 0) { - if (conf.debug) { + if (conf->debug) { dolog ("warning: Invalid available size, size=3D%d bufsi= ze=3D%d\n", abinfo.bytes, bufsize); } @@ -520,16 +514,17 @@ static int oss_init_out(HWVoiceOut *hw, struct auds= ettings *as, int fd; audfmt_e effective_fmt; struct audsettings obt_as; + OSSConf *conf =3D drv_opaque; =20 oss->fd =3D -1; =20 req.fmt =3D aud_to_ossfmt (as->fmt, as->endianness); req.freq =3D as->freq; req.nchannels =3D as->nchannels; - req.fragsize =3D conf.fragsize; - req.nfrags =3D conf.nfrags; + req.fragsize =3D conf->fragsize; + req.nfrags =3D conf->nfrags; =20 - if (oss_open (0, &req, &obt, &fd)) { + if (oss_open (0, &req, &obt, &fd, conf)) { return -1; } =20 @@ -556,7 +551,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audset= tings *as, hw->samples =3D (obt.nfrags * obt.fragsize) >> hw->info.shift; =20 oss->mmapped =3D 0; - if (conf.try_mmap) { + if (conf->try_mmap) { oss->pcm_buf =3D mmap ( NULL, hw->samples << hw->info.shift, @@ -616,6 +611,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audset= tings *as, } =20 oss->fd =3D fd; + oss->conf =3D conf; return 0; } =20 @@ -686,15 +682,16 @@ static int oss_init_in(HWVoiceIn *hw, struct audset= tings *as, void *drv_opaque) int fd; audfmt_e effective_fmt; struct audsettings obt_as; + OSSConf *conf =3D drv_opaque; =20 oss->fd =3D -1; =20 req.fmt =3D aud_to_ossfmt (as->fmt, as->endianness); req.freq =3D as->freq; req.nchannels =3D as->nchannels; - req.fragsize =3D conf.fragsize; - req.nfrags =3D conf.nfrags; - if (oss_open (1, &req, &obt, &fd)) { + req.fragsize =3D conf->fragsize; + req.nfrags =3D conf->nfrags; + if (oss_open (1, &req, &obt, &fd, conf)) { return -1; } =20 @@ -728,6 +725,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsetti= ngs *as, void *drv_opaque) } =20 oss->fd =3D fd; + oss->conf =3D conf; return 0; } =20 @@ -846,69 +844,83 @@ static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...) return 0; } =20 +static OSSConf glob_conf =3D { + .try_mmap =3D 0, + .nfrags =3D 4, + .fragsize =3D 4096, + .devpath_out =3D "/dev/dsp", + .devpath_in =3D "/dev/dsp", + .debug =3D 0, + .exclusive =3D 0, + .policy =3D 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 =3D g_malloc(sizeof(OSSConf)); + *conf =3D 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; } =20 static void oss_audio_fini (void *opaque) { - (void) opaque; + g_free(opaque); } =20 static struct audio_option oss_options[] =3D { { .name =3D "FRAGSIZE", .tag =3D AUD_OPT_INT, - .valp =3D &conf.fragsize, + .valp =3D &glob_conf.fragsize, .descr =3D "Fragment size in bytes" }, { .name =3D "NFRAGS", .tag =3D AUD_OPT_INT, - .valp =3D &conf.nfrags, + .valp =3D &glob_conf.nfrags, .descr =3D "Number of fragments" }, { .name =3D "MMAP", .tag =3D AUD_OPT_BOOL, - .valp =3D &conf.try_mmap, + .valp =3D &glob_conf.try_mmap, .descr =3D "Try using memory mapped access" }, { .name =3D "DAC_DEV", .tag =3D AUD_OPT_STR, - .valp =3D &conf.devpath_out, + .valp =3D &glob_conf.devpath_out, .descr =3D "Path to DAC device" }, { .name =3D "ADC_DEV", .tag =3D AUD_OPT_STR, - .valp =3D &conf.devpath_in, + .valp =3D &glob_conf.devpath_in, .descr =3D "Path to ADC device" }, { .name =3D "EXCLUSIVE", .tag =3D AUD_OPT_BOOL, - .valp =3D &conf.exclusive, + .valp =3D &glob_conf.exclusive, .descr =3D "Open device in exclusive mode (vmix wont work)" }, #ifdef USE_DSP_POLICY { .name =3D "POLICY", .tag =3D AUD_OPT_INT, - .valp =3D &conf.policy, + .valp =3D &glob_conf.policy, .descr =3D "Set the timing policy of the device, -1 to use fragm= ent mode", }, #endif { .name =3D "DEBUG", .tag =3D AUD_OPT_BOOL, - .valp =3D &conf.debug, + .valp =3D &glob_conf.debug, .descr =3D "Turn on some debugging messages" }, { /* End of list */ } --=20 1.8.3.1