rtpmux: More Refactoring
authorzeeshan.ali@nokia.com <zeeshan.ali@nokia.com>
Thu, 22 Mar 2007 11:32:28 +0000 (11:32 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Sun, 16 Dec 2012 16:29:29 +0000 (16:29 +0000)
20070322113228-65035-bae34a79599e7de5293ed77b022361ccff822bb9.gz

gst/rtpmanager/gstrtpdtmfmux.c

index 44dad2b..9d0da4e 100644 (file)
@@ -187,8 +187,42 @@ gst_rtp_dtmf_mux_chain (GstPad * pad, GstBuffer * buffer)
   return ret;
 }
 
+static void
+gst_rtp_dtmf_mux_lock_stream (GstRTPDTMFMux *mux, GstPad * pad)
+{
+  if (mux->special_pad != NULL) {
+    GST_WARNING_OBJECT (mux,
+            "Stream lock already acquired by pad %s",
+            GST_ELEMENT_NAME (mux->special_pad));
+  }
+
+  else
+    mux->special_pad = gst_object_ref (pad);
+}
+
+static void
+gst_rtp_dtmf_mux_unlock_stream (GstRTPDTMFMux *mux, GstPad * pad)
+{
+  if (mux->special_pad == NULL) {
+    GST_WARNING_OBJECT (mux,
+            "Stream lock not acquired, can't release it");
+  }
+
+  else if (pad != mux->special_pad) {
+    GST_WARNING_OBJECT (mux,
+            "pad %s attempted to release Stream lock"
+            " which was acquired by pad %s", GST_ELEMENT_NAME (pad),
+            GST_ELEMENT_NAME (mux->special_pad));
+  }
+
+  else {
+    gst_object_unref (mux->special_pad);
+    mux->special_pad = NULL;
+  }
+}
+
 static gboolean
-gst_rtp_dtmf_mux_stream_lock_event_handler (GstRTPDTMFMux *mux, GstPad * pad,
+gst_rtp_dtmf_mux_handle_stream_lock_event (GstRTPDTMFMux *mux, GstPad * pad,
         const GstStructure * event_structure)
 {
   gboolean lock;
@@ -197,39 +231,44 @@ gst_rtp_dtmf_mux_stream_lock_event_handler (GstRTPDTMFMux *mux, GstPad * pad,
     return FALSE;
 
   GST_OBJECT_LOCK (mux);
-  if (lock) {
-    if (mux->special_pad != NULL) {
-      GST_WARNING_OBJECT (mux,
-              "Stream lock already acquired by pad %s",
-              GST_ELEMENT_NAME (mux->special_pad));
-    }
+  if (lock)
+    gst_rtp_dtmf_mux_lock_stream (mux, pad);
+  else
+    gst_rtp_dtmf_mux_unlock_stream (mux, pad);
+  GST_OBJECT_UNLOCK (mux);
 
-    else
-      mux->special_pad = gst_object_ref (pad);
+  return TRUE;
+}
+
+static gboolean
+gst_rtp_dtmf_mux_handle_downstream_event (GstRTPDTMFMux *mux, GstPad * pad, GstEvent * event)
+{
+  const GstStructure *structure;
+  gboolean ret = FALSE;
+
+  structure = gst_event_get_structure (event);
+  /* FIXME: is this event generic enough to be given a generic name? */
+  if (structure && gst_structure_has_name (structure, "stream-lock")) {
+    ret = gst_rtp_dtmf_mux_handle_stream_lock_event (mux, pad, structure);
   }
 
-  else {
-    if (mux->special_pad == NULL) {
-      GST_WARNING_OBJECT (mux,
-              "Stream lock not acquired, can't release it");
-    }
-
-    else if (pad != mux->special_pad) {
-      GST_WARNING_OBJECT (mux,
-              "pad %s attempted to release Stream lock"
-              " which was acquired by pad %s", GST_ELEMENT_NAME (pad),
-              GST_ELEMENT_NAME (mux->special_pad));
-    }
-
-    else {
-      gst_object_unref (mux->special_pad);
-      mux->special_pad = NULL;
-    }
+  return ret;
+}
+
+static gboolean
+gst_rtp_dtmf_mux_ignore_event (GstPad * pad, GstEvent * event)
+{
+  gboolean ret;
+
+  if (parent_class->sink_event_func) {
+    /* Give the parent a chance to handle the event first */
+    ret = parent_class->sink_event_func (pad, event);
   }
 
-  GST_OBJECT_UNLOCK (mux);
+  else
+    ret = gst_pad_event_default (pad, event);
 
-  return TRUE;
+  return ret;
 }
 
 static gboolean
@@ -245,33 +284,14 @@ gst_rtp_dtmf_mux_sink_event (GstPad * pad, GstEvent * event)
 
   switch (type) {
     case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
-    {
-      const GstStructure *structure;
-
-      structure = gst_event_get_structure (event);
-      /* FIXME: is this event generic enough to be given a generic name? */
-      if (structure && gst_structure_has_name (structure, "stream-lock")) {
-        ret = gst_rtp_dtmf_mux_stream_lock_event_handler (mux, pad, structure);
-      }
-
-      ret = TRUE;
+      ret = gst_rtp_dtmf_mux_handle_downstream_event (mux, pad, event);
       break;
-    }
     default:
-    {
-      if (parent_class->sink_event_func) {
-        /* Give the parent a chance to handle the event first */
-        ret = parent_class->sink_event_func (pad, event);
-      }
-
-      else
-        ret = gst_pad_event_default (pad, event);
+      ret = gst_rtp_dtmf_mux_ignore_event (pad, event);
       break;
-    }
   }
 
   gst_object_unref (mux);
-
   return ret;
 }