Browse Source

TT#59100 support case insensitive codec names

closes #775

Change-Id: Id54309bf0920e731ad42fb09b078580090f6f82e
changes/89/29989/1
Richard Fuchs 7 years ago
parent
commit
db507468de
6 changed files with 194 additions and 4 deletions
  1. +2
    -2
      daemon/call.c
  2. +1
    -1
      daemon/codec.c
  3. +1
    -1
      lib/codeclib.c
  4. +18
    -0
      lib/str.c
  5. +17
    -0
      lib/str.h
  6. +155
    -0
      t/auto-daemon-tests.pl

+ 2
- 2
daemon/call.c View File

@ -689,8 +689,8 @@ struct call_media *call_media_new(struct call *call) {
med->call = call;
med->codecs_recv = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
med->codecs_send = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL);
med->codec_names_recv = g_hash_table_new_full(str_hash, str_equal, NULL, (void (*)(void*)) g_queue_free);
med->codec_names_send = g_hash_table_new_full(str_hash, str_equal, NULL, (void (*)(void*)) g_queue_free);
med->codec_names_recv = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, (void (*)(void*)) g_queue_free);
med->codec_names_send = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, (void (*)(void*)) g_queue_free);
return med;
}


+ 1
- 1
daemon/codec.c View File

@ -1343,7 +1343,7 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_
struct call *call = media->call;
struct rtp_payload_type *pt;
static const str str_all = STR_CONST_INIT("all");
GHashTable *removed = g_hash_table_new_full(str_hash, str_equal, NULL, __payload_queue_free);
GHashTable *removed = g_hash_table_new_full(str_case_hash, str_case_equal, NULL, __payload_queue_free);
int strip_all = 0, mask_all = 0;
// start fresh


+ 1
- 1
lib/codeclib.c View File

@ -725,7 +725,7 @@ void codeclib_init(int print) {
avformat_network_init();
av_log_set_callback(avlog_ilog);
codecs_ht = g_hash_table_new(str_hash, str_equal);
codecs_ht = g_hash_table_new(str_case_hash, str_case_equal);
codecs_ht_by_av = g_hash_table_new(g_direct_hash, g_direct_equal);
for (int i = 0; i < G_N_ELEMENTS(__codec_defs); i++) {


+ 18
- 0
lib/str.c View File

@ -22,6 +22,24 @@ gboolean str_equal(gconstpointer a, gconstpointer b) {
return str_cmp_str((str *) a, (str *) b) == 0;
}
guint str_case_hash(gconstpointer ss) {
const str *s = ss;
guint ret = 5381;
str it = *s;
while (it.len > 0) {
ret = (ret << 5) + ret + (*it.s & 0xdf);
it.s++;
it.len--;
}
return ret;
}
gboolean str_case_equal(gconstpointer a, gconstpointer b) {
return str_casecmp_str((str *) a, (str *) b) == 0;
}
str *__str_sprintf(const char *fmt, ...) {
str *ret;
va_list ap;


+ 17
- 0
lib/str.h View File

@ -51,6 +51,7 @@ INLINE int str_cmp(const str *a, const char *b);
INLINE int str_cmp_len(const str *a, const char *b, int len);
/* compares two str objects */
INLINE int str_cmp_str(const str *a, const str *b);
INLINE int str_casecmp_str(const str *a, const str *b);
/* compares two str objects, allows either to be NULL */
INLINE int str_cmp_str0(const str *a, const str *b);
/* inits a str object from a regular string. returns out */
@ -100,6 +101,8 @@ INLINE str *g_string_free_str(GString *gs);
/* for GHashTables */
guint str_hash(gconstpointer s);
gboolean str_equal(gconstpointer a, gconstpointer b);
guint str_case_hash(gconstpointer s);
gboolean str_case_equal(gconstpointer a, gconstpointer b);
/* returns a new str object, duplicates the pointers but doesn't duplicate the contents */
INLINE str *str_slice_dup(const str *);
@ -182,6 +185,20 @@ INLINE int str_cmp_str(const str *a, const str *b) {
return 0;
return memcmp(a->s, b->s, a->len);
}
INLINE int str_casecmp_str(const str *a, const str *b) {
if (a->len < b->len)
return -1;
if (a->len > b->len)
return 1;
if (a->len == 0 && b->len == 0)
return 0;
// fail if any strings contains a null byte
if (memchr(a->s, '\0', a->len))
return -1;
if (memchr(b->s, '\0', a->len))
return 1;
return strncasecmp(a->s, b->s, a->len);
}
INLINE int str_cmp_str0(const str *a, const str *b) {
if (!a) {
if (!b)


+ 155
- 0
t/auto-daemon-tests.pl View File

@ -1387,6 +1387,161 @@ rcv($sock_a, $port_b, rtpm(0, 2014, 4000+160*14, $ssrc, "\x00" x 160));
($sock_a, $sock_b) = new_call([qw(198.51.100.1 2210)], [qw(198.51.100.3 2212)]);
($port_a) = offer('one codec with one for transcoding, lower case', { ICE => 'remove', replace => ['origin'],
codec => { transcode => ['PCMA'] }}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2210 RTP/AVP 0
c=IN IP4 198.51.100.1
a=rtpmap:0 pcmu/8000
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 203.0.113.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
a=rtpmap:0 pcmu/8000
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
SDP
($port_b) = answer('one codec with one for transcoding, lower case', { replace => ['origin'] }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.3
s=tester
t=0 0
m=audio 2212 RTP/AVP 0 8
c=IN IP4 198.51.100.3
a=rtpmap:0 pcmu/8000
a=rtpmap:8 pcma/8000
a=sendrecv
--------------------------------------
v=0
o=- 1545997027 1 IN IP4 203.0.113.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
a=rtpmap:0 pcmu/8000
a=sendrecv
a=rtcp:PORT
SDP
snd($sock_a, $port_b, rtp(0, 1000, 3000, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1000, 3000, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1001, 3160, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1001, 3160, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1010, 4600, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1010, 4600, 0x1234, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2000, 4000, 0x5678, "\x00" x 160));
($ssrc) = rcv($sock_a, $port_b, rtpm(0, 2000, 4000, -1, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2000, 4000, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2000, 4000, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2001, 4000+160, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2001, 4000+160, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2010, 4000+1600, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2010, 4000+1600, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(8, 2011, 4000+160*11, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2011, 4000+160*11, $ssrc, ")" x 160));
# #664 seq reset
snd($sock_b, $port_a, rtp(8, 62011, 4000+160*12, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2012, 4000+160*12, $ssrc, ")" x 160));
snd($sock_b, $port_a, rtp(8, 62012, 4000+160*13, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2013, 4000+160*13, $ssrc, ")" x 160));
snd($sock_b, $port_a, rtp(0, 62013, 4000+160*14, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2014, 4000+160*14, $ssrc, "\x00" x 160));
($sock_a, $sock_b) = new_call([qw(198.51.100.1 2216)], [qw(198.51.100.3 2218)]);
($port_a) = offer('one codec with one for transcoding, lower case 2', { ICE => 'remove', replace => ['origin'],
codec => { transcode => ['pcma'] }}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2216 RTP/AVP 0
c=IN IP4 198.51.100.1
a=rtpmap:0 pcmu/8000
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 203.0.113.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 203.0.113.1
a=rtpmap:0 pcmu/8000
a=rtpmap:8 pcma/8000
a=sendrecv
a=rtcp:PORT
SDP
($port_b) = answer('one codec with one for transcoding, lower case 2', { replace => ['origin'] }, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.3
s=tester
t=0 0
m=audio 2218 RTP/AVP 0 8
c=IN IP4 198.51.100.3
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=sendrecv
--------------------------------------
v=0
o=- 1545997027 1 IN IP4 203.0.113.1
s=tester
t=0 0
m=audio PORT RTP/AVP 0
c=IN IP4 203.0.113.1
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtcp:PORT
SDP
snd($sock_a, $port_b, rtp(0, 1000, 3000, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1000, 3000, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1001, 3160, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1001, 3160, 0x1234, "\x00" x 160));
snd($sock_a, $port_b, rtp(0, 1010, 4600, 0x1234, "\x00" x 160));
rcv($sock_b, $port_a, rtpm(0, 1010, 4600, 0x1234, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2000, 4000, 0x5678, "\x00" x 160));
($ssrc) = rcv($sock_a, $port_b, rtpm(0, 2000, 4000, -1, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2000, 4000, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2000, 4000, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2001, 4000+160, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2001, 4000+160, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(0, 2010, 4000+1600, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2010, 4000+1600, $ssrc, "\x00" x 160));
snd($sock_b, $port_a, rtp(8, 2011, 4000+160*11, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2011, 4000+160*11, $ssrc, ")" x 160));
# #664 seq reset
snd($sock_b, $port_a, rtp(8, 62011, 4000+160*12, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2012, 4000+160*12, $ssrc, ")" x 160));
snd($sock_b, $port_a, rtp(8, 62012, 4000+160*13, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2013, 4000+160*13, $ssrc, ")" x 160));
snd($sock_b, $port_a, rtp(0, 62013, 4000+160*14, 0x5678, "\x00" x 160));
rcv($sock_a, $port_b, rtpm(0, 2014, 4000+160*14, $ssrc, "\x00" x 160));
# media playback


Loading…
Cancel
Save