From nobody Fri Nov 7 04:03:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545598750844522.8693811269593; Sun, 23 Dec 2018 12:59:10 -0800 (PST) Received: from localhost ([127.0.0.1]:42180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbAq5-0008HH-5O for importer@patchew.org; Sun, 23 Dec 2018 15:59:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbAjp-0007Rr-0O for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:52:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbAjm-0001oM-Lh for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:52:40 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:35867) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbAjm-0001kk-AV for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:52:38 -0500 Received: by mail-wr1-x442.google.com with SMTP id u4so10091652wrp.3 for ; Sun, 23 Dec 2018 12:52:38 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-24a3-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:24a3::5]) by smtp.gmail.com with ESMTPSA id g198sm25456920wmd.23.2018.12.23.12.52.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Dec 2018 12:52:36 -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=Y3icb4jpF6MQbt4owFVdSTjplHJtm83/PBbVt/5t8w4=; b=MocmvEHAYqB3Y/iKz4rjBHdWKaAAps3tBZZe+mtTRgqZcQySTgCx9+7ygwWQnGv2cX 9VrmVhV6kvBSxtlvSCf68jNpjGpvtI6B9hdkjEPSO7U4CK7qYMPaZhVxmYkoTO02aFZ6 vYJp1BZSRj82rkvxKWIP14ng9kkoK1py601qm4vAeBVLeqRvjlmmoCgmxdymgdw235NS 5bQZCM0MZVjXDaRasmn1D8fHKh+uTDc/CxdGK7635rCfv8OMnhuJ24SBcjbqLcwDUTrp E2wbuBwTmdx5SAW8p+6d1Tp/E6qFxUX+jdk9qX10dxMtFMCmuCESmg1ABeYfCX7V+Xs8 WH6Q== 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=Y3icb4jpF6MQbt4owFVdSTjplHJtm83/PBbVt/5t8w4=; b=IsOj5kOtqQQn/gdsJOjazDNoVCPIAos+eug+wnv/AfVmry7eT74eqXFva37rjpol0X bQYiLdWQMQgqdP8+pJ35R6M8fWEKvDOZf2j2HtDL7zyA952HyknL1BaCh1XJ6T/vm4Ip 8xkoFHOWB60C89yIU/T3iPakq6NjuMGnC8VG8EcW3coBjR9B4UtEBlcykglI0GIvnu0E PR36RUdbUAEqud3K99fuY2SO9Qw04V4qk6jse4lu+uNIoHatVOmVnxBUhRu4gcHll3aI 0eu/qPP1WOu3kQlPmurH41KJCvIGXebmTMZkQ9WsXu7hzhxSGUjwclN6FWRLopMJGLZO NDjA== X-Gm-Message-State: AJcUukduIC1iwpy+/+3UC0m/9pt+q3cNEllTfJjv7l7ioQH1UGKslD25 J1cuzr1Njcksa4guNyI9sUVazJiabGk= X-Google-Smtp-Source: ALg8bN6gneuFZJ7L+EYekuqBi8wzuIc/RZdJWj6sm4NJ0LHv1fzOC4Z0N+9lwRTbC4m2dw2RfrVdBA== X-Received: by 2002:adf:efd1:: with SMTP id i17mr9387418wrp.200.1545598356912; Sun, 23 Dec 2018 12:52:36 -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: Sun, 23 Dec 2018 21:51:43 +0100 Message-Id: <07f5a54a86ae8083a91111e06387c8dc892aaf4b.1545598229.git.DirtY.iCE.hu@gmail.com> 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::442 Subject: [Qemu-devel] [PATCH v2 07/52] alsaaudio: 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/alsaaudio.c | 314 ++++++++++++------------------------------- audio/audio_legacy.c | 64 +++++++++ 2 files changed, 152 insertions(+), 226 deletions(-) diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index 8302f3e882..6f75644538 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -23,6 +23,7 @@ */ #include "qemu/osdep.h" #include +#include "qapi/opts-visitor.h" #include "qemu-common.h" #include "qemu/main-loop.h" #include "audio.h" @@ -33,28 +34,9 @@ #define AUDIO_CAP "alsa" #include "audio_int.h" =20 -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; -} ALSAConf; - struct pollhlp { snd_pcm_t *handle; struct pollfd *pfds; - ALSAConf *conf; int count; int mask; }; @@ -66,6 +48,7 @@ typedef struct ALSAVoiceOut { void *pcm_buf; snd_pcm_t *handle; struct pollhlp pollhlp; + Audiodev *dev; } ALSAVoiceOut; =20 typedef struct ALSAVoiceIn { @@ -73,16 +56,13 @@ typedef struct ALSAVoiceIn { snd_pcm_t *handle; void *pcm_buf; struct pollhlp pollhlp; + Audiodev *dev; } ALSAVoiceIn; =20 struct alsa_params_req { int freq; snd_pcm_format_t fmt; int nchannels; - int size_in_usec; - int override_mask; - unsigned int buffer_size; - unsigned int period_size; }; =20 struct alsa_params_obt { @@ -408,7 +388,8 @@ static int alsa_to_audfmt (snd_pcm_format_t alsafmt, Au= dioFormat *fmt, =20 static void alsa_dump_info (struct alsa_params_req *req, struct alsa_params_obt *obt, - snd_pcm_format_t obtfmt) + snd_pcm_format_t obtfmt, + AudiodevPerDirectionOptions *pdo) { dolog ("parameter | requested value | obtained value\n"); dolog ("format | %10d | %10d\n", req->fmt, obtfmt); @@ -416,8 +397,9 @@ static void alsa_dump_info (struct alsa_params_req *req, req->nchannels, obt->nchannels); dolog ("frequency | %10d | %10d\n", req->freq, obt->freq); dolog ("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"= ); - dolog ("requested: buffer size %d period size %d\n", - req->buffer_size, req->period_size); + dolog ("requested: buffer len %" PRId64 " buffer count %" PRId64 "\n", + pdo->has_buffer_len ? pdo->buffer_len : 0, + pdo->has_buffer_count ? pdo->buffer_count : 0); dolog ("obtained: samples %ld\n", obt->samples); } =20 @@ -451,23 +433,25 @@ static void alsa_set_threshold (snd_pcm_t *handle, sn= d_pcm_uframes_t threshold) } } =20 -static int alsa_open (int in, struct alsa_params_req *req, - struct alsa_params_obt *obt, snd_pcm_t **handlep, - ALSAConf *conf) +static int alsa_open(bool in, struct alsa_params_req *req, + struct alsa_params_obt *obt, snd_pcm_t **handlep, + Audiodev *dev) { + AudiodevPerDirectionOptions *pdo =3D in ? dev->in : dev->out; + AudiodevAlsaOptions *aopts =3D &dev->u.alsa; + AudiodevAlsaPerDirectionOptions *apdo =3D + in ? aopts->alsa_in : aopts->alsa_out; 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 =3D in ? conf->pcm_name_in : conf->pcm_name_out; + const char *pcm_name =3D apdo->has_dev ? apdo->dev : "default"; snd_pcm_uframes_t obt_buffer_size; const char *typ =3D in ? "ADC" : "DAC"; snd_pcm_format_t obtfmt; =20 freq =3D req->freq; nchannels =3D req->nchannels; - size_in_usec =3D req->size_in_usec; =20 snd_pcm_hw_params_alloca (&hw_params); =20 @@ -527,79 +511,49 @@ static int alsa_open (int in, struct alsa_params_req = *req, goto err; } =20 - if (req->buffer_size) { - unsigned long obt; + if (pdo->buffer_count) { + if (pdo->buffer_len) { + int64_t req =3D pdo->buffer_len * pdo->buffer_count; =20 - if (size_in_usec) { int dir =3D 0; - unsigned int btime =3D req->buffer_size; + unsigned int btime =3D req; =20 - err =3D snd_pcm_hw_params_set_buffer_time_near ( - handle, - hw_params, - &btime, - &dir - ); - obt =3D btime; - } - else { - snd_pcm_uframes_t bsize =3D req->buffer_size; + err =3D snd_pcm_hw_params_set_buffer_time_near( + handle, hw_params, &btime, &dir); =20 - err =3D snd_pcm_hw_params_set_buffer_size_near ( - handle, - hw_params, - &bsize - ); - obt =3D bsize; - } - if (err < 0) { - alsa_logerr2 (err, typ, "Failed to set buffer %s to %d\n", - size_in_usec ? "time" : "size", req->buffer_size= ); - goto err; - } + if (err < 0) { + alsa_logerr2(err, typ, + "Failed to set buffer time to %" PRId64 "\n", + req); + goto err; + } =20 - if ((req->override_mask & 2) && (obt - req->buffer_size)) - dolog ("Requested buffer %s %u was rejected, using %lu\n", - size_in_usec ? "time" : "size", req->buffer_size, obt); + if (pdo->has_buffer_count && btime !=3D req) { + dolog("Requested buffer time %" PRId64 + " was rejected, using %u\n", req, btime); + } + } else { + dolog("Can't set buffer-count without buffer-len!\n"); + } } =20 - if (req->period_size) { - unsigned long obt; + if (pdo->buffer_len) { + int dir =3D 0; + unsigned int ptime =3D pdo->buffer_len; =20 - if (size_in_usec) { - int dir =3D 0; - unsigned int ptime =3D req->period_size; - - err =3D snd_pcm_hw_params_set_period_time_near ( - handle, - hw_params, - &ptime, - &dir - ); - obt =3D ptime; - } - else { - int dir =3D 0; - snd_pcm_uframes_t psize =3D req->period_size; - - err =3D snd_pcm_hw_params_set_period_size_near ( - handle, - hw_params, - &psize, - &dir - ); - obt =3D psize; - } + err =3D snd_pcm_hw_params_set_period_time_near(handle, hw_params, = &ptime, + &dir); =20 if (err < 0) { - alsa_logerr2 (err, typ, "Failed to set period %s to %d\n", - size_in_usec ? "time" : "size", req->period_size= ); + alsa_logerr2(err, typ, "Failed to set period time to %" PRId64= "\n", + pdo->buffer_len); goto err; } =20 - if (((req->override_mask & 1) && (obt - req->period_size))) - dolog ("Requested period %s %u was rejected, using %lu\n", - size_in_usec ? "time" : "size", req->period_size, obt); + if (pdo->has_buffer_len && ptime !=3D pdo->buffer_len) { + dolog("Requested period time %" PRId64 " was rejected, using %= d\n", + pdo->buffer_len, ptime); + } } =20 err =3D snd_pcm_hw_params (handle, hw_params); @@ -631,33 +585,10 @@ static int alsa_open (int in, struct alsa_params_req = *req, goto err; } =20 - if (!in && conf->threshold) { - snd_pcm_uframes_t threshold; - int bytes_per_sec; - - bytes_per_sec =3D freq << (nchannels =3D=3D 2); - - switch (obt->fmt) { - case AUDIO_FORMAT_S8: - case AUDIO_FORMAT_U8: - break; - - case AUDIO_FORMAT_S16: - case AUDIO_FORMAT_U16: - bytes_per_sec <<=3D 1; - break; - - case AUDIO_FORMAT_S32: - case AUDIO_FORMAT_U32: - bytes_per_sec <<=3D 2; - break; - - default: - abort(); - } - - threshold =3D (conf->threshold * bytes_per_sec) / 1000; - alsa_set_threshold (handle, threshold); + if (!in && aopts->has_threshold && aopts->threshold) { + struct audsettings as =3D { .freq =3D freq }; + alsa_set_threshold(handle, + audio_buffer_frames(pdo, &as, aopts->threshold)= ); } =20 obt->nchannels =3D nchannels; @@ -670,11 +601,11 @@ static int alsa_open (int in, struct alsa_params_req = *req, obt->nchannels !=3D req->nchannels || obt->freq !=3D req->freq) { dolog ("Audio parameters for %s\n", typ); - alsa_dump_info (req, obt, obtfmt); + alsa_dump_info (req, obt, obtfmt, pdo); } =20 #ifdef DEBUG - alsa_dump_info (req, obt, obtfmt); + alsa_dump_info (req, obt, obtfmt, pdo); #endif return 0; =20 @@ -800,19 +731,13 @@ static int alsa_init_out(HWVoiceOut *hw, struct audse= ttings *as, struct alsa_params_obt obt; snd_pcm_t *handle; struct audsettings obt_as; - ALSAConf *conf =3D drv_opaque; + Audiodev *dev =3D drv_opaque; =20 req.fmt =3D aud_to_alsafmt (as->fmt, as->endianness); req.freq =3D as->freq; req.nchannels =3D as->nchannels; - req.period_size =3D conf->period_size_out; - req.buffer_size =3D conf->buffer_size_out; - req.size_in_usec =3D conf->size_in_usec_out; - req.override_mask =3D - (conf->period_size_out_overridden ? 1 : 0) | - (conf->buffer_size_out_overridden ? 2 : 0); =20 - if (alsa_open (0, &req, &obt, &handle, conf)) { + if (alsa_open (0, &req, &obt, &handle, dev)) { return -1; } =20 @@ -833,7 +758,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsett= ings *as, } =20 alsa->handle =3D handle; - alsa->pollhlp.conf =3D conf; + alsa->dev =3D dev; return 0; } =20 @@ -873,16 +798,12 @@ static int alsa_voice_ctl (snd_pcm_t *handle, const c= har *typ, int ctl) static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...) { ALSAVoiceOut *alsa =3D (ALSAVoiceOut *) hw; + AudiodevAlsaPerDirectionOptions *apdo =3D alsa->dev->u.alsa.alsa_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 !apdo->has_try_poll || apdo->try_poll; =20 ldebug ("enabling voice\n"); if (poll_mode && alsa_poll_out (hw)) { @@ -911,19 +832,13 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsett= ings *as, void *drv_opaque) struct alsa_params_obt obt; snd_pcm_t *handle; struct audsettings obt_as; - ALSAConf *conf =3D drv_opaque; + Audiodev *dev =3D drv_opaque; =20 req.fmt =3D aud_to_alsafmt (as->fmt, as->endianness); req.freq =3D as->freq; req.nchannels =3D as->nchannels; - req.period_size =3D conf->period_size_in; - req.buffer_size =3D conf->buffer_size_in; - req.size_in_usec =3D conf->size_in_usec_in; - req.override_mask =3D - (conf->period_size_in_overridden ? 1 : 0) | - (conf->buffer_size_in_overridden ? 2 : 0); =20 - if (alsa_open (1, &req, &obt, &handle, conf)) { + if (alsa_open (1, &req, &obt, &handle, dev)) { return -1; } =20 @@ -944,7 +859,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettin= gs *as, void *drv_opaque) } =20 alsa->handle =3D handle; - alsa->pollhlp.conf =3D conf; + alsa->dev =3D dev; return 0; } =20 @@ -1086,16 +1001,12 @@ static int alsa_read (SWVoiceIn *sw, void *buf, int= size) static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...) { ALSAVoiceIn *alsa =3D (ALSAVoiceIn *) hw; + AudiodevAlsaPerDirectionOptions *apdo =3D alsa->dev->u.alsa.alsa_in; =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 !apdo->has_try_poll || apdo->try_poll; =20 ldebug ("enabling voice\n"); if (poll_mode && alsa_poll_in (hw)) { @@ -1118,88 +1029,40 @@ static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...) return -1; } =20 -static ALSAConf glob_conf =3D { - .buffer_size_out =3D 4096, - .period_size_out =3D 1024, - .pcm_name_out =3D "default", - .pcm_name_in =3D "default", -}; - static void *alsa_audio_init(Audiodev *dev) { - ALSAConf *conf =3D g_malloc(sizeof(ALSAConf)); - *conf =3D glob_conf; - return conf; + assert(dev->driver =3D=3D AUDIODEV_DRIVER_ALSA); + + /* + * need to define them, as otherwise alsa produces no sound + * doesn't set has_* so alsa_open can identify it wasn't set by the us= er + */ + if (!dev->out->has_buffer_count) { + dev->out->buffer_count =3D 4; + } + if (!dev->out->has_buffer_len) { + /* 1024 frames assuming 44100Hz */ + dev->out->buffer_len =3D 1024 * 1000000 / 44100; + } + + /* + * OptsVisitor sets unspecified optional fields to zero, but do not de= pend + * on it... + */ + if (!dev->in->has_buffer_count) { + dev->in->buffer_count =3D 0; + } + if (!dev->in->has_buffer_len) { + dev->in->buffer_len =3D 0; + } + + return dev; } =20 static void alsa_audio_fini (void *opaque) { - g_free(opaque); } =20 -static struct audio_option alsa_options[] =3D { - { - .name =3D "DAC_SIZE_IN_USEC", - .tag =3D AUD_OPT_BOOL, - .valp =3D &glob_conf.size_in_usec_out, - .descr =3D "DAC period/buffer size in microseconds (otherwis= e in frames)" - }, - { - .name =3D "DAC_PERIOD_SIZE", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.period_size_out, - .descr =3D "DAC period size (0 to go with system default)", - .overriddenp =3D &glob_conf.period_size_out_overridden - }, - { - .name =3D "DAC_BUFFER_SIZE", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.buffer_size_out, - .descr =3D "DAC buffer size (0 to go with system default)", - .overriddenp =3D &glob_conf.buffer_size_out_overridden - }, - { - .name =3D "ADC_SIZE_IN_USEC", - .tag =3D AUD_OPT_BOOL, - .valp =3D &glob_conf.size_in_usec_in, - .descr =3D - "ADC period/buffer size in microseconds (otherwise in frames)" - }, - { - .name =3D "ADC_PERIOD_SIZE", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.period_size_in, - .descr =3D "ADC period size (0 to go with system default)", - .overriddenp =3D &glob_conf.period_size_in_overridden - }, - { - .name =3D "ADC_BUFFER_SIZE", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.buffer_size_in, - .descr =3D "ADC buffer size (0 to go with system default)", - .overriddenp =3D &glob_conf.buffer_size_in_overridden - }, - { - .name =3D "THRESHOLD", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.threshold, - .descr =3D "(undocumented)" - }, - { - .name =3D "DAC_DEV", - .tag =3D AUD_OPT_STR, - .valp =3D &glob_conf.pcm_name_out, - .descr =3D "DAC device name (for instance dmix)" - }, - { - .name =3D "ADC_DEV", - .tag =3D AUD_OPT_STR, - .valp =3D &glob_conf.pcm_name_in, - .descr =3D "ADC device name" - }, - { /* End of list */ } -}; - static struct audio_pcm_ops alsa_pcm_ops =3D { .init_out =3D alsa_init_out, .fini_out =3D alsa_fini_out, @@ -1217,7 +1080,6 @@ static struct audio_pcm_ops alsa_pcm_ops =3D { static struct audio_driver alsa_audio_driver =3D { .name =3D "alsa", .descr =3D "ALSA http://www.alsa-project.org", - .options =3D alsa_options, .init =3D alsa_audio_init, .fini =3D alsa_audio_fini, .pcm_ops =3D &alsa_pcm_ops, diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 2242f06a5e..f91ce0c3e2 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -52,6 +52,17 @@ SimpleEnvMap global_map[] =3D { { /* End of list */ } }; =20 +SimpleEnvMap alsa_map[] =3D { + { "QEMU_AUDIO_DAC_TRY_POLL", "alsa-out.try-poll", ENV_TRANSFORM_BOOL }, + { "QEMU_AUDIO_ADC_TRY_POLL", "alsa-in.try-poll", ENV_TRANSFORM_BOOL }, + + { "QEMU_ALSA_THRESHOLD", "threshold", ENV_TRANSFORM_MILLIS_TO_USECS }, + { "QEMU_ALSA_DAC_DEV", "alsa-out.dev" }, + { "QEMU_ALSA_ADC_DEV", "alsa-in.dev" }, + + { /* End of list */ } +}; + static unsigned long long toull(const char *str) { unsigned long long ret; @@ -162,6 +173,54 @@ static void handle_env_opts(QemuOpts *opts, SimpleEnvM= ap *map) } } =20 +static void handle_alsa_side(QemuOpts *opts, int period, int buffer, + const char *usec_env, const char *period_env, + const char *buffer_env, const char *usec_opt, + const char *count_opt, bool in) +{ + char *usec_s, *period_s, *buffer_s; + bool usec =3D false; + + usec_s =3D getenv(usec_env); + if (usec_s) { + usec =3D toull(usec_s); + } + + period_s =3D getenv(period_env); + if (period_s) { + period =3D toull(period_s); + } + if (!usec) { + period =3D frames_to_usecs(opts, period, in); + } + if (period_s) { + qemu_opt_set(opts, usec_opt, tostr(period), &error_abort); + } + + buffer_s =3D getenv(buffer_env); + if (buffer_s) { + buffer =3D toull(buffer_s); + if (!usec) { + buffer =3D frames_to_usecs(opts, buffer, in); + } + printf("buffer %d period %d\n", buffer, period); + qemu_opt_set(opts, count_opt, tostr((buffer + period / 2) / period= ), + &error_abort); + } +} + +static void handle_alsa(QemuOpts *opts) +{ + handle_alsa_side(opts, 1024, 4096, + "QEMU_ALSA_DAC_SIZE_IN_USEC", "QEMU_ALSA_DAC_PERIOD_S= IZE", + "QEMU_ALSA_DAC_BUFFER_SIZE", + "out.buffer-len", "out.buffer-count", false); + handle_alsa_side(opts, 0, 0, + "QEMU_ALSA_ADC_SIZE_IN_USEC", "QEMU_ALSA_ADC_PERIOD_S= IZE", + "QEMU_ALSA_ADC_BUFFER_SIZE", + "in.buffer-len", "in.buffer-count", true); +} + static void legacy_opt(const char *drv) { QemuOpts *opts; @@ -170,6 +229,11 @@ static void legacy_opt(const char *drv) qemu_opt_set(opts, "driver", drv, &error_abort); =20 handle_env_opts(opts, global_map); + + if (strcmp(drv, "alsa") =3D=3D 0) { + handle_env_opts(opts, alsa_map); + handle_alsa(opts); + } } =20 void audio_handle_legacy_opts(void) --=20 2.20.1