From 926b60f44f078f24bd54be35484708c0a40dad07 Mon Sep 17 00:00:00 2001 From: Vincent Cheah Beng Keat Date: Wed, 3 Jul 2024 20:52:13 +0800 Subject: [PATCH 1/3] [Encode] Add rgb32 flag for BGR4 case This is to fix BGR4 JPEG Enc internal alloction case where the vaattrib never got set. Hence, results in corruption. OSPR: [PUBLIC]333 Issue: HSD-15015751297 Test: manual Github PR: 333 (Enable YUV400 JPEG Enc and BGR4 JPEG Enc (api2x)) Signed-off-by: Cheah, Vincent Beng Keat vincent.beng.keat.cheah@intel.com> --- .../encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h | 10 ++++++++++ _studio/mfx_lib/shared/src/libmfxsw_encode.cpp | 2 +- _studio/shared/include/mfxvideo++int.h | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/_studio/mfx_lib/encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h b/_studio/mfx_lib/encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h index a6cd292fa3..428ec0d84d 100644 --- a/_studio/mfx_lib/encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h +++ b/_studio/mfx_lib/encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h @@ -102,6 +102,16 @@ class MFXVideoENCODEMJPEG_HW : public VideoENCODE { MFX_RETURN(MFX_ERR_UNDEFINED_BEHAVIOR); } + mfxU16 GetMemType(mfxVideoParam par) override + { + mfxU16 memory_type = mfxU16(par.IOPattern == MFX_IOPATTERN_IN_SYSTEM_MEMORY ? MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_SYSTEM_MEMORY : MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_DXVA2_DECODER_TARGET); + + if (par.mfx.FrameInfo.FourCC == MFX_FOURCC_BGR4) + memory_type |= MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET; + + return memory_type; + } + MFX_PROPAGATE_GetSurface_VideoENCODE_Definition; protected: diff --git a/_studio/mfx_lib/shared/src/libmfxsw_encode.cpp b/_studio/mfx_lib/shared/src/libmfxsw_encode.cpp index fe85c64c56..92420ad235 100644 --- a/_studio/mfx_lib/shared/src/libmfxsw_encode.cpp +++ b/_studio/mfx_lib/shared/src/libmfxsw_encode.cpp @@ -510,7 +510,7 @@ static mfxStatus SetupCache(mfxSession session, const mfxVideoParam& par) if (session->m_pCORE->IsExternalFrameAllocator()) return MFX_ERR_NONE; - mfxU16 memory_type = mfxU16(par.IOPattern == MFX_IOPATTERN_IN_SYSTEM_MEMORY ? MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_SYSTEM_MEMORY : MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_DXVA2_DECODER_TARGET); + mfxU16 memory_type = session->m_pENCODE->GetMemType(par); auto& pCache = session->m_pENCODE->m_pSurfaceCache; diff --git a/_studio/shared/include/mfxvideo++int.h b/_studio/shared/include/mfxvideo++int.h index aa39c49ebe..897b22fd26 100644 --- a/_studio/shared/include/mfxvideo++int.h +++ b/_studio/shared/include/mfxvideo++int.h @@ -451,6 +451,12 @@ class VideoENCODE return MFX_ERR_NONE; } + virtual + mfxU16 GetMemType(mfxVideoParam par) + { + return mfxU16(par.IOPattern == MFX_IOPATTERN_IN_SYSTEM_MEMORY ? MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_SYSTEM_MEMORY : MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_DXVA2_DECODER_TARGET); + } + virtual mfxStatus GetSurface(mfxFrameSurface1** output_surf, mfxSurfaceHeader* import_surface) = 0; std::unique_ptr, std::function*)>> m_pSurfaceCache; From 6cb1ff305c2fe910f7493fed54c2a48eec954fa1 Mon Sep 17 00:00:00 2001 From: Vincent Cheah Beng Keat Date: Wed, 3 Jul 2024 20:54:34 +0800 Subject: [PATCH 2/3] [JPEGe] Enable YUV400 JPEG Enc support The changes only enable YUV400 JPEG Enc support for Linux only. OSPR: [PUBLIC]333 Issue: VSMGWL-73224 Test: manual Github PR: 333 (Enable YUV400 JPEG Enc and BGR4 JPEG Enc (api2x)) Signed-off-by: Cheah, Vincent Beng Keat vincent.beng.keat.cheah@intel.com> --- .../mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp | 7 +++++++ .../encode_hw/mjpeg/src/mfx_mjpeg_encode_hw_utils.cpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp b/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp index 332f637288..b3466d965e 100644 --- a/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp +++ b/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp @@ -213,7 +213,12 @@ mfxStatus MFXVideoENCODEMJPEG_HW::QueryImplsDescription( ah.PushBack(memCaps.ColorFormats) = MFX_FOURCC_YUY2; ah.PushBack(memCaps.ColorFormats) = MFX_FOURCC_RGB4; ah.PushBack(memCaps.ColorFormats) = MFX_FOURCC_BGR4; +#if defined(LINUX) + ah.PushBack(memCaps.ColorFormats) = MFX_FOURCC_YUV400; + memCaps.NumColorFormats = 6; +#else memCaps.NumColorFormats = 5; +#endif ah.PushBack(profileCaps.MemDesc); profileCaps.MemDesc[1] = profileCaps.MemDesc[0]; @@ -392,6 +397,7 @@ mfxStatus MFXVideoENCODEMJPEG_HW::Query(VideoCORE * core, mfxVideoParam *in, mfx if ((fourCC == 0 && chromaFormat == 0) || (fourCC == MFX_FOURCC_NV12 && (chromaFormat == MFX_CHROMAFORMAT_YUV420 || chromaFormat == MFX_CHROMAFORMAT_YUV400)) || + (fourCC == MFX_FOURCC_YUV400 && chromaFormat == MFX_CHROMAFORMAT_YUV400) || (fourCC == MFX_FOURCC_YUY2 && chromaFormat == MFX_CHROMAFORMAT_YUV422H) || ((fourCC == MFX_FOURCC_RGB4 || fourCC == MFX_FOURCC_BGR4) && chromaFormat == MFX_CHROMAFORMAT_YUV444)) { @@ -691,6 +697,7 @@ mfxStatus MFXVideoENCODEMJPEG_HW::Init(mfxVideoParam *par) mfxU16 doubleBytesPerPx = 0; switch(m_vParam.mfx.FrameInfo.FourCC) { + case MFX_FOURCC_YUV400: case MFX_FOURCC_NV12: case MFX_FOURCC_YV12: doubleBytesPerPx = 3; diff --git a/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw_utils.cpp b/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw_utils.cpp index b1ab556e5e..469da22c6f 100644 --- a/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw_utils.cpp +++ b/_studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw_utils.cpp @@ -100,6 +100,7 @@ mfxStatus MfxHwMJpegEncode::CheckJpegParam(VideoCORE *core, mfxVideoParam & par, mfxF64 BytesPerPx = 0; switch (par.mfx.FrameInfo.FourCC) { + case MFX_FOURCC_YUV400: case MFX_FOURCC_NV12: case MFX_FOURCC_YV12: BytesPerPx = 1.5; @@ -286,7 +287,7 @@ mfxStatus ExecuteBuffers::Init(mfxVideoParam const *par, mfxEncodeCtrl const * c m_pps.num_components = 3; else if (fourCC == MFX_FOURCC_YUY2 && chromaFormat == MFX_CHROMAFORMAT_YUV422H) m_pps.num_components = 3; - else if (fourCC == MFX_FOURCC_NV12 && chromaFormat == MFX_CHROMAFORMAT_YUV400) + else if ((fourCC == MFX_FOURCC_NV12 || fourCC == MFX_FOURCC_YUV400) && chromaFormat == MFX_CHROMAFORMAT_YUV400) m_pps.num_components = 1; else if ((fourCC == MFX_FOURCC_RGB4 || fourCC == MFX_FOURCC_BGR4) && chromaFormat == MFX_CHROMAFORMAT_YUV444) m_pps.num_components = 3; From fe55e6e70b93364b8953cdbc347442742b29181a Mon Sep 17 00:00:00 2001 From: Vincent Cheah Beng Keat Date: Wed, 3 Jul 2024 20:55:27 +0800 Subject: [PATCH 3/3] [JPEGe] Enable YUV400 internal vaapi allocator OSPR: [PUBLIC]333 Issue: VSMGWL-73224 Test: manual Github PR: 333 (Enable YUV400 JPEG Enc and BGR4 JPEG Enc (api2x)) Signed-off-by: Cheah, Vincent Beng Keat vincent.beng.keat.cheah@intel.com> --- _studio/shared/src/libmfx_allocator_vaapi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/_studio/shared/src/libmfx_allocator_vaapi.cpp b/_studio/shared/src/libmfx_allocator_vaapi.cpp index 40fa128b2e..e9207533b8 100644 --- a/_studio/shared/src/libmfx_allocator_vaapi.cpp +++ b/_studio/shared/src/libmfx_allocator_vaapi.cpp @@ -603,6 +603,7 @@ mfxStatus mfxDefaultAllocatorVAAPI::SetFrameData(const VAImage &va_image, mfxU32 frame_data.A = frame_data.R + 3; break; + case MFX_FOURCC_YUV400: case VA_FOURCC_P208: frame_data.Y = p_buffer + va_image.offsets[0]; break;