Skip to content

Commit b750bb4

Browse files
author
jianfeng.zheng
committed
vaapi: support VAProfileH264High10
see intel/libva#664 Signed-off-by: jianfeng.zheng <[email protected]>
1 parent b92260f commit b750bb4

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

configure

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,7 @@ HAVE_LIST="
24102410
texi2html
24112411
xmllint
24122412
zlib_gzip
2413+
va_profile_h264_high10
24132414
"
24142415

24152416
# options emitted with CONFIG_ prefix but not available on the command line
@@ -6958,6 +6959,18 @@ if enabled vaapi; then
69586959
check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
69596960
check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8"
69606961
check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9"
6962+
6963+
#
6964+
# Using 'VA_CHECK_VERSION' in source codes make things easy. But we have to wait
6965+
# until newly added VAProfile being distributed by VAAPI released version.
6966+
#
6967+
# Before or after that, we can use auto-detection to keep version compatibility.
6968+
# It always works.
6969+
#
6970+
disable va_profile_h264_high10 && enabled h264_vaapi_hwaccel
6971+
test_code cc va/va.h "VAProfile p = VAProfileH264High10" &&
6972+
enable va_profile_h264_high10
6973+
69616974
fi
69626975

69636976
if enabled_all opencl libdrm ; then

libavcodec/h264_slice.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,15 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
805805
*fmt++ = AV_PIX_FMT_YUV444P10;
806806
} else if (CHROMA422(h))
807807
*fmt++ = AV_PIX_FMT_YUV422P10;
808-
else
808+
else {
809+
#if CONFIG_H264_VAAPI_HWACCEL
810+
// Just add as candidate. Whether VAProfileH264High10 usable or
811+
// not is decided by vaapi_decode_make_config() defined in FFmpeg
812+
// and vaQueryCodingProfile() defined in libva.
813+
*fmt++ = AV_PIX_FMT_VAAPI;
814+
#endif
809815
*fmt++ = AV_PIX_FMT_YUV420P10;
816+
}
810817
break;
811818
case 12:
812819
if (CHROMA444(h)) {

libavcodec/vaapi_decode.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ static const struct {
402402
H264ConstrainedBaseline),
403403
MAP(H264, H264_MAIN, H264Main ),
404404
MAP(H264, H264_HIGH, H264High ),
405+
#if HAVE_VA_PROFILE_H264_HIGH10
406+
MAP(H264, H264_HIGH_10, H264High10 ),
407+
#endif
405408
#if VA_CHECK_VERSION(0, 37, 0)
406409
MAP(HEVC, HEVC_MAIN, HEVCMain ),
407410
MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
@@ -510,6 +513,13 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
510513
if (exact_match)
511514
break;
512515
}
516+
#if HAVE_VA_PROFILE_H264_HIGH10
517+
//incase 8bit stream being decoded under VAProfileH264High10
518+
if (avctx->codec_id == AV_CODEC_ID_H264 &&
519+
(avctx->profile == FF_PROFILE_H264_EXTENDED || avctx->profile == FF_PROFILE_H264_BASELINE) &&
520+
matched_va_profile == VAProfileH264High)
521+
break;
522+
#endif
513523
}
514524
av_freep(&profile_list);
515525

libavcodec/vaapi_encode_h264.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "libavutil/avassert.h"
2525
#include "libavutil/common.h"
26+
#include "libavutil/pixdesc.h"
2627
#include "libavutil/internal.h"
2728
#include "libavutil/opt.h"
2829

@@ -290,10 +291,21 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
290291
H264RawPPS *pps = &priv->raw_pps;
291292
VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
292293
VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
294+
const AVPixFmtDescriptor *desc;
295+
int bit_depth;
293296

294297
memset(sps, 0, sizeof(*sps));
295298
memset(pps, 0, sizeof(*pps));
296299

300+
desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format);
301+
av_assert0(desc);
302+
if (desc->nb_components == 1 || desc->log2_chroma_w != 1 || desc->log2_chroma_h != 1) {
303+
av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
304+
"%s is not supported.\n", desc->name);
305+
return AVERROR(EINVAL);
306+
}
307+
bit_depth = desc->comp[0].depth;
308+
297309
sps->nal_unit_header.nal_ref_idc = 3;
298310
sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
299311

@@ -303,11 +315,11 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
303315
avctx->profile == FF_PROFILE_H264_MAIN)
304316
sps->constraint_set1_flag = 1;
305317

306-
if (avctx->profile == FF_PROFILE_H264_HIGH)
318+
if (avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10)
307319
sps->constraint_set3_flag = ctx->gop_size == 1;
308320

309321
if (avctx->profile == FF_PROFILE_H264_MAIN ||
310-
avctx->profile == FF_PROFILE_H264_HIGH) {
322+
avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10) {
311323
sps->constraint_set4_flag = 1;
312324
sps->constraint_set5_flag = ctx->b_per_p == 0;
313325
}
@@ -348,6 +360,8 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
348360

349361
sps->seq_parameter_set_id = 0;
350362
sps->chroma_format_idc = 1;
363+
sps->bit_depth_luma_minus8 = bit_depth - 8;
364+
sps->bit_depth_chroma_minus8 = bit_depth - 8;
351365

352366
sps->log2_max_frame_num_minus4 = 4;
353367
sps->pic_order_cnt_type = 0;
@@ -1111,6 +1125,9 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
11111125
}
11121126

11131127
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[] = {
1128+
#if HAVE_VA_PROFILE_H264_HIGH10
1129+
{ FF_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 },
1130+
#endif
11141131
{ FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High },
11151132
{ FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main },
11161133
{ FF_PROFILE_H264_CONSTRAINED_BASELINE,
@@ -1175,10 +1192,9 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
11751192
av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
11761193
"is not supported.\n");
11771194
return AVERROR_PATCHWELCOME;
1178-
case FF_PROFILE_H264_HIGH_10:
11791195
case FF_PROFILE_H264_HIGH_10_INTRA:
1180-
av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles "
1181-
"are not supported.\n");
1196+
av_log(avctx, AV_LOG_ERROR, "H.264 high 10 intra profile "
1197+
"is not supported.\n");
11821198
return AVERROR_PATCHWELCOME;
11831199
case FF_PROFILE_H264_HIGH_422:
11841200
case FF_PROFILE_H264_HIGH_422_INTRA:
@@ -1267,6 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = {
12671283
{ PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
12681284
{ PROFILE("main", FF_PROFILE_H264_MAIN) },
12691285
{ PROFILE("high", FF_PROFILE_H264_HIGH) },
1286+
{ PROFILE("high10", FF_PROFILE_H264_HIGH_10) },
12701287
#undef PROFILE
12711288

12721289
{ "level", "Set level (level_idc)",

0 commit comments

Comments
 (0)