From patchwork Tue Sep 24 06:19:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11157961 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F33017EE for ; Tue, 24 Sep 2019 06:34:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E03120665 for ; Tue, 24 Sep 2019 06:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E03120665 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCeOr-0007kC-4s for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Sep 2019 02:34:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59231) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCeBA-0003bo-2H for qemu-devel@nongnu.org; Tue, 24 Sep 2019 02:20:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCeB7-0000s3-68 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 02:20:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCeB6-0000rK-Ms for qemu-devel@nongnu.org; Tue, 24 Sep 2019 02:20:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2A0013A82; Tue, 24 Sep 2019 06:19:59 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD79910018F8; Tue, 24 Sep 2019 06:19:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EAFC79CA7; Tue, 24 Sep 2019 08:19:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 11/16] spiceaudio: port to the new audio backend api Date: Tue, 24 Sep 2019 08:19:46 +0200 Message-Id: <20190924061951.27916-12-kraxel@redhat.com> In-Reply-To: <20190924061951.27916-1-kraxel@redhat.com> References: <20190924061951.27916-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 24 Sep 2019 06:19:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?unknown-8bit?b?S8WRdsOhZ8OzQHJlZGhhdC5jb20sIEdlcmQgSG9mZm1hbm4gPGty?= =?unknown-8bit?b?YXhlbEByZWRoYXQuY29tPiwgPT9VVEYtOD9xP1pvbHQ9QzM9QTFuPz0g?= =?unknown-8bit?b?PERpcnRZLmlDRS5odUBnbWFpbC5jb20+?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Kővágó, Zoltán Signed-off-by: Kővágó, Zoltán Message-id: 4d3356df9ccbffee2f710b93d456443c81e3f011.1568927990.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann --- audio/spiceaudio.c | 116 ++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 74 deletions(-) diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index 26873c7f22a5..ff4e4dcbb022 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -51,7 +51,7 @@ typedef struct SpiceVoiceOut { SpiceRateCtl rate; int active; uint32_t *frame; - uint32_t *fpos; + uint32_t fpos; uint32_t fsize; } SpiceVoiceOut; @@ -60,7 +60,6 @@ typedef struct SpiceVoiceIn { SpiceRecordInstance sin; SpiceRateCtl rate; int active; - uint32_t samples[LINE_IN_SAMPLES]; } SpiceVoiceIn; static const SpicePlaybackInterface playback_sif = { @@ -152,44 +151,40 @@ static void line_out_fini (HWVoiceOut *hw) spice_server_remove_interface (&out->sin.base); } -static size_t line_out_run (HWVoiceOut *hw, size_t live) +static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size) { - SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); - size_t rpos, decr; - size_t samples; + SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); + size_t decr; - if (!live) { - return 0; + if (!out->frame) { + spice_server_playback_get_buffer(&out->sin, &out->frame, &out->fsize); + out->fpos = 0; } - decr = rate_get_samples (&hw->info, &out->rate); - decr = MIN (live, decr); + if (out->frame) { + decr = rate_get_samples(&hw->info, &out->rate); + decr = MIN(out->fsize - out->fpos, decr); - samples = decr; - rpos = hw->rpos; - while (samples) { - int left_till_end_samples = hw->samples - rpos; - int len = MIN (samples, left_till_end_samples); + *size = decr << hw->info.shift; + } else { + rate_start(&out->rate); + } + return out->frame + out->fpos; +} + +static size_t line_out_put_buffer(HWVoiceOut *hw, void *buf, size_t size) +{ + SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw); - if (!out->frame) { - spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize); - out->fpos = out->frame; - } - if (out->frame) { - len = MIN (len, out->fsize); - hw->clip (out->fpos, hw->mix_buf + rpos, len); - out->fsize -= len; - out->fpos += len; - if (out->fsize == 0) { - spice_server_playback_put_samples (&out->sin, out->frame); - out->frame = out->fpos = NULL; - } - } - rpos = (rpos + len) % hw->samples; - samples -= len; + assert(buf == out->frame + out->fpos && out->fpos <= out->fsize); + out->fpos += size >> 2; + + if (out->fpos == out->fsize) { /* buffer full */ + spice_server_playback_put_samples(&out->sin, out->frame); + out->frame = NULL; } - hw->rpos = rpos; - return decr; + + return size; } static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) @@ -211,9 +206,9 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) } out->active = 0; if (out->frame) { - memset (out->fpos, 0, out->fsize << 2); + memset(out->frame + out->fpos, 0, (out->fsize - out->fpos) << 2); spice_server_playback_put_samples (&out->sin, out->frame); - out->frame = out->fpos = NULL; + out->frame = NULL; } spice_server_playback_stop (&out->sin); break; @@ -275,49 +270,20 @@ static void line_in_fini (HWVoiceIn *hw) spice_server_remove_interface (&in->sin.base); } -static size_t line_in_run(HWVoiceIn *hw) +static size_t line_in_read(HWVoiceIn *hw, void *buf, size_t len) { SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); - size_t num_samples; - int ready; - size_t len[2]; - uint64_t delta_samp; - const uint32_t *samples; + uint64_t delta_samp = rate_get_samples(&hw->info, &in->rate); + uint64_t to_read = MIN(len >> 2, delta_samp); + size_t ready = spice_server_record_get_samples(&in->sin, buf, to_read); - if (!(num_samples = hw->samples - audio_pcm_hw_get_live_in (hw))) { - return 0; - } - - delta_samp = rate_get_samples (&hw->info, &in->rate); - num_samples = MIN (num_samples, delta_samp); - - ready = spice_server_record_get_samples (&in->sin, in->samples, num_samples); - samples = in->samples; + /* XXX: do we need this? */ if (ready == 0) { - static const uint32_t silence[LINE_IN_SAMPLES]; - samples = silence; - ready = LINE_IN_SAMPLES; + memset(buf, 0, to_read << 2); + ready = to_read; } - num_samples = MIN (ready, num_samples); - - if (hw->wpos + num_samples > hw->samples) { - len[0] = hw->samples - hw->wpos; - len[1] = num_samples - len[0]; - } else { - len[0] = num_samples; - len[1] = 0; - } - - hw->conv (hw->conv_buf + hw->wpos, samples, len[0]); - - if (len[1]) { - hw->conv (hw->conv_buf, samples + len[0], len[1]); - } - - hw->wpos = (hw->wpos + num_samples) % hw->samples; - - return num_samples; + return ready << 2; } static int line_in_ctl (HWVoiceIn *hw, int cmd, ...) @@ -366,12 +332,14 @@ static int line_in_ctl (HWVoiceIn *hw, int cmd, ...) static struct audio_pcm_ops audio_callbacks = { .init_out = line_out_init, .fini_out = line_out_fini, - .run_out = line_out_run, + .write = audio_generic_write, + .get_buffer_out = line_out_get_buffer, + .put_buffer_out = line_out_put_buffer, .ctl_out = line_out_ctl, .init_in = line_in_init, .fini_in = line_in_fini, - .run_in = line_in_run, + .read = line_in_read, .ctl_in = line_in_ctl, };