static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t width, uint32_t height)
{
-
+ int sane = 0;
+
if (!context->encoder) context->encoder = avcodec_find_encoder(context->av_codec_id);
if (!context->encoder) {
context->bandwidth = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 0, 0) * 8;
}
+ if (context->bandwidth > sane) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "BITRATE TRUNCATED TO %d\n", sane);
+ context->bandwidth = sane * 8;
+ }
+
//context->encoder_ctx->bit_rate = context->bandwidth * 1024;
context->encoder_ctx->width = context->codec_settings.video.width;
context->encoder_ctx->height = context->codec_settings.video.height;
vpx_codec_enc_cfg_t *config = &context->config;
int token_parts = 1;
int cpus = switch_core_cpu_count();
-
+ int sane;
+
if (!context->codec_settings.video.width) {
context->codec_settings.video.width = 1280;
}
if (context->codec_settings.video.bandwidth == -1) {
context->codec_settings.video.bandwidth = 0;
}
-
+
if (context->codec_settings.video.bandwidth) {
context->bandwidth = context->codec_settings.video.bandwidth;
} else {
context->bandwidth = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 0, 0);
+
}
- if (context->bandwidth > 40960) {
- context->bandwidth = 40960;
+ sane = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 4, 30);
+
+ if (context->bandwidth > sane) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_WARNING, "BITRATE TRUNCATED TO %d\n", sane);
+ context->bandwidth = sane;
}
context->pkt = NULL;
}
if ((bandwidth = cJSON_GetObjectItem(dialog, "outgoingBandwidth"))) {
+ int core_bw = 0, bwval = 0;
+ const char *val;
+
+ if ((val = switch_channel_get_variable_dup(channel, "rtp_video_max_bandwidth_in", SWITCH_FALSE, -1))) {
+ core_bw = switch_parse_bandwidth_string(val);
+ }
+
if (!zstr(bandwidth->valuestring) && strcasecmp(bandwidth->valuestring, "default")) {
- switch_channel_set_variable(channel, "rtp_video_max_bandwidth_in", bandwidth->valuestring);
+ bwval = atoi(bandwidth->valuestring);
} else if (bandwidth->valueint) {
- switch_channel_set_variable_printf(channel, "rtp_video_max_bandwidth_in", "%d", bandwidth->valueint);
+ bwval = bandwidth->valueint;
+ }
+
+ if (bwval <= 0 || (core_bw && bwval < core_bw)) {
+ switch_channel_set_variable_printf(channel, "rtp_video_max_bandwidth_in", "%d", bwval);
}
}
if ((bandwidth = cJSON_GetObjectItem(dialog, "incomingBandwidth"))) {
+ int core_bw = 0, bwval = 0;
+ const char *val;
+
+ if ((val = switch_channel_get_variable_dup(channel, "rtp_video_max_bandwidth_out", SWITCH_FALSE, -1))) {
+ core_bw = switch_parse_bandwidth_string(val);
+ }
+
if (!zstr(bandwidth->valuestring) && strcasecmp(bandwidth->valuestring, "default")) {
- switch_channel_set_variable(channel, "rtp_video_max_bandwidth_out", bandwidth->valuestring);
+ bwval = atoi(bandwidth->valuestring);
} else if (bandwidth->valueint) {
- switch_channel_set_variable_printf(channel, "rtp_video_max_bandwidth_out", "%d", bandwidth->valueint);
+ bwval = bandwidth->valueint;
+ }
+
+ if (bwval <= 0 || (core_bw && bwval < core_bw)) {
+ switch_channel_set_variable_printf(channel, "rtp_video_max_bandwidth_out", "%d", bwval);
}
}