From 96f1cc0a309afac124d40dbbf71bfa50a91f4584 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Fri, 6 May 2022 00:55:39 +0200 Subject: [PATCH] sip: call: Defer setting up codecs for pipeline until activated This let's us get rid of some ugly code --- plugins/sip/calls-sip-call.c | 60 +++++++++------------------------- plugins/sip/calls-sip-call.h | 1 - plugins/sip/calls-sip-origin.c | 2 -- 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/plugins/sip/calls-sip-call.c b/plugins/sip/calls-sip-call.c index 1b616f7..3a6d685 100644 --- a/plugins/sip/calls-sip-call.c +++ b/plugins/sip/calls-sip-call.c @@ -78,35 +78,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsSipCall, calls_sip_call, CALLS_TYPE_CALL, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, calls_sip_call_message_source_interface_init)) -static gboolean -try_setting_up_media_pipeline (CallsSipCall *self) -{ - g_assert (CALLS_SIP_CALL (self)); - - if (!self->codecs) - return FALSE; - - if (calls_sip_media_pipeline_get_state (self->pipeline) == - CALLS_MEDIA_PIPELINE_STATE_NEED_CODEC) { - MediaCodecInfo *codec = (MediaCodecInfo *) self->codecs->data; - - g_debug ("Setting codec '%s' for pipeline", codec->name); - calls_sip_media_pipeline_set_codec (self->pipeline, codec); - } - - g_debug ("Setting remote ports: RTP/RTCP %u/%u", - self->rport_rtp, self->rport_rtcp); - - g_object_set (self->pipeline, - "remote", self->remote, - "rport-rtp", self->rport_rtp, - "rport-rtcp", self->rport_rtcp, - NULL); - - return TRUE; -} - - static void calls_sip_call_answer (CallsCall *call) { @@ -129,8 +100,6 @@ calls_sip_call_answer (CallsCall *call) 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, rtp_port, @@ -302,18 +271,6 @@ calls_sip_call_init (CallsSipCall *self) self->manager = calls_sip_media_manager_default (); } -/** - * calls_sip_call_setup_local_media_connection: - * @self: A #CallsSipCall - */ -void -calls_sip_call_setup_local_media_connection (CallsSipCall *self) -{ - g_return_if_fail (CALLS_IS_SIP_CALL (self)); - - /* XXX maybe we can get rid of this completely */ - try_setting_up_media_pipeline (self); -} /** * calls_sip_call_setup_remote_media_connection: @@ -335,7 +292,14 @@ calls_sip_call_setup_remote_media_connection (CallsSipCall *self, self->rport_rtp = port_rtp; self->rport_rtcp = port_rtcp; - try_setting_up_media_pipeline (self); + g_debug ("Setting remote ports: RTP/RTCP %u/%u", + self->rport_rtp, self->rport_rtcp); + + g_object_set (self->pipeline, + "remote", self->remote, + "rport-rtp", self->rport_rtp, + "rport-rtcp", self->rport_rtcp, + NULL); } /** @@ -357,6 +321,14 @@ calls_sip_call_activate_media (CallsSipCall *self, g_return_if_fail (CALLS_IS_SIP_MEDIA_PIPELINE (self->pipeline)); if (enabled) { + if (calls_sip_media_pipeline_get_state (self->pipeline) == + CALLS_MEDIA_PIPELINE_STATE_NEED_CODEC) { + MediaCodecInfo *codec = (MediaCodecInfo *) self->codecs->data; + + g_debug ("Setting codec '%s' for pipeline", codec->name); + calls_sip_media_pipeline_set_codec (self->pipeline, codec); + } + calls_sip_media_pipeline_start (self->pipeline); } else { calls_sip_media_pipeline_stop (self->pipeline); diff --git a/plugins/sip/calls-sip-call.h b/plugins/sip/calls-sip-call.h index b62e531..5c9c189 100644 --- a/plugins/sip/calls-sip-call.h +++ b/plugins/sip/calls-sip-call.h @@ -45,7 +45,6 @@ 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); 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-origin.c b/plugins/sip/calls-sip-origin.c index 4f29291..750cc4f 100644 --- a/plugins/sip/calls-sip-origin.c +++ b/plugins/sip/calls-sip-origin.c @@ -272,8 +272,6 @@ add_call (CallsSipOrigin *self, self); if (!inbound) { - calls_sip_call_setup_local_media_connection (sip_call); - local_sdp = calls_sip_media_manager_static_capabilities (self->media_manager, self->own_ip, rtp_port,