diff --git a/content/media/AudioStream.cpp b/content/media/AudioStream.cpp index 1a330d48e3b..7f66457bd1f 100644 --- a/content/media/AudioStream.cpp +++ b/content/media/AudioStream.cpp @@ -554,7 +554,7 @@ AudioStream::Init(int32_t aNumChannels, int32_t aRate, void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive) { #ifdef XP_MACOSX - cubeb_output_device* out; + cubeb_device* device; int rv; char name[128]; size_t length = sizeof(name); @@ -565,9 +565,9 @@ void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive) } if (!strncmp(name, "MacBookPro", 10)) { - if (cubeb_stream_get_current_output_device(mCubebStream, &out) == CUBEB_OK) { + if (cubeb_stream_get_current_evice(mCubebStream, &device) == CUBEB_OK) { // Check if we are currently outputing sound on external speakers. - if (!strcmp(out->name, "ispk")) { + if (!strcmp(device->name, "ispk")) { // Pan everything to the right speaker. if (aMicrophoneActive) { if (cubeb_stream_set_panning(mCubebStream, 1.0) != CUBEB_OK) { @@ -583,7 +583,7 @@ void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive) NS_WARNING("Could not pan audio output to the center."); } } - cubeb_stream_output_device_destroy(mCubebStream, out); + cubeb_stream_device_destroy(mCubebStream, device); } } #endif diff --git a/layout/media/symbols.def.in b/layout/media/symbols.def.in index ba5cc44a9b6..648f3a4b694 100644 --- a/layout/media/symbols.def.in +++ b/layout/media/symbols.def.in @@ -137,8 +137,8 @@ cubeb_stream_stop cubeb_stream_get_latency cubeb_stream_set_volume cubeb_stream_set_panning -cubeb_stream_get_current_output_device -cubeb_stream_output_device_destroy +cubeb_stream_get_current_device +cubeb_stream_device_destroy cubeb_stream_register_device_changed_callback th_comment_clear th_comment_init diff --git a/media/libcubeb/include/cubeb.h b/media/libcubeb/include/cubeb.h index a86c4983edd..2c0d74777f9 100644 --- a/media/libcubeb/include/cubeb.h +++ b/media/libcubeb/include/cubeb.h @@ -131,8 +131,9 @@ typedef struct { /** Output device description */ typedef struct { - char * name; /**< The name of the output device */ -} cubeb_output_device; + char * output_name; /**< The name of the output device */ + char * input_name; /**< The name of the input device */ +} cubeb_device; /** Stream states signaled via state_callback. */ typedef enum { @@ -303,18 +304,18 @@ int cubeb_stream_set_panning(cubeb_stream * stream, float panning); * @return CUBEB_ERROR_INVALID_PARAMETER if either stm, device or count are * invalid pointers */ -int cubeb_stream_get_current_output_device(cubeb_stream * stm, - cubeb_output_device ** const device); +int cubeb_stream_get_current_device(cubeb_stream * stm, + cubeb_device ** const device); /** - * Destroy a cubeb_output_device structure. - * @param stream the stream passed in cubeb_stream_get_current_output_device + * Destroy a cubeb_device structure. + * @param stream the stream passed in cubeb_stream_get_current_device * @param devices the devices to destroy * @return CUBEB_OK in case of success * @return CUBEB_ERROR_INVALID_PARAMETER if devices is an invalid pointer */ -int cubeb_stream_output_device_destroy(cubeb_stream * stream, - cubeb_output_device * devices); +int cubeb_stream_device_destroy(cubeb_stream * stream, + cubeb_device * devices); /** * Set a callback to be notified when the output device changes. diff --git a/media/libcubeb/src/cubeb-internal.h b/media/libcubeb/src/cubeb-internal.h index be3de8939a0..57b8349495c 100644 --- a/media/libcubeb/src/cubeb-internal.h +++ b/media/libcubeb/src/cubeb-internal.h @@ -30,10 +30,10 @@ struct cubeb_ops { int (* stream_get_latency)(cubeb_stream * stream, uint32_t * latency); int (* stream_set_volume)(cubeb_stream * stream, float volumes); int (* stream_set_panning)(cubeb_stream * stream, float panning); - int (* stream_get_current_output_device)(cubeb_stream * stream, - cubeb_output_device ** const device); - int (* stream_output_device_destroy)(cubeb_stream * stream, - cubeb_output_device * device); + int (* stream_get_current_device)(cubeb_stream * stream, + cubeb_device ** const device); + int (* stream_device_destroy)(cubeb_stream * stream, + cubeb_device * device); int (*stream_register_device_changed_callback)(cubeb_stream * stream, cubeb_device_changed_callback device_changed_callback); diff --git a/media/libcubeb/src/cubeb.c b/media/libcubeb/src/cubeb.c index b12589883c2..9c3adccb870 100644 --- a/media/libcubeb/src/cubeb.c +++ b/media/libcubeb/src/cubeb.c @@ -278,8 +278,8 @@ int cubeb_stream_set_panning(cubeb_stream * stream, float panning) return stream->context->ops->stream_set_panning(stream, panning); } -int cubeb_stream_get_current_output_device(cubeb_stream * stream, - cubeb_output_device ** const device) +int cubeb_stream_get_current_device(cubeb_stream * stream, + cubeb_device ** const device) { if (!stream || !device) { return CUBEB_ERROR_INVALID_PARAMETER; @@ -287,16 +287,16 @@ int cubeb_stream_get_current_output_device(cubeb_stream * stream, // If we find an implementation, call the function, it might not be available // on some platforms. - if (stream->context->ops->stream_get_current_output_device) { - return stream->context->ops->stream_get_current_output_device(stream, - device); + if (stream->context->ops->stream_get_current_device) { + return stream->context->ops->stream_get_current_device(stream, + device); } return CUBEB_ERROR; } -int cubeb_stream_output_device_destroy(cubeb_stream * stream, - cubeb_output_device * device) +int cubeb_stream_device_destroy(cubeb_stream * stream, + cubeb_device * device) { if (!stream || !device) { return CUBEB_ERROR_INVALID_PARAMETER; @@ -304,8 +304,8 @@ int cubeb_stream_output_device_destroy(cubeb_stream * stream, // If we find an implementation, call the function, it might not be available // on some platforms. - if (stream->context->ops->stream_output_device_destroy) { - return stream->context->ops->stream_output_device_destroy(stream, device); + if (stream->context->ops->stream_device_destroy) { + return stream->context->ops->stream_device_destroy(stream, device); } return CUBEB_ERROR; diff --git a/media/libcubeb/src/cubeb_alsa.c b/media/libcubeb/src/cubeb_alsa.c index a706ac99340..a962553d2a2 100644 --- a/media/libcubeb/src/cubeb_alsa.c +++ b/media/libcubeb/src/cubeb_alsa.c @@ -1131,7 +1131,7 @@ static struct cubeb_ops const alsa_ops = { .stream_get_latency = alsa_stream_get_latency, .stream_set_volume = alsa_stream_set_volume, .stream_set_panning = alsa_stream_set_panning, - .stream_get_current_output_device = NULL, - .stream_output_device_destroy = NULL, + .stream_get_current_device = NULL, + .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL }; diff --git a/media/libcubeb/src/cubeb_audiotrack.c b/media/libcubeb/src/cubeb_audiotrack.c index c5db455e81c..e2c65d789d5 100644 --- a/media/libcubeb/src/cubeb_audiotrack.c +++ b/media/libcubeb/src/cubeb_audiotrack.c @@ -505,7 +505,7 @@ static struct cubeb_ops const audiotrack_ops = { .stream_get_latency = audiotrack_stream_get_latency, .stream_set_volume = audiotrack_stream_set_volume, .stream_set_panning = audiotrack_stream_set_panning, - .stream_get_current_output_device = NULL, - .stream_output_device_destroy = NULL, + .stream_get_current_device = NULL, + .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL }; diff --git a/media/libcubeb/src/cubeb_audiounit.c b/media/libcubeb/src/cubeb_audiounit.c index 3ed2a3275bb..54d7acf576a 100644 --- a/media/libcubeb/src/cubeb_audiounit.c +++ b/media/libcubeb/src/cubeb_audiounit.c @@ -182,6 +182,32 @@ audiounit_get_output_device_id(AudioDeviceID * device_id) return CUBEB_OK; } +static int +audiounit_get_input_device_id(AudioDeviceID * device_id) +{ + UInt32 size; + OSStatus r; + AudioObjectPropertyAddress input_device_address = { + kAudioHardwarePropertyDefaultInputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + + size = sizeof(*device_id); + + r = AudioObjectGetPropertyData(kAudioObjectSystemObject, + &input_device_address, + 0, + NULL, + &size, + device_id); + if (r != noErr) { + return CUBEB_ERROR; + } + + return CUBEB_OK; +} + static int audiounit_install_device_changed_callback(cubeb_stream * stm); static int audiounit_uninstall_device_changed_callback(); @@ -794,14 +820,15 @@ int audiounit_stream_set_panning(cubeb_stream * stm, float panning) return CUBEB_OK; } -int audiounit_stream_get_current_output_device(cubeb_stream * stm, - cubeb_output_device ** const device) +int audiounit_stream_get_current_device(cubeb_stream * stm, + cubeb_device ** const device) { OSStatus r; UInt32 size; UInt32 data; char strdata[4]; AudioDeviceID output_device_id; + AudioDeviceID input_device_id; AudioObjectPropertyAddress datasource_address = { kAudioDevicePropertyDataSource, @@ -809,12 +836,23 @@ int audiounit_stream_get_current_output_device(cubeb_stream * stm, kAudioObjectPropertyElementMaster }; + AudioObjectPropertyAddress datasource_address_input = { + kAudioDevicePropertyDataSource, + kAudioDevicePropertyScopeInput, + kAudioObjectPropertyElementMaster + }; + *device = NULL; if (audiounit_get_output_device_id(&output_device_id) != CUBEB_OK) { return CUBEB_ERROR; } + *device = malloc(sizeof(cubeb_device)); + if (!*device) { + return CUBEB_ERROR; + } + size = sizeof(UInt32); /* This fails with some USB headset, so simply return an empty string. */ r = AudioObjectGetPropertyData(output_device_id, @@ -825,13 +863,13 @@ int audiounit_stream_get_current_output_device(cubeb_stream * stm, data = 0; } - *device = malloc(sizeof(cubeb_output_device)); - if (!*device) { + (*device)->output_name = malloc(size + 1); + if (!(*device)->output_name) { return CUBEB_ERROR; } - (*device)->name = malloc(size + 1); - if (!(*device)->name) { + (*device)->output_name = malloc(size + 1); + if (!(*device)->output_name) { return CUBEB_ERROR; } @@ -841,16 +879,43 @@ int audiounit_stream_get_current_output_device(cubeb_stream * stm, strdata[2] = (char)(data >> 8); strdata[3] = (char)(data); - memcpy((*device)->name, strdata, size); - (*device)->name[size] = '\0'; + memcpy((*device)->output_name, strdata, size); + (*device)->output_name[size] = '\0'; + + if (audiounit_get_input_device_id(&input_device_id) != CUBEB_OK) { + return CUBEB_ERROR; + } + + size = sizeof(UInt32); + r = AudioObjectGetPropertyData(input_device_id, &datasource_address_input, 0, NULL, &size, &data); + if (r != noErr) { + printf("Error when getting device !\n"); + size = 0; + data = 0; + } + + (*device)->input_name = malloc(size + 1); + if (!(*device)->input_name) { + return CUBEB_ERROR; + } + + // Turn the four chars packed into a uint32 into a string + strdata[0] = (char)(data >> 24); + strdata[1] = (char)(data >> 16); + strdata[2] = (char)(data >> 8); + strdata[3] = (char)(data); + + memcpy((*device)->input_name, strdata, size); + (*device)->input_name[size] = '\0'; return CUBEB_OK; } -int audiounit_stream_output_device_destroy(cubeb_stream * stream, - cubeb_output_device * device) +int audiounit_stream_device_destroy(cubeb_stream * stream, + cubeb_device * device) { - free(device->name); + free(device->output_name); + free(device->input_name); free(device); return CUBEB_OK; } @@ -880,7 +945,7 @@ static struct cubeb_ops const audiounit_ops = { .stream_get_latency = audiounit_stream_get_latency, .stream_set_volume = audiounit_stream_set_volume, .stream_set_panning = audiounit_stream_set_panning, - .stream_get_current_output_device = audiounit_stream_get_current_output_device, - .stream_output_device_destroy = audiounit_stream_output_device_destroy, + .stream_get_current_device = audiounit_stream_get_current_device, + .stream_device_destroy = audiounit_stream_device_destroy, .stream_register_device_changed_callback = audiounit_stream_register_device_changed_callback }; diff --git a/media/libcubeb/src/cubeb_opensl.c b/media/libcubeb/src/cubeb_opensl.c index 28736667a5e..4a058e68ea8 100644 --- a/media/libcubeb/src/cubeb_opensl.c +++ b/media/libcubeb/src/cubeb_opensl.c @@ -788,7 +788,7 @@ static struct cubeb_ops const opensl_ops = { .stream_get_latency = opensl_stream_get_latency, .stream_set_volume = opensl_stream_set_volume, .stream_set_panning = opensl_stream_set_panning, - .stream_get_current_output_device = NULL, - .stream_output_device_destroy = NULL, + .stream_get_current_device = NULL, + .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL }; diff --git a/media/libcubeb/src/cubeb_pulse.c b/media/libcubeb/src/cubeb_pulse.c index d7287d34730..da9aa0672d6 100644 --- a/media/libcubeb/src/cubeb_pulse.c +++ b/media/libcubeb/src/cubeb_pulse.c @@ -749,7 +749,7 @@ static struct cubeb_ops const pulse_ops = { .stream_get_latency = pulse_stream_get_latency, .stream_set_volume = pulse_stream_set_volume, .stream_set_panning = pulse_stream_set_panning, - .stream_get_current_output_device = NULL, - .stream_output_device_destroy = NULL, + .stream_get_current_device = NULL, + .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL }; diff --git a/media/libcubeb/src/cubeb_sndio.c b/media/libcubeb/src/cubeb_sndio.c index e1895eb91c5..751b7f6c42e 100644 --- a/media/libcubeb/src/cubeb_sndio.c +++ b/media/libcubeb/src/cubeb_sndio.c @@ -362,7 +362,7 @@ static struct cubeb_ops const sndio_ops = { .stream_get_latency = sndio_stream_get_latency, .stream_set_volume = sndio_stream_set_volume, .stream_set_panning = sndio_stream_set_panning, - .stream_get_current_output_device = NULL, - .stream_output_device_destroy = NULL, + .stream_get_current_device = NULL, + .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL }; diff --git a/media/libcubeb/src/cubeb_wasapi.cpp b/media/libcubeb/src/cubeb_wasapi.cpp index e960cd69917..585b8647d5b 100644 --- a/media/libcubeb/src/cubeb_wasapi.cpp +++ b/media/libcubeb/src/cubeb_wasapi.cpp @@ -940,8 +940,8 @@ cubeb_ops const wasapi_ops = { /*.stream_get_latency =*/ wasapi_stream_get_latency, /*.stream_set_volume =*/ wasapi_stream_set_volume, /*.stream_set_panning =*/ wasapi_stream_set_panning, - /*.stream_get_current_output_device =*/ NULL, - /*.stream_output_device_destroy =*/ NULL, + /*.stream_get_current_device =*/ NULL, + /*.stream_device_destroy =*/ NULL, /*.stream_register_device_changed_callback =*/ NULL }; } // namespace anonymous diff --git a/media/libcubeb/src/cubeb_winmm.c b/media/libcubeb/src/cubeb_winmm.c index 84175931438..6ac7e1ed1c2 100644 --- a/media/libcubeb/src/cubeb_winmm.c +++ b/media/libcubeb/src/cubeb_winmm.c @@ -715,7 +715,7 @@ static struct cubeb_ops const winmm_ops = { /*.stream_get_latency = */ winmm_stream_get_latency, /*.stream_set_volume =*/ winmm_stream_set_volume, /*.stream_set_panning =*/ winmm_stream_set_panning, - /*.stream_get_current_output_device =*/ NULL, - /*.stream_output_device_destroy =*/ NULL, + /*.stream_get_current_device =*/ NULL, + /*.stream_device_destroy =*/ NULL, /*.stream_register_device_changed_callback=*/ NULL };