From nobody Sat May 18 23:44:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615891863; cv=none; d=zohomail.com; s=zohoarc; b=XCGBKZElXicDLBBIz4YVWw1gf4rZehnJZ7jT1QDkcz/Y9dahgcm7O1Nb6oeyrLrkzfpMMvzzw3HFS5XSsxFrM+OJWkcXnorNbxQTokR2tibeCLB3kma3gVaMysc69g0zM5nQd9dgxehOYshxAEnDx2l2vYfSLA7qxhnBwNAd5Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615891863; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ymyrr+jeHk2GXb54WOBG62It1gs6WqwaBFik8eJiS9Y=; b=WgJs9osihe/xIvsyaO6W8tx1r0gasdfwMec0dsvlvTkBMqW/8eJn1bzYhRC/pWDgEvexa6Co+Mhv/fYKZc4d1yEtnkoKrzHijgieo5VWwYAOT0X8cFgaaSiaDsSHWujaj8f05XVVA2Pisl19SASQcZriBEHN0KW9qB10tv+cjHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615891863471500.0013682812072; Tue, 16 Mar 2021 03:51:03 -0700 (PDT) Received: from localhost ([::1]:56376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lM7Hy-0004wL-5S for importer@patchew.org; Tue, 16 Mar 2021 06:51:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lM7F1-0001Vx-RA for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lM7Ey-00008T-Rw for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-8UludegKMjS4xrGGMrmDsA-1; Tue, 16 Mar 2021 06:47:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA144801817; Tue, 16 Mar 2021 10:47:50 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-141.ams2.redhat.com [10.36.112.141]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89C6950F1A; Tue, 16 Mar 2021 10:47:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 6ADFB1800617; Tue, 16 Mar 2021 11:47:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615891676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ymyrr+jeHk2GXb54WOBG62It1gs6WqwaBFik8eJiS9Y=; b=ec/c9dxPoFgPmo/NFjBGeb4mXGnO0BfEMBYAoE5ReNn4B+9zLqs9MkrFR1Fu096f9w8VSn 7eKkMMc23k6Oph06FtdISb4qNCWElcA8+jKfylJM7XdHYoXWAqIDtX4bvJnwoKvRJxguo7 IGRgqNJTzfLqxrSlWhPzurdqlix20Gg= X-MC-Unique: 8UludegKMjS4xrGGMrmDsA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 1/3] coreaudio: Drop support for macOS older than 10.6 Date: Tue, 16 Mar 2021 11:47:43 +0100 Message-Id: <20210316104745.2196286-2-kraxel@redhat.com> In-Reply-To: <20210316104745.2196286-1-kraxel@redhat.com> References: <20210316104745.2196286-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Gerd Hoffmann , Akihiko Odaki Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki Mac OS X 10.6 was released in 2009. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Message-Id: <20210311151512.22096-1-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- audio/coreaudio.c | 103 ---------------------------------------------- 1 file changed, 103 deletions(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index b7c02e0e516d..c5f0b615d643 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -32,10 +32,6 @@ #define AUDIO_CAP "coreaudio" #include "audio_int.h" =20 -#ifndef MAC_OS_X_VERSION_10_6 -#define MAC_OS_X_VERSION_10_6 1060 -#endif - typedef struct coreaudioVoiceOut { HWVoiceOut hw; pthread_mutex_t mutex; @@ -45,9 +41,6 @@ typedef struct coreaudioVoiceOut { AudioDeviceIOProcID ioprocid; } coreaudioVoiceOut; =20 -#if MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_X_VERSION_10_6 -/* The APIs used here only become available from 10.6 */ - static OSStatus coreaudio_get_voice(AudioDeviceID *id) { UInt32 size =3D sizeof(*id); @@ -169,102 +162,6 @@ static OSStatus coreaudio_get_isrunning(AudioDeviceID= id, UInt32 *result) &size, result); } -#else -/* Legacy versions of functions using deprecated APIs */ - -static OSStatus coreaudio_get_voice(AudioDeviceID *id) -{ - UInt32 size =3D sizeof(*id); - - return AudioHardwareGetProperty( - kAudioHardwarePropertyDefaultOutputDevice, - &size, - id); -} - -static OSStatus coreaudio_get_framesizerange(AudioDeviceID id, - AudioValueRange *framerange) -{ - UInt32 size =3D sizeof(*framerange); - - return AudioDeviceGetProperty( - id, - 0, - 0, - kAudioDevicePropertyBufferFrameSizeRange, - &size, - framerange); -} - -static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesiz= e) -{ - UInt32 size =3D sizeof(*framesize); - - return AudioDeviceGetProperty( - id, - 0, - false, - kAudioDevicePropertyBufferFrameSize, - &size, - framesize); -} - -static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesiz= e) -{ - UInt32 size =3D sizeof(*framesize); - - return AudioDeviceSetProperty( - id, - NULL, - 0, - false, - kAudioDevicePropertyBufferFrameSize, - size, - framesize); -} - -static OSStatus coreaudio_get_streamformat(AudioDeviceID id, - AudioStreamBasicDescription *d) -{ - UInt32 size =3D sizeof(*d); - - return AudioDeviceGetProperty( - id, - 0, - false, - kAudioDevicePropertyStreamFormat, - &size, - d); -} - -static OSStatus coreaudio_set_streamformat(AudioDeviceID id, - AudioStreamBasicDescription *d) -{ - UInt32 size =3D sizeof(*d); - - return AudioDeviceSetProperty( - id, - 0, - 0, - 0, - kAudioDevicePropertyStreamFormat, - size, - d); -} - -static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result) -{ - UInt32 size =3D sizeof(*result); - - return AudioDeviceGetProperty( - id, - 0, - 0, - kAudioDevicePropertyDeviceIsRunning, - &size, - result); -} -#endif =20 static void coreaudio_logstatus (OSStatus status) { --=20 2.30.2 From nobody Sat May 18 23:44:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615891775; cv=none; d=zohomail.com; s=zohoarc; b=jXr/y6GEd0Axduch+MmELLvWNQqBu7FZvWQvZ6oxeew6SAaLjf8fwTBbjEx0FesHBCckb8WiZDUsqe3IP9tdtRrAEsf4dM4wuRhxKDss/H8li82wfUqbSWK+Hrp+cXlQXvb97DMITTTkkpKW217N96r/GdDFFfWctUFL7L4VGGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615891775; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8uZG7+y4lE+Kg15hMyyT1iMabpnUBAcGmRBmKaPTHfo=; b=D4ZzZ2QBRBsCdU4MvwYN2DmCl9OLqzb1cMqsRj44pvfn7W621UIDZTDQpVZq6gcVXxCzbAC79UDf+G6LdMX3fQRXfa4Xh/psNtdI8jolewNuhZVpu11T9Fu3I6h2OhG2wrF0cP9n3MIWZ7GpuB2oKYLgqamFBdFkVN+gm8kIWxc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615891775588603.4597656249178; Tue, 16 Mar 2021 03:49:35 -0700 (PDT) Received: from localhost ([::1]:51190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lM7GY-0002jX-DT for importer@patchew.org; Tue, 16 Mar 2021 06:49:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lM7Ey-0001RG-N5 for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lM7Ew-00007X-Ph for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-8RoIRtzRMrGEUw4huzV2Aw-1; Tue, 16 Mar 2021 06:47:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2FE418460E0; Tue, 16 Mar 2021 10:47:50 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-141.ams2.redhat.com [10.36.112.141]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F7D260C0F; Tue, 16 Mar 2021 10:47:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 76EE6180061A; Tue, 16 Mar 2021 11:47:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615891674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8uZG7+y4lE+Kg15hMyyT1iMabpnUBAcGmRBmKaPTHfo=; b=S9rt77Q4hiORo6boWdCf+58AWLbUJcn5Zeaq4a1dNiyxp45PLtOdgnHlDeSw49viR/TgWR l6KceCc84onekR9fDmIrKhUnWwugSnUNv8nj6DVPTifxSaU6QWEc9Sog2og/1M3cZvWpHF 4NuCyNApt3a/R682OXFPrxi2iiwHqm4= X-MC-Unique: 8RoIRtzRMrGEUw4huzV2Aw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 2/3] coreaudio: Extract device operations Date: Tue, 16 Mar 2021 11:47:44 +0100 Message-Id: <20210316104745.2196286-3-kraxel@redhat.com> In-Reply-To: <20210316104745.2196286-1-kraxel@redhat.com> References: <20210316104745.2196286-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Akihiko Odaki Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki This change prepare to support dynamic device changes, which requires to perform device initialization/deinitialization multiple times. Signed-off-by: Akihiko Odaki Message-Id: <20210311151512.22096-2-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- audio/coreaudio.c | 137 +++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index c5f0b615d643..ab43cdcac199 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -36,6 +36,8 @@ typedef struct coreaudioVoiceOut { HWVoiceOut hw; pthread_mutex_t mutex; AudioDeviceID outputDeviceID; + int frameSizeSetting; + uint32_t bufferCount; UInt32 audioDevicePropertyBufferFrameSize; AudioStreamBasicDescription outputStreamBasicDescription; AudioDeviceIOProcID ioprocid; @@ -253,6 +255,9 @@ static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 ( coreaudio_logstatus (status); } =20 +#define coreaudio_playback_logerr(status, ...) \ + coreaudio_logerr2(status, "playback", __VA_ARGS__) + static inline UInt32 isPlaying (AudioDeviceID outputDeviceID) { OSStatus status; @@ -368,126 +373,100 @@ static OSStatus audioDeviceIOProc( return 0; } =20 -static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, - void *drv_opaque) +static OSStatus init_out_device(coreaudioVoiceOut *core) { OSStatus status; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; - int err; - const char *typ =3D "playback"; AudioValueRange frameRange; - Audiodev *dev =3D drv_opaque; - AudiodevCoreaudioPerDirectionOptions *cpdo =3D dev->u.coreaudio.out; - int frames; - struct audsettings obt_as; - - /* create mutex */ - err =3D pthread_mutex_init(&core->mutex, NULL); - if (err) { - dolog("Could not create mutex\nReason: %s\n", strerror (err)); - return -1; - } - - obt_as =3D *as; - as =3D &obt_as; - as->fmt =3D AUDIO_FORMAT_F32; - audio_pcm_init_info (&hw->info, as); =20 status =3D coreaudio_get_voice(&core->outputDeviceID); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, - "Could not get default output Device\n"); - return -1; + coreaudio_playback_logerr (status, + "Could not get default output Device\n"= ); + return status; } if (core->outputDeviceID =3D=3D kAudioDeviceUnknown) { - dolog ("Could not initialize %s - Unknown Audiodevice\n", typ); - return -1; + dolog ("Could not initialize playback - Unknown Audiodevice\n"); + return status; } =20 /* get minimum and maximum buffer frame sizes */ status =3D coreaudio_get_framesizerange(core->outputDeviceID, &frameRange); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, - "Could not get device buffer frame range\n"); - return -1; + coreaudio_playback_logerr (status, + "Could not get device buffer frame ran= ge\n"); + return status; } =20 - frames =3D audio_buffer_frames( - qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); - if (frameRange.mMinimum > frames) { + if (frameRange.mMinimum > core->frameSizeSetting) { core->audioDevicePropertyBufferFrameSize =3D (UInt32) frameRange.m= Minimum; dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMini= mum); - } else if (frameRange.mMaximum < frames) { + } else if (frameRange.mMaximum < core->frameSizeSetting) { core->audioDevicePropertyBufferFrameSize =3D (UInt32) frameRange.m= Maximum; dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMa= ximum); } else { - core->audioDevicePropertyBufferFrameSize =3D frames; + core->audioDevicePropertyBufferFrameSize =3D core->frameSizeSettin= g; } =20 /* set Buffer Frame Size */ status =3D coreaudio_set_framesize(core->outputDeviceID, &core->audioDevicePropertyBufferFrame= Size); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, - "Could not set device buffer frame size %" PRIu= 32 "\n", - (uint32_t)core->audioDevicePropertyBufferFrameS= ize); - return -1; + coreaudio_playback_logerr (status, + "Could not set device buffer frame siz= e %" PRIu32 "\n", + (uint32_t)core->audioDevicePropertyBuf= ferFrameSize); + return status; } =20 /* get Buffer Frame Size */ status =3D coreaudio_get_framesize(core->outputDeviceID, &core->audioDevicePropertyBufferFrame= Size); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, - "Could not get device buffer frame size\n"); - return -1; + coreaudio_playback_logerr (status, + "Could not get device buffer frame siz= e\n"); + return status; } - hw->samples =3D (cpdo->has_buffer_count ? cpdo->buffer_count : 4) * - core->audioDevicePropertyBufferFrameSize; + core->hw.samples =3D core->bufferCount * core->audioDevicePropertyBuff= erFrameSize; =20 /* get StreamFormat */ status =3D coreaudio_get_streamformat(core->outputDeviceID, &core->outputStreamBasicDescriptio= n); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, - "Could not get Device Stream properties\n"); + coreaudio_playback_logerr (status, + "Could not get Device Stream propertie= s\n"); core->outputDeviceID =3D kAudioDeviceUnknown; - return -1; + return status; } =20 /* set Samplerate */ - core->outputStreamBasicDescription.mSampleRate =3D (Float64) as->freq; - status =3D coreaudio_set_streamformat(core->outputDeviceID, &core->outputStreamBasicDescriptio= n); if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr2 (status, typ, "Could not set samplerate %d\n", - as->freq); + coreaudio_playback_logerr (status, + "Could not set samplerate %lf\n", + core->outputStreamBasicDescription.mSam= pleRate); core->outputDeviceID =3D kAudioDeviceUnknown; - return -1; + return status; } =20 /* set Callback */ core->ioprocid =3D NULL; status =3D AudioDeviceCreateIOProcID(core->outputDeviceID, audioDeviceIOProc, - hw, + &core->hw, &core->ioprocid); if (status !=3D kAudioHardwareNoError || core->ioprocid =3D=3D NULL) { - coreaudio_logerr2 (status, typ, "Could not set IOProc\n"); + coreaudio_playback_logerr (status, "Could not set IOProc\n"); core->outputDeviceID =3D kAudioDeviceUnknown; - return -1; + return status; } =20 return 0; } =20 -static void coreaudio_fini_out (HWVoiceOut *hw) +static void fini_out_device(coreaudioVoiceOut *core) { OSStatus status; - int err; - coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; =20 /* stop playback */ if (isPlaying(core->outputDeviceID)) { @@ -504,6 +483,50 @@ static void coreaudio_fini_out (HWVoiceOut *hw) coreaudio_logerr(status, "Could not remove IOProc\n"); } core->outputDeviceID =3D kAudioDeviceUnknown; +} + +static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, + void *drv_opaque) +{ + OSStatus status; + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; + int err; + Audiodev *dev =3D drv_opaque; + AudiodevCoreaudioPerDirectionOptions *cpdo =3D dev->u.coreaudio.out; + struct audsettings obt_as; + + /* create mutex */ + err =3D pthread_mutex_init(&core->mutex, NULL); + if (err) { + dolog("Could not create mutex\nReason: %s\n", strerror (err)); + return -1; + } + + obt_as =3D *as; + as =3D &obt_as; + as->fmt =3D AUDIO_FORMAT_F32; + audio_pcm_init_info (&hw->info, as); + + core->frameSizeSetting =3D audio_buffer_frames( + qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610); + + core->bufferCount =3D cpdo->has_buffer_count ? cpdo->buffer_count : 4; + core->outputStreamBasicDescription.mSampleRate =3D (Float64) as->freq; + + if (init_out_device(core)) { + return -1; + } + + return 0; +} + +static void coreaudio_fini_out (HWVoiceOut *hw) +{ + OSStatus status; + int err; + coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; + + fini_out_device(core); =20 /* destroy mutex */ err =3D pthread_mutex_destroy(&core->mutex); --=20 2.30.2 From nobody Sat May 18 23:44:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615891777; cv=none; d=zohomail.com; s=zohoarc; b=a4KvV4qkW6SbzzMX6+PNeIvTnysnYX2svdw0UX+MALX52inL5gK6VGI/jWxzP0rYTPW0xW8PIOO065CaBbimxg+YIrZ+J47kJ6sRK7bOubOPcgITKTXvWcCd/S4LAFC1g4xjtOl+m6V9/CdkWj50T6eU8S6+ydjze3srE1RlJKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615891777; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8Jih6FDQb6lUSb9kigVSaKbZInp2qwCLvP8TQZBTBzQ=; b=Hl5zj1fFz07kndWEL2EIW1hIOBiU3OcahvDrU5bmWlFZjxo7XaAdqwWKeZjrTPAlrXLKKm0H0A1Tf7I3/qG1SF1Op9DpKOFls5DDqeKH4FRnxEwJXa0iT5FYjTw4atoeCjOoYx3kn0eh3GCvBJuTFCQvtxdnUItEzzhup4ng0Ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615891777662205.97529114454926; Tue, 16 Mar 2021 03:49:37 -0700 (PDT) Received: from localhost ([::1]:51390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lM7Ga-0002qS-ID for importer@patchew.org; Tue, 16 Mar 2021 06:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lM7Ez-0001Re-Py for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27543) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lM7Ex-00007Y-0m for qemu-devel@nongnu.org; Tue, 16 Mar 2021 06:47:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-149-iHXqj6yCNRKSO-VQv1BA0A-1; Tue, 16 Mar 2021 06:47:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3315E83DD20; Tue, 16 Mar 2021 10:47:51 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-141.ams2.redhat.com [10.36.112.141]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CB0D5C1A1; Tue, 16 Mar 2021 10:47:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 83D68180061B; Tue, 16 Mar 2021 11:47:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615891674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Jih6FDQb6lUSb9kigVSaKbZInp2qwCLvP8TQZBTBzQ=; b=JFTuqr3NtvozoNe8SjI/XkAVNL9wzwBmYXFotuEPubOs5k4W3XqYJj2uLkEDsHXyIzPy9+ sYgRMLe68Sc0PtkGVy8VP9GSgiU0JboxP3WB1q3+Ug3Ccmoyyh7bTU5Fa4Y7kRbTbj9UBn 7+ZraoNlzqpIgAFEH6GBPd4W1pzJIZg= X-MC-Unique: iHXqj6yCNRKSO-VQv1BA0A-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 3/3] coreaudio: Handle output device change Date: Tue, 16 Mar 2021 11:47:45 +0100 Message-Id: <20210316104745.2196286-4-kraxel@redhat.com> In-Reply-To: <20210316104745.2196286-1-kraxel@redhat.com> References: <20210316104745.2196286-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Akihiko Odaki Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki An output device change can occur when plugging or unplugging an earphone. Signed-off-by: Akihiko Odaki Message-Id: <20210311151512.22096-3-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- audio/coreaudio.c | 206 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 164 insertions(+), 42 deletions(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index ab43cdcac199..578ec9b8b2e6 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -41,19 +41,21 @@ typedef struct coreaudioVoiceOut { UInt32 audioDevicePropertyBufferFrameSize; AudioStreamBasicDescription outputStreamBasicDescription; AudioDeviceIOProcID ioprocid; + bool enabled; } coreaudioVoiceOut; =20 +static const AudioObjectPropertyAddress voice_addr =3D { + kAudioHardwarePropertyDefaultOutputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster +}; + static OSStatus coreaudio_get_voice(AudioDeviceID *id) { UInt32 size =3D sizeof(*id); - AudioObjectPropertyAddress addr =3D { - kAudioHardwarePropertyDefaultOutputDevice, - kAudioObjectPropertyScopeGlobal, - kAudioObjectPropertyElementMaster - }; =20 return AudioObjectGetPropertyData(kAudioObjectSystemObject, - &addr, + &voice_addr, 0, NULL, &size, @@ -258,18 +260,6 @@ static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 ( #define coreaudio_playback_logerr(status, ...) \ coreaudio_logerr2(status, "playback", __VA_ARGS__) =20 -static inline UInt32 isPlaying (AudioDeviceID outputDeviceID) -{ - OSStatus status; - UInt32 result =3D 0; - status =3D coreaudio_get_isrunning(outputDeviceID, &result); - if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr(status, - "Could not determine whether Device is playing\n"= ); - } - return result; -} - static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name) { int err; @@ -341,6 +331,11 @@ static OSStatus audioDeviceIOProc( return 0; } =20 + if (inDevice !=3D core->outputDeviceID) { + coreaudio_unlock (core, "audioDeviceIOProc(old device)"); + return 0; + } + frameCount =3D core->audioDevicePropertyBufferFrameSize; pending_frames =3D hw->pending_emul / hw->info.bytes_per_frame; =20 @@ -392,6 +387,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) /* get minimum and maximum buffer frame sizes */ status =3D coreaudio_get_framesizerange(core->outputDeviceID, &frameRange); + if (status =3D=3D kAudioHardwareBadObjectError) { + return 0; + } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not get device buffer frame ran= ge\n"); @@ -411,6 +409,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) /* set Buffer Frame Size */ status =3D coreaudio_set_framesize(core->outputDeviceID, &core->audioDevicePropertyBufferFrame= Size); + if (status =3D=3D kAudioHardwareBadObjectError) { + return 0; + } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not set device buffer frame siz= e %" PRIu32 "\n", @@ -421,6 +422,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) /* get Buffer Frame Size */ status =3D coreaudio_get_framesize(core->outputDeviceID, &core->audioDevicePropertyBufferFrame= Size); + if (status =3D=3D kAudioHardwareBadObjectError) { + return 0; + } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not get device buffer frame siz= e\n"); @@ -431,6 +435,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) /* get StreamFormat */ status =3D coreaudio_get_streamformat(core->outputDeviceID, &core->outputStreamBasicDescriptio= n); + if (status =3D=3D kAudioHardwareBadObjectError) { + return 0; + } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not get Device Stream propertie= s\n"); @@ -441,6 +448,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) /* set Samplerate */ status =3D coreaudio_set_streamformat(core->outputDeviceID, &core->outputStreamBasicDescriptio= n); + if (status =3D=3D kAudioHardwareBadObjectError) { + return 0; + } if (status !=3D kAudioHardwareNoError) { coreaudio_playback_logerr (status, "Could not set samplerate %lf\n", @@ -455,6 +465,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core) audioDeviceIOProc, &core->hw, &core->ioprocid); + if (status =3D=3D kAudioHardwareBadDeviceError) { + return 0; + } if (status !=3D kAudioHardwareNoError || core->ioprocid =3D=3D NULL) { coreaudio_playback_logerr (status, "Could not set IOProc\n"); core->outputDeviceID =3D kAudioDeviceUnknown; @@ -467,24 +480,94 @@ static OSStatus init_out_device(coreaudioVoiceOut *co= re) static void fini_out_device(coreaudioVoiceOut *core) { OSStatus status; + UInt32 isrunning; =20 /* stop playback */ - if (isPlaying(core->outputDeviceID)) { - status =3D AudioDeviceStop(core->outputDeviceID, core->ioprocid); + status =3D coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + if (status !=3D kAudioHardwareBadObjectError) { if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr(status, "Could not stop playback\n"); + coreaudio_logerr(status, + "Could not determine whether Device is playin= g\n"); + } + + if (isrunning) { + status =3D AudioDeviceStop(core->outputDeviceID, core->ioproci= d); + if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { + coreaudio_logerr(status, "Could not stop playback\n"); + } } } =20 /* remove callback */ status =3D AudioDeviceDestroyIOProcID(core->outputDeviceID, core->ioprocid); - if (status !=3D kAudioHardwareNoError) { + if (status !=3D kAudioHardwareBadDeviceError && status !=3D kAudioHard= wareNoError) { coreaudio_logerr(status, "Could not remove IOProc\n"); } core->outputDeviceID =3D kAudioDeviceUnknown; } =20 +static void update_device_playback_state(coreaudioVoiceOut *core) +{ + OSStatus status; + UInt32 isrunning; + + status =3D coreaudio_get_isrunning(core->outputDeviceID, &isrunning); + if (status !=3D kAudioHardwareNoError) { + if (status !=3D kAudioHardwareBadObjectError) { + coreaudio_logerr(status, + "Could not determine whether Device is playin= g\n"); + } + + return; + } + + if (core->enabled) { + /* start playback */ + if (!isrunning) { + status =3D AudioDeviceStart(core->outputDeviceID, core->ioproc= id); + if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { + coreaudio_logerr (status, "Could not resume playback\n"); + } + } + } else { + /* stop playback */ + if (isrunning) { + status =3D AudioDeviceStop(core->outputDeviceID, + core->ioprocid); + if (status !=3D kAudioHardwareBadDeviceError && status !=3D kA= udioHardwareNoError) { + coreaudio_logerr(status, "Could not pause playback\n"); + } + } + } +} + +static OSStatus handle_voice_change( + AudioObjectID in_object_id, + UInt32 in_number_addresses, + const AudioObjectPropertyAddress *in_addresses, + void *in_client_data) +{ + OSStatus status; + coreaudioVoiceOut *core =3D in_client_data; + + if (coreaudio_lock(core, __func__)) { + abort(); + } + + if (core->outputDeviceID) { + fini_out_device(core); + } + + status =3D init_out_device(core); + if (!status) { + update_device_playback_state(core); + } + + coreaudio_unlock (core, __func__); + return status; +} + static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque) { @@ -499,7 +582,11 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct a= udsettings *as, err =3D pthread_mutex_init(&core->mutex, NULL); if (err) { dolog("Could not create mutex\nReason: %s\n", strerror (err)); - return -1; + goto mutex_error; + } + + if (coreaudio_lock(core, __func__)) { + goto lock_error; } =20 obt_as =3D *as; @@ -513,11 +600,43 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct = audsettings *as, core->bufferCount =3D cpdo->has_buffer_count ? cpdo->buffer_count : 4; core->outputStreamBasicDescription.mSampleRate =3D (Float64) as->freq; =20 + status =3D AudioObjectAddPropertyListener(kAudioObjectSystemObject, + &voice_addr, handle_voice_chan= ge, + core); + if (status !=3D kAudioHardwareNoError) { + coreaudio_playback_logerr (status, + "Could not listen to voice property cha= nge\n"); + goto listener_error; + } + if (init_out_device(core)) { - return -1; + goto device_error; } =20 + coreaudio_unlock(core, __func__); return 0; + +device_error: + status =3D AudioObjectRemovePropertyListener(kAudioObjectSystemObject, + &voice_addr, + handle_voice_change, + core); + if (status !=3D kAudioHardwareNoError) { + coreaudio_playback_logerr(status, + "Could not remove voice property change = listener\n"); + } + +listener_error: + coreaudio_unlock(core, __func__); + +lock_error: + err =3D pthread_mutex_destroy(&core->mutex); + if (err) { + dolog("Could not destroy mutex\nReason: %s\n", strerror (err)); + } + +mutex_error: + return -1; } =20 static void coreaudio_fini_out (HWVoiceOut *hw) @@ -526,8 +645,22 @@ static void coreaudio_fini_out (HWVoiceOut *hw) int err; coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; =20 + if (coreaudio_lock(core, __func__)) { + abort(); + } + + status =3D AudioObjectRemovePropertyListener(kAudioObjectSystemObject, + &voice_addr, + handle_voice_change, + core); + if (status !=3D kAudioHardwareNoError) { + coreaudio_logerr(status, "Could not remove voice property change l= istener\n"); + } + fini_out_device(core); =20 + coreaudio_unlock(core, __func__); + /* destroy mutex */ err =3D pthread_mutex_destroy(&core->mutex); if (err) { @@ -537,27 +670,16 @@ static void coreaudio_fini_out (HWVoiceOut *hw) =20 static void coreaudio_enable_out(HWVoiceOut *hw, bool enable) { - OSStatus status; coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; =20 - if (enable) { - /* start playback */ - if (!isPlaying(core->outputDeviceID)) { - status =3D AudioDeviceStart(core->outputDeviceID, core->ioproc= id); - if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr (status, "Could not resume playback\n"); - } - } - } else { - /* stop playback */ - if (isPlaying(core->outputDeviceID)) { - status =3D AudioDeviceStop(core->outputDeviceID, - core->ioprocid); - if (status !=3D kAudioHardwareNoError) { - coreaudio_logerr(status, "Could not pause playback\n"); - } - } + if (coreaudio_lock(core, __func__)) { + abort(); } + + core->enabled =3D enable; + update_device_playback_state(core); + + coreaudio_unlock(core, __func__); } =20 static void *coreaudio_audio_init(Audiodev *dev) --=20 2.30.2