SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session,
uint32_t queue_frames,
uint32_t max_queue_frames,
- uint32_t samples_per_packet, uint32_t samples_per_second);
+ uint32_t samples_per_packet, uint32_t samples_per_second, uint32_t max_drift);
SWITCH_DECLARE(switch_status_t) switch_rtp_debug_jitter_buffer(switch_rtp_t *rtp_session, const char *name);
case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER:
{
if (switch_rtp_ready(tech_pvt->rtp_session)) {
- int len, maxlen = 0, qlen = 0, maxqlen = 50;
+ int len, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
if (msg->string_arg) {
- char *p;
+ char *p, *q;
const char *s;
if (!strcasecmp(msg->string_arg, "pause")) {
if ((p = strchr(msg->string_arg, ':'))) {
p++;
maxlen = atol(p);
+ if ((q = strchr(p, ':'))) {
+ q++;
+ max_drift = abs(atol(q));
+ }
}
}
if (qlen) {
if (switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen, maxqlen,
tech_pvt->read_impl.samples_per_packet,
- tech_pvt->read_impl.samples_per_second) == SWITCH_STATUS_SUCCESS) {
+ tech_pvt->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session),
- SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames)\n", len, qlen, maxqlen);
+ SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames) (%d max drift)\n",
+ len, qlen, maxqlen, max_drift);
switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session),
if ((val = switch_channel_get_variable(tech_pvt->channel, "jitterbuffer_msec")) || (val = tech_pvt->profile->jb_msec)) {
int jb_msec = atoi(val);
- int maxlen = 0;
- char *p;
-
+ int maxlen = 0, max_drift = 0;
+ char *p, *q;
+
if ((p = strchr(val, ':'))) {
p++;
maxlen = atoi(p);
+ if ((q = strchr(p, ':'))) {
+ q++;
+ max_drift = abs(atoi(q));
+ }
}
if (jb_msec < 20 || jb_msec > 10000) {
if (switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen, maxqlen,
tech_pvt->read_impl.samples_per_packet,
- tech_pvt->read_impl.samples_per_second) == SWITCH_STATUS_SUCCESS) {
+ tech_pvt->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session),
SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER);
qlen = delay_ms / (interval);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
- jb = stfu_n_init(qlen, qlen, read_impl.samples_per_packet, read_impl.samples_per_second);
+ jb = stfu_n_init(qlen, qlen, read_impl.samples_per_packet, read_impl.samples_per_second, 0);
write_frame.codec = switch_core_session_get_read_codec(session);
uint32_t queue_frames,
uint32_t max_queue_frames,
uint32_t samples_per_packet,
- uint32_t samples_per_second)
+ uint32_t samples_per_second,
+ uint32_t max_drift)
{
if (!switch_rtp_ready(rtp_session)) {
if (rtp_session->jb) {
stfu_n_resize(rtp_session->jb, queue_frames);
} else {
- rtp_session->jb = stfu_n_init(queue_frames, max_queue_frames ? max_queue_frames : 50, samples_per_packet, samples_per_second);
+ rtp_session->jb = stfu_n_init(queue_frames, max_queue_frames ? max_queue_frames : 50, samples_per_packet, samples_per_second, max_drift);
}
READ_DEC(rtp_session);
uint32_t ts;
switch_assert(bytes);
-
+ more:
*bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes);
ts = ntohl(rtp_session->recv_msg.header.ts);
stfu_n_reset(rtp_session->jb);
}
- stfu_n_eat(rtp_session->jb, rtp_session->last_read_ts,
- rtp_session->recv_msg.header.pt,
- rtp_session->recv_msg.body, *bytes - rtp_header_len, rtp_session->timer.samplecount);
+ if (stfu_n_eat(rtp_session->jb, rtp_session->last_read_ts,
+ rtp_session->recv_msg.header.pt,
+ rtp_session->recv_msg.body, *bytes - rtp_header_len, rtp_session->timer.samplecount) == STFU_ITS_TOO_LATE) {
+ printf("doh\n");
+ goto more;
+ }
+
status = SWITCH_STATUS_FALSE;
if (!return_jb_packet) {
return status;