diff --git a/plugins/sip/calls-sip-call.c b/plugins/sip/calls-sip-call.c index 18bb7f4..8270d56 100644 --- a/plugins/sip/calls-sip-call.c +++ b/plugins/sip/calls-sip-call.c @@ -65,8 +65,6 @@ struct _CallsSipCall char *ip; - guint lport_rtp; - guint lport_rtcp; guint rport_rtp; guint rport_rtcp; gchar *remote; @@ -97,18 +95,6 @@ try_setting_up_media_pipeline (CallsSipCall *self) calls_sip_media_pipeline_set_codec (self->pipeline, codec); } - if (!self->lport_rtp || !self->lport_rtcp || !self->remote || - !self->rport_rtp || !self->rport_rtcp) - return FALSE; - - g_debug ("Setting local ports: RTP/RTCP %u/%u", - self->lport_rtp, self->lport_rtcp); - - g_object_set (G_OBJECT (self->pipeline), - "lport-rtp", self->lport_rtp, - "lport-rtcp", self->lport_rtcp, - NULL); - g_debug ("Setting remote ports: RTP/RTCP %u/%u", self->rport_rtp, self->rport_rtcp); @@ -127,7 +113,7 @@ calls_sip_call_answer (CallsCall *call) { CallsSipCall *self; g_autofree gchar *local_sdp = NULL; - guint local_port = get_port_for_rtp (); + guint rtp_port, rtcp_port; g_assert (CALLS_IS_CALL (call)); g_assert (CALLS_IS_SIP_CALL (call)); @@ -141,12 +127,15 @@ calls_sip_call_answer (CallsCall *call) return; } - /* TODO get free port by creating GSocket and passing that to the pipeline */ - calls_sip_call_setup_local_media_connection (self, local_port, local_port + 1); + rtp_port = calls_sip_media_pipeline_get_rtp_port (self->pipeline); + rtcp_port = calls_sip_media_pipeline_get_rtcp_port (self->pipeline); + + calls_sip_call_setup_local_media_connection (self); local_sdp = calls_sip_media_manager_get_capabilities (self->manager, self->ip, - local_port, + rtp_port, + rtcp_port, FALSE, self->codecs); @@ -317,19 +306,13 @@ calls_sip_call_init (CallsSipCall *self) /** * calls_sip_call_setup_local_media_connection: * @self: A #CallsSipCall - * @port_rtp: The RTP port on the the local host - * @port_rtcp: The RTCP port on the local host */ void -calls_sip_call_setup_local_media_connection (CallsSipCall *self, - guint port_rtp, - guint port_rtcp) +calls_sip_call_setup_local_media_connection (CallsSipCall *self) { g_return_if_fail (CALLS_IS_SIP_CALL (self)); - self->lport_rtp = port_rtp; - self->lport_rtcp = port_rtcp; - + /* XXX maybe we can get rid of this completely */ try_setting_up_media_pipeline (self); } diff --git a/plugins/sip/calls-sip-call.h b/plugins/sip/calls-sip-call.h index dcb6329..5a57dc3 100644 --- a/plugins/sip/calls-sip-call.h +++ b/plugins/sip/calls-sip-call.h @@ -45,9 +45,7 @@ void calls_sip_call_setup_remote_media_connection (CallsSi const char *remote, guint port_rtp, guint port_rtcp); -void calls_sip_call_setup_local_media_connection (CallsSipCall *self, - guint port_rtp, - guint port_rtcp); +void calls_sip_call_setup_local_media_connection (CallsSipCall *self); void calls_sip_call_activate_media (CallsSipCall *self, gboolean enabled); void calls_sip_call_set_state (CallsSipCall *self, diff --git a/plugins/sip/calls-sip-media-manager.c b/plugins/sip/calls-sip-media-manager.c index 1a00161..9d3746d 100644 --- a/plugins/sip/calls-sip-media-manager.c +++ b/plugins/sip/calls-sip-media-manager.c @@ -222,7 +222,8 @@ calls_sip_media_manager_default (void) char * calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, const char *own_ip, - guint port, + gint rtp_port, + gint rtcp_port, gboolean use_srtp, GList *supported_codecs) { @@ -245,7 +246,7 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, /* media lines look f.e like "audio 31337 RTP/AVP 9 8 0" */ g_string_append_printf (media_line, - "m=audio %d RTP/%s", port, payload_type); + "m=audio %d RTP/%s", rtp_port, payload_type); for (node = supported_codecs; node != NULL; node = node->next) { MediaCodecInfo *codec = node->data; @@ -259,7 +260,7 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, "\r\n"); } - g_string_append_printf (attribute_lines, "a=rtcp:%d\r\n", port + 1); + g_string_append_printf (attribute_lines, "a=rtcp:%d\r\n", rtcp_port); done: if (own_ip && *own_ip) @@ -287,7 +288,8 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, /* calls_sip_media_manager_static_capabilities: * * @self: A #CallsSipMediaManager - * @port: Should eventually come from the ICE stack + * @rtp_port: Port to use for RTP. Should eventually come from the ICE stack + * @rtcp_port: Port to use for RTCP.Should eventually come from the ICE stack * @use_srtp: Whether to use srtp (not really handled) * * Returns: (transfer full): string describing capabilities @@ -296,14 +298,16 @@ calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, char * calls_sip_media_manager_static_capabilities (CallsSipMediaManager *self, const char *own_ip, - guint port, + gint rtp_port, + gint rtcp_port, gboolean use_srtp) { g_return_val_if_fail (CALLS_IS_SIP_MEDIA_MANAGER (self), NULL); return calls_sip_media_manager_get_capabilities (self, own_ip, - port, + rtp_port, + rtcp_port, use_srtp, self->preferred_codecs); } diff --git a/plugins/sip/calls-sip-media-manager.h b/plugins/sip/calls-sip-media-manager.h index 076235b..4158d78 100644 --- a/plugins/sip/calls-sip-media-manager.h +++ b/plugins/sip/calls-sip-media-manager.h @@ -40,12 +40,14 @@ G_DECLARE_FINAL_TYPE (CallsSipMediaManager, calls_sip_media_manager, CALLS, SIP_ CallsSipMediaManager* calls_sip_media_manager_default (void); gchar* calls_sip_media_manager_get_capabilities (CallsSipMediaManager *self, const char *own_ip, - guint port, + gint rtp_port, + gint rtcp_port, gboolean use_srtp, GList *supported_codecs); gchar* calls_sip_media_manager_static_capabilities (CallsSipMediaManager *self, const char *own_ip, - guint port, + gint rtp_port, + gint rtcp_port, gboolean use_srtp); gboolean calls_sip_media_manager_supports_media (CallsSipMediaManager *self, const char *media_type); diff --git a/plugins/sip/calls-sip-media-pipeline.c b/plugins/sip/calls-sip-media-pipeline.c index 4d64310..9c740b8 100644 --- a/plugins/sip/calls-sip-media-pipeline.c +++ b/plugins/sip/calls-sip-media-pipeline.c @@ -95,9 +95,7 @@ enum { PROP_0, PROP_CODEC, PROP_REMOTE, - PROP_LPORT_RTP, PROP_RPORT_RTP, - PROP_LPORT_RTCP, PROP_RPORT_RTCP, PROP_DEBUG, PROP_STATE, @@ -128,10 +126,8 @@ struct _CallsSipMediaPipeline { char *remote; gint rport_rtp; - gint lport_rtp; gint rport_rtcp; - gint lport_rtcp; /* Gstreamer Elements (sending) */ GstElement *send_pipeline; @@ -740,14 +736,6 @@ calls_sip_media_pipeline_get_property (GObject *object, g_value_set_string (value, self->remote); break; - case PROP_LPORT_RTP: - g_value_set_uint (value, self->lport_rtp); - break; - - case PROP_LPORT_RTCP: - g_value_set_uint (value, self->lport_rtcp); - break; - case PROP_RPORT_RTP: g_value_set_uint (value, self->rport_rtp); break; @@ -789,14 +777,6 @@ calls_sip_media_pipeline_set_property (GObject *object, self->remote = g_value_dup_string (value); break; - case PROP_LPORT_RTP: - self->lport_rtp = g_value_get_uint (value); - break; - - case PROP_LPORT_RTCP: - self->lport_rtcp = g_value_get_uint (value); - break; - case PROP_RPORT_RTP: self->rport_rtp = g_value_get_uint (value); break; @@ -884,18 +864,6 @@ calls_sip_media_pipeline_class_init (CallsSipMediaPipelineClass *klass) NULL, G_PARAM_READWRITE); - props[PROP_LPORT_RTP] = g_param_spec_uint ("lport-rtp", - "lport-rtp", - "local rtp port", - 1025, 65535, 5002, - G_PARAM_READWRITE); - - props[PROP_LPORT_RTCP] = g_param_spec_uint ("lport-rtcp", - "lport-rtcp", - "local rtcp port", - 1025, 65535, 5003, - G_PARAM_READWRITE); - props[PROP_RPORT_RTP] = g_param_spec_uint ("rport-rtp", "rport-rtp", "remote rtp port", diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c index c649d57..81057f5 100644 --- a/plugins/sip/calls-sip-origin.c +++ b/plugins/sip/calls-sip-origin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Purism SPC + * Copyright (C) 2021-2022 Purism SPC * * This file is part of Calls. * @@ -239,10 +239,11 @@ add_call (CallsSipOrigin *self, g_autofree gchar *local_sdp = NULL; g_auto (GStrv) address_split = NULL; const char *call_address = address; + gint rtp_port, rtcp_port; - /* TODO get free port by creating GSocket and passing that to the pipeline */ - guint local_port = get_port_for_rtp (); pipeline = calls_sip_media_manager_get_pipeline (self->media_manager); + rtp_port = calls_sip_media_pipeline_get_rtp_port (pipeline); + rtcp_port = calls_sip_media_pipeline_get_rtcp_port (pipeline); if (self->can_tel) { address_split = g_strsplit_set (address, ":@;", -1); @@ -271,11 +272,12 @@ add_call (CallsSipOrigin *self, self); if (!inbound) { - calls_sip_call_setup_local_media_connection (sip_call, local_port, local_port + 1); + calls_sip_call_setup_local_media_connection (sip_call); local_sdp = calls_sip_media_manager_static_capabilities (self->media_manager, self->own_ip, - local_port, + rtp_port, + rtcp_port, FALSE); g_assert (local_sdp); diff --git a/plugins/sip/calls-sip-util.c b/plugins/sip/calls-sip-util.c index d5ea2a3..a4349e2 100644 --- a/plugins/sip/calls-sip-util.c +++ b/plugins/sip/calls-sip-util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Purism SPC + * Copyright (C) 2021-2022 Purism SPC * * This file is part of Calls. * @@ -61,17 +61,3 @@ protocol_is_valid (const char *protocol) g_strcmp0 (protocol, "TCP") == 0 || g_strcmp0 (protocol, "TLS") == 0; } - -#define RTP_PORT_MIN 20000 -#define RTP_PORT_MAX 65534 -guint -get_port_for_rtp (void) -{ - const guint rand_range = RTP_PORT_MAX - RTP_PORT_MIN; - guint rand = (g_random_int () % rand_range) + RTP_PORT_MIN; - - /* RTP ports must be even */ - return rand % 2 == 0 ? rand : rand + 1; -} -#undef RTP_PORT_MIN -#undef RTP_PORT_MAX diff --git a/plugins/sip/calls-sip-util.h b/plugins/sip/calls-sip-util.h index a0ebb02..86b4709 100644 --- a/plugins/sip/calls-sip-util.h +++ b/plugins/sip/calls-sip-util.h @@ -62,4 +62,3 @@ gboolean check_sips (const char *addr); gboolean check_ipv6 (const char *host); const char *get_protocol_prefix (const char *protocol); gboolean protocol_is_valid (const char *protocol); -guint get_port_for_rtp (void); diff --git a/tests/test-media.c b/tests/test-media.c index 84793ff..c02f965 100644 --- a/tests/test-media.c +++ b/tests/test-media.c @@ -48,7 +48,7 @@ test_sip_media_manager_caps (void) /* PCMA RTP */ sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 40002, FALSE, codecs); + calls_sip_media_manager_get_capabilities (manager, NULL, 40002, 40003, FALSE, codecs); g_assert_true (sdp_message); g_assert_true (find_string_in_sdp_message (sdp_message, @@ -64,7 +64,7 @@ test_sip_media_manager_caps (void) /* PCMA SRTP */ sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 42002, TRUE, codecs); + calls_sip_media_manager_get_capabilities (manager, NULL, 42002, 42003, TRUE, codecs); g_assert_true (sdp_message); g_assert_true (find_string_in_sdp_message (sdp_message, "m=audio 42002 RTP/SAVP 8")); @@ -78,7 +78,7 @@ test_sip_media_manager_caps (void) codecs = g_list_append (NULL, media_codec_by_name ("G722")); sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 42042, FALSE, codecs); + calls_sip_media_manager_get_capabilities (manager, NULL, 42042, 55543, FALSE, codecs); g_assert_true (sdp_message); g_assert_true (find_string_in_sdp_message (sdp_message, @@ -86,7 +86,7 @@ test_sip_media_manager_caps (void) g_assert_true (find_string_in_sdp_message (sdp_message, "a=rtpmap:9 G722/8000")); g_assert_true (find_string_in_sdp_message (sdp_message, - "a=rtcp:42043")); + "a=rtcp:55543")); g_clear_pointer (&codecs, g_list_free); g_free (sdp_message); @@ -99,7 +99,7 @@ test_sip_media_manager_caps (void) codecs = g_list_append (codecs, media_codec_by_name ("PCMA")); sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 33340, FALSE, codecs); + calls_sip_media_manager_get_capabilities (manager, NULL, 33340, 33341, FALSE, codecs); g_assert_true (sdp_message); g_assert_true (find_string_in_sdp_message (sdp_message, @@ -123,7 +123,7 @@ test_sip_media_manager_caps (void) codecs = g_list_append (codecs, media_codec_by_name ("PCMU")); sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 18098, TRUE, codecs); + calls_sip_media_manager_get_capabilities (manager, NULL, 18098, 18099, TRUE, codecs); g_assert_true (sdp_message); g_assert_true (find_string_in_sdp_message (sdp_message, @@ -138,7 +138,7 @@ test_sip_media_manager_caps (void) g_test_expect_message ("CallsSipMediaManager", G_LOG_LEVEL_WARNING, "No supported codecs found. Can't build meaningful SDP message"); sdp_message = - calls_sip_media_manager_get_capabilities (manager, NULL, 25048, FALSE, NULL); + calls_sip_media_manager_get_capabilities (manager, NULL, 25048, 25049, FALSE, NULL); g_test_assert_expected_messages (); g_assert_true (sdp_message);