From 0ad867f3ddad48004beb7dff4f497e6e42899377 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Thu, 14 Jun 2018 16:56:41 +0800 Subject: [PATCH] FS-11189 make rtp-slice-size and key-frame-min-freq configurable --- conf/vanilla/autoload_configs/vpx.conf.xml | 5 +++++ src/switch_vpx.c | 25 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/conf/vanilla/autoload_configs/vpx.conf.xml b/conf/vanilla/autoload_configs/vpx.conf.xml index cdf677710a..f20f984e01 100644 --- a/conf/vanilla/autoload_configs/vpx.conf.xml +++ b/conf/vanilla/autoload_configs/vpx.conf.xml @@ -3,6 +3,11 @@ + + + + + diff --git a/src/switch_vpx.c b/src/switch_vpx.c index ae1cc6ddab..eff164eae4 100644 --- a/src/switch_vpx.c +++ b/src/switch_vpx.c @@ -380,6 +380,9 @@ typedef struct vpx_context vpx_context_t; struct vpx_globals { int debug; uint32_t max_bitrate; + uint32_t rtp_slice_size; + uint32_t key_frame_min_freq; + char vp8_profile[20]; char vp9_profile[20]; char vp10_profile[20]; @@ -651,7 +654,7 @@ static switch_status_t consume_partition(vpx_context_t *context, switch_frame_t // if !extended hdrlen = 1; body = ((uint8_t *)frame->data) + hdrlen; - packet_size = SLICE_SIZE; + packet_size = vpx_globals.rtp_slice_size; payload_size = packet_size - hdrlen; // else add extended TBD @@ -820,7 +823,7 @@ static switch_status_t switch_vpx_encode(switch_codec_t *codec, switch_frame_t * if (context->need_key_frame > 0) { // force generate a key frame - if (!context->last_key_frame || (now - context->last_key_frame) > KEY_FRAME_MIN_FREQ) { + if (!context->last_key_frame || (now - context->last_key_frame) > vpx_globals.key_frame_min_freq) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "VPX KEYFRAME GENERATED\n"); vpx_flags |= VPX_EFLAG_FORCE_KF; context->need_key_frame = 0; @@ -1406,6 +1409,13 @@ static void load_config() if (!strcmp(name, "max-bitrate")) { vpx_globals.max_bitrate = switch_parse_bandwidth_string(value); + } else if (!strcmp(name, "rtp-slice-size")) { + int val = atoi(value); + vpx_globals.rtp_slice_size = UINTVAL(val); + } else if (!strcmp(name, "key-frame-min-freq")) { + int val = atoi(value); + vpx_globals.key_frame_min_freq = UINTVAL(val); + vpx_globals.key_frame_min_freq *= 1000; } else if (!strcmp(name, "dec-threads")) { vpx_globals.vp8.dec_cfg.threads = switch_parse_cpu_string(value); vpx_globals.vp9.dec_cfg.threads = switch_parse_cpu_string(value); @@ -1634,6 +1644,14 @@ static void load_config() vpx_globals.max_bitrate = switch_calc_bitrate(1920, 1080, 5, 60); } + if (vpx_globals.rtp_slice_size < 500 || vpx_globals.rtp_slice_size > 1500) { + vpx_globals.rtp_slice_size = SLICE_SIZE; + } + + if (vpx_globals.key_frame_min_freq < 10000 || vpx_globals.key_frame_min_freq > 3 * 1000000) { + vpx_globals.key_frame_min_freq = KEY_FRAME_MIN_FREQ; + } + if (!vpx_globals.vp8.enc_cfg.g_threads) vpx_globals.vp8.enc_cfg.g_threads = 1; if (!vpx_globals.vp8.dec_cfg.threads) vpx_globals.vp8.dec_cfg.threads = switch_parse_cpu_string("cpu/2/4"); if (!vpx_globals.vp9.enc_cfg.g_threads) vpx_globals.vp9.enc_cfg.g_threads = vpx_globals.vp8.enc_cfg.g_threads; @@ -1661,6 +1679,9 @@ SWITCH_STANDARD_API(vpx_api_function) load_config(); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %-26s = %d\n", "rtp-slice-size", vpx_globals.rtp_slice_size); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %-26s = %d\n", "key-frame-min-freq", vpx_globals.key_frame_min_freq); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %-26s = %d\n", "vp8-dec-threads", vpx_globals.vp8.dec_cfg.threads); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %-26s = %d\n", "vp9-dec-threads", vpx_globals.vp9.dec_cfg.threads); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %-26s = %d\n", "vp10-dec-threads", vpx_globals.vp10.dec_cfg.threads);