From patchwork Wed Jan 16 23:37:15 2019 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: 1026320 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=209.51.188.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="RLyzQe95"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43g4BP2WLsz9sCX for ; Thu, 17 Jan 2019 11:06:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:38039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjvCt-0000xi-7S for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2019 19:06:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjul9-0004Qi-6q for qemu-devel@nongnu.org; Wed, 16 Jan 2019 18:38:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjul4-0003S6-Ke for qemu-devel@nongnu.org; Wed, 16 Jan 2019 18:38:11 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjul4-0003Kf-69 for qemu-devel@nongnu.org; Wed, 16 Jan 2019 18:38:06 -0500 Received: by mail-wr1-x442.google.com with SMTP id l9so8888921wrt.13 for ; Wed, 16 Jan 2019 15:38:03 -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=+GJrV0c5zzNT39TwSPxNd5uWTZp42OGxJwGSrdyqRJw=; b=RLyzQe952zw0PoyTjO6eYGpJpd4PMU4ruHmv7eubsIjkXWXmCrOtsyAfTaFud9tOLw qwGQZYENhRjIPttWpJ+d/N5QJPfxZsYnjZQoerD5y15+3Kz0Pd1Z1r0bBvn6BI1BRgja PoTo8xGtFiwChm1eCTbOZF7gqhD9ZBCZfqMrFUMUL5sbzYOR+rX1jZIufgn1VMWByNdC HLc7jnbLRXTrpwk/dgyRyvPlZext+3HIxkyH7c10KglZ44uzt5kts419A4JOxZxfnvCj fIgKamj696EVw/Dvobv2vKDvXxAn7r0UF/mU5/V4e/qmBcVEVOLIPoswtfbjy7RLve/U X6Ng== 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=+GJrV0c5zzNT39TwSPxNd5uWTZp42OGxJwGSrdyqRJw=; b=uF84/vjRpx6+lEXtEk3jYKhEXk21sD/D52lcxYZRfiSaKJ3FOggwy6rkW94lh81Lqq 7LpwlVAFG9MmAtRXcK8iEQ9i3+27keIzKvz4pJek92K2yFihfqlQKmb9OEFYfs8iX1HY C1N1+IIPHoU8usoiWK6xo8ZCTlO+67fN3GSNQHhzojk3TonUuoDx3kgfPlVTTK7KnI5j gMkxduvF3RYXB/tmm7FP3UPAbfuYp+N829uULwql26UHfSItD6aU6aK4qb1Cxh2WIq0p 4Eydui4B2YltnocYHjRVxOAzjZt5zTfrB2Z41pqcbVMyMgle97ZA1a6nKMenSgdgL7lF s5NA== X-Gm-Message-State: AJcUukdH1fUlJMcHImvcJdHoZ/f6dOs9UQskMFw+88mxx5bYWHhG9Ig4 +5oaF7VXI6Zjg9YN/a/9TgXMygGB0cg= X-Google-Smtp-Source: ALg8bN4JRfBBv+Pp2dab6ZPrR6B1hzZ4j/mSo5HINLyDeJO+/1GCf8EzvLQj74AaZVYY+Md4n7k7AA== X-Received: by 2002:adf:a58a:: with SMTP id g10mr9366125wrc.3.1547681882807; Wed, 16 Jan 2019 15:38:02 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-e4b0-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:e4b0::5]) by smtp.gmail.com with ESMTPSA id s66sm30760437wmf.34.2019.01.16.15.38.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 15:38:02 -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: Thu, 17 Jan 2019 00:37:15 +0100 Message-Id: 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::442 Subject: [Qemu-devel] [PATCH v3 42/50] 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_template.h | 46 ++++++++++++++++----------- audio/audio.c | 70 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 24 deletions(-) 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)); diff --git a/audio/audio.c b/audio/audio.c index 6bbbcd3e03..db42d89dc3 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -839,32 +839,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) @@ -1086,6 +1100,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; @@ -1223,6 +1257,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; @@ -1738,6 +1783,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); @@ -1888,9 +1938,13 @@ static void audio_validate_per_direction_opts( *has_pdo = true; } + 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)) { @@ -1898,6 +1952,10 @@ static void audio_validate_per_direction_opts( "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; @@ -1909,7 +1967,7 @@ static void audio_validate_per_direction_opts( } 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;