[calls] sip: sdp: Honour per media connections



commit 929d76708a85fd4b6f90adf08c448c519af6f717
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Thu Sep 16 13:58:13 2021 +0200

    sip: sdp: Honour per media connections
    
    Otherwise we might miss the IP of the remote peer leaving us unable to
    establish a connection for RTP.
    
    From https://datatracker.ietf.org/doc/html/rfc4566#section-5.7
    
       A session description MUST contain either at least one "c=" field in
       each media description or a single "c=" field at the session level.
       It MAY contain a single session-level "c=" field and additional "c="
       field(s) per media description, in which case the per-media values
       override the session-level settings for the respective media.

 plugins/sip/calls-sip-origin.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 0ebd5585..2a04b0bd 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -513,25 +513,31 @@ sip_i_state (int              status,
     CALLS_EMIT_MESSAGE (origin, "DNS error", GTK_MESSAGE_ERROR);
   }
   /* XXX making some assumptions about the received SDP message here...
-   * namely: that there is only the session wide connection c= line
-   * and no individual connections per media stream.
-   * also: rtcp port = rtp port + 1
+   * namely: rtcp port = rtp port + 1
    */
   if (r_sdp) {
     g_autoptr (GList) codecs =
       calls_sip_media_manager_get_codecs_from_sdp (origin->media_manager,
                                                    r_sdp->sdp_media);
-    const char *remote_ip = NULL;
-    if (r_sdp->sdp_connection && r_sdp->sdp_connection->c_address) {
-      remote_ip = r_sdp->sdp_connection->c_address;
-    } else {
+    const char *session_ip = NULL;
+    const char *media_ip = NULL;
+
+    if (r_sdp->sdp_connection && r_sdp->sdp_connection->c_address)
+      session_ip = r_sdp->sdp_connection->c_address;
+
+    if (r_sdp->sdp_media && r_sdp->sdp_media->m_connections &&
+        r_sdp->sdp_media->m_connections->c_address)
+      media_ip = r_sdp->sdp_media->m_connections->c_address;
+
+    if (!session_ip && !media_ip) {
       g_warning ("Could not determine IP of remote peer. Hanging up");
       calls_call_hang_up (CALLS_CALL (call));
       return;
     }
+
     calls_sip_call_set_codecs (call, codecs);
     calls_sip_call_setup_remote_media_connection (call,
-                                                  remote_ip,
+                                                  media_ip ? : session_ip,
                                                   r_sdp->sdp_media->m_port,
                                                   r_sdp->sdp_media->m_port + 1);
   }


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