diff options
author | Arun Raghavan <git@arunraghavan.net> | 2014-11-28 15:06:35 +0530 |
---|---|---|
committer | Arun Raghavan <git@arunraghavan.net> | 2014-12-15 11:19:51 +0530 |
commit | b06ae280610dac8eb11de3ac758dfa691bdb210b (patch) | |
tree | 06d5232df2803aa9696f11f0517daf86e978a722 /sys | |
parent | 199461bb2eec8adeeceffba3817e7d533cf55d87 (diff) |
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
Diffstat (limited to 'sys')
-rw-r--r-- | sys/osxaudio/gstosxaudioringbuffer.c | 6 | ||||
-rw-r--r-- | sys/osxaudio/gstosxaudioringbuffer.h | 3 | ||||
-rw-r--r-- | sys/osxaudio/gstosxaudiosink.c | 21 | ||||
-rw-r--r-- | sys/osxaudio/gstosxaudiosrc.c | 21 |
4 files changed, 32 insertions, 19 deletions
diff --git a/sys/osxaudio/gstosxaudioringbuffer.c b/sys/osxaudio/gstosxaudioringbuffer.c index 14faa7835..047665151 100644 --- a/sys/osxaudio/gstosxaudioringbuffer.c +++ b/sys/osxaudio/gstosxaudioringbuffer.c @@ -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); } diff --git a/sys/osxaudio/gstosxaudioringbuffer.h b/sys/osxaudio/gstosxaudioringbuffer.h index 5054fd385..dbc2e1225 100644 --- a/sys/osxaudio/gstosxaudioringbuffer.h +++ b/sys/osxaudio/gstosxaudioringbuffer.h @@ -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; }; diff --git a/sys/osxaudio/gstosxaudiosink.c b/sys/osxaudio/gstosxaudiosink.c index 6764c3b48..dcc2d6c7d 100644 --- a/sys/osxaudio/gstosxaudiosink.c +++ b/sys/osxaudio/gstosxaudiosink.c @@ -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; } diff --git a/sys/osxaudio/gstosxaudiosrc.c b/sys/osxaudio/gstosxaudiosrc.c index a57b35fed..6698714ff 100644 --- a/sys/osxaudio/gstosxaudiosrc.c +++ b/sys/osxaudio/gstosxaudiosrc.c @@ -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; } |