osxaudio: Consolidate input and output code paths a bit

https://bugzilla.gnome.org/show_bug.cgi?id=740987
This commit is contained in:
Arun Raghavan 2014-11-28 14:34:34 +05:30
parent 76944350c0
commit 199461bb2e
6 changed files with 52 additions and 74 deletions

View file

@ -537,7 +537,8 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink)
/* First collect info about the HW capabilites and preferences */ /* First collect info about the HW capabilites and preferences */
spdif_allowed = spdif_allowed =
gst_core_audio_audio_device_is_spdif_avail (osxsink->device_id); 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", GST_DEBUG_OBJECT (osxsink, "Selected device ID: %u SPDIF allowed: %d",
(unsigned) osxsink->device_id, spdif_allowed); (unsigned) osxsink->device_id, spdif_allowed);
@ -648,7 +649,7 @@ gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink)
{ {
gboolean res = FALSE; gboolean res = FALSE;
if (!gst_core_audio_select_device (&osxsink->device_id)) if (!gst_core_audio_select_device (&osxsink->device_id, TRUE))
return FALSE; return FALSE;
res = gst_osx_audio_sink_allowed_caps (osxsink); res = gst_osx_audio_sink_allowed_caps (osxsink);

View file

@ -109,7 +109,7 @@ static OSStatus gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
AudioUnitRenderActionFlags * ioActionFlags, AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber, const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber,
UInt32 inNumberFrames, AudioBufferList * bufferList); 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 static void
gst_osx_audio_src_do_init (GType type) 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, GST_DEBUG_CATEGORY_INIT (osx_audiosrc_debug, "osxaudiosrc", 0,
"OSX Audio Src"); "OSX Audio Src");
GST_DEBUG ("Adding static interface");
g_type_add_interface_static (type, GST_OSX_AUDIO_ELEMENT_TYPE, g_type_add_interface_static (type, GST_OSX_AUDIO_ELEMENT_TYPE,
&osxelement_info); &osxelement_info);
} }
@ -252,11 +251,14 @@ gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
osxsrc = GST_OSX_AUDIO_SRC (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); 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), GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc),
(void *) gst_osx_audio_src_io_proc); (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; iface->io_proc = (AURenderCallback) gst_osx_audio_src_io_proc;
} }
static void static gboolean
gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc) 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);
} }

View file

@ -196,15 +196,9 @@ gst_core_audio_set_volume (GstCoreAudio * core_audio, gfloat volume)
} }
gboolean 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); return gst_core_audio_select_device_impl (device_id, output);
}
gboolean
gst_core_audio_select_source_device (AudioDeviceID * device_id)
{
return gst_core_audio_select_source_device_impl (device_id);
} }
void void

View file

@ -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_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, gboolean output);
AudioChannelLayout * gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id);
G_END_DECLS G_END_DECLS

View file

@ -49,15 +49,19 @@ _audio_system_set_runloop (CFRunLoopRef runLoop)
} }
static inline AudioDeviceID static inline AudioDeviceID
_audio_system_get_default_output (void) _audio_system_get_default_device (gboolean output)
{ {
OSStatus status = noErr; OSStatus status = noErr;
UInt32 propertySize = sizeof (AudioDeviceID); UInt32 propertySize = sizeof (AudioDeviceID);
AudioDeviceID device_id = kAudioDeviceUnknown; AudioDeviceID device_id = kAudioDeviceUnknown;
AudioObjectPropertySelector prop_selector;
prop_selector = output ? kAudioHardwarePropertyDefaultOutputDevice :
kAudioHardwarePropertyDefaultInputDevice;
AudioObjectPropertyAddress defaultDeviceAddress = { AudioObjectPropertyAddress defaultDeviceAddress = {
kAudioHardwarePropertyDefaultOutputDevice, prop_selector,
kAudioDevicePropertyScopeOutput, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
@ -79,7 +83,7 @@ _audio_system_get_devices (gint * ndevices)
AudioObjectPropertyAddress audioDevicesAddress = { AudioObjectPropertyAddress audioDevicesAddress = {
kAudioHardwarePropertyDevices, kAudioHardwarePropertyDevices,
kAudioDevicePropertyScopeOutput, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
@ -107,15 +111,19 @@ _audio_system_get_devices (gint * ndevices)
} }
static inline gboolean static inline gboolean
_audio_device_is_alive (AudioDeviceID device_id) _audio_device_is_alive (AudioDeviceID device_id, gboolean output)
{ {
OSStatus status = noErr; OSStatus status = noErr;
int alive = FALSE; int alive = FALSE;
UInt32 propertySize = sizeof (alive); UInt32 propertySize = sizeof (alive);
AudioObjectPropertyScope prop_scope;
prop_scope = output ? kAudioDevicePropertyScopeOutput :
kAudioDevicePropertyScopeInput;
AudioObjectPropertyAddress audioDeviceAliveAddress = { AudioObjectPropertyAddress audioDeviceAliveAddress = {
kAudioDevicePropertyDeviceIsAlive, kAudioDevicePropertyDeviceIsAlive,
kAudioDevicePropertyScopeOutput, prop_scope,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
@ -249,15 +257,19 @@ _audio_device_set_mixing (AudioDeviceID device_id, gboolean enable_mix)
} }
static inline gchar * static inline gchar *
_audio_device_get_name (AudioDeviceID device_id) _audio_device_get_name (AudioDeviceID device_id, gboolean output)
{ {
OSStatus status = noErr; OSStatus status = noErr;
UInt32 propertySize = 0; UInt32 propertySize = 0;
gchar *device_name = NULL; gchar *device_name = NULL;
AudioObjectPropertyScope prop_scope;
prop_scope = output ? kAudioDevicePropertyScopeOutput :
kAudioDevicePropertyScopeInput;
AudioObjectPropertyAddress deviceNameAddress = { AudioObjectPropertyAddress deviceNameAddress = {
kAudioDevicePropertyDeviceName, kAudioDevicePropertyDeviceName,
kAudioDevicePropertyScopeOutput, prop_scope,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
@ -306,15 +318,20 @@ _audio_device_has_output (AudioDeviceID device_id)
} }
AudioChannelLayout * 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; OSStatus status = noErr;
UInt32 propertySize = 0; UInt32 propertySize = 0;
AudioChannelLayout *layout = NULL; AudioChannelLayout *layout = NULL;
AudioObjectPropertyScope prop_scope;
prop_scope = output ? kAudioDevicePropertyScopeOutput :
kAudioDevicePropertyScopeInput;
AudioObjectPropertyAddress channelLayoutAddress = { AudioObjectPropertyAddress channelLayoutAddress = {
kAudioDevicePropertyPreferredChannelLayout, kAudioDevicePropertyPreferredChannelLayout,
kAudioDevicePropertyScopeOutput, prop_scope,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
@ -1131,7 +1148,7 @@ done:
} }
static gboolean 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 *devices = NULL;
AudioDeviceID default_device_id = 0; AudioDeviceID default_device_id = 0;
@ -1151,7 +1168,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id)
for (i = 0; i < ndevices; i++) { for (i = 0; i < ndevices; i++) {
gchar *device_name; 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])) { if (!_audio_device_has_output (devices[i])) {
GST_DEBUG ("Input Device ID: %u Name: %s", GST_DEBUG ("Input Device ID: %u Name: %s",
(unsigned) devices[i], device_name); (unsigned) devices[i], device_name);
@ -1160,7 +1177,7 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id)
(unsigned) devices[i], device_name); (unsigned) devices[i], device_name);
channel_layout = 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) { if (channel_layout) {
gst_core_audio_dump_channel_layout (channel_layout); gst_core_audio_dump_channel_layout (channel_layout);
g_free (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 */ /* 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 /* Here we decide if selected device is valid or autoselect
* the default one when required */ * the default one when required */
@ -1180,6 +1197,9 @@ gst_core_audio_select_device_impl (AudioDeviceID * device_id)
if (default_device_id != kAudioDeviceUnknown) { if (default_device_id != kAudioDeviceUnknown) {
*device_id = default_device_id; *device_id = default_device_id;
res = TRUE; res = TRUE;
} else {
/* No device of required type available */
res = FALSE;
} }
} else { } else {
for (i = 0; i < ndevices; i++) { 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"); GST_ERROR ("Requested device not usable");
res = FALSE; res = FALSE;
goto done; goto done;
@ -1221,34 +1241,3 @@ gst_core_audio_audio_device_is_spdif_avail_impl (AudioDeviceID device_id)
return res; 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;
}

View file

@ -106,18 +106,12 @@ gst_core_audio_audio_device_get_channel_layout (AudioDeviceID device_id)
} }
static gboolean 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 */ /* No device selection in iOS */
return TRUE; return TRUE;
} }
static gboolean
gst_core_audio_select_source_device_impl (AudioDeviceID * device_id)
{
return TRUE;
}
static gboolean static gboolean
gst_core_audio_audio_device_is_spdif_avail_impl (AudioDeviceID device_id) gst_core_audio_audio_device_is_spdif_avail_impl (AudioDeviceID device_id)
{ {