From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6383549CBC for ; Fri, 8 Mar 2024 08:47:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD78F68CDB9; Fri, 8 Mar 2024 10:47:26 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25DBF68C9F8 for ; Fri, 8 Mar 2024 10:47:19 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709887645; x=1741423645; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zypl6DwsPOHSDiSkC06YfU2RwUcH/gjcxKic+GoA/Kk=; b=enNsMlGtm/h6y960bkrbTo32apmpKgkdT3l135aIBuHlkV/Yp3KaAVy7 kAuf+em+ludyVvbXZiNZ6tVNw12xLkpYNnd18+FCq25V5D/i1zU9fNta9 Fl5jqu4zOf4kJRUAvqpL3YVyz+Qagps61qDFSoMkM3MNC21yYDm9eusyk ukGsH3XaUMeOklT4eG/ht+7zKp5bjigPi2csjBwrbBZNmNs/QQ6NDQkfS 5NuKGiqZnsAKvg5X6hywRpQvtPMPDL6az1x8ar/NgZIeh3LJXLGFsT3cd Ixhyjcc+YfyQo2NsHI32sLMjgEBpdcL9snwQonDN7FYwh+lIb/GkmB3wU w==; X-IronPort-AV: E=McAfee;i="6600,9927,11006"; a="8417617" X-IronPort-AV: E=Sophos;i="6.07,109,1708416000"; d="scan'208";a="8417617" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2024 00:47:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,109,1708416000"; d="scan'208";a="10485855" Received: from t-dg2.sh.intel.com ([10.239.159.57]) by fmviesa008.fm.intel.com with ESMTP; 08 Mar 2024 00:47:12 -0800 From: fei.w.wang-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Mar 2024 16:47:23 +0800 Message-Id: <20240308084723.70916-2-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308084723.70916-1-fei.w.wang@intel.com> References: <20240308084723.70916-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] lavc/vaapi_encode_h265: Set general_*_constriaint flags with profile X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: fei.w.wang@intel.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Fei Wang According to Table A.2 in spec. Signed-off-by: Fei Wang --- libavcodec/vaapi_encode_h265.c | 181 +++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 53 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 43755e2188..7c9916eac8 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -258,6 +258,129 @@ fail: return err; } +static int vaapi_encode_h265_init_ptl(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + VAAPIEncodeH265Context *priv = avctx->priv_data; + H265RawVPS *vps = &priv->raw_vps; + H265RawProfileTierLevel *ptl = &vps->profile_tier_level; + + ptl->general_profile_space = 0; + ptl->general_profile_idc = avctx->profile; + ptl->general_tier_flag = priv->tier; + + ptl->general_profile_compatibility_flag[ptl->general_profile_idc] = 1; + + if (ptl->general_profile_compatibility_flag[1]) + ptl->general_profile_compatibility_flag[2] = 1; + if (ptl->general_profile_compatibility_flag[3]) { + ptl->general_profile_compatibility_flag[1] = 1; + ptl->general_profile_compatibility_flag[2] = 1; + } + + ptl->general_progressive_source_flag = 1; + ptl->general_interlaced_source_flag = 0; + ptl->general_non_packed_constraint_flag = 1; + ptl->general_frame_only_constraint_flag = 1; + + if (avctx->profile >= 4) { + ptl->general_intra_constraint_flag = ctx->gop_size == 1; + ptl->general_one_picture_only_constraint_flag = 0; + ptl->general_lower_bit_rate_constraint_flag = 1; + + switch (ctx->va_profile) { +#if VA_CHECK_VERSION(1, 2, 0) + case VAProfileHEVCMain12: + // Main 12 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 0; + ptl->general_max_8bit_constraint_flag = 0; + ptl->general_max_422chroma_constraint_flag = 1; + ptl->general_max_420chroma_constraint_flag = 1; + ptl->general_max_monochrome_constraint_flag = 0; + break; + case VAProfileHEVCMain422_10: + // Main 4:2:2 10 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 1; + ptl->general_max_8bit_constraint_flag = 0; + ptl->general_max_422chroma_constraint_flag = 1; + ptl->general_max_420chroma_constraint_flag = 0; + ptl->general_max_monochrome_constraint_flag = 0; + break; + case VAProfileHEVCMain422_12: + // Main 4:2:2 12 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 0; + ptl->general_max_8bit_constraint_flag = 0; + ptl->general_max_422chroma_constraint_flag = 1; + ptl->general_max_420chroma_constraint_flag = 0; + ptl->general_max_monochrome_constraint_flag = 0; + break; + case VAProfileHEVCMain444: + // Main 4:4:4 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 1; + ptl->general_max_8bit_constraint_flag = 1; + ptl->general_max_422chroma_constraint_flag = 0; + ptl->general_max_420chroma_constraint_flag = 0; + ptl->general_max_monochrome_constraint_flag = 0; + break; + case VAProfileHEVCMain444_10: + // Main 4:4:4 10 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 1; + ptl->general_max_8bit_constraint_flag = 0; + ptl->general_max_422chroma_constraint_flag = 0; + ptl->general_max_420chroma_constraint_flag = 0; + ptl->general_max_monochrome_constraint_flag = 0; + break; + case VAProfileHEVCMain444_12: + // Main 4:4:4 12 + ptl->general_max_14bit_constraint_flag = 0; + ptl->general_max_12bit_constraint_flag = 1; + ptl->general_max_10bit_constraint_flag = 0; + ptl->general_max_8bit_constraint_flag = 0; + ptl->general_max_422chroma_constraint_flag = 0; + ptl->general_max_420chroma_constraint_flag = 0; + ptl->general_max_monochrome_constraint_flag = 0; + break; +#endif + default: + av_log(avctx, AV_LOG_ERROR, "Unknown profile to init PTL.\n"); + return AVERROR(EINVAL); + } + } + + if (avctx->level != AV_LEVEL_UNKNOWN) { + ptl->general_level_idc = avctx->level; + } else { + const H265LevelDescriptor *level; + + level = ff_h265_guess_level(ptl, avctx->bit_rate, + ctx->surface_width, ctx->surface_height, + ctx->nb_slices, ctx->tile_rows, ctx->tile_cols, + (ctx->b_per_p > 0) + 1); + if (level) { + av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); + ptl->general_level_idc = level->level_idc; + } else { + av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to " + "any normal level; using level 8.5.\n"); + ptl->general_level_idc = 255; + // The tier flag must be set in level 8.5. + ptl->general_tier_flag = 1; + } + } + + return 0; +} + static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -265,13 +388,12 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) H265RawVPS *vps = &priv->raw_vps; H265RawSPS *sps = &priv->raw_sps; H265RawPPS *pps = &priv->raw_pps; - H265RawProfileTierLevel *ptl = &vps->profile_tier_level; H265RawVUI *vui = &sps->vui; VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params; const AVPixFmtDescriptor *desc; int chroma_format, bit_depth; - int i; + int i, err; memset(vps, 0, sizeof(*vps)); memset(sps, 0, sizeof(*sps)); @@ -314,57 +436,10 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) vps->vps_max_sub_layers_minus1 = 0; vps->vps_temporal_id_nesting_flag = 1; - ptl->general_profile_space = 0; - ptl->general_profile_idc = avctx->profile; - ptl->general_tier_flag = priv->tier; - - ptl->general_profile_compatibility_flag[ptl->general_profile_idc] = 1; - - if (ptl->general_profile_compatibility_flag[1]) - ptl->general_profile_compatibility_flag[2] = 1; - if (ptl->general_profile_compatibility_flag[3]) { - ptl->general_profile_compatibility_flag[1] = 1; - ptl->general_profile_compatibility_flag[2] = 1; - } - - ptl->general_progressive_source_flag = 1; - ptl->general_interlaced_source_flag = 0; - ptl->general_non_packed_constraint_flag = 1; - ptl->general_frame_only_constraint_flag = 1; - - ptl->general_max_14bit_constraint_flag = bit_depth <= 14; - ptl->general_max_12bit_constraint_flag = bit_depth <= 12; - ptl->general_max_10bit_constraint_flag = bit_depth <= 10; - ptl->general_max_8bit_constraint_flag = bit_depth == 8; - - ptl->general_max_422chroma_constraint_flag = chroma_format <= 2; - ptl->general_max_420chroma_constraint_flag = chroma_format <= 1; - ptl->general_max_monochrome_constraint_flag = chroma_format == 0; - - ptl->general_intra_constraint_flag = ctx->gop_size == 1; - ptl->general_one_picture_only_constraint_flag = 0; - - ptl->general_lower_bit_rate_constraint_flag = 1; - - if (avctx->level != AV_LEVEL_UNKNOWN) { - ptl->general_level_idc = avctx->level; - } else { - const H265LevelDescriptor *level; - - level = ff_h265_guess_level(ptl, avctx->bit_rate, - ctx->surface_width, ctx->surface_height, - ctx->nb_slices, ctx->tile_rows, ctx->tile_cols, - (ctx->b_per_p > 0) + 1); - if (level) { - av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); - ptl->general_level_idc = level->level_idc; - } else { - av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to " - "any normal level; using level 8.5.\n"); - ptl->general_level_idc = 255; - // The tier flag must be set in level 8.5. - ptl->general_tier_flag = 1; - } + err = vaapi_encode_h265_init_ptl(avctx); + if (err < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to init PTL.\n"); + return err; } vps->vps_sub_layer_ordering_info_present_flag = 0; -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".