FS-6926 #resolve #comment please test and reopen if necessary

This commit is contained in:
Anthony Minessale 2014-10-16 17:57:40 -05:00
parent f1ee4ba4d7
commit 1f9025d446
2 changed files with 100 additions and 135 deletions

View File

@ -1628,6 +1628,95 @@ SWITCH_DECLARE(void) switch_core_media_prepare_codecs(switch_core_session_t *ses
}
static void check_jb(switch_core_session_t *session)
{
const char *val;
switch_media_handle_t *smh;
switch_rtp_engine_t *a_engine;
switch_assert(session);
if (!(smh = session->media_handle)) {
return;
}
a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
if (!a_engine->rtp_session) return;
if ((val = switch_channel_get_variable(session->channel, "jitterbuffer_msec")) || (val = smh->mparams->jb_msec)) {
int jb_msec = atoi(val);
int maxlen = 0, max_drift = 0;
char *p, *q;
const char *s;
if (!strcasecmp(val, "pause")) {
switch_rtp_pause_jitter_buffer(a_engine->rtp_session, SWITCH_TRUE);
return;
} else if (!strcasecmp(val, "resume")) {
switch_rtp_pause_jitter_buffer(a_engine->rtp_session, SWITCH_FALSE);
return;
} else if (!strncasecmp(val, "debug:", 6)) {
s = val + 6;
if (s && !strcmp(s, "off")) {
s = NULL;
}
switch_rtp_debug_jitter_buffer(a_engine->rtp_session, s);
return;
}
if ((p = strchr(val, ':'))) {
p++;
maxlen = atoi(p);
if ((q = strchr(p, ':'))) {
q++;
max_drift = abs(atoi(q));
}
}
if (jb_msec < 0 && jb_msec > -20) {
jb_msec = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(jb_msec);
}
if (maxlen < 0 && maxlen > -20) {
maxlen = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(maxlen);
}
if (jb_msec < 20 || jb_msec > 10000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
"Invalid Jitterbuffer spec [%d] must be between 20 and 10000\n", jb_msec);
} else {
int qlen, maxqlen = 10;
qlen = jb_msec / (a_engine->read_impl.microseconds_per_packet / 1000);
if (maxlen) {
maxqlen = maxlen / (a_engine->read_impl.microseconds_per_packet / 1000);
}
if (maxqlen < qlen) {
maxqlen = qlen * 5;
}
if (switch_rtp_activate_jitter_buffer(a_engine->rtp_session, qlen, maxqlen,
a_engine->read_impl.samples_per_packet,
a_engine->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames) (%d max drift)\n",
jb_msec, qlen, maxqlen, max_drift);
switch_channel_set_flag(session->channel, CF_JITTERBUFFER);
if (!switch_false(switch_channel_get_variable(session->channel, "rtp_jitter_buffer_plc"))) {
switch_channel_set_flag(session->channel, CF_JITTERBUFFER_PLC);
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_WARNING, "Error Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
}
}
}
}
//?
SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session_t *session, switch_frame_t **frame,
switch_io_flag_t flags, int stream_id, switch_media_type_t type)
@ -1741,7 +1830,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session
engine->read_impl.samples_per_packet;
}
}
check_jb(session);
engine->check_frames = 0;
engine->last_ts = 0;
engine->last_seq = 0;
@ -5248,61 +5339,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
}
if ((val = switch_channel_get_variable(session->channel, "jitterbuffer_msec")) || (val = smh->mparams->jb_msec)) {
int jb_msec = atoi(val);
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 < 0 && jb_msec > -20) {
jb_msec = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(jb_msec);
}
if (maxlen < 0 && maxlen > -20) {
maxlen = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(maxlen);
}
if (jb_msec < 20 || jb_msec > 10000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
"Invalid Jitterbuffer spec [%d] must be between 20 and 10000\n", jb_msec);
} else {
int qlen, maxqlen = 10;
qlen = jb_msec / (a_engine->read_impl.microseconds_per_packet / 1000);
if (maxlen) {
maxqlen = maxlen / (a_engine->read_impl.microseconds_per_packet / 1000);
}
if (maxqlen < qlen) {
maxqlen = qlen * 5;
}
if (switch_rtp_activate_jitter_buffer(a_engine->rtp_session, qlen, maxqlen,
a_engine->read_impl.samples_per_packet,
a_engine->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
switch_channel_set_flag(session->channel, CF_JITTERBUFFER);
if (!switch_false(switch_channel_get_variable(session->channel, "rtp_jitter_buffer_plc"))) {
switch_channel_set_flag(session->channel, CF_JITTERBUFFER_PLC);
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_WARNING, "Error Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
}
}
}
check_jb(session);
if ((val = switch_channel_get_variable(session->channel, "rtp_timeout_sec"))) {
int v = atoi(val);
@ -7666,82 +7703,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se
case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER:
{
if (switch_rtp_ready(a_engine->rtp_session)) {
int len = 0, maxlen = 0, qlen = 0, maxqlen = 10, max_drift = 0;
if (msg->string_arg) {
char *p, *q;
const char *s;
if (!strcasecmp(msg->string_arg, "pause")) {
switch_rtp_pause_jitter_buffer(a_engine->rtp_session, SWITCH_TRUE);
goto end;
} else if (!strcasecmp(msg->string_arg, "resume")) {
switch_rtp_pause_jitter_buffer(a_engine->rtp_session, SWITCH_FALSE);
goto end;
} else if (!strncasecmp(msg->string_arg, "debug:", 6)) {
s = msg->string_arg + 6;
if (s && !strcmp(s, "off")) {
s = NULL;
}
status = switch_rtp_debug_jitter_buffer(a_engine->rtp_session, s);
goto end;
}
if ((len = atoi(msg->string_arg))) {
qlen = len / (a_engine->read_impl.microseconds_per_packet / 1000);
if (qlen < 1) {
qlen = 1;
}
}
if (qlen) {
if ((p = strchr(msg->string_arg, ':'))) {
p++;
maxlen = atol(p);
if ((q = strchr(p, ':'))) {
q++;
max_drift = abs(atoi(q));
}
}
}
if (qlen < 0 && qlen > -20) {
qlen = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(qlen);
}
if (maxlen < 0 && maxlen > -20) {
maxlen = (a_engine->read_codec.implementation->microseconds_per_packet / 1000) * abs(maxlen);
}
if (maxlen) {
maxqlen = maxlen / (a_engine->read_impl.microseconds_per_packet / 1000);
}
}
if (qlen) {
if (maxqlen < qlen) {
maxqlen = qlen * 5;
}
if (switch_rtp_activate_jitter_buffer(a_engine->rtp_session, qlen, maxqlen,
a_engine->read_impl.samples_per_packet,
a_engine->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
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(session->channel, CF_JITTERBUFFER);
if (!switch_false(switch_channel_get_variable(session->channel, "rtp_jitter_buffer_plc"))) {
switch_channel_set_flag(session->channel, CF_JITTERBUFFER_PLC);
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_WARNING, "Error Setting Jitterbuffer to %dms (%d frames)\n", len, qlen);
}
} else {
switch_rtp_deactivate_jitter_buffer(a_engine->rtp_session);
}
switch_channel_set_variable(session->channel, "jitterbuffer_msec", msg->string_arg);
check_jb(session);
}
}
break;

View File

@ -3825,11 +3825,13 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *
}
READ_INC(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, max_drift);
stfu_n_destroy(&rtp_session->jb);
}
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);
if (rtp_session->jb) {