From dcff7538f2a912cd2782a652afdf2b4695b77a05 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Mon, 8 Mar 2021 09:54:08 +0100 Subject: [PATCH] sip: media: improve SDP offer/answer handling --- plugins/sip/calls-sip-media-manager.c | 11 ++++++++--- plugins/sip/gst-rfc3551.c | 16 ++++++++-------- plugins/sip/gst-rfc3551.h | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/plugins/sip/calls-sip-media-manager.c b/plugins/sip/calls-sip-media-manager.c index 04a4fa8..b3bef1b 100644 --- a/plugins/sip/calls-sip-media-manager.c +++ b/plugins/sip/calls-sip-media-manager.c @@ -99,15 +99,20 @@ calls_sip_media_manager_static_capabilities (CallsSipMediaManager *self, guint port, gboolean use_srtp) { - char *attribute_line = "rtpmap:0 PCMU/8000"; char *payload_type = use_srtp ? "SAVP" : "AVP"; g_autofree char *media_line = NULL; + g_autofree char *attribute_line = NULL; + MediaCodecInfo *codec; g_return_val_if_fail (CALLS_IS_SIP_MEDIA_MANAGER (self), NULL); - media_line = g_strdup_printf ("audio %d RTP/%s 0", port, payload_type); + codec = get_best_codec (self); + /* TODO support multiplice codecs: f.e. audio 31337 RTP/AVP 9 8 0 96 */ + media_line = g_strdup_printf ("audio %d RTP/%s %s", + port, payload_type, codec->payload_id); + attribute_line = g_strdup_printf ("rtpmap:%s %s/%s", + codec->payload_id, codec->name, codec->clock_rate); - /* TODO we can have multiple attribute lines (or media lines for that matter) */ /* TODO add attribute describing RTCP stream */ return g_strdup_printf ("v=0\r\n" "m=%s\r\n" diff --git a/plugins/sip/gst-rfc3551.c b/plugins/sip/gst-rfc3551.c index 4a9d886..786a857 100644 --- a/plugins/sip/gst-rfc3551.c +++ b/plugins/sip/gst-rfc3551.c @@ -28,11 +28,11 @@ /* TODO check available codecs during runtime */ static MediaCodecInfo gst_codecs[] = { - {0, "PCMU", 8000, 1, "rtppcmupay", "rtppcmudepay", "mulawenc", "mulawdec"}, - {3, "GSM", 8000, 1, "rtpgsmpay", "rtpgsmdepay", "gsmenc", "gsmdec"}, - {4, "G723", 8000, 1, "rtpg723pay", "rtpg723depay", "avenc_g723_1", "avdec_g723_1"}, // does not seem to work - {8, "PCMA", 8000, 1, "rtppcmapay", "rtppcmadepay", "alawenc", "alawdec"}, - {9, "G722", 8000, 1, "rtpg722pay", "rtpg722depay", "avenc_g722", "avdec_g722"}, + {"0", "PCMU", "8000", 1, "rtppcmupay", "rtppcmudepay", "mulawenc", "mulawdec"}, + {"3", "GSM", "8000", 1, "rtpgsmpay", "rtpgsmdepay", "gsmenc", "gsmdec"}, + {"4", "G723", "8000", 1, "rtpg723pay", "rtpg723depay", "avenc_g723_1", "avdec_g723_1"}, // does not seem to work + {"8", "PCMA", "8000", 1, "rtppcmapay", "rtppcmadepay", "alawenc", "alawdec"}, + {"9", "G722", "8000", 1, "rtpg722pay", "rtpg722depay", "avenc_g722", "avdec_g722"}, }; @@ -53,9 +53,9 @@ media_codec_by_name (const char *name) gchar * media_codec_get_gst_capabilities (MediaCodecInfo *codec) { - return g_strdup_printf ("application/x-rtp,media=(string)audio,clock-rate=(int)%d" - ",encoding-name=(string)%s,payload=(int)%d", + return g_strdup_printf ("application/x-rtp,media=(string)audio,clock-rate=(int)%s" + ",encoding-name=(string)%s,payload=(int)%s", codec->clock_rate, codec->name, - codec->payload_type); + codec->payload_id); } diff --git a/plugins/sip/gst-rfc3551.h b/plugins/sip/gst-rfc3551.h index 5ded2ee..bd1cf29 100644 --- a/plugins/sip/gst-rfc3551.h +++ b/plugins/sip/gst-rfc3551.h @@ -32,9 +32,9 @@ */ typedef struct { - gint payload_type; - gchar* name; - gint clock_rate; + char *payload_id; + char *name; + char *clock_rate; gint channels; char *gst_payloader_name; char *gst_depayloader_name;