Bug 1266753 - Update cubeb to revision dbdfb to pick up OSX device notification changes. r=padenot

MozReview-Commit-ID: 7N66FmG9P5u
This commit is contained in:
Alex Chronopoulos 2016-04-22 16:36:39 +02:00
Родитель 8fda7f21b4
Коммит a60e62f398
3 изменённых файлов: 121 добавлений и 72 удалений

Просмотреть файл

@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system.
The cubeb git repository is: git://github.com/kinetiknz/cubeb.git The cubeb git repository is: git://github.com/kinetiknz/cubeb.git
The git commit ID used was 0bc02f9f34dc8c39175157daf770d522ec160a64. The git commit ID used was dbdfb3904deb7a0381588209cdd7388217d96e61.

Просмотреть файл

@ -384,7 +384,7 @@ int cubeb_stream_device_destroy(cubeb_stream * stream,
int cubeb_stream_register_device_changed_callback(cubeb_stream * stream, int cubeb_stream_register_device_changed_callback(cubeb_stream * stream,
cubeb_device_changed_callback device_changed_callback) cubeb_device_changed_callback device_changed_callback)
{ {
if (!stream || !device_changed_callback) { if (!stream) {
return CUBEB_ERROR_INVALID_PARAMETER; return CUBEB_ERROR_INVALID_PARAMETER;
} }

Просмотреть файл

@ -440,9 +440,6 @@ audiounit_get_input_device_id(AudioDeviceID * device_id)
return CUBEB_OK; return CUBEB_OK;
} }
static int audiounit_install_device_changed_callback(cubeb_stream * stm);
static int audiounit_uninstall_device_changed_callback();
static OSStatus static OSStatus
audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count, audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count,
const AudioObjectPropertyAddress * addresses, const AudioObjectPropertyAddress * addresses,
@ -453,6 +450,7 @@ audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count,
for (UInt32 i = 0; i < address_count; i++) { for (UInt32 i = 0; i < address_count; i++) {
switch(addresses[i].mSelector) { switch(addresses[i].mSelector) {
case kAudioHardwarePropertyDefaultOutputDevice: case kAudioHardwarePropertyDefaultOutputDevice:
case kAudioHardwarePropertyDefaultInputDevice:
/* fall through */ /* fall through */
case kAudioDevicePropertyDataSource: case kAudioDevicePropertyDataSource:
pthread_mutex_lock(&stm->mutex); pthread_mutex_lock(&stm->mutex);
@ -467,48 +465,86 @@ audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count,
return noErr; return noErr;
} }
OSStatus
audiounit_add_listener(cubeb_stream * stm, AudioDeviceID id, AudioObjectPropertySelector selector,
AudioObjectPropertyScope scope, AudioObjectPropertyListenerProc listener)
{
AudioObjectPropertyAddress address = {
selector,
scope,
kAudioObjectPropertyElementMaster
};
return AudioObjectAddPropertyListener(id, &address, listener, stm);
}
OSStatus
audiounit_remove_listener(cubeb_stream * stm, AudioDeviceID id,
AudioObjectPropertySelector selector,
AudioObjectPropertyScope scope,
AudioObjectPropertyListenerProc listener)
{
AudioObjectPropertyAddress address = {
selector,
scope,
kAudioObjectPropertyElementMaster
};
return AudioObjectRemovePropertyListener(id, &address, listener, stm);
}
static int static int
audiounit_install_device_changed_callback(cubeb_stream * stm) audiounit_install_device_changed_callback(cubeb_stream * stm)
{ {
OSStatus r; OSStatus r;
AudioDeviceID id;
/* This event will notify us when the data source on the same device changes, if (stm->output_unit) {
* for example when the user plugs in a normal (non-usb) headset in the /* This event will notify us when the data source on the same device changes,
* headphone jack. */ * for example when the user plugs in a normal (non-usb) headset in the
AudioObjectPropertyAddress alive_address = { * headphone jack. */
kAudioDevicePropertyDataSource, AudioDeviceID output_dev_id;
kAudioObjectPropertyScopeGlobal, r = audiounit_get_output_device_id(&output_dev_id);
kAudioObjectPropertyElementMaster if (r != noErr) {
}; return CUBEB_ERROR;
}
if (audiounit_get_output_device_id(&id) != noErr) { r = audiounit_add_listener(stm, output_dev_id, kAudioDevicePropertyDataSource,
return CUBEB_ERROR; kAudioObjectPropertyScopeOutput, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
/* This event will notify us when the default audio device changes,
* for example when the user plugs in a USB headset and the system chooses it
* automatically as the default, or when another device is chosen in the
* dropdown list. */
r = audiounit_add_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
} }
r = AudioObjectAddPropertyListener(id, &alive_address, if (stm->input_unit) {
&audiounit_property_listener_callback, /* This event will notify us when the data source on the input device changes. */
stm); AudioDeviceID input_dev_id;
if (r != noErr) { r = audiounit_get_input_device_id(&input_dev_id);
return CUBEB_ERROR; if (r != noErr) {
} return CUBEB_ERROR;
}
/* This event will notify us when the default audio device changes, r = audiounit_add_listener(stm, input_dev_id, kAudioDevicePropertyDataSource,
* for example when the user plugs in a USB headset and the system chooses it kAudioObjectPropertyScopeInput, &audiounit_property_listener_callback);
* automatically as the default, or when another device is chosen in the if (r != noErr) {
* dropdown list. */ return CUBEB_ERROR;
AudioObjectPropertyAddress default_device_address = { }
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
r = AudioObjectAddPropertyListener(kAudioObjectSystemObject, /* This event will notify us when the default input device changes. */
&default_device_address, r = audiounit_add_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultInputDevice,
&audiounit_property_listener_callback, kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback);
stm); if (r != noErr) {
if (r != noErr) { return CUBEB_ERROR;
return CUBEB_ERROR; }
} }
return CUBEB_OK; return CUBEB_OK;
@ -518,39 +554,46 @@ static int
audiounit_uninstall_device_changed_callback(cubeb_stream * stm) audiounit_uninstall_device_changed_callback(cubeb_stream * stm)
{ {
OSStatus r; OSStatus r;
AudioDeviceID id;
AudioObjectPropertyAddress datasource_address = { if (stm->output_unit) {
kAudioDevicePropertyDataSource, AudioDeviceID output_dev_id;
kAudioObjectPropertyScopeGlobal, r = audiounit_get_output_device_id(&output_dev_id);
kAudioObjectPropertyElementMaster if (r != noErr) {
}; return CUBEB_ERROR;
}
if (audiounit_get_output_device_id(&id) != noErr) { r = audiounit_remove_listener(stm, output_dev_id, kAudioDevicePropertyDataSource,
return CUBEB_ERROR; kAudioObjectPropertyScopeOutput, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
r = audiounit_remove_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
} }
r = AudioObjectRemovePropertyListener(id, &datasource_address, if (stm->input_unit) {
&audiounit_property_listener_callback, AudioDeviceID input_dev_id;
stm); r = audiounit_get_input_device_id(&input_dev_id);
if (r != noErr) { if (r != noErr) {
return CUBEB_ERROR; return CUBEB_ERROR;
}
r = audiounit_remove_listener(stm, input_dev_id, kAudioDevicePropertyDataSource,
kAudioObjectPropertyScopeInput, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
r = audiounit_remove_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultInputDevice,
kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback);
if (r != noErr) {
return CUBEB_ERROR;
}
} }
AudioObjectPropertyAddress default_device_address = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
r = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
&default_device_address,
&audiounit_property_listener_callback,
stm);
if (r != noErr) {
return CUBEB_ERROR;
}
return CUBEB_OK; return CUBEB_OK;
} }
@ -1140,12 +1183,6 @@ audiounit_stream_init(cubeb * context,
} }
*stream = stm; *stream = stm;
#if !TARGET_OS_IPHONE
/* we dont' check the return value here, because we want to be able to play
* even if we can't detect device changes. */
audiounit_install_device_changed_callback(stm);
#endif
LOG("Cubeb stream init successfully.\n"); LOG("Cubeb stream init successfully.\n");
return CUBEB_OK; return CUBEB_OK;
} }
@ -1446,11 +1483,23 @@ int audiounit_stream_device_destroy(cubeb_stream * stream,
int audiounit_stream_register_device_changed_callback(cubeb_stream * stream, int audiounit_stream_register_device_changed_callback(cubeb_stream * stream,
cubeb_device_changed_callback device_changed_callback) cubeb_device_changed_callback device_changed_callback)
{ {
/* Note: second register without unregister first causes 'nope' error.
* Current implementation requires unregister before register a new cb. */
assert(!stream->device_changed_callback);
pthread_mutex_lock(&stream->mutex); pthread_mutex_lock(&stream->mutex);
stream->device_changed_callback = device_changed_callback; stream->device_changed_callback = device_changed_callback;
int r = CUBEB_OK;
#if !TARGET_OS_IPHONE
if (device_changed_callback) {
r = audiounit_install_device_changed_callback(stream);
} else {
r = audiounit_uninstall_device_changed_callback(stream);
}
#endif
pthread_mutex_unlock(&stream->mutex); pthread_mutex_unlock(&stream->mutex);
return CUBEB_OK; return r;
} }
static OSStatus static OSStatus