rsnstreamselector: Use iterate internal links instead of deprecated get internal...
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 19 Aug 2009 15:18:25 +0000 (17:18 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 31 Aug 2009 06:14:10 +0000 (08:14 +0200)
ext/resindvd/rsnstreamselector.c

index 2c7e58e..5ab5903 100644 (file)
@@ -114,7 +114,6 @@ static GstPadClass *selector_pad_parent_class = NULL;
 static void gst_selector_pad_reset (RsnSelectorPad * pad);
 static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
 static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
-static GList *gst_selector_pad_get_linked_pads (GstPad * pad);
 static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
 static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
     guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
@@ -233,23 +232,6 @@ gst_selector_pad_reset (RsnSelectorPad * pad)
   gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
 }
 
-/* strictly get the linked pad from the sinkpad. If the pad is active we return
- * the srcpad else we return NULL */
-static GList *
-gst_selector_pad_get_linked_pads (GstPad * pad)
-{
-  GstPad *otherpad;
-
-  otherpad = rsn_stream_selector_get_linked_pad (pad, TRUE);
-  if (!otherpad)
-    return NULL;
-
-  /* need to drop the ref, internal linked pads is not MT safe */
-  gst_object_unref (otherpad);
-
-  return g_list_append (NULL, otherpad);
-}
-
 static gboolean
 gst_selector_pad_event (GstPad * pad, GstEvent * event)
 {
@@ -467,7 +449,7 @@ static GstPad *rsn_stream_selector_request_new_pad (GstElement * element,
     GstPadTemplate * templ, const gchar * unused);
 static void rsn_stream_selector_release_pad (GstElement * element,
     GstPad * pad);
-static GList *rsn_stream_selector_get_linked_pads (GstPad * pad);
+static GstIterator *rsn_stream_selector_iterate_linked_pads (GstPad * pad);
 static GstCaps *rsn_stream_selector_getcaps (GstPad * pad);
 
 static GstElementClass *parent_class = NULL;
@@ -544,8 +526,8 @@ static void
 rsn_stream_selector_init (RsnStreamSelector * sel)
 {
   sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
-  gst_pad_set_internal_link_function (sel->srcpad,
-      GST_DEBUG_FUNCPTR (rsn_stream_selector_get_linked_pads));
+  gst_pad_set_iterate_internal_links_function (sel->srcpad,
+      GST_DEBUG_FUNCPTR (rsn_stream_selector_iterate_linked_pads));
   gst_pad_set_getcaps_function (sel->srcpad,
       GST_DEBUG_FUNCPTR (rsn_stream_selector_getcaps));
   gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
@@ -733,17 +715,71 @@ rsn_stream_selector_set_active (RsnStreamSelector * sel, GstPad * pad)
   GST_OBJECT_UNLOCK (GST_OBJECT_CAST (sel));
 }
 
-static GList *
-rsn_stream_selector_get_linked_pads (GstPad * pad)
+typedef struct
 {
-  GstPad *otherpad;
+  GstIterator parent;
+
+  GstPad *pad;
+  gboolean start;
+} RsnStreamSelectorIterator;
+
+static void
+_iterate_free (GstIterator * it)
+{
+  RsnStreamSelectorIterator *sit = (RsnStreamSelectorIterator *) it;
+
+  gst_object_unref (sit->pad);
+  g_free (it);
+}
+
+static GstIteratorResult
+_iterate_next (GstIterator * it, gpointer * result)
+{
+  RsnStreamSelectorIterator *sit = (RsnStreamSelectorIterator *) it;
+
+  if (sit->start) {
+    GstPad *res = rsn_stream_selector_get_linked_pad (sit->pad, TRUE);
+
+    *result = res;
+    sit->start = FALSE;
+    return res ? GST_ITERATOR_OK : GST_ITERATOR_DONE;
+  }
+
+  *result = NULL;
+  return GST_ITERATOR_DONE;
+}
+
+static GstIteratorItem
+_iterate_item (GstIterator * it, gpointer item)
+{
+  return GST_ITERATOR_ITEM_PASS;
+}
+
+static void
+_iterate_resync (GstIterator * it)
+{
+  RsnStreamSelectorIterator *sit = (RsnStreamSelectorIterator *) it;
+
+  sit->start = TRUE;
+}
+
+static GstIterator *
+rsn_stream_selector_iterate_linked_pads (GstPad * pad)
+{
+  RsnStreamSelector *sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
+  RsnStreamSelectorIterator *it = (RsnStreamSelectorIterator *)
+      gst_iterator_new (sizeof (RsnStreamSelectorIterator),
+      GST_TYPE_PAD,
+      GST_OBJECT_CAST (sel)->lock,
+      &GST_ELEMENT_CAST (sel)->pads_cookie,
+      _iterate_next, _iterate_item, _iterate_resync, _iterate_free);
+
+  it->pad = gst_object_ref (pad);
+  it->start = TRUE;
+
+  gst_object_unref (sel);
 
-  otherpad = rsn_stream_selector_get_linked_pad (pad, TRUE);
-  if (!otherpad)
-    return NULL;
-  /* need to drop the ref, internal linked pads is not MT safe */
-  gst_object_unref (otherpad);
-  return g_list_append (NULL, otherpad);
+  return (GstIterator *) it;
 }
 
 static GstPad *
@@ -771,8 +807,8 @@ rsn_stream_selector_request_new_pad (GstElement * element,
       GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
   gst_pad_set_chain_function (sinkpad,
       GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
-  gst_pad_set_internal_link_function (sinkpad,
-      GST_DEBUG_FUNCPTR (gst_selector_pad_get_linked_pads));
+  gst_pad_set_iterate_internal_links_function (sinkpad,
+      GST_DEBUG_FUNCPTR (rsn_stream_selector_iterate_linked_pads));
   gst_pad_set_bufferalloc_function (sinkpad,
       GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));