TT#98901 avoid PT collisions with asymmetric codec setup

Change-Id: Icce014312cef57e9df6dbe4165a67bef617b84c7
pull/1130/head
Richard Fuchs 5 years ago
parent 2f5cd2fcee
commit a642a1e694

@ -512,12 +512,32 @@ static int __dtmf_payload_type(GHashTable *supplemental_sinks, struct rtp_payloa
return dtmf_payload_type;
}
static int __unused_pt_number(struct call_media *media, int num) {
static int __unused_pt_number(struct call_media *media, struct call_media *other_media,
struct rtp_payload_type *pt)
{
int num = pt ? pt->payload_type : -1;
struct rtp_payload_type *pt_match;
if (num < 0)
num = 96; // default first dynamic payload type number
while (1) {
if (!g_hash_table_lookup(media->codecs_recv, &num))
break; // OK
if ((pt_match = g_hash_table_lookup(media->codecs_recv, &num)))
goto next;
if ((pt_match = g_hash_table_lookup(media->codecs_send, &num)))
goto next;
if (other_media) {
if ((pt_match = g_hash_table_lookup(other_media->codecs_recv, &num)))
goto next;
if ((pt_match = g_hash_table_lookup(other_media->codecs_send, &num)))
goto next;
}
// OK
break;
next:
// is this actually the same?
if (pt && !rtp_payload_type_cmp_nf(pt, pt_match))
break;
num++;
if (num < 96) // if an RFC type was taken already
num = 96;
@ -587,7 +607,7 @@ static void __accept_transcode_codecs(struct call_media *receiver, struct call_m
// PT collision. We must renumber one of the entries. `pt` is taken
// from the send list, so the PT should remain the same. Renumber
// the existing entry.
int new_pt = __unused_pt_number(receiver, existing_pt->payload_type);
int new_pt = __unused_pt_number(receiver, sink, existing_pt);
if (new_pt < 0) {
ilog(LOG_WARN, "Ran out of RTP payload type numbers while accepting '"
STR_FORMAT "' due to '" STR_FORMAT "'",
@ -1163,7 +1183,10 @@ void codec_handlers_update(struct call_media *receiver, struct call_media *sink,
goto transcode;
}
// XXX check format parameters as well
// XXX needs more intelligent fmtp matching
if (rtp_payload_type_cmp_nf(pt, dest_pt))
goto transcode;
ilog(LOG_DEBUG, "Sink supports codec " STR_FORMAT, STR_FMT(&pt->encoding_with_params));
__make_passthrough_gsl(handler, &passthrough_handlers);
if (pt->codec_def && pt->codec_def->dtmf)
@ -2486,7 +2509,9 @@ err:
}
static struct rtp_payload_type *codec_add_payload_type(const str *codec, struct call_media *media) {
static struct rtp_payload_type *codec_add_payload_type(const str *codec, struct call_media *media,
struct call_media *other_media)
{
struct rtp_payload_type *pt = codec_make_payload_type_sup(codec, media);
if (!pt) {
ilog(LOG_WARN, "Codec '" STR_FORMAT "' requested for transcoding is not supported",
@ -2496,7 +2521,7 @@ static struct rtp_payload_type *codec_add_payload_type(const str *codec, struct
if (pt == (void *) 0x1)
return NULL;
pt->payload_type = __unused_pt_number(media, pt->payload_type);
pt->payload_type = __unused_pt_number(media, other_media, pt);
if (pt->payload_type < 0) {
ilog(LOG_WARN, "Ran out of RTP payload type numbers while adding codec '"
STR_FORMAT "' for transcoding",
@ -2789,7 +2814,7 @@ void codec_tracker_finish(struct call_media *media) {
str pt_str;
str_init(&pt_str, pt_s);
struct rtp_payload_type *pt = codec_add_payload_type(&pt_str, media);
struct rtp_payload_type *pt = codec_add_payload_type(&pt_str, media, NULL);
if (!pt)
continue;
pt->for_transcoding = 1;
@ -2971,7 +2996,7 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
}
// create new payload type
pt = codec_add_payload_type(codec, media);
pt = codec_add_payload_type(codec, media, other_media);
if (!pt)
continue;
pt->for_transcoding = 1;
@ -3003,10 +3028,10 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
// XXX can we improve the codec lookup/synthesis?
static const str PCMU_str = STR_CONST_INIT("PCMU");
static const str PCMA_str = STR_CONST_INIT("PCMA");
pt = codec_add_payload_type(&PCMU_str, media);
pt = codec_add_payload_type(&PCMU_str, media, NULL);
assert(pt != NULL);
__rtp_payload_type_add_recv(media, pt, 1);
pt = codec_add_payload_type(&PCMA_str, media);
pt = codec_add_payload_type(&PCMA_str, media, NULL);
assert(pt != NULL);
__rtp_payload_type_add_recv(media, pt, 1);

@ -198,6 +198,52 @@ exit;
new_call;
offer('dup codec number', {
codec => {
mask => ['all'],
transcode => ['G722', 'opus/48000/1//test=1', 'speex', 'PCMA', 'telephone-event'],
}
}, <<SDP);
v=0
o=- 3816337545 3816337545 IN IP4 ims.imscore.net
s=-
c=IN IP4 139.156.119.237
t=0 0
m=audio 44964 RTP/AVP 111 108 8 101 96
a=ptime:20
a=rtpmap:111 opus/48000
a=rtpmap:108 speex/16000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/48000
a=rtpmap:96 telephone-event/8000
a=fmtp:96 0-15
a=fmtp:101 0-15
----------------------------------
v=0
o=- 3816337545 3816337545 IN IP4 ims.imscore.net
s=-
c=IN IP4 203.0.113.1
t=0 0
m=audio PORT RTP/AVP 9 97 108 8 101 96 98
a=rtpmap:9 G722/8000
a=rtpmap:97 opus/48000
a=rtpmap:108 speex/16000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/48000
a=rtpmap:96 telephone-event/8000
a=rtpmap:98 telephone-event/16000
a=fmtp:101 0-15
a=fmtp:96 0-15
a=fmtp:98 0-15
a=sendrecv
a=rtcp:PORT
a=ptime:20
SDP
if (0) {
# GH 1098
@ -1668,9 +1714,9 @@ o=- 3815883745 3815883745 IN IP4 ims.imscore.net
s=-
c=IN IP4 203.0.113.1
t=0 0
m=audio PORT RTP/AVP 9 96 8 101 96
m=audio PORT RTP/AVP 9 97 8 101 96
a=rtpmap:9 G722/8000
a=rtpmap:96 opus/48000
a=rtpmap:97 opus/48000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/48000
a=rtpmap:96 telephone-event/8000
@ -2057,8 +2103,8 @@ o=Z 58440449 0 IN IP4 89.225.243.254
s=Z
c=IN IP4 203.0.113.1
t=0 0
m=audio PORT RTP/AVP 96 8 102 101
a=rtpmap:96 opus/48000
m=audio PORT RTP/AVP 97 8 102 101
a=rtpmap:97 opus/48000
a=rtpmap:8 PCMA/8000
a=rtpmap:102 telephone-event/48000
a=rtpmap:101 telephone-event/8000
@ -4367,10 +4413,10 @@ o=- 1822058533 1822058533 IN IP4 1.2.3.4
s=Asterisk
c=IN IP4 203.0.113.1
t=0 0
m=audio PORT RTP/AVP 8 96
m=audio PORT RTP/AVP 8 97
a=rtpmap:8 PCMA/8000
a=rtpmap:96 telephone-event/8000
a=fmtp:96 0-15
a=rtpmap:97 telephone-event/8000
a=fmtp:97 0-15
a=sendrecv
a=rtcp:PORT
SDP
@ -4380,11 +4426,11 @@ v=0
o=- 3793596600 3793596601 IN IP4 172.17.0.2
s=pjmedia
t=0 0
m=audio 40935 RTP/AVP 8 96
m=audio 40935 RTP/AVP 8 97
c=IN IP4 172.17.0.2
a=rtpmap:8 PCMA/8000
a=rtpmap:96 telephone-event/8000
a=fmtp:96 0-15
a=rtpmap:97 telephone-event/8000
a=fmtp:97 0-15
----------------------------------
v=0
o=- 3793596600 3793596601 IN IP4 172.17.0.2

Loading…
Cancel
Save