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)
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);
}
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);
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);
}
}
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
};
AudioObjectPropertyAddress audioDevicesAddress = {
kAudioHardwarePropertyDevices,
- kAudioDevicePropertyScopeOutput,
+ kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
}
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
};
}
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
};
}
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
};
}
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;
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);
(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);
}
/* 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 */
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++) {
}
}
- 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;
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;
-}