[PATCH 1/6] lavu/hwcontext_qsv: specify Shift for each format
From: Haihao Xiang <haihao.xiang@intel.com> We can't get Shift from bit depth for some formats in the SDK. For example, bit depth is 10, however Shift is 0 for Y410 (XV30 in FFmpeg). In order to support these formats in the next commits, this patch specified Shift for each format Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavutil/hwcontext_qsv.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 9fa0dfa1c0..2272df52f2 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -109,20 +109,21 @@ typedef struct QSVFramesContext { static const struct { enum AVPixelFormat pix_fmt; uint32_t fourcc; + uint16_t mfx_shift; } supported_pixel_formats[] = { - { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 }, - { AV_PIX_FMT_BGRA, MFX_FOURCC_RGB4 }, - { AV_PIX_FMT_P010, MFX_FOURCC_P010 }, - { AV_PIX_FMT_PAL8, MFX_FOURCC_P8 }, + { AV_PIX_FMT_NV12, MFX_FOURCC_NV12, 0 }, + { AV_PIX_FMT_BGRA, MFX_FOURCC_RGB4, 0 }, + { AV_PIX_FMT_P010, MFX_FOURCC_P010, 1 }, + { AV_PIX_FMT_PAL8, MFX_FOURCC_P8, 0 }, #if CONFIG_VAAPI { AV_PIX_FMT_YUYV422, - MFX_FOURCC_YUY2 }, + MFX_FOURCC_YUY2, 0 }, { AV_PIX_FMT_Y210, - MFX_FOURCC_Y210 }, + MFX_FOURCC_Y210, 1 }, // VUYX is used for VAAPI child device, // the SDK only delares support for AYUV { AV_PIX_FMT_VUYX, - MFX_FOURCC_AYUV }, + MFX_FOURCC_AYUV, 0 }, #endif }; @@ -170,6 +171,16 @@ static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt) return 0; } +static uint16_t qsv_shift_from_pix_fmt(enum AVPixelFormat pix_fmt) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(supported_pixel_formats); i++) { + if (supported_pixel_formats[i].pix_fmt == pix_fmt) + return supported_pixel_formats[i].mfx_shift; + } + + return 0; +} + #if CONFIG_D3D11VA static uint32_t qsv_get_d3d11va_bind_flags(int mem_type) { @@ -503,7 +514,7 @@ static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf) surf->Info.BitDepthLuma = desc->comp[0].depth; surf->Info.BitDepthChroma = desc->comp[0].depth; - surf->Info.Shift = desc->comp[0].depth > 8; + surf->Info.Shift = qsv_shift_from_pix_fmt(ctx->sw_format); if (desc->log2_chroma_w && desc->log2_chroma_h) surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420; -- 2.17.1
From: Haihao Xiang <haihao.xiang@intel.com> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavcodec/qsv.c | 9 ++++++++- libavcodec/qsv_internal.h | 2 +- libavcodec/qsvenc.c | 6 ++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 51aac16695..4e11b33a7d 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -217,35 +217,42 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc) return AV_PIX_FMT_NONE; } -int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc) +int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shift) { switch (format) { case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUVJ420P: case AV_PIX_FMT_NV12: *fourcc = MFX_FOURCC_NV12; + *shift = 0; return AV_PIX_FMT_NV12; case AV_PIX_FMT_YUV420P10: case AV_PIX_FMT_P010: *fourcc = MFX_FOURCC_P010; + *shift = 1; return AV_PIX_FMT_P010; case AV_PIX_FMT_X2RGB10: *fourcc = MFX_FOURCC_A2RGB10; + *shift = 1; return AV_PIX_FMT_X2RGB10; case AV_PIX_FMT_BGRA: *fourcc = MFX_FOURCC_RGB4; + *shift = 0; return AV_PIX_FMT_BGRA; #if CONFIG_VAAPI case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUYV422: *fourcc = MFX_FOURCC_YUY2; + *shift = 0; return AV_PIX_FMT_YUYV422; case AV_PIX_FMT_YUV422P10: case AV_PIX_FMT_Y210: *fourcc = MFX_FOURCC_Y210; + *shift = 1; return AV_PIX_FMT_Y210; case AV_PIX_FMT_VUYX: *fourcc = MFX_FOURCC_AYUV; + *shift = 0; return AV_PIX_FMT_VUYX; #endif default: diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index f914956596..f95e23c5e8 100644 --- a/libavcodec/qsv_internal.h +++ b/libavcodec/qsv_internal.h @@ -132,7 +132,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id); enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc); -int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc); +int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shift); enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type); enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct); diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 398fa6ff22..dc5479d0f3 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -553,7 +553,7 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) if (!desc) return AVERROR_BUG; - ret = ff_qsv_map_pixfmt(sw_format, &q->param.mfx.FrameInfo.FourCC); + ret = ff_qsv_map_pixfmt(sw_format, &q->param.mfx.FrameInfo.FourCC, &q->param.mfx.FrameInfo.Shift); if (ret < 0) return AVERROR_BUG; @@ -567,7 +567,6 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) !desc->log2_chroma_w + !desc->log2_chroma_h; q->param.mfx.FrameInfo.BitDepthLuma = desc->comp[0].depth; q->param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth; - q->param.mfx.FrameInfo.Shift = desc->comp[0].depth > 8; q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, 16); q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, 16); @@ -653,7 +652,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) if (!desc) return AVERROR_BUG; - ret = ff_qsv_map_pixfmt(sw_format, &q->param.mfx.FrameInfo.FourCC); + ret = ff_qsv_map_pixfmt(sw_format, &q->param.mfx.FrameInfo.FourCC, &q->param.mfx.FrameInfo.Shift); if (ret < 0) return AVERROR_BUG; @@ -667,7 +666,6 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) !desc->log2_chroma_w + !desc->log2_chroma_h; q->param.mfx.FrameInfo.BitDepthLuma = desc->comp[0].depth; q->param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth; - q->param.mfx.FrameInfo.Shift = desc->comp[0].depth > 8; // If the minor version is greater than or equal to 19, // then can use the same alignment settings as H.264 for HEVC -- 2.17.1
From: Haihao Xiang <haihao.xiang@intel.com> XV30 is used for 10bit 4:4:4 content in FFmpeg VAAPI, so XV30 should be used for 10bit 4:4:4 content in FFmpeg QSV too because QSV is based on VAAPI on Linux. However the SDK only declares support for Y410 but does nothing with the alpha in Y410, so this commit fudged a mapping between AV_PIX_FMT_XV30 and MFX_FOURCC_Y410. Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavutil/hwcontext_qsv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 2272df52f2..93ecd2f1a3 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -124,6 +124,10 @@ static const struct { // the SDK only delares support for AYUV { AV_PIX_FMT_VUYX, MFX_FOURCC_AYUV, 0 }, + // XV30 is used for VAAPI child device, + // the SDK only delares support for Y410 + { AV_PIX_FMT_XV30, + MFX_FOURCC_Y410, 0 }, #endif }; @@ -1525,6 +1529,9 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) // use the value from the frame. surface->Data.A = frame->data[0] + 3; break; + case AV_PIX_FMT_XV30: + surface->Data.U = frame->data[0]; + break; #endif default: return MFX_ERR_UNSUPPORTED; -- 2.17.1
From: Haihao Xiang <haihao.xiang@intel.com> AV_PIX_FMT_XV30 is used in FFmpeg and MFX_FOURCC_Y410 is used in the SDK. Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavcodec/qsv.c | 9 +++++++++ libavcodec/qsvdec.c | 2 ++ libavcodec/qsvenc_hevc.c | 1 + libavcodec/qsvenc_vp9.c | 1 + 4 files changed, 13 insertions(+) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 4e11b33a7d..f38c617fc3 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -212,6 +212,7 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc) case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422; case MFX_FOURCC_Y210: return AV_PIX_FMT_Y210; case MFX_FOURCC_AYUV: return AV_PIX_FMT_VUYX; + case MFX_FOURCC_Y410: return AV_PIX_FMT_XV30; #endif } return AV_PIX_FMT_NONE; @@ -254,6 +255,10 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shi *fourcc = MFX_FOURCC_AYUV; *shift = 0; return AV_PIX_FMT_VUYX; + case AV_PIX_FMT_XV30: + *fourcc = MFX_FOURCC_Y410; + *shift = 0; + return AV_PIX_FMT_XV30; #endif default: return AVERROR(ENOSYS); @@ -298,6 +303,10 @@ int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) surface->Data.A = frame->data[0] + 3; break; + case AV_PIX_FMT_XV30: + surface->Data.U = frame->data[0]; + break; + default: return AVERROR(ENOSYS); } diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 0254a394bd..912d58965a 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -142,6 +142,7 @@ static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, break; case AV_PIX_FMT_Y210: case AV_PIX_FMT_VUYX: + case AV_PIX_FMT_XV30: frame->linesize[0] = 4 * FFALIGN(avctx->width, 128); break; default: @@ -1043,6 +1044,7 @@ const FFCodec ff_##x##_qsv_decoder = { \ AV_PIX_FMT_YUYV422, \ AV_PIX_FMT_Y210, \ AV_PIX_FMT_VUYX, \ + AV_PIX_FMT_XV30, \ AV_PIX_FMT_QSV, \ AV_PIX_FMT_NONE }, \ .hw_configs = qsv_hw_configs, \ diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index a5bf915954..1e1574a6f2 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -316,6 +316,7 @@ const FFCodec ff_hevc_qsv_encoder = { AV_PIX_FMT_BGRA, AV_PIX_FMT_X2RGB10, AV_PIX_FMT_VUYX, + AV_PIX_FMT_XV30, AV_PIX_FMT_NONE }, .p.priv_class = &class, .defaults = qsv_enc_defaults, diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c index 044a882d1a..d0340ef94b 100644 --- a/libavcodec/qsvenc_vp9.c +++ b/libavcodec/qsvenc_vp9.c @@ -115,6 +115,7 @@ const FFCodec ff_vp9_qsv_encoder = { AV_PIX_FMT_P010, AV_PIX_FMT_VUYX, AV_PIX_FMT_QSV, + AV_PIX_FMT_XV30, AV_PIX_FMT_NONE }, .p.priv_class = &class, .defaults = qsv_enc_defaults, -- 2.17.1
From: Fei Wang <fei.w.wang@intel.com> P012, Y212 and XV36 are used for 12bit content in FFmpeg VAAPI, so these formats should be used in FFmpeg QSV too, however the SDK only declares support for P016, Y216 and Y416. So this commit fudged mappings between AV_PIX_FMT_P012 and MFX_FOURCC_P016, AV_PIX_FMT_Y212 and MFX_FOURCC_Y216, AV_PIX_FMT_XV36 and MFX_FOURCC_Y416. Signed-off-by: Fei Wang <fei.w.wang@intel.com> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavutil/hwcontext_qsv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 93ecd2f1a3..ec0f72b329 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -128,6 +128,20 @@ static const struct { // the SDK only delares support for Y410 { AV_PIX_FMT_XV30, MFX_FOURCC_Y410, 0 }, +#if QSV_VERSION_ATLEAST(1, 31) + // P012 is used for VAAPI child device, + // the SDK only delares support for P016 + { AV_PIX_FMT_P012, + MFX_FOURCC_P016, 1 }, + // Y212 is used for VAAPI child device, + // the SDK only delares support for Y216 + { AV_PIX_FMT_Y212, + MFX_FOURCC_Y216, 1 }, + // XV36 is used for VAAPI child device, + // the SDK only delares support for Y416 + { AV_PIX_FMT_XV36, + MFX_FOURCC_Y416, 1 }, +#endif #endif }; @@ -1493,6 +1507,7 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) switch (frame->format) { case AV_PIX_FMT_NV12: case AV_PIX_FMT_P010: + case AV_PIX_FMT_P012: surface->Data.Y = frame->data[0]; surface->Data.UV = frame->data[1]; break; @@ -1517,6 +1532,7 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) break; case AV_PIX_FMT_Y210: + case AV_PIX_FMT_Y212: surface->Data.Y16 = (mfxU16 *)frame->data[0]; surface->Data.U16 = (mfxU16 *)frame->data[0] + 1; surface->Data.V16 = (mfxU16 *)frame->data[0] + 3; @@ -1532,6 +1548,14 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) case AV_PIX_FMT_XV30: surface->Data.U = frame->data[0]; break; + case AV_PIX_FMT_XV36: + surface->Data.U = frame->data[0]; + surface->Data.Y = frame->data[0] + 2; + surface->Data.V = frame->data[0] + 4; + // Only set Data.A to a valid address, the SDK doesn't + // use the value from the frame. + surface->Data.A = frame->data[0] + 6; + break; #endif default: return MFX_ERR_UNSUPPORTED; -- 2.17.1
From: Fei Wang <fei.w.wang@intel.com> AV_PIX_FMT_P012, AV_PIX_FMT_Y212 and AV_PIX_FMT_XV36 are used in FFmpeg and MFX_FOURCC_P016, MFX_FOURCC_Y216, and MFX_FOURCC_Y416 are used in the SDK Signed-off-by: Fei Wang <fei.w.wang@intel.com> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavcodec/qsv.c | 30 ++++++++++++++++++++++++++++++ libavcodec/qsvdec.c | 11 ++++++++++- libavcodec/qsvenc_hevc.c | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index f38c617fc3..7af154202c 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -213,6 +213,11 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc) case MFX_FOURCC_Y210: return AV_PIX_FMT_Y210; case MFX_FOURCC_AYUV: return AV_PIX_FMT_VUYX; case MFX_FOURCC_Y410: return AV_PIX_FMT_XV30; +#if QSV_VERSION_ATLEAST(1, 31) + case MFX_FOURCC_P016: return AV_PIX_FMT_P012; + case MFX_FOURCC_Y216: return AV_PIX_FMT_Y212; + case MFX_FOURCC_Y416: return AV_PIX_FMT_XV36; +#endif #endif } return AV_PIX_FMT_NONE; @@ -259,6 +264,20 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shi *fourcc = MFX_FOURCC_Y410; *shift = 0; return AV_PIX_FMT_XV30; +#if QSV_VERSION_ATLEAST(1, 31) + case AV_PIX_FMT_P012: + *fourcc = MFX_FOURCC_P016; + *shift = 1; + return AV_PIX_FMT_P012; + case AV_PIX_FMT_Y212: + *fourcc = MFX_FOURCC_Y216; + *shift = 1; + return AV_PIX_FMT_Y212; + case AV_PIX_FMT_XV36: + *fourcc = MFX_FOURCC_Y416; + *shift = 1; + return AV_PIX_FMT_XV36; +#endif #endif default: return AVERROR(ENOSYS); @@ -270,6 +289,7 @@ int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) switch (frame->format) { case AV_PIX_FMT_NV12: case AV_PIX_FMT_P010: + case AV_PIX_FMT_P012: surface->Data.Y = frame->data[0]; surface->Data.UV = frame->data[1]; /* The SDK checks Data.V when using system memory for VP9 encoding */ @@ -289,6 +309,7 @@ int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) break; case AV_PIX_FMT_Y210: + case AV_PIX_FMT_Y212: surface->Data.Y16 = (mfxU16 *)frame->data[0]; surface->Data.U16 = (mfxU16 *)frame->data[0] + 1; surface->Data.V16 = (mfxU16 *)frame->data[0] + 3; @@ -307,6 +328,15 @@ int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface) surface->Data.U = frame->data[0]; break; + case AV_PIX_FMT_XV36: + surface->Data.U = frame->data[0]; + surface->Data.Y = frame->data[0] + 2; + surface->Data.V = frame->data[0] + 4; + // Only set Data.A to a valid address, the SDK doesn't + // use the value from the frame. + surface->Data.A = frame->data[0] + 6; + break; + default: return AVERROR(ENOSYS); } diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 912d58965a..73405b5747 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -137,14 +137,19 @@ static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, frame->linesize[0] = FFALIGN(avctx->width, 128); break; case AV_PIX_FMT_P010: + case AV_PIX_FMT_P012: case AV_PIX_FMT_YUYV422: frame->linesize[0] = 2 * FFALIGN(avctx->width, 128); break; case AV_PIX_FMT_Y210: case AV_PIX_FMT_VUYX: case AV_PIX_FMT_XV30: + case AV_PIX_FMT_Y212: frame->linesize[0] = 4 * FFALIGN(avctx->width, 128); break; + case AV_PIX_FMT_XV36: + frame->linesize[0] = 8 * FFALIGN(avctx->width, 128); + break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n"); return AVERROR(EINVAL); @@ -156,7 +161,8 @@ static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, frame->data[0] = frame->buf[0]->data; if (avctx->pix_fmt == AV_PIX_FMT_NV12 || - avctx->pix_fmt == AV_PIX_FMT_P010) { + avctx->pix_fmt == AV_PIX_FMT_P010 || + avctx->pix_fmt == AV_PIX_FMT_P012) { frame->linesize[1] = frame->linesize[0]; frame->data[1] = frame->data[0] + frame->linesize[0] * FFALIGN(avctx->height, 64); @@ -1041,10 +1047,13 @@ const FFCodec ff_##x##_qsv_decoder = { \ .p.priv_class = &x##_qsv_class, \ .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \ AV_PIX_FMT_P010, \ + AV_PIX_FMT_P012, \ AV_PIX_FMT_YUYV422, \ AV_PIX_FMT_Y210, \ + AV_PIX_FMT_Y212, \ AV_PIX_FMT_VUYX, \ AV_PIX_FMT_XV30, \ + AV_PIX_FMT_XV36, \ AV_PIX_FMT_QSV, \ AV_PIX_FMT_NONE }, \ .hw_configs = qsv_hw_configs, \ diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index 1e1574a6f2..8127fcc6c3 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -310,6 +310,7 @@ const FFCodec ff_hevc_qsv_encoder = { .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID, .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, AV_PIX_FMT_P010, + AV_PIX_FMT_P012, AV_PIX_FMT_YUYV422, AV_PIX_FMT_Y210, AV_PIX_FMT_QSV, -- 2.17.1
On Thu, 2022-10-06 at 15:35 +0800, Xiang, Haihao wrote:
From: Haihao Xiang <haihao.xiang@intel.com>
We can't get Shift from bit depth for some formats in the SDK. For example, bit depth is 10, however Shift is 0 for Y410 (XV30 in FFmpeg). In order to support these formats in the next commits, this patch specified Shift for each format
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> --- libavutil/hwcontext_qsv.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 9fa0dfa1c0..2272df52f2 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -109,20 +109,21 @@ typedef struct QSVFramesContext { static const struct { enum AVPixelFormat pix_fmt; uint32_t fourcc; + uint16_t mfx_shift; } supported_pixel_formats[] = { - { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 }, - { AV_PIX_FMT_BGRA, MFX_FOURCC_RGB4 }, - { AV_PIX_FMT_P010, MFX_FOURCC_P010 }, - { AV_PIX_FMT_PAL8, MFX_FOURCC_P8 }, + { AV_PIX_FMT_NV12, MFX_FOURCC_NV12, 0 }, + { AV_PIX_FMT_BGRA, MFX_FOURCC_RGB4, 0 }, + { AV_PIX_FMT_P010, MFX_FOURCC_P010, 1 }, + { AV_PIX_FMT_PAL8, MFX_FOURCC_P8, 0 }, #if CONFIG_VAAPI { AV_PIX_FMT_YUYV422, - MFX_FOURCC_YUY2 }, + MFX_FOURCC_YUY2, 0 }, { AV_PIX_FMT_Y210, - MFX_FOURCC_Y210 }, + MFX_FOURCC_Y210, 1 }, // VUYX is used for VAAPI child device, // the SDK only delares support for AYUV { AV_PIX_FMT_VUYX, - MFX_FOURCC_AYUV }, + MFX_FOURCC_AYUV, 0 }, #endif };
@@ -170,6 +171,16 @@ static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt) return 0; }
+static uint16_t qsv_shift_from_pix_fmt(enum AVPixelFormat pix_fmt) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(supported_pixel_formats); i++) { + if (supported_pixel_formats[i].pix_fmt == pix_fmt) + return supported_pixel_formats[i].mfx_shift; + } + + return 0; +} + #if CONFIG_D3D11VA static uint32_t qsv_get_d3d11va_bind_flags(int mem_type) { @@ -503,7 +514,7 @@ static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf)
surf->Info.BitDepthLuma = desc->comp[0].depth; surf->Info.BitDepthChroma = desc->comp[0].depth; - surf->Info.Shift = desc->comp[0].depth > 8; + surf->Info.Shift = qsv_shift_from_pix_fmt(ctx->sw_format);
if (desc->log2_chroma_w && desc->log2_chroma_h) surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
Will apply, -Haihao
participants (1)
-
Xiang, Haihao