From patchwork Thu Jan 23 07:18:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13947965 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 A6224C0218B for ; Thu, 23 Jan 2025 07:19:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tarUG-0007UC-6K; Thu, 23 Jan 2025 02:18: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 1tarUD-0007T3-CT for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:45 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tarUA-0006Ci-HK for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:45 -0500 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2efb17478adso1138457a91.1 for ; Wed, 22 Jan 2025 23:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737616721; x=1738221521; 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=ZqwJ3lt+S692i6rY22sQ+2HVEoq+Ggl5P39jwm8jG6c=; b=0z/J5m+tNZ1e+ZDApW4Sp+7gf0tC1EC7+Ta/UZ9L1LSPxn8r3q6bV8fVqz+expS7LK oi9plEYIzMcNKWcPtRpf2Adb6nVkO3xoTb6QusKGdVW1OaOeThG5F6hnBMpWJoeSqwcG Y5p3FdOmZaLeTWESa7ck4DRs+izqD7itmc8w3YTYcBTxaQapOrfPLpIykatCmMbbrF7Y UJ9WRoFQU8QmD+WRXE8eAqBi9tHsAzsAG4Bd3MTk2Z2CY747lkKMSKLritsaTPcjOLxs xoJ4r0lc/RUHnX/tEWKzF6WcDmKQkYaFxEL7hnBJXVnhRnJHZETx+7htFAQtiUycDOM0 Ue4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737616721; x=1738221521; 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=ZqwJ3lt+S692i6rY22sQ+2HVEoq+Ggl5P39jwm8jG6c=; b=Qc+HhvvAtx0mSCXN0GC7ry9TRvW4X1Sch3t/eO8bfjQ9q6pHZOR04dcj3YMNRzOo2L ueGyUsNck4hN2uzDMKxHhs2oxMVc4oILXdm+pW6/G5EBP9NVpTDiIsFw6P9zNuPSwYnu e/bT0+T2uOzaqOtO2pdS8c2Nh2bKU9jw58ke+n0OUGsmPhcztM19ZY7o4IPFOVbkW3v1 W8u/4Yj9JZz7CfPLkpDDzcHS1PR9XBvEEE1JCmVDxaEvtAyvSabhXkixx+NTV3LuMh4t 5q/dMLU34abd8KPjy/QvP6jIAUSpiYZ+faxsHdE2ljoOY7MDau08IDaY06pRH52LZCZV RXUQ== X-Gm-Message-State: AOJu0YxXSq64a8SZ6FTivIi9aalDyPtTnJQGqHfVPYJeM0/3vH3H7HcL h15klt/ZuDQmbGPRAoGjv/+Dvt8AaQMFys9eNVIni/ZTFiqI7QrsitBQ5hav4TI= X-Gm-Gg: ASbGnct91D/UiSwVX9QimPwVJNM+geomMkBH25Tiszv6mOEBmC+RVur0cLapNfB7v2C K9wXj6tysKhRfSKJz7a7dn9v2XppEVRfjK/lY8iDEFzKyFF4P/F5z9q6+S9WALtn8NGfFfKM1e9 yMBEHdyAQGN/zjBuJzU9WDURDd1YeRMeNCFJoYw17t18+huzmhTUUX6kM7F9EDWKQOmEL6MG5nM C2Pf0A3xJvjAFe1YpamzT20m43WrcLrWsSmmxOh/CAgicZmxux+k3lEKBqbzuJW7PAShEGB45DK nRuuvx2N X-Google-Smtp-Source: AGHT+IHNigt71t56kq3/8hvS8xUkWU5FBybI15QihYS3+igVdUYYDdekuIuOBW+AOGNwZEkOupjt9g== X-Received: by 2002:a17:90b:2c85:b0:2ee:f80c:6892 with SMTP id 98e67ed59e1d1-2f782c4d587mr32582051a91.3.1737616720780; Wed, 22 Jan 2025 23:18:40 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7e6abee96sm3062508a91.31.2025.01.22.23.18.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jan 2025 23:18:40 -0800 (PST) From: Akihiko Odaki Date: Thu, 23 Jan 2025 16:18:29 +0900 Subject: [PATCH v5 1/4] coreaudio: Improve naming MIME-Version: 1.0 Message-Id: <20250123-coreaudio-v5-1-6873df4215a0@daynix.com> References: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> In-Reply-To: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck 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::1035; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org coreaudio had names that are not conforming to QEMU codding style. coreaudioVoiceOut also had some members that are prefixed with redundant words like "output" or "audio". Global names included "out" to tell they are specific to output devices, but this rule was not completely enforced. The frame size had three different names "frameSize", "bufferFrameSize", and "frameCount". Replace identifiers to fix these problems. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé --- audio/coreaudio.m | 191 +++++++++++++++++++++++++++--------------------------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/audio/coreaudio.m b/audio/coreaudio.m index cadd729d50537850d81718b9284efed5877d9185..d6469b77cbde3d84a40017aed64279ab4fce6b29 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 = (coreaudioVoiceOut *) hwptr; + CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) 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 = (UInt32) frameRange.mMinimum; - dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum); - } else if (frameRange.mMaximum < core->frameSizeSetting) { - core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum; - dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum); + if (framerange.mMinimum > core->frame_size_setting) { + core->device_frame_size = (UInt32) framerange.mMinimum; + dolog ("warning: Upsizing Buffer Frames to %f\n", framerange.mMinimum); + } else if (framerange.mMaximum < core->frame_size_setting) { + core->device_frame_size = (UInt32) 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,7 +636,7 @@ 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); @@ -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 Thu Jan 23 07:18:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13947968 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 EEF51C02182 for ; Thu, 23 Jan 2025 07:20:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tarUI-0007VS-Pd; Thu, 23 Jan 2025 02:18:50 -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 1tarUH-0007UK-Gd for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:49 -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 1tarUE-0006D3-Dq for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:48 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-216281bc30fso12569145ad.0 for ; Wed, 22 Jan 2025 23:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737616725; x=1738221525; 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=pLPszRf5z+P++6TKNc8EVJlN/G55/bMgM7kgbbSSz1c=; b=yJAnEoxbBU4U2numWx8cBwRZnMaJCktMxBeXjP2YLi9B9PvkvMWnvmh3VcWDOXUb5j ZnzuIKGVkXPENu2GMLP+He6Ps32svG2hZpwVvnCQ2MMmZWe9qxVXsYbiC3KVPth34yMb Sdk9OKqMNw5WLV3Oxkpq60Ai/9cBzCtlyIv6OlJnYakWkbFbTgKXefMcE4cNy3PWoicf U7jcgtcTC/vQ9pg7XB/zrn6aKmsqOd5W3UBzC0FoH0uvfXxOLTS+bdxVQCi7Om6wtfY0 mNDzChrU4O71U5e+1+/HqSTv0ylsX9M7RnCKcwqE44ZbTPUxvVrKulvL/Y4kXnL0G7OL o8kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737616725; x=1738221525; 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=pLPszRf5z+P++6TKNc8EVJlN/G55/bMgM7kgbbSSz1c=; b=q5o1VPuFXprF/Hk7tHoFzHlQ1v3nXZglqt7QEF7Rdu0fvOAzpcah48iKU/krmfnA55 u17o8BV1kgLKTXZECjPyUsN9oDxOgSSE1euNME4lq2Z8zEFbQwyAKffesknm5MUu9uzb Flnj+kKEFNJ9zkbgg06g8g68EP2dn7GMfWJBbSSI5dqZS6Pper0gCAGW41i5RjnO5TfA dMQn38itufNYD0ef4KP9e4l0CS29NFce4TR9vidk8IGjPMvnGHXjFE30ARuGKsHZtHbQ 1u2tWM/+OyRopt9nOdv32B8KctAwS0J0ecorCI54nzLNqLDAMVkYzHng0g35ZG6Q9xuk E0HA== X-Gm-Message-State: AOJu0Yx6kS/VP8Rr2rWCpoeRD6W2BYah2HkDpeN3Ksl887u2s+BxmsDM UNm+qUvNzqEReQO6eSB/c6zQQ/JPa/n51aDdBKq1tZFCQwJxFi1qajFRwoHQUp9hAyFJm0sy+tG f+F0= X-Gm-Gg: ASbGncvV+j7O0xcNF8mUlqj1bZbnKzqyAXuWVBoSeE4KPZofmbOzFjsIzpD3GhTVB/9 RjOfxiTkMVbOsHR+sFfUaT9nAfho4qvXikJ+b0gPWq+mU5jLUULe45Ly8L2qFEh+JUkk7alaf2i RDFJ+ZEBjnBZTOmg0ANiv6rmw1Uoa46NXeTeDvGstTZc7TNqzyyUJOihCqWUtIqsF5PuwetFou3 uqxfQBoibrcKqQoOLfdqEYaB23MZ7KDg1qQR5h1iyoa3vSFxACUZVHhR80kr6lkICTkaNaO8jbG 4YCpqUMT X-Google-Smtp-Source: AGHT+IHG71N0QYJXYNnld0YfPcCsh1t2ARibmJoY9fGOTeQD8i3Tli5lFT7RpMBbpkPI8D3XW7PRwg== X-Received: by 2002:a17:903:1cc:b0:216:2474:3c9f with SMTP id d9443c01a7336-21c357b6a7bmr332836005ad.52.1737616724921; Wed, 22 Jan 2025 23:18:44 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21d92a67da3sm19943405ad.225.2025.01.22.23.18.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jan 2025 23:18:44 -0800 (PST) From: Akihiko Odaki Date: Thu, 23 Jan 2025 16:18:30 +0900 Subject: [PATCH v5 2/4] coreaudio: Commit the result of init in the end MIME-Version: 1.0 Message-Id: <20250123-coreaudio-v5-2-6873df4215a0@daynix.com> References: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> In-Reply-To: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck 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 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 d6469b77cbde3d84a40017aed64279ab4fce6b29..a8d71c6cf816f7658037e26608a4c1101ebd071e 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 = (UInt32) framerange.mMinimum; + device_frame_size = (UInt32) framerange.mMinimum; dolog ("warning: Upsizing Buffer Frames to %f\n", framerange.mMinimum); } else if (framerange.mMaximum < core->frame_size_setting) { - core->device_frame_size = (UInt32) framerange.mMaximum; + device_frame_size = (UInt32) 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_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 Thu Jan 23 07:18:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13947964 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 A446BC02182 for ; Thu, 23 Jan 2025 07:19:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tarUM-0007XH-2P; Thu, 23 Jan 2025 02:18:54 -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 1tarUK-0007WI-9U for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:52 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tarUI-0006DK-J6 for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:52 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2163b0c09afso9611245ad.0 for ; Wed, 22 Jan 2025 23:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737616729; x=1738221529; 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=X7NnqSLbP50yyPr1nvmPp8EVEX2lH+TtUMccwxL8k+p9i9XTqZBEVh1mOyOWeyODOm FyQ+DwyzXZ632ZvMuGvrsQr9gCI64gfAXB+LjM2Y2gFpTEf4m5VMhl+0N9I8h47SqL0F dBWLiAzjuIKdtXCLTLnqWM9Spst9QMJ4Y2Y+JPcEZwyNZ3uES1i9a2IcxEcrrq14F7ed AGZzco1KLb8lHUwZQta3KcB1PnqlJFwItgSflokNqZ3Wi4K8uO07nvcw1qfa7O9Ixom/ Dy58e9Q5bwG/07QoU10vFP7+HoXP2rQ7IfcazlxYyenfvSrvJ2cYXpFPA1c0bVu92XXL MjGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737616729; x=1738221529; 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=jNUmSu2xwMAkggKqW/qbo3FHmqGfBzW4kpklqbzYg+NBD0rk4RfOz9JpNeLJciNp/F JTQgV7RhkSF4ey/ELgN4nIcr27GziIQM0KGzOlSO77Z0LmPc/Q6wfcnSYcEGOWNzOFV8 CKcz6gFKC5/cnzQQ21EGIv4yREv36J47JxELzDqq1/PWPoU9rJ4nUX3/mH5o585y1rhb g9OUzpW1uWEHDnGMOQQE7CzUHIE3MnOCPOTQUdujbeOA/cpy4B63tnF4BsKRPDzsQme+ EP2b6/yuEsLpVEeWanFXPIDuulVOpal7APgL3qLysku3QAEnDynreQCgzCPilQzkluWJ ZR6A== X-Gm-Message-State: AOJu0YwwycBw/qbV9HqzLGoAbCg7vHKhcQQFZOefOQOafxcXkYs/UC/y iSg111cL71E/40HOsRi3WVrJX/Rs7J5UlAVDGM/RSIYEqLAKKlIGWagthhcegUI= X-Gm-Gg: ASbGnctRxeFfRVjZ+z9GVNOZOSGQ8ltcTOgRqxw6wArB3HdiQWL7C5ch2t1a0Pbliw/ lqtDJ48vIs5vRZV05s+ocowfHbFR7I6emsy2QkwkEDF5OCHUd5WsiY4p+dq4bUyLf+c9WKGj+x9 +lrQtiKMHw2TPV/w/8RMsAv0gVxcPp9GHQXCVGEeolxqtV7LLAJuYxYkmLFzTU3jyWj3RKkSb9z mFq+zLETOOvjU0v3dN8/Yz9jrZ5Q3ypnCA41HiYH4sdvq6tWYvKgiJPV4E6zpk94f5qGuvpPxJE YaXXY+5a X-Google-Smtp-Source: AGHT+IGWFk/C4qu2ySbEIlwWdXkpRSKfXoca0h8O2asfkukSMzKeTW2ZpjY4q3Vq60WQW+u7KrPEEQ== X-Received: by 2002:a17:903:2342:b0:215:cbbf:8926 with SMTP id d9443c01a7336-21c355b053fmr370941785ad.35.1737616729260; Wed, 22 Jan 2025 23:18:49 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21c2ceb8cfbsm106203235ad.63.2025.01.22.23.18.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jan 2025 23:18:48 -0800 (PST) From: Akihiko Odaki Date: Thu, 23 Jan 2025 16:18:31 +0900 Subject: [PATCH v5 3/4] audio: Add functions to initialize buffers MIME-Version: 1.0 Message-Id: <20250123-coreaudio-v5-3-6873df4215a0@daynix.com> References: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> In-Reply-To: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck 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::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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 Thu Jan 23 07:18:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13947967 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 EEF8BC0218B for ; Thu, 23 Jan 2025 07:20:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tarUR-0007ZD-AC; Thu, 23 Jan 2025 02:18:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tarUO-0007YD-Mq for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:57 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tarUM-0006DX-VR for qemu-devel@nongnu.org; Thu, 23 Jan 2025 02:18:56 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2163b0c09afso9612355ad.0 for ; Wed, 22 Jan 2025 23:18:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1737616733; x=1738221533; 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=dnbmNif4o9FGZl1LjI7Slk5zmQWIsYzZyTRTPo22AKw=; b=1Ml4+yUwynxmleGGG6G263127R3mRHMJTGEgIQ8FmnLqK266RlX3pbHYmc8Wy8a4SH QwfMAhENgbdD67vGHo33smto14GeF9Lr9zgXkIrKLJcF+GIZ0fSGXd7KJwnBVeNHCEeR FjBHg8O4ewpnKwgRsKd6vOUWQJQfEAv7iLfvpKFtiP344EatYJyNtbGAnpL4nGtLiaO/ cKteE+eakNv/TOk+13nMhB/eCVhsNStJ2ED/ISy5fsAS1/KIKnlYETTyKE/6uGUTSULR ED1vwtsQ6eRCN79ux4CwcHMMgRY56rROE+KIq5a0CczGQmdfC1ihRQf4YcBkkflqGsKx Gnww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737616733; x=1738221533; 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=dnbmNif4o9FGZl1LjI7Slk5zmQWIsYzZyTRTPo22AKw=; b=GNyMbdl56inCaXGxTDXgkUYEXJqj0guqu5GuA8Qgfi7HuCN9DX4vEM3J1Sn8YWu7Rk lkcVzQU8TDHjYAGUP8gZ++lt6eoN+xkbxU/G8gwrcdaC1B4Ri1H1XWfPagTt58BnGydp 1wfeErUee2LtpIswvkMy+18RLaG37JGgEiiMguNkD2lHiOUyGoQ3Uy2yiBhfRMlHe9eA c452gmrzPJstkmO9un3lr/wFCDo5PXeuv/o3wTit1+yPUSWpqpTtXNomnPhA4PzUHOub jeZrr5izBauE/SDyHY33FLEPVtn4P/8jRKE4C2GISSHDk3wj5meX5eodMvfWQqgeRnAR uXIA== X-Gm-Message-State: AOJu0YxWh3R8tVOu26RyiOAnLRUs7dJRdohoDmt7q0yuZLCdwy0iu/01 qOL9S8koI/tAc5JZD2rrOnJYVS0km1ngpwllMjZqQ5QgLKFA53lnRCW1bav8FPU= X-Gm-Gg: ASbGncti6Qzo3VWJMtyIHbzRQnSQjfruGYHmLopw0zsD8UCbKGNeKT4QUlGku8S/qzt 3D3jb14iCfgTQrqK+JirG/aaLxVpBsjL3xH6RTl+G1GmD+G0zjFVdb2MUU3PEoMMYtUsseAJlG8 47kV/IiS/8T5uuCSOQHYk+IFx/b8j12GJkTMjenkSGReliO6YkRzLs8NfTo/cl7Ted6Ou2rLDHy ZLDUxf5FkF9eT2z0THWM3zJ3hdxEGgAVnj33VjHPwpFY1J79uW4t3swOdrDVjlZJPbDaw1Hl0Mx 0fzh8InF X-Google-Smtp-Source: AGHT+IFuf0ALdxA2AAO9i0FcV5uXd+RctVpJCLDnzAWVPnd/JBJrJFOPK1SIIbhwBh4c+eDiNSTyug== X-Received: by 2002:a05:6a20:2591:b0:1e1:e2d9:3f31 with SMTP id adf61e73a8af0-1eb2148df72mr35037552637.16.1737616733530; Wed, 22 Jan 2025 23:18:53 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72daba46239sm12329319b3a.123.2025.01.22.23.18.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jan 2025 23:18:53 -0800 (PST) From: Akihiko Odaki Date: Thu, 23 Jan 2025 16:18:32 +0900 Subject: [PATCH v5 4/4] coreaudio: Initialize the buffer for device change MIME-Version: 1.0 Message-Id: <20250123-coreaudio-v5-4-6873df4215a0@daynix.com> References: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> In-Reply-To: <20250123-coreaudio-v5-0-6873df4215a0@daynix.com> To: Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christian Schoenebeck 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::62f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62f.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 a8d71c6cf816f7658037e26608a4c1101ebd071e..9edae3d7443a57076781a69dde522cdfcfb77662 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;