From patchwork Fri Aug 21 15:37:14 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: 509564 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 8D52F140784 for ; Sat, 22 Aug 2015 02:01:33 +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=zSXMxDPx; dkim-atps=neutral Received: from localhost ([::1]:42332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSol1-0003Wk-O6 for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2015 12:01:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoOG-0002VI-Du for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSoOC-00024s-C3 for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:38:00 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:38650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoOB-00024V-W7 for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:37:56 -0400 Received: by wicja10 with SMTP id ja10so19171929wic.1 for ; Fri, 21 Aug 2015 08:37:55 -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=yurVnTG0z4Astb+4Zyr0cHslH7MxqOZgOEYWKnqMhp0=; b=zSXMxDPxL2Q6edvkzuHSW6FKxDwysSmwC8fTnVZqYxt02KFL1M2Do6bzXJW4pMV+py Lk/Tca+8AppVqsLACR1kpknq4WiNmlqKqTGrj0uNQ+OUy4JtFpH/bSAkFEI9RodT+pa4 Y6MfUbinsp+t80vDmQ2tr8j5vTH2RoQ7M6DcNxLvRgtcDrCHFw8t5875oUm1uELXeZhX da0huwRQuGdX22eDk55zNQnAVkW477Ag2/dOLhLCgm2P5FRGXEYq5fE8kbKn0igpxqLB jIp69+KI88aFogfBVIUDgy1O0bHDjprwWaRF6zeh6lcqq/Bnlz5GGogMJgV5UcERUNsO qhSA== X-Received: by 10.194.9.102 with SMTP id y6mr16557633wja.91.1440171475418; Fri, 21 Aug 2015 08:37:55 -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.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Aug 2015 08:37:55 -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:14 +0200 Message-Id: <9b46d5bd56d2797e5de19e432eb9238a4bc4e7b4.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::232 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2 18/49] paaudio: 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 | 11 ++++++++ audio/paaudio.c | 80 +++++++++++++++++++--------------------------------- 2 files changed, 40 insertions(+), 51 deletions(-) diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 3d9f212..3eab2b9 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -91,6 +91,15 @@ SimpleEnvMap oss_map[] = { { /* End of list */ } }; +SimpleEnvMap pa_map[] = { + { "QEMU_PA_SAMPLES", "buffer", ENV_TRANSFORM_SAMPLES_TO_USECS_OUT }, + { "QEMU_PA_SERVER", "server" }, + { "QEMU_PA_SINK", "sink.name" }, + { "QEMU_PA_SOURCE", "source.name" }, + + { /* End of list */ } +}; + static unsigned long long toull(const char *str) { unsigned long long ret; @@ -267,6 +276,8 @@ static void legacy_opt(const char *drv) handle_env_opts(opts, dsound_map); } else if (strcmp(drv, "oss") == 0) { handle_env_opts(opts, oss_map); + } else if (strcmp(drv, "pa") == 0) { + handle_env_opts(opts, pa_map); } } diff --git a/audio/paaudio.c b/audio/paaudio.c index dd46fa0..a53aaf6 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -1,6 +1,7 @@ /* public domain */ #include "qemu-common.h" #include "audio.h" +#include "qapi-visit.h" #include @@ -9,14 +10,7 @@ #include "audio_pt_int.h" typedef struct { - int samples; - char *server; - char *sink; - char *source; -} PAConf; - -typedef struct { - PAConf conf; + Audiodev *dev; pa_threaded_mainloop *mainloop; pa_context *context; } paaudio; @@ -31,6 +25,7 @@ typedef struct { void *pcm_buf; struct audio_pt pt; paaudio *g; + int samples; } PAVoiceOut; typedef struct { @@ -45,6 +40,7 @@ typedef struct { const void *read_data; size_t read_index, read_length; paaudio *g; + int samples; } PAVoiceIn; static void qpa_audio_fini(void *opaque); @@ -226,7 +222,7 @@ static void *qpa_thread_out (void *arg) } } - decr = to_mix = audio_MIN (pa->live, pa->g->conf.samples >> 2); + decr = to_mix = audio_MIN (pa->live, pa->samples >> 2); rpos = pa->rpos; if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) { @@ -318,7 +314,7 @@ static void *qpa_thread_in (void *arg) } } - incr = to_grab = audio_MIN (pa->dead, pa->g->conf.samples >> 2); + incr = to_grab = audio_MIN (pa->dead, pa->samples >> 2); wpos = pa->wpos; if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) { @@ -545,6 +541,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, struct audsettings obt_as = *as; PAVoiceOut *pa = (PAVoiceOut *) hw; paaudio *g = pa->g = drv_opaque; + AudiodevPaOptions *popts = g->dev->pa; + AudiodevPaPerDirectionOptions *ppdo = popts->sink; ss.format = audfmt_to_pa (as->fmt, as->endianness); ss.channels = as->nchannels; @@ -565,7 +563,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, g, "qemu", PA_STREAM_PLAYBACK, - g->conf.sink, + ppdo->has_name ? ppdo->name : NULL, &ss, NULL, /* channel map */ &ba, /* buffering attributes */ @@ -577,7 +575,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, } audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = g->conf.samples; + hw->samples = pa->samples = audio_buffer_samples(g->dev->out, &obt_as, + 46440); pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); pa->rpos = hw->rpos; if (!pa->pcm_buf) { @@ -611,6 +610,8 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) struct audsettings obt_as = *as; PAVoiceIn *pa = (PAVoiceIn *) hw; paaudio *g = pa->g = drv_opaque; + AudiodevPaOptions *popts = g->dev->pa; + AudiodevPaPerDirectionOptions *ppdo = popts->source; ss.format = audfmt_to_pa (as->fmt, as->endianness); ss.channels = as->nchannels; @@ -622,7 +623,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) g, "qemu", PA_STREAM_RECORD, - g->conf.source, + ppdo->has_name ? ppdo->name : NULL, &ss, NULL, /* channel map */ NULL, /* buffering attributes */ @@ -634,7 +635,8 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) } audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = g->conf.samples; + hw->samples = pa->samples = audio_buffer_samples(g->dev->in, &obt_as, + 46440); pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); pa->wpos = hw->wpos; if (!pa->pcm_buf) { @@ -808,14 +810,19 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...) } /* common */ -static PAConf glob_conf = { - .samples = 4096, -}; - static void *qpa_audio_init(Audiodev *dev) { - paaudio *g = g_malloc(sizeof(paaudio)); - g->conf = glob_conf; + paaudio *g; + AudiodevPaOptions *popts; + const char *server; + + assert(dev->kind == AUDIODEV_DRIVER_PA); + + g = g_malloc(sizeof(paaudio)); + popts = dev->pa; + server = popts->has_server ? popts->server : NULL; + + g->dev = dev; g->mainloop = NULL; g->context = NULL; @@ -825,14 +832,14 @@ static void *qpa_audio_init(Audiodev *dev) } g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop), - g->conf.server); + server); if (!g->context) { goto fail; } pa_context_set_state_callback (g->context, context_state_cb, g); - if (pa_context_connect (g->context, g->conf.server, 0, NULL) < 0) { + if (pa_context_connect (g->context, server, 0, NULL) < 0) { qpa_logerr (pa_context_errno (g->context), "pa_context_connect() failed\n"); goto fail; @@ -895,34 +902,6 @@ static void qpa_audio_fini (void *opaque) g_free(g); } -struct audio_option qpa_options[] = { - { - .name = "SAMPLES", - .tag = AUD_OPT_INT, - .valp = &glob_conf.samples, - .descr = "buffer size in samples" - }, - { - .name = "SERVER", - .tag = AUD_OPT_STR, - .valp = &glob_conf.server, - .descr = "server address" - }, - { - .name = "SINK", - .tag = AUD_OPT_STR, - .valp = &glob_conf.sink, - .descr = "sink device name" - }, - { - .name = "SOURCE", - .tag = AUD_OPT_STR, - .valp = &glob_conf.source, - .descr = "source device name" - }, - { /* End of list */ } -}; - static struct audio_pcm_ops qpa_pcm_ops = { .init_out = qpa_init_out, .fini_out = qpa_fini_out, @@ -940,7 +919,6 @@ static struct audio_pcm_ops qpa_pcm_ops = { struct audio_driver pa_audio_driver = { .name = "pa", .descr = "http://www.pulseaudio.org/", - .options = qpa_options, .init = qpa_audio_init, .fini = qpa_audio_fini, .pcm_ops = &qpa_pcm_ops,