From 8486f82d980188ca86d468b6bda0e1d9e2cffdaf Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 3 Apr 2020 14:53:40 +0800 Subject: [PATCH] libs: encoder: h265: Add support for MAIN 4:2:2 10 profile. Using YUY2 as the input of the encoder can generate main 4:2:2 bit streams and using Y210 as the input of the encoder can generate main 4:2:2 10 bit streams. Part-of: --- gst-libs/gst/vaapi/gstvaapiencoder.c | 3 ++- gst-libs/gst/vaapi/gstvaapiencoder_h265.c | 26 +++++++++++++++++++++-- gst-libs/gst/vaapi/gstvaapiutils_h265.c | 2 ++ gst/vaapi/gstvaapiencode_h265.c | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index d989bde6be..ec71fec2b9 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -668,7 +668,8 @@ is_chroma_type_supported (GstVaapiEncoder * encoder) cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV422 && cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV420_10BPP && cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV444 && - cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV444_10BPP) + cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV444_10BPP && + cip->chroma_type != GST_VAAPI_CHROMA_TYPE_YUV422_10BPP) goto unsupported; if (!get_config_attribute (encoder, VAConfigAttribRTFormat, &format)) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index dd785f4cb8..c5712efefd 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -305,8 +305,8 @@ bs_write_profile_tier_level (GstBitWriter * bs, /* additional indications specified for general_profile_idc from 4~10 */ if (seq_param->general_profile_idc == 4) { /* In A.3.5, Format range extensions profiles. - Just support main444 and main444-10 profile now, may add more profiles - when needed. */ + Just support main444, main444-10 and main422-10 profile now, may add + more profiles when needed. */ switch (profile) { case GST_VAAPI_PROFILE_H265_MAIN_444: /* max_12bit_constraint_flag */ @@ -348,6 +348,26 @@ bs_write_profile_tier_level (GstBitWriter * bs, /* lower_bit_rate_constraint_flag */ WRITE_UINT32 (bs, 1, 1); break; + case GST_VAAPI_PROFILE_H265_MAIN_422_10: + /* max_12bit_constraint_flag */ + WRITE_UINT32 (bs, 1, 1); + /* max_10bit_constraint_flag */ + WRITE_UINT32 (bs, 1, 1); + /* max_8bit_constraint_flag */ + WRITE_UINT32 (bs, 0, 1); + /* max_422chroma_constraint_flag */ + WRITE_UINT32 (bs, 1, 1); + /* max_420chroma_constraint_flag */ + WRITE_UINT32 (bs, 0, 1); + /* max_monochrome_constraint_flag */ + WRITE_UINT32 (bs, 0, 1); + /* intra_constraint_flag */ + WRITE_UINT32 (bs, 0, 1); + /* one_picture_only_constraint_flag */ + WRITE_UINT32 (bs, 0, 1); + /* lower_bit_rate_constraint_flag */ + WRITE_UINT32 (bs, 1, 1); + break; default: GST_WARNING ("do not support the profile: %s of range extensions", gst_vaapi_profile_get_va_name (profile)); @@ -1110,6 +1130,8 @@ ensure_profile (GstVaapiEncoderH265 * encoder) profile = GST_VAAPI_PROFILE_H265_MAIN_444; else if (format == GST_VIDEO_FORMAT_Y410) profile = GST_VAAPI_PROFILE_H265_MAIN_444_10; + else if (format == GST_VIDEO_FORMAT_Y210 || format == GST_VIDEO_FORMAT_YUY2) + profile = GST_VAAPI_PROFILE_H265_MAIN_422_10; encoder->profile = profile; encoder->profile_idc = gst_vaapi_utils_h265_get_profile_idc (profile); diff --git a/gst-libs/gst/vaapi/gstvaapiutils_h265.c b/gst-libs/gst/vaapi/gstvaapiutils_h265.c index b24273b0ad..47da26d68e 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_h265.c @@ -42,6 +42,7 @@ static const struct map gst_vaapi_h265_profile_map[] = { { GST_VAAPI_PROFILE_H265_MAIN_STILL_PICTURE, "main-still-picture" }, { GST_VAAPI_PROFILE_H265_MAIN_444, "main-444" }, { GST_VAAPI_PROFILE_H265_MAIN_444_10, "main-444-10" }, + { GST_VAAPI_PROFILE_H265_MAIN_422_10, "main-422-10" }, { 0, NULL } /* *INDENT-ON* */ }; @@ -445,6 +446,7 @@ gst_vaapi_utils_h265_get_chroma_format_idc (GstVaapiChromaType chroma_type) chroma_format_idc = 1; break; case GST_VAAPI_CHROMA_TYPE_YUV422: + case GST_VAAPI_CHROMA_TYPE_YUV422_10BPP: chroma_format_idc = 2; break; case GST_VAAPI_CHROMA_TYPE_YUV444: diff --git a/gst/vaapi/gstvaapiencode_h265.c b/gst/vaapi/gstvaapiencode_h265.c index 5b97991b10..b5a19f6aa3 100644 --- a/gst/vaapi/gstvaapiencode_h265.c +++ b/gst/vaapi/gstvaapiencode_h265.c @@ -55,7 +55,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_vaapi_h265_encode_debug); /* *INDENT-OFF* */ static const char gst_vaapiencode_h265_src_caps_str[] = GST_CODEC_CAPS ", " - "profile = (string) { main, main-10, main-444, main-444-10 }"; + "profile = (string) { main, main-10, main-444, main-444-10, main-422-10 }"; /* *INDENT-ON* */ /* *INDENT-OFF* */