FS-7499 FS-7500 mods for interop against latest chrome builds

This commit is contained in:
Anthony Minessale 2015-05-22 22:08:27 -05:00 committed by Michael Jerris
parent abd6943cf5
commit 40484fce58
4 changed files with 196 additions and 106 deletions

View File

@ -159,7 +159,7 @@ typedef union {
#endif #endif
#define __IS_VP8_KEY_FRAME(byte) (((byte) & 0x01) ^ 0x01) #define __IS_VP8_KEY_FRAME(byte) !(((byte) & 0x01))
static inline int IS_VP8_KEY_FRAME(uint8_t *data) static inline int IS_VP8_KEY_FRAME(uint8_t *data)
{ {
uint8_t S; uint8_t S;
@ -227,6 +227,7 @@ struct vpx_context {
uint8_t decoder_init; uint8_t decoder_init;
switch_buffer_t *vpx_packet_buffer; switch_buffer_t *vpx_packet_buffer;
int got_key_frame; int got_key_frame;
int got_start_frame;
uint32_t last_received_timestamp; uint32_t last_received_timestamp;
switch_bool_t last_received_complete_picture; switch_bool_t last_received_complete_picture;
int need_key_frame; int need_key_frame;
@ -272,6 +273,7 @@ static switch_status_t init_decoder(switch_codec_t *codec)
context->last_received_complete_picture = 0; context->last_received_complete_picture = 0;
context->decoder_init = 1; context->decoder_init = 1;
context->got_key_frame = 0; context->got_key_frame = 0;
context->got_start_frame = 0;
// the types of post processing to be done, should be combination of "vp8_postproc_level" // the types of post processing to be done, should be combination of "vp8_postproc_level"
ppcfg.post_proc_flag = VP8_DEBLOCK;//VP8_DEMACROBLOCK | VP8_DEBLOCK; ppcfg.post_proc_flag = VP8_DEBLOCK;//VP8_DEMACROBLOCK | VP8_DEBLOCK;
// the strength of deblocking, valid range [0, 16] // the strength of deblocking, valid range [0, 16]
@ -681,29 +683,57 @@ static switch_status_t buffer_vp8_packets(vpx_context_t *context, switch_frame_t
uint8_t *data = frame->data; uint8_t *data = frame->data;
uint8_t S; uint8_t S;
uint8_t DES; uint8_t DES;
//uint8_t PID; uint8_t PID;
int len; int len;
int key = 0;
#if 0
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"VIDEO VPX: seq: %d ts: %u len: %ld %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x mark: %d\n",
frame->seq, frame->timestamp, frame->datalen,
*((uint8_t *)data), *((uint8_t *)data + 1),
*((uint8_t *)data + 2), *((uint8_t *)data + 3),
*((uint8_t *)data + 4), *((uint8_t *)data + 5),
*((uint8_t *)data + 6), *((uint8_t *)data + 7),
*((uint8_t *)data + 8), *((uint8_t *)data + 9),
*((uint8_t *)data + 10), frame->m);
#endif
DES = *data; DES = *data;
data++; data++;
S = DES & 0x10; S = (DES & 0x10);
//PID = DES & 0x07; PID = DES & 0x07;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DATA LEN %d S BIT %d PID: %d\n", frame->datalen, S, PID);
if (DES & 0x80) { // X if (DES & 0x80) { // X
uint8_t X = *data; uint8_t X = *data;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "X BIT SET\n");
data++; data++;
if (X & 0x80) { // I if (X & 0x80) { // I
uint8_t M = (*data) & 0x80; uint8_t M = (*data) & 0x80;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "I BIT SET\n");
data++; data++;
if (M) data++; if (M) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "M BIT SET\n");
data++;
}
}
if (X & 0x40) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "L BIT SET\n");
data++; // L
}
if (X & 0x30) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "T/K BIT SET\n");
data++; // T/K
} }
if (X & 0x40) data++; // L
if (X & 0x30) data++; // T/K
} }
if (!switch_buffer_inuse(context->vpx_packet_buffer) && !S) { if (!switch_buffer_inuse(context->vpx_packet_buffer) && !S) {
if (context->got_key_frame > 0) { if (context->got_key_frame > 0) {
context->got_key_frame = 0; context->got_key_frame = 0;
context->got_start_frame = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG2, "packet loss?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG2, "packet loss?\n");
} }
return SWITCH_STATUS_MORE_DATA; return SWITCH_STATUS_MORE_DATA;
@ -712,10 +742,14 @@ static switch_status_t buffer_vp8_packets(vpx_context_t *context, switch_frame_t
if (S) { if (S) {
switch_buffer_zero(context->vpx_packet_buffer); switch_buffer_zero(context->vpx_packet_buffer);
context->last_received_timestamp = frame->timestamp; context->last_received_timestamp = frame->timestamp;
if (PID == 0) {
key = __IS_VP8_KEY_FRAME(*data);
}
} }
len = frame->datalen - (data - (uint8_t *)frame->data); len = frame->datalen - (data - (uint8_t *)frame->data);
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "POST PARSE: DATA LEN %d KEY %d KEYBYTE = %0x\n", len, key, *data);
if (len <= 0) { if (len <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid packet %d\n", len); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid packet %d\n", len);
return SWITCH_STATUS_RESTART; return SWITCH_STATUS_RESTART;
@ -802,7 +836,11 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
// context->last_received_timestamp = frame->timestamp; // context->last_received_timestamp = frame->timestamp;
context->last_received_complete_picture = frame->m ? SWITCH_TRUE : SWITCH_FALSE; context->last_received_complete_picture = frame->m ? SWITCH_TRUE : SWITCH_FALSE;
if (is_keyframe || is_start) { if (is_start) {
context->got_start_frame = 1;
}
if (is_keyframe) {
if (context->got_key_frame <= 0) { if (context->got_key_frame <= 0) {
context->got_key_frame = 1; context->got_key_frame = 1;
if (!is_keyframe) { if (!is_keyframe) {
@ -815,7 +853,9 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
if ((--context->got_key_frame % 200) == 0) { if ((--context->got_key_frame % 200) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Waiting for key frame %d\n", context->got_key_frame); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Waiting for key frame %d\n", context->got_key_frame);
} }
switch_goto_status(SWITCH_STATUS_MORE_DATA, end); if (!context->got_start_frame) {
switch_goto_status(SWITCH_STATUS_MORE_DATA, end);
}
} }
@ -839,12 +879,12 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
uint8_t *data; uint8_t *data;
int corrupted = 0; int corrupted = 0;
int err; int err;
//int keyframe = 0; int keyframe = 0;
//printf("WTF %d %ld\n", frame->m, len); //printf("WTF %d %ld\n", frame->m, len);
switch_buffer_peek_zerocopy(context->vpx_packet_buffer, (void *)&data); switch_buffer_peek_zerocopy(context->vpx_packet_buffer, (void *)&data);
//keyframe = (*data & 0x01) ? 0 : 1; keyframe = (*data & 0x01) ? 0 : 1;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffered: %" SWITCH_SIZE_T_FMT ", key: %d\n", len, keyframe); //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffered: %" SWITCH_SIZE_T_FMT ", key: %d\n", len, keyframe);
@ -871,17 +911,22 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
switch_buffer_zero(context->vpx_packet_buffer); switch_buffer_zero(context->vpx_packet_buffer);
if (!frame->img) { if (!frame->img) {
context->need_decoder_reset = 1; //context->need_decoder_reset = 1;
context->got_key_frame = 0; context->got_key_frame = 0;
context->got_start_frame = 0;
status = SWITCH_STATUS_RESTART; status = SWITCH_STATUS_RESTART;
} }
} }
end: end:
//if (status == SWITCH_STATUS_RESTART) { if (status == SWITCH_STATUS_RESTART) {
// context->need_decoder_reset = 1; switch_buffer_zero(context->vpx_packet_buffer);
//} //context->need_decoder_reset = 1;
context->got_key_frame = 0;
context->got_start_frame = 0;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "RESET VPX\n");
}
if (!frame->img || status == SWITCH_STATUS_RESTART) { if (!frame->img || status == SWITCH_STATUS_RESTART) {
status = SWITCH_STATUS_MORE_DATA; status = SWITCH_STATUS_MORE_DATA;

View File

@ -1852,7 +1852,13 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw
switch_channel_set_variable(channel, "recovered", "true"); switch_channel_set_variable(channel, "recovered", "true");
} }
if (flag == CF_VIDEO_ECHO) {
switch_core_session_start_video_thread(channel->session);
}
if (flag == CF_VIDEO_DECODED_READ) { if (flag == CF_VIDEO_DECODED_READ) {
switch_core_session_request_video_refresh(channel->session);
switch_core_session_start_video_thread(channel->session);
if (!switch_core_session_in_video_thread(channel->session)) { if (!switch_core_session_in_video_thread(channel->session)) {
switch_channel_wait_for_flag(channel, CF_VIDEO_READY, SWITCH_TRUE, 10000, NULL); switch_channel_wait_for_flag(channel, CF_VIDEO_READY, SWITCH_TRUE, 10000, NULL);
} }

View File

@ -3154,7 +3154,7 @@ static void check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_
engine->ice_in.cand_idx++; engine->ice_in.cand_idx++;
for (i = 0; i < engine->cand_acl_count; i++) { for (i = 0; i < engine->cand_acl_count; i++) {
if (!engine->ice_in.chosen[cid] && switch_check_network_list_ip(fields[4], engine->cand_acl[i])) { if (!engine->ice_in.chosen[cid] && !strchr(fields[4], ':') && switch_check_network_list_ip(fields[4], engine->cand_acl[i])) {
engine->ice_in.chosen[cid] = engine->ice_in.cand_idx; engine->ice_in.chosen[cid] = engine->ice_in.cand_idx;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE, switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE,
"Choose %s Candidate cid: %d proto: %s type: %s addr: %s:%s\n", "Choose %s Candidate cid: %d proto: %s type: %s addr: %s:%s\n",
@ -4778,6 +4778,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses
switch_mutex_unlock(v_engine->mh.file_mutex); switch_mutex_unlock(v_engine->mh.file_mutex);
switch_core_session_start_video_thread(session);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -4931,7 +4933,7 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi
} else if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ)) { } else if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ)) {
send_blank = 1; send_blank = 1;
} }
if ((send_blank || switch_channel_test_flag(channel, CF_VIDEO_BLANK)) && if ((send_blank || switch_channel_test_flag(channel, CF_VIDEO_BLANK)) &&
!session->video_read_callback && !switch_channel_test_flag(session->channel, CF_BRIDGED)) { !session->video_read_callback && !switch_channel_test_flag(session->channel, CF_BRIDGED)) {
fr.img = blank_img; fr.img = blank_img;
@ -5003,7 +5005,6 @@ SWITCH_DECLARE(void) switch_core_media_start_video_function(switch_core_session_
smh->video_function = video_function; smh->video_function = video_function;
smh->video_user_data = user_data; smh->video_user_data = user_data;
switch_core_session_video_reset(session); switch_core_session_video_reset(session);
switch_core_session_start_video_thread(session);
} }
switch_mutex_unlock(smh->control_mutex); switch_mutex_unlock(smh->control_mutex);
} }
@ -5191,7 +5192,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_proxy_remote_addr(switch_core_
!switch_channel_test_flag(session->channel, CF_AVPF)) { !switch_channel_test_flag(session->channel, CF_AVPF)) {
/* Reactivate the NAT buster flag. */ /* Reactivate the NAT buster flag. */
switch_rtp_set_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_AUTOADJ); switch_rtp_set_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
switch_core_session_start_video_thread(session);
} }
if (switch_media_handle_test_media_flag(smh, SCMF_AUTOFIX_TIMING)) { if (switch_media_handle_test_media_flag(smh, SCMF_AUTOFIX_TIMING)) {
v_engine->check_frames = 0; v_engine->check_frames = 0;
@ -6169,7 +6169,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
v_engine->local_sdp_ip, v_engine->local_sdp_port, v_engine->cur_payload_map->remote_sdp_ip, v_engine->local_sdp_ip, v_engine->local_sdp_port, v_engine->cur_payload_map->remote_sdp_ip,
v_engine->cur_payload_map->remote_sdp_port, v_engine->cur_payload_map->agreed_pt); v_engine->cur_payload_map->remote_sdp_port, v_engine->cur_payload_map->agreed_pt);
switch_core_session_start_video_thread(session);
switch_rtp_set_default_payload(v_engine->rtp_session, v_engine->cur_payload_map->agreed_pt); switch_rtp_set_default_payload(v_engine->rtp_session, v_engine->cur_payload_map->agreed_pt);
} }
} }
@ -6202,7 +6201,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
!((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) { !((val = switch_channel_get_variable(session->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
/* Reactivate the NAT buster flag. */ /* Reactivate the NAT buster flag. */
switch_rtp_set_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_AUTOADJ); switch_rtp_set_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
switch_core_session_start_video_thread(session);
} }
} }
@ -6317,7 +6315,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
} }
switch_rtp_set_payload_map(v_engine->rtp_session, &v_engine->payload_map); switch_rtp_set_payload_map(v_engine->rtp_session, &v_engine->payload_map);
switch_core_session_start_video_thread(session); //switch_core_session_start_video_thread(session);
switch_channel_set_flag(session->channel, CF_VIDEO); switch_channel_set_flag(session->channel, CF_VIDEO);
if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_video_ssrc"))) { if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_video_ssrc"))) {
@ -6923,7 +6921,7 @@ static void add_fb(char *buf, uint32_t buflen, int pt, int fir, int nack, int pl
sp = " "; sp = " ";
} }
if (fir) { if (!zstr(zfir) || !zstr(ztmmbr)) {
switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d ccm %s%s%s\n", pt, zfir, sp, ztmmbr); switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=rtcp-fb:%d ccm %s%s%s\n", pt, zfir, sp, ztmmbr);
} }
@ -7324,7 +7322,8 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
if (!zstr(a_engine->local_dtls_fingerprint.type)) { if (!zstr(a_engine->local_dtls_fingerprint.type)) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\n", a_engine->local_dtls_fingerprint.type, switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\na=mid:audio\n",
a_engine->local_dtls_fingerprint.type,
a_engine->local_dtls_fingerprint.str, get_setup(session)); a_engine->local_dtls_fingerprint.str, get_setup(session));
} }
@ -7358,13 +7357,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
ice_out = &a_engine->ice_out; ice_out = &a_engine->ice_out;
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u cname:%s\n", a_engine->ssrc, smh->cname);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u msid:%s a0\n", a_engine->ssrc, smh->msid);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u mslabel:%s\n", a_engine->ssrc, smh->msid);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u label:%sa0\n", a_engine->ssrc, smh->msid);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-ufrag:%s\n", ice_out->ufrag); switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-ufrag:%s\n", ice_out->ufrag);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-pwd:%s\n", ice_out->pwd); switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-pwd:%s\n", ice_out->pwd);
@ -7406,7 +7399,13 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
); );
} }
} }
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u cname:%s\n", a_engine->ssrc, smh->cname);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u msid:%s a0\n", a_engine->ssrc, smh->msid);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u mslabel:%s\n", a_engine->ssrc, smh->msid);
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ssrc:%u label:%sa0\n", a_engine->ssrc, smh->msid);
#ifdef GOOGLE_ICE #ifdef GOOGLE_ICE
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-options:google-ice\n"); switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=ice-options:google-ice\n");
@ -8600,13 +8599,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se
case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ: case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
{ {
if (v_engine->rtp_session) { if (v_engine->rtp_session) {
if (switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_PLI)) {
switch_rtp_video_loss(v_engine->rtp_session);
}
if (switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_FIR)) { if (switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_FIR)) {
switch_rtp_video_refresh(v_engine->rtp_session); switch_rtp_video_refresh(v_engine->rtp_session);
} }// else {
if (switch_rtp_test_flag(v_engine->rtp_session, SWITCH_RTP_FLAG_PLI)) {
switch_rtp_video_loss(v_engine->rtp_session);
}
// }
} }
} }
@ -10482,7 +10481,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
if (status == SWITCH_STATUS_INUSE) { if (status == SWITCH_STATUS_INUSE) {
*frame = &runtime.dummy_cng_frame; *frame = &runtime.dummy_cng_frame;
switch_yield(20000); switch_cond_next();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -10541,7 +10540,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
if (!(*frame)->img) { if (!(*frame)->img) {
*frame = &runtime.dummy_cng_frame; *frame = &runtime.dummy_cng_frame;
switch_yield(66000); switch_cond_next();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
} }

View File

@ -852,6 +852,9 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
int is_rtcp = ice == &rtp_session->rtcp_ice; int is_rtcp = ice == &rtp_session->rtcp_ice;
uint32_t elapsed; uint32_t elapsed;
//if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s CALL\n", rtp_type(rtp_session));
//}
if (!switch_rtp_ready(rtp_session) || zstr(ice->user_ice) || zstr(ice->ice_user)) { if (!switch_rtp_ready(rtp_session) || zstr(ice->user_ice) || zstr(ice->ice_user)) {
return; return;
@ -1107,6 +1110,11 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
ok = 1; ok = 1;
} }
//if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s %d\n", rtp_type(rtp_session), ok);
//}
if (ok) { if (ok) {
const char *host = NULL, *host2 = NULL; const char *host = NULL, *host2 = NULL;
switch_port_t port = 0, port2 = 0; switch_port_t port = 0, port2 = 0;
@ -1878,7 +1886,7 @@ static int using_ice(switch_rtp_t *rtp_session)
static int check_rtcp_and_ice(switch_rtp_t *rtp_session) static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
{ {
int ret = 0; int ret = 0;
int rtcp_ok = 0; int rtcp_ok = 0, rtcp_fb = 0;
switch_time_t now = switch_micro_time_now(); switch_time_t now = switch_micro_time_now();
int rate = 0; int rate = 0;
@ -1905,26 +1913,35 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
rate = 4000; rate = 4000;
} else { } else {
if (rtp_session->pli_count || rtp_session->fir_count || rtp_session->cur_nack || rtp_session->tmmbr || rtp_session->tmmbn) { if (rtp_session->pli_count || rtp_session->fir_count || rtp_session->cur_nack || rtp_session->tmmbr || rtp_session->tmmbn) {
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "MARK BW/FIR ETC %d %d\n", rtp_session->pli_count, rtp_session->fir_count);
rtcp_ok = 1; rtcp_ok = 1;
rtcp_fb = 1;
} }
} }
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "TIME CHECK %d > %d\n", (int)((now - rtp_session->rtcp_last_sent) / 1000), rate);
if (!rtcp_ok && (!rtp_session->rtcp_last_sent || (int)((now - rtp_session->rtcp_last_sent) / 1000) > rate)) { if (!rtcp_ok && (!rtp_session->rtcp_last_sent || (int)((now - rtp_session->rtcp_last_sent) / 1000) > rate)) {
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "TIME UP\n");
rtcp_ok = 1; rtcp_ok = 1;
} }
if (rtcp_ok && using_ice(rtp_session)) { if (rtcp_ok && using_ice(rtp_session)) {
if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
if (!rtp_session->ice.rready) { if (!rtp_session->ice.rready) {
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "FUCK 1\n");
rtcp_ok = 0; rtcp_ok = 0;
} }
} else { } else {
if (!rtp_session->rtcp_ice.rready) { if (!rtp_session->rtcp_ice.rready) {
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "FUCK 2\n");
rtcp_ok = 0; rtcp_ok = 0;
} }
} }
} }
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "WTF %d %d %d\n", rate, rtp_session->rtcp_sent_packets, rtcp_ok);
if (rtp_session->flags[SWITCH_RTP_FLAG_NACK] && rtp_session->vb) { if (rtp_session->flags[SWITCH_RTP_FLAG_NACK] && rtp_session->vb) {
rtp_session->cur_nack = switch_vb_pop_nack(rtp_session->vb); rtp_session->cur_nack = switch_vb_pop_nack(rtp_session->vb);
} }
@ -1941,11 +1958,15 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
uint32_t *ssrc; uint32_t *ssrc;
switch_rtcp_sdes_unit_t *unit; switch_rtcp_sdes_unit_t *unit;
rtp_session->rtcp_last_sent = now; if (!rtcp_fb) {
rtp_session->rtcp_last_sent = now;
rtp_session->rtcp_sent_packets++;
}
rtp_session->rtcp_send_msg.header.version = 2; rtp_session->rtcp_send_msg.header.version = 2;
rtp_session->rtcp_send_msg.header.p = 0; rtp_session->rtcp_send_msg.header.p = 0;
rtp_session->rtcp_send_msg.header.count = 1; rtp_session->rtcp_send_msg.header.count = 1;
rtp_session->rtcp_sent_packets++;
if (!rtp_session->stats.rtcp.sent_pkt_count) { if (!rtp_session->stats.rtcp.sent_pkt_count) {
rtp_session->rtcp_send_msg.header.type = RTCP_PT_RR; /* Receiver report */ rtp_session->rtcp_send_msg.header.type = RTCP_PT_RR; /* Receiver report */
@ -2129,8 +2150,9 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1); sdes->length = htons((uint16_t)(sdes_bytes / 4) - 1);
rtcp_bytes += sdes_bytes; rtcp_bytes += sdes_bytes;
/* Prepare next report */ /* Prepare next report */
stats->last_rpt_cycle = stats->cycle; stats->last_rpt_cycle = stats->cycle;
stats->last_rpt_ext_seq = stats->high_ext_seq_recv; stats->last_rpt_ext_seq = stats->high_ext_seq_recv;
stats->last_rpt_ts = rtp_session->timer.samplecount; stats->last_rpt_ts = rtp_session->timer.samplecount;
@ -2138,6 +2160,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
stats->sent_pkt_count = 0; stats->sent_pkt_count = 0;
#ifdef ENABLE_SRTP #ifdef ENABLE_SRTP
if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) { if (rtp_session->flags[SWITCH_RTP_FLAG_SECURE_SEND]) {
int sbytes = (int) rtcp_bytes; int sbytes = (int) rtcp_bytes;
@ -3670,12 +3693,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Starting video timer.\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Starting video timer.\n");
} }
//switch_vb_create(&rtp_session->vb, 5, 30, rtp_session->pool); //switch_vb_create(&rtp_session->vb, 3, 10, rtp_session->pool);
//switch_vb_debug_level(rtp_session->vb, 10); //switch_vb_debug_level(rtp_session->vb, 10);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Not using a timer\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Not using a timer\n");
@ -3981,8 +4000,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_video_buffer_size(switch_rtp_t *r
switch_vb_set_frames(rtp_session->vb, frames, frames * 3); switch_vb_set_frames(rtp_session->vb, frames, frames * 3);
} }
switch_rtp_flush(rtp_session); //switch_rtp_flush(rtp_session);
switch_core_session_request_video_refresh(rtp_session->session); //switch_core_session_request_video_refresh(rtp_session->session);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Setting video buffer %u Frames.\n", frames); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "Setting video buffer %u Frames.\n", frames);
@ -4856,14 +4875,14 @@ static void do_flush(switch_rtp_t *rtp_session, int force)
stfu_n_reset(rtp_session->jb); stfu_n_reset(rtp_session->jb);
} }
if (rtp_session->vb) { //if (rtp_session->vb) {
switch_vb_reset(rtp_session->vb); // switch_vb_reset(rtp_session->vb);
} //}
if (rtp_session->vbw) { if (rtp_session->vbw) {
switch_vb_reset(rtp_session->vbw); switch_vb_reset(rtp_session->vbw);
} }
if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]) { if (rtp_session->flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session),
SWITCH_LOG_CONSOLE, "%s FLUSH\n", SWITCH_LOG_CONSOLE, "%s FLUSH\n",
@ -4915,14 +4934,15 @@ static void do_flush(switch_rtp_t *rtp_session, int force)
switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK); switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE); switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
} }
}
if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->session) { if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->session) {
int type = 1; // sum flags: 1 encoder; 2; decoder //int type = 1; // sum flags: 1 encoder; 2; decoder
switch_core_media_codec_control(rtp_session->session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_READ, SCC_VIDEO_RESET, SCCT_INT, (void *)&type, NULL, NULL); //switch_core_media_codec_control(rtp_session->session, SWITCH_MEDIA_TYPE_VIDEO, SWITCH_IO_READ, SCC_VIDEO_RESET, SCCT_INT, (void *)&type, NULL, NULL);
switch_core_session_request_video_refresh(rtp_session->session); switch_core_session_request_video_refresh(rtp_session->session);
}
} }
READ_DEC(rtp_session); READ_DEC(rtp_session);
} }
@ -4992,6 +5012,9 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
} }
if (check_rtcp_and_ice(rtp_session) == -1) { if (check_rtcp_and_ice(rtp_session) == -1) {
//if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF CHECK FAIL\n");
//}
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -5005,6 +5028,11 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
*flags &= ~SFF_PROXY_PACKET; *flags &= ~SFF_PROXY_PACKET;
//if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF BYTES %ld b=%d\n", *bytes, *b);
//}
if (*b == 0 || *b == 1) { if (*b == 0 || *b == 1) {
if (rtp_session->ice.ice_user) { if (rtp_session->ice.ice_user) {
handle_ice(rtp_session, &rtp_session->ice, (void *) &rtp_session->recv_msg, *bytes); handle_ice(rtp_session, &rtp_session->ice, (void *) &rtp_session->recv_msg, *bytes);
@ -5143,19 +5171,6 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
uint16_t seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq); uint16_t seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
ts = ntohl(rtp_session->recv_msg.header.ts); ts = ntohl(rtp_session->recv_msg.header.ts);
if (!rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] && !rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] &&
rtp_session->recv_msg.header.version == 2 && rtp_session->recv_msg.header.x) { /* header extensions */
uint16_t length;
rtp_session->recv_msg.ext = (switch_rtp_hdr_ext_t *) rtp_session->recv_msg.body;
length = ntohs((uint16_t)rtp_session->recv_msg.ext->length);
if (length < SWITCH_RTP_MAX_BUF_LEN_WORDS) {
rtp_session->recv_msg.ebody = rtp_session->recv_msg.body + (length * 4) + 4;
}
}
#ifdef DEBUG_MISSED_SEQ #ifdef DEBUG_MISSED_SEQ
if (rtp_session->last_seq && rtp_session->last_seq+1 != seq) { if (rtp_session->last_seq && rtp_session->last_seq+1 != seq) {
//2012-11-28 18:33:11.799070 [ERR] switch_rtp.c:2883 Missed -65536 RTP frames from sequence [65536] to [-1] (missed). Time since last read [20021] //2012-11-28 18:33:11.799070 [ERR] switch_rtp.c:2883 Missed -65536 RTP frames from sequence [65536] to [-1] (missed). Time since last read [20021]
@ -5216,19 +5231,6 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
} }
if (*bytes) { if (*bytes) {
rtp_session->stats.inbound.raw_bytes += *bytes;
if (rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) {
rtp_session->stats.inbound.dtmf_packet_count++;
} else if (rtp_session->cng_pt && (rtp_session->recv_msg.header.pt == rtp_session->cng_pt || rtp_session->recv_msg.header.pt == 13)) {
rtp_session->stats.inbound.cng_packet_count++;
} else {
rtp_session->stats.inbound.media_packet_count++;
rtp_session->stats.inbound.media_bytes += *bytes;
}
rtp_session->stats.inbound.packet_count++;
if (!rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] && !rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) { if (!rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] && !rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
#ifdef ENABLE_ZRTP #ifdef ENABLE_ZRTP
/* ZRTP Recv */ /* ZRTP Recv */
@ -5328,11 +5330,62 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
if (rtp_session->recv_msg.header.version == 2) { if (rtp_session->recv_msg.header.version == 2) {
/* recalculate body length in case rtp extension used */
if (!rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] && !rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] &&
rtp_session->recv_msg.header.version == 2 && rtp_session->recv_msg.header.x) { /* header extensions */
uint16_t length;
rtp_session->recv_msg.ext = (switch_rtp_hdr_ext_t *) rtp_session->recv_msg.body;
length = ntohs((uint16_t)rtp_session->recv_msg.ext->length);
if (length < SWITCH_RTP_MAX_BUF_LEN_WORDS) {
rtp_session->recv_msg.ebody = rtp_session->recv_msg.body + (length * 4) + 4;
if (*bytes > (length * 4 + 4)) {
*bytes -= (length * 4 + 4);
} else {
*bytes = 0;
}
}
}
#ifdef DEBUG_CHROME
if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->recv_msg.header.version == 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"VIDEO: seq: %d ts: %u len: %ld %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x mark: %d\n",
ntohs(rtp_session->recv_msg.header.seq), ntohl(rtp_session->recv_msg.header.ts), *bytes,
*((uint8_t *)RTP_BODY(rtp_session)), *((uint8_t *)RTP_BODY(rtp_session) + 1),
*((uint8_t *)RTP_BODY(rtp_session) + 2), *((uint8_t *)RTP_BODY(rtp_session) + 3),
*((uint8_t *)RTP_BODY(rtp_session) + 4), *((uint8_t *)RTP_BODY(rtp_session) + 5),
*((uint8_t *)RTP_BODY(rtp_session) + 6), *((uint8_t *)RTP_BODY(rtp_session) + 7),
*((uint8_t *)RTP_BODY(rtp_session) + 8), *((uint8_t *)RTP_BODY(rtp_session) + 9),
*((uint8_t *)RTP_BODY(rtp_session) + 10), rtp_session->recv_msg.header.m);
}
#endif
if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) { if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
rtcp_stats(rtp_session); rtcp_stats(rtp_session);
} }
} }
rtp_session->stats.inbound.raw_bytes += *bytes;
if (rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) {
rtp_session->stats.inbound.dtmf_packet_count++;
} else if (rtp_session->cng_pt && (rtp_session->recv_msg.header.pt == rtp_session->cng_pt || rtp_session->recv_msg.header.pt == 13)) {
rtp_session->stats.inbound.cng_packet_count++;
} else {
rtp_session->stats.inbound.media_packet_count++;
rtp_session->stats.inbound.media_bytes += *bytes;
}
rtp_session->stats.inbound.packet_count++;
} }
if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) || if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) ||
@ -5454,24 +5507,6 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
} }
} }
/* recalculate body length in case rtp extension used */
if (!rtp_session->flags[SWITCH_RTP_FLAG_PROXY_MEDIA] && !rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] &&
rtp_session->recv_msg.header.version == 2 && rtp_session->recv_msg.header.x) { /* header extensions */
uint16_t length;
rtp_session->recv_msg.ext = (switch_rtp_hdr_ext_t *) rtp_session->recv_msg.body;
length = ntohs((uint16_t)rtp_session->recv_msg.ext->length);
if (length < SWITCH_RTP_MAX_BUF_LEN_WORDS) {
rtp_session->recv_msg.ebody = rtp_session->recv_msg.body + (length * 4) + 4;
if (*bytes > (length * 4 + 4)) {
*bytes -= (length * 4 + 4);
} else {
*bytes = 0;
}
}
}
return status; return status;
} }
@ -6006,6 +6041,11 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
poll_status = switch_poll(rtp_session->read_pollfd, 1, &fdr, pt); poll_status = switch_poll(rtp_session->read_pollfd, 1, &fdr, pt);
//if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF Poll %d\n", poll_status);
//}
if (!rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->dtmf_data.out_digit_dur > 0) { if (!rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] && rtp_session->dtmf_data.out_digit_dur > 0) {
return_cng_frame(); return_cng_frame();
} }
@ -6849,7 +6889,7 @@ static int rtp_write_ready(switch_rtp_t *rtp_session, uint32_t bytes, int line)
{ {
if (!rtp_session) return 0; if (!rtp_session) return 0;
if (rtp_session->ice.ice_user && !(rtp_session->ice.rready && rtp_session->ice.ready)) { if (rtp_session->ice.ice_user && !(rtp_session->ice.rready || rtp_session->ice.ready)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG3, "Skip sending %s packet %ld bytes (ice not ready @ line %d!)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG3, "Skip sending %s packet %ld bytes (ice not ready @ line %d!)\n",
rtp_type(rtp_session), (long)bytes, line); rtp_type(rtp_session), (long)bytes, line);
return 0; return 0;
@ -7241,7 +7281,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
if (rtp_session->flags[SWITCH_RTP_FLAG_NACK]) { if (rtp_session->flags[SWITCH_RTP_FLAG_NACK]) {
if (!rtp_session->vbw) { if (!rtp_session->vbw) {
switch_vb_create(&rtp_session->vbw, 150, 150, rtp_session->pool); switch_vb_create(&rtp_session->vbw, 10, 10, rtp_session->pool);
//switch_vb_debug_level(rtp_session->vbw, 10); //switch_vb_debug_level(rtp_session->vbw, 10);
} }
switch_vb_push_packet(rtp_session->vbw, (switch_rtp_packet_t *)send_msg, bytes); switch_vb_push_packet(rtp_session->vbw, (switch_rtp_packet_t *)send_msg, bytes);