diff --git a/libs/sofia-sip/libsofia-sip-ua/sdp/sdp_parse.c b/libs/sofia-sip/libsofia-sip-ua/sdp/sdp_parse.c index d56bc9d23c..4a79bf3b36 100644 --- a/libs/sofia-sip/libsofia-sip-ua/sdp/sdp_parse.c +++ b/libs/sofia-sip/libsofia-sip-ua/sdp/sdp_parse.c @@ -921,13 +921,13 @@ static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result) } if (su_casematch(name, "CT")) - modifier = sdp_bw_ct, name = NULL; + modifier = sdp_bw_ct, name = "CT"; else if (su_casematch(name, "TIAS") == 1) - modifier = sdp_bw_tias, name = NULL; + modifier = sdp_bw_tias, name = "TIAS"; else if (su_casematch(name, "AS") == 1) - modifier = sdp_bw_as, name = NULL; + modifier = sdp_bw_as, name = "AS"; else - modifier = sdp_bw_x; + modifier = sdp_bw_x, name = "BW-X"; if (STRICT(p)) PARSE_CHECK_REST(p, r, "b"); diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index 5349e11708..87deb3d1a9 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -843,17 +843,19 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt } if (context->codec_settings.video.bandwidth) { - context->bandwidth = context->codec_settings.video.bandwidth * 8; + context->bandwidth = context->codec_settings.video.bandwidth; } else { - context->bandwidth = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 1, 15) * 8; + context->bandwidth = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 1, 15); } sane = switch_calc_bitrate(1920, 1080, 2, 30); - if (context->bandwidth / 8 > sane) { + if (context->bandwidth > sane) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "BITRATE TRUNCATED TO %d\n", sane); - context->bandwidth = sane * 8; + context->bandwidth = sane; } + + context->bandwidth *= 3; //context->encoder_ctx->bit_rate = context->bandwidth * 1024; context->encoder_ctx->width = context->codec_settings.video.width; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 85bd05b944..a3dba3cfd1 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -173,6 +173,7 @@ typedef struct switch_rtp_engine_s { switch_thread_id_t thread_id; uint8_t new_ice; uint8_t new_dtls; + uint32_t sdp_bw; } switch_rtp_engine_t; struct switch_media_handle_s { @@ -2646,20 +2647,29 @@ static void switch_core_session_parse_codec_settings(switch_core_session_t *sess switch(type) { case SWITCH_MEDIA_TYPE_AUDIO: break; - case SWITCH_MEDIA_TYPE_VIDEO: - { - const char *bwv = switch_channel_get_variable(session->channel, "rtp_video_max_bandwidth"); + case SWITCH_MEDIA_TYPE_VIDEO: { + uint32_t system_bw = 0; - if (!bwv) { - bwv = switch_channel_get_variable(session->channel, "rtp_video_max_bandwidth_out"); - } - - if (!bwv) { - bwv = "1mb"; - } - - engine->codec_settings.video.bandwidth = switch_parse_bandwidth_string(bwv); + const char *bwv = switch_channel_get_variable(session->channel, "rtp_video_max_bandwidth"); + + if (!bwv) { + bwv = switch_channel_get_variable(session->channel, "rtp_video_max_bandwidth_out"); } + + if (!bwv) { + bwv = "1mb"; + } + + system_bw = switch_parse_bandwidth_string(bwv); + + printf("%d %d\n", engine->sdp_bw, system_bw); + + if (engine->sdp_bw && engine->sdp_bw <= system_bw) { + engine->codec_settings.video.bandwidth = engine->sdp_bw; + } else { + engine->codec_settings.video.bandwidth = system_bw; + } + } break; default: break; @@ -4039,7 +4049,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s maxptime = atoi(attr->a_value); } else if (got_crypto < 1 && !strcasecmp(attr->a_name, "crypto") && !zstr(attr->a_value)) { int crypto_tag; - + if (!(smh->mparams->ndlb & SM_NDLB_ALLOW_CRYPTO_IN_AVP) && !switch_true(switch_channel_get_variable(session->channel, "rtp_allow_crypto_in_avp"))) { if (m->m_proto != sdp_proto_srtp && !got_webrtc) { @@ -4547,6 +4557,18 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s v_engine->rmode = sdp_media_flow(m->m_mode); if (sdp_type == SDP_TYPE_REQUEST) { + sdp_bandwidth_t *bw; + int tias = 0; + + for (bw = m->m_bandwidths; bw; bw = bw->b_next) { + if (bw->b_modifier == sdp_bw_as && !tias) { + v_engine->sdp_bw = bw->b_value / 1024; + } else if (bw->b_modifier == sdp_bw_tias) { + tias = 1; + v_engine->sdp_bw = bw->b_value / 1024; + } + } + switch(v_engine->rmode) { case SWITCH_MEDIA_FLOW_RECVONLY: switch_channel_set_variable(smh->session->channel, "video_media_flow", "sendonly"); diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 9be39f1fd7..a99690d95f 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -380,7 +380,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se int restart_limit_on_dtmf = 0; const char *prefix, *var, *video_file = NULL; int vid_play_file_flags = SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT | SWITCH_FILE_FLAG_VIDEO; - + int echo_on = 0; if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; @@ -575,6 +575,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se } if (!switch_test_flag(&vfh, SWITCH_FILE_OPEN)) { + echo_on = 1; + switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ); switch_channel_set_flag(channel, CF_VIDEO_ECHO); } @@ -654,8 +656,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, read_impl.microseconds_per_packet / 1000); if (switch_core_file_has_video(fh)) { - switch_channel_clear_flag(channel, CF_VIDEO_ECHO); - switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); + if (echo_on) { + switch_channel_clear_flag(channel, CF_VIDEO_ECHO); + switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); + echo_on = 0; + } switch_core_media_set_video_file(session, NULL, SWITCH_RW_READ); if (switch_test_flag(&vfh, SWITCH_FILE_OPEN)) { switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); @@ -867,10 +872,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se if (fill_cng || waste_resources) { switch_core_codec_destroy(&write_codec); } - + if (switch_core_file_has_video(fh)) { - switch_channel_clear_flag(channel, CF_VIDEO_ECHO); - switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); + if (echo_on) { + switch_channel_clear_flag(channel, CF_VIDEO_ECHO); + switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); + echo_on = 0; + } switch_core_media_set_video_file(session, NULL, SWITCH_RW_READ); if (switch_test_flag(&vfh, SWITCH_FILE_OPEN)) { switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE);