From patchwork Fri Jan 24 04:47:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5933CC0218B for ; Fri, 24 Jan 2025 04:48:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBbX-0002CI-TU; Thu, 23 Jan 2025 23:47:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbBbW-0002C3-6k for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:38 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBbU-0004Zb-R6 for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:37 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-21680814d42so27383395ad.2 for ; Thu, 23 Jan 2025 20:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737694055; x=1738298855; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fWOg7aqqH8nu4hr/5SdBWnNPemUm1VuYD9oCJuZW3aE=; b=Yf7sW242y2ERKrpgJORkeLjo86ekfEL6eH3sBZ9d1b6A8UA/nf0MzkEUDXp/N+rIf8 nJryKhv+gIT2fyCGH4ssRRyvG0MP9KqB7Fch5KyP/kVN3SyM8/0Ge9qBHcORPvhyvlXf TQNWMSWS/oN8Pepqbv77tnOo+vphKP7AXKSN8Dxzb/FrSKjRXjo06txxwDimoYtVZLiq GNzsUb4nuKAXjEiR/EsMCjt5CBzLFyGQQi+qDz1nsHlMFMAGd+n91bu4jHoatPJEHHPa 65RMPpHk+/7FTy1/V1BVbYpVjBmmlthYR6/VKSUCjJy0WrLTvdBtXwZxdLKQ0KsJHAtM Qdjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737694055; x=1738298855; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fWOg7aqqH8nu4hr/5SdBWnNPemUm1VuYD9oCJuZW3aE=; b=JtA6iSawGieQcrAjIX+FwnkfOCCuyGpcW3ZQsGkt0zaNWkyXBdoaqfWADigM+h9v5Y W/NmahUPCWs5dy5Ff5I8UbGdjY+8bEHm1pb7DoUKCdtoCKJNj8LlFrEhbw1LKbWCCzTq 3guy5pjAfwmIRg2Dbp4wLDnG3UtxYuHXU6060E9FaIRZmyL9f3CCEOTCHrxjGIoD5iAT oyxo39Rl35WF/qlyKn3CZOWMgwccYoCkHxQYK/qH2UqVlcd2EwfHP+iG4/yyB5JgA6kg QZRve3U5EYjrDZWHQAymAvF7mox3GAJ6STqbhfPcHEJbJC7mm0LQAzPlpw5xqQC1GMDa Uukg== X-Gm-Message-State: AOJu0YyKOsMC8/5/QYDXUTnH8LcL5tCpSAhsC6QTL2D6jjAqNpQUKKdq Y11djh03lsX1RTwWwkVSXLUefe0LC0aJlmITwPZyGCCg5skdxX5AseGOOCJjxFc= X-Gm-Gg: ASbGncuLzRAfqVuE+o0XfxrbHtW0TmfJHTbrPvSrUufGW948JSjBNG+penskD2vSfcp fE5dTDSgIV06UuErzq49LFTRd89HAWGzwW6fneomZPDKbc/zap1TJa7zZH5j+DboHOsKHhOLPHw Ev5cxMdhWLGs8l7Vo8aWcE4oh2u2H5MBUA4epucP6jruX0VZy38q+aWRTjPWfb4BBtoZD+XzBsc GfWR3q+aIQcx5xpm1O+j8hFXBV+lHaN5xdtm/OGtv7HY0iQk1Md4qLJnC036zquQRbGgpDbWbt0 JSdH6BAy X-Google-Smtp-Source: AGHT+IEPyTfoIfaOFcNA3mKbm3rw1E6lj09kAm3vncu8SxIPog25Xj5NILL0mlaA9gfh8EvfVoY/CA== X-Received: by 2002:a05:6a20:a12a:b0:1e6:51d2:c8a3 with SMTP id adf61e73a8af0-1eb21481781mr42563687637.10.1737694055163; Thu, 23 Jan 2025 20:47:35 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a6b323esm886124b3a.60.2025.01.23.20.47.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 20:47:34 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 13:47:11 +0900 Subject: [PATCH v6 1/5] coreaudio: Remove unnecessary explicit casts MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v6-1-11fbcb6c47cf@daynix.com> References: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> In-Reply-To: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14.2 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org coreaudio had unnecessary explicit casts and they had extra whitespaces around them so remove them. Signed-off-by: Akihiko Odaki --- audio/coreaudio.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index cadd729d50537850d81718b9284efed5877d9185..0b67347ad7e8c43a77af308a1a3a654dd7084083 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -309,7 +309,7 @@ static OSStatus audioDeviceIOProc( UInt32 frameCount, pending_frames; void *out = outOutputData->mBuffers[0].mData; HWVoiceOut *hw = hwptr; - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr; + coreaudioVoiceOut *core = hwptr; size_t len; if (coreaudio_buf_lock (core, "audioDeviceIOProc")) { @@ -392,10 +392,10 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) } if (frameRange.mMinimum > core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum; + core->audioDevicePropertyBufferFrameSize = frameRange.mMinimum; dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum); } else if (frameRange.mMaximum < core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum; + core->audioDevicePropertyBufferFrameSize = frameRange.mMaximum; dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum); } else { core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting; From patchwork Fri Jan 24 04:47:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id ABE3EC02181 for ; Fri, 24 Jan 2025 04:48:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBbc-0002D2-NF; Thu, 23 Jan 2025 23:47:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbBbb-0002Ct-CB for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:43 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBbY-0004a9-TC for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:43 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2162c0f6a39so53293085ad.0 for ; Thu, 23 Jan 2025 20:47:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737694059; x=1738298859; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZIyI0qvbvpdUn6jjHdqpbqPdeIJiTAS6cWO23BAFteQ=; b=ak9j1OX2yxH+VMPk6TUMFlxu3gXMLTCIZrp7CIo9i/dxPnxwoTvRkZj4GaQK2pnEbc TEhqoSQ0hQcSM1886vPqfMhOTmgL4kePtiTJA8GFfVzQBWGtIeZMX8rrNWxs+Wk5gweV XUSUht7Kwa41IoWkQ87Pswr7hZucbC8Q6m1flVuaVY+aQgNioyQwwpY+okcxE0NAnfxM Oa996Vukc7CGxP2mUPbqgUKvq2zoWMTF2OuOa/GACq6SiaLRdvj5OsMSc8XI/0BGVCpB EhqQ7qVfpquCTrVMvbKcQqE71v2pQf4VgeOkDq6tC2uB6TNmr39JOXEdknY8TDw+ZJfj vwrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737694059; x=1738298859; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZIyI0qvbvpdUn6jjHdqpbqPdeIJiTAS6cWO23BAFteQ=; b=HuYuconE5xq2hp+GI4OQtO6Xxw7pFrj9uSB6RITe1gQVrkreJcurRLiyrtjXoWMwqW 0VLAYmUfxpohjANrlmHZ+S3k/G++vSOobPeR0vt50MrhYr90nlQw8I27prtd+9lURWmb ZLvdf9c2RmQ5MPPhb+tbG90nG2E4NVHms6L6wuBi9pZ/7A+NVdrzBDpy8Cz3uREZPFn0 EWdt6QGwqF7DGhxJEiNSUlmQDYhZYN/n3uOru9CxPkeG2KPovLbmc+oXUzYgpBIN4ZEC Ts5eHRPojcLD4Ep9qg40sKBLVKXd6Zlg4JrlqY4c/dZN+cD12qtuvIIek8W57Cl6sXr2 2wEg== X-Gm-Message-State: AOJu0YzzdQfhIVEtnqiRdxmtazS5+TXSoQTaEpcugbTlg5drNzSbinAn Oo+Ffa0CHZ91eiRKW9d8yyyI6t626W45stjhTzUU5jVfnoHF0Anv7oKCpzj0dpK/K2hFsj7G1y1 OQSo= X-Gm-Gg: ASbGncv/ST5KCzcQYHVfSnvzXURyUT+ibz7wCAZ+ZA/UdC/K0WIOYUpGp3isRM5qqRz 3CisrFVdSPglf4LUT8jmc7BbUrzHCt75vChbR/ywPTRZ+HzS/29lU63YCYfPEZVNZ+9+RCy2uZH xrInn5ZrW9AC18/cFQxizpv1n8JLfq8qdntZs7xMLTBdLSiPwg2cbaCByF1BgvThMh4TNrDFirH pNlsKQm9etGGTak6qz6/njbUiCuCd/J318DXM315ipRG574RSCrJNmI2dGAL0cyu85AeDezH+Yw wc9o2u6w X-Google-Smtp-Source: AGHT+IGhrTo6CVWbb3uHQp4Mgv3HV4QPhFdKwRgjV62bcXc2YN8u9DgJ5LRIcLIimTilPWR4FR6txQ== X-Received: by 2002:a05:6a21:6d9f:b0:1e1:ad90:dda6 with SMTP id adf61e73a8af0-1eb697c1bb0mr10235028637.20.1737694059446; Thu, 23 Jan 2025 20:47:39 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a6b2ed8sm847555b3a.41.2025.01.23.20.47.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 20:47:39 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 13:47:12 +0900 Subject: [PATCH v6 2/5] coreaudio: Improve naming MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v6-2-11fbcb6c47cf@daynix.com> References: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> In-Reply-To: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14.2 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org coreaudio had names that are not conforming to QEMU codding style. coreaudioVoiceOut also had some members that are prefixed with redundant words like "output" or "audio". Global names included "out" to tell they are specific to output devices, but this rule was not completely enforced. The frame size had three different names "frameSize", "bufferFrameSize", and "frameCount". Replace identifiers to fix these problems. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé --- audio/coreaudio.m | 193 +++++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 95 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index 0b67347ad7e8c43a77af308a1a3a654dd7084083..c3ede586bbee1711d6a798175995b8db7dc89398 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -33,37 +33,37 @@ #define AUDIO_CAP "coreaudio" #include "audio_int.h" -typedef struct coreaudioVoiceOut { +typedef struct CoreaudioVoiceOut { HWVoiceOut hw; pthread_mutex_t buf_mutex; - AudioDeviceID outputDeviceID; - int frameSizeSetting; - uint32_t bufferCount; - UInt32 audioDevicePropertyBufferFrameSize; + AudioDeviceID device_id; + int frame_size_setting; + uint32_t buffer_count; + UInt32 device_frame_size; AudioDeviceIOProcID ioprocid; bool enabled; -} coreaudioVoiceOut; +} CoreaudioVoiceOut; -static const AudioObjectPropertyAddress voice_addr = { +static const AudioObjectPropertyAddress voice_out_addr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain }; -static OSStatus coreaudio_get_voice(AudioDeviceID *id) +static OSStatus coreaudio_get_voice_out(AudioDeviceID *id) { UInt32 size = sizeof(*id); return AudioObjectGetPropertyData(kAudioObjectSystemObject, - &voice_addr, + &voice_out_addr, 0, NULL, &size, id); } -static OSStatus coreaudio_get_framesizerange(AudioDeviceID id, - AudioValueRange *framerange) +static OSStatus coreaudio_get_out_framesizerange(AudioDeviceID id, + AudioValueRange *framerange) { UInt32 size = sizeof(*framerange); AudioObjectPropertyAddress addr = { @@ -80,7 +80,7 @@ static OSStatus coreaudio_get_framesizerange(AudioDeviceID id, framerange); } -static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize) +static OSStatus coreaudio_get_out_framesize(AudioDeviceID id, UInt32 *framesize) { UInt32 size = sizeof(*framesize); AudioObjectPropertyAddress addr = { @@ -97,7 +97,7 @@ static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize) framesize); } -static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize) +static OSStatus coreaudio_set_out_framesize(AudioDeviceID id, UInt32 *framesize) { UInt32 size = sizeof(*framesize); AudioObjectPropertyAddress addr = { @@ -114,8 +114,8 @@ static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize) framesize); } -static OSStatus coreaudio_set_streamformat(AudioDeviceID id, - AudioStreamBasicDescription *d) +static OSStatus coreaudio_set_out_streamformat(AudioDeviceID id, + AudioStreamBasicDescription *d) { UInt32 size = sizeof(*d); AudioObjectPropertyAddress addr = { @@ -132,7 +132,7 @@ static OSStatus coreaudio_set_streamformat(AudioDeviceID id, d); } -static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result) +static OSStatus coreaudio_get_out_isrunning(AudioDeviceID id, UInt32 *result) { UInt32 size = sizeof(*result); AudioObjectPropertyAddress addr = { @@ -242,7 +242,8 @@ static void G_GNUC_PRINTF (3, 4) coreaudio_logerr2 ( #define coreaudio_playback_logerr(status, ...) \ coreaudio_logerr2(status, "playback", __VA_ARGS__) -static int coreaudio_buf_lock (coreaudioVoiceOut *core, const char *fn_name) +static int coreaudio_voice_out_buf_lock(CoreaudioVoiceOut *core, + const char *fn_name) { int err; @@ -255,7 +256,8 @@ static int coreaudio_buf_lock (coreaudioVoiceOut *core, const char *fn_name) return 0; } -static int coreaudio_buf_unlock (coreaudioVoiceOut *core, const char *fn_name) +static int coreaudio_voice_out_buf_unlock(CoreaudioVoiceOut *core, + const char *fn_name) { int err; @@ -268,20 +270,20 @@ static int coreaudio_buf_unlock (coreaudioVoiceOut *core, const char *fn_name) return 0; } -#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \ - static ret_type glue(coreaudio_, name)args_decl \ - { \ - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; \ - ret_type ret; \ - \ - if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \ - return 0; \ - } \ - \ - ret = glue(audio_generic_, name)args; \ - \ - coreaudio_buf_unlock(core, "coreaudio_" #name); \ - return ret; \ +#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \ + static ret_type glue(coreaudio_, name)args_decl \ + { \ + CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw; \ + ret_type ret; \ + \ + if (coreaudio_voice_out_buf_lock(core, "coreaudio_" #name)) { \ + return 0; \ + } \ + \ + ret = glue(audio_generic_, name)args; \ + \ + coreaudio_voice_out_buf_unlock(core, "coreaudio_" #name); \ + return ret; \ } COREAUDIO_WRAPPER_FUNC(buffer_get_free, size_t, (HWVoiceOut *hw), (hw)) COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), @@ -297,7 +299,7 @@ static ret_type glue(coreaudio_, name)args_decl \ * callback to feed audiooutput buffer. called without BQL. * allowed to lock "buf_mutex", but disallowed to have any other locks. */ -static OSStatus audioDeviceIOProc( +static OSStatus out_device_ioproc( AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, @@ -306,33 +308,33 @@ static OSStatus audioDeviceIOProc( const AudioTimeStamp *inOutputTime, void *hwptr) { - UInt32 frameCount, pending_frames; + UInt32 frame_size, pending_frames; void *out = outOutputData->mBuffers[0].mData; HWVoiceOut *hw = hwptr; - coreaudioVoiceOut *core = hwptr; + CoreaudioVoiceOut *core = hwptr; size_t len; - if (coreaudio_buf_lock (core, "audioDeviceIOProc")) { + if (coreaudio_voice_out_buf_lock (core, "out_device_ioproc")) { inInputTime = 0; return 0; } - if (inDevice != core->outputDeviceID) { - coreaudio_buf_unlock (core, "audioDeviceIOProc(old device)"); + if (inDevice != core->device_id) { + coreaudio_voice_out_buf_unlock (core, "out_device_ioproc(old device)"); return 0; } - frameCount = core->audioDevicePropertyBufferFrameSize; + frame_size = core->device_frame_size; pending_frames = hw->pending_emul / hw->info.bytes_per_frame; /* if there are not enough samples, set signal and return */ - if (pending_frames < frameCount) { + if (pending_frames < frame_size) { inInputTime = 0; - coreaudio_buf_unlock (core, "audioDeviceIOProc(empty)"); + coreaudio_voice_out_buf_unlock (core, "out_device_ioproc(empty)"); return 0; } - len = frameCount * hw->info.bytes_per_frame; + len = frame_size * hw->info.bytes_per_frame; while (len) { size_t write_len, start; @@ -348,16 +350,16 @@ static OSStatus audioDeviceIOProc( out += write_len; } - coreaudio_buf_unlock (core, "audioDeviceIOProc"); + coreaudio_voice_out_buf_unlock (core, "out_device_ioproc"); return 0; } -static OSStatus init_out_device(coreaudioVoiceOut *core) +static OSStatus init_out_device(CoreaudioVoiceOut *core) { OSStatus status; - AudioValueRange frameRange; + AudioValueRange framerange; - AudioStreamBasicDescription streamBasicDescription = { + AudioStreamBasicDescription stream_basic_description = { .mBitsPerChannel = core->hw.info.bits, .mBytesPerFrame = core->hw.info.bytes_per_frame, .mBytesPerPacket = core->hw.info.bytes_per_frame, @@ -368,20 +370,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) .mSampleRate = core->hw.info.freq }; - status = coreaudio_get_voice(&core->outputDeviceID); + status = coreaudio_get_voice_out(&core->device_id); if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not get default output Device\n"); return status; } - if (core->outputDeviceID == kAudioDeviceUnknown) { + if (core->device_id == kAudioDeviceUnknown) { dolog ("Could not initialize playback - Unknown Audiodevice\n"); return status; } /* get minimum and maximum buffer frame sizes */ - status = coreaudio_get_framesizerange(core->outputDeviceID, - &frameRange); + status = coreaudio_get_out_framesizerange(core->device_id, + &framerange); if (status == kAudioHardwareBadObjectError) { return 0; } @@ -391,32 +393,32 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return status; } - if (frameRange.mMinimum > core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize = frameRange.mMinimum; - dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum); - } else if (frameRange.mMaximum < core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize = frameRange.mMaximum; - dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum); + if (framerange.mMinimum > core->frame_size_setting) { + core->device_frame_size = framerange.mMinimum; + dolog ("warning: Upsizing Buffer Frames to %f\n", framerange.mMinimum); + } else if (framerange.mMaximum < core->frame_size_setting) { + core->device_frame_size = framerange.mMaximum; + dolog ("warning: Downsizing Buffer Frames to %f\n", framerange.mMaximum); } else { - core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting; + core->device_frame_size = core->frame_size_setting; } /* set Buffer Frame Size */ - status = coreaudio_set_framesize(core->outputDeviceID, - &core->audioDevicePropertyBufferFrameSize); + status = coreaudio_set_out_framesize(core->device_id, + &core->device_frame_size); if (status == kAudioHardwareBadObjectError) { return 0; } if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not set device buffer frame size %" PRIu32 "\n", - (uint32_t)core->audioDevicePropertyBufferFrameSize); + (uint32_t)core->device_frame_size); return status; } /* get Buffer Frame Size */ - status = coreaudio_get_framesize(core->outputDeviceID, - &core->audioDevicePropertyBufferFrameSize); + status = coreaudio_get_out_framesize(core->device_id, + &core->device_frame_size); if (status == kAudioHardwareBadObjectError) { return 0; } @@ -425,19 +427,19 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) "Could not get device buffer frame size\n"); return status; } - core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize; + core->hw.samples = core->buffer_count * core->device_frame_size; /* set Samplerate */ - status = coreaudio_set_streamformat(core->outputDeviceID, - &streamBasicDescription); + status = coreaudio_set_out_streamformat(core->device_id, + &stream_basic_description); if (status == kAudioHardwareBadObjectError) { return 0; } if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not set samplerate %lf\n", - streamBasicDescription.mSampleRate); - core->outputDeviceID = kAudioDeviceUnknown; + stream_basic_description.mSampleRate); + core->device_id = kAudioDeviceUnknown; return status; } @@ -452,8 +454,8 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) * with the callers of AudioObjectGetPropertyData. */ core->ioprocid = NULL; - status = AudioDeviceCreateIOProcID(core->outputDeviceID, - audioDeviceIOProc, + status = AudioDeviceCreateIOProcID(core->device_id, + out_device_ioproc, &core->hw, &core->ioprocid); if (status == kAudioHardwareBadDeviceError) { @@ -461,20 +463,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) } if (status != kAudioHardwareNoError || core->ioprocid == NULL) { coreaudio_playback_logerr (status, "Could not set IOProc\n"); - core->outputDeviceID = kAudioDeviceUnknown; + core->device_id = kAudioDeviceUnknown; return status; } return 0; } -static void fini_out_device(coreaudioVoiceOut *core) +static void fini_out_device(CoreaudioVoiceOut *core) { OSStatus status; UInt32 isrunning; /* stop playback */ - status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + status = coreaudio_get_out_isrunning(core->device_id, &isrunning); if (status != kAudioHardwareBadObjectError) { if (status != kAudioHardwareNoError) { coreaudio_logerr(status, @@ -482,7 +484,7 @@ static void fini_out_device(coreaudioVoiceOut *core) } if (isrunning) { - status = AudioDeviceStop(core->outputDeviceID, core->ioprocid); + status = AudioDeviceStop(core->device_id, core->ioprocid); if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) { coreaudio_logerr(status, "Could not stop playback\n"); } @@ -490,20 +492,20 @@ static void fini_out_device(coreaudioVoiceOut *core) } /* remove callback */ - status = AudioDeviceDestroyIOProcID(core->outputDeviceID, + status = AudioDeviceDestroyIOProcID(core->device_id, core->ioprocid); if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) { coreaudio_logerr(status, "Could not remove IOProc\n"); } - core->outputDeviceID = kAudioDeviceUnknown; + core->device_id = kAudioDeviceUnknown; } -static void update_device_playback_state(coreaudioVoiceOut *core) +static void update_out_device_playback_state(CoreaudioVoiceOut *core) { OSStatus status; UInt32 isrunning; - status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + status = coreaudio_get_out_isrunning(core->device_id, &isrunning); if (status != kAudioHardwareNoError) { if (status != kAudioHardwareBadObjectError) { coreaudio_logerr(status, @@ -516,7 +518,7 @@ static void update_device_playback_state(coreaudioVoiceOut *core) if (core->enabled) { /* start playback */ if (!isrunning) { - status = AudioDeviceStart(core->outputDeviceID, core->ioprocid); + status = AudioDeviceStart(core->device_id, core->ioprocid); if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) { coreaudio_logerr (status, "Could not resume playback\n"); } @@ -524,7 +526,7 @@ static void update_device_playback_state(coreaudioVoiceOut *core) } else { /* stop playback */ if (isrunning) { - status = AudioDeviceStop(core->outputDeviceID, + status = AudioDeviceStop(core->device_id, core->ioprocid); if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) { coreaudio_logerr(status, "Could not pause playback\n"); @@ -534,22 +536,22 @@ static void update_device_playback_state(coreaudioVoiceOut *core) } /* called without BQL. */ -static OSStatus handle_voice_change( +static OSStatus handle_voice_out_change( AudioObjectID in_object_id, UInt32 in_number_addresses, const AudioObjectPropertyAddress *in_addresses, void *in_client_data) { - coreaudioVoiceOut *core = in_client_data; + CoreaudioVoiceOut *core = in_client_data; bql_lock(); - if (core->outputDeviceID) { + if (core->device_id) { fini_out_device(core); } if (!init_out_device(core)) { - update_device_playback_state(core); + update_out_device_playback_state(core); } bql_unlock(); @@ -560,7 +562,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque) { OSStatus status; - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; + CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw; int err; Audiodev *dev = drv_opaque; AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out; @@ -578,13 +580,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, as->fmt = AUDIO_FORMAT_F32; audio_pcm_init_info (&hw->info, as); - core->frameSizeSetting = audio_buffer_frames( + core->frame_size_setting = audio_buffer_frames( qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); - core->bufferCount = cpdo->has_buffer_count ? cpdo->buffer_count : 4; + core->buffer_count = cpdo->has_buffer_count ? cpdo->buffer_count : 4; status = AudioObjectAddPropertyListener(kAudioObjectSystemObject, - &voice_addr, handle_voice_change, + &voice_out_addr, + handle_voice_out_change, core); if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, @@ -594,8 +597,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, if (init_out_device(core)) { status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, - &voice_addr, - handle_voice_change, + &voice_out_addr, + handle_voice_out_change, core); if (status != kAudioHardwareNoError) { coreaudio_playback_logerr(status, @@ -612,11 +615,11 @@ static void coreaudio_fini_out (HWVoiceOut *hw) { OSStatus status; int err; - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; + CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw; status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, - &voice_addr, - handle_voice_change, + &voice_out_addr, + handle_voice_out_change, core); if (status != kAudioHardwareNoError) { coreaudio_logerr(status, "Could not remove voice property change listener\n"); @@ -633,10 +636,10 @@ static void coreaudio_fini_out (HWVoiceOut *hw) static void coreaudio_enable_out(HWVoiceOut *hw, bool enable) { - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; + CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw; core->enabled = enable; - update_device_playback_state(core); + update_out_device_playback_state(core); } static void *coreaudio_audio_init(Audiodev *dev, Error **errp) @@ -670,7 +673,7 @@ static void coreaudio_audio_fini (void *opaque) .pcm_ops = &coreaudio_pcm_ops, .max_voices_out = 1, .max_voices_in = 0, - .voice_size_out = sizeof (coreaudioVoiceOut), + .voice_size_out = sizeof (CoreaudioVoiceOut), .voice_size_in = 0 }; From patchwork Fri Jan 24 04:47:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 81069C0218C for ; Fri, 24 Jan 2025 04:48:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBbg-0002Dg-NT; Thu, 23 Jan 2025 23:47:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbBbf-0002DQ-Br for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:47 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBbd-0004aj-Gv for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:47 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2162c0f6a39so53293805ad.0 for ; Thu, 23 Jan 2025 20:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737694064; x=1738298864; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lRSdohQfLb761s33NJwI3rtsR7FUzyHNb2eLwHUAZsw=; b=Gsw2/LdDRjG29WoF8EWbrI/p4e5vAqBNiCB99JGLzu1C7xrHPt06UhTum0CRAFQp5U Ok1fJkKxGwJCvGnfjoEWAdepyjmjAam4sKtxqM5S32rcfWd1Lacezpgvv2nJX707JJ6X HST50gEE3XAaXA7ck4q3L67ohsdzDFP4mJC52ddNX1nJG4BGyvQNpalLGO9DEWw19EBr 7MPfUs1Y1q3GWGeu9MYx0rKuaxxQfon9VErNRXdoQR/EadXxBV79RQB70S4o8LREAyuq 6Pd2x1A16hkxZQDhItULEXZOBylTYFO0CqNcH8a/e7H8EMDibwTVC8FXRND66xRcflr2 kdXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737694064; x=1738298864; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lRSdohQfLb761s33NJwI3rtsR7FUzyHNb2eLwHUAZsw=; b=hULNCk445q4Y9vDj0+bJQwzRBmmtMOnmsIzL29AU2xLdNG8aPJ+SecHxepL5/aZFF2 Q9NHTQBWyVc8I9LPEMWGVPGYxR5ZIDLxyJm5j9D3MGJ5FvsoBIIDvas6tYE8VSMdKfV7 76XdpVyqBJdmUVJWMoF52uBUjYfZn9HS4JNXf2RTM3G+CIHuZAwI/cuw76z5qQ935+wY ELrxACUtL7fr7EiMNOrluJL9A4zNSJsaZDwOnlZiXBbeMmLUjidCj81+JpVQetS8BSHU 7yMxTx2PCOlQrx0Jdhsm1MMXiLRLoZri/h+EfXFOxxYcY4xdVjnOEIGTms3v3sjTS35z 46sA== X-Gm-Message-State: AOJu0YyG/uwljHmJ1JHj3iGBjK+x7J1yHvsWSfwU+/NKpBF8VTQitTca sMccKtkfDcmNbIfyToglQqmyzrAX6m9evkVnq8Dn4TEBC4yAPcXXoMg88KFv9ME= X-Gm-Gg: ASbGncuxuzbx8MdMZ7E4Xe/jUSFHVtTHydtc7mMWBsrxqF5qOzuT7yuYaT69m8L40nQ hfq8Sjdmy0tXGAYluKv1KfFfCFqMHykKTzV7FH8+ClF9k9/O6z7JbkYdrWFITSc8dBxLdiJHPx1 ayAqAQDb7A3ECiwbetCq6c8sgvzBUeMUO9x4n0ANSYldG4tS8jQCpbekdAL58fjjYG0jtc1s6sf XGgbga/N3vlaqPR89GHjfZdqGqcEM8Z/5G7PgKxYaFOYdsG/e8GDe4onPMpNvS27b5guLIvbmtL rpKFqBtt X-Google-Smtp-Source: AGHT+IFaSpCQ9bWxknYT0k3+h24wh4djgMb0e0qAbKWwEsunVTl+948nBkPWMS4v1PrwFdDDdA4dZA== X-Received: by 2002:a05:6a21:158d:b0:1e1:a449:ff71 with SMTP id adf61e73a8af0-1eb6968a845mr10039499637.1.1737694064224; Thu, 23 Jan 2025 20:47:44 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-ac48e84e199sm721025a12.11.2025.01.23.20.47.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 20:47:43 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 13:47:13 +0900 Subject: [PATCH v6 3/5] coreaudio: Commit the result of init in the end MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v6-3-11fbcb6c47cf@daynix.com> References: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> In-Reply-To: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14.2 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org init_out_device may only commit some part of the result and leave the state inconsistent when it encounters a fatal error or the device gets unplugged during the operation, which is expressed by kAudioHardwareBadObjectError or kAudioHardwareBadDeviceError. Commit the result in the end of the function so that it commits the result iff it sees no fatal error and the device remains plugged. With this change, handle_voice_change can rely on core->outputDeviceID to know whether the output device is initialized after calling init_out_device. Signed-off-by: Akihiko Odaki --- audio/coreaudio.m | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index c3ede586bbee1711d6a798175995b8db7dc89398..aff2b37b12aca723849645297c04f30ed365b8f8 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -357,7 +357,10 @@ static OSStatus out_device_ioproc( static OSStatus init_out_device(CoreaudioVoiceOut *core) { OSStatus status; + AudioDeviceID device_id; AudioValueRange framerange; + UInt32 device_frame_size; + AudioDeviceIOProcID ioprocid; AudioStreamBasicDescription stream_basic_description = { .mBitsPerChannel = core->hw.info.bits, @@ -370,20 +373,19 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) .mSampleRate = core->hw.info.freq }; - status = coreaudio_get_voice_out(&core->device_id); + status = coreaudio_get_voice_out(&device_id); if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not get default output Device\n"); return status; } - if (core->device_id == kAudioDeviceUnknown) { + if (device_id == kAudioDeviceUnknown) { dolog ("Could not initialize playback - Unknown Audiodevice\n"); return status; } /* get minimum and maximum buffer frame sizes */ - status = coreaudio_get_out_framesizerange(core->device_id, - &framerange); + status = coreaudio_get_out_framesizerange(device_id, &framerange); if (status == kAudioHardwareBadObjectError) { return 0; } @@ -394,31 +396,29 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) } if (framerange.mMinimum > core->frame_size_setting) { - core->device_frame_size = framerange.mMinimum; + device_frame_size = framerange.mMinimum; dolog ("warning: Upsizing Buffer Frames to %f\n", framerange.mMinimum); } else if (framerange.mMaximum < core->frame_size_setting) { - core->device_frame_size = framerange.mMaximum; + device_frame_size = framerange.mMaximum; dolog ("warning: Downsizing Buffer Frames to %f\n", framerange.mMaximum); } else { - core->device_frame_size = core->frame_size_setting; + device_frame_size = core->frame_size_setting; } /* set Buffer Frame Size */ - status = coreaudio_set_out_framesize(core->device_id, - &core->device_frame_size); + status = coreaudio_set_out_framesize(device_id, &device_frame_size); if (status == kAudioHardwareBadObjectError) { return 0; } if (status != kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not set device buffer frame size %" PRIu32 "\n", - (uint32_t)core->device_frame_size); + (uint32_t)device_frame_size); return status; } /* get Buffer Frame Size */ - status = coreaudio_get_out_framesize(core->device_id, - &core->device_frame_size); + status = coreaudio_get_out_framesize(device_id, &device_frame_size); if (status == kAudioHardwareBadObjectError) { return 0; } @@ -427,10 +427,9 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) "Could not get device buffer frame size\n"); return status; } - core->hw.samples = core->buffer_count * core->device_frame_size; /* set Samplerate */ - status = coreaudio_set_out_streamformat(core->device_id, + status = coreaudio_set_out_streamformat(device_id, &stream_basic_description); if (status == kAudioHardwareBadObjectError) { return 0; @@ -439,7 +438,6 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) coreaudio_playback_logerr (status, "Could not set samplerate %lf\n", stream_basic_description.mSampleRate); - core->device_id = kAudioDeviceUnknown; return status; } @@ -453,20 +451,24 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) * Therefore, the specified callback must be designed to avoid a deadlock * with the callers of AudioObjectGetPropertyData. */ - core->ioprocid = NULL; - status = AudioDeviceCreateIOProcID(core->device_id, + ioprocid = NULL; + status = AudioDeviceCreateIOProcID(device_id, out_device_ioproc, &core->hw, - &core->ioprocid); + &ioprocid); if (status == kAudioHardwareBadDeviceError) { return 0; } - if (status != kAudioHardwareNoError || core->ioprocid == NULL) { + if (status != kAudioHardwareNoError || ioprocid == NULL) { coreaudio_playback_logerr (status, "Could not set IOProc\n"); - core->device_id = kAudioDeviceUnknown; return status; } + core->device_id = device_id; + core->device_frame_size = device_frame_size; + core->hw.samples = core->buffer_count * core->device_frame_size; + core->ioprocid = ioprocid; + return 0; } @@ -550,7 +552,9 @@ static OSStatus handle_voice_out_change( fini_out_device(core); } - if (!init_out_device(core)) { + init_out_device(core); + + if (core->device_id) { update_out_device_playback_state(core); } From patchwork Fri Jan 24 04:47:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 673BDC02181 for ; Fri, 24 Jan 2025 04:49:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBbn-0002EV-JA; Thu, 23 Jan 2025 23:47:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbBbk-0002EF-9n for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:52 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBbi-0004bh-Fd for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:52 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-218c8aca5f1so38826925ad.0 for ; Thu, 23 Jan 2025 20:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737694069; x=1738298869; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cE+X4PDl66cqVXABqWkosmyuaKRyDx9YI4ApMGsc4ZM=; b=wNX6ETHZscXX78uEAmonlxo80jjc4kwHkSPhvFbQM1wYOwyw5X1iTNuNqGoxKOviS5 Rsls/PH2KZyo6zRXrC2qXMyYMvntS3VFYucskyhwAG+XzIvLURg73Z7/NVky6uFlTalO pCXv3qrgMF/CMHeZZbqJ5Nbba1jqaZBYqlmLkE9aQ0lTN6PQ1PQuK73B5bh1pqNXtJfB LX5PyGbpD3zHzTQFzkvU1TxbLWFQg0E1bwmyM7l/SDxCIVFeI93bIu6L6JyZL4Ehcbp4 wUrm4iURR6Jl50ETmrF3ovFf1CFJenWUJ8CXK1kbwrEqxcOlnGo1ZDuuflejHb6RCR9D ts8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737694069; x=1738298869; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cE+X4PDl66cqVXABqWkosmyuaKRyDx9YI4ApMGsc4ZM=; b=lcmQXc7RmKkrPC5E1VSES80w9AjIvYUqHUFqvl8atC3qest0n9235XaB3qISwqsyRW 6Z58rYcmRFgsUi8gLbmC5JovWlkcBYblIpLkdXhrY9w2oBrVvFAaHCLz5FmCxg8Nt8w4 JVELKTyhATA0og7vaLqu+XZRslqgRZng9W5EqvlzOYLnwd61inaiyQCSSmctt/b8q7WA Klo4W3qxfziiB06wGipD7xLql7QpoAVn8369bqKIS4Rvf42M6sT6EeSw2co9O53QtgPy pW59AFh628/rxFRF40PRFk9cy5nNe5Uinb1bCftSSUIFlNc8ihg40LDS4oFVX0DXbsD6 fL6Q== X-Gm-Message-State: AOJu0YyExO6Cd/iUF3CHN2z7NOKSk0nQpX99EtvQao9KgBAyk6exAHD4 6YQVzoBJ+mF5bG0rUm4r6/H90xnZi5gDJGvAP3lnlo+QULTr38FkASaM6YDyiFw= X-Gm-Gg: ASbGncv95oiwQ0vfirLfTgUa3c75QJTmC+Bm+GaHOSSnp1MFW+iLdo1YJ1+f2xior2K /KMs8DsrRkfSBk+pXu0mCXK14suFFrGFs/znSkYonRPtJ5jV7br4OTmYa6yEzXa3/J9HppYJ5Cv bXIrCrjA7YHGUzdmIfnsoFoRkSvmq8n/BMQMOe2YS6Ha+2yO52EvNJl6yyuOHdlQHp+5aKn6fz/ MCPD6EpCa59nttjXZVJBk5fMTlz8jsVYuXKfQdosJItqXUYAo+6AFc6dnlWH8+d7BzsS1gykDZi GPDsJUnG X-Google-Smtp-Source: AGHT+IFDR10KCpM2sTwaaKsNc6HmovCtplomlJBglujhD5kfO8Vvjj+fFXO4NsWRZxaHER1p0dXI+A== X-Received: by 2002:a05:6a20:3d8e:b0:1ea:ddd1:2fb6 with SMTP id adf61e73a8af0-1eb2158170dmr53880068637.30.1737694069293; Thu, 23 Jan 2025 20:47:49 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a782774sm834784b3a.156.2025.01.23.20.47.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 20:47:49 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 13:47:14 +0900 Subject: [PATCH v6 4/5] audio: Add functions to initialize buffers MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v6-4-11fbcb6c47cf@daynix.com> References: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> In-Reply-To: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki , Phil Dennis-Jordan X-Mailer: b4 0.14.2 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These functions can be used to re-initialize buffers when hardware parameters change due to device hotplug, for example. Signed-off-by: Akihiko Odaki Reviewed-by: Phil Dennis-Jordan Reviewed-by: Christian Schoenebeck --- audio/audio_int.h | 2 ++ audio/audio.c | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/audio/audio_int.h b/audio/audio_int.h index 2d079d00a2596e6bce20e1f52abf01a88c4e0012..9ba4a144d571659ad2d32a4d6b2919ad0db89e25 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -187,9 +187,11 @@ struct audio_pcm_ops { void (*volume_in)(HWVoiceIn *hw, Volume *vol); }; +void audio_generic_initialize_buffer_in(HWVoiceIn *hw); void audio_generic_run_buffer_in(HWVoiceIn *hw); void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size); void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size); +void audio_generic_initialize_buffer_out(HWVoiceOut *hw); void audio_generic_run_buffer_out(HWVoiceOut *hw); size_t audio_generic_buffer_get_free(HWVoiceOut *hw); void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size); diff --git a/audio/audio.c b/audio/audio.c index 87b4e9b6f2f356b6e5e972eabc100cf270fcbc29..17c6bbd0ae9e6ff810c0989dbfa1710ef674ff0a 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1407,12 +1407,18 @@ void audio_run(AudioState *s, const char *msg) #endif } +void audio_generic_initialize_buffer_in(HWVoiceIn *hw) +{ + g_free(hw->buf_emul); + hw->size_emul = hw->samples * hw->info.bytes_per_frame; + hw->buf_emul = g_malloc(hw->size_emul); + hw->pos_emul = hw->pending_emul = 0; +} + void audio_generic_run_buffer_in(HWVoiceIn *hw) { if (unlikely(!hw->buf_emul)) { - hw->size_emul = hw->samples * hw->info.bytes_per_frame; - hw->buf_emul = g_malloc(hw->size_emul); - hw->pos_emul = hw->pending_emul = 0; + audio_generic_initialize_buffer_in(hw); } while (hw->pending_emul < hw->size_emul) { @@ -1446,6 +1452,14 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size) hw->pending_emul -= size; } +void audio_generic_initialize_buffer_out(HWVoiceOut *hw) +{ + g_free(hw->buf_emul); + hw->size_emul = hw->samples * hw->info.bytes_per_frame; + hw->buf_emul = g_malloc(hw->size_emul); + hw->pos_emul = hw->pending_emul = 0; +} + size_t audio_generic_buffer_get_free(HWVoiceOut *hw) { if (hw->buf_emul) { @@ -1477,9 +1491,7 @@ void audio_generic_run_buffer_out(HWVoiceOut *hw) void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size) { if (unlikely(!hw->buf_emul)) { - hw->size_emul = hw->samples * hw->info.bytes_per_frame; - hw->buf_emul = g_malloc(hw->size_emul); - hw->pos_emul = hw->pending_emul = 0; + audio_generic_initialize_buffer_out(hw); } *size = MIN(hw->size_emul - hw->pending_emul, From patchwork Fri Jan 24 04:47:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 31C12C0218B for ; Fri, 24 Jan 2025 04:49:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBbr-0002F5-Ah; Thu, 23 Jan 2025 23:47:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbBbo-0002Eo-GL for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:56 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBbn-0004cH-1A for qemu-devel@nongnu.org; Thu, 23 Jan 2025 23:47:56 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-219f8263ae0so31615675ad.0 for ; Thu, 23 Jan 2025 20:47:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737694073; x=1738298873; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6ez9apN9lZeka8SxY6TZjMinLRnJzvs/6Urk4IfIR58=; b=J+VvZQEyZgrSmJ3/k2srTLzC9WjxrbW5utHp+M3Yu+c2ELBtfyGRQW+6poVn79ABnE YZh4Ey9aAa0Ys4ij6kzRfytbL7U1lGIr14jSdpa4xiFkt1SBQqcZHwHJVLlos7SyowkV hRMbOiNopM+XcX0KmU1zMiLh4jcwdebMaBGqAAqWo8AHUOmZsg5tC+HvZPUb4jjeK5Yi hmfdzPynEMNovZtsIg31Mz8iwgcajZ9eQJm8yrctFuaFUc5XsrXja4yM8Ndtn+Y7lInX QEY2MKfZdETrWOqfylLtnS3L40YxTq5eGPdrllcE8FwboREiuP5oNDYt4vS5v6C5peU8 qmqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737694073; x=1738298873; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ez9apN9lZeka8SxY6TZjMinLRnJzvs/6Urk4IfIR58=; b=asBq2l52UAAWLmk7rZSiGJZjWMwZN6cAh8FKYzmH3MQ3UeXoz3/0zG1BEX/3br2YXn STgNiAyPRh4+EOI/GZl456FpunOofLAgJrSfIJo8bSPGClLVbXVUeH0qAVlf88yF8836 4SkcQWU4kJ2VRheD9ZWf4nfZwYG8knzO3bjnRstCnWp1GsgkRCA6iAAh5adYEPGCvP9k rCdkTTlEumj39zDJ9/JSQ5JgjN77Bh0szso22Zzsk1C/zHtPRGr8/4eFINXHLTmXYWYe pj133B9i9FqkJXz+nFkOezyx0JmR2IrORt265zI6fEZCQeWge5nFr1kyOvYk5E1SSovP U0xg== X-Gm-Message-State: AOJu0YwmBoLP+FOX8lth+5ncfyOMQBa/6J01O0vyWq3h4a3MvGv9bR51 orHZIsEVY+8LLvSgeo4RKvublHprpJbEYxDh/6GShaBjZAyREDlpAU2vsSAc6Fo= X-Gm-Gg: ASbGncsSpFiv/U7jvqS2j7mmWcnJrComydKy3/WgNhMajTvbHNP1IGXJZwhhF0cccxn WhtaA6SoUFcxFDX1NyoNaaup+u7tvUy8k59p3EYlTc/Hpa44UVCAYsJ1ixpV/b7000w7yY0xadF ZndVcXOeRs+fbrtX0gTHkcrDHC2TOJacno6MtpTZNtA/Qx1DpESJfFNL+/IOwlmFMsGFcqahF8C ShUD99a7Ujdo0gjR0+/IzM7OU3Ub4fbSafceE6igDfX/EyN3eLMni0mR4Qn8hR+VVL/AgaGbpX+ yiMdIoE6 X-Google-Smtp-Source: AGHT+IF0oiJ0lCG3YNEFI0fRiEBrardZzxC42QtzY+4VnY5cFYt/mGw9/gbPJ+ZwDNfpXKiSbxvdXw== X-Received: by 2002:a05:6a00:244d:b0:71e:6c3f:2fb6 with SMTP id d2e1a72fcca58-72daf950b94mr48574479b3a.8.1737694073622; Thu, 23 Jan 2025 20:47:53 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a760e2asm850203b3a.88.2025.01.23.20.47.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 20:47:53 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 13:47:15 +0900 Subject: [PATCH v6 5/5] coreaudio: Initialize the buffer for device change MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v6-5-11fbcb6c47cf@daynix.com> References: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> In-Reply-To: <20250124-coreaudio-v6-0-11fbcb6c47cf@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki , Phil Dennis-Jordan X-Mailer: b4 0.14.2 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reallocate buffers when the active device change as the required buffer size may differ. Signed-off-by: Akihiko Odaki Reviewed-by: Phil Dennis-Jordan Acked-by: Christian Schoenebeck --- audio/coreaudio.m | 1 + 1 file changed, 1 insertion(+) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index aff2b37b12aca723849645297c04f30ed365b8f8..2ad47dcbbab338f2791251297202af328b0baf49 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -467,6 +467,7 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) core->device_id = device_id; core->device_frame_size = device_frame_size; core->hw.samples = core->buffer_count * core->device_frame_size; + audio_generic_initialize_buffer_out(&core->hw); core->ioprocid = ioprocid; return 0;