diff --git a/plugins/obs-qsv11/QSV_Encoder.cpp b/plugins/obs-qsv11/QSV_Encoder.cpp index e3d7873ab..bad352106 100644 --- a/plugins/obs-qsv11/QSV_Encoder.cpp +++ b/plugins/obs-qsv11/QSV_Encoder.cpp @@ -397,6 +397,8 @@ enum qsv_cpu_platform qsv_get_cpu_platform() case 0x8e: case 0x9e: return QSV_CPU_PLATFORM_KBL; + case 0x66: + return QSV_CPU_PLATFORM_CNL; case 0x7d: case 0x7e: return QSV_CPU_PLATFORM_ICL; diff --git a/plugins/obs-qsv11/QSV_Encoder.h b/plugins/obs-qsv11/QSV_Encoder.h index e79bda42f..146b34c74 100644 --- a/plugins/obs-qsv11/QSV_Encoder.h +++ b/plugins/obs-qsv11/QSV_Encoder.h @@ -78,7 +78,8 @@ static const char *const qsv_usage_names[] = {"quality", "balanced", "speed", "veryslow", "slower", "slow", "medium", "fast", "faster", "veryfast", 0}; - +static const char *const qsv_latency_names[] = {"ultra-low", "low", "normal", + 0}; typedef struct qsv_t qsv_t; typedef struct { @@ -117,6 +118,7 @@ enum qsv_cpu_platform { QSV_CPU_PLATFORM_BDW, QSV_CPU_PLATFORM_SKL, QSV_CPU_PLATFORM_KBL, + QSV_CPU_PLATFORM_CNL, QSV_CPU_PLATFORM_ICL, QSV_CPU_PLATFORM_INTEL }; diff --git a/plugins/obs-qsv11/QSV_Encoder_Internal.cpp b/plugins/obs-qsv11/QSV_Encoder_Internal.cpp index 514b242f6..4de63b43e 100644 --- a/plugins/obs-qsv11/QSV_Encoder_Internal.cpp +++ b/plugins/obs-qsv11/QSV_Encoder_Internal.cpp @@ -211,6 +211,17 @@ bool QSV_Encoder_Internal::InitParams(qsv_param_t *pParams) m_mfxEncParams.mfx.FrameInfo.CropH = pParams->nHeight; m_mfxEncParams.mfx.GopRefDist = pParams->nbFrames + 1; + enum qsv_cpu_platform qsv_platform = qsv_get_cpu_platform(); + if ((qsv_platform >= QSV_CPU_PLATFORM_ICL) && + (pParams->nbFrames == 0) && + (m_ver.Major == 1 && m_ver.Minor >= 31)) { + m_mfxEncParams.mfx.LowPower = MFX_CODINGOPTION_ON; + if (pParams->nRateControl == MFX_RATECONTROL_LA_ICQ || + pParams->nRateControl == MFX_RATECONTROL_LA_HRD || + pParams->nRateControl == MFX_RATECONTROL_LA) + pParams->nRateControl = MFX_RATECONTROL_VBR; + } + m_mfxEncParams.mfx.RateControlMethod = pParams->nRateControl; switch (pParams->nRateControl) { @@ -268,10 +279,23 @@ bool QSV_Encoder_Internal::InitParams(qsv_param_t *pParams) m_co2.MBBRC = MFX_CODINGOPTION_ON; if (pParams->nbFrames > 1) m_co2.BRefType = MFX_B_REF_PYRAMID; + if (m_mfxEncParams.mfx.LowPower == MFX_CODINGOPTION_ON) { + m_co2.RepeatPPS = MFX_CODINGOPTION_OFF; + if (pParams->nRateControl == MFX_RATECONTROL_CBR || + pParams->nRateControl == MFX_RATECONTROL_VBR) { + m_co2.LookAheadDepth = pParams->nLADEPTH; + } + } extendedBuffers[iBuffers++] = (mfxExtBuffer *)&m_co2; } - if (pParams->bCQM) { + if (m_mfxEncParams.mfx.LowPower == MFX_CODINGOPTION_ON) { + memset(&m_co3, 0, sizeof(mfxExtCodingOption3)); + m_co3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3; + m_co3.Header.BufferSz = sizeof(m_co3); + m_co3.ScenarioInfo = MFX_SCENARIO_GAME_STREAMING; + extendedBuffers[iBuffers++] = (mfxExtBuffer *)&m_co3; + } else if (pParams->bCQM) { if (m_ver.Major == 1 && m_ver.Minor >= 16) { memset(&m_co3, 0, sizeof(mfxExtCodingOption3)); m_co3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3; @@ -297,6 +321,11 @@ bool QSV_Encoder_Internal::InitParams(qsv_param_t *pParams) else m_mfxEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY; + mfxStatus sts = m_pmfxENC->Query(&m_mfxEncParams, &m_mfxEncParams); + if (sts == MFX_ERR_UNSUPPORTED || sts == MFX_ERR_UNDEFINED_BEHAVIOR) { + m_mfxEncParams.mfx.LowPower = MFX_CODINGOPTION_OFF; + } + return true; } diff --git a/plugins/obs-qsv11/data/locale/en-US.ini b/plugins/obs-qsv11/data/locale/en-US.ini index 84b5e07c6..682c8098f 100644 --- a/plugins/obs-qsv11/data/locale/en-US.ini +++ b/plugins/obs-qsv11/data/locale/en-US.ini @@ -4,8 +4,9 @@ MaxBitrate="Max Bitrate" RateControl="Rate Control" KeyframeIntervalSec="Keyframe Interval (seconds, 0=auto)" Profile="Profile" -AsyncDepth="Async Depth" Accuracy="Accuracy" Convergence="Convergence" ICQQuality="ICQ Quality" -LookAheadDepth="Lookahead Depth" +Latency="Latency" +Latency.ToolTip="There is trade-off between latency and quality.\nIf your case prefers on quality, please select 'normal' mode, which may get > 2s end-to-end latency.\nIf your case requires < 500ms end-to-end latency, please select 'ultra-low' mode." +SubjectiveVideoEnhancements="Subjective Video Enhancements" diff --git a/plugins/obs-qsv11/libmfx/include/msdk/include/mfxstructures.h b/plugins/obs-qsv11/libmfx/include/msdk/include/mfxstructures.h index 4f1c27f48..229ad8ed4 100644 --- a/plugins/obs-qsv11/libmfx/include/msdk/include/mfxstructures.h +++ b/plugins/obs-qsv11/libmfx/include/msdk/include/mfxstructures.h @@ -642,7 +642,10 @@ enum { MFX_SCENARIO_VIDEO_CONFERENCE = 2, MFX_SCENARIO_ARCHIVE = 3, MFX_SCENARIO_LIVE_STREAMING = 4, - MFX_SCENARIO_CAMERA_CAPTURE = 5 + MFX_SCENARIO_CAMERA_CAPTURE = 5, + MFX_SCENARIO_VIDEO_SURVEILLANCE = 6, + MFX_SCENARIO_GAME_STREAMING = 7, + MFX_SCENARIO_REMOTE_GAMING = 8 }; /* ContentInfo */ diff --git a/plugins/obs-qsv11/obs-qsv11.c b/plugins/obs-qsv11/obs-qsv11.c index 5036f8312..cec074e35 100644 --- a/plugins/obs-qsv11/obs-qsv11.c +++ b/plugins/obs-qsv11/obs-qsv11.c @@ -160,7 +160,9 @@ static void obs_qsv_defaults(obs_data_t *settings) obs_data_set_default_int(settings, "la_depth", 15); obs_data_set_default_int(settings, "keyint_sec", 3); + obs_data_set_default_string(settings, "latency", "normal"); obs_data_set_default_int(settings, "bframes", 3); + obs_data_set_default_bool(settings, "enhancements", false); obs_data_set_default_bool(settings, "mbbrc", true); } @@ -176,21 +178,77 @@ static inline void add_strings(obs_property_t *list, const char *const *strings) #define TEXT_TARGET_BITRATE obs_module_text("Bitrate") #define TEXT_MAX_BITRATE obs_module_text("MaxBitrate") #define TEXT_PROFILE obs_module_text("Profile") -#define TEXT_ASYNC_DEPTH obs_module_text("AsyncDepth") +#define TEXT_LATENCY obs_module_text("Latency") #define TEXT_RATE_CONTROL obs_module_text("RateControl") #define TEXT_ACCURACY obs_module_text("Accuracy") #define TEXT_CONVERGENCE obs_module_text("Convergence") #define TEXT_ICQ_QUALITY obs_module_text("ICQQuality") -#define TEXT_LA_DEPTH obs_module_text("LookAheadDepth") #define TEXT_KEYINT_SEC obs_module_text("KeyframeIntervalSec") #define TEXT_BFRAMES obs_module_text("B Frames") -#define TEXT_MBBRC obs_module_text("Content Adaptive Quantization") +#define TEXT_PERCEPTUAL_ENHANCEMENTS \ + obs_module_text("SubjectiveVideoEnhancements") static inline bool is_skl_or_greater_platform() { enum qsv_cpu_platform plat = qsv_get_cpu_platform(); return (plat >= QSV_CPU_PLATFORM_SKL); } + +static bool update_latency(obs_data_t *settings) +{ + int async_depth = (int)obs_data_get_int(settings, "async_depth"); + int la_depth = (int)obs_data_get_int(settings, "la_depth"); + + if (async_depth > 0 || la_depth > 0) { + const char *rate_control = + obs_data_get_string(settings, "rate_control"); + + bool lookahead = astrcmpi(rate_control, "LA_CBR") == 0 || + astrcmpi(rate_control, "LA_VBR") == 0 || + astrcmpi(rate_control, "LA_ICQ") == 0; + + if (lookahead) { + if (la_depth == 0 || la_depth >= 15) + obs_data_set_string(settings, "latency", + "normal"); + else + obs_data_set_string(settings, "latency", "low"); + } else { + if (async_depth != 1) + obs_data_set_string(settings, "latency", + "normal"); + else + obs_data_set_string(settings, "latency", + "ultra-low"); + } + + obs_data_erase(settings, "async_depth"); + obs_data_erase(settings, "la_depth"); + } + + return true; +} + +static bool update_enhancements(obs_data_t *settings) +{ + bool mbbrc = true; + if (obs_data_item_byname(settings, "mbbrc") != NULL) { + mbbrc = (bool)obs_data_get_bool(settings, "mbbrc"); + obs_data_erase(settings, "mbbrc"); + } + + bool cqm = false; + if (obs_data_item_byname(settings, "CQM") != NULL) { + cqm = (bool)obs_data_get_bool(settings, "CQM"); + obs_data_erase(settings, "CQM"); + } + + bool enabled = (mbbrc && cqm); + obs_data_set_bool(settings, "enhancements", enabled); + + return true; +} + static bool rate_control_modified(obs_properties_t *ppts, obs_property_t *p, obs_data_t *settings) { @@ -227,17 +285,13 @@ static bool rate_control_modified(obs_properties_t *ppts, obs_property_t *p, p = obs_properties_get(ppts, "icq_quality"); obs_property_set_visible(p, bVisible); - bVisible = astrcmpi(rate_control, "LA_ICQ") == 0 || - astrcmpi(rate_control, "LA_CBR") == 0 || - astrcmpi(rate_control, "LA_VBR") == 0; - p = obs_properties_get(ppts, "la_depth"); + bVisible = astrcmpi(rate_control, "CBR") == 0 || + astrcmpi(rate_control, "VBR") == 0; + p = obs_properties_get(ppts, "enhancements"); obs_property_set_visible(p, bVisible); - bVisible = astrcmpi(rate_control, "CBR") == 0 || - astrcmpi(rate_control, "VBR") == 0 || - astrcmpi(rate_control, "AVBR") == 0; - p = obs_properties_get(ppts, "mbbrc"); - obs_property_set_visible(p, bVisible); + update_latency(settings); + update_enhancements(settings); return true; } @@ -285,7 +339,6 @@ static obs_properties_t *obs_qsv_props(void *unused) obs_property_set_modified_callback(list, profile_modified); obs_properties_add_int(props, "keyint_sec", TEXT_KEYINT_SEC, 1, 20, 1); - obs_properties_add_int(props, "async_depth", TEXT_ASYNC_DEPTH, 1, 7, 1); list = obs_properties_add_list(props, "rate_control", TEXT_RATE_CONTROL, OBS_COMBO_TYPE_LIST, @@ -310,13 +363,18 @@ static obs_properties_t *obs_qsv_props(void *unused) obs_properties_add_int(props, "qpb", "QPB", 1, 51, 1); obs_properties_add_int(props, "icq_quality", TEXT_ICQ_QUALITY, 1, 51, 1); - obs_properties_add_int(props, "la_depth", TEXT_LA_DEPTH, 10, 100, 1); + list = obs_properties_add_list(props, "latency", TEXT_LATENCY, + OBS_COMBO_TYPE_LIST, + OBS_COMBO_FORMAT_STRING); + add_strings(list, qsv_latency_names); + obs_property_set_long_description(list, + obs_module_text("Latency.ToolTip")); + obs_properties_add_int(props, "bframes", TEXT_BFRAMES, 0, 3, 1); if (is_skl_or_greater_platform()) - obs_properties_add_bool(props, "mbbrc", TEXT_MBBRC); - - obs_properties_add_bool(props, "CQM", "Customized quantization matrix"); + obs_properties_add_bool(props, "enhancements", + TEXT_PERCEPTUAL_ENHANCEMENTS); return props; } @@ -325,13 +383,15 @@ static void update_params(struct obs_qsv *obsqsv, obs_data_t *settings) { video_t *video = obs_encoder_video(obsqsv->encoder); const struct video_output_info *voi = video_output_get_info(video); + update_latency(settings); + update_enhancements(settings); const char *target_usage = obs_data_get_string(settings, "target_usage"); const char *profile = obs_data_get_string(settings, "profile"); const char *rate_control = obs_data_get_string(settings, "rate_control"); - int async_depth = (int)obs_data_get_int(settings, "async_depth"); + const char *latency = obs_data_get_string(settings, "latency"); int target_bitrate = (int)obs_data_get_int(settings, "bitrate"); int max_bitrate = (int)obs_data_get_int(settings, "max_bitrate"); int accuracy = (int)obs_data_get_int(settings, "accuracy"); @@ -340,11 +400,10 @@ static void update_params(struct obs_qsv *obsqsv, obs_data_t *settings) int qpp = (int)obs_data_get_int(settings, "qpp"); int qpb = (int)obs_data_get_int(settings, "qpb"); int icq_quality = (int)obs_data_get_int(settings, "icq_quality"); - int la_depth = (int)obs_data_get_int(settings, "la_depth"); int keyint_sec = (int)obs_data_get_int(settings, "keyint_sec"); bool cbr_override = obs_data_get_bool(settings, "cbr"); int bFrames = (int)obs_data_get_int(settings, "bframes"); - bool mbbrc = obs_data_get_bool(settings, "mbbrc"); + bool enhancements = obs_data_get_bool(settings, "enhancements"); if (obs_data_has_user_value(settings, "bf")) bFrames = (int)obs_data_get_int(settings, "bf"); @@ -413,13 +472,30 @@ static void update_params(struct obs_qsv *obsqsv, obs_data_t *settings) else if (astrcmpi(rate_control, "LA_CBR") == 0) obsqsv->params.nRateControl = MFX_RATECONTROL_LA_HRD; - obsqsv->params.nAsyncDepth = (mfxU16)async_depth; + if (astrcmpi(latency, "ultra-low") == 0) { + obsqsv->params.nAsyncDepth = 1; + obsqsv->params.nLADEPTH = (mfxU16)0; + } else if (astrcmpi(latency, "low") == 0) { + obsqsv->params.nAsyncDepth = 4; + obsqsv->params.nLADEPTH = + (mfxU16)(voi->fps_num / voi->fps_den / 2); + } else if (astrcmpi(latency, "normal") == 0) { + obsqsv->params.nAsyncDepth = 4; + obsqsv->params.nLADEPTH = (mfxU16)(voi->fps_num / voi->fps_den); + } + + if (obsqsv->params.nLADEPTH > 0) { + if (obsqsv->params.nLADEPTH > 100) + obsqsv->params.nLADEPTH = 100; + else if (obsqsv->params.nLADEPTH < 10) + obsqsv->params.nLADEPTH = 10; + } + obsqsv->params.nAccuracy = (mfxU16)accuracy; obsqsv->params.nConvergence = (mfxU16)convergence; obsqsv->params.nQPI = (mfxU16)qpi; obsqsv->params.nQPP = (mfxU16)qpp; obsqsv->params.nQPB = (mfxU16)qpb; - obsqsv->params.nLADEPTH = (mfxU16)la_depth; obsqsv->params.nTargetBitRate = (mfxU16)target_bitrate; obsqsv->params.nMaxBitRate = (mfxU16)max_bitrate; obsqsv->params.nWidth = (mfxU16)width; @@ -429,7 +505,8 @@ static void update_params(struct obs_qsv *obsqsv, obs_data_t *settings) obsqsv->params.nbFrames = (mfxU16)bFrames; obsqsv->params.nKeyIntSec = (mfxU16)keyint_sec; obsqsv->params.nICQQuality = (mfxU16)icq_quality; - obsqsv->params.bMBBRC = mbbrc; + obsqsv->params.bMBBRC = enhancements; + obsqsv->params.bCQM = enhancements; info("settings:\n\trate_control: %s", rate_control); @@ -469,8 +546,6 @@ static void update_params(struct obs_qsv *obsqsv, obs_data_t *settings) "\theight: %d", voi->fps_num, voi->fps_den, width, height); - obsqsv->params.bCQM = (bool)obs_data_get_bool(settings, "CQM"); - info("debug info:"); }