mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-01 13:49:58 +00:00
osxaudio: Move device selection to ringbuffer->open_device()
This is conceptually the right thing to do, and allows us to correctly catch errors in device selection as well, which we could not do while creating the ringbuffer. https://bugzilla.gnome.org/show_bug.cgi?id=740987
This commit is contained in:
parent
199461bb2e
commit
b06ae28061
4 changed files with 32 additions and 19 deletions
|
@ -148,9 +148,11 @@ gst_osx_audio_ring_buffer_finalize (GObject * object)
|
|||
static gboolean
|
||||
gst_osx_audio_ring_buffer_open_device (GstAudioRingBuffer * buf)
|
||||
{
|
||||
GstOsxAudioRingBuffer *osxbuf;
|
||||
GstOsxAudioRingBuffer *osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);;
|
||||
GstElement *parent = GST_ELEMENT_CAST (GST_OBJECT_PARENT (buf));
|
||||
|
||||
osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
|
||||
if (!osxbuf->select_device (parent, osxbuf))
|
||||
return FALSE;
|
||||
|
||||
return gst_core_audio_open (osxbuf->core_audio);
|
||||
}
|
||||
|
|
|
@ -81,6 +81,9 @@ struct _GstOsxAudioRingBuffer
|
|||
|
||||
GstCoreAudio *core_audio;
|
||||
|
||||
/* Set by the parent to select the required device */
|
||||
gboolean (*select_device) (GstElement * element, GstOsxAudioRingBuffer * buf);
|
||||
|
||||
guint buffer_len;
|
||||
guint segoffset;
|
||||
};
|
||||
|
|
|
@ -130,7 +130,8 @@ static GstAudioRingBuffer
|
|||
* gst_osx_audio_sink_create_ringbuffer (GstAudioBaseSink * sink);
|
||||
static void gst_osx_audio_sink_osxelement_init (gpointer g_iface,
|
||||
gpointer iface_data);
|
||||
static gboolean gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink);
|
||||
static gboolean gst_osx_audio_sink_select_device (GstElement * sink,
|
||||
GstOsxAudioRingBuffer * ringbuffer);
|
||||
static void gst_osx_audio_sink_set_volume (GstOsxAudioSink * sink);
|
||||
|
||||
static OSStatus gst_osx_audio_sink_io_proc (GstOsxAudioRingBuffer * buf,
|
||||
|
@ -434,24 +435,21 @@ gst_osx_audio_sink_create_ringbuffer (GstAudioBaseSink * sink)
|
|||
|
||||
osxsink = GST_OSX_AUDIO_SINK (sink);
|
||||
|
||||
if (!gst_osx_audio_sink_select_device (osxsink)) {
|
||||
GST_ERROR_OBJECT (sink, "Could not select device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (sink, "Creating ringbuffer");
|
||||
ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL);
|
||||
GST_DEBUG_OBJECT (sink, "osx sink %p element %p ioproc %p", osxsink,
|
||||
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsink),
|
||||
(void *) gst_osx_audio_sink_io_proc);
|
||||
|
||||
gst_osx_audio_sink_set_volume (osxsink);
|
||||
ringbuffer->select_device =
|
||||
GST_DEBUG_FUNCPTR (gst_osx_audio_sink_select_device);
|
||||
|
||||
ringbuffer->core_audio->element =
|
||||
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsink);
|
||||
ringbuffer->core_audio->device_id = osxsink->device_id;
|
||||
ringbuffer->core_audio->is_src = FALSE;
|
||||
|
||||
gst_osx_audio_sink_set_volume (osxsink);
|
||||
|
||||
return GST_AUDIO_RING_BUFFER (ringbuffer);
|
||||
}
|
||||
|
||||
|
@ -645,13 +643,18 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink)
|
||||
gst_osx_audio_sink_select_device (GstElement * sink,
|
||||
GstOsxAudioRingBuffer * ringbuffer)
|
||||
{
|
||||
GstOsxAudioSink *osxsink = GST_OSX_AUDIO_SINK (sink);
|
||||
gboolean res = FALSE;
|
||||
|
||||
if (!gst_core_audio_select_device (&osxsink->device_id, TRUE))
|
||||
return FALSE;
|
||||
|
||||
res = gst_osx_audio_sink_allowed_caps (osxsink);
|
||||
|
||||
ringbuffer->core_audio->device_id = osxsink->device_id;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,8 @@ static OSStatus gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
|
|||
AudioUnitRenderActionFlags * ioActionFlags,
|
||||
const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber,
|
||||
UInt32 inNumberFrames, AudioBufferList * bufferList);
|
||||
static gboolean gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc);
|
||||
static gboolean gst_osx_audio_src_select_device (GstElement * src,
|
||||
GstOsxAudioRingBuffer * ringbuffer);
|
||||
|
||||
static void
|
||||
gst_osx_audio_src_do_init (GType type)
|
||||
|
@ -251,21 +252,18 @@ gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
|
|||
|
||||
osxsrc = GST_OSX_AUDIO_SRC (src);
|
||||
|
||||
if (!gst_osx_audio_src_select_device (osxsrc)) {
|
||||
GST_ERROR_OBJECT (src, "Could not select device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (osxsrc, "Creating ringbuffer");
|
||||
ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL);
|
||||
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);
|
||||
|
||||
ringbuffer->select_device =
|
||||
GST_DEBUG_FUNCPTR (gst_osx_audio_src_select_device);
|
||||
|
||||
ringbuffer->core_audio->element =
|
||||
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc);
|
||||
ringbuffer->core_audio->is_src = TRUE;
|
||||
ringbuffer->core_audio->device_id = osxsrc->device_id;
|
||||
|
||||
return GST_AUDIO_RING_BUFFER (ringbuffer);
|
||||
}
|
||||
|
@ -332,5 +330,12 @@ gst_osx_audio_src_osxelement_init (gpointer g_iface, gpointer iface_data)
|
|||
static gboolean
|
||||
gst_osx_audio_src_select_device (GstOsxAudioSrc * osxsrc)
|
||||
{
|
||||
return gst_core_audio_select_device (&osxsrc->device_id, FALSE);
|
||||
GstOsxAudioSrc *osxsrc = GST_OSX_AUDIO_SRC (element);
|
||||
|
||||
if (!gst_core_audio_select_device (&osxsrc->device_id, FALSE))
|
||||
return FALSE;
|
||||
|
||||
ringbuffer->core_audio->device_id = osxsrc->device_id;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue