From patchwork Fri Jan 24 05:12:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948917 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 0DD37C02181 for ; Fri, 24 Jan 2025 05:12:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBzS-0003KZ-8h; Fri, 24 Jan 2025 00:12:22 -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 1tbBzP-0003KQ-Op for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:19 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBzO-0000G5-1Y for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:19 -0500 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2f43da61ba9so2468866a91.2 for ; Thu, 23 Jan 2025 21:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695536; x=1738300336; 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=VC5srrpXmTmiRocFYx9LwhoK9ZBUM6/oC9S/Ro/eMn9+Pykl0HGJdAAcVFJkneT+im 3s0im+W+yL2L2HPbldSoH3az6K1/JdNn+f8iEnzdlhDP2Rvb8wYHeVx+g1hTG9tGgTo6 7DMb4fvkA1znr3i6dlMGMf5DvKZmYMefHgFdJjRUtX9Jpc2JNt6isbqyIaUaE5J5h1qh 7+6DSR0mvuD97RVQcvWp6y6Gc+ZPqEkEfp22J+FkyTWINsmsJlkdFXvulFwhp2lO9Rp6 3u4726u8ql5uqPhAyXk/P/0bd5zyYtS9/n6IlEms+AV8EYz724DmHojpc7AsFc+hkg/+ UM4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695536; x=1738300336; 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=FSAuGcReOtxAO8DRXoLqcVuNt8mKlCk0lRs0ZbU7xxW3LyLTOcB9FSI3sooSWV5b6U 6yAPS02GZkRZYzKLvP274R+pf1XaRvTZjG0t/IY6/s5vKp1c3BhYbiKf8ftk38r73w2j 11TjCboiyyi9J5aQZwsklQIhUA5blm0eBRD1pm8e2EP3xu/err0GZoahZEXBNeNsPnmq pG63dBRTHmG66/9hMytwmpgcvvWbeKRjcOcyt+Cg3aHO5Eh6B0LxVBbS+D41EVvU+ZdO +F8px8VTuAlUy7UVBHP3y4YVmdpqWCtPgTNd5ok6MmPaz6TLN5On8Z3tmfSEAzFarNKs TqdA== X-Gm-Message-State: AOJu0Yxi/2Na93ThBNK7pFGxD4yju9QL+6b5nsRZUxensNvyzBrhFLX1 9y3WFOfzol50jY0LO5/eH8LdUsnF0ypyYSJ9s23+iF/lfXnvx6yl34IHhTW1ZkO2PJwfSZBnsyn wKpc= X-Gm-Gg: ASbGnctY8BYZQlLMOV0ai6QupxiW7hIlz+WSPjbQ29+TCMysLoS4dDSWPr0ifalSgBX SurLLEstjlny+Kh31sJzJINZsSBjL3zSBva+3XuNMOuMVHlHsek6NcMGCmJqBI0Bi5tlTp2ZsvG b7hLHo21cLjm6QNrdVbGmpXT/vW/Gx62/p0wT9Um5cjxwNmIbcPKbhgigp1rxGbqHE1XB3WYVi3 QxRQY5L7gBH6/wtD2PcVKmwm5HngaGtH0JYyD43K79mv8FqHfBabgoTTX4goWimktj9iWllX1pg ugeFt81M X-Google-Smtp-Source: AGHT+IFQR7veNA3427gt+Q1w9A+lism8AIZBq4q+JA7zi4tFaNSM/5PO93Rt1wA1bp1Tt4TDxdZ1hQ== X-Received: by 2002:a17:90b:2809:b0:2ea:a9ac:eee1 with SMTP id 98e67ed59e1d1-2f782c92bd9mr44061452a91.10.1737695536404; Thu, 23 Jan 2025 21:12:16 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffa44cc3sm667189a91.10.2025.01.23.21.12.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:16 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:04 +0900 Subject: [PATCH v7 1/6] coreaudio: Remove unnecessary explicit casts MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-1-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::1030; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1030.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 05:12:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948922 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 D1234C02181 for ; Fri, 24 Jan 2025 05:14:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBzZ-0003Lc-45; Fri, 24 Jan 2025 00:12:29 -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 1tbBzU-0003Kn-CW for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:24 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBzS-0000Ge-9o for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:24 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-216426b0865so27595795ad.0 for ; Thu, 23 Jan 2025 21:12:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695541; x=1738300341; 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=s7r/m+Ynal1Hau8iDW2vBlCw59o8z1y0oQ4nfOltvLo=; b=Qjjy0zFi9EtoK2sTQXqU5OqCvYh5Zo1RtpBg6+Cyl8rUgkkzdhbnSEiNDw+gmOUn8Z Gbgyh8NJU/k93At5qZ9Wygglk2Tx/+N/7VDb+Cg3PxEYcAoWmwbGjyIF6PPPtT3KIuE0 agNZ4OOT5eGeb9GrJ1CddUrz+lXrLxjRjYAE7n8u2f4nDVU2Q3r75/h073sTuiFN/0V2 u5HxqzLiuWMUlmHruYFEiJtqFzat5x26ix/H4kKq75Dv9QeDre885M8nQ+nTrLZm4AEc p38kEbu5zcMvF3T0nXXwFH3ZcgYaiWJK2HgqEglLeXma1oLQakRQSrUDHDSrDxy+38Fd KETA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695541; x=1738300341; 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=s7r/m+Ynal1Hau8iDW2vBlCw59o8z1y0oQ4nfOltvLo=; b=jCJJBgS+HN8vrpXTNTZkMEdLy4y7/HRelDOsbJ23IVXH73YVsD/tAvhF9j7q24cApv TjynGY1DHEPKrnTndIFRshhykMDR8yB7Nbg0VsT340uAC9K4LNfpA8Rghu09pyhPyQYU OQgkvpfKMOwOg6ALh6CC3d/OSWUM+K3J8AZALObOHcPuJ9f/T2noPEE8puBRPUDd18eH kVCf0R7MKtuUwBBQkByEzs1ji0xiWokGTVpYQQz6iWeQgtbgV9KAs23b1ioBLQVvRDM3 92lvOdpo7gMpShQOvQv/IgEHHDEKOoCL2OOAXb4qLcPFUCCqq3dJbvhd11DIbPdtNqqm B2cA== X-Gm-Message-State: AOJu0Yx8velGWdVIMxC4A7DQMgqwj/4DggOyMeoeEqLNFoiPMbjEPBkq HCEM/QkqfQugr1htZvq3oS7woW3Fs9VpGec/1BN2xrTh9yaIt8Mt3Db2UGJzBa35oy7d5vaIdCd pVrM= X-Gm-Gg: ASbGncsLjWXwtsz6MPzZa75YZ3X2fAxQu0RXJDkgqLzZ3f3c+Yd/t7qMaRq6jrcDGsf a/SWW1R7RbXsLRScFDEahr++qNtLwbcgSEC2uEFT60mCP4Q5ZiJLnpJV8qdS0jzMETAld7czQ3H Ylu0X+elQm+pIzGdaY3Tuwv3cX7VQWm3PWBbhlXTIPIeEL1EFsO/xTe1xw41k34ejr09aX2RkgR /3RVLgkWbF7Lazs0dbdZUAAWSWeF7sND4pHS03iMD/5UYTFah9JZHefRFUB2FAzY15Uzx6WU1KR J3jPAWpyvHTOwkoKozU= X-Google-Smtp-Source: AGHT+IFmD6tR92H7g1qTfwFHwuCyokARPnkLLWIX8jC8F17hnI4A31uXhHcWglYXwrM7HyHgVu++xg== X-Received: by 2002:a17:903:2286:b0:21b:b3c9:3908 with SMTP id d9443c01a7336-21c35577cb7mr468067785ad.34.1737695540639; Thu, 23 Jan 2025 21:12:20 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da555a428sm5428055ad.84.2025.01.23.21.12.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:20 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:05 +0900 Subject: [PATCH v7 2/6] coreaudio: Remove extra whitespaces MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-2-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.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 Remove extra whitespaces around parentheses. Signed-off-by: Akihiko Odaki Reviewed-by: Christian Schoenebeck --- audio/coreaudio.m | 108 +++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index 0b67347ad7e8c43a77af308a1a3a654dd7084083..04e8ac59f4572c1e5fb7dc4f04f5e21520507ab5 100644 --- a/audio/coreaudio.m +++ b/audio/coreaudio.m @@ -149,7 +149,7 @@ static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result) result); } -static void coreaudio_logstatus (OSStatus status) +static void coreaudio_logstatus(OSStatus status) { const char *str = "BUG"; @@ -199,14 +199,14 @@ static void coreaudio_logstatus (OSStatus status) break; default: - AUD_log (AUDIO_CAP, "Reason: status code %" PRId32 "\n", (int32_t)status); + AUD_log(AUDIO_CAP, "Reason: status code %" PRId32 "\n", (int32_t)status); return; } - AUD_log (AUDIO_CAP, "Reason: %s\n", str); + AUD_log(AUDIO_CAP, "Reason: %s\n", str); } -static void G_GNUC_PRINTF (2, 3) coreaudio_logerr ( +static void G_GNUC_PRINTF(2, 3) coreaudio_logerr( OSStatus status, const char *fmt, ... @@ -214,14 +214,14 @@ static void G_GNUC_PRINTF (2, 3) coreaudio_logerr ( { va_list ap; - va_start (ap, fmt); - AUD_log (AUDIO_CAP, fmt, ap); - va_end (ap); + va_start(ap, fmt); + AUD_log(AUDIO_CAP, fmt, ap); + va_end(ap); - coreaudio_logstatus (status); + coreaudio_logstatus(status); } -static void G_GNUC_PRINTF (3, 4) coreaudio_logerr2 ( +static void G_GNUC_PRINTF(3, 4) coreaudio_logerr2( OSStatus status, const char *typ, const char *fmt, @@ -230,39 +230,39 @@ static void G_GNUC_PRINTF (3, 4) coreaudio_logerr2 ( { va_list ap; - AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); + AUD_log(AUDIO_CAP, "Could not initialize %s\n", typ); - va_start (ap, fmt); - AUD_vlog (AUDIO_CAP, fmt, ap); - va_end (ap); + va_start(ap, fmt); + AUD_vlog(AUDIO_CAP, fmt, ap); + va_end(ap); - coreaudio_logstatus (status); + coreaudio_logstatus(status); } #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_buf_lock(coreaudioVoiceOut *core, const char *fn_name) { int err; - err = pthread_mutex_lock (&core->buf_mutex); + err = pthread_mutex_lock(&core->buf_mutex); if (err) { - dolog ("Could not lock voice for %s\nReason: %s\n", - fn_name, strerror (err)); + dolog("Could not lock voice for %s\nReason: %s\n", + fn_name, strerror(err)); return -1; } return 0; } -static int coreaudio_buf_unlock (coreaudioVoiceOut *core, const char *fn_name) +static int coreaudio_buf_unlock(coreaudioVoiceOut *core, const char *fn_name) { int err; - err = pthread_mutex_unlock (&core->buf_mutex); + err = pthread_mutex_unlock(&core->buf_mutex); if (err) { - dolog ("Could not unlock voice for %s\nReason: %s\n", - fn_name, strerror (err)); + dolog("Could not unlock voice for %s\nReason: %s\n", + fn_name, strerror(err)); return -1; } return 0; @@ -271,7 +271,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 = (coreaudioVoiceOut *) hw; \ + coreaudioVoiceOut *core = (coreaudioVoiceOut *)hw; \ ret_type ret; \ \ if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \ @@ -312,13 +312,13 @@ static OSStatus audioDeviceIOProc( coreaudioVoiceOut *core = hwptr; size_t len; - if (coreaudio_buf_lock (core, "audioDeviceIOProc")) { + if (coreaudio_buf_lock(core, "audioDeviceIOProc")) { inInputTime = 0; return 0; } if (inDevice != core->outputDeviceID) { - coreaudio_buf_unlock (core, "audioDeviceIOProc(old device)"); + coreaudio_buf_unlock(core, "audioDeviceIOProc(old device)"); return 0; } @@ -328,7 +328,7 @@ static OSStatus audioDeviceIOProc( /* if there are not enough samples, set signal and return */ if (pending_frames < frameCount) { inInputTime = 0; - coreaudio_buf_unlock (core, "audioDeviceIOProc(empty)"); + coreaudio_buf_unlock(core, "audioDeviceIOProc(empty)"); return 0; } @@ -348,7 +348,7 @@ static OSStatus audioDeviceIOProc( out += write_len; } - coreaudio_buf_unlock (core, "audioDeviceIOProc"); + coreaudio_buf_unlock(core, "audioDeviceIOProc"); return 0; } @@ -370,12 +370,12 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) status = coreaudio_get_voice(&core->outputDeviceID); if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not get default output Device\n"); + coreaudio_playback_logerr(status, + "Could not get default output Device\n"); return status; } if (core->outputDeviceID == kAudioDeviceUnknown) { - dolog ("Could not initialize playback - Unknown Audiodevice\n"); + dolog("Could not initialize playback - Unknown Audiodevice\n"); return status; } @@ -386,17 +386,17 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return 0; } if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not get device buffer frame range\n"); + coreaudio_playback_logerr(status, + "Could not get device buffer frame range\n"); return status; } if (frameRange.mMinimum > core->frameSizeSetting) { core->audioDevicePropertyBufferFrameSize = frameRange.mMinimum; - dolog ("warning: Upsizing Buffer Frames to %f\n", 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); + dolog("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum); } else { core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting; } @@ -408,9 +408,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return 0; } if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not set device buffer frame size %" PRIu32 "\n", - (uint32_t)core->audioDevicePropertyBufferFrameSize); + coreaudio_playback_logerr(status, + "Could not set device buffer frame size %" PRIu32 "\n", + (uint32_t)core->audioDevicePropertyBufferFrameSize); return status; } @@ -421,8 +421,8 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return 0; } if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not get device buffer frame size\n"); + coreaudio_playback_logerr(status, + "Could not get device buffer frame size\n"); return status; } core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize; @@ -434,9 +434,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return 0; } if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not set samplerate %lf\n", - streamBasicDescription.mSampleRate); + coreaudio_playback_logerr(status, + "Could not set samplerate %lf\n", + streamBasicDescription.mSampleRate); core->outputDeviceID = kAudioDeviceUnknown; return status; } @@ -460,7 +460,7 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) return 0; } if (status != kAudioHardwareNoError || core->ioprocid == NULL) { - coreaudio_playback_logerr (status, "Could not set IOProc\n"); + coreaudio_playback_logerr(status, "Could not set IOProc\n"); core->outputDeviceID = kAudioDeviceUnknown; return status; } @@ -518,7 +518,7 @@ static void update_device_playback_state(coreaudioVoiceOut *core) if (!isrunning) { status = AudioDeviceStart(core->outputDeviceID, core->ioprocid); if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) { - coreaudio_logerr (status, "Could not resume playback\n"); + coreaudio_logerr(status, "Could not resume playback\n"); } } } else { @@ -560,7 +560,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; @@ -569,14 +569,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, /* create mutex */ err = pthread_mutex_init(&core->buf_mutex, NULL); if (err) { - dolog("Could not create mutex\nReason: %s\n", strerror (err)); + dolog("Could not create mutex\nReason: %s\n", strerror(err)); return -1; } obt_as = *as; as = &obt_as; as->fmt = AUDIO_FORMAT_F32; - audio_pcm_init_info (&hw->info, as); + audio_pcm_init_info(&hw->info, as); core->frameSizeSetting = audio_buffer_frames( qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); @@ -587,8 +587,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, &voice_addr, handle_voice_change, core); if (status != kAudioHardwareNoError) { - coreaudio_playback_logerr (status, - "Could not listen to voice property change\n"); + coreaudio_playback_logerr(status, + "Could not listen to voice property change\n"); return -1; } @@ -612,7 +612,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) { OSStatus status; int err; - coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; + coreaudioVoiceOut *core = (coreaudioVoiceOut *)hw; status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &voice_addr, @@ -627,13 +627,13 @@ static void coreaudio_fini_out (HWVoiceOut *hw) /* destroy mutex */ err = pthread_mutex_destroy(&core->buf_mutex); if (err) { - dolog("Could not destroy mutex\nReason: %s\n", strerror (err)); + dolog("Could not destroy mutex\nReason: %s\n", strerror(err)); } } 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); @@ -644,7 +644,7 @@ static void coreaudio_enable_out(HWVoiceOut *hw, bool enable) return dev; } -static void coreaudio_audio_fini (void *opaque) +static void coreaudio_audio_fini(void *opaque) { } @@ -670,7 +670,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 05:12:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948924 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 EE3CAC02181 for ; Fri, 24 Jan 2025 05:19:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbC6J-0007jQ-6Y; Fri, 24 Jan 2025 00:19:27 -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 1tbC6F-0007gV-7k for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:19:23 -0500 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbC6C-0001Js-Jv for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:19:23 -0500 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3ce886a2d5bso12731515ab.1 for ; Thu, 23 Jan 2025 21:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695959; x=1738300759; 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=eNvKszHorz0182xJOZsYgnwbAowCh/yan25Vyw/F0BQ=; b=WUilaJodiSCqSMSngYzZNYrDEQWUFy+W+2TzL5XVsgBKlrtaEkdlEXKMCgE8soZHTj dTClqF8iMhtqAFkbiJY0Weha/oYsveay9VJld7JrgFPo/EXIsoFCWHv3lzbpFV7FG0D+ I2EQu495wUbnB8nF5rT9Uo9tjDBQLSb86F953BKcev2A3+hiBmMHX3F7/7sUAr2LIOv+ q2BRVqC0wqU2IxvmsEfvFh2mgVBQnfo+pvgxwjqVV5GYaicPYlwCsFulk5B0S0j3WBk/ Ls4e1UE800a+cNep/ttnH7AaeOFecb040W0Hhd6QBTvJurPRrmLdTOO1R89RLhvfw4O/ HMSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695959; x=1738300759; 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=eNvKszHorz0182xJOZsYgnwbAowCh/yan25Vyw/F0BQ=; b=s8n0iLmB6fgfVfw2qrXBKePSoNOdhmf4uz4ZLmgAtCHCL52oO7oyzMMR9zkozwk0HD ZlKEyUrMRQ75q265e260gu0UCTegAZaP8iL1gk//Y2qFgKZHVMVAaxA9iTOieIloclPQ DWOmaL7x8O/EhBRJRvQJ5vVk459H2q7cUAcaf0bJURaNrW5DQo9GHtFDenWFtrt0Ko0p J5bq1uysPpUQhYQ8jFgQx1B03V6HqIb9jiTjqXbsWdM4awlj+38EjgGwfU5EoGGbqKIf Nr8QUHlyITSoFnub/ri+zy+zlV/EJcJ/+7wsIyW2jKijAYJ6hATwi6xIwJlVOdGj3UY5 Kbbw== X-Gm-Message-State: AOJu0YxuX9tcKeCOa1MHLOEOeizAgiHMtUxfUvG5FjVC6YPECoExrTal SL7iHFTlLM3V36APxJCzUFUbgLm/Uuru7vWfdPXTllyyN2BG9cjEXfzqY14D5LlFTUPeqxUiu4u XMCg= X-Gm-Gg: ASbGncueaHZ9SddqG84M2b6sNVH8oJiM4ceUq9uKE5g6ORz7rgxPWCZ+QDl9Htk/Co9 DTkRSOMGBvaspjn1QM7r87W4b12gnYSoREQYlZkgM/Zps1MY0yuRj7oppbObEV2+j7IkGhkOPnE EAPyrhudNclXH7jsdIBazkj9Nf5rDVumUj67BWb4YAnNcmO95msfMM9k74h4EbuxAV0fvIAcgJC /iQFjvPfXicw/V8vxL4c76d8AW111VX1DIFwwlAWqYCJEavbp2uf25fN5wSgZfzs1ZN6wgOpAhm 7Pmeaue1 X-Google-Smtp-Source: AGHT+IFjT/qSMpIrZ/uKaguf5hPwe7rEFQ70dLjYSNlV1hvnQdFv+uJxVNWPVquUcrYf8Ib0pH8voA== X-Received: by 2002:a17:90b:38d0:b0:2ee:d35c:3996 with SMTP id 98e67ed59e1d1-2f782d972f5mr40983865a91.31.1737695545726; Thu, 23 Jan 2025 21:12:25 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffa6b2bdsm670460a91.25.2025.01.23.21.12.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:25 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:06 +0900 Subject: [PATCH v7 3/6] coreaudio: Improve naming MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-3-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::12c; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12c.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é Reviewed-by: Christian Schoenebeck --- audio/coreaudio.m | 193 +++++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 95 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index 04e8ac59f4572c1e5fb7dc4f04f5e21520507ab5..6f170a909983b2a5c6abd6fc04c6c3f32828c10c 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 05:12:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948920 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 1D717C02181 for ; Fri, 24 Jan 2025 05:13:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBzi-0003Me-Rb; Fri, 24 Jan 2025 00:12:38 -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 1tbBze-0003M0-0e for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:34 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBzc-0000Hl-5j for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:33 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2156e078563so23718035ad.2 for ; Thu, 23 Jan 2025 21:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695550; x=1738300350; 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=eTpw4AwgYNUkCwOt27kW7PR4isG8aZO8Eymx6q5/DGs=; b=iUDjs4EkOxuTwEUfyu4QvPLC4VMesRjZrq+sC3/igK8YEp9o331DXNHHqwjnMX6s3Z 9H9KQ3eWC1xupjPfNxhwz4RXbFlF2cOavnzmjTEjiRBcQbDxULXk3NUBPZ5GNVDCSYA+ AnL8pdWDSq4wQDnyNDVESo4KhTEiAiJmE+0CManqWaImHX8/lH7Hb35BIAuBBuu/6KEP QithG65yFNzE/yVCmyzSrM/XV+X1nVRQH/61Hotr6fFkOuQZy0q0JB5pWGML2nzD9B+A 5E62CApCRcYnj06DSTjExTN46FHYI/63bzGhoRjgyim5QKS3B05chayT/inXR0gJfNdb Qh9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695550; x=1738300350; 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=eTpw4AwgYNUkCwOt27kW7PR4isG8aZO8Eymx6q5/DGs=; b=YCL3HOxbj+fPMhxHrIQQuTDRbM0cAs4zlgwiXfGNysUBtGKcY+vogppsfKpbT6uaqP iWxptcii6FbpYPSGC/GW9PQUKl3yaCGqoJaHsgpKq2cZ0+mbVdI47KVIuMEJ2cK95zv+ 9SD3trI9SKJuwYrNtIfyqXDNqDAbTMd8vV9jF9478diBEZMU/MKU2zdrhPE+XVXywsir IvIGW3fUSpFjmEbrjmaq+OVdryyT/ULitZ7Mab6U4cj5yTR1uekZsiPorGagWZJM5uw6 qWVeqRqWAVYOF9IcQPufOqgPMo52PCUSQxYsUYdAgk8k9Rk8dBNZBluTBUfkjwGEI0FV cd4w== X-Gm-Message-State: AOJu0YxmN3e38MfKQAc3fMazfTBsaXTmy2eJ9fgKChocHyrhp6ANTbYg m3exc1HR2n6uVsbyyDitIegtmIjDQNKBF+zg9eV+7dp/23AHkm42barM3OIMZpN/3wLYXYoVNrk vg7k= X-Gm-Gg: ASbGncu64fDXA5/AuOMJkIGozDgcVrZlu6dGVWsnt19VUjQFASiMyVCHNI4tfq++pGB LrqGo7QJKe73RutSrpdczhEm1n5Nx5zA9L/yAYD/4UI0RmM5AbQ0oTi84KD3IfUdKIxdHTRZ9VM ozSvV6Kcq9A9BSlFxWfEbFHmoMnX4XCX5cqeDIEH88z2osMw1i6aDkBw2rxCMIhdBUAHgv1dR12 ju5vonzYRnuYhTca67Kio1VJbNrhpBiNhabMqKsXN04nn5RM21QPTWDNwl/0EmmxvtF/KYf/vVX 9Zz8IqBA X-Google-Smtp-Source: AGHT+IE66H7/8702WeVhGd+qOs8zkORfdtW4FA+mNH2Fsr//gSVGrIE0ep7ydXW869XJaLDYc6RBCw== X-Received: by 2002:a17:903:234e:b0:216:7d22:f69 with SMTP id d9443c01a7336-21c35613b55mr352971935ad.50.1737695550641; Thu, 23 Jan 2025 21:12:30 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da3ea31cdsm7773195ad.67.2025.01.23.21.12.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:30 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:07 +0900 Subject: [PATCH v7 4/6] coreaudio: Commit the result of init in the end MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-4-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::635; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x635.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 6f170a909983b2a5c6abd6fc04c6c3f32828c10c..43a5f837ba4cfe4464eaab8f1693696638e14113 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 05:12:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948919 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 4CE26C0218C for ; Fri, 24 Jan 2025 05:12:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBzm-0003ND-T4; Fri, 24 Jan 2025 00:12:43 -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 1tbBzj-0003N1-1O for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:39 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBzh-0000IL-87 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:38 -0500 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2ee74291415so2430207a91.3 for ; Thu, 23 Jan 2025 21:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695556; x=1738300356; 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=HRBsxvighgfrv8xRWoA8s9jARR/nsISmueJJT9zFahZIodtMnLwBL5oHSBeKtNsRr4 /ZVHs37JCWbnE2iCOkFZx++4Xz4Odxb0x93ZmV2EXMRWDbTl0Ig/S9WVCjIrSFfpIVKE XzPOOwJoauAJ2UZESJF932UejDPaOKkVgc8WqxgtLDDlEycepnB0Asl3dDw+h4cpQ5So kKi+3Mxl0dJgNUI4xv+CiPC9W8Bqs/ZT31ioweVO7o4Cd2aXqgNkdtyDk3/VONcviulO ruWNqn9CDLg2Qy7kkAY6xh66alzNHIFcqeuQ0IgkiOzG6ilSKqmkWVMeTexG2t+ZfxyB voPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695556; x=1738300356; 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=Ne9hrroUOXriloHHzXotJFH/jHS8GYTrMn2SeWXljA/0NEj6ED1bdDDHLt4D9u9BqQ ffpM73b4AxL7n66GbUfjqBVdZu6jxbqfCi5f4aKgOfwJbTHgS/DUpwYIVJKYxXtzkj06 EezTLlzw6+mB93EfPgNeYgR8ZfAzTlDa7HHqo7C2YgMlOhFlgVMwOU/RimpJgG0g2Zx2 kFoPkQB7qm5SYvC/O8u8AQOWFcsxlxwwBH1bXmcSvE1ikr9Ojalb2B4y+VCjw6btInUe inoCMWijF6CbcJV8tQnAG+ALNAffOoFg1i2Q5XFLP8Jm+nW7OpJNZ/EV9QTqK2M4k/cN 7ZPA== X-Gm-Message-State: AOJu0YzIJXL23vitqdlpcygZzKhF0zxzhznYMraDRO5yN5DYggy4jRNv 4vBc2DNgCIgMWfD1AmkSizZZYHpo0lzyLMXYBNeCN46zdgbh8alNksCGpG1Awe20QsRSSpTidty jOMc= X-Gm-Gg: ASbGnctTQ70zozKXZFWp/4RvHtop3uQiAkCkFOEIrkZTGRlBxPwL5QG3B+WaAa4Xkux Eyv+d2AgdpDIM7etbMFcJCWWcBlac/UnIB8GH3qEO4bH4qoE4lUP8g5Lv1mNwny+KkEeJr05LrT n6AHsCDXI1dSaAsuL7jV3Yb7U3SxD4+4WiRkPMj3UhkntRFoukyJF0SFcTwI8CjLY74JBi2K/0k E0E/v/aFqEy4ZWF0pcjB9uPtYO7m1hZSeL+VHCQ/u34xprD9vmQHIr1mQv9SK1ln6jLkpbPfs2a SIV3eAAw X-Google-Smtp-Source: AGHT+IHHKJJMgySAVNEEeRdAsWcztyEON7u7Z76JcUbbL/CUGS8JPM68FiNCzwJiBQHKymGDWkOEyw== X-Received: by 2002:a17:90a:c2c5:b0:2ee:8008:b583 with SMTP id 98e67ed59e1d1-2f782c9c88fmr45584761a91.16.1737695555692; Thu, 23 Jan 2025 21:12:35 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffa6b315sm667766a91.26.2025.01.23.21.12.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:35 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:08 +0900 Subject: [PATCH v7 5/6] audio: Add functions to initialize buffers MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-5-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::1029; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1029.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 05:12:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13948921 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 D4AB6C02181 for ; Fri, 24 Jan 2025 05:13:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbBzr-0003Ng-7g; Fri, 24 Jan 2025 00:12: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 1tbBzo-0003NY-0E for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:44 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbBzm-0000Ja-D6 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 00:12:43 -0500 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2f441791e40so2466038a91.3 for ; Thu, 23 Jan 2025 21:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737695561; x=1738300361; 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=g+lXBbs5YuiYag7M+LKLMwPIA9V9eQc3hh5ELptHd08=; b=lSYpWwlq9jYof58bB6qIX2aiwRcZ9plw2Z4hkZvMh27sZNYOxJ1S9B30GPDG9irocG qaVvH11kmmB4Q3TyQshA2YNUyHE0h8ypyOqrOyHUvwRVbZnO0TOIc069m5jEXl53CxWD DejJucf51H4+D8egbeD7GJJk6dCVRSCCupqkNE1FUmZ+1zvCG6v/6M2Hv4BlVHinukki nJv465E4GJaBxDjUoTbE+FJzYdYHiJ2/5V0YgrEylnxIYNZMSkgxdEe2coBV/Vy7Sav6 AOhAhhNoPVNzyjzuGdgF2wE8d+d5WS6EeZQIf8DiDpAjtRR8FsmWhCX+J9t63AeGsEx2 qq1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737695561; x=1738300361; 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=g+lXBbs5YuiYag7M+LKLMwPIA9V9eQc3hh5ELptHd08=; b=onGLhhftK1aoipJeDTxxxy2cOXvgWIeZfvAk7Pik/MGGQcUbJo8KqVtTVoKWquvkS8 VvPbtNDaNwtACqndvgBR1U13a/nATjlOtyxnSY6ki6kchx37s+yqnT59vVftMI/Y3lhU dbLTnHhf+yzDrgu2IItQChDdRer4P9Ve4V7dZEgRDZzeUuERmXtjcmbL8E0w1EIBcOsN 15yf8EbYfFTRet/wXyjSpqGmmQOFyTxYTam0XD1xLdLVpw3EoLdFHh6eEB80vLufb2lj dvALMCm1aqtHd9K36fzt9RJdyZzU6YLL7e8iQDG8Hr40P4TQfhYHxI3at1CBKVe5zw31 o0cg== X-Gm-Message-State: AOJu0Yz5r3gphBx8svBe9WmEB/EzosG/63KaBNoG5JHXBpjmLHXP5t+K GSeQQA3rJZSIaWE4CEyJ8rD+RjqfRmPNUBZakjPS2FTJUJBTNy8M3t/bGwmIgysomSJaGMqQCh4 x5Qo= X-Gm-Gg: ASbGncsK8xsWOL3bN4u9GbD6ca6UFvwmn+cE6erYC0szrkzlH8Nn1DYK5bZxD1F+9xa 5J0Rj+W+qgNBfPLMquVzC39EAmry4P1SORsTO/uHR1PnoAxWzMeJXbhRuVEWXiaPppZ8A+Y9wUG pQPPTkw+YxYt7Sx03hSWemt6yp/fJYaz5Nqk+Y5MzGOQE43y3vwwAvgHMWDEJI8qEatBRV9tcUB ich2KEgplvl5bX5OaIl5DSqPZlbnBrDwu3rKCuv5H8H4T01snbua08PgHkUtGhRJ7l8NZIMF+tO uffqVdTz X-Google-Smtp-Source: AGHT+IG5GA3c262fmfqBYrYphoG3LFLWJZvCyQi7pnvD/+6bHwYIQ3K7scFfPfvQMNVUbT91Ffd7wA== X-Received: by 2002:a17:90b:568b:b0:2ee:90a1:5d42 with SMTP id 98e67ed59e1d1-2f782b179efmr50107278a91.0.1737695560854; Thu, 23 Jan 2025 21:12:40 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffa6b315sm667914a91.26.2025.01.23.21.12.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 21:12:40 -0800 (PST) From: Akihiko Odaki Date: Fri, 24 Jan 2025 14:12:09 +0900 Subject: [PATCH v7 6/6] coreaudio: Initialize the buffer for device change MIME-Version: 1.0 Message-Id: <20250124-coreaudio-v7-6-9d9a4d91db37@daynix.com> References: <20250124-coreaudio-v7-0-9d9a4d91db37@daynix.com> In-Reply-To: <20250124-coreaudio-v7-0-9d9a4d91db37@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::102a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102a.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 43a5f837ba4cfe4464eaab8f1693696638e14113..6ca5c038c9fc176238a9d845e8705177c0d2341c 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;