diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 892d8c0919..fcce2da4c0 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -2014,7 +2014,7 @@ static void check_jb_sync(switch_core_session_t *session) switch_rtp_get_video_buffer_size(v_engine->rtp_session, &min_frames, &max_frames, &cur_frames, NULL); - if (frames == cur_frames) { + if (cur_frames > min_frames || frames == min_frames) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s %s \"%s\" A/V JB not changed %dms %u VFrames FPS %u\n", switch_core_session_get_uuid(session), @@ -3079,6 +3079,24 @@ static int dtls_ok(switch_core_session_t *session) #pragma warning(disable:4702) #endif +//? +SWITCH_DECLARE(switch_call_direction_t) switch_ice_direction(switch_core_session_t *session) +{ + switch_call_direction_t r = switch_channel_direction(session->channel); + + if (switch_channel_test_flag(session->channel, CF_3PCC)) { + r = (r == SWITCH_CALL_DIRECTION_INBOUND) ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND; + } + + if ((switch_channel_test_flag(session->channel, CF_REINVITE) || switch_channel_test_flag(session->channel, CF_RECOVERING)) + && switch_channel_test_flag(session->channel, CF_AVPF)) { + r = SWITCH_CALL_DIRECTION_OUTBOUND; + } + + return r; +} + + //? static switch_status_t ip_choose_family(switch_media_handle_t *smh, const char *ip) { @@ -3178,11 +3196,13 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t if (!strcasecmp(attr->a_value, "passive") || !strcasecmp(attr->a_value, "actpass")) { if (!engine->dtls_controller) { engine->new_dtls = 1; + engine->new_ice = 1; } engine->dtls_controller = 1; } else if (!strcasecmp(attr->a_value, "active")) { if (engine->dtls_controller) { engine->new_dtls = 1; + engine->new_ice = 1; } engine->dtls_controller = 0; } @@ -3200,6 +3220,7 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t } else { switch_set_string(engine->remote_dtls_fingerprint.str, p); engine->new_dtls = 1; + engine->new_ice = 1; } } @@ -3414,7 +3435,8 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t ICE_GOOGLE_JINGLE, NULL #else - engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(smh->session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &engine->ice_in #endif ); @@ -3468,7 +3490,8 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t ICE_GOOGLE_JINGLE, NULL #else - engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(smh->session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &engine->ice_in #endif ); @@ -6171,7 +6194,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi ICE_GOOGLE_JINGLE, NULL #else - a_engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &a_engine->ice_in #endif ); @@ -6223,7 +6247,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi ICE_GOOGLE_JINGLE, NULL #else - a_engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &a_engine->ice_in #endif ); @@ -6233,11 +6258,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi } if (!zstr(a_engine->local_dtls_fingerprint.str) && switch_rtp_has_dtls() && dtls_ok(smh->session)) { - dtls_type_t xtype, dtype = switch_channel_direction(smh->session->channel) == SWITCH_CALL_DIRECTION_INBOUND ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER; + dtls_type_t xtype, dtype = a_engine->dtls_controller ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER; - if (switch_channel_test_flag(smh->session->channel, CF_3PCC)) { - dtype = (dtype == DTLS_TYPE_CLIENT) ? DTLS_TYPE_SERVER : DTLS_TYPE_CLIENT; - } + //if (switch_channel_test_flag(smh->session->channel, CF_3PCC)) { + // dtype = (dtype == DTLS_TYPE_CLIENT) ? DTLS_TYPE_SERVER : DTLS_TYPE_CLIENT; + //} xtype = DTLS_TYPE_RTP; if (a_engine->rtcp_mux > 0 && smh->mparams->rtcp_audio_interval_msec) xtype |= DTLS_TYPE_RTCP; @@ -6551,7 +6576,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi ICE_GOOGLE_JINGLE, NULL #else - v_engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &v_engine->ice_in #endif ); @@ -6601,7 +6627,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi ICE_GOOGLE_JINGLE, NULL #else - v_engine->dtls_controller ? (ICE_VANILLA | ICE_CONTROLLED) : ICE_VANILLA, + switch_ice_direction(session) == + SWITCH_CALL_DIRECTION_OUTBOUND ? ICE_VANILLA : (ICE_VANILLA | ICE_CONTROLLED), &v_engine->ice_in #endif ); @@ -6615,7 +6642,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi if (!zstr(v_engine->local_dtls_fingerprint.str) && switch_rtp_has_dtls() && dtls_ok(smh->session)) { dtls_type_t xtype, - dtype = switch_channel_direction(smh->session->channel) == SWITCH_CALL_DIRECTION_INBOUND ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER; + dtype = v_engine->dtls_controller ? DTLS_TYPE_CLIENT : DTLS_TYPE_SERVER; xtype = DTLS_TYPE_RTP; if (v_engine->rtcp_mux > 0 && smh->mparams->rtcp_video_interval_msec) xtype |= DTLS_TYPE_RTCP; @@ -6715,14 +6742,18 @@ static const char *get_media_profile_name(switch_core_session_t *session, int se static char *get_setup(switch_rtp_engine_t *engine, switch_core_session_t *session, switch_sdp_type_t sdp_type) { + if (sdp_type == SDP_TYPE_REQUEST) { engine->dtls_controller = 0; + engine->new_dtls = 1; + engine->new_ice = 1; return "actpass"; } else { return engine->dtls_controller ? "active" : "passive"; } } + //? static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, switch_port_t port, const char *family, const char *ip, diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index 8614e17f14..de9e835a76 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -538,11 +538,11 @@ static inline void add_node(switch_jb_t *jb, switch_rtp_packet_t *packet, switch jb_debug(jb, (packet->header.m ? 1 : 2), "PUT packet last_ts:%u ts:%u seq:%u%s\n", ntohl(jb->highest_wrote_ts), ntohl(node->packet.header.ts), ntohs(node->packet.header.seq), packet->header.m ? " " : ""); - //if (jb->write_init && jb->type == SJB_VIDEO && ((abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq))) >= jb->max_frame_len) || - // (abs((int)((int64_t)ntohl(node->packet.header.ts) - (int64_t)ntohl(jb->highest_wrote_ts))) > (900000 * 5)))) { - // jb_debug(jb, 2, "CHANGE DETECTED, PUNT %u\n", abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq)))); - // switch_jb_reset(jb); - //} + if (jb->write_init && jb->type == SJB_VIDEO && ((abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq))) >= jb->max_frame_len) || + (abs((int)((int64_t)ntohl(node->packet.header.ts) - (int64_t)ntohl(jb->highest_wrote_ts))) > (900000 * 5)))) { + jb_debug(jb, 2, "CHANGE DETECTED, PUNT %u\n", abs(((int)ntohs(packet->header.seq) - ntohs(jb->highest_wrote_seq)))); + switch_jb_reset(jb); + } if (!jb->write_init || ntohs(packet->header.seq) > ntohs(jb->highest_wrote_seq) || (ntohs(jb->highest_wrote_seq) > USHRT_MAX - 10 && ntohs(packet->header.seq) <= 10) ) { @@ -797,11 +797,6 @@ SWITCH_DECLARE(void) switch_jb_reset(switch_jb_t *jb) jb->period_count = 0; jb->target_ts = 0; jb->last_target_ts = 0; - jb->frame_len = jb->min_frame_len; - - if (jb->channel) { - switch_channel_video_sync(jb->channel); - } switch_mutex_lock(jb->mutex); hide_nodes(jb); @@ -1034,11 +1029,19 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp switch_core_inthash_delete(jb->missing_seq_hash, (uint32_t)htons(got)); if (got > want) { - jb_debug(jb, 2, "GOT %u WANTED %u; MARK SEQS MISSING %u - %u\n", got, want, want, got - 1); + if (got - want > jb->max_frame_len && got - want > 17) { + jb_debug(jb, 2, "Missing %u frames, Resetting\n", got - want); + switch_jb_reset(jb); + if (jb->session) { + switch_core_session_request_video_refresh(jb->session); + } + } else { + jb_debug(jb, 2, "GOT %u WANTED %u; MARK SEQS MISSING %u - %u\n", got, want, want, got - 1); - for (i = want; i < got; i++) { - jb_debug(jb, 2, "MARK MISSING %u ts:%u\n", i, ntohl(packet->header.ts)); - switch_core_inthash_insert(jb->missing_seq_hash, (uint32_t)htons(i), (void *)(intptr_t)packet->header.ts); + for (i = want; i < got; i++) { + jb_debug(jb, 2, "MARK MISSING %u ts:%u\n", i, ntohl(packet->header.ts)); + switch_core_inthash_insert(jb->missing_seq_hash, (uint32_t)htons(i), (void *)(intptr_t)packet->header.ts); + } } } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index d40cb665f9..db772f061f 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -3259,7 +3259,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_dtls(switch_rtp_t *rtp_session, d dtls->ca = switch_core_sprintf(rtp_session->pool, "%s%sca-bundle.crt", SWITCH_GLOBAL_dirs.certs_dir, SWITCH_PATH_SEPARATOR); - dtls->ssl_ctx = SSL_CTX_new(DTLSv1_method()); + dtls->ssl_ctx = SSL_CTX_new((type & DTLS_TYPE_SERVER) ? DTLSv1_server_method() : DTLSv1_client_method()); switch_assert(dtls->ssl_ctx); bio = BIO_new_file(dtls->pem, "r");