From patchwork Mon Jan 28 22:43:29 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: 1032290 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="UVgtYJcx"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43pQ1t5DDGz9sDK for ; Tue, 29 Jan 2019 09:54:58 +1100 (AEDT) Received: from localhost ([127.0.0.1]:39744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFns-00071Z-Kv for incoming@patchwork.ozlabs.org; Mon, 28 Jan 2019 17:54:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFdA-0007oK-Qa for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFd7-0003Pd-1A for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:52 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46768) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFd6-0003Ny-Mh for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:43:48 -0500 Received: by mail-wr1-x442.google.com with SMTP id l9so19893289wrt.13 for ; Mon, 28 Jan 2019 14:43:45 -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=/WpCKV8MsWS/5GWJUv56eUCSrUMworAvsqT17LI1kn8=; b=UVgtYJcxq/zb2YrAmzCGnl+uSlUeNNW1xF3MgacVembQr5MN2kbnOCyxFQ6QaCnase /W6NXdx5cXU2f0Exzp+dz0pXJwNQw0wOPYQJPjzIqBjCyD+8bOgptcb+mbHk+zheL77y eomvzNNhAfdQbeItwCDgUjxrSfNaUFSUWgGyQ3ARZXb6wggkFewsnDrDWxHaR5k0T1k+ pOz0CJAqh6tkwAywZmvrBKdNC0UsjuQsxS57K0l4DPMr8b034yeghkVa5ysUcg/V4Bt/ JJbUs6epxFDqKJx0rKnl1LceHetyKrK6jy349WhcHilYHohNvjPUXbiNs9a2TPdte58S RBhw== 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=/WpCKV8MsWS/5GWJUv56eUCSrUMworAvsqT17LI1kn8=; b=av5enGJpeuptUPYkDhYlFEGnP9apSsnR4cB1YaiNH+3+dBUt6MRnLT+iGkCKNmT4zs ErlOitsc6uawXcAiJXoV7AqMr4ut1Tw5880HxbHEKXT+Ub7lwhcBqNRFsc7HRIW1caGp fJZrOPoh5v5KLqGX6hTgQvTMw3rYZUFO3YEwfTShu+e2bD9/XKTdm149SUiVYOeKjA5Z FXX+HlrhSDgp2I2U/wolP+r4hJ3i8wVkLTLaYvTAAwkQt5OWSBuFO5JocV4ropNk/1Kn bbTkZYcHbXQtjn6XZzyeVeq5QIOWGK57KSn/p4Eun0okZmLgrzT+3yxlJi4JSFheaNcK aN5Q== X-Gm-Message-State: AJcUukdxfQ2dh7+yrWnRqcjAFG0OZELlzh6B2WnC5eCBPZoD6I6sg1B+ Kli7pwoVM5HP+HXWY4aSKaUXSYCS4LOQSA== X-Google-Smtp-Source: ALg8bN52UrcE6v8CHXQemoDmOKNbfLmIdK2G8Pzy6OCnlB88NSFltGhMDA3LE4Hy9xwWChK0DQgUDw== X-Received: by 2002:a5d:6a42:: with SMTP id t2mr25268758wrw.50.1548715424390; Mon, 28 Jan 2019 14:43:44 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-2152-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:2152::5]) by smtp.gmail.com with ESMTPSA id k7sm100088187wrl.51.2019.01.28.14.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 14:43:44 -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: Mon, 28 Jan 2019 23:43:29 +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 v4 06/14] coreaudio: port to -audiodev config 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" Signed-off-by: Kővágó, Zoltán --- audio/audio_legacy.c | 24 ++++++++++++++++++++++ audio/coreaudio.c | 48 +++++++++----------------------------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c index 8319dc5240..301934bf0c 100644 --- a/audio/audio_legacy.c +++ b/audio/audio_legacy.c @@ -109,6 +109,17 @@ static uint32_t frames_to_usecs(uint32_t frames, return (frames * 1000000 + freq / 2) / freq; } + +static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst, + AudiodevPerDirectionOptions *pdo) +{ + const char *val = getenv(env); + if (val) { + *dst = frames_to_usecs(toui32(val), pdo); + *has_dst = true; + } +} + /* backend specific functions */ /* ALSA */ static void handle_alsa_per_direction( @@ -166,6 +177,15 @@ static void handle_alsa(Audiodev *dev) &aopt->threshold, &aopt->has_threshold); } +/* coreaudio */ +static void handle_coreaudio(Audiodev *dev) +{ + get_frames_to_usecs("QEMU_COREAUDIO_BUFFER_SIZE", &dev->out->buffer_len, + &dev->out->has_buffer_len, dev->out); + get_int("QEMU_COREAUDIO_BUFFER_COUNT", + &dev->out->buffer_count, &dev->out->has_buffer_count); +} + /* general */ static void handle_per_direction( AudiodevPerDirectionOptions *pdo, const char *prefix) @@ -213,6 +233,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname) handle_alsa(e->dev); break; + case AUDIODEV_DRIVER_COREAUDIO: + handle_coreaudio(e->dev); + break; + default: break; } diff --git a/audio/coreaudio.c b/audio/coreaudio.c index 7d4225dbee..a7c1e418b6 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -36,11 +36,6 @@ #define MAC_OS_X_VERSION_10_6 1060 #endif -typedef struct { - int buffer_frames; - int nbuffers; -} CoreaudioConf; - typedef struct coreaudioVoiceOut { HWVoiceOut hw; pthread_mutex_t mutex; @@ -507,7 +502,9 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, int err; const char *typ = "playback"; AudioValueRange frameRange; - CoreaudioConf *conf = drv_opaque; + Audiodev *dev = drv_opaque; + AudiodevPerDirectionOptions *pdo = dev->out; + int frames; /* create mutex */ err = pthread_mutex_init(&core->mutex, NULL); @@ -538,16 +535,16 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, return -1; } - if (frameRange.mMinimum > conf->buffer_frames) { + frames = audio_buffer_frames(pdo, as, 11610); + if (frameRange.mMinimum > frames) { core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum; dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum); - } - else if (frameRange.mMaximum < conf->buffer_frames) { + } else if (frameRange.mMaximum < frames) { core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum; dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum); } else { - core->audioDevicePropertyBufferFrameSize = conf->buffer_frames; + core->audioDevicePropertyBufferFrameSize = frames; } /* set Buffer Frame Size */ @@ -568,7 +565,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, "Could not get device buffer frame size\n"); return -1; } - hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize; + hw->samples = (pdo->has_buffer_count ? pdo->buffer_count : 4) * + core->audioDevicePropertyBufferFrameSize; /* get StreamFormat */ status = coreaudio_get_streamformat(core->outputDeviceID, @@ -680,40 +678,15 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) return 0; } -static CoreaudioConf glob_conf = { - .buffer_frames = 512, - .nbuffers = 4, -}; - static void *coreaudio_audio_init(Audiodev *dev) { - CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf)); - *conf = glob_conf; - - return conf; + return dev; } static void coreaudio_audio_fini (void *opaque) { - g_free(opaque); } -static struct audio_option coreaudio_options[] = { - { - .name = "BUFFER_SIZE", - .tag = AUD_OPT_INT, - .valp = &glob_conf.buffer_frames, - .descr = "Size of the buffer in frames" - }, - { - .name = "BUFFER_COUNT", - .tag = AUD_OPT_INT, - .valp = &glob_conf.nbuffers, - .descr = "Number of buffers" - }, - { /* End of list */ } -}; - static struct audio_pcm_ops coreaudio_pcm_ops = { .init_out = coreaudio_init_out, .fini_out = coreaudio_fini_out, @@ -725,7 +698,6 @@ static struct audio_pcm_ops coreaudio_pcm_ops = { static struct audio_driver coreaudio_audio_driver = { .name = "coreaudio", .descr = "CoreAudio http://developer.apple.com/audio/coreaudio.html", - .options = coreaudio_options, .init = coreaudio_audio_init, .fini = coreaudio_audio_fini, .pcm_ops = &coreaudio_pcm_ops,