From nobody Sun Nov 9 14:50:02 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155069952449693.89506345989264; Wed, 20 Feb 2019 13:52:04 -0800 (PST) Received: from localhost ([127.0.0.1]:49432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwZmZ-0000Cd-Cr for importer@patchew.org; Wed, 20 Feb 2019 16:51:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwZZ9-0006EF-8i for qemu-devel@nongnu.org; Wed, 20 Feb 2019 16:38:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwZZ5-0000ph-HT for qemu-devel@nongnu.org; Wed, 20 Feb 2019 16:38:07 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:33171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwZZ5-0000SK-4R for qemu-devel@nongnu.org; Wed, 20 Feb 2019 16:38:03 -0500 Received: by mail-wm1-x344.google.com with SMTP id h22so5603236wmb.0 for ; Wed, 20 Feb 2019 13:37:53 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-6fd0-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:6fd0::5]) by smtp.gmail.com with ESMTPSA id o18sm66452489wrg.40.2019.02.20.13.37.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 13:37:51 -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=jSBA1Wv7wKta81FrmbJvc3DZ6wHHt8hTdkSdE3PLTzg=; b=WZbOSAE4ld49K7Fgk2cUKiXMpTJQ+6QJsU+iDwXJP3X6VIy5ZqA46CPqfS14DiViTL z62P7CnITRQUTRPal/uRMEfBMQdKky3BTrCCLvyrmH2qbmlyIP2mexE9bDpcV8FKT/lj LktsrJ2+lFd3nBgO9WMMbiK5iNOlBJUFvEkhasHsUCCQadbuDgNpvWPNeBCVrJDpoZYk dhBfzLiC9i5HkF/xKBqwZqxOAsrI7KxIkU9VFO4NQ9nCHL7IAVf/o7/Cwr4J2K3ek/Nk LVvyDtW95tFz8s1itZSu0ymNn75YKXdjXEQx7MXz+P4rEMVohuRfWBUWzSfeXpmMh2Si TEsg== 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=jSBA1Wv7wKta81FrmbJvc3DZ6wHHt8hTdkSdE3PLTzg=; b=je/choscQYCFWeDJ4vSd89xVUwqOID8pR0Zx2E/fEbeJZk01peY7y7sIa8pBRaawH0 FXrQPWrZJwsbLic+qo9vwX3MNW/ympgXr/cuhLkqh3QX6yc9RT3Hj7+BBJTOmnNhFML0 cOFXznEDY67lqc/3Z3/Eeq1DTeePCDdndTSRXDRCxnacR8wpHaLtzXpsygE/ZSHGVeec l3YLKj2rD93jBhfzf7oIq/9D9juKlV+4CcISqGbrrt2gAMJUuB0OM2840VT5dxxLTUEr DBLl+SDFU5FOuBZtxtPb3aYSGd1OTZENW08kJpbOI4oqgnddDKe4lJcKL2VKh/GRAx0A Sasg== X-Gm-Message-State: AHQUAuaHe3CYGUyxRnDifyif7cV1cgokOwAk/OJ3FemZbCQf+hpCWvYy Qy+58NwWJieHu81/NedoZQNzkQL5uLw= X-Google-Smtp-Source: AHgI3IZTMdFi0WdU6P8MVyZY8EE9yNopeSKNWuikuGAynnt/6tl4DHTvmP4UXY6Rgk9mHb7gJe8STg== X-Received: by 2002:a1c:a58c:: with SMTP id o134mr2131184wme.79.1550698671948; Wed, 20 Feb 2019 13:37:51 -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: Wed, 20 Feb 2019 22:37:36 +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::344 Subject: [Qemu-devel] [PATCH v5 07/14] dsoundaudio: 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/dsound_template.h | 6 ++--- audio/audio_legacy.c | 41 ++++++++++++++++++++++++++++ audio/dsoundaudio.c | 59 ++++++++++++----------------------------- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/audio/dsound_template.h b/audio/dsound_template.h index b439f33f58..8ece870c9e 100644 --- a/audio/dsound_template.h +++ b/audio/dsound_template.h @@ -167,17 +167,18 @@ static int dsound_init_out(HWVoiceOut *hw, struct aud= settings *as, dsound *s =3D drv_opaque; WAVEFORMATEX wfx; struct audsettings obt_as; - DSoundConf *conf =3D &s->conf; #ifdef DSBTYPE_IN const char *typ =3D "ADC"; DSoundVoiceIn *ds =3D (DSoundVoiceIn *) hw; DSCBUFFERDESC bd; DSCBCAPS bc; + AudiodevPerDirectionOptions *pdo =3D s->dev->u.dsound.in; #else const char *typ =3D "DAC"; DSoundVoiceOut *ds =3D (DSoundVoiceOut *) hw; DSBUFFERDESC bd; DSBCAPS bc; + AudiodevPerDirectionOptions *pdo =3D s->dev->u.dsound.out; #endif =20 if (!s->FIELD2) { @@ -193,8 +194,8 @@ static int dsound_init_out(HWVoiceOut *hw, struct audse= ttings *as, memset (&bd, 0, sizeof (bd)); bd.dwSize =3D sizeof (bd); bd.lpwfxFormat =3D &wfx; + bd.dwBufferBytes =3D audio_buffer_bytes(pdo, as, 92880); #ifdef DSBTYPE_IN - bd.dwBufferBytes =3D conf->bufsize_in; hr =3D IDirectSoundCapture_CreateCaptureBuffer ( s->dsound_capture, &bd, @@ -203,7 +204,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct audse= ttings *as, ); #else bd.dwFlags =3D DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2; - bd.dwBufferBytes =3D conf->bufsize_out; hr =3D IDirectSound_CreateSoundBuffer ( s->dsound, &bd, diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 086011fbff..17105e7239 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -120,6 +120,30 @@ static void get_frames_to_usecs(const char *env, uint3= 2_t *dst, bool *has_dst, } } =20 +static uint32_t samples_to_usecs(uint32_t samples, + AudiodevPerDirectionOptions *pdo) +{ + uint32_t channels =3D pdo->has_channels ? pdo->channels : 2; + return frames_to_usecs(samples / channels, pdo); +} + +static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions= *pdo) +{ + AudioFormat fmt =3D pdo->has_format ? pdo->format : AUDIO_FORMAT_S16; + uint32_t bytes_per_sample =3D audioformat_bytes_per_sample(fmt); + return samples_to_usecs(bytes / bytes_per_sample, pdo); +} + +static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_d= st, + AudiodevPerDirectionOptions *pdo) +{ + const char *val =3D getenv(env); + if (val) { + *dst =3D bytes_to_usecs(toui32(val), pdo); + *has_dst =3D true; + } +} + /* backend specific functions */ /* ALSA */ static void handle_alsa_per_direction( @@ -180,6 +204,19 @@ static void handle_coreaudio(Audiodev *dev) &dev->u.coreaudio.out->has_buffer_count); } =20 +/* dsound */ +static void handle_dsound(Audiodev *dev) +{ + get_millis_to_usecs("QEMU_DSOUND_LATENCY_MILLIS", + &dev->u.dsound.latency, &dev->u.dsound.has_latency= ); + get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_OUT", + &dev->u.dsound.out->buffer_len, + &dev->u.dsound.out->has_buffer_len, dev->u.dsound.o= ut); + get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_IN", + &dev->u.dsound.in->buffer_len, + &dev->u.dsound.in->has_buffer_len, dev->u.dsound.in= ); +} + /* general */ static void handle_per_direction( AudiodevPerDirectionOptions *pdo, const char *prefix) @@ -229,6 +266,10 @@ static AudiodevListEntry *legacy_opt(const char *drvna= me) handle_coreaudio(e->dev); break; =20 + case AUDIODEV_DRIVER_DSOUND: + handle_dsound(e->dev); + break; + default: break; } diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index 02fe777cba..a7d04b5033 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -32,6 +32,7 @@ =20 #define AUDIO_CAP "dsound" #include "audio_int.h" +#include "qemu/host-utils.h" =20 #include #include @@ -42,17 +43,11 @@ =20 /* #define DEBUG_DSOUND */ =20 -typedef struct { - int bufsize_in; - int bufsize_out; - int latency_millis; -} DSoundConf; - typedef struct { LPDIRECTSOUND dsound; LPDIRECTSOUNDCAPTURE dsound_capture; struct audsettings settings; - DSoundConf conf; + Audiodev *dev; } dsound; =20 typedef struct { @@ -248,9 +243,9 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( dsound_log_hresult (hr); } =20 -static DWORD millis_to_bytes (struct audio_pcm_info *info, DWORD millis) +static uint64_t usecs_to_bytes(struct audio_pcm_info *info, uint32_t usecs) { - return (millis * info->bytes_per_second) / 1000; + return muldiv64(usecs, info->bytes_per_second, 1000000); } =20 #ifdef DEBUG_DSOUND @@ -478,7 +473,7 @@ static int dsound_run_out (HWVoiceOut *hw, int live) LPVOID p1, p2; int bufsize; dsound *s =3D ds->s; - DSoundConf *conf =3D &s->conf; + AudiodevDsoundOptions *dso =3D &s->dev->u.dsound; =20 if (!dsb) { dolog ("Attempt to run empty with playback buffer\n"); @@ -501,14 +496,14 @@ static int dsound_run_out (HWVoiceOut *hw, int live) len =3D live << hwshift; =20 if (ds->first_time) { - if (conf->latency_millis) { + if (dso->latency) { DWORD cur_blat; =20 cur_blat =3D audio_ring_dist (wpos, ppos, bufsize); ds->first_time =3D 0; old_pos =3D wpos; old_pos +=3D - millis_to_bytes (&hw->info, conf->latency_millis) - cur_bl= at; + usecs_to_bytes(&hw->info, dso->latency) - cur_blat; old_pos %=3D bufsize; old_pos &=3D ~hw->info.align; } @@ -747,12 +742,6 @@ static int dsound_run_in (HWVoiceIn *hw) return decr; } =20 -static DSoundConf glob_conf =3D { - .bufsize_in =3D 16384, - .bufsize_out =3D 16384, - .latency_millis =3D 10 -}; - static void dsound_audio_fini (void *opaque) { HRESULT hr; @@ -788,8 +777,17 @@ static void *dsound_audio_init(Audiodev *dev) int err; HRESULT hr; dsound *s =3D g_malloc0(sizeof(dsound)); + AudiodevDsoundOptions *dso; + + assert(dev->driver =3D=3D AUDIODEV_DRIVER_DSOUND); + s->dev =3D dev; + dso =3D &dev->u.dsound; + + if (!dso->has_latency) { + dso->has_latency =3D true; + dso->latency =3D 10000; /* 10 ms */ + } =20 - s->conf =3D glob_conf; hr =3D CoInitialize (NULL); if (FAILED (hr)) { dsound_logerr (hr, "Could not initialize COM\n"); @@ -854,28 +852,6 @@ static void *dsound_audio_init(Audiodev *dev) return s; } =20 -static struct audio_option dsound_options[] =3D { - { - .name =3D "LATENCY_MILLIS", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.latency_millis, - .descr =3D "(undocumented)" - }, - { - .name =3D "BUFSIZE_OUT", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.bufsize_out, - .descr =3D "(undocumented)" - }, - { - .name =3D "BUFSIZE_IN", - .tag =3D AUD_OPT_INT, - .valp =3D &glob_conf.bufsize_in, - .descr =3D "(undocumented)" - }, - { /* End of list */ } -}; - static struct audio_pcm_ops dsound_pcm_ops =3D { .init_out =3D dsound_init_out, .fini_out =3D dsound_fini_out, @@ -893,7 +869,6 @@ static struct audio_pcm_ops dsound_pcm_ops =3D { static struct audio_driver dsound_audio_driver =3D { .name =3D "dsound", .descr =3D "DirectSound http://wikipedia.org/wiki/DirectSound= ", - .options =3D dsound_options, .init =3D dsound_audio_init, .fini =3D dsound_audio_fini, .pcm_ops =3D &dsound_pcm_ops, --=20 2.20.1