Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable YUV400 JPEG Enc and BGR4 JPEG Enc (api2x) #333

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions _studio/mfx_lib/encode_hw/mjpeg/include/mfx_mjpeg_encode_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions _studio/mfx_lib/encode_hw/mjpeg/src/mfx_mjpeg_encode_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion _studio/mfx_lib/shared/src/libmfxsw_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions _studio/shared/include/mfxvideo++int.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<surface_cache_controller<SurfaceCache>, std::function<void(surface_cache_controller<SurfaceCache>*)>> m_pSurfaceCache;
Expand Down
1 change: 1 addition & 0 deletions _studio/shared/src/libmfx_allocator_vaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down