2005-10-30 21:58:22 +03:00
|
|
|
/*
|
|
|
|
* QEMU OS X CoreAudio audio driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Mike Kronenberg
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-18 20:33:52 +03:00
|
|
|
#include "qemu/osdep.h"
|
2005-10-30 21:58:22 +03:00
|
|
|
#include <CoreAudio/CoreAudio.h>
|
|
|
|
#include <pthread.h> /* pthread_X */
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2007-11-17 20:35:54 +03:00
|
|
|
#include "audio.h"
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
#define AUDIO_CAP "coreaudio"
|
|
|
|
#include "audio_int.h"
|
|
|
|
|
|
|
|
typedef struct coreaudioVoiceOut {
|
|
|
|
HWVoiceOut hw;
|
2021-06-22 23:17:40 +03:00
|
|
|
pthread_mutex_t buf_mutex;
|
2005-10-30 21:58:22 +03:00
|
|
|
AudioDeviceID outputDeviceID;
|
2021-03-11 18:15:11 +03:00
|
|
|
int frameSizeSetting;
|
|
|
|
uint32_t bufferCount;
|
2005-11-20 19:24:09 +03:00
|
|
|
UInt32 audioDevicePropertyBufferFrameSize;
|
2015-11-29 00:55:24 +03:00
|
|
|
AudioDeviceIOProcID ioprocid;
|
2021-03-11 18:15:12 +03:00
|
|
|
bool enabled;
|
2005-10-30 21:58:22 +03:00
|
|
|
} coreaudioVoiceOut;
|
|
|
|
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
#if !defined(MAC_OS_VERSION_12_0) \
|
|
|
|
|| (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_12_0)
|
|
|
|
#define kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster
|
|
|
|
#endif
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
static const AudioObjectPropertyAddress voice_addr = {
|
|
|
|
kAudioHardwarePropertyDefaultOutputDevice,
|
|
|
|
kAudioObjectPropertyScopeGlobal,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2021-03-11 18:15:12 +03:00
|
|
|
};
|
|
|
|
|
2015-11-29 00:55:21 +03:00
|
|
|
static OSStatus coreaudio_get_voice(AudioDeviceID *id)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*id);
|
|
|
|
|
|
|
|
return AudioObjectGetPropertyData(kAudioObjectSystemObject,
|
2021-03-11 18:15:12 +03:00
|
|
|
&voice_addr,
|
2015-11-29 00:55:21 +03:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&size,
|
|
|
|
id);
|
|
|
|
}
|
2015-11-29 00:55:23 +03:00
|
|
|
|
|
|
|
static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
|
|
|
|
AudioValueRange *framerange)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*framerange);
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
kAudioDevicePropertyBufferFrameSizeRange,
|
|
|
|
kAudioDevicePropertyScopeOutput,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2015-11-29 00:55:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return AudioObjectGetPropertyData(id,
|
|
|
|
&addr,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&size,
|
|
|
|
framerange);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*framesize);
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
kAudioDevicePropertyBufferFrameSize,
|
|
|
|
kAudioDevicePropertyScopeOutput,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2015-11-29 00:55:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return AudioObjectGetPropertyData(id,
|
|
|
|
&addr,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&size,
|
|
|
|
framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*framesize);
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
kAudioDevicePropertyBufferFrameSize,
|
|
|
|
kAudioDevicePropertyScopeOutput,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2015-11-29 00:55:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return AudioObjectSetPropertyData(id,
|
|
|
|
&addr,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
size,
|
|
|
|
framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
|
|
|
|
AudioStreamBasicDescription *d)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*d);
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
kAudioDevicePropertyStreamFormat,
|
|
|
|
kAudioDevicePropertyScopeOutput,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2015-11-29 00:55:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return AudioObjectSetPropertyData(id,
|
|
|
|
&addr,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
size,
|
|
|
|
d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result)
|
|
|
|
{
|
|
|
|
UInt32 size = sizeof(*result);
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
kAudioDevicePropertyDeviceIsRunning,
|
|
|
|
kAudioDevicePropertyScopeOutput,
|
audio/coreaudio: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
kAudioObjectPropertyElementMaster
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kAudioObjectPropertyElementMain
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
^
Replace by kAudioObjectPropertyElementMain, redefining it to
kAudioObjectPropertyElementMaster if not available.
Suggested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Suggested-by: Roman Bolshakov <roman@roolebo.dev>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Tested-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2022-01-09 16:30:03 +03:00
|
|
|
kAudioObjectPropertyElementMain
|
2015-11-29 00:55:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return AudioObjectGetPropertyData(id,
|
|
|
|
&addr,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&size,
|
|
|
|
result);
|
|
|
|
}
|
2015-11-29 00:55:22 +03:00
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
static void coreaudio_logstatus (OSStatus status)
|
|
|
|
{
|
2011-05-27 21:22:28 +04:00
|
|
|
const char *str = "BUG";
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2021-01-15 04:24:26 +03:00
|
|
|
switch (status) {
|
2005-10-30 21:58:22 +03:00
|
|
|
case kAudioHardwareNoError:
|
|
|
|
str = "kAudioHardwareNoError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareNotRunningError:
|
|
|
|
str = "kAudioHardwareNotRunningError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareUnspecifiedError:
|
|
|
|
str = "kAudioHardwareUnspecifiedError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareUnknownPropertyError:
|
|
|
|
str = "kAudioHardwareUnknownPropertyError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareBadPropertySizeError:
|
|
|
|
str = "kAudioHardwareBadPropertySizeError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareIllegalOperationError:
|
|
|
|
str = "kAudioHardwareIllegalOperationError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareBadDeviceError:
|
|
|
|
str = "kAudioHardwareBadDeviceError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareBadStreamError:
|
|
|
|
str = "kAudioHardwareBadStreamError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioHardwareUnsupportedOperationError:
|
|
|
|
str = "kAudioHardwareUnsupportedOperationError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioDeviceUnsupportedFormatError:
|
|
|
|
str = "kAudioDeviceUnsupportedFormatError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioDevicePermissionsError:
|
|
|
|
str = "kAudioDevicePermissionsError";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-06-23 18:24:45 +04:00
|
|
|
AUD_log (AUDIO_CAP, "Reason: status code %" PRId32 "\n", (int32_t)status);
|
2005-10-30 21:58:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_log (AUDIO_CAP, "Reason: %s\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GCC_FMT_ATTR (2, 3) coreaudio_logerr (
|
|
|
|
OSStatus status,
|
|
|
|
const char *fmt,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_log (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
coreaudio_logstatus (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 (
|
|
|
|
OSStatus status,
|
|
|
|
const char *typ,
|
|
|
|
const char *fmt,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
coreaudio_logstatus (status);
|
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
#define coreaudio_playback_logerr(status, ...) \
|
|
|
|
coreaudio_logerr2(status, "playback", __VA_ARGS__)
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
static int coreaudio_buf_lock (coreaudioVoiceOut *core, const char *fn_name)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
err = pthread_mutex_lock (&core->buf_mutex);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (err) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("Could not lock voice for %s\nReason: %s\n",
|
2005-10-30 21:58:22 +03:00
|
|
|
fn_name, strerror (err));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
static int coreaudio_buf_unlock (coreaudioVoiceOut *core, const char *fn_name)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
err = pthread_mutex_unlock (&core->buf_mutex);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (err) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("Could not unlock voice for %s\nReason: %s\n",
|
2005-10-30 21:58:22 +03:00
|
|
|
fn_name, strerror (err));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-20 00:24:11 +03:00
|
|
|
#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; \
|
|
|
|
\
|
2021-06-22 23:17:40 +03:00
|
|
|
if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \
|
2019-09-20 00:24:11 +03:00
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ret = glue(audio_generic_, name)args; \
|
|
|
|
\
|
2021-06-22 23:17:40 +03:00
|
|
|
coreaudio_buf_unlock(core, "coreaudio_" #name); \
|
2019-09-20 00:24:11 +03:00
|
|
|
return ret; \
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
2022-03-01 22:13:06 +03:00
|
|
|
COREAUDIO_WRAPPER_FUNC(buffer_get_free, size_t, (HWVoiceOut *hw), (hw))
|
2019-09-20 00:24:11 +03:00
|
|
|
COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size),
|
|
|
|
(hw, size))
|
2020-01-23 10:49:39 +03:00
|
|
|
COREAUDIO_WRAPPER_FUNC(put_buffer_out, size_t,
|
2019-09-20 00:24:11 +03:00
|
|
|
(HWVoiceOut *hw, void *buf, size_t size),
|
|
|
|
(hw, buf, size))
|
|
|
|
COREAUDIO_WRAPPER_FUNC(write, size_t, (HWVoiceOut *hw, void *buf, size_t size),
|
|
|
|
(hw, buf, size))
|
|
|
|
#undef COREAUDIO_WRAPPER_FUNC
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
/*
|
|
|
|
* callback to feed audiooutput buffer. called without iothread lock.
|
|
|
|
* allowed to lock "buf_mutex", but disallowed to have any other locks.
|
|
|
|
*/
|
2005-10-30 21:58:22 +03:00
|
|
|
static OSStatus audioDeviceIOProc(
|
|
|
|
AudioDeviceID inDevice,
|
2021-01-15 04:24:27 +03:00
|
|
|
const AudioTimeStamp *inNow,
|
|
|
|
const AudioBufferList *inInputData,
|
|
|
|
const AudioTimeStamp *inInputTime,
|
|
|
|
AudioBufferList *outOutputData,
|
|
|
|
const AudioTimeStamp *inOutputTime,
|
|
|
|
void *hwptr)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
2019-09-20 00:24:11 +03:00
|
|
|
UInt32 frameCount, pending_frames;
|
|
|
|
void *out = outOutputData->mBuffers[0].mData;
|
2005-10-30 21:58:22 +03:00
|
|
|
HWVoiceOut *hw = hwptr;
|
|
|
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
|
2019-09-20 00:24:11 +03:00
|
|
|
size_t len;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
if (coreaudio_buf_lock (core, "audioDeviceIOProc")) {
|
2005-10-30 21:58:22 +03:00
|
|
|
inInputTime = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
if (inDevice != core->outputDeviceID) {
|
2021-06-22 23:17:40 +03:00
|
|
|
coreaudio_buf_unlock (core, "audioDeviceIOProc(old device)");
|
2021-03-11 18:15:12 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:09 +03:00
|
|
|
frameCount = core->audioDevicePropertyBufferFrameSize;
|
2019-10-13 22:58:02 +03:00
|
|
|
pending_frames = hw->pending_emul / hw->info.bytes_per_frame;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
/* if there are not enough samples, set signal and return */
|
2019-09-20 00:24:11 +03:00
|
|
|
if (pending_frames < frameCount) {
|
2005-10-30 21:58:22 +03:00
|
|
|
inInputTime = 0;
|
2021-06-22 23:17:40 +03:00
|
|
|
coreaudio_buf_unlock (core, "audioDeviceIOProc(empty)");
|
2005-10-30 21:58:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-13 22:58:02 +03:00
|
|
|
len = frameCount * hw->info.bytes_per_frame;
|
2019-09-20 00:24:11 +03:00
|
|
|
while (len) {
|
2022-03-01 22:12:57 +03:00
|
|
|
size_t write_len, start;
|
|
|
|
|
|
|
|
start = audio_ring_posb(hw->pos_emul, hw->pending_emul, hw->size_emul);
|
|
|
|
assert(start < hw->size_emul);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2019-09-20 00:24:11 +03:00
|
|
|
write_len = MIN(MIN(hw->pending_emul, len),
|
|
|
|
hw->size_emul - start);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2019-09-20 00:24:11 +03:00
|
|
|
memcpy(out, hw->buf_emul + start, write_len);
|
|
|
|
hw->pending_emul -= write_len;
|
|
|
|
len -= write_len;
|
|
|
|
out += write_len;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
coreaudio_buf_unlock (core, "audioDeviceIOProc");
|
2005-10-30 21:58:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
static OSStatus init_out_device(coreaudioVoiceOut *core)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
OSStatus status;
|
2005-11-20 19:24:09 +03:00
|
|
|
AudioValueRange frameRange;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2021-06-16 17:17:21 +03:00
|
|
|
AudioStreamBasicDescription streamBasicDescription = {
|
|
|
|
.mBitsPerChannel = core->hw.info.bits,
|
|
|
|
.mBytesPerFrame = core->hw.info.bytes_per_frame,
|
|
|
|
.mBytesPerPacket = core->hw.info.bytes_per_frame,
|
|
|
|
.mChannelsPerFrame = core->hw.info.nchannels,
|
|
|
|
.mFormatFlags = kLinearPCMFormatFlagIsFloat,
|
|
|
|
.mFormatID = kAudioFormatLinearPCM,
|
|
|
|
.mFramesPerPacket = 1,
|
|
|
|
.mSampleRate = core->hw.info.freq
|
|
|
|
};
|
|
|
|
|
2015-11-29 00:55:20 +03:00
|
|
|
status = coreaudio_get_voice(&core->outputDeviceID);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not get default output Device\n");
|
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
if (core->outputDeviceID == kAudioDeviceUnknown) {
|
2021-03-11 18:15:11 +03:00
|
|
|
dolog ("Could not initialize playback - Unknown Audiodevice\n");
|
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:09 +03:00
|
|
|
/* get minimum and maximum buffer frame sizes */
|
2015-11-29 00:55:22 +03:00
|
|
|
status = coreaudio_get_framesizerange(core->outputDeviceID,
|
|
|
|
&frameRange);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status == kAudioHardwareBadObjectError) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-11-20 19:24:09 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not get device buffer frame range\n");
|
|
|
|
return status;
|
2005-11-20 19:24:09 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
if (frameRange.mMinimum > core->frameSizeSetting) {
|
2005-11-20 19:24:09 +03:00
|
|
|
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
|
|
|
|
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
|
2021-03-11 18:15:11 +03:00
|
|
|
} else if (frameRange.mMaximum < core->frameSizeSetting) {
|
2005-11-20 19:24:09 +03:00
|
|
|
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
|
|
|
|
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
|
2021-01-15 04:24:25 +03:00
|
|
|
} else {
|
2021-03-11 18:15:11 +03:00
|
|
|
core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
|
2005-11-20 19:24:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set Buffer Frame Size */
|
2015-11-29 00:55:22 +03:00
|
|
|
status = coreaudio_set_framesize(core->outputDeviceID,
|
|
|
|
&core->audioDevicePropertyBufferFrameSize);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status == kAudioHardwareBadObjectError) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not set device buffer frame size %" PRIu32 "\n",
|
|
|
|
(uint32_t)core->audioDevicePropertyBufferFrameSize);
|
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:09 +03:00
|
|
|
/* get Buffer Frame Size */
|
2015-11-29 00:55:22 +03:00
|
|
|
status = coreaudio_get_framesize(core->outputDeviceID,
|
|
|
|
&core->audioDevicePropertyBufferFrameSize);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status == kAudioHardwareBadObjectError) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not get device buffer frame size\n");
|
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
2021-03-11 18:15:11 +03:00
|
|
|
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
/* set Samplerate */
|
2015-11-29 00:55:22 +03:00
|
|
|
status = coreaudio_set_streamformat(core->outputDeviceID,
|
2021-06-16 17:17:21 +03:00
|
|
|
&streamBasicDescription);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status == kAudioHardwareBadObjectError) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not set samplerate %lf\n",
|
2021-06-16 17:17:21 +03:00
|
|
|
streamBasicDescription.mSampleRate);
|
2005-10-30 21:58:22 +03:00
|
|
|
core->outputDeviceID = kAudioDeviceUnknown;
|
2021-03-11 18:15:11 +03:00
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
/*
|
|
|
|
* set Callback.
|
|
|
|
*
|
|
|
|
* On macOS 11.3.1, Core Audio calls AudioDeviceIOProc after calling an
|
|
|
|
* internal function named HALB_Mutex::Lock(), which locks a mutex in
|
|
|
|
* HALB_IOThread::Entry(void*). HALB_Mutex::Lock() is also called in
|
|
|
|
* AudioObjectGetPropertyData, which is called by coreaudio driver.
|
|
|
|
* Therefore, the specified callback must be designed to avoid a deadlock
|
|
|
|
* with the callers of AudioObjectGetPropertyData.
|
|
|
|
*/
|
2015-11-29 00:55:24 +03:00
|
|
|
core->ioprocid = NULL;
|
|
|
|
status = AudioDeviceCreateIOProcID(core->outputDeviceID,
|
|
|
|
audioDeviceIOProc,
|
2021-03-11 18:15:11 +03:00
|
|
|
&core->hw,
|
2015-11-29 00:55:24 +03:00
|
|
|
&core->ioprocid);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status == kAudioHardwareBadDeviceError) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-29 00:55:24 +03:00
|
|
|
if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
|
2021-03-11 18:15:11 +03:00
|
|
|
coreaudio_playback_logerr (status, "Could not set IOProc\n");
|
2005-10-30 21:58:22 +03:00
|
|
|
core->outputDeviceID = kAudioDeviceUnknown;
|
2021-03-11 18:15:11 +03:00
|
|
|
return status;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
static void fini_out_device(coreaudioVoiceOut *core)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
OSStatus status;
|
2021-03-11 18:15:12 +03:00
|
|
|
UInt32 isrunning;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2020-12-13 16:05:27 +03:00
|
|
|
/* stop playback */
|
2021-03-11 18:15:12 +03:00
|
|
|
status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning);
|
|
|
|
if (status != kAudioHardwareBadObjectError) {
|
2005-11-20 19:24:09 +03:00
|
|
|
if (status != kAudioHardwareNoError) {
|
2021-03-11 18:15:12 +03:00
|
|
|
coreaudio_logerr(status,
|
|
|
|
"Could not determine whether Device is playing\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isrunning) {
|
|
|
|
status = AudioDeviceStop(core->outputDeviceID, core->ioprocid);
|
|
|
|
if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_logerr(status, "Could not stop playback\n");
|
|
|
|
}
|
2005-11-20 19:24:09 +03:00
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
2020-12-13 16:05:27 +03:00
|
|
|
|
|
|
|
/* remove callback */
|
|
|
|
status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
|
|
|
|
core->ioprocid);
|
2021-03-11 18:15:12 +03:00
|
|
|
if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) {
|
2020-12-13 16:05:27 +03:00
|
|
|
coreaudio_logerr(status, "Could not remove IOProc\n");
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
core->outputDeviceID = kAudioDeviceUnknown;
|
2021-03-11 18:15:11 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
static void update_device_playback_state(coreaudioVoiceOut *core)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
UInt32 isrunning;
|
|
|
|
|
|
|
|
status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning);
|
|
|
|
if (status != kAudioHardwareNoError) {
|
|
|
|
if (status != kAudioHardwareBadObjectError) {
|
|
|
|
coreaudio_logerr(status,
|
|
|
|
"Could not determine whether Device is playing\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (core->enabled) {
|
|
|
|
/* start playback */
|
|
|
|
if (!isrunning) {
|
|
|
|
status = AudioDeviceStart(core->outputDeviceID, core->ioprocid);
|
|
|
|
if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_logerr (status, "Could not resume playback\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* stop playback */
|
|
|
|
if (isrunning) {
|
|
|
|
status = AudioDeviceStop(core->outputDeviceID,
|
|
|
|
core->ioprocid);
|
|
|
|
if (status != kAudioHardwareBadDeviceError && status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_logerr(status, "Could not pause playback\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
/* called without iothread lock. */
|
2021-03-11 18:15:12 +03:00
|
|
|
static OSStatus handle_voice_change(
|
|
|
|
AudioObjectID in_object_id,
|
|
|
|
UInt32 in_number_addresses,
|
|
|
|
const AudioObjectPropertyAddress *in_addresses,
|
|
|
|
void *in_client_data)
|
|
|
|
{
|
|
|
|
coreaudioVoiceOut *core = in_client_data;
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
qemu_mutex_lock_iothread();
|
2021-03-11 18:15:12 +03:00
|
|
|
|
|
|
|
if (core->outputDeviceID) {
|
|
|
|
fini_out_device(core);
|
|
|
|
}
|
|
|
|
|
2022-03-06 15:34:10 +03:00
|
|
|
if (!init_out_device(core)) {
|
2021-03-11 18:15:12 +03:00
|
|
|
update_device_playback_state(core);
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:17:40 +03:00
|
|
|
qemu_mutex_unlock_iothread();
|
2022-03-06 15:34:10 +03:00
|
|
|
return 0;
|
2021-03-11 18:15:12 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
|
|
|
|
void *drv_opaque)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
|
|
|
int err;
|
|
|
|
Audiodev *dev = drv_opaque;
|
|
|
|
AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
|
|
|
|
struct audsettings obt_as;
|
|
|
|
|
|
|
|
/* create mutex */
|
2021-06-22 23:17:40 +03:00
|
|
|
err = pthread_mutex_init(&core->buf_mutex, NULL);
|
2021-03-11 18:15:11 +03:00
|
|
|
if (err) {
|
|
|
|
dolog("Could not create mutex\nReason: %s\n", strerror (err));
|
2021-06-22 23:17:40 +03:00
|
|
|
return -1;
|
2021-03-11 18:15:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
obt_as = *as;
|
|
|
|
as = &obt_as;
|
|
|
|
as->fmt = AUDIO_FORMAT_F32;
|
|
|
|
audio_pcm_init_info (&hw->info, as);
|
|
|
|
|
|
|
|
core->frameSizeSetting = audio_buffer_frames(
|
|
|
|
qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
|
|
|
|
|
|
|
|
core->bufferCount = cpdo->has_buffer_count ? cpdo->buffer_count : 4;
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
status = AudioObjectAddPropertyListener(kAudioObjectSystemObject,
|
|
|
|
&voice_addr, handle_voice_change,
|
|
|
|
core);
|
|
|
|
if (status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_playback_logerr (status,
|
|
|
|
"Could not listen to voice property change\n");
|
2021-06-22 23:17:40 +03:00
|
|
|
return -1;
|
2021-03-11 18:15:12 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
if (init_out_device(core)) {
|
2021-06-22 23:17:40 +03:00
|
|
|
status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
|
|
|
|
&voice_addr,
|
|
|
|
handle_voice_change,
|
|
|
|
core);
|
|
|
|
if (status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_playback_logerr(status,
|
|
|
|
"Could not remove voice property change listener\n");
|
|
|
|
}
|
2022-02-26 14:59:53 +03:00
|
|
|
|
|
|
|
return -1;
|
2021-03-11 18:15:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void coreaudio_fini_out (HWVoiceOut *hw)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
int err;
|
|
|
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
|
|
|
|
&voice_addr,
|
|
|
|
handle_voice_change,
|
|
|
|
core);
|
|
|
|
if (status != kAudioHardwareNoError) {
|
|
|
|
coreaudio_logerr(status, "Could not remove voice property change listener\n");
|
|
|
|
}
|
|
|
|
|
2021-03-11 18:15:11 +03:00
|
|
|
fini_out_device(core);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
/* destroy mutex */
|
2021-06-22 23:17:40 +03:00
|
|
|
err = pthread_mutex_destroy(&core->buf_mutex);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (err) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog("Could not destroy mutex\nReason: %s\n", strerror (err));
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 00:24:22 +03:00
|
|
|
static void coreaudio_enable_out(HWVoiceOut *hw, bool enable)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
|
|
|
|
2021-03-11 18:15:12 +03:00
|
|
|
core->enabled = enable;
|
|
|
|
update_device_playback_state(core);
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
2019-03-09 01:34:15 +03:00
|
|
|
static void *coreaudio_audio_init(Audiodev *dev)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
2019-03-09 01:34:17 +03:00
|
|
|
return dev;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void coreaudio_audio_fini (void *opaque)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-06 22:08:30 +04:00
|
|
|
static struct audio_pcm_ops coreaudio_pcm_ops = {
|
2009-08-11 04:31:15 +04:00
|
|
|
.init_out = coreaudio_init_out,
|
|
|
|
.fini_out = coreaudio_fini_out,
|
2020-01-23 10:49:39 +03:00
|
|
|
/* wrapper for audio_generic_write */
|
2019-09-20 00:24:11 +03:00
|
|
|
.write = coreaudio_write,
|
2022-03-01 22:13:06 +03:00
|
|
|
/* wrapper for audio_generic_buffer_get_free */
|
|
|
|
.buffer_get_free = coreaudio_buffer_get_free,
|
2020-01-23 10:49:39 +03:00
|
|
|
/* wrapper for audio_generic_get_buffer_out */
|
2019-09-20 00:24:11 +03:00
|
|
|
.get_buffer_out = coreaudio_get_buffer_out,
|
2020-01-23 10:49:39 +03:00
|
|
|
/* wrapper for audio_generic_put_buffer_out */
|
|
|
|
.put_buffer_out = coreaudio_put_buffer_out,
|
2019-09-20 00:24:22 +03:00
|
|
|
.enable_out = coreaudio_enable_out
|
2005-10-30 21:58:22 +03:00
|
|
|
};
|
|
|
|
|
2018-03-06 10:40:47 +03:00
|
|
|
static struct audio_driver coreaudio_audio_driver = {
|
2009-08-11 04:31:14 +04:00
|
|
|
.name = "coreaudio",
|
|
|
|
.descr = "CoreAudio http://developer.apple.com/audio/coreaudio.html",
|
|
|
|
.init = coreaudio_audio_init,
|
|
|
|
.fini = coreaudio_audio_fini,
|
|
|
|
.pcm_ops = &coreaudio_pcm_ops,
|
|
|
|
.can_be_default = 1,
|
|
|
|
.max_voices_out = 1,
|
|
|
|
.max_voices_in = 0,
|
|
|
|
.voice_size_out = sizeof (coreaudioVoiceOut),
|
|
|
|
.voice_size_in = 0
|
2005-10-30 21:58:22 +03:00
|
|
|
};
|
2018-03-06 10:40:47 +03:00
|
|
|
|
|
|
|
static void register_audio_coreaudio(void)
|
|
|
|
{
|
|
|
|
audio_driver_register(&coreaudio_audio_driver);
|
|
|
|
}
|
|
|
|
type_init(register_audio_coreaudio);
|