From e95f3686adaedf2c89af18d2e0d4bae90adf776d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 18 Nov 2015 10:31:30 -0600 Subject: [PATCH] FS-8053 #resolve [When WebRTC's SDP contains a=sendonly for video, the client will still receive the video stream] --- src/mod/codecs/mod_vpx/mod_vpx.c | 22 ++++++++++++++++++---- src/switch_core_media.c | 4 ++++ src/switch_rtp.c | 20 +++++++++++++------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/mod/codecs/mod_vpx/mod_vpx.c b/src/mod/codecs/mod_vpx/mod_vpx.c index e1311b8f84..c772baa457 100644 --- a/src/mod/codecs/mod_vpx/mod_vpx.c +++ b/src/mod/codecs/mod_vpx/mod_vpx.c @@ -227,6 +227,7 @@ struct vpx_context { uint8_t decoder_init; switch_buffer_t *vpx_packet_buffer; int got_key_frame; + int no_key_frame; int got_start_frame; uint32_t last_received_timestamp; switch_bool_t last_received_complete_picture; @@ -273,6 +274,7 @@ static switch_status_t init_decoder(switch_codec_t *codec) context->last_received_complete_picture = 0; context->decoder_init = 1; context->got_key_frame = 0; + context->no_key_frame = 0; context->got_start_frame = 0; // 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; @@ -812,7 +814,18 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * is_start = (*(unsigned char *)frame->data & 0x10); is_keyframe = IS_VP8_KEY_FRAME((uint8_t *)frame->data); } - + + + if (context->got_key_frame <= 0) { + context->no_key_frame++; + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no keyframe, %d\n", context->no_key_frame); + if (context->no_key_frame > 50) { + if ((is_keyframe = is_start)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no keyframe, treating start as key.\n"); + } + } + } + // if (is_keyframe) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "got key %d\n", is_keyframe); if (context->need_decoder_reset != 0) { @@ -845,9 +858,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * if (is_keyframe) { if (context->got_key_frame <= 0) { context->got_key_frame = 1; - if (!is_keyframe) { - get_refresh = 1; - } + context->no_key_frame = 0; } else { context->got_key_frame++; } @@ -855,6 +866,9 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * 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); } + + get_refresh = 1; + if (!context->got_start_frame) { switch_goto_status(SWITCH_STATUS_MORE_DATA, end); } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index dbec5b0d95..fa989e092d 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -3430,6 +3430,10 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t if (switch_channel_test_flag(smh->session->channel, CF_REINVITE)) { + if (v_engine->remote_ssrc) { + switch_rtp_set_remote_ssrc(v_engine->rtp_session, v_engine->remote_ssrc); + } + if (switch_rtp_ready(engine->rtp_session) && engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready && engine->new_ice) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_INFO, "RE-Activating %s ICE\n", type2str(type)); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3175e56e47..c04d626a59 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2266,7 +2266,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session) rtcp_bytes = sbytes; } #endif -//#define DEBUG_EXTRA + //#define DEBUG_EXTRA #ifdef DEBUG_EXTRA { const char *old_host; @@ -2740,6 +2740,17 @@ SWITCH_DECLARE(void) switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session rtp_session->max_missed_packets = max; } +SWITCH_DECLARE(void) switch_rtp_reset_vb(switch_rtp_t *rtp_session) +{ + if (rtp_session->vb) { + switch_jb_reset(rtp_session->vb); + } + + if (rtp_session->vbw) { + switch_jb_reset(rtp_session->vbw); + } +} + SWITCH_DECLARE(void) switch_rtp_reset(switch_rtp_t *rtp_session) { if (!rtp_session) { @@ -2762,12 +2773,7 @@ SWITCH_DECLARE(void) switch_rtp_reset(switch_rtp_t *rtp_session) rtcp_stats_init(rtp_session); if (rtp_session->ice.ready) { - if (rtp_session->vb) { - switch_jb_reset(rtp_session->vb); - } - if (rtp_session->vbw) { - switch_jb_reset(rtp_session->vbw); - } + switch_rtp_reset_vb(rtp_session); rtp_session->ice.ready = rtp_session->ice.rready = 0; }