From 21677a39e6690c6b8a60acc674b6c79a3bf8c51f Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Tue, 13 Aug 2024 14:26:13 +0200 Subject: [PATCH] MT#60688 Add support of maxptime for media Same as ptime but for the maxptime. Also add replication of it. This is required later to be used for the sdp_create() handling. Additionally: fix tests, because maxptime now takes another place within the media session, which doesn't affect functionality. Change-Id: I058e35323849679976c60b2e9fb2555fd0168e67 --- daemon/call.c | 3 +++ daemon/redis.c | 4 ++++ daemon/sdp.c | 12 ++++++++++++ include/call.h | 3 ++- t/auto-daemon-tests.pl | 40 +++++++++++++++++++++------------------- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index afc8ba103..e2a319c12 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2842,6 +2842,9 @@ static void __media_init_from_flags(struct call_media *other_media, struct call_ if (!MEDIA_ISSET(other_media, PTIME_OVERRIDE)) other_media->ptime = sp->ptime; } + if (sp->maxptime > 0) { + media->maxptime = sp->maxptime; + } if (media && flags->ptime > 0) { media->ptime = flags->ptime; MEDIA_SET(media, PTIME_OVERRIDE); diff --git a/daemon/redis.c b/daemon/redis.c index 63c6c3d42..0c9ba97e4 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1619,6 +1619,9 @@ static int json_medias(call_t *c, struct redis_list *medias, struct redis_list * if (!redis_hash_get_str(&s, rh, "media_id")) call_str_cpy(c, &med->media_id, &s); + if (redis_hash_get_int(&med->maxptime, rh, "maxptime")) + return -1; + if (redis_hash_get_str(&s, rh, "protocol")) return -1; med->protocol = transport_protocol(&s); @@ -2686,6 +2689,7 @@ char* redis_encode_json(call_t *c) { JSON_SET_SIMPLE_CSTR("desired_family", media->desired_family ? media->desired_family->rfc_name : ""); JSON_SET_SIMPLE_STR("logical_intf", &media->logical_intf->name); JSON_SET_SIMPLE("ptime","%i", media->ptime); + JSON_SET_SIMPLE("maxptime","%i", media->maxptime); JSON_SET_SIMPLE("media_flags", "%" PRIu64, atomic64_get_na(&media->media_flags)); if (media->bandwidth_as >= 0) diff --git a/daemon/sdp.c b/daemon/sdp.c index ef654e1ae..ef0f3edbe 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1892,6 +1892,11 @@ int sdp_streams(const sdp_sessions_q *sessions, sdp_streams_q *streams, sdp_ng_f if (attr && attr->strs.value.s) sp->ptime = str_to_i(&attr->strs.value, 0); + // a=maxptime + attr = attr_get_by_id(&media->attributes, ATTR_MAXPTIME); + if (attr && attr->strs.value.s) + sp->maxptime = str_to_i(&attr->strs.value, 0); + sp->format_str = media->formats; errstr = "Invalid RTP payload types"; if (__rtp_payload_types(sp, media)) @@ -2567,6 +2572,10 @@ static int process_media_attributes(struct sdp_chopper *chop, struct sdp_media * if (media->ptime) goto strip; break; + case ATTR_MAXPTIME: + if (media->maxptime) + goto strip; + break; case ATTR_RTCP_FB: if (attr->rtcp_fb.payload_type == -1) break; // leave this one alone @@ -3188,6 +3197,9 @@ static struct packet_stream *print_sdp_media_section(GString *s, struct call_med if (media->ptime) append_attr_int_to_gstring(s, "ptime", media->ptime, flags, media->type_id); + if (media->maxptime) + append_attr_int_to_gstring(s, "maxptime", media->maxptime, flags, + media->type_id); } if (MEDIA_ISSET(media, ICE) && media->ice_agent) { diff --git a/include/call.h b/include/call.h index cff90de58..9090e6425 100644 --- a/include/call.h +++ b/include/call.h @@ -352,7 +352,7 @@ struct stream_params { candidate_q ice_candidates; /* slice-alloc'd */ str ice_ufrag; str ice_pwd; - int ptime; + int ptime, maxptime; str media_id; struct t38_options t38_options; str tls_id; @@ -523,6 +523,7 @@ struct call_media { #endif int ptime; /* either from SDP or overridden */ + int maxptime; /* from SDP */ atomic64 media_flags; }; diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl index 840ce12b7..6694176e4 100755 --- a/t/auto-daemon-tests.pl +++ b/t/auto-daemon-tests.pl @@ -386,12 +386,12 @@ t=0 0 m=audio PORT RTP/AVP 8 96 b=RS:0 b=RR:0 -a=maxptime:40 a=rtpmap:8 PCMA/8000 a=rtpmap:96 telephone-event/8000 a=fmtp:96 0-15 a=sendrecv a=rtcp:PORT +a=maxptime:40 SDP answer('t-e fmtp', { flags => [qw(codec-strip-all codec-transcode-PCMA codec-transcode-telephone-event)], @@ -1690,7 +1690,6 @@ m=audio PORT RTP/AVP 96 97 8 98 b=AS:80 b=RS:362 b=RR:1087 -a=maxptime:40 a=rtpmap:96 AMR/8000 a=fmtp:96 mode-set=0,2,4,7;mode-change-period=2;mode-change-neighbor=1;mode-change-capability=2;max-red=0 a=rtpmap:97 AMR/8000 @@ -1702,6 +1701,7 @@ a=msi:mavodi-0-15b-6c6-2-ffffffff-d3c00000-6005c95738e64-171f-ffffffffffffffff-. a=sendrecv a=rtcp:PORT a=ptime:20 +a=maxptime:40 SDP answer('AMR asymmetric, control', {}, < ['allow asymmetric codecs']}, < [qw/SIPREC all/]}, < 'remove', }, < 'remove', flags => ['symmetric codecs'] }, < 'remove', }, < 'remove', flags => ['symmetric codecs'] }, < 'remove', }, < 'remove', flags => ['symmetric codecs'] }, <