From 5d11524dcfd924f8cad7e65dc4fc67047fb2100b Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sat, 7 May 2016 10:18:40 +0800 Subject: [PATCH 1/2] FS-9137 update to openh264 release 1.5.0 and tweak some params --- src/mod/codecs/mod_openh264/mod_openh264.cpp | 33 ++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/mod/codecs/mod_openh264/mod_openh264.cpp b/src/mod/codecs/mod_openh264/mod_openh264.cpp index 0e8beaf100..2357779ee7 100644 --- a/src/mod/codecs/mod_openh264/mod_openh264.cpp +++ b/src/mod/codecs/mod_openh264/mod_openh264.cpp @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2015, Anthony Minessale II + * Copyright (C) 2005-2016, Anthony Minessale II * * Version: MPL 1.1 * @@ -43,7 +43,7 @@ #define NAL_HEADER_ADD_0X30BYTES 50 #endif -#define FPS 15.0f // frame rate +#define FPS 30.0f // frame rate #define H264_NALU_BUFFER_SIZE 65536 #define SLICE_SIZE SWITCH_DEFAULT_VIDEO_SIZE //NALU Slice Size @@ -80,6 +80,7 @@ typedef struct h264_codec_context_s { } h264_codec_context_t; int FillSpecificParameters(h264_codec_context_t *context) { + int sane = 0; SEncParamExt *param; param = &context->encoder_params; @@ -98,11 +99,16 @@ int FillSpecificParameters(h264_codec_context_t *context) { context->bandwidth = switch_calc_bitrate(context->codec_settings.video.width, context->codec_settings.video.height, 1, 15); } - if (context->bandwidth > 5120) { - context->bandwidth = 5120; + sane = switch_calc_bitrate(1920, 1080, 2, 30); + + if (context->bandwidth > sane) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "BITRATE TRUNCATED TO %d\n", sane); + context->bandwidth = sane; } - /* Test for temporal, spatial, SNR scalability */ + context->bandwidth *= 1024; + + param->fMaxFrameRate = FPS * 2; param->iPicWidth = context->codec_settings.video.width; // width of picture in samples param->iPicHeight = context->codec_settings.video.height; // height of picture in samples param->iTargetBitrate = context->bandwidth; @@ -132,18 +138,16 @@ int FillSpecificParameters(h264_codec_context_t *context) { int iIndexLayer = 0; param->sSpatialLayers[iIndexLayer].iVideoWidth = context->codec_settings.video.width; param->sSpatialLayers[iIndexLayer].iVideoHeight = context->codec_settings.video.height; - param->sSpatialLayers[iIndexLayer].fFrameRate = (double) (FPS * 1.0f); + param->sSpatialLayers[iIndexLayer].fFrameRate = FPS; // param->sSpatialLayers[iIndexLayer].iQualityLayerNum = 1; param->sSpatialLayers[iIndexLayer].iSpatialBitrate = param->iTargetBitrate; - //param->sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = param->iTargetBitrate; - //param->sSpatialLayers[iIndexLayer].uiLevelIdc = LEVEL_3_1; + param->sSpatialLayers[iIndexLayer].iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE; + param->sSpatialLayers[iIndexLayer].uiLevelIdc = LEVEL_4_1; param->sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_BASELINE; - param->iUsageType = CAMERA_VIDEO_REAL_TIME; param->bEnableFrameCroppingFlag = 1; - //param->iMaxBitrate = 1250000; - //param->iTargetBitrate = 1250000; + param->iMaxBitrate = UNSPECIFIED_BIT_RATE; #ifdef MT_ENABLED param->sSpatialLayers[iIndexLayer].sSliceCfg.uiSliceMode = SM_DYN_SLICE; @@ -513,7 +517,7 @@ static switch_status_t init_encoder(h264_codec_context_t *context, uint32_t widt } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Codec ready; picture size %dx%d Bandwidth: %d\n", - context->encoder_params.iPicWidth, context->encoder_params.iPicHeight, context->codec_settings.video.bandwidth); + context->encoder_params.iPicWidth, context->encoder_params.iPicHeight, context->bandwidth); context->encoder_initialized = SWITCH_TRUE; @@ -796,6 +800,10 @@ static switch_status_t switch_h264_destroy(switch_codec_t *codec) SWITCH_MODULE_LOAD_FUNCTION(mod_openh264_load) { switch_codec_interface_t *codec_interface; + OpenH264Version ver; + + ver = WelsGetCodecVersion(); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "OpenH264 version %u.%u.%u.%u\n", ver.uMajor, ver.uMinor, ver.uRevision, ver.uReserved); /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -804,7 +812,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openh264_load) switch_core_codec_add_video_implementation(pool, codec_interface, 99, "H264", NULL, switch_h264_init, switch_h264_encode, switch_h264_decode, switch_h264_control, switch_h264_destroy); - /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } From 8df7fe34673409639b5b914d1eeaca89bc87d0e7 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Thu, 9 Feb 2017 11:32:35 +0800 Subject: [PATCH 2/2] FS-9137 update to openh264 release 1.6.0 --- src/mod/codecs/mod_openh264/mod_openh264.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mod/codecs/mod_openh264/mod_openh264.cpp b/src/mod/codecs/mod_openh264/mod_openh264.cpp index 2357779ee7..b497ed2386 100644 --- a/src/mod/codecs/mod_openh264/mod_openh264.cpp +++ b/src/mod/codecs/mod_openh264/mod_openh264.cpp @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2016, Anthony Minessale II + * Copyright (C) 2005-2017, Anthony Minessale II * * Version: MPL 1.1 * @@ -150,8 +150,8 @@ int FillSpecificParameters(h264_codec_context_t *context) { param->iMaxBitrate = UNSPECIFIED_BIT_RATE; #ifdef MT_ENABLED - param->sSpatialLayers[iIndexLayer].sSliceCfg.uiSliceMode = SM_DYN_SLICE; - param->sSpatialLayers[iIndexLayer].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = SLICE_SIZE; + param->sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE; + param->sSpatialLayers[iIndexLayer].sSliceArgument.uiSliceSizeConstraint = SLICE_SIZE; param->uiMaxNalSize = SLICE_SIZE + NAL_HEADER_ADD_0X30BYTES; #else param->sSpatialLayers[iIndexLayer].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE; @@ -175,7 +175,6 @@ long set_decoder_options(ISVCDecoder *decoder) // EBufferProperty eOutputProperty = BUFFER_HOST; long ret = 0; - ret += decoder->SetOption(DECODER_OPTION_DATAFORMAT, &iColorFormat); // ret += decoder->SetOption(DECODER_OPTION_OUTPUT_PROPERTY, &eOutputProperty); return ret; @@ -458,7 +457,6 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag return SWITCH_STATUS_FALSE; } - context->decoder_params.eOutputColorFormat = videoFormatI420; context->decoder_params.uiTargetDqLayer = (uint8_t) -1; context->decoder_params.eEcActiveIdc = ERROR_CON_SLICE_COPY; context->decoder_params.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;