Browse Source

Change packet_index functions to more closely match RFC

This became necessary because of the way Asterisk handles Sequence
numbers when changing SSRC.  They continue to increment a single
sequence number even though the SSRC is different, on switching back
this causes the packet_index function to interpret this as many lost
packets.  The previous function had dead-spots that would not adjust
the packet_index at all if the difference fell in these ranges.  These
gaps always resulted in behavior contra what would happen in webrtc
clients.
pull/110/head
Kevin McAllister 11 years ago
committed by Marc Soda
parent
commit
965fa396d2
2 changed files with 38 additions and 36 deletions
  1. +16
    -18
      daemon/rtp.c
  2. +22
    -18
      kernel-module/xt_RTPENGINE.c

+ 16
- 18
daemon/rtp.c View File

@ -137,8 +137,6 @@ error:
static u_int64_t packet_index(struct crypto_context *c, struct rtp_header *rtp) {
u_int16_t seq;
u_int64_t index;
long long int diff;
seq = ntohs(rtp->seq_num);
/* rfc 3711 section 3.3.1 */
@ -146,24 +144,24 @@ static u_int64_t packet_index(struct crypto_context *c, struct rtp_header *rtp)
c->last_index = seq;
/* rfc 3711 appendix A, modified, and sections 3.3 and 3.3.1 */
index = (c->last_index & 0xffffffff0000ULL) | seq;
diff = index - c->last_index;
if (diff >= 0) {
if (diff < 0x8000)
c->last_index = index;
else if (index >= 0x10000)
index -= 0x10000;
}
else {
if (diff >= -0x8000)
;
else {
index += 0x10000;
c->last_index = index;
}
u_int16_t s_l = (c->last_index & 0x00000000ffffULL);
u_int32_t roc = (c->last_index & 0xffffffff0000ULL) >> 16;
u_int32_t v = 0;
if (s_l < 0x8000) {
if (((seq - s_l) > 0x8000) && roc > 0)
v = (roc - 1) % 0x10000;
else
v = roc;
} else {
if ((s_l - 0x8000) > seq)
v = (roc + 1) % 0x10000;
else
v = roc;
}
return index;
c->last_index = (u_int64_t)(((v << 16) | seq) & 0xffffffffffffULL);
return c->last_index;
}
void rtp_append_mki(str *s, struct crypto_context *c) {


+ 22
- 18
kernel-module/xt_RTPENGINE.c View File

@ -1889,8 +1889,10 @@ static u_int64_t packet_index(struct re_crypto_context *c,
{
u_int16_t seq;
u_int64_t index;
long long int diff;
unsigned long flags;
u_int16_t s_l;
u_int32_t roc;
u_int32_t v;
// Keep the crypt context SSRC in sync.
if (unlikely(!c->ssrc))
@ -1906,25 +1908,27 @@ static u_int64_t packet_index(struct re_crypto_context *c,
if (unlikely(!s->last_index))
s->last_index = seq;
/* rfc 3711 appendix A, modified, and sections 3.3 and 3.3.1 */
index = ((u_int64_t) c->roc << 16) | seq;
diff = index - s->last_index;
if (diff >= 0) {
if (diff < 0x8000)
s->last_index = index;
else if (index >= 0x10000)
index -= 0x10000;
}
else {
if (diff >= -0x8000)
;
else {
index += 0x10000;
c->roc++;
s->last_index = index;
}
/* rfc 3711 appendix A, modified, and sections 3.3 and 3.3.1 */
s_l = (s->last_index & 0x00000000ffffULL);
roc = (s->last_index & 0xffffffff0000ULL) >> 16;
v = 0;
if (s_l < 0x8000) {
if (((seq - s_l) > 0x8000) && roc > 0)
v = (roc - 1) % 0x10000;
else
v = roc;
} else {
if ((s_l - 0x8000) > seq)
v = (roc + 1) % 0x10000;
else
v = roc;
}
index = (v << 16) | seq;
s->last_index = index;
c->roc = v;
spin_unlock_irqrestore(&c->lock, flags);
return index;


Loading…
Cancel
Save