From patchwork Sun Dec 23 20:52:20 2018 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: 1018132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pWHJZatr"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43NFsy6nBmz9sDL for ; Mon, 24 Dec 2018 08:31:18 +1100 (AEDT) Received: from localhost ([127.0.0.1]:60028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbBLA-00055e-QJ for incoming@patchwork.ozlabs.org; Sun, 23 Dec 2018 16:31:16 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbAkH-0008O3-Dx for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbAkG-0003df-27 for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:09 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45127) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbAkF-0003WH-OC for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:07 -0500 Received: by mail-wr1-x441.google.com with SMTP id t6so10091170wrr.12 for ; Sun, 23 Dec 2018 12:53:06 -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=sHasOL13Sm4lJqugf3XEUgVeA6clMRH1eNhcHgdVAJw=; b=pWHJZatrWpkqjkvdsrDDYEW8oYKm25EwxCbDuvDs0Jc61h0rSwBcbcYVnDQIMdQoml uYCCj6fv7GWGfac3nkB0/U/8fw4wMSvyaxkv1zSup/IphBwFqHhyjrcADmnA+/mKR2ST oBlS4vn4KkB/lsQ59jSQOT4rRXEhDh/7GrkTQyLXW/oVjE/IDrULMq0eW19fs0zm6wd3 4L/FiKHq3iBLG6YBpdSnFm7Hhz48P0NvpJ69e2TaWYreHcWI+DJqZz7dGAFsky6603Uo Opf/HqsiQnD1vlNN24UwnaRxxiLuSIyvzuGplnHT2lpMkY6tvxc6qMHHm2eRpO31BFbZ pBhA== 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=sHasOL13Sm4lJqugf3XEUgVeA6clMRH1eNhcHgdVAJw=; b=OAgq4CcPhqYvoe8JK/2GP/yrY0F8mc8lsTCJ6EijvnlppX6CyYYBhvExJUuNznrmOl DWE0inFrnm4ttvXHzOWnUcGWnNlGrI0HX15zpA88BaQqeXwEM5gk61YyCzF5ewlZGFh0 vYAGx/oGuXDlDA65MSuxLrZTiJ05BNE61CoEYzn71pnfIfrukRcYsqg60PmXl0JA1Yv2 SjgXEvKEfeiHiaUsEE9j/c9J8aeafkF1hugqGQxaFV59nZhx5a07J5HNWC5LMwhH3L68 CLsgdNGsQPxJA7yQy5N1TdSKKoj3ArqYRJRtxQSo59mlrV6gMJ34YLYJhvFxhX9IciRA fVLg== X-Gm-Message-State: AJcUukcfgIeBE53fSLXQz0J7XAYzYfWJmvecwjfxagfcWsVWWDJMRX32 Y649yF/Aqz9CWZgelv/1t66w3zy7VBU= X-Google-Smtp-Source: ALg8bN7R+zlBOiKtf4GhRCImIWqcr7PtNjhDTHPhvmC0m6ifYDIAEGzKAXUxbkac+mA8ER/typV3Pw== X-Received: by 2002:adf:ae41:: with SMTP id u1mr9136811wrd.20.1545598385358; Sun, 23 Dec 2018 12:53:05 -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.53.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Dec 2018 12:53:04 -0800 (PST) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?utf-8?b?S8WRdsOhZ8OzLCBab2x0w6Fu?= To: qemu-devel@nongnu.org Date: Sun, 23 Dec 2018 21:52:20 +0100 Message-Id: <03189c11f5216339f472d06925582a8e20e7b21b.1545598229.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v2 44/52] audio: make mixeng optional 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Implementation of the previously added mixeng option. Signed-off-by: Kővágó, Zoltán --- audio/audio.c | 70 ++++++++++++++++++++++++++++++++++++++---- audio/audio_template.h | 46 ++++++++++++++++----------- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 7ba939560a..26ce25989f 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -840,32 +840,46 @@ static void audio_timer (void *opaque) */ size_t AUD_write(SWVoiceOut *sw, void *buf, size_t size) { + HWVoiceOut *hw; + if (!sw) { /* XXX: Consider options */ return size; } + hw = sw->hw; - if (!sw->hw->enabled) { + if (!hw->enabled) { dolog ("Writing to disabled voice %s\n", SW_NAME (sw)); return 0; } - return audio_pcm_sw_write(sw, buf, size); + if (hw->s->dev->out->mixeng) { + return audio_pcm_sw_write(sw, buf, size); + } else { + return hw->pcm_ops->write(hw, buf, size); + } } size_t AUD_read(SWVoiceIn *sw, void *buf, size_t size) { + HWVoiceIn *hw; + if (!sw) { /* XXX: Consider options */ return size; } + hw = sw->hw; - if (!sw->hw->enabled) { + if (!hw->enabled) { dolog ("Reading from disabled voice %s\n", SW_NAME (sw)); return 0; } - return audio_pcm_sw_read(sw, buf, size); + if (hw->s->dev->in->mixeng) { + return audio_pcm_sw_read(sw, buf, size); + } else { + return hw->pcm_ops->read(hw, buf, size); + } } int AUD_get_buffer_size_out (SWVoiceOut *sw) @@ -1087,6 +1101,26 @@ static void audio_run_out (AudioState *s) HWVoiceOut *hw = NULL; SWVoiceOut *sw; + if (!s->dev->out->mixeng) { + while ((hw = audio_pcm_hw_find_any_enabled_out(s, hw))) { + /* there is exactly 1 sw for each hw with no mixeng */ + sw = hw->sw_head.lh_first; + + if (hw->pending_disable) { + hw->enabled = 0; + hw->pending_disable = 0; + if (hw->pcm_ops->enable_out) { + hw->pcm_ops->enable_out(hw, false); + } + } + + if (sw->active) { + sw->callback.fn(sw->callback.opaque, INT_MAX); + } + } + return; + } + while ((hw = audio_pcm_hw_find_any_enabled_out(s, hw))) { size_t played, live, prev_rpos, free; int nb_live, cleanup_required; @@ -1224,6 +1258,17 @@ static void audio_run_in (AudioState *s) { HWVoiceIn *hw = NULL; + if (!s->dev->in->mixeng) { + while ((hw = audio_pcm_hw_find_any_enabled_in(s, hw))) { + /* there is exactly 1 sw for each hw with no mixeng */ + SWVoiceIn *sw = hw->sw_head.lh_first; + if (sw->active) { + sw->callback.fn(sw->callback.opaque, INT_MAX); + } + } + return; + } + while ((hw = audio_pcm_hw_find_any_enabled_in(s, hw))) { SWVoiceIn *sw; size_t captured = 0, min; @@ -1717,6 +1762,11 @@ CaptureVoiceOut *AUD_add_capture( s = audio_init(NULL, NULL); } + if (!s->dev->out->mixeng) { + dolog("Can't capture with mixeng disabled\n"); + goto err0; + } + if (audio_validate_settings (as)) { dolog ("Invalid settings were passed when trying to add capture\n"); audio_print_settings (as); @@ -1875,9 +1925,13 @@ QemuOptsList qemu_audiodev_opts = { static void validate_per_direction_opts(AudiodevPerDirectionOptions *pdo, Error **errp) { + if (!pdo->has_mixeng) { + pdo->has_mixeng = true; + pdo->mixeng = true; + } if (!pdo->has_fixed_settings) { pdo->has_fixed_settings = true; - pdo->fixed_settings = true; + pdo->fixed_settings = pdo->mixeng; } if (!pdo->fixed_settings && (pdo->has_frequency || pdo->has_channels || pdo->has_format)) { @@ -1885,6 +1939,10 @@ static void validate_per_direction_opts(AudiodevPerDirectionOptions *pdo, "You can't use frequency, channels or format with fixed-settings=off"); return; } + if (!pdo->mixeng && pdo->fixed_settings) { + error_setg(errp, "You can't use fixed-settings without mixeng"); + return; + } if (!pdo->has_frequency) { pdo->has_frequency = true; @@ -1896,7 +1954,7 @@ static void validate_per_direction_opts(AudiodevPerDirectionOptions *pdo, } if (!pdo->has_voices) { pdo->has_voices = true; - pdo->voices = 1; + pdo->voices = pdo->mixeng ? 1 : INT_MAX; } if (!pdo->has_format) { pdo->has_format = true; diff --git a/audio/audio_template.h b/audio/audio_template.h index 9ec565fc48..e5a4d6fa40 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -78,26 +78,32 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw) static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw) { - size_t samples; - if (!hw->pcm_ops) { - /* - * We should only end up here when using wavcapture hmp command (and not - * the wavcapture audio backend). - * It needs a lot of samples, otherwise you'll end up with "Could not - * mix X bytes into a capture buffer" warnings and a garbled capture. - */ - samples = 4096 * 4; - } else if (hw->pcm_ops->glue(buffer_size_, TYPE)) { - samples = hw->pcm_ops->glue(buffer_size_, TYPE)(hw); + if (hw->s->dev->TYPE->mixeng) { + size_t samples; + if (!hw->pcm_ops) { + /* + * We should only end up here when using wavcapture hmp command (and + * not the wavcapture audio backend). + * It needs a lot of samples, otherwise you'll end up with "Could + * not mix X bytes into a capture buffer" warnings and a garbled + * capture. + */ + samples = 4096 * 4; + } else if (hw->pcm_ops->glue(buffer_size_, TYPE)) { + samples = hw->pcm_ops->glue(buffer_size_, TYPE)(hw); + } else { + samples = 1024; /* todo better default */ + } + + if (audio_bug(__func__, samples == 0)) { + dolog("Attempted to allocate empty buffer\n"); + } + + HWBUF = g_malloc0(sizeof(STSampleBuffer) + sizeof(st_sample) * samples); + HWBUF->size = samples; } else { - samples = 1024; /* todo better default */ + HWBUF = NULL; } - if (audio_bug(__func__, samples == 0)) { - dolog("Attempted to allocate empty buffer\n"); - } - - HWBUF = g_malloc0(sizeof(STSampleBuffer) + sizeof(st_sample) * samples); - HWBUF->size = samples; } static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw) @@ -116,6 +122,10 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) { int samples; + if (!sw->s->dev->TYPE->mixeng) { + return 0; + } + samples = ((int64_t) sw->HWBUF->size << 32) / sw->ratio; sw->buf = audio_calloc(__func__, samples, sizeof(struct st_sample));