Message ID | 20230111104629.402504-1-jianfeng.zheng@mthreads.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v3] vaapi: support VAProfileH264High10 | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
On Wo, 2023-01-11 at 18:46 +0800, jianfeng.zheng wrote: > see https://github.com/intel/libva/pull/664 > > Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com> > --- > configure | 13 +++++++++++++ > libavcodec/h264_slice.c | 9 ++++++++- > libavcodec/vaapi_decode.c | 10 ++++++++++ > libavcodec/vaapi_encode_h264.c | 27 ++++++++++++++++++++++----- > 4 files changed, 53 insertions(+), 6 deletions(-) > > diff --git a/configure b/configure > index f08cdab3d1..ac199d97cb 100755 > --- a/configure > +++ b/configure > @@ -2410,6 +2410,7 @@ HAVE_LIST=" > texi2html > xmllint > zlib_gzip > + va_profile_h264_high10 > " > > # options emitted with CONFIG_ prefix but not available on the command line > @@ -6958,6 +6959,18 @@ if enabled vaapi; then > check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" > check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" > check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9" > + > + # > + # Using 'VA_CHECK_VERSION' in source codes make things easy. But we have > to wait > + # until newly added VAProfile being distributed by VAAPI released > version. > + # > + # Before or after that, we can use auto-detection to keep version > compatibility. > + # It always works. > + # > + disable va_profile_h264_high10 && enabled h264_vaapi_hwaccel > + test_code cc va/va.h "VAProfile p = VAProfileH264High10" && > + enable va_profile_h264_high10 > + VAProfileH264High10 was added into libva 2.18.0 (va-api 1.18.0) recently, could you use VA_CHECK_VERSION instead now ? > fi > > if enabled_all opencl libdrm ; then > diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c > index 420758ba0a..3abb671e99 100644 > --- a/libavcodec/h264_slice.c > +++ b/libavcodec/h264_slice.c > @@ -805,8 +805,15 @@ static enum AVPixelFormat get_pixel_format(H264Context > *h, int force_callback) > *fmt++ = AV_PIX_FMT_YUV444P10; > } else if (CHROMA422(h)) > *fmt++ = AV_PIX_FMT_YUV422P10; > - else > + else { > +#if CONFIG_H264_VAAPI_HWACCEL > + // Just add as candidate. Whether VAProfileH264High10 usable or > + // not is decided by vaapi_decode_make_config() defined in FFmpeg > + // and vaQueryCodingProfile() defined in libva. > + *fmt++ = AV_PIX_FMT_VAAPI; > +#endif > *fmt++ = AV_PIX_FMT_YUV420P10; > + } > break; > case 12: > if (CHROMA444(h)) { > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c > index 134f10eca5..048b27fde1 100644 > --- a/libavcodec/vaapi_decode.c > +++ b/libavcodec/vaapi_decode.c > @@ -402,6 +402,9 @@ static const struct { > H264ConstrainedBaseline), > MAP(H264, H264_MAIN, H264Main ), > MAP(H264, H264_HIGH, H264High ), > +#if HAVE_VA_PROFILE_H264_HIGH10 > + MAP(H264, H264_HIGH_10, H264High10 ), > +#endif > #if VA_CHECK_VERSION(0, 37, 0) > MAP(HEVC, HEVC_MAIN, HEVCMain ), > MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ), > @@ -510,6 +513,13 @@ static int vaapi_decode_make_config(AVCodecContext > *avctx, > if (exact_match) > break; > } > +#if HAVE_VA_PROFILE_H264_HIGH10 > + //incase 8bit stream being decoded under VAProfileH264High10 > + if (avctx->codec_id == AV_CODEC_ID_H264 && > + (avctx->profile == FF_PROFILE_H264_EXTENDED || avctx->profile == > FF_PROFILE_H264_BASELINE) && > + matched_va_profile == VAProfileH264High) > + break; > +#endif >> How about to take bit depth into account when finding out the matched va >> profile >> ? >> > This is just for deeling with bit depth issues when no va profile > matched for H.264 extended or baseline profile. Yes, I am aware that this special case is for bit depth issue. What I meant is we needn't this special case if we could take bit depth into account when setting matched_va_profile and matched_ff_profile below. matched_va_profile and matched_ff_profile should support the same bit depth. if (j < profile_count) { matched_va_profile = va_profile; matched_ff_profile = codec_profile; if (exact_match) break; } Thanks Haihao > } > av_freep(&profile_list); > > diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c > index dd17be2190..e99e13cb40 100644 > --- a/libavcodec/vaapi_encode_h264.c > +++ b/libavcodec/vaapi_encode_h264.c > @@ -23,6 +23,7 @@ > > #include "libavutil/avassert.h" > #include "libavutil/common.h" > +#include "libavutil/pixdesc.h" > #include "libavutil/internal.h" > #include "libavutil/opt.h" > > @@ -290,10 +291,21 @@ static int > vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) > H264RawPPS *pps = &priv->raw_pps; > VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; > VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params; > + const AVPixFmtDescriptor *desc; > + int bit_depth; > > memset(sps, 0, sizeof(*sps)); > memset(pps, 0, sizeof(*pps)); > > + desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); > + av_assert0(desc); > + if (desc->nb_components == 1 || desc->log2_chroma_w != 1 || desc- > >log2_chroma_h != 1) { > + av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format " > + "%s is not supported.\n", desc->name); > + return AVERROR(EINVAL); > + } > + bit_depth = desc->comp[0].depth; > + > sps->nal_unit_header.nal_ref_idc = 3; > sps->nal_unit_header.nal_unit_type = H264_NAL_SPS; > > @@ -303,11 +315,11 @@ static int > vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) > avctx->profile == FF_PROFILE_H264_MAIN) > sps->constraint_set1_flag = 1; > > - if (avctx->profile == FF_PROFILE_H264_HIGH) > + if (avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == > FF_PROFILE_H264_HIGH_10) > sps->constraint_set3_flag = ctx->gop_size == 1; > > if (avctx->profile == FF_PROFILE_H264_MAIN || > - avctx->profile == FF_PROFILE_H264_HIGH) { > + avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == > FF_PROFILE_H264_HIGH_10) { > sps->constraint_set4_flag = 1; > sps->constraint_set5_flag = ctx->b_per_p == 0; > } > @@ -348,6 +360,8 @@ static int > vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) > > sps->seq_parameter_set_id = 0; > sps->chroma_format_idc = 1; > + sps->bit_depth_luma_minus8 = bit_depth - 8; > + sps->bit_depth_chroma_minus8 = bit_depth - 8; > > sps->log2_max_frame_num_minus4 = 4; > sps->pic_order_cnt_type = 0; > @@ -1111,6 +1125,9 @@ static av_cold int > vaapi_encode_h264_configure(AVCodecContext *avctx) > } > > static const VAAPIEncodeProfile vaapi_encode_h264_profiles[] = { > +#if HAVE_VA_PROFILE_H264_HIGH10 > + { FF_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 }, > +#endif > { FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High }, > { FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main }, > { FF_PROFILE_H264_CONSTRAINED_BASELINE, > @@ -1175,10 +1192,9 @@ static av_cold int > vaapi_encode_h264_init(AVCodecContext *avctx) > av_log(avctx, AV_LOG_ERROR, "H.264 extended profile " > "is not supported.\n"); > return AVERROR_PATCHWELCOME; > - case FF_PROFILE_H264_HIGH_10: > case FF_PROFILE_H264_HIGH_10_INTRA: > - av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles " > - "are not supported.\n"); > + av_log(avctx, AV_LOG_ERROR, "H.264 high 10 intra profile " > + "is not supported.\n"); > return AVERROR_PATCHWELCOME; > case FF_PROFILE_H264_HIGH_422: > case FF_PROFILE_H264_HIGH_422_INTRA: > @@ -1267,6 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = { > { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) > }, > { PROFILE("main", FF_PROFILE_H264_MAIN) }, > { PROFILE("high", FF_PROFILE_H264_HIGH) }, > + { PROFILE("high10", FF_PROFILE_H264_HIGH_10) }, > #undef PROFILE > > { "level", "Set level (level_idc)",
Quoting jianfeng.zheng (2023-01-11 11:46:29) > see https://github.com/intel/libva/pull/664 > > Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com> > --- > configure | 13 +++++++++++++ > libavcodec/h264_slice.c | 9 ++++++++- > libavcodec/vaapi_decode.c | 10 ++++++++++ > libavcodec/vaapi_encode_h264.c | 27 ++++++++++++++++++++++----- > 4 files changed, 53 insertions(+), 6 deletions(-) The decoder and encoder changes should be in separate patches, as they are completely unrelated.
diff --git a/configure b/configure index f08cdab3d1..ac199d97cb 100755 --- a/configure +++ b/configure @@ -2410,6 +2410,7 @@ HAVE_LIST=" texi2html xmllint zlib_gzip + va_profile_h264_high10 " # options emitted with CONFIG_ prefix but not available on the command line @@ -6958,6 +6959,18 @@ if enabled vaapi; then check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9" + + # + # Using 'VA_CHECK_VERSION' in source codes make things easy. But we have to wait + # until newly added VAProfile being distributed by VAAPI released version. + # + # Before or after that, we can use auto-detection to keep version compatibility. + # It always works. + # + disable va_profile_h264_high10 && enabled h264_vaapi_hwaccel + test_code cc va/va.h "VAProfile p = VAProfileH264High10" && + enable va_profile_h264_high10 + fi if enabled_all opencl libdrm ; then diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 420758ba0a..3abb671e99 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -805,8 +805,15 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) *fmt++ = AV_PIX_FMT_YUV444P10; } else if (CHROMA422(h)) *fmt++ = AV_PIX_FMT_YUV422P10; - else + else { +#if CONFIG_H264_VAAPI_HWACCEL + // Just add as candidate. Whether VAProfileH264High10 usable or + // not is decided by vaapi_decode_make_config() defined in FFmpeg + // and vaQueryCodingProfile() defined in libva. + *fmt++ = AV_PIX_FMT_VAAPI; +#endif *fmt++ = AV_PIX_FMT_YUV420P10; + } break; case 12: if (CHROMA444(h)) { diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 134f10eca5..048b27fde1 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -402,6 +402,9 @@ static const struct { H264ConstrainedBaseline), MAP(H264, H264_MAIN, H264Main ), MAP(H264, H264_HIGH, H264High ), +#if HAVE_VA_PROFILE_H264_HIGH10 + MAP(H264, H264_HIGH_10, H264High10 ), +#endif #if VA_CHECK_VERSION(0, 37, 0) MAP(HEVC, HEVC_MAIN, HEVCMain ), MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ), @@ -510,6 +513,13 @@ static int vaapi_decode_make_config(AVCodecContext *avctx, if (exact_match) break; } +#if HAVE_VA_PROFILE_H264_HIGH10 + //incase 8bit stream being decoded under VAProfileH264High10 + if (avctx->codec_id == AV_CODEC_ID_H264 && + (avctx->profile == FF_PROFILE_H264_EXTENDED || avctx->profile == FF_PROFILE_H264_BASELINE) && + matched_va_profile == VAProfileH264High) + break; +#endif } av_freep(&profile_list); diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index dd17be2190..e99e13cb40 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -23,6 +23,7 @@ #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/pixdesc.h" #include "libavutil/internal.h" #include "libavutil/opt.h" @@ -290,10 +291,21 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) H264RawPPS *pps = &priv->raw_pps; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params; + const AVPixFmtDescriptor *desc; + int bit_depth; memset(sps, 0, sizeof(*sps)); memset(pps, 0, sizeof(*pps)); + desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); + av_assert0(desc); + if (desc->nb_components == 1 || desc->log2_chroma_w != 1 || desc->log2_chroma_h != 1) { + av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format " + "%s is not supported.\n", desc->name); + return AVERROR(EINVAL); + } + bit_depth = desc->comp[0].depth; + sps->nal_unit_header.nal_ref_idc = 3; sps->nal_unit_header.nal_unit_type = H264_NAL_SPS; @@ -303,11 +315,11 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) avctx->profile == FF_PROFILE_H264_MAIN) sps->constraint_set1_flag = 1; - if (avctx->profile == FF_PROFILE_H264_HIGH) + if (avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10) sps->constraint_set3_flag = ctx->gop_size == 1; if (avctx->profile == FF_PROFILE_H264_MAIN || - avctx->profile == FF_PROFILE_H264_HIGH) { + avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10) { sps->constraint_set4_flag = 1; sps->constraint_set5_flag = ctx->b_per_p == 0; } @@ -348,6 +360,8 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->seq_parameter_set_id = 0; sps->chroma_format_idc = 1; + sps->bit_depth_luma_minus8 = bit_depth - 8; + sps->bit_depth_chroma_minus8 = bit_depth - 8; sps->log2_max_frame_num_minus4 = 4; sps->pic_order_cnt_type = 0; @@ -1111,6 +1125,9 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx) } static const VAAPIEncodeProfile vaapi_encode_h264_profiles[] = { +#if HAVE_VA_PROFILE_H264_HIGH10 + { FF_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 }, +#endif { FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High }, { FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main }, { FF_PROFILE_H264_CONSTRAINED_BASELINE, @@ -1175,10 +1192,9 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "H.264 extended profile " "is not supported.\n"); return AVERROR_PATCHWELCOME; - case FF_PROFILE_H264_HIGH_10: case FF_PROFILE_H264_HIGH_10_INTRA: - av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles " - "are not supported.\n"); + av_log(avctx, AV_LOG_ERROR, "H.264 high 10 intra profile " + "is not supported.\n"); return AVERROR_PATCHWELCOME; case FF_PROFILE_H264_HIGH_422: case FF_PROFILE_H264_HIGH_422_INTRA: @@ -1267,6 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = { { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) }, { PROFILE("main", FF_PROFILE_H264_MAIN) }, { PROFILE("high", FF_PROFILE_H264_HIGH) }, + { PROFILE("high10", FF_PROFILE_H264_HIGH_10) }, #undef PROFILE { "level", "Set level (level_idc)",
see https://github.com/intel/libva/pull/664 Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com> --- configure | 13 +++++++++++++ libavcodec/h264_slice.c | 9 ++++++++- libavcodec/vaapi_decode.c | 10 ++++++++++ libavcodec/vaapi_encode_h264.c | 27 ++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 6 deletions(-)