Skip to content

Commit

Permalink
[Decode] JPEG HW transition comments fix (#5583)
Browse files Browse the repository at this point in the history
1. add sw to decode+vpp
 2. use decode + vpp to convert to rgb4 if vdsfc not support
 3. add format in IsFormatSupport
 4. combine the bytes calculation of UYVY/422V with 422H
 5. fix some coding style

Co-authored-by: Yuan, Pengxin <[email protected]>
  • Loading branch information
gfxVPLsdm and pengxin99 authored Aug 9, 2023
1 parent 598179a commit 0338a5a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 80 deletions.
6 changes: 4 additions & 2 deletions _studio/mfx_lib/decode/mjpeg/include/mfx_mjpeg_dec_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ class VideoDECODEMJPEGBase_HW : public VideoDECODEMJPEGBase
virtual mfxStatus AllocateFrameData(UMC::FrameData *&data);
virtual mfxStatus FillEntryPoint(MFX_ENTRY_POINT *pEntryPoint, mfxFrameSurface1 *surface_work, mfxFrameSurface1 *surface_out);

mfxU32 AdjustFrameAllocRequest(mfxFrameAllocRequest *request, mfxInfoMFX *info, eMFXVAType vaType, bool usePostProcessing);
mfxU32 AdjustFrameAllocRequest(mfxFrameAllocRequest *request, mfxInfoMFX *info, VideoCORE * core, bool isPostProcEnable);

static void AdjustFourCC(mfxFrameInfo *requestFrameInfo, const mfxInfoMFX *info, eMFXVAType vaType, bool usePostProc, bool *needVpp);
static void AdjustFourCC(mfxFrameInfo *requestFrameInfo, const mfxInfoMFX *info, eMFXVAType vaType, bool isPostProcEnable, bool *needVpp);

static mfxStatus CheckVPPCaps(VideoCORE * core, mfxVideoParam * par);
static bool isVideoPostprocEnabled(VideoCORE * core);



protected:
Expand Down
141 changes: 74 additions & 67 deletions _studio/mfx_lib/decode/mjpeg/src/mfx_mjpeg_dec_decode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2004-2022 Intel Corporation
// Copyright (c) 2004-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -192,11 +192,10 @@ mfxStatus VideoDECODEMJPEG::Init(mfxVideoParam *par)
{
VideoDECODEMJPEGBase_HW * dec = new VideoDECODEMJPEGBase_HW;
decoder.reset(dec);
bool usePostProcessing = GetExtendedBuffer(m_vPar.ExtParam, m_vPar.NumExtParam, MFX_EXTBUFF_DEC_VIDEO_PROCESSING);
mfxU32 bNeedVpp = dec->AdjustFrameAllocRequest(&request_internal,
&m_vPar.mfx,
m_core->GetVAType(),
usePostProcessing);
m_core,
VideoDECODEMJPEGBase_HW::isVideoPostprocEnabled(m_core));
useInternal |= bNeedVpp;

if (bNeedVpp)
Expand Down Expand Up @@ -617,9 +616,9 @@ mfxStatus VideoDECODEMJPEG::QueryIOSurfInternal(VideoCORE *core, mfxVideoParam *
}

mfxFrameAllocRequest request_internal = *request;
bool usePostProcessing = GetExtendedBuffer(par->ExtParam, par->NumExtParam, MFX_EXTBUFF_DEC_VIDEO_PROCESSING);
bool isPostProcEnable = VideoDECODEMJPEGBase_HW::isVideoPostprocEnabled(core);
VideoDECODEMJPEGBase_HW::AdjustFourCC(&request_internal.Info, &par->mfx, core->GetVAType(),
usePostProcessing, &needVpp);
isPostProcEnable, &needVpp);


if (needVpp && MFX_HW_D3D11 == core->GetVAType())
Expand Down Expand Up @@ -1037,53 +1036,25 @@ bool MFX_JPEG_Utility::IsNeedPartialAcceleration(VideoCORE * core, mfxVideoParam
par->mfx.JPEGChromaFormat != MFX_CHROMAFORMAT_YUV444)
return true;

