osxaudio: Move device selection to ringbuffer->open_device()
authorArun Raghavan <git@arunraghavan.net>
Fri, 28 Nov 2014 09:36:35 +0000 (15:06 +0530)
committerArun Raghavan <git@arunraghavan.net>
Mon, 15 Dec 2014 05:49:51 +0000 (11:19 +0530)
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

sys/osxaudio/gstosxaudioringbuffer.c
sys/osxaudio/gstosxaudioringbuffer.h
sys/osxaudio/gstosxaudiosink.c
sys/osxaudio/gstosxaudiosrc.c

index 14faa78..0476651 100644 (file)
@@ -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);
 }
index 5054fd3..dbc2e12 100644 (file)
@@ -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;
 };
index 6764c3b..dcc2d6c 100644 (file)
@@ -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;
 }
index a57b35f..6698714 100644 (file)
@@ -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;
 }