diff --git a/sys/osxaudio/gstosxaudiosink.c b/sys/osxaudio/gstosxaudiosink.c index 0479ce1ce5..6764c3b480 100644 --- a/sys/osxaudio/gstosxaudiosink.c +++ b/sys/osxaudio/gstosxaudiosink.c @@ -537,7 +537,8 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink) /* First collect info about the HW capabilites and preferences */ spdif_allowed = gst_core_audio_audio_device_is_spdif_avail (osxsink->device_id); - layout = gst_core_audio_audio_device_get_channel_layout (osxsink->device_id); + layout = gst_core_audio_audio_device_get_channel_layout (osxsink->device_id, + TRUE); GST_DEBUG_OBJECT (osxsink, "Selected device ID: %u SPDIF allowed: %d", (unsigned) osxsink->device_id, spdif_allowed); @@ -648,7 +649,7 @@ gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink) { gboolean res = FALSE; - if (!gst_core_audio_select_device (&osxsink->device_id)) + if (!gst_core_audio_select_device (&osxsink->device_id, TRUE)) return FALSE; res = gst_osx_audio_sink_allowed_caps (osxsink); diff --git a/sys/osxaudio/gstosxaudiosrc.c b/sys/osxaudio/gstosxaudiosrc.c index fa5da162f1..a57b35fed0 100644 --- a/sys/osxaudio/gstosxaudiosrc.c +++ b/sys/osxaudio/gstosxaudiosrc.c @@ -109,7 +109,7 @@ static OSStatus gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf, AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList); -static void gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc); +static gboolean gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc); static void gst_osx_audio_src_do_init (GType type) @@ -122,7 +122,6 @@ gst_osx_audio_src_do_init (GType type) GST_DEBUG_CATEGORY_INIT (osx_audiosrc_debug, "osxaudiosrc", 0, "OSX Audio Src"); - GST_DEBUG ("Adding static interface"); g_type_add_interface_static (type, GST_OSX_AUDIO_ELEMENT_TYPE, &osxelement_info); } @@ -252,11 +251,14 @@ gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src) osxsrc = GST_OSX_AUDIO_SRC (src); - gst_osx_audio_src_select_device (osxsrc); + if (!gst_osx_audio_src_select_device (osxsrc)) { + GST_ERROR_OBJECT (src, "Could not select device"); + return NULL; + } - GST_DEBUG ("Creating ringbuffer"); + GST_DEBUG_OBJECT (osxsrc, "Creating ringbuffer"); ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL); - GST_DEBUG ("osx src 0x%p element 0x%p ioproc 0x%p", osxsrc, + GST_DEBUG_OBJECT (osxsrc, "osx src 0x%p element 0x%p ioproc 0x%p", osxsrc, GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc), (void *) gst_osx_audio_src_io_proc); @@ -327,8 +329,8 @@ gst_osx_audio_src_osxelement_init (gpointer g_iface, gpointer iface_data) iface->io_proc = (AURenderCallback) gst_osx_audio_src_io_proc; } -static void +static gboolean gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc) { - gst_core_audio_select_source_device (&osxsrc->device_id); + return gst_core_audio_select_device (&osxsrc->device_id, FALSE); } diff --git a/sys/osxaudio/gstosxcoreaudio.c b/sys/osxaudio/gstosxcoreaudio.c index 9f69dc0809..d7129f13ba 100644 --- a/sys/osxaudio/gstosxcoreaudio.c +++ b/sys/osxaudio/gstosxcoreaudio.c @@ -196,15 +196,9 @@ gst_core_audio_set_volume (GstCoreAudio * core_audio, gfloat volume) } gboolean -gst_core_audio_select_device (AudioDeviceID * device_id) +gst_core_audio_select_device (AudioDeviceID * device_id, gboolean output) { - return gst_core_audio_select_device_impl (device_id); -} - -gboolean -gst_core_audio_select_source_device (AudioDeviceID * device_id) -{ - return gst_core_audio_select_source_device_impl (device_id); + return gst_core_audio_select_device_impl (device_id, output); } void diff --git a/sys/osxaudio/gstosxcoreaudio.h b/sys/osxaudio/gstosxcoreaudio.h index 78cd4b9975..ff97f509b0 100644 --- a/sys/osxaudio/gstosxcoreaudio.h +++ b/sys/osxaudio/gstosxcoreaudio.h @@ -139,11 +139,9 @@ void gst_core_audio_set_volume (GstCoreAudio *core gboolean gst_core_audio_audio_device_is_spdif_avail (AudioDeviceID device_id); -gboolean gst_core_audio_select_device (AudioDeviceID *device_id); +gboolean gst_core_audio_select_device (AudioDeviceID *device_id, gboolean output); -gboolean gst_core_audio_select_source_device (AudioDeviceID *device_id); - -AudioChannelLayout * gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id); +AudioChannelLayout * gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id, gboolean output); G_END_DECLS diff --git a/sys/osxaudio/gstosxcoreaudiohal.c b/sys/osxaudio/gstosxcoreaudiohal.c index fde41f3eea..0fd4ab0e7c 100644 --- a/sys/osxaudio/gstosxcoreaudiohal.c +++ b/sys/osxaudio/gstosxcoreaudiohal.c @@ -49,15 +49,19 @@ _audio_system_set_runloop (CFRunLoopRef runLoop) } static inline AudioDeviceID -_audio_system_get_default_output (void) +_audio_system_get_default_device (gboolean output) { OSStatus status = noErr; UInt32 propertySize = sizeof (AudioDeviceID); AudioDeviceID device_id = kAudioDeviceUnknown; + AudioObjectPropertySelector prop_selector; + + prop_selector = output ? kAudioHardwarePropertyDefaultOutputDevice : + kAudioHardwarePropertyDefaultInputDevice; AudioObjectPropertyAddress defaultDeviceAddress = { - kAudioHardwarePropertyDefaultOutputDevice, - kAudioDevicePropertyScopeOutput, + prop_selector, + kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; @@ -79,7 +83,7 @@ _audio_system_get_devices (gint * ndevices) AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, - kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; @@ -107,15 +111,19 @@ _audio_system_get_devices (gint * ndevices) } static inline gboolean -_audio_device_is_alive (AudioDeviceID device_id) +_audio_device_is_alive (AudioDeviceID device_id, gboolean output) { OSStatus status = noErr; int alive = FALSE; UInt32 propertySize = sizeof (alive); + AudioObjectPropertyScope prop_scope; + + prop_scope = output ? kAudioDevicePropertyScopeOutput : + kAudioDevicePropertyScopeInput; AudioObjectPropertyAddress audioDeviceAliveAddress = { kAudioDevicePropertyDeviceIsAlive, - kAudioDevicePropertyScopeOutput, + prop_scope, kAudioObjectPropertyElementMaster }; @@ -249,15 +257,19 @@ _audio_device_set_mixing (AudioDeviceID device_id, gboolean enable_mix) } static inline gchar * -_audio_device_get_name (AudioDeviceID device_id) +_audio_device_get_name (AudioDeviceID device_id, gboolean output) { OSStatus status = noErr; UInt32 propertySize = 0; gchar *device_name = NULL; + AudioObjectPropertyScope prop_scope; + + prop_scope = output ? kAudioDevicePropertyScopeOutput : + kAudioDevicePropertyScopeInput; AudioObjectPropertyAddress deviceNameAddress = { kAudioDevicePropertyDeviceName, - kAudioDevicePropertyScopeOutput, + prop_scope, kAudioObjectPropertyElementMaster }; @@ -306,15 +318,20 @@ _audio_device_has_output (AudioDeviceID device_id) } AudioChannelLayout * -gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id) +gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id, + gboolean output) { OSStatus status = noErr; UInt32 propertySize = 0; AudioChannelLayout *layout = NULL; + AudioObjectPropertyScope prop_scope; + + prop_scope = output ? kAudioDevicePropertyScopeOutput : + kAudioDevicePropertyScopeInput; AudioObjectPropertyAddress channelLayoutAddress = { kAudioDevicePropertyPreferredChannelLayout, - kAudioDevicePropertyScopeOutput, + prop_scope, kAudioObjectPropertyElementMaster }; @@ -1131,7 +1148,7 @@ done: } static gboolean -gst_core_audio_select_device_impl (AudioDeviceID * device_id) +gst_core_audio_select_device_impl (AudioDeviceID * device_id, gboolean output) { AudioDeviceID *devices = NULL; AudioDeviceID default_device_id = 0; @@ -1151,7 +1168,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id) for (i = 0; i < ndevices; i++) { gchar *device_name; - if ((device_name = _audio_device_get_name (devices[i]))) { + if ((device_name = _audio_device_get_name (devices[i], output))) { if (!_audio_device_has_output (devices[i])) { GST_DEBUG ("Input Device ID: %u Name: %s", (unsigned) devices[i], device_name); @@ -1160,7 +1177,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id) (unsigned) devices[i], device_name); channel_layout = - gst_core_audio_audio_device_get_channel_layout (devices[i]); + gst_core_audio_audio_device_get_channel_layout (devices[i], output); if (channel_layout) { gst_core_audio_dump_channel_layout (channel_layout); g_free (channel_layout); @@ -1172,7 +1189,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id) } /* Find the ID of the default output device */ - default_device_id = _audio_system_get_default_output (); + default_device_id = _audio_system_get_default_device (output); /* Here we decide if selected device is valid or autoselect * the default one when required */ @@ -1180,6 +1197,9 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id) if (default_device_id != kAudioDeviceUnknown) { *device_id = default_device_id; res = TRUE; + } else { + /* No device of required type available */ + res = FALSE; } } else { for (i = 0; i < ndevices; i++) { @@ -1188,7 +1208,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id) } } - if (res && !_audio_device_is_alive (*device_id)) { + if (res && !_audio_device_is_alive (*device_id, output)) { GST_ERROR ("Requested device not usable"); res = FALSE; goto done; @@ -1221,34 +1241,3 @@ gst_core_audio_audio_device_is_spdif_avail_impl (AudioDeviceID device_id) return res; } - -static gboolean -gst_core_audio_select_source_device_impl (AudioDeviceID * device_id) -{ - OSStatus status; - UInt32 propertySize; - - if (*device_id == kAudioDeviceUnknown) { - /* If no specific device has been selected by the user, then pick the - * default device */ - GST_DEBUG ("Selecting device for OSXAudioSrc"); - propertySize = sizeof (*device_id); - status = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultInputDevice, - &propertySize, device_id); - - if (status) { - GST_WARNING ("AudioHardwareGetProperty returned %d", (int) status); - } else { - GST_DEBUG ("AudioHardwareGetProperty returned 0"); - } - - if (*device_id == kAudioDeviceUnknown) { - GST_WARNING ("AudioHardwareGetProperty: device_id is " - "kAudioDeviceUnknown"); - } - - GST_DEBUG ("AudioHardwareGetProperty: device_id is %lu", (long) *device_id); - } - - return TRUE; -} diff --git a/sys/osxaudio/gstosxcoreaudioremoteio.c b/sys/osxaudio/gstosxcoreaudioremoteio.c index dd97aa1e03..58ad5d036b 100644 --- a/sys/osxaudio/gstosxcoreaudioremoteio.c +++ b/sys/osxaudio/gstosxcoreaudioremoteio.c @@ -106,18 +106,12 @@ gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id) } static gboolean -gst_core_audio_select_device_impl (AudioDeviceID * device_id) +gst_core_audio_select_device_impl (AudioDeviceID * device_id, gboolean output) { /* No device selection in iOS */ return TRUE; } -static gboolean -gst_core_audio_select_source_device_impl (AudioDeviceID * device_id) -{ - return TRUE; -} - static gboolean gst_core_audio_audio_device_is_spdif_avail_impl (AudioDeviceID device_id) {