From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605104987337.65180299945814; Tue, 3 Mar 2026 22:18:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfYL-0004EC-AI; Wed, 04 Mar 2026 01:17:49 -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 1vxfY1-0004Cs-0C for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003De-9Q for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:28 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77q067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:17 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=v6Idt5M6E9tHdoXYyHcE87svc+qklUeVvG1RTj4ebPQ=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605037; v=1; b=SXq8zv6YKmVaos6PFL7LPhgkezZYOtN6PebuLe5QW3B7phtT1F5iSKIvLx75RNBQ AW5mxLp+d3pmOTrtOoJij8KzO6ntYdIP6Oi+fb8YgFeNZZAVIkOkWvjPwFaiC3qA 5q1UdanEVZ6XEv5UF3mf+0FdVMYWsIbew9ECxR7Fn9CbOLfl2kaDtMQNS/+PaGZx JG7RUze6ba/4qNcF/rr2KBd8avNWArfmCPtW4lMKOCEgJDyqHAIYsyWF0VlZ9QcR L7Z0yVbWrSWgWHPCsAAYW827taG8qUrRVR0iWpUG811PY7g1sRcPRr5cFFEF8RsE xBOmfCCmTVJ+IYelCbIuuw== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:54 +0900 Subject: [PATCH v8 1/6] coreaudio: Remove unnecessary explicit casts MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-1-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605106606139100 coreaudio had unnecessary explicit casts and they had extra whitespaces around them so remove them. Signed-off-by: Akihiko Odaki Reviewed-by: Marc-Andr=C3=A9 Lureau --- audio/coreaudio.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index a28fa77d73ff..cbda4f143698 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -310,7 +310,7 @@ static OSStatus audioDeviceIOProc( UInt32 frameCount, pending_frames; void *out =3D outOutputData->mBuffers[0].mData; HWVoiceOut *hw =3D hwptr; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hwptr; + coreaudioVoiceOut *core =3D hwptr; size_t len; =20 if (coreaudio_buf_lock (core, "audioDeviceIOProc")) { @@ -394,11 +394,11 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) } =20 if (frameRange.mMinimum > core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize =3D (UInt32) frameRange.m= Minimum; + core->audioDevicePropertyBufferFrameSize =3D frameRange.mMinimum; warn_report("coreaudio: Upsizing buffer frames to %f", frameRange.mMinimum); } else if (frameRange.mMaximum < core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize =3D (UInt32) frameRange.m= Maximum; + core->audioDevicePropertyBufferFrameSize =3D frameRange.mMaximum; warn_report("coreaudio: Downsizing buffer frames to %f", frameRange.mMaximum); } else { --=20 2.53.0 From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605125182700.4789203527121; Tue, 3 Mar 2026 22:18:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfYP-0004FI-Jo; Wed, 04 Mar 2026 01:17:53 -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 1vxfY2-0004Cz-8Q for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003Di-FL for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:29 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77r067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:17 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=1c39cPmv2n24yxC+0JhoxYKLp5eYLtjZSWAVp+nTdDM=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605037; v=1; b=R3hlQlCqhT2pQrpBlF7uYOhc0mSyLqWCuYCI/sDdi4eIxr3eg05WJBZ74jBVoz2N ZodULKEi6l3HllrnJ8PZITnE3aqQPIz7OXOyrRKjeReI7fDVMmcC178AxAsU4Y0Y VzfkdRBqM1S57V6Fr7gSNcbcVt/KO11QqHz42qp+XXUd5hO5D0NRMFFp4hdFbQt4 lw1QoWLeKwAyojjUWV5cWR2gsXhqtNXCWYte8S4Wbwt5UsUDeacaK7HSiU5Aa66E XPnKKXio/prsZsnEg5qrQmzX2C4ek/Ls+Ymib+bOKnKuXy3hNp2N69k6VAtHMVyO IZKZB40QZhHDPUT7hD0uXQ== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:55 +0900 Subject: [PATCH v8 2/6] coreaudio: Remove extra whitespaces MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-2-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605147776158500 Remove extra whitespaces around parentheses. Signed-off-by: Akihiko Odaki Reviewed-by: Marc-Andr=C3=A9 Lureau --- audio/coreaudio.m | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index cbda4f143698..bc9ab7477b68 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -272,7 +272,7 @@ static int coreaudio_buf_unlock(coreaudioVoiceOut *core= , const char *fn_name) #define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \ static ret_type glue(coreaudio_, name)args_decl \ { \ - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; \ + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; \ ret_type ret; \ \ if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \ @@ -313,13 +313,13 @@ static OSStatus audioDeviceIOProc( coreaudioVoiceOut *core =3D hwptr; size_t len; =20 - if (coreaudio_buf_lock (core, "audioDeviceIOProc")) { + if (coreaudio_buf_lock(core, "audioDeviceIOProc")) { inInputTime =3D 0; return 0; } =20 if (inDevice !=3D core->outputDeviceID) { - coreaudio_buf_unlock (core, "audioDeviceIOProc(old device)"); + coreaudio_buf_unlock(core, "audioDeviceIOProc(old device)"); return 0; } =20 @@ -329,7 +329,7 @@ static OSStatus audioDeviceIOProc( /* if there are not enough samples, set signal and return */ if (pending_frames < frameCount) { inInputTime =3D 0; - coreaudio_buf_unlock (core, "audioDeviceIOProc(empty)"); + coreaudio_buf_unlock(core, "audioDeviceIOProc(empty)"); return 0; } =20 @@ -349,7 +349,7 @@ static OSStatus audioDeviceIOProc( out +=3D write_len; } =20 - coreaudio_buf_unlock (core, "audioDeviceIOProc"); + coreaudio_buf_unlock(core, "audioDeviceIOProc"); return 0; } =20 @@ -563,7 +563,7 @@ static OSStatus handle_voice_change( static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as) { OSStatus status; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; int err; Audiodev *dev =3D hw->s->dev; AudiodevCoreaudioPerDirectionOptions *cpdo =3D dev->u.coreaudio.out; @@ -579,7 +579,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct au= dsettings *as) obt_as =3D *as; as =3D &obt_as; as->fmt =3D AUDIO_FORMAT_F32; - audio_pcm_init_info (&hw->info, as); + audio_pcm_init_info(&hw->info, as); =20 core->frameSizeSetting =3D audio_buffer_frames( qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); @@ -615,7 +615,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) { OSStatus status; int err; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; =20 status =3D AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &voice_addr, @@ -636,7 +636,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) =20 static void coreaudio_enable_out(HWVoiceOut *hw, bool enable) { - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; =20 core->enabled =3D enable; update_device_playback_state(core); --=20 2.53.0 From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605121819443.658231407784; Tue, 3 Mar 2026 22:18:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfYP-0004FF-5M; Wed, 04 Mar 2026 01:17:53 -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 1vxfY3-0004D4-36 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:34 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003Dk-Fa for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77s067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:17 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=J9MzZzp44MSzoWyytEppT1gJTng3MsU07TyB3vWHLJw=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605037; v=1; b=H151VZEQGeynLWvn+BY6zAExrj266BeqDYDf5HiRpPesMUgLdU1Z157gDHk6OYC+ iUb8Shv+s/y3NYpQ53pBQkv9aKu2Kdrr0t8Knnas2P+Z56igh7F/JlwVle24J1UH XYeKKaqK8bGtBoXxIBfc3J1XYAOpkIFCVPeO0hFf2woHNWK2QiN2aDXYIkJO658z W4HjbnfT+V8guzN9WqEOaoRnnVjUbrcE3trNpCuEri5W1O7X0CJiF8wpK22JYdw0 sC+JZ2NJwXFHvsk8f2zv5pt1dURacZfWadldMHWn7y10tFcfIeppyNLFvh8Ht5+3 kA5QDkPX4UehaCLN7Lj3LQ== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:56 +0900 Subject: [PATCH v8 3/6] coreaudio: Improve naming MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-3-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605142608139100 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=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- audio/coreaudio.m | 188 +++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 95 insertions(+), 93 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index bc9ab7477b68..736227eb2b7a 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -43,34 +43,34 @@ 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; =20 -static const AudioObjectPropertyAddress voice_addr =3D { +static const AudioObjectPropertyAddress voice_out_addr =3D { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain }; =20 -static OSStatus coreaudio_get_voice(AudioDeviceID *id) +static OSStatus coreaudio_get_voice_out(AudioDeviceID *id) { UInt32 size =3D sizeof(*id); =20 return AudioObjectGetPropertyData(kAudioObjectSystemObject, - &voice_addr, + &voice_out_addr, 0, NULL, &size, id); } =20 -static OSStatus coreaudio_get_framesizerange(AudioDeviceID id, - AudioValueRange *framerange) +static OSStatus coreaudio_get_out_framesizerange(AudioDeviceID id, + AudioValueRange *frameran= ge) { UInt32 size =3D sizeof(*framerange); AudioObjectPropertyAddress addr =3D { @@ -87,7 +87,7 @@ static OSStatus coreaudio_get_framesizerange(AudioDeviceI= D id, framerange); } =20 -static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesiz= e) +static OSStatus coreaudio_get_out_framesize(AudioDeviceID id, UInt32 *fram= esize) { UInt32 size =3D sizeof(*framesize); AudioObjectPropertyAddress addr =3D { @@ -104,7 +104,7 @@ static OSStatus coreaudio_get_framesize(AudioDeviceID i= d, UInt32 *framesize) framesize); } =20 -static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesiz= e) +static OSStatus coreaudio_set_out_framesize(AudioDeviceID id, UInt32 *fram= esize) { UInt32 size =3D sizeof(*framesize); AudioObjectPropertyAddress addr =3D { @@ -121,8 +121,8 @@ static OSStatus coreaudio_set_framesize(AudioDeviceID i= d, UInt32 *framesize) framesize); } =20 -static OSStatus coreaudio_set_streamformat(AudioDeviceID id, - AudioStreamBasicDescription *d) +static OSStatus coreaudio_set_out_streamformat(AudioDeviceID id, + AudioStreamBasicDescription= *d) { UInt32 size =3D sizeof(*d); AudioObjectPropertyAddress addr =3D { @@ -139,7 +139,7 @@ static OSStatus coreaudio_set_streamformat(AudioDeviceI= D id, d); } =20 -static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result) +static OSStatus coreaudio_get_out_isrunning(AudioDeviceID id, UInt32 *resu= lt) { UInt32 size =3D sizeof(*result); AudioObjectPropertyAddress addr =3D { @@ -243,7 +243,8 @@ static void G_GNUC_PRINTF(3, 4) coreaudio_logerr2(OSSta= tus status, #define coreaudio_playback_logerr(status, ...) \ coreaudio_logerr2(status, "playback", __VA_ARGS__) =20 -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; =20 @@ -256,7 +257,8 @@ static int coreaudio_buf_lock(coreaudioVoiceOut *core, = const char *fn_name) return 0; } =20 -static int coreaudio_buf_unlock(coreaudioVoiceOut *core, const char *fn_na= me) +static int coreaudio_voice_out_buf_unlock(CoreaudioVoiceOut *core, + const char *fn_name) { int err; =20 @@ -269,20 +271,20 @@ static int coreaudio_buf_unlock(coreaudioVoiceOut *co= re, const char *fn_name) return 0; } =20 -#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \ - static ret_type glue(coreaudio_, name)args_decl \ - { \ - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; \ - ret_type ret; \ - \ - if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \ - return 0; \ - } \ - \ - ret =3D 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 =3D (CoreaudioVoiceOut *)hw; \ + ret_type ret; \ + \ + if (coreaudio_voice_out_buf_lock(core, "coreaudio_" #name)) { \ + return 0; \ + } \ + \ + ret =3D 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 *si= ze), @@ -298,7 +300,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, @@ -307,33 +309,33 @@ static OSStatus audioDeviceIOProc( const AudioTimeStamp *inOutputTime, void *hwptr) { - UInt32 frameCount, pending_frames; + UInt32 frame_size, pending_frames; void *out =3D outOutputData->mBuffers[0].mData; HWVoiceOut *hw =3D hwptr; - coreaudioVoiceOut *core =3D hwptr; + CoreaudioVoiceOut *core =3D hwptr; size_t len; =20 - if (coreaudio_buf_lock(core, "audioDeviceIOProc")) { + if (coreaudio_voice_out_buf_lock(core, "out_device_ioproc")) { inInputTime =3D 0; return 0; } =20 - if (inDevice !=3D core->outputDeviceID) { - coreaudio_buf_unlock(core, "audioDeviceIOProc(old device)"); + if (inDevice !=3D core->device_id) { + coreaudio_voice_out_buf_unlock(core, "out_device_ioproc(old device= )"); return 0; } =20 - frameCount =3D core->audioDevicePropertyBufferFrameSize; + frame_size =3D core->device_frame_size; pending_frames =3D hw->pending_emul / hw->info.bytes_per_frame; =20 /* if there are not enough samples, set signal and return */ - if (pending_frames < frameCount) { + if (pending_frames < frame_size) { inInputTime =3D 0; - coreaudio_buf_unlock(core, "audioDeviceIOProc(empty)"); + coreaudio_voice_out_buf_unlock(core, "out_device_ioproc(empty)"); return 0; } =20 - len =3D frameCount * hw->info.bytes_per_frame; + len =3D frame_size * hw->info.bytes_per_frame; while (len) { size_t write_len, start; =20 @@ -349,16 +351,16 @@ static OSStatus audioDeviceIOProc( out +=3D write_len; } =20 - coreaudio_buf_unlock(core, "audioDeviceIOProc"); + coreaudio_voice_out_buf_unlock(core, "out_device_ioproc"); return 0; } =20 -static OSStatus init_out_device(coreaudioVoiceOut *core) +static OSStatus init_out_device(CoreaudioVoiceOut *core) { + AudioValueRange value_range; OSStatus status; - AudioValueRange frameRange; =20 - AudioStreamBasicDescription streamBasicDescription =3D { + AudioStreamBasicDescription stream_basic_description =3D { .mBitsPerChannel =3D audio_format_bits(core->hw.info.af), .mBytesPerFrame =3D core->hw.info.bytes_per_frame, .mBytesPerPacket =3D core->hw.info.bytes_per_frame, @@ -369,21 +371,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) .mSampleRate =3D core->hw.info.freq }; =20 - status =3D coreaudio_get_voice(&core->outputDeviceID); + status =3D coreaudio_get_voice_out(&core->device_id); if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, "Could not get default output device"); return status; } - if (core->outputDeviceID =3D=3D kAudioDeviceUnknown) { + if (core->device_id =3D=3D kAudioDeviceUnknown) { error_report("coreaudio: Could not initialize playback: " "Unknown audio device"); return status; } =20 /* get minimum and maximum buffer frame sizes */ - status =3D coreaudio_get_framesizerange(core->outputDeviceID, - &frameRange); + status =3D coreaudio_get_out_framesizerange(core->device_id, &value_ra= nge); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } @@ -393,34 +394,34 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) return status; } =20 - if (frameRange.mMinimum > core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize =3D frameRange.mMinimum; + if (value_range.mMinimum > core->frame_size_setting) { + core->device_frame_size =3D value_range.mMinimum; warn_report("coreaudio: Upsizing buffer frames to %f", - frameRange.mMinimum); - } else if (frameRange.mMaximum < core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize =3D frameRange.mMaximum; + value_range.mMinimum); + } else if (value_range.mMaximum < core->frame_size_setting) { + core->device_frame_size =3D value_range.mMaximum; warn_report("coreaudio: Downsizing buffer frames to %f", - frameRange.mMaximum); + value_range.mMaximum); } else { - core->audioDevicePropertyBufferFrameSize =3D core->frameSizeSettin= g; + core->device_frame_size =3D core->frame_size_setting; } =20 /* set Buffer Frame Size */ - status =3D coreaudio_set_framesize(core->outputDeviceID, - &core->audioDevicePropertyBufferFrame= Size); + status =3D coreaudio_set_out_framesize(core->device_id, + &core->device_frame_size); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, "Could not set device buffer frame size = %" PRIu32, - (uint32_t)core->audioDevicePropertyBuffe= rFrameSize); + (uint32_t)core->device_frame_size); return status; } =20 /* get Buffer Frame Size */ - status =3D coreaudio_get_framesize(core->outputDeviceID, - &core->audioDevicePropertyBufferFrame= Size); + status =3D coreaudio_get_out_framesize(core->device_id, + &core->device_frame_size); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } @@ -429,19 +430,19 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) "Could not get device buffer frame size"= ); return status; } - core->hw.samples =3D core->bufferCount * core->audioDevicePropertyBuff= erFrameSize; + core->hw.samples =3D core->buffer_count * core->device_frame_size; =20 /* set Samplerate */ - status =3D coreaudio_set_streamformat(core->outputDeviceID, - &streamBasicDescription); + status =3D coreaudio_set_out_streamformat(core->device_id, + &stream_basic_description); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, "Could not set samplerate %lf", - streamBasicDescription.mSampleRate); - core->outputDeviceID =3D kAudioDeviceUnknown; + stream_basic_description.mSampleRate); + core->device_id =3D kAudioDeviceUnknown; return status; } =20 @@ -456,8 +457,8 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) * with the callers of AudioObjectGetPropertyData. */ core->ioprocid =3D NULL; - status =3D AudioDeviceCreateIOProcID(core->outputDeviceID, - audioDeviceIOProc, + status =3D AudioDeviceCreateIOProcID(core->device_id, + out_device_ioproc, &core->hw, &core->ioprocid); if (status =3D=3D kAudioHardwareBadDeviceError) { @@ -465,20 +466,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) } if (status !=3D kAudioHardwareNoError || core->ioprocid =3D=3D NULL) { coreaudio_playback_logerr(status, "Could not set IOProc"); - core->outputDeviceID =3D kAudioDeviceUnknown; + core->device_id =3D kAudioDeviceUnknown; return status; } =20 return 0; } =20 -static void fini_out_device(coreaudioVoiceOut *core) +static void fini_out_device(CoreaudioVoiceOut *core) { OSStatus status; UInt32 isrunning; =20 /* stop playback */ - status =3D coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + status =3D coreaudio_get_out_isrunning(core->device_id, &isrunning); if (status !=3D kAudioHardwareBadObjectError) { if (status !=3D kAudioHardwareNoError) { coreaudio_logerr(status, @@ -486,7 +487,7 @@ static void fini_out_device(coreaudioVoiceOut *core) } =20 if (isrunning) { - status =3D AudioDeviceStop(core->outputDeviceID, core->ioproci= d); + status =3D AudioDeviceStop(core->device_id, core->ioprocid); if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { coreaudio_logerr(status, "Could not stop playback"); } @@ -494,20 +495,20 @@ static void fini_out_device(coreaudioVoiceOut *core) } =20 /* remove callback */ - status =3D AudioDeviceDestroyIOProcID(core->outputDeviceID, + status =3D AudioDeviceDestroyIOProcID(core->device_id, core->ioprocid); if (status !=3D kAudioHardwareBadDeviceError && status !=3D kAudioHard= wareNoError) { coreaudio_logerr(status, "Could not remove IOProc"); } - core->outputDeviceID =3D kAudioDeviceUnknown; + core->device_id =3D kAudioDeviceUnknown; } =20 -static void update_device_playback_state(coreaudioVoiceOut *core) +static void update_out_device_playback_state(CoreaudioVoiceOut *core) { OSStatus status; UInt32 isrunning; =20 - status =3D coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + status =3D coreaudio_get_out_isrunning(core->device_id, &isrunning); if (status !=3D kAudioHardwareNoError) { if (status !=3D kAudioHardwareBadObjectError) { coreaudio_logerr(status, @@ -520,7 +521,7 @@ static void update_device_playback_state(coreaudioVoice= Out *core) if (core->enabled) { /* start playback */ if (!isrunning) { - status =3D AudioDeviceStart(core->outputDeviceID, core->ioproc= id); + status =3D AudioDeviceStart(core->device_id, core->ioprocid); if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { coreaudio_logerr(status, "Could not resume playback"); } @@ -528,7 +529,7 @@ static void update_device_playback_state(coreaudioVoice= Out *core) } else { /* stop playback */ if (isrunning) { - status =3D AudioDeviceStop(core->outputDeviceID, + status =3D AudioDeviceStop(core->device_id, core->ioprocid); if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { coreaudio_logerr(status, "Could not pause playback"); @@ -538,22 +539,22 @@ static void update_device_playback_state(coreaudioVoi= ceOut *core) } =20 /* 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 =3D in_client_data; + CoreaudioVoiceOut *core =3D in_client_data; =20 bql_lock(); =20 - if (core->outputDeviceID) { + if (core->device_id) { fini_out_device(core); } =20 if (!init_out_device(core)) { - update_device_playback_state(core); + update_out_device_playback_state(core); } =20 bql_unlock(); @@ -563,7 +564,7 @@ static OSStatus handle_voice_change( static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as) { OSStatus status; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; + CoreaudioVoiceOut *core =3D (CoreaudioVoiceOut *)hw; int err; Audiodev *dev =3D hw->s->dev; AudiodevCoreaudioPerDirectionOptions *cpdo =3D dev->u.coreaudio.out; @@ -581,13 +582,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct = audsettings *as) as->fmt =3D AUDIO_FORMAT_F32; audio_pcm_init_info(&hw->info, as); =20 - core->frameSizeSetting =3D audio_buffer_frames( + core->frame_size_setting =3D audio_buffer_frames( qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); =20 - core->bufferCount =3D cpdo->has_buffer_count ? cpdo->buffer_count : 4; + core->buffer_count =3D cpdo->has_buffer_count ? cpdo->buffer_count : 4; =20 status =3D AudioObjectAddPropertyListener(kAudioObjectSystemObject, - &voice_addr, handle_voice_chan= ge, + &voice_out_addr, + handle_voice_out_change, core); if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, @@ -597,8 +599,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct au= dsettings *as) =20 if (init_out_device(core)) { status =3D AudioObjectRemovePropertyListener(kAudioObjectSystemObj= ect, - &voice_addr, - handle_voice_change, + &voice_out_addr, + handle_voice_out_change, core); if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, @@ -615,11 +617,11 @@ static void coreaudio_fini_out (HWVoiceOut *hw) { OSStatus status; int err; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; + CoreaudioVoiceOut *core =3D (CoreaudioVoiceOut *)hw; =20 status =3D AudioObjectRemovePropertyListener(kAudioObjectSystemObject, - &voice_addr, - handle_voice_change, + &voice_out_addr, + handle_voice_out_change, core); if (status !=3D kAudioHardwareNoError) { coreaudio_logerr(status, "Could not remove voice property change l= istener"); @@ -636,10 +638,10 @@ static void coreaudio_fini_out (HWVoiceOut *hw) =20 static void coreaudio_enable_out(HWVoiceOut *hw, bool enable) { - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *)hw; + CoreaudioVoiceOut *core =3D (CoreaudioVoiceOut *)hw; =20 core->enabled =3D enable; - update_device_playback_state(core); + update_out_device_playback_state(core); } =20 static void audio_coreaudio_class_init(ObjectClass *klass, const void *dat= a) --=20 2.53.0 From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605111985454.69687332448734; Tue, 3 Mar 2026 22:18:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfYL-0004Ed-GM; Wed, 04 Mar 2026 01:17:49 -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 1vxfY2-0004D3-MQ for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003Dq-P3 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77t067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:17 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=u0Fc5umq6WceNnLCwNli3zJ0ydLQmjhO/wjOG2BnQPY=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605038; v=1; b=bYAvoam+Ch+rHrZihl68CpjodfxPAbP8V2TUgspsd+xKQvX8R2dB0OkkgJU4Y6GS Mnv2SF6KTzJrOGIb9myc80Vz0F7PI95BiVIpF66KHmj/YqBdvtAj1E3Co7H099FN 1RDxzWjUxOXWZKNRwsN3XiiBekpuw6GGI9oDbt5dSLsjUM6sBcV/VgtiVTOady6G 41uG+wez6xzsl1pS0IuGcAOYXjHZ7w0CASOb00DIoMcF3/+VGGuAmaY/WccFfQBh 30/noOHMBhPpxs2n2s2WMjqwRqsBJY+TFuluQToPFQl2JT0el7lkWM21rBFrelxk VZOtDtubPyEQ1vw220Husg== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:57 +0900 Subject: [PATCH v8 4/6] coreaudio: Commit the result of init in the end MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-4-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605114648158500 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 | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index 736227eb2b7a..23c3d1f80ac5 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -357,8 +357,11 @@ static OSStatus out_device_ioproc( =20 static OSStatus init_out_device(CoreaudioVoiceOut *core) { + AudioDeviceID device_id; + AudioDeviceIOProcID ioprocid; AudioValueRange value_range; OSStatus status; + UInt32 device_frame_size; =20 AudioStreamBasicDescription stream_basic_description =3D { .mBitsPerChannel =3D audio_format_bits(core->hw.info.af), @@ -371,20 +374,20 @@ static OSStatus init_out_device(CoreaudioVoiceOut *co= re) .mSampleRate =3D core->hw.info.freq }; =20 - status =3D coreaudio_get_voice_out(&core->device_id); + status =3D coreaudio_get_voice_out(&device_id); if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, "Could not get default output device"); return status; } - if (core->device_id =3D=3D kAudioDeviceUnknown) { + if (device_id =3D=3D kAudioDeviceUnknown) { error_report("coreaudio: Could not initialize playback: " "Unknown audio device"); return status; } =20 /* get minimum and maximum buffer frame sizes */ - status =3D coreaudio_get_out_framesizerange(core->device_id, &value_ra= nge); + status =3D coreaudio_get_out_framesizerange(device_id, &value_range); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } @@ -395,33 +398,31 @@ static OSStatus init_out_device(CoreaudioVoiceOut *co= re) } =20 if (value_range.mMinimum > core->frame_size_setting) { - core->device_frame_size =3D value_range.mMinimum; + device_frame_size =3D value_range.mMinimum; warn_report("coreaudio: Upsizing buffer frames to %f", value_range.mMinimum); } else if (value_range.mMaximum < core->frame_size_setting) { - core->device_frame_size =3D value_range.mMaximum; + device_frame_size =3D value_range.mMaximum; warn_report("coreaudio: Downsizing buffer frames to %f", value_range.mMaximum); } else { - core->device_frame_size =3D core->frame_size_setting; + device_frame_size =3D core->frame_size_setting; } =20 /* set Buffer Frame Size */ - status =3D coreaudio_set_out_framesize(core->device_id, - &core->device_frame_size); + status =3D coreaudio_set_out_framesize(device_id, &device_frame_size); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr(status, "Could not set device buffer frame size = %" PRIu32, - (uint32_t)core->device_frame_size); + (uint32_t)device_frame_size); return status; } =20 /* get Buffer Frame Size */ - status =3D coreaudio_get_out_framesize(core->device_id, - &core->device_frame_size); + status =3D coreaudio_get_out_framesize(device_id, &device_frame_size); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; } @@ -430,10 +431,9 @@ static OSStatus init_out_device(CoreaudioVoiceOut *cor= e) "Could not get device buffer frame size"= ); return status; } - core->hw.samples =3D core->buffer_count * core->device_frame_size; =20 /* set Samplerate */ - status =3D coreaudio_set_out_streamformat(core->device_id, + status =3D coreaudio_set_out_streamformat(device_id, &stream_basic_description); if (status =3D=3D kAudioHardwareBadObjectError) { return 0; @@ -442,7 +442,6 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) coreaudio_playback_logerr(status, "Could not set samplerate %lf", stream_basic_description.mSampleRate); - core->device_id =3D kAudioDeviceUnknown; return status; } =20 @@ -456,20 +455,24 @@ static OSStatus init_out_device(CoreaudioVoiceOut *co= re) * Therefore, the specified callback must be designed to avoid a deadl= ock * with the callers of AudioObjectGetPropertyData. */ - core->ioprocid =3D NULL; - status =3D AudioDeviceCreateIOProcID(core->device_id, + ioprocid =3D NULL; + status =3D AudioDeviceCreateIOProcID(device_id, out_device_ioproc, &core->hw, - &core->ioprocid); + &ioprocid); if (status =3D=3D kAudioHardwareBadDeviceError) { return 0; } - if (status !=3D kAudioHardwareNoError || core->ioprocid =3D=3D NULL) { + if (status !=3D kAudioHardwareNoError || ioprocid =3D=3D NULL) { coreaudio_playback_logerr(status, "Could not set IOProc"); - core->device_id =3D kAudioDeviceUnknown; return status; } =20 + core->device_id =3D device_id; + core->device_frame_size =3D device_frame_size; + core->hw.samples =3D core->buffer_count * core->device_frame_size; + core->ioprocid =3D ioprocid; + return 0; } =20 @@ -553,7 +556,9 @@ static OSStatus handle_voice_out_change( fini_out_device(core); } =20 - if (!init_out_device(core)) { + init_out_device(core); + + if (core->device_id) { update_out_device_playback_state(core); } =20 @@ -650,7 +655,7 @@ static void audio_coreaudio_class_init(ObjectClass *kla= ss, const void *data) =20 k->max_voices_out =3D 1; k->max_voices_in =3D 0; - k->voice_size_out =3D sizeof(coreaudioVoiceOut); + k->voice_size_out =3D sizeof(CoreaudioVoiceOut); k->voice_size_in =3D 0; =20 k->init_out =3D coreaudio_init_out; --=20 2.53.0 From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605076477213.12064610518246; Tue, 3 Mar 2026 22:17:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfY8-0004Dy-Kf; Wed, 04 Mar 2026 01:17:37 -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 1vxfY2-0004D1-A6 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003Df-Kv for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77u067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:18 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=w61ce1R8XUXkpU7hpBsRGRcv0aB4Z5vn3TmzvMPi8Nc=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605038; v=1; b=EtcLAHwb+RSDWtXVx9m586mJUlS6Z6zDMXtDthkvNKNCgCCqtbBjhs5LOf34TJpp qSHwFY0gQ2eFlc+1TBl/r6TQ0UDvPD5BJ2hRyEikIm6w1E6wd4tv4SclZ/Y1H7mb 2p1zXnelMyrC2LwqBQs9dbtpoYOcFyGfh+od6MQiXdZXWv5BE0YNzYwm65HuykBD aEDl2v7/fUPIIvO6d1VFOVJ1wbFUIjG+k1eH5NC7x9Rn+R5rOWCF7bxO+AxzvRW2 AeRVGYkS2xfYSsoQgwcZTKhIldpHmFd0ZK4kVPPuGLrBA+1cM6ArxUs6p6WADq7s 3xGK1RSQhEr1OVZCoG+WEQ== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:58 +0900 Subject: [PATCH v8 5/6] audio: Add functions to initialize buffers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-5-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki , Phil Dennis-Jordan X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605079580139100 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- audio/audio_int.h | 2 ++ audio/audio-mixeng-be.c | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/audio/audio_int.h b/audio/audio_int.h index 06f79ade6b0a..290cf373b49f 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -141,9 +141,11 @@ static inline void *advance(void *p, size_t incr) int wav_start_capture(AudioBackend *state, CaptureState *s, const char *pa= th, int freq, int bits, int nchannels); =20 +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-mixeng-be.c b/audio/audio-mixeng-be.c index 370404505111..1419e7521503 100644 --- a/audio/audio-mixeng-be.c +++ b/audio/audio-mixeng-be.c @@ -1187,14 +1187,20 @@ void audio_run(AudioMixengBackend *s, const char *m= sg) } } =20 +void audio_generic_initialize_buffer_in(HWVoiceIn *hw) +{ + g_free(hw->buf_emul); + hw->size_emul =3D hw->samples * hw->info.bytes_per_frame; + hw->buf_emul =3D g_malloc(hw->size_emul); + hw->pos_emul =3D hw->pending_emul =3D 0; +} + void audio_generic_run_buffer_in(HWVoiceIn *hw) { AudioMixengBackendClass *k =3D AUDIO_MIXENG_BACKEND_GET_CLASS(hw->s); =20 if (unlikely(!hw->buf_emul)) { - hw->size_emul =3D hw->samples * hw->info.bytes_per_frame; - hw->buf_emul =3D g_malloc(hw->size_emul); - hw->pos_emul =3D hw->pending_emul =3D 0; + audio_generic_initialize_buffer_in(hw); } =20 while (hw->pending_emul < hw->size_emul) { @@ -1227,6 +1233,14 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void= *buf, size_t size) hw->pending_emul -=3D size; } =20 +void audio_generic_initialize_buffer_out(HWVoiceOut *hw) +{ + g_free(hw->buf_emul); + hw->size_emul =3D hw->samples * hw->info.bytes_per_frame; + hw->buf_emul =3D g_malloc(hw->size_emul); + hw->pos_emul =3D hw->pending_emul =3D 0; +} + size_t audio_generic_buffer_get_free(HWVoiceOut *hw) { if (hw->buf_emul) { @@ -1260,9 +1274,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 =3D hw->samples * hw->info.bytes_per_frame; - hw->buf_emul =3D g_malloc(hw->size_emul); - hw->pos_emul =3D hw->pending_emul =3D 0; + audio_generic_initialize_buffer_out(hw); } =20 *size =3D MIN(hw->size_emul - hw->pending_emul, --=20 2.53.0 From nobody Sat Apr 11 23:05:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772605124396202.35619635390492; Tue, 3 Mar 2026 22:18:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxfYL-0004EM-9i; Wed, 04 Mar 2026 01:17:49 -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 1vxfY2-0004D0-8w for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:30 -0500 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxfXz-0003Dm-Ks for qemu-devel@nongnu.org; Wed, 04 Mar 2026 01:17:29 -0500 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 6246H77v067747 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Mar 2026 15:17:18 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=a/H7TImbmJZ+c2VyUsniI9acZE7Us9dMDZ/gN5hNhDA=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1772605038; v=1; b=KPOMLUz8SZqUa4/aOEYGc9d2zw/Yj0kg2xZ+t4NVhEinGcZUc6gUcwhEWgxIrnWc piInmLEkdSAy9COMU/qtbKGTiOdz7ivJ5mW3XP8TUrfYkT+3hulgtdYPyPVf+mgv 65HApLhOdw1Zj8gMpjUTYFwx37vFiYAn8P8KWF1VQ64mPc3wMwCT5cqUqtEyVYgh rhWNSRHAWuX3za54/Oe9g3P/s6LL/MfAkRwwdXZyWM6rz5LUuvOUnsPJol0DCaqf LoiWUV/pXhlK8YAXquHpSNyK6qIkRK0MiSQidlYSvTNiAHgQhx+SBJpyuvZ+9MSf aUOAhsNZlwz5qa82yTGGGg== From: Akihiko Odaki Date: Wed, 04 Mar 2026 15:16:59 +0900 Subject: [PATCH v8 6/6] coreaudio: Initialize the buffer for device change MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260304-coreaudio-v8-6-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> References: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260304-coreaudio-v8-0-bf1d40731e73@rsg.ci.i.u-tokyo.ac.jp> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck , BALATON Zoltan Cc: qemu-devel@nongnu.org, devel@daynix.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Akihiko Odaki , Phil Dennis-Jordan X-Mailer: b4 0.15-dev-5ab4c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1772605126760158500 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 Reviewed-by: Christian Schoenebeck Reviewed-by: Marc-Andr=C3=A9 Lureau --- audio/coreaudio.m | 1 + 1 file changed, 1 insertion(+) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index 23c3d1f80ac5..e4ec1df971c8 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -471,6 +471,7 @@ static OSStatus init_out_device(CoreaudioVoiceOut *core) core->device_id =3D device_id; core->device_frame_size =3D device_frame_size; core->hw.samples =3D core->buffer_count * core->device_frame_size; + audio_generic_initialize_buffer_out(&core->hw); core->ioprocid =3D ioprocid; =20 return 0; --=20 2.53.0