bool isVideoPostprocEnabled = false;
// check sfc capability for some platform may not support sfc
{
VAProfile vaProfile = VAProfileJPEGBaseline;
VAEntrypoint vaEntrypoint = VAEntrypointVLD;

VAConfigAttrib vaAttrib;
memset(&vaAttrib, 0, sizeof(vaAttrib));
vaAttrib.type = VAConfigAttribDecProcessing;
vaAttrib.value = 0;

VADisplay vaDisplay;
mfxStatus mfxSts = core->GetHandle(MFX_HANDLE_VA_DISPLAY, &vaDisplay);
if (MFX_ERR_NONE != mfxSts)
return true;

// Had to duplicate that functionality here, as LinuxVideoAccelerator::Init() has not
// called at this point.
VAStatus vaStatus = vaGetConfigAttributes(vaDisplay, vaProfile, vaEntrypoint, &vaAttrib, 1);
if (VA_STATUS_SUCCESS != vaStatus)
return true;

isVideoPostprocEnabled = vaAttrib.value == VA_DEC_PROCESSING;
}

switch (par->mfx.FrameInfo.FourCC)
{
case MFX_FOURCC_NV12:
if ((par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_YCbCr &&
(par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV420 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV444 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422H ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422V ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV411 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_MONOCHROME)) ||
(par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_RGB &&
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV444))
if (par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV420 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV444 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422H ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422V ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV411 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_MONOCHROME)
return false;
else
return true;
case MFX_FOURCC_YUY2:
if(( par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_YCbCr &&
(par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV420 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422H ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_MONOCHROME)) ||
(par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_RGB &&
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV444))
if (par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV420 ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422H ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422V ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_MONOCHROME ||
par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV444)
return false;
else
return true;
Expand All @@ -1094,12 +1065,7 @@ bool MFX_JPEG_Utility::IsNeedPartialAcceleration(VideoCORE * core, mfxVideoParam
else
return true;
case MFX_FOURCC_RGB4:
if (!isVideoPostprocEnabled)
return true;
else if ((par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_RGB && par->mfx.JPEGChromaFormat != MFX_CHROMAFORMAT_YUV444) ||
(par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_YCbCr && par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV422V) ||
(par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_YCbCr && par->mfx.JPEGChromaFormat == MFX_CHROMAFORMAT_YUV411)
)
if (par->mfx.JPEGColorFormat == MFX_JPEG_COLORFORMAT_RGB && par->mfx.JPEGChromaFormat != MFX_CHROMAFORMAT_YUV444)
return true;
else
return false;
Expand Down Expand Up @@ -1172,10 +1138,10 @@ eMFXPlatform MFX_JPEG_Utility::GetPlatform(VideoCORE * core, mfxVideoParam * par
mfxFrameAllocRequest request;
memset(&request, 0, sizeof(request));
request.Info = par->mfx.FrameInfo;
bool usePostProcessing = GetExtendedBuffer(par->ExtParam, par->NumExtParam, MFX_EXTBUFF_DEC_VIDEO_PROCESSING);
bool isPostProcEnable = VideoDECODEMJPEGBase_HW::isVideoPostprocEnabled(core);

VideoDECODEMJPEGBase_HW::AdjustFourCC(&request.Info, &par->mfx, core->GetVAType(),
usePostProcessing, &needVpp);
isPostProcEnable, &needVpp);

if (needVpp)
{
Expand All @@ -1200,29 +1166,31 @@ bool MFX_JPEG_Utility::IsFormatSupport(mfxVideoParam * in)
switch (chromaFormat)
{
case MFX_CHROMAFORMAT_MONOCHROME:
if (fourCC == 0 || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUV400 || fourCC == MFX_FOURCC_RGB4)
if (fourCC == 0 || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUV400 || fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_RGB4)
support = true;
break;
case MFX_CHROMAFORMAT_YUV420:
if (fourCC == MFX_FOURCC_IMC3 || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_UYVY)
if (fourCC == MFX_FOURCC_IMC3 || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_UYVY || fourCC == MFX_FOURCC_RGB4)
support = true;
break;
case MFX_CHROMAFORMAT_YUV411:
if (fourCC == MFX_FOURCC_YUV411 || fourCC == MFX_FOURCC_NV12)
support = true;
break;
case MFX_CHROMAFORMAT_YUV422H:
if ((fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_YUV422H || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_UYVY))
if ((fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_YUV422H || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_UYVY || fourCC == MFX_FOURCC_RGB4))
support = true;
break;
case MFX_CHROMAFORMAT_YUV422V:
if ((fourCC == MFX_FOURCC_YUV422V || fourCC == MFX_FOURCC_NV12))
if ((fourCC == MFX_FOURCC_YUV422V || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUY2 || fourCC == MFX_FOURCC_RGB4))
support = true;
break;
case MFX_CHROMAFORMAT_YUV444:
if (colorFormat == MFX_JPEG_COLORFORMAT_RGB && (fourCC == MFX_FOURCC_RGBP || fourCC == MFX_FOURCC_BGRP || fourCC == MFX_FOURCC_RGB4))
if (fourCC == MFX_FOURCC_RGB4 || fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUY2)
support = true;
else if (colorFormat == MFX_JPEG_COLORFORMAT_RGB && (fourCC == MFX_FOURCC_RGBP || fourCC == MFX_FOURCC_BGRP))
support = true;
else if (colorFormat == MFX_JPEG_COLORFORMAT_YCbCr && (fourCC == MFX_FOURCC_YUV444 || fourCC == MFX_FOURCC_RGB4))
else if (colorFormat == MFX_JPEG_COLORFORMAT_YCbCr && fourCC == MFX_FOURCC_YUV444)
support = true;
break;
default:
Expand Down Expand Up @@ -1671,8 +1639,8 @@ mfxStatus VideoDECODEMJPEGBase_HW::CheckVPPCaps(VideoCORE * core, mfxVideoParam

mfxU32 VideoDECODEMJPEGBase_HW::AdjustFrameAllocRequest(mfxFrameAllocRequest *request,
mfxInfoMFX *info,
eMFXVAType vaType,
bool usePostProcessing)
VideoCORE *core,
bool isPostProcEnable)
{
bool needVpp = false;

Expand All @@ -1688,7 +1656,7 @@ mfxU32 VideoDECODEMJPEGBase_HW::AdjustFrameAllocRequest(mfxFrameAllocRequest *re
}

// set FourCC
AdjustFourCC(&request->Info, info, vaType, usePostProcessing, &needVpp);
AdjustFourCC(&request->Info, info, core->GetVAType(), isPostProcEnable, &needVpp);

#ifdef MFX_ENABLE_MJPEG_ROTATE_VPP
if(info->Rotation == MFX_ROTATION_90 || info->Rotation == MFX_ROTATION_180 || info->Rotation == MFX_ROTATION_270)
Expand Down Expand Up @@ -1767,7 +1735,30 @@ mfxU32 VideoDECODEMJPEGBase_HW::AdjustFrameAllocRequest(mfxFrameAllocRequest *re
return m_needVpp ? 1 : 0;
}

void VideoDECODEMJPEGBase_HW::AdjustFourCC(mfxFrameInfo *requestFrameInfo, const mfxInfoMFX *info, eMFXVAType vaType, bool usePostProc, bool *needVpp)
bool VideoDECODEMJPEGBase_HW::isVideoPostprocEnabled(VideoCORE * core)
{
// check sfc capability for some platform may not support sfc
VAProfile vaProfile = VAProfileJPEGBaseline;
VAEntrypoint vaEntrypoint = VAEntrypointVLD;
VAConfigAttrib vaAttrib;
memset(&vaAttrib, 0, sizeof(vaAttrib));
vaAttrib.type = VAConfigAttribDecProcessing;
vaAttrib.value = 0;
VADisplay vaDisplay;
mfxStatus mfxSts = core->GetHandle(MFX_HANDLE_VA_DISPLAY, &vaDisplay);
if (MFX_ERR_NONE != mfxSts)
return false;

// Had to duplicate that functionality here, as LinuxVideoAccelerator::Init() has not
// called at this point.
VAStatus vaStatus = vaGetConfigAttributes(vaDisplay, vaProfile, vaEntrypoint, &vaAttrib, 1);
if (VA_STATUS_SUCCESS != vaStatus)
return false;

return vaAttrib.value == VA_DEC_PROCESSING;
}

void VideoDECODEMJPEGBase_HW::AdjustFourCC(mfxFrameInfo *requestFrameInfo, const mfxInfoMFX *info, eMFXVAType vaType, bool isVideoPostprocEnabled, bool *needVpp)
{
(void)vaType;

Expand All @@ -1776,16 +1767,23 @@ void VideoDECODEMJPEGBase_HW::AdjustFourCC(mfxFrameInfo *requestFrameInfo, const
switch(info->JPEGChromaFormat)
{
case MFX_CHROMAFORMAT_MONOCHROME:
if (requestFrameInfo->FourCC == MFX_FOURCC_NV12 || requestFrameInfo->FourCC == MFX_FOURCC_YUY2)
if (requestFrameInfo->FourCC == MFX_FOURCC_NV12 ||
requestFrameInfo->FourCC == MFX_FOURCC_YUY2 ||
(requestFrameInfo->FourCC == MFX_FOURCC_RGB4 && !isVideoPostprocEnabled))
{
requestFrameInfo->FourCC = MFX_FOURCC_YUV400;
*needVpp = true;
}
break;
case MFX_CHROMAFORMAT_YUV420:
if (requestFrameInfo->FourCC == MFX_FOURCC_RGB4 && !isVideoPostprocEnabled)
{
requestFrameInfo->FourCC = MFX_FOURCC_NV12;
*needVpp = true;
}
break;
case MFX_CHROMAFORMAT_YUV411:
if (requestFrameInfo->FourCC == MFX_FOURCC_NV12)
if (requestFrameInfo->FourCC == MFX_FOURCC_NV12 || requestFrameInfo->FourCC == MFX_FOURCC_RGB4)
{
requestFrameInfo->FourCC = MFX_FOURCC_YUV411;
*needVpp = true;
Expand All @@ -1794,12 +1792,21 @@ void VideoDECODEMJPEGBase_HW::AdjustFourCC(mfxFrameInfo *requestFrameInfo, const
case MFX_CHROMAFORMAT_YUV422H:
break;
case MFX_CHROMAFORMAT_YUV422V:
// 422V can not do hw decode to YUY2/RGB4 directly, so use VPP to do csc
if (info->Rotation == MFX_ROTATION_0 &&
(requestFrameInfo->FourCC == MFX_FOURCC_YUY2 || requestFrameInfo->FourCC == MFX_FOURCC_RGB4))
{
requestFrameInfo->FourCC = MFX_FOURCC_NV12;
*needVpp = true;
}
break;
case MFX_CHROMAFORMAT_YUV444:
if (info->Rotation == MFX_ROTATION_0 &&
// for YUV444 jpeg, decoded stream is YUV444P from driver,
// to get NV12 we must use VPP
requestFrameInfo->FourCC == MFX_FOURCC_NV12)
// to get NV12/YUY2 we must use VPP
(requestFrameInfo->FourCC == MFX_FOURCC_NV12 ||
requestFrameInfo->FourCC == MFX_FOURCC_YUY2 ||
(requestFrameInfo->FourCC == MFX_FOURCC_RGB4 && !isVideoPostprocEnabled)))
{
requestFrameInfo->FourCC = MFX_FOURCC_YUV444;
*needVpp = true;
Expand Down
2 changes: 1 addition & 1 deletion _studio/mfx_lib/shared/src/mfx_common_decode_int.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2020 Intel Corporation
// Copyright (c) 2017-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion _studio/mfx_lib/shared/src/mfx_common_int.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009-2021 Intel Corporation
// Copyright (c) 2009-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 3 additions & 5 deletions _studio/shared/src/libmfx_allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2021 Intel Corporation
// Copyright (c) 2007-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -169,6 +169,8 @@ mfxStatus mfxDefaultAllocator::GetSurfaceSizeInBytes(mfxU32 pitch, mfxU32 height
case MFX_FOURCC_Y210:
case MFX_FOURCC_Y216:
case MFX_FOURCC_YUV422H:
case MFX_FOURCC_YUV422V:
case MFX_FOURCC_UYVY:
nBytes = pitch * height + (pitch >> 1) * height + (pitch >> 1) * height;
break;
case MFX_FOURCC_YUV444:
Expand All @@ -193,10 +195,6 @@ mfxStatus mfxDefaultAllocator::GetSurfaceSizeInBytes(mfxU32 pitch, mfxU32 height
case MFX_FOURCC_YUV400:
nBytes = pitch * height;
break;
case MFX_FOURCC_YUV422V:
case MFX_FOURCC_UYVY:
nBytes = pitch * height + pitch * (height >> 1) + pitch * (height >> 1);
break;
case MFX_FOURCC_ABGR16F:
nBytes = (pitch * height + pitch * height + pitch * height + pitch * height) * 2;
break;
Expand Down
4 changes: 2 additions & 2 deletions _studio/shared/src/libmfx_allocator_vaapi.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Intel Corporation
// Copyright (c) 2007-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -1083,4 +1083,4 @@ void FlexibleFrameAllocatorHW_VAAPI::SetDevice(mfxHDL device)
m_staging_adapter->SetDevice(device);
}

/* EOF */
/* EOF */
4 changes: 2 additions & 2 deletions _studio/shared/src/mfx_umc_alloc_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2008-2020 Intel Corporation
// Copyright (c) 2008-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -2361,4 +2361,4 @@ mfxStatus mfx_UMC_FrameAllocator_D3D::PrepareToOutput(mfxFrameSurface1 *surfac
}

return sts;
}
}

0 comments on commit 0338a5a

Please sign in to comment.