2003-05-21 21:15:46 +00:00
|
|
|
/*
|
2014-06-30 17:09:03 +00:00
|
|
|
* This file is part of mpv.
|
2003-05-21 21:15:46 +00:00
|
|
|
*
|
2017-05-08 11:57:40 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-05-21 21:15:46 +00:00
|
|
|
*
|
2014-06-30 17:09:03 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2008-06-06 00:45:35 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-05-08 11:57:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2003-05-21 21:15:46 +00:00
|
|
|
*
|
2017-05-08 11:57:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2003-05-21 21:15:46 +00:00
|
|
|
*/
|
|
|
|
|
2014-07-02 20:47:54 +00:00
|
|
|
#include <CoreAudio/HostTime.h>
|
|
|
|
|
2005-01-12 22:00:02 +00:00
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "ao.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "internal.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/format.h"
|
2013-06-26 06:23:31 +00:00
|
|
|
#include "osdep/timer.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "misc/ring.h"
|
|
|
|
#include "common/msg.h"
|
2015-05-05 19:47:19 +00:00
|
|
|
#include "ao_coreaudio_chmap.h"
|
|
|
|
#include "ao_coreaudio_properties.h"
|
|
|
|
#include "ao_coreaudio_utils.h"
|
2013-04-20 08:02:23 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
struct priv {
|
2014-07-02 06:19:55 +00:00
|
|
|
AudioDeviceID device;
|
|
|
|
AudioUnit audio_unit;
|
2013-07-22 20:27:08 +00:00
|
|
|
|
2014-07-03 17:05:22 +00:00
|
|
|
uint64_t hw_latency_us;
|
2015-05-04 23:07:57 +00:00
|
|
|
|
2015-05-05 19:58:51 +00:00
|
|
|
AudioStreamBasicDescription original_asbd;
|
|
|
|
AudioStreamID original_asbd_stream;
|
|
|
|
|
2015-05-04 23:07:57 +00:00
|
|
|
int change_physical_format;
|
2013-04-19 21:04:11 +00:00
|
|
|
};
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2014-07-03 17:05:22 +00:00
|
|
|
static int64_t ca_get_hardware_latency(struct ao *ao) {
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
|
|
|
|
double audiounit_latency_sec = 0.0;
|
|
|
|
uint32_t size = sizeof(audiounit_latency_sec);
|
|
|
|
OSStatus err = AudioUnitGetProperty(
|
|
|
|
p->audio_unit,
|
|
|
|
kAudioUnitProperty_Latency,
|
|
|
|
kAudioUnitScope_Global,
|
|
|
|
0,
|
|
|
|
&audiounit_latency_sec,
|
|
|
|
&size);
|
|
|
|
CHECK_CA_ERROR("cannot get audio unit latency");
|
|
|
|
|
|
|
|
uint64_t audiounit_latency_us = audiounit_latency_sec * 1e6;
|
2015-07-06 15:49:28 +00:00
|
|
|
uint64_t device_latency_us = ca_get_device_latency_us(ao, p->device);
|
2014-07-03 17:05:22 +00:00
|
|
|
|
|
|
|
MP_VERBOSE(ao, "audiounit latency [us]: %lld\n", audiounit_latency_us);
|
|
|
|
MP_VERBOSE(ao, "device latency [us]: %lld\n", device_latency_us);
|
|
|
|
|
|
|
|
return audiounit_latency_us + device_latency_us;
|
|
|
|
|
|
|
|
coreaudio_error:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:03:19 +00:00
|
|
|
static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags,
|
|
|
|
const AudioTimeStamp *ts, UInt32 bus,
|
|
|
|
UInt32 frames, AudioBufferList *buffer_list)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-06-17 21:03:19 +00:00
|
|
|
struct ao *ao = ctx;
|
2014-07-03 17:05:22 +00:00
|
|
|
struct priv *p = ao->priv;
|
2015-06-26 13:49:52 +00:00
|
|
|
void *planes[MP_NUM_CHANNELS] = {0};
|
|
|
|
|
|
|
|
for (int n = 0; n < ao->num_planes; n++)
|
|
|
|
planes[n] = buffer_list->mBuffers[n].mData;
|
2014-07-02 20:47:54 +00:00
|
|
|
|
2014-07-03 17:05:22 +00:00
|
|
|
int64_t end = mp_time_us();
|
|
|
|
end += p->hw_latency_us + ca_get_latency(ts) + ca_frames_to_us(ao, frames);
|
2015-06-26 13:49:52 +00:00
|
|
|
ao_read_data(ao, planes, frames, end);
|
2013-04-18 19:25:02 +00:00
|
|
|
return noErr;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 17:14:55 +00:00
|
|
|
static int get_volume(struct ao *ao, struct ao_control_vol *vol) {
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
float auvol;
|
|
|
|
OSStatus err =
|
|
|
|
AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume,
|
|
|
|
kAudioUnitScope_Global, 0, &auvol);
|
|
|
|
|
|
|
|
CHECK_CA_ERROR("could not get HAL output volume");
|
|
|
|
vol->left = vol->right = auvol * 100.0;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
coreaudio_error:
|
|
|
|
return CONTROL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_volume(struct ao *ao, struct ao_control_vol *vol) {
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
float auvol = (vol->left + vol->right) / 200.0;
|
|
|
|
OSStatus err =
|
|
|
|
AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume,
|
|
|
|
kAudioUnitScope_Global, 0, auvol, 0);
|
|
|
|
CHECK_CA_ERROR("could not set HAL output volume");
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
coreaudio_error:
|
|
|
|
return CONTROL_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2013-04-18 19:25:02 +00:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
2014-07-01 17:14:55 +00:00
|
|
|
case AOCONTROL_GET_VOLUME:
|
|
|
|
return get_volume(ao, arg);
|
|
|
|
case AOCONTROL_SET_VOLUME:
|
|
|
|
return set_volume(ao, arg);
|
2014-09-06 00:30:57 +00:00
|
|
|
case AOCONTROL_HAS_SOFT_VOLUME:
|
|
|
|
return CONTROL_TRUE;
|
2014-07-02 06:19:55 +00:00
|
|
|
}
|
2013-06-18 21:48:48 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 06:18:46 +00:00
|
|
|
static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd);
|
2015-05-05 19:45:55 +00:00
|
|
|
static void init_physical_format(struct ao *ao);
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2015-02-14 11:43:55 +00:00
|
|
|
static bool reinit_device(struct ao *ao) {
|
2014-06-30 17:09:03 +00:00
|
|
|
struct priv *p = ao->priv;
|
2005-06-05 14:47:26 +00:00
|
|
|
|
2014-10-12 10:11:32 +00:00
|
|
|
OSStatus err = ca_select_device(ao, ao->device, &p->device);
|
2014-06-30 17:09:03 +00:00
|
|
|
CHECK_CA_ERROR("failed to select device");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2015-02-14 11:43:55 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
coreaudio_error:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(struct ao *ao)
|
|
|
|
{
|
2015-05-05 19:45:55 +00:00
|
|
|
struct priv *p = ao->priv;
|
|
|
|
|
2016-11-25 20:00:39 +00:00
|
|
|
if (!af_fmt_is_pcm(ao->format) || (ao->init_flags & AO_INIT_EXCLUSIVE)) {
|
2015-07-03 17:21:22 +00:00
|
|
|
MP_VERBOSE(ao, "redirecting to coreaudio_exclusive\n");
|
2015-02-14 11:43:55 +00:00
|
|
|
ao->redirect = "coreaudio_exclusive";
|
|
|
|
return CONTROL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reinit_device(ao))
|
|
|
|
goto coreaudio_error;
|
|
|
|
|
2015-05-05 19:45:55 +00:00
|
|
|
if (p->change_physical_format)
|
|
|
|
init_physical_format(ao);
|
|
|
|
|
2015-05-05 19:47:19 +00:00
|
|
|
if (!ca_init_chmap(ao, p->device))
|
2014-06-30 17:09:03 +00:00
|
|
|
goto coreaudio_error;
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
AudioStreamBasicDescription asbd;
|
2014-07-02 06:02:00 +00:00
|
|
|
ca_fill_asbd(ao, &asbd);
|
2014-07-02 06:18:46 +00:00
|
|
|
|
|
|
|
if (!init_audiounit(ao, asbd))
|
|
|
|
goto coreaudio_error;
|
|
|
|
|
|
|
|
return CONTROL_OK;
|
2013-06-23 09:18:54 +00:00
|
|
|
|
|
|
|
coreaudio_error:
|
2013-07-04 16:51:46 +00:00
|
|
|
return CONTROL_ERROR;
|
2013-06-23 09:18:54 +00:00
|
|
|
}
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2015-05-05 19:45:55 +00:00
|
|
|
static void init_physical_format(struct ao *ao)
|
2015-05-04 23:07:57 +00:00
|
|
|
{
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
OSErr err;
|
|
|
|
|
2015-10-21 16:53:34 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
|
2015-05-05 19:45:55 +00:00
|
|
|
AudioStreamBasicDescription asbd;
|
|
|
|
ca_fill_asbd(ao, &asbd);
|
|
|
|
|
2015-05-04 23:07:57 +00:00
|
|
|
AudioStreamID *streams;
|
|
|
|
size_t n_streams;
|
|
|
|
|
|
|
|
err = CA_GET_ARY_O(p->device, kAudioDevicePropertyStreams,
|
|
|
|
&streams, &n_streams);
|
|
|
|
CHECK_CA_ERROR("could not get number of streams");
|
|
|
|
|
2015-10-21 16:53:34 +00:00
|
|
|
talloc_steal(tmp, streams);
|
|
|
|
|
2015-06-26 13:49:40 +00:00
|
|
|
MP_VERBOSE(ao, "Found %zd substream(s).\n", n_streams);
|
|
|
|
|
2015-05-04 23:07:57 +00:00
|
|
|
for (int i = 0; i < n_streams; i++) {
|
|
|
|
AudioStreamRangedDescription *formats;
|
|
|
|
size_t n_formats;
|
|
|
|
|
2015-06-26 13:49:40 +00:00
|
|
|
MP_VERBOSE(ao, "Looking at formats in substream %d...\n", i);
|
|
|
|
|
|
|
|
err = CA_GET_ARY(streams[i], kAudioStreamPropertyAvailablePhysicalFormats,
|
|
|
|
&formats, &n_formats);
|
2015-05-04 23:07:57 +00:00
|
|
|
|
|
|
|
if (!CHECK_CA_WARN("could not get number of stream formats"))
|
|
|
|
continue; // try next one
|
|
|
|
|
2015-10-21 16:53:34 +00:00
|
|
|
talloc_steal(tmp, formats);
|
2015-06-26 13:49:40 +00:00
|
|
|
|
|
|
|
uint32_t direction;
|
|
|
|
err = CA_GET(streams[i], kAudioStreamPropertyDirection, &direction);
|
|
|
|
CHECK_CA_ERROR("could not get stream direction");
|
|
|
|
if (direction != 0) {
|
|
|
|
MP_VERBOSE(ao, "Not an output stream.\n");
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-05 20:04:00 +00:00
|
|
|
|
2015-05-04 23:07:57 +00:00
|
|
|
AudioStreamBasicDescription best_asbd = {0};
|
|
|
|
|
|
|
|
for (int j = 0; j < n_formats; j++) {
|
|
|
|
AudioStreamBasicDescription *stream_asbd = &formats[j].mFormat;
|
|
|
|
|
2015-05-05 20:04:00 +00:00
|
|
|
ca_print_asbd(ao, "- ", stream_asbd);
|
|
|
|
|
2015-05-04 23:07:57 +00:00
|
|
|
if (!best_asbd.mFormatID || ca_asbd_is_better(&asbd, &best_asbd,
|
|
|
|
stream_asbd))
|
|
|
|
best_asbd = *stream_asbd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_asbd.mFormatID) {
|
2015-05-05 19:58:51 +00:00
|
|
|
p->original_asbd_stream = streams[i];
|
|
|
|
err = CA_GET(p->original_asbd_stream,
|
|
|
|
kAudioStreamPropertyPhysicalFormat,
|
|
|
|
&p->original_asbd);
|
|
|
|
CHECK_CA_WARN("could not get current physical stream format");
|
|
|
|
|
2015-10-21 16:54:36 +00:00
|
|
|
if (ca_asbd_equals(&p->original_asbd, &best_asbd)) {
|
|
|
|
MP_VERBOSE(ao, "Requested format already set, not changing.\n");
|
|
|
|
p->original_asbd.mFormatID = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-29 21:59:41 +00:00
|
|
|
if (!ca_change_physical_format_sync(ao, streams[i], best_asbd))
|
|
|
|
p->original_asbd = (AudioStreamBasicDescription){0};
|
2015-05-04 23:07:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
coreaudio_error:
|
2015-10-21 16:53:34 +00:00
|
|
|
talloc_free(tmp);
|
2015-05-04 23:07:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-02 06:18:46 +00:00
|
|
|
static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd)
|
2013-06-23 09:18:54 +00:00
|
|
|
{
|
|
|
|
OSStatus err;
|
|
|
|
uint32_t size;
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
|
|
|
|
AudioComponentDescription desc = (AudioComponentDescription) {
|
|
|
|
.componentType = kAudioUnitType_Output,
|
2014-10-12 10:11:32 +00:00
|
|
|
.componentSubType = (ao->device) ?
|
|
|
|
kAudioUnitSubType_HALOutput :
|
|
|
|
kAudioUnitSubType_DefaultOutput,
|
2013-06-23 09:18:54 +00:00
|
|
|
.componentManufacturer = kAudioUnitManufacturer_Apple,
|
|
|
|
.componentFlags = 0,
|
|
|
|
.componentFlagsMask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
|
2013-04-18 19:25:02 +00:00
|
|
|
if (comp == NULL) {
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_ERR(ao, "unable to find audio component\n");
|
2013-06-23 09:18:54 +00:00
|
|
|
goto coreaudio_error;
|
2013-04-18 19:25:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioComponentInstanceNew(comp, &(p->audio_unit));
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR("unable to open audio component");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitInitialize(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_component,
|
|
|
|
"unable to initialize audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
size = sizeof(AudioStreamBasicDescription);
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitProperty_StreamFormat,
|
2013-06-23 09:18:54 +00:00
|
|
|
kAudioUnitScope_Input, 0, &asbd, size);
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set the input format on the audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioOutputUnitProperty_CurrentDevice,
|
2013-06-27 06:29:48 +00:00
|
|
|
kAudioUnitScope_Global, 0, &p->device,
|
|
|
|
sizeof(p->device));
|
2013-07-03 16:49:02 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"can't link audio unit to selected device");
|
|
|
|
|
2014-07-03 17:05:22 +00:00
|
|
|
p->hw_latency_us = ca_get_hardware_latency(ao);
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
AURenderCallbackStruct render_cb = (AURenderCallbackStruct) {
|
|
|
|
.inputProc = render_cb_lpcm,
|
|
|
|
.inputProcRefCon = ao,
|
|
|
|
};
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitProperty_SetRenderCallback,
|
2013-06-23 09:18:54 +00:00
|
|
|
kAudioUnitScope_Input, 0, &render_cb,
|
2013-04-18 19:25:02 +00:00
|
|
|
sizeof(AURenderCallbackStruct));
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set render callback on audio unit");
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2014-07-02 06:18:46 +00:00
|
|
|
return true;
|
2007-12-04 12:38:31 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error_audiounit:
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error_component:
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error:
|
2014-07-02 06:18:46 +00:00
|
|
|
return false;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 17:29:18 +00:00
|
|
|
static void stop(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2014-07-02 17:29:18 +00:00
|
|
|
OSStatus err = AudioOutputUnitStop(p->audio_unit);
|
|
|
|
CHECK_CA_WARN("can't stop audio unit");
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 17:29:18 +00:00
|
|
|
static void start(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2014-07-02 17:29:18 +00:00
|
|
|
OSStatus err = AudioOutputUnitStart(p->audio_unit);
|
|
|
|
CHECK_CA_WARN("can't start audio unit");
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-08 23:49:39 +00:00
|
|
|
static void uninit(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2014-06-30 17:09:03 +00:00
|
|
|
AudioOutputUnitStop(p->audio_unit);
|
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2015-05-05 19:58:51 +00:00
|
|
|
|
|
|
|
if (p->original_asbd.mFormatID) {
|
|
|
|
OSStatus err = CA_SET(p->original_asbd_stream,
|
|
|
|
kAudioStreamPropertyPhysicalFormat,
|
|
|
|
&p->original_asbd);
|
|
|
|
CHECK_CA_WARN("could not restore physical stream format");
|
|
|
|
}
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-14 11:43:55 +00:00
|
|
|
static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr,
|
|
|
|
const AudioObjectPropertyAddress addr[],
|
2015-06-29 21:54:18 +00:00
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
struct ao *ao = ctx;
|
|
|
|
MP_VERBOSE(ao, "Handling potential hotplug event...\n");
|
|
|
|
reinit_device(ao);
|
|
|
|
ao_hotplug_event(ao);
|
2015-02-14 11:43:55 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t hotplug_properties[] = {
|
|
|
|
kAudioHardwarePropertyDevices,
|
|
|
|
kAudioHardwarePropertyDefaultOutputDevice
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hotplug_init(struct ao *ao)
|
|
|
|
{
|
|
|
|
if (!reinit_device(ao))
|
|
|
|
goto coreaudio_error;
|
|
|
|
|
|
|
|
OSStatus err = noErr;
|
|
|
|
for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
hotplug_properties[i],
|
|
|
|
kAudioObjectPropertyScopeGlobal,
|
|
|
|
kAudioObjectPropertyElementMaster
|
|
|
|
};
|
|
|
|
err = AudioObjectAddPropertyListener(
|
|
|
|
kAudioObjectSystemObject, &addr, hotplug_cb, (void *)ao);
|
|
|
|
if (err != noErr) {
|
2016-01-11 19:25:00 +00:00
|
|
|
char *c1 = mp_tag_str(hotplug_properties[i]);
|
|
|
|
char *c2 = mp_tag_str(err);
|
2015-02-14 11:43:55 +00:00
|
|
|
MP_ERR(ao, "failed to set device listener %s (%s)", c1, c2);
|
|
|
|
goto coreaudio_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
coreaudio_error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hotplug_uninit(struct ao *ao)
|
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
|
|
|
for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {
|
|
|
|
AudioObjectPropertyAddress addr = {
|
|
|
|
hotplug_properties[i],
|
|
|
|
kAudioObjectPropertyScopeGlobal,
|
|
|
|
kAudioObjectPropertyElementMaster
|
|
|
|
};
|
|
|
|
err = AudioObjectRemovePropertyListener(
|
|
|
|
kAudioObjectSystemObject, &addr, hotplug_cb, (void *)ao);
|
|
|
|
if (err != noErr) {
|
2016-01-11 19:25:00 +00:00
|
|
|
char *c1 = mp_tag_str(hotplug_properties[i]);
|
|
|
|
char *c2 = mp_tag_str(err);
|
2015-02-14 11:43:55 +00:00
|
|
|
MP_ERR(ao, "failed to set device listener %s (%s)", c1, c2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 20:27:08 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
const struct ao_driver audio_out_coreaudio = {
|
2015-02-14 11:43:55 +00:00
|
|
|
.description = "CoreAudio AudioUnit",
|
|
|
|
.name = "coreaudio",
|
|
|
|
.uninit = uninit,
|
|
|
|
.init = init,
|
|
|
|
.control = control,
|
2016-08-09 10:30:18 +00:00
|
|
|
.reset = stop,
|
2015-02-14 11:43:55 +00:00
|
|
|
.resume = start,
|
|
|
|
.hotplug_init = hotplug_init,
|
|
|
|
.hotplug_uninit = hotplug_uninit,
|
|
|
|
.list_devs = ca_get_device_list,
|
|
|
|
.priv_size = sizeof(struct priv),
|
2015-05-04 23:07:57 +00:00
|
|
|
.options = (const struct m_option[]){
|
|
|
|
OPT_FLAG("change-physical-format", change_physical_format, 0),
|
|
|
|
{0}
|
|
|
|
},
|
2016-11-25 20:00:39 +00:00
|
|
|
.options_prefix = "coreaudio",
|
2013-04-19 21:04:11 +00:00
|
|
|
};
|