Merge pull request #1442 from dragos-oancea/jb-fix
[core] Fix jitter buffer- it is not truncating frames properly. It's also overflowing the node packet body and is copying the packet body twice.
This commit is contained in:
commit
d1372cd6e5
|
@ -41,9 +41,11 @@
|
||||||
|
|
||||||
SWITCH_BEGIN_EXTERN_C
|
SWITCH_BEGIN_EXTERN_C
|
||||||
|
|
||||||
|
#define SWITCH_RTP_HEADER_LEN sizeof(switch_rtp_hdr_t)
|
||||||
#define SWITCH_RTP_MAX_BUF_LEN 16384
|
#define SWITCH_RTP_MAX_BUF_LEN 16384
|
||||||
#define SWITCH_RTCP_MAX_BUF_LEN 16384
|
#define SWITCH_RTCP_MAX_BUF_LEN 16384
|
||||||
#define SWITCH_RTP_MAX_BUF_LEN_WORDS 4094 /* (max / 4) - 2 */
|
#define SWITCH_RTP_MAX_BUF_LEN_WORDS 4094 /* (max / 4) - 2 */
|
||||||
|
#define SWITCH_RTP_MAX_PACKET_LEN (SWITCH_RTP_MAX_BUF_LEN + SWITCH_RTP_HEADER_LEN)
|
||||||
//#define SWITCH_RTP_KEY_LEN 30
|
//#define SWITCH_RTP_KEY_LEN 30
|
||||||
//#define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32"
|
//#define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32"
|
||||||
#define SWITCH_RTP_CRYPTO_KEY_80 "AES_CM_128_HMAC_SHA1_80"
|
#define SWITCH_RTP_CRYPTO_KEY_80 "AES_CM_128_HMAC_SHA1_80"
|
||||||
|
|
|
@ -640,7 +640,6 @@ static inline void add_node(switch_jb_t *jb, switch_rtp_packet_t *packet, switch
|
||||||
|
|
||||||
node->packet = *packet;
|
node->packet = *packet;
|
||||||
node->len = len;
|
node->len = len;
|
||||||
memcpy(node->packet.body, packet->body, len);
|
|
||||||
|
|
||||||
switch_core_inthash_insert(jb->node_hash, node->packet.header.seq, node);
|
switch_core_inthash_insert(jb->node_hash, node->packet.header.seq, node);
|
||||||
|
|
||||||
|
@ -1006,10 +1005,10 @@ SWITCH_DECLARE(switch_status_t) switch_jb_peek_frame(switch_jb_t *jb, uint32_t t
|
||||||
frame->seq = ntohs(node->packet.header.seq);
|
frame->seq = ntohs(node->packet.header.seq);
|
||||||
frame->timestamp = ntohl(node->packet.header.ts);
|
frame->timestamp = ntohl(node->packet.header.ts);
|
||||||
frame->m = node->packet.header.m;
|
frame->m = node->packet.header.m;
|
||||||
frame->datalen = node->len - 12;
|
frame->datalen = node->len - SWITCH_RTP_HEADER_LEN;
|
||||||
|
|
||||||
if (frame->data && frame->buflen > node->len - 12) {
|
if (frame->data && frame->buflen > node->len - SWITCH_RTP_HEADER_LEN) {
|
||||||
memcpy(frame->data, node->packet.body, node->len - 12);
|
memcpy(frame->data, node->packet.body, node->len - SWITCH_RTP_HEADER_LEN);
|
||||||
}
|
}
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1221,9 +1220,9 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint16_t want = ntohs(jb->next_seq), got = ntohs(packet->header.seq);
|
uint16_t want = ntohs(jb->next_seq), got = ntohs(packet->header.seq);
|
||||||
|
|
||||||
if (len >= sizeof(switch_rtp_packet_t)) {
|
if (len >= SWITCH_RTP_MAX_PACKET_LEN) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "trying to put %" SWITCH_SIZE_T_FMT " bytes exceeding buffer, truncate to %" SWITCH_SIZE_T_FMT "\n", len, sizeof(switch_rtp_packet_t));
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "trying to put %" SWITCH_SIZE_T_FMT " bytes exceeding buffer, truncate to %" SWITCH_SIZE_T_FMT "\n", len, SWITCH_RTP_MAX_PACKET_LEN);
|
||||||
len = sizeof(switch_rtp_packet_t);
|
len = SWITCH_RTP_MAX_PACKET_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_mutex_lock(jb->mutex);
|
switch_mutex_lock(jb->mutex);
|
||||||
|
@ -1279,7 +1278,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
add_node(jb, packet, len);
|
add_node(jb, packet, len);
|
||||||
|
|
||||||
if (switch_test_flag(jb, SJB_QUEUE_ONLY) && jb->max_packet_len && jb->max_frame_len * 2 > jb->max_packet_len &&
|
if (switch_test_flag(jb, SJB_QUEUE_ONLY) && jb->max_packet_len && jb->max_frame_len * 2 > jb->max_packet_len &&
|
||||||
|
@ -1307,7 +1305,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet_by_seq(switch_jb_t *jb, uin
|
||||||
jb_debug(jb, 2, "Found buffered seq: %u\n", ntohs(seq));
|
jb_debug(jb, 2, "Found buffered seq: %u\n", ntohs(seq));
|
||||||
*packet = node->packet;
|
*packet = node->packet;
|
||||||
*len = node->len;
|
*len = node->len;
|
||||||
memcpy(packet->body, node->packet.body, node->len);
|
|
||||||
packet->header.version = 2;
|
packet->header.version = 2;
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1461,7 +1458,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp
|
||||||
*packet = node->packet;
|
*packet = node->packet;
|
||||||
*len = node->len;
|
*len = node->len;
|
||||||
jb->last_len = *len;
|
jb->last_len = *len;
|
||||||
memcpy(packet->body, node->packet.body, node->len);
|
|
||||||
packet->header.version = 2;
|
packet->header.version = 2;
|
||||||
hide_node(node, SWITCH_TRUE);
|
hide_node(node, SWITCH_TRUE);
|
||||||
|
|
||||||
|
@ -1505,7 +1501,6 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* For Emacs:
|
/* For Emacs:
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* mode:c
|
* mode:c
|
||||||
|
|
Loading…
Reference in New Issue