From nobody Wed Oct 1 04:57:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548716366552445.95275278788915; Mon, 28 Jan 2019 14:59:26 -0800 (PST) Received: from localhost ([127.0.0.1]:39828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFs7-0002C9-CR for importer@patchew.org; Mon, 28 Jan 2019 17:59:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFdD-0007ri-Lr for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFd7-0003QZ-Fg for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:55 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:34354) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFd6-0003Oi-VR for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:49 -0500 Received: by mail-wr1-x432.google.com with SMTP id f7so20038775wrp.1 for ; Mon, 28 Jan 2019 14:43:48 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-2152-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:2152::5]) by smtp.gmail.com with ESMTPSA id k7sm100088187wrl.51.2019.01.28.14.43.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 14:43:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M5gW65KWfoio9ch/cCsBtqrDedZAk0WVqWxAzsg11b4=; b=nEpVCbmIQJLmugJ0unKM2V9wI3LTku0tvCgnmeLUyt1C5eKa7uOlxJLmnjUQELau0m HtAD0ZJCf8pK8LWOF2xK8uwwm2s9eyKOoE0yW1KKDmsqPgAgzHY4nQgr5IinrYbFFVb2 ZN9VkGgnqRes/nYXrn37IORyPyjQNwW6Cnau3b6wYFiq8VDzGlAlTWRkzpN6o6uw0yT/ t59RyD0IDCV7QTtH3nskQ6Xb4YAdy2u0vNF8GC1QHLivzI9nWQi5k39EFxdqtXREIXB4 tbey0iMpNpTBN3XzDlgx0JmAecBRntqzOQdTNox7LHCjpPUUS/lMG7jWLBi7xWvZbTJa IxHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M5gW65KWfoio9ch/cCsBtqrDedZAk0WVqWxAzsg11b4=; b=DU10LROaWMLtD6Fo2aCcAY4mh7hWkGr2xbxxZKyzA2XLcW5w6w7t0FBJfHmWnxtYxb +cjyvUPYyOOfVLAkLAEH/u40hTzOY36pXfYzDHvufVHUQjhK65+/lBZTJdtLvS7E5ddh 7UiCllUXKqJWe7THK46C9Y0AHvE7fG3UwUuqjPGrkw1ENeeSYfNoEai4VDnv2DNafOx8 X/w14DfljNBdeH9SKPtEN8PzOl2uKGiRuNn8ai16eOF3wR9YdSU31jwkEzYLjMU/k/lb 9bU/ihzsvAiIZUEidunQJ4nW16PM7SWl25ao7ttvm0AcH8IYyQcz5TJe73/eHKeH+L+x D4gg== X-Gm-Message-State: AJcUuke3VcT49gCo4raUe6VQ3w6u0Yi/HeCkRQF4ipznPHAd4hG/yONb IO7QUx/IQPeRYIFwGYp4HEXXU5WbwIn9aw== X-Google-Smtp-Source: ALg8bN5Dq7KqJVf56EkjdNUOhHoN1HhIa4BrIqMIyUNwS3zggZ7uMcr8bQjUR/aoAMHExhqKmSb4Fg== X-Received: by 2002:adf:f9cb:: with SMTP id w11mr23075132wrr.201.1548715427361; Mon, 28 Jan 2019 14:43:47 -0800 (PST) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 23:43:32 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PATCH v4 09/14] ossaudio: port to -audiodev config X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n --- audio/audio_legacy.c | 33 +++++++++ audio/ossaudio.c | 167 +++++++++++++++---------------------------- 2 files changed, 90 insertions(+), 110 deletions(-) diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 0002fce627..3d336259bb 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -221,6 +221,35 @@ static void handle_dsound(Audiodev *dev) &dev->in->has_buffer_len, dev->in); } =20 +/* OSS */ +static void handle_oss_per_direction( + AudiodevPerDirectionOptions *pdo, AudiodevOssPerDirectionOptions **opd= o, + bool *has_opdo, const char *try_poll_env, const char *dev_env) +{ + *opdo =3D g_malloc0(sizeof(AudiodevOssPerDirectionOptions)); + *has_opdo =3D true; + + get_bool(try_poll_env, &(*opdo)->try_poll, &(*opdo)->has_try_poll); + get_str(dev_env, &(*opdo)->dev, &(*opdo)->has_dev); + + get_bytes_to_usecs("QEMU_OSS_FRAGSIZE", + &pdo->buffer_len, &pdo->has_buffer_len, pdo); + get_int("QEMU_OSS_NFRAGS", &pdo->buffer_count, &pdo->has_buffer_count); +} + +static void handle_oss(Audiodev *dev) +{ + AudiodevOssOptions *oopt =3D &dev->u.oss; + handle_oss_per_direction(dev->in, &oopt->oss_in, &oopt->has_oss_in, + "QEMU_AUDIO_ADC_TRY_POLL", "QEMU_OSS_ADC_DEV"= ); + handle_oss_per_direction(dev->out, &oopt->oss_out, &oopt->has_oss_out, + "QEMU_AUDIO_DAC_TRY_POLL", "QEMU_OSS_DAC_DEV"= ); + + get_bool("QEMU_OSS_MMAP", &oopt->try_mmap, &oopt->has_try_mmap); + get_bool("QEMU_OSS_EXCLUSIVE", &oopt->exclusive, &oopt->has_exclusive); + get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy); +} + /* general */ static void handle_per_direction( AudiodevPerDirectionOptions *pdo, const char *prefix) @@ -276,6 +305,10 @@ static AudiodevListEntry *legacy_opt(const char *drvna= me) handle_dsound(e->dev); break; =20 + case AUDIODEV_DRIVER_OSS: + handle_oss(e->dev); + break; + default: break; } diff --git a/audio/ossaudio.c b/audio/ossaudio.c index e0cadbef29..72b9dc3b5f 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -37,16 +37,6 @@ #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 exclusive; - int policy; -} OSSConf; - typedef struct OSSVoiceOut { HWVoiceOut hw; void *pcm_buf; @@ -56,7 +46,7 @@ typedef struct OSSVoiceOut { int fragsize; int mmapped; int pending; - OSSConf *conf; + Audiodev *dev; } OSSVoiceOut; =20 typedef struct OSSVoiceIn { @@ -65,12 +55,12 @@ typedef struct OSSVoiceIn { int fd; int nfrags; int fragsize; - OSSConf *conf; + Audiodev *dev; } OSSVoiceIn; =20 struct oss_params { int freq; - AudioFormat fmt; + int fmt; int nchannels; int nfrags; int fragsize; @@ -262,19 +252,26 @@ static int oss_get_version (int fd, int *version, con= st char *typ) } #endif =20 -static int oss_open (int in, struct oss_params *req, - struct oss_params *obt, int *pfd, OSSConf* conf) +static int oss_open(int in, struct oss_params *req, audsettings *as, + struct oss_params *obt, int *pfd, Audiodev *dev) { + AudiodevOssOptions *oopts =3D &dev->u.oss; + AudiodevOssPerDirectionOptions *opdo =3D in ? oopts->oss_in : oopts->o= ss_out; + AudiodevPerDirectionOptions *pdo =3D in ? dev->in : dev->out; int fd; - int oflags =3D conf->exclusive ? O_EXCL : 0; + int oflags =3D (oopts->has_exclusive && oopts->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 opdo->has_dev ? opdo->dev : "/dev/dsp"; const char *typ =3D in ? "ADC" : "DAC"; +#ifdef USE_DSP_POLICY + int policy =3D oopts->has_dsp_policy ? oopts->dsp_policy : 5; +#endif =20 /* Kludge needed to have working mmap on Linux */ - oflags |=3D conf->try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY); + oflags |=3D (oopts->has_try_mmap && oopts->try_mmap) ? + O_RDWR : (in ? O_RDONLY : O_WRONLY); =20 fd =3D open (dspname, oflags | O_NONBLOCK); if (-1 =3D=3D fd) { @@ -285,6 +282,8 @@ static int oss_open (int in, struct oss_params *req, freq =3D req->freq; nchannels =3D req->nchannels; fmt =3D req->fmt; + req->nfrags =3D pdo->has_buffer_count ? pdo->buffer_count : 4; + req->fragsize =3D audio_buffer_bytes(pdo, as, 23220); =20 if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) { oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fm= t); @@ -308,18 +307,18 @@ static int oss_open (int in, struct oss_params *req, } =20 #ifdef USE_DSP_POLICY - if (conf->policy >=3D 0) { + if (policy >=3D 0) { int version; =20 if (!oss_get_version (fd, &version, typ)) { trace_oss_version(version); =20 if (version >=3D 0x040000) { - int policy =3D conf->policy; - if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) { + int policy2 =3D policy; + if (ioctl(fd, SNDCTL_DSP_POLICY, &policy2)) { oss_logerr2 (errno, typ, "Failed to set timing policy to %d\n", - conf->policy); + policy); goto err; } setfragment =3D 0; @@ -502,17 +501,16 @@ static int oss_init_out(HWVoiceOut *hw, struct audset= tings *as, int fd; AudioFormat effective_fmt; struct audsettings obt_as; - OSSConf *conf =3D drv_opaque; + Audiodev *dev =3D drv_opaque; + AudiodevOssOptions *oopts =3D &dev->u.oss; =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; =20 - if (oss_open (0, &req, &obt, &fd, conf)) { + if (oss_open(0, &req, as, &obt, &fd, dev)) { return -1; } =20 @@ -539,7 +537,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsetti= ngs *as, hw->samples =3D (obt.nfrags * obt.fragsize) >> hw->info.shift; =20 oss->mmapped =3D 0; - if (conf->try_mmap) { + if (oopts->has_try_mmap && oopts->try_mmap) { oss->pcm_buf =3D mmap ( NULL, hw->samples << hw->info.shift, @@ -597,7 +595,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsetti= ngs *as, } =20 oss->fd =3D fd; - oss->conf =3D conf; + oss->dev =3D dev; return 0; } =20 @@ -605,16 +603,12 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) { int trig; OSSVoiceOut *oss =3D (OSSVoiceOut *) hw; + AudiodevOssPerDirectionOptions *opdo =3D oss->dev->u.oss.oss_out; =20 switch (cmd) { case VOICE_ENABLE: { - va_list ap; - int poll_mode; - - va_start (ap, cmd); - poll_mode =3D va_arg (ap, int); - va_end (ap); + bool poll_mode =3D opdo->try_poll; =20 ldebug ("enabling voice\n"); if (poll_mode) { @@ -669,16 +663,14 @@ static int oss_init_in(HWVoiceIn *hw, struct audsetti= ngs *as, void *drv_opaque) int fd; AudioFormat effective_fmt; struct audsettings obt_as; - OSSConf *conf =3D drv_opaque; + Audiodev *dev =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, conf)) { + if (oss_open(1, &req, as, &obt, &fd, dev)) { return -1; } =20 @@ -712,7 +704,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsetting= s *as, void *drv_opaque) } =20 oss->fd =3D fd; - oss->conf =3D conf; + oss->dev =3D dev; return 0; } =20 @@ -803,16 +795,12 @@ static int oss_read (SWVoiceIn *sw, void *buf, int si= ze) static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...) { OSSVoiceIn *oss =3D (OSSVoiceIn *) hw; + AudiodevOssPerDirectionOptions *opdo =3D oss->dev->u.oss.oss_out; =20 switch (cmd) { case VOICE_ENABLE: { - va_list ap; - int poll_mode; - - va_start (ap, cmd); - poll_mode =3D va_arg (ap, int); - va_end (ap); + bool poll_mode =3D opdo->try_poll; =20 if (poll_mode) { oss_poll_in (hw); @@ -832,82 +820,42 @@ 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", - .exclusive =3D 0, - .policy =3D 5 -}; +static void oss_init_per_direction(AudiodevOssPerDirectionOptions **opdo, + bool *has_opdo) +{ + if (!*has_opdo) { + *opdo =3D g_malloc0(sizeof(AudiodevOssPerDirectionOptions)); + *has_opdo =3D true; + } + + if (!(*opdo)->has_try_poll) { + (*opdo)->try_poll =3D true; + (*opdo)->has_try_poll =3D true; + } +} =20 static void *oss_audio_init(Audiodev *dev) { - OSSConf *conf =3D g_malloc(sizeof(OSSConf)); - *conf =3D glob_conf; + AudiodevOssOptions *oopts; + assert(dev->driver =3D=3D AUDIODEV_DRIVER_OSS); =20 - if (access(conf->devpath_in, R_OK | W_OK) < 0 || - access(conf->devpath_out, R_OK | W_OK) < 0) { - g_free(conf); + oopts =3D &dev->u.oss; + oss_init_per_direction(&oopts->oss_in, &oopts->has_oss_in); + oss_init_per_direction(&oopts->oss_out, &oopts->has_oss_out); + + if (access(oopts->oss_in->has_dev ? oopts->oss_in->dev : "/dev/dsp", + R_OK | W_OK) < 0 || + access(oopts->oss_out->has_dev ? oopts->oss_out->dev : "/dev/dsp", + R_OK | W_OK) < 0) { return NULL; } - return conf; + return dev; } =20 static void oss_audio_fini (void *opaque) { - g_free(opaque); } =20 -static struct audio_option oss_options[] =3D { - { - .name =3D "FRAGSIZE", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.fragsize, - .descr =3D "Fragment size in bytes" - }, - { - .name =3D "NFRAGS", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.nfrags, - .descr =3D "Number of fragments" - }, - { - .name =3D "MMAP", - .tag =3D AUD_OPT_BOOL, - .valp =3D &glob_conf.try_mmap, - .descr =3D "Try using memory mapped access" - }, - { - .name =3D "DAC_DEV", - .tag =3D AUD_OPT_STR, - .valp =3D &glob_conf.devpath_out, - .descr =3D "Path to DAC device" - }, - { - .name =3D "ADC_DEV", - .tag =3D AUD_OPT_STR, - .valp =3D &glob_conf.devpath_in, - .descr =3D "Path to ADC device" - }, - { - .name =3D "EXCLUSIVE", - .tag =3D AUD_OPT_BOOL, - .valp =3D &glob_conf.exclusive, - .descr =3D "Open device in exclusive mode (vmix won't work)" - }, -#ifdef USE_DSP_POLICY - { - .name =3D "POLICY", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.policy, - .descr =3D "Set the timing policy of the device, -1 to use fragmen= t mode", - }, -#endif - { /* End of list */ } -}; - static struct audio_pcm_ops oss_pcm_ops =3D { .init_out =3D oss_init_out, .fini_out =3D oss_fini_out, @@ -925,7 +873,6 @@ static struct audio_pcm_ops oss_pcm_ops =3D { static struct audio_driver oss_audio_driver =3D { .name =3D "oss", .descr =3D "OSS http://www.opensound.com", - .options =3D oss_options, .init =3D oss_audio_init, .fini =3D oss_audio_fini, .pcm_ops =3D &oss_pcm_ops, --=20 2.20.1