[calls] sip: media-pipeline: Let the OS allocate sockets for udpsrc



commit 53d6082d64637a0455bfe1a28a412d002d0f8aaa
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Mon Feb 28 09:49:43 2022 +0100

    sip: media-pipeline: Let the OS allocate sockets for udpsrc
    
    First of we get rid of the bindings between from "lport-rtp" and "lport-rtcp" to
    the "port" property of the udpsrc elements. The properties themselves will get
    removed a little later as the required changes are rather intrusive and we need
    some more infrastructure in place before we can do the switch.

 plugins/sip/calls-sip-media-pipeline.c | 57 ++++++++++++++++++++++------------
 plugins/sip/calls-sip-media-pipeline.h |  2 ++
 2 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/plugins/sip/calls-sip-media-pipeline.c b/plugins/sip/calls-sip-media-pipeline.c
index 285b4c43..ca9afc61 100644
--- a/plugins/sip/calls-sip-media-pipeline.c
+++ b/plugins/sip/calls-sip-media-pipeline.c
@@ -295,7 +295,7 @@ send_pipeline_setup_codecs (CallsSipMediaPipeline *self,
   return send_pipeline_link_elements (self, error);
 }
 
-/** TODO: we're describing the desired state (not the current state)
+/**
  * Prepare a skeleton send pipeline where we can later
  * plug the codec specific elements into.
  *
@@ -363,10 +363,6 @@ send_pipeline_init (CallsSipMediaPipeline *self,
                           self->rtp_sink, "host",
                           G_BINDING_BIDIRECTIONAL);
 
-  g_object_bind_property (self, "lport-rtcp",
-                          self->rtcp_send_src, "port",
-                          G_BINDING_BIDIRECTIONAL);
-
   g_object_bind_property (self, "rport-rtcp",
                           self->rtcp_send_sink, "port",
                           G_BINDING_BIDIRECTIONAL);
@@ -375,6 +371,8 @@ send_pipeline_init (CallsSipMediaPipeline *self,
                           self->rtcp_send_sink, "host",
                           G_BINDING_BIDIRECTIONAL);
 
+  /* TODO bind sockets */
+
   gst_bin_add (GST_BIN (self->send_pipeline), self->send_rtpbin);
   gst_bin_add_many (GST_BIN (self->send_pipeline), self->rtp_sink,
                     self->rtcp_send_src, self->rtcp_send_sink, NULL);
@@ -485,17 +483,16 @@ recv_pipeline_setup_codecs (CallsSipMediaPipeline *self,
 }
 
 
-/** TODO: we're describing the desired state (not the current state)
+/**
  * Prepares a skeleton receiver pipeline which can later be
  * used to plug codec specific element in.
  * This pipeline just consists of (minimally linked) rtpbin
  * audio sink and two udpsrc elements, one for RTP and one for RTCP.
  *
- * The pipeline will be started and stopped to let the OS allocate
- * sockets for us instead of building and providing GSockets ourselves
- * by hand. These GSockets will later be reused for any outgoing
- * traffic for of our hole punching scheme as a simple NAT traversal
- * technique.
+ * The pipeline will be set ready to let the OS allocate sockets
+ * for us instead of building and providing GSockets ourselves
+ * by hand. These GSockets are reused for any outgoing traffic in our
+ * hole punching scheme as a simple NAT traversal technique.
  */
 static gboolean
 recv_pipeline_init (CallsSipMediaPipeline *self,
@@ -550,13 +547,9 @@ recv_pipeline_init (CallsSipMediaPipeline *self,
                 NULL);
 
 
-  g_object_bind_property (self, "lport-rtp",
-                          self->rtp_src, "port",
-                          G_BINDING_BIDIRECTIONAL);
-
-  g_object_bind_property (self, "lport-rtcp",
-                          self->rtcp_recv_src, "port",
-                          G_BINDING_BIDIRECTIONAL);
+  /* port 0 means allocate */
+  g_object_set (self->rtp_src, "port", 0, NULL);
+  g_object_set (self->rtcp_recv_src, "port", 0, NULL);
 
   g_object_bind_property (self, "rport-rtcp",
                           self->rtcp_recv_sink, "port",
@@ -570,10 +563,11 @@ recv_pipeline_init (CallsSipMediaPipeline *self,
   gst_bin_add_many (GST_BIN (self->recv_pipeline), self->rtp_src,
                     self->rtcp_recv_src, self->rtcp_recv_sink, NULL);
 
-  /* TODO use temporary bus watch for the initial pipeline start/stop */
   self->bus_recv = gst_pipeline_get_bus (GST_PIPELINE (self->recv_pipeline));
   self->bus_watch_recv = gst_bus_add_watch (self->bus_recv, on_bus_message, self);
 
+  /* Set pipeline to ready to get ports allocated */
+  gst_element_set_state (self->recv_pipeline, GST_STATE_READY);
 
   return TRUE;
 }
@@ -973,4 +967,29 @@ calls_sip_media_pipeline_pause (CallsSipMediaPipeline *self,
 }
 
 
+int
+calls_sip_media_pipeline_get_rtp_port (CallsSipMediaPipeline *self)
+{
+  int port;
+
+  g_return_val_if_fail (CALLS_IS_SIP_MEDIA_PIPELINE (self), 0);
+
+  g_object_get (self->rtp_src, "port", &port, NULL);
+
+  return port;
+}
+
+
+int
+calls_sip_media_pipeline_get_rtcp_port (CallsSipMediaPipeline *self)
+{
+  int port;
+
+  g_return_val_if_fail (CALLS_IS_SIP_MEDIA_PIPELINE (self), 0);
+
+  g_object_get (self->rtcp_recv_src, "port", &port, NULL);
+
+  return port;
+}
+
 #undef MAKE_ELEMENT
diff --git a/plugins/sip/calls-sip-media-pipeline.h b/plugins/sip/calls-sip-media-pipeline.h
index fdcc9b07..4cc01152 100644
--- a/plugins/sip/calls-sip-media-pipeline.h
+++ b/plugins/sip/calls-sip-media-pipeline.h
@@ -42,5 +42,7 @@ void                   calls_sip_media_pipeline_start                  (CallsSip
 void                   calls_sip_media_pipeline_stop                   (CallsSipMediaPipeline *self);
 void                   calls_sip_media_pipeline_pause                  (CallsSipMediaPipeline *self,
                                                                         gboolean               pause);
+int                    calls_sip_media_pipeline_get_rtp_port           (CallsSipMediaPipeline *self);
+int                    calls_sip_media_pipeline_get_rtcp_port          (CallsSipMediaPipeline *self);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]