From patchwork Fri Aug 21 15:37:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= X-Patchwork-Id: 509528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D39901402A9 for ; Sat, 22 Aug 2015 01:41:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=EW0LMLLj; dkim-atps=neutral Received: from localhost ([::1]:42172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoRn-0008C9-Qr for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2015 11:41:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoOB-0002M3-JR for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSoOA-00023e-6O for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:37:55 -0400 Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:36531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoO9-00023R-TB for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:37:54 -0400 Received: by wicja10 with SMTP id ja10so19031259wic.1 for ; Fri, 21 Aug 2015 08:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=4iS4vuiBtQ+7e5wxbeX2YrO7SkkKYCSCPZQBvjSIYF0=; b=EW0LMLLjCNylPsfBRu1kly0/z4BDO7/YZEODS/E4NKLZ31PTSzbeTMW8CQEIaMRfvv pvTX01tIH0xPMQwmbCW1jY7zGAjbBKOwZSFFMAF0ZFyfnnDPy/v7EFa3MY3zEHP9MVEA IXb3IQOgDV5VCpcJBL/EwMv6mE1MV0mKCoYAzs2HJ26XCfG3RGN4LnrUzwiDg/4t8+pY dhHn3bmM1YsQtgEO/HsB1e5Ku36s70pQad83vUj4jkEX58OA+cnuLQxOtTG7H77a3oxm WKmd1bwPalYgfOHARbIEnjlhRWkd90cs8ufWTyo8mBmOg3OWNUttNNoUtwARxa8u0ISy A3/Q== X-Received: by 10.194.121.163 with SMTP id ll3mr16897915wjb.142.1440171473320; Fri, 21 Aug 2015 08:37:53 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (178-164-172-216.pool.digikabel.hu. [178.164.172.216]) by smtp.gmail.com with ESMTPSA id v8sm10479895wjr.15.2015.08.21.08.37.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Aug 2015 08:37:52 -0700 (PDT) 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: Fri, 21 Aug 2015 17:37:11 +0200 Message-Id: <188b0a4bfe1ddcfb9b2c88adf0854556bc9648b0.1440171025.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22e Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2 15/49] dsoundaudio: port to -audiodev config X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kővágó, Zoltán --- audio/audio_legacy.c | 12 ++++++++++ audio/dsound_template.h | 6 ++--- audio/dsoundaudio.c | 59 ++++++++++++++----------------------------------- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 4be972e..bcf87ff 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -66,6 +66,16 @@ SimpleEnvMap coreaudio_map[] = { { /* End of list */ } }; +SimpleEnvMap dsound_map[] = { + { "QEMU_DSOUND_LATENCY_MILLIS", "latency", ENV_TRANSFORM_MILLIS_TO_USECS }, + { "QEMU_DSOUND_BUFSIZE_OUT", "out.buffer-len", + ENV_TRANSFORM_BYTES_TO_USECS_OUT }, + { "QEMU_DSOUND_BUFSIZE_IN", "in.buffer-len", + ENV_TRANSFORM_BYTES_TO_USECS_IN }, + + { /* End of list */ } +}; + static unsigned long long toull(const char *str) { unsigned long long ret; @@ -238,6 +248,8 @@ static void legacy_opt(const char *drv) handle_alsa(opts); } else if (strcmp(drv, "coreaudio") == 0) { handle_env_opts(opts, coreaudio_map); + } else if (strcmp(drv, "dsound") == 0) { + handle_env_opts(opts, dsound_map); } } diff --git a/audio/dsound_template.h b/audio/dsound_template.h index b439f33..96181ef 100644 --- a/audio/dsound_template.h +++ b/audio/dsound_template.h @@ -167,17 +167,18 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, dsound *s = drv_opaque; WAVEFORMATEX wfx; struct audsettings obt_as; - DSoundConf *conf = &s->conf; #ifdef DSBTYPE_IN const char *typ = "ADC"; DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; DSCBUFFERDESC bd; DSCBCAPS bc; + AudiodevPerDirectionOptions *pdo = s->dev->in; #else const char *typ = "DAC"; DSoundVoiceOut *ds = (DSoundVoiceOut *) hw; DSBUFFERDESC bd; DSBCAPS bc; + AudiodevPerDirectionOptions *pdo = s->dev->out; #endif if (!s->FIELD2) { @@ -193,8 +194,8 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, memset (&bd, 0, sizeof (bd)); bd.dwSize = sizeof (bd); bd.lpwfxFormat = &wfx; + bd.dwBufferBytes = audio_buffer_bytes(pdo, as, 92880); #ifdef DSBTYPE_IN - bd.dwBufferBytes = conf->bufsize_in; hr = IDirectSoundCapture_CreateCaptureBuffer ( s->dsound_capture, &bd, @@ -203,7 +204,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, ); #else bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2; - bd.dwBufferBytes = conf->bufsize_out; hr = IDirectSound_CreateSoundBuffer ( s->dsound, &bd, diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index d447e12..0a4a72d 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -31,6 +31,7 @@ #define AUDIO_CAP "dsound" #include "audio_int.h" +#include "qemu/host-utils.h" #include #include @@ -42,16 +43,10 @@ /* #define DEBUG_DSOUND */ 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; typedef struct { @@ -247,9 +242,9 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( dsound_log_hresult (hr); } -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); } #ifdef DEBUG_DSOUND @@ -477,7 +472,7 @@ static int dsound_run_out (HWVoiceOut *hw, int live) LPVOID p1, p2; int bufsize; dsound *s = ds->s; - DSoundConf *conf = &s->conf; + AudiodevDsoundOptions *dso = s->dev->dsound; if (!dsb) { dolog ("Attempt to run empty with playback buffer\n"); @@ -500,14 +495,14 @@ static int dsound_run_out (HWVoiceOut *hw, int live) len = live << hwshift; if (ds->first_time) { - if (conf->latency_millis) { + if (dso->latency) { DWORD cur_blat; cur_blat = audio_ring_dist (wpos, ppos, bufsize); ds->first_time = 0; old_pos = wpos; old_pos += - millis_to_bytes (&hw->info, conf->latency_millis) - cur_blat; + usecs_to_bytes(&hw->info, dso->latency) - cur_blat; old_pos %= bufsize; old_pos &= ~hw->info.align; } @@ -746,12 +741,6 @@ static int dsound_run_in (HWVoiceIn *hw) return decr; } -static DSoundConf glob_conf = { - .bufsize_in = 16384, - .bufsize_out = 16384, - .latency_millis = 10 -}; - static void dsound_audio_fini (void *opaque) { HRESULT hr; @@ -787,8 +776,17 @@ static void *dsound_audio_init(Audiodev *dev) int err; HRESULT hr; dsound *s = g_malloc0(sizeof(dsound)); + AudiodevDsoundOptions *dso; + + assert(dev->kind == AUDIODEV_DRIVER_DSOUND); + s->dev = dev; + dso = dev->dsound; + + if (!dso->has_latency) { + dso->has_latency = true; + dso->latency = 10000; /* 10 ms */ + } - s->conf = glob_conf; hr = CoInitialize (NULL); if (FAILED (hr)) { dsound_logerr (hr, "Could not initialize COM\n"); @@ -853,28 +851,6 @@ static void *dsound_audio_init(Audiodev *dev) return s; } -static struct audio_option dsound_options[] = { - { - .name = "LATENCY_MILLIS", - .tag = AUD_OPT_INT, - .valp = &glob_conf.latency_millis, - .descr = "(undocumented)" - }, - { - .name = "BUFSIZE_OUT", - .tag = AUD_OPT_INT, - .valp = &glob_conf.bufsize_out, - .descr = "(undocumented)" - }, - { - .name = "BUFSIZE_IN", - .tag = AUD_OPT_INT, - .valp = &glob_conf.bufsize_in, - .descr = "(undocumented)" - }, - { /* End of list */ } -}; - static struct audio_pcm_ops dsound_pcm_ops = { .init_out = dsound_init_out, .fini_out = dsound_fini_out, @@ -892,7 +868,6 @@ static struct audio_pcm_ops dsound_pcm_ops = { struct audio_driver dsound_audio_driver = { .name = "dsound", .descr = "DirectSound http://wikipedia.org/wiki/DirectSound", - .options = dsound_options, .init = dsound_audio_init, .fini = dsound_audio_fini, .pcm_ops = &dsound_pcm_ops,