Skip to content

Commit

Permalink
Enabled i420->nv12 through vpp but not filereader (Intel-Media-SDK#20)
Browse files Browse the repository at this point in the history
on SampleVPP and SampleEncode.
cmd: add -i420 option.

Signed-off-by: Zhang, Wenjuan <[email protected]>

Signed-off-by: Zhang, Wenjuan <[email protected]>
  • Loading branch information
JaneZhang8 committed Nov 25, 2022
1 parent c8d674e commit 0c0ad0d
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 23 deletions.
3 changes: 2 additions & 1 deletion _studio/mfx_lib/shared/src/mfx_common_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ mfxStatus CheckFramePointers(mfxFrameInfo const& info, mfxFrameData const& data)
case MFX_FOURCC_BGR4:
case MFX_FOURCC_ARGB16:
case MFX_FOURCC_ABGR16: MFX_CHECK(data.R && data.G && data.B && data.A, MFX_ERR_UNDEFINED_BEHAVIOR); break;

case MFX_FOURCC_I420:
case MFX_FOURCC_YV12:
case MFX_FOURCC_YUY2:
default: MFX_CHECK(data.Y && data.U && data.V, MFX_ERR_UNDEFINED_BEHAVIOR); break;
Expand Down Expand Up @@ -938,6 +938,7 @@ mfxU32 GetMinPitch(mfxU32 fourcc, mfxU16 width)
case MFX_FOURCC_P8_TEXTURE:
case MFX_FOURCC_NV12:
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
#ifdef MFX_ENABLE_RGBP
case MFX_FOURCC_RGBP:
#endif
Expand Down
1 change: 1 addition & 0 deletions _studio/mfx_lib/vpp/src/mfx_vpp_sw_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ mfxStatus VideoVPPBase::Query(VideoCORE * core, mfxVideoParam *in, mfxVideoParam

/* [IN VPP] data */
if( out->vpp.In.FourCC != MFX_FOURCC_YV12 &&
out->vpp.In.FourCC != MFX_FOURCC_I420 &&
out->vpp.In.FourCC != MFX_FOURCC_NV12 &&
out->vpp.In.FourCC != MFX_FOURCC_YUY2 &&
#if defined (MFX_ENABLE_FOURCC_RGB565)
Expand Down
1 change: 1 addition & 0 deletions _studio/mfx_lib/vpp/src/mfx_vpp_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ mfxStatus CheckFrameInfo(mfxFrameInfo* info, mfxU32 request, eMFXHWType platform
{
case MFX_FOURCC_NV12:
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
#if defined (MFX_ENABLE_FOURCC_RGB565)
case MFX_FOURCC_RGB565:
#endif // MFX_ENABLE_FOURCC_RGB565
Expand Down
1 change: 1 addition & 0 deletions _studio/shared/include/mfx_vpp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace MfxHwVideoProcessing
{
MFX_FOURCC_NV12 ,
MFX_FOURCC_YV12 ,
MFX_FOURCC_I420 ,
MFX_FOURCC_NV16 ,
MFX_FOURCC_YUY2 ,
MFX_FOURCC_RGB3 ,
Expand Down
1 change: 1 addition & 0 deletions _studio/shared/src/cm_mem_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ bool CmCopyWrapper::isSinglePlainFormat(mfxU32 format)
case MFX_FOURCC_NV12:
case MFX_FOURCC_P010:
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
case MFX_FOURCC_NV16:
case MFX_FOURCC_P210:
#if (MFX_VERSION >= 1031)
Expand Down
13 changes: 13 additions & 0 deletions _studio/shared/src/libmfx_allocator_vaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ static inline unsigned int ConvertMfxFourccToVAFormat(mfxU32 fourcc)
return VA_FOURCC_YUY2;
case MFX_FOURCC_YV12:
return VA_FOURCC_YV12;
case MFX_FOURCC_I420:
return VA_FOURCC_I420;
case MFX_FOURCC_AYUV:
return VA_FOURCC_AYUV;
#if defined (MFX_ENABLE_FOURCC_RGB565)
Expand Down Expand Up @@ -176,6 +178,7 @@ static inline bool isFourCCSupported(unsigned int va_fourcc)
{
case VA_FOURCC_NV12:
case VA_FOURCC_YV12:
case VA_FOURCC_I420:
case VA_FOURCC_YUY2:
case VA_FOURCC_ARGB:
case VA_FOURCC_ABGR:
Expand Down Expand Up @@ -471,6 +474,16 @@ mfxStatus mfxDefaultAllocatorVAAPI::SetFrameData(const VAImage &va_image, mfxU32
}
break;

case VA_FOURCC_I420:
if (mfx_fourcc != va_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

{
ptr->Y = p_buffer + va_image.offsets[0];
ptr->U = p_buffer + va_image.offsets[1];
ptr->V = p_buffer + va_image.offsets[2];
}
break;

case VA_FOURCC_YUY2:
if (mfx_fourcc != va_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

Expand Down
4 changes: 2 additions & 2 deletions _studio/shared/src/libmfx_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ mfxStatus CommonCORE::DoFastCopy(mfxFrameSurface1 *dst, mfxFrameSurface1 *src)
break;

case MFX_FOURCC_YV12:

case MFX_FOURCC_I420:
sts = m_pFastCopy->Copy(pDst, dstPitch, pSrc, srcPitch, roi, COPY_SYS_TO_SYS);

roi.height >>= 1;
Expand Down Expand Up @@ -1364,7 +1364,7 @@ mfxStatus CoreDoSWFastCopy(mfxFrameSurface1 *pDst, mfxFrameSurface1 *pSrc, int c
break;

case MFX_FOURCC_YV12:

case MFX_FOURCC_I420:
sts = FastCopy::Copy(pDst->Data.Y, dstPitch, pSrc->Data.Y, srcPitch, roi, copyFlag);
MFX_CHECK_STS(sts);
roi.width >>= 1;
Expand Down
3 changes: 2 additions & 1 deletion _studio/shared/src/mfx_vpp_vaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ mfxStatus VAAPIVideoProcessing::QueryCapabilities(mfxVppCaps& caps)
{
case MFX_FOURCC_NV12:
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
case MFX_FOURCC_YUY2:
case MFX_FOURCC_UYVY:
case MFX_FOURCC_RGB4:
Expand Down Expand Up @@ -1995,7 +1996,7 @@ mfxStatus VAAPIVideoProcessing::Execute_Composition_TiledVideoWall(mfxExecutePar
mfxStatus VAAPIVideoProcessing::Execute_Composition(mfxExecuteParams *pParams)
{
MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "VAAPIVideoProcessing::Execute_Composition");

VAStatus vaSts = VA_STATUS_SUCCESS;
VASurfaceAttrib attrib;
std::vector<VABlendState> blend_state;
Expand Down
23 changes: 20 additions & 3 deletions _studio/shared/src/va_mem_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,16 @@ VAStatus VaCopyWrapper::CreateUserVaSurface(
ext_buffer.offsets[2] = ext_buffer.offsets[1] + 1;
ext_buffer.num_planes = 2;
break;

case VA_FOURCC_I420:
ext_buffer.pitches[0] = ALIGN(surfaceInfo.pitch, 32);
ext_buffer.pitches[1] = ext_buffer.pitches[0]/2;
ext_buffer.pitches[2] = ext_buffer.pitches[0]/2;
size = (ext_buffer.pitches[0] * ALIGN(surfaceInfo.height, 32)) * 3 / 2;// frame size align with pitch.
ext_buffer.offsets[0] = 0;// Y channel
ext_buffer.offsets[1] = ext_buffer.pitches[0] * ALIGN(surfaceInfo.height, 32); // UV channel.
ext_buffer.offsets[2] = ext_buffer.offsets[1] + ext_buffer.pitches[0] * ALIGN(surfaceInfo.height, 32)/4;
ext_buffer.num_planes = 3;
break;
case VA_FOURCC_AYUV:
ext_buffer.pitches[0] = ALIGN(surfaceInfo.pitch, 32);
size = ext_buffer.pitches[0] * ALIGN(surfaceInfo.height, 16);// frame size align with pitch.
Expand Down Expand Up @@ -289,6 +298,7 @@ bool VaCopyWrapper::IsVaCopyFormatSupported(mfxU32 fourCC)
switch (fourCC)
{
case VA_FOURCC_NV12:
case VA_FOURCC_I420:
case VA_FOURCC_AYUV:
case VA_FOURCC_P010:
case VA_FOURCC_YUY2:
Expand All @@ -311,6 +321,8 @@ mfxU32 VaCopyWrapper::ConvertVAFormatToMfxFourcc(mfxU32 fourCC)
return MFX_FOURCC_UYVY;
case VA_FOURCC_YV12:
return MFX_FOURCC_YV12;
case VA_FOURCC_I420:
return MFX_FOURCC_I420;
#if (MFX_VERSION >= 1028)
case VA_FOURCC_RGB565:
return MFX_FOURCC_RGB565;
Expand Down Expand Up @@ -353,6 +365,8 @@ mfxU32 VaCopyWrapper::ConvertMfxFourccToVAFormat(mfxU32 fourcc)
{
case MFX_FOURCC_NV12:
return VA_FOURCC_NV12;
case MFX_FOURCC_I420:
return VA_FOURCC_I420;
case MFX_FOURCC_YUY2:
return VA_FOURCC_YUY2;
case MFX_FOURCC_UYVY:
Expand Down Expand Up @@ -422,7 +436,10 @@ mfxStatus VaCopyWrapper::AcquireUserVaSurface(mfxFrameSurface1 *pSurface)
surfaceInfo.fourCC = VA_FOURCC_NV12;
surfaceInfo.format = VA_RT_FORMAT_YUV420;
break;

case MFX_FOURCC_I420:
surfaceInfo.fourCC = VA_FOURCC_I420;
surfaceInfo.format = VA_RT_FORMAT_YUV420;
break;
case MFX_FOURCC_AYUV:
surfaceInfo.fourCC = VA_FOURCC_AYUV;
surfaceInfo.format = VA_FOURCC_AYUV;
Expand Down Expand Up @@ -484,7 +501,7 @@ mfxStatus VaCopyWrapper::VACopy(VASurfaceID srcSurface, VASurfaceID dstSurface,

option.bits.va_copy_sync = VA_EXEC_SYNC;
option.bits.va_copy_mode = vaCopyMode;

va_sts = vaCopy(m_dpy, &dst_obj, &src_obj, option);
mfx_sts = va_to_mfx_status(va_sts);
MFX_CHECK_STS(mfx_sts);
Expand Down
1 change: 1 addition & 0 deletions api/include/mfxstructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ MFX_PACK_END()
enum {
MFX_FOURCC_NV12 = MFX_MAKEFOURCC('N','V','1','2'), /* Native Format */
MFX_FOURCC_YV12 = MFX_MAKEFOURCC('Y','V','1','2'),
MFX_FOURCC_I420 = MFX_MAKEFOURCC('I','4','2','0'),
MFX_FOURCC_NV16 = MFX_MAKEFOURCC('N','V','1','6'),
MFX_FOURCC_YUY2 = MFX_MAKEFOURCC('Y','U','Y','2'),
#if (MFX_VERSION >= 1028)
Expand Down
1 change: 0 additions & 1 deletion samples/sample_common/include/sample_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ enum
#if (MFX_VERSION <= 1027)
MFX_FOURCC_RGBP = MFX_MAKEFOURCC('R','G','B','P'),
#endif
MFX_FOURCC_I420 = MFX_MAKEFOURCC('I','4','2','0')
};

enum ExtBRCType {
Expand Down
37 changes: 35 additions & 2 deletions samples/sample_common/src/sample_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mfxStatus CSmplYUVReader::LoadNextFrame(mfxFrameSurface1* pSurface)
return MFX_ERR_UNSUPPORTED;
}
}
else if (MFX_FOURCC_NV12 == pInfo.FourCC || MFX_FOURCC_YV12 == pInfo.FourCC || MFX_FOURCC_P010 == pInfo.FourCC || MFX_FOURCC_P210 == pInfo.FourCC)
else if (MFX_FOURCC_NV12 == pInfo.FourCC || MFX_FOURCC_YV12 == pInfo.FourCC || MFX_FOURCC_I420 == pInfo.FourCC || MFX_FOURCC_P010 == pInfo.FourCC || MFX_FOURCC_P210 == pInfo.FourCC)
{
pitch = pData.Pitch;
ptr = pData.Y + pInfo.CropX + pInfo.CropY * pData.Pitch;
Expand Down Expand Up @@ -415,6 +415,37 @@ mfxStatus CSmplYUVReader::LoadNextFrame(mfxFrameSurface1* pSurface)
ptr2 = pData.U + (pInfo.CropX / 2) + (pInfo.CropY / 2) * pitch;
}

for(i = 0; i < h; i++)
{

nBytesRead = (mfxU32)fread(ptr + i * pitch, 1, w, m_files[vid]);

if (w != nBytesRead)
{
return MFX_ERR_MORE_DATA;
}
}
for(i = 0; i < h; i++)
{
nBytesRead = (mfxU32)fread(ptr2 + i * pitch, 1, w, m_files[vid]);

if (w != nBytesRead)
{
return MFX_ERR_MORE_DATA;
}
}
break;
case MFX_FOURCC_I420:
w /= 2;
h /= 2;
pitch /= 2;
if (m_ColorFormat == MFX_FOURCC_I420) {
ptr = pData.U + (pInfo.CropX / 2) + (pInfo.CropY / 2) * pitch;
ptr2 = pData.V + (pInfo.CropX / 2) + (pInfo.CropY / 2) * pitch;
} else {
ptr = pData.V + (pInfo.CropX / 2) + (pInfo.CropY / 2) * pitch;
ptr2 = pData.U + (pInfo.CropX / 2) + (pInfo.CropY / 2) * pitch;
}
for(i = 0; i < h; i++)
{

Expand Down Expand Up @@ -1749,7 +1780,7 @@ const msdk_char* ColorFormatToStr(mfxU32 format)
case MFX_FOURCC_YV12:
return MSDK_STRING("YV12");
case MFX_FOURCC_I420:
return MSDK_STRING("YUV420");
return MSDK_STRING("I420");
case MFX_FOURCC_RGB4:
return MSDK_STRING("RGB4");
case MFX_FOURCC_YUY2:
Expand Down Expand Up @@ -2624,6 +2655,8 @@ mfxU16 FourCCToChroma(mfxU32 fourCC)
switch(fourCC)
{
case MFX_FOURCC_NV12:
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
case MFX_FOURCC_P010:
return MFX_CHROMAFORMAT_YUV420;
case MFX_FOURCC_NV16:
Expand Down
7 changes: 7 additions & 0 deletions samples/sample_common/src/sysmem_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
ptr->PitchHigh = 0;
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width);
break;
case MFX_FOURCC_I420:
ptr->U = ptr->Y + Width2 * Height2;
ptr->V = ptr->U + (Width2 >> 1) * (Height2 >> 1);
ptr->PitchHigh = 0;
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width);
break;
case MFX_FOURCC_UYVY:
ptr->U = ptr->Y;
ptr->Y = ptr->U + 1;
Expand Down Expand Up @@ -293,6 +299,7 @@ static mfxU32 GetSurfaceSize(mfxU32 FourCC, mfxU32 Width2, mfxU32 Height2)
switch (FourCC)
{
case MFX_FOURCC_YV12:
case MFX_FOURCC_I420:
case MFX_FOURCC_NV12:
nbytes = Width2*Height2 + (Width2>>1)*(Height2>>1) + (Width2>>1)*(Height2>>1);
break;
Expand Down
12 changes: 12 additions & 0 deletions samples/sample_common/src/vaapi_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ unsigned int ConvertMfxFourccToVAFormat(mfxU32 fourcc)
return VA_FOURCC_NV12;
case MFX_FOURCC_YUY2:
return VA_FOURCC_YUY2;
case MFX_FOURCC_I420:
return VA_FOURCC_I420;
case MFX_FOURCC_UYVY:
return VA_FOURCC_UYVY;
case MFX_FOURCC_YV12:
Expand Down Expand Up @@ -157,6 +159,7 @@ static mfxStatus GetVAFourcc(mfxU32 fourcc, unsigned int &va_fourcc)
va_fourcc = ConvertMfxFourccToVAFormat(mfx_fourcc);
if (!va_fourcc || ((VA_FOURCC_NV12 != va_fourcc) &&
(VA_FOURCC_YV12 != va_fourcc) &&
(VA_FOURCC_I420 != va_fourcc) &&
(VA_FOURCC_YUY2 != va_fourcc) &&
(VA_FOURCC_ARGB != va_fourcc) &&
(VA_FOURCC_ABGR != va_fourcc) &&
Expand Down Expand Up @@ -604,6 +607,15 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
ptr->U = pBuffer + vaapi_mid->m_image.offsets[2];
}
break;
case VA_FOURCC_I420:
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

{
ptr->Y = pBuffer + vaapi_mid->m_image.offsets[0];
ptr->U = pBuffer + vaapi_mid->m_image.offsets[1];
ptr->V = pBuffer + vaapi_mid->m_image.offsets[2];
}
break;
case VA_FOURCC_YUY2:
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

Expand Down
11 changes: 9 additions & 2 deletions samples/sample_common/src/vaapi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,10 @@ mfxStatus CVAAPIDeviceDRM::SetupUserSurface(mfxFrameSurface1 * pSurface)
m_sysSurfInfo.fourCC = VA_FOURCC_NV12;
m_sysSurfInfo.format = VA_RT_FORMAT_YUV420;
break;

case MFX_FOURCC_I420:
m_sysSurfInfo.fourCC = VA_FOURCC_I420;
m_sysSurfInfo.format = VA_RT_FORMAT_YUV420;
break;
case MFX_FOURCC_AYUV:
m_sysSurfInfo.fourCC = VA_FOURCC_AYUV;
m_sysSurfInfo.format = VA_FOURCC_AYUV;
Expand Down Expand Up @@ -540,7 +543,11 @@ mfxStatus CVAAPIDeviceDRM::SetupUserSurface(mfxFrameSurface1 * pSurface)
ptr->U = p_buf + pitch * pInfo.Height;
ptr->V = ptr->U + 1;
break;

case MFX_FOURCC_I420:
ptr->Y = p_buf;
ptr->U = p_buf + pitch * pInfo.Height;
ptr->V = p_buf + pitch * pInfo.Height * 5 / 4;
break;
case MFX_FOURCC_AYUV:
pitch *= 4;
ptr->V = p_buf;
Expand Down
18 changes: 17 additions & 1 deletion samples/sample_common/src/vaapi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,23 @@ VAStatus CLibVA::AcquireUserSurface(
ext_buffer.pitches[1] = ext_buffer.pitches[0];
ext_buffer.num_planes = 2;
break;

case VA_FOURCC_I420:
ext_buffer.pitches[0] = ((surf_info.width + pitch_align -1) /
pitch_align) *
pitch_align;
size = (ext_buffer.pitches[0] * surf_info.height) * 3/2;// frame size align with pitch.
size = (size+base_addr_align-1) /
base_addr_align *
base_addr_align;// frame size align as 4K page.
ext_buffer.offsets[0] = 0;// Y channel
ext_buffer.offsets[1] = ext_buffer.pitches[0] *
surf_info.height; // UV channel.
ext_buffer.offsets[2] = ext_buffer.pitches[0] *
surf_info.height * 5 / 4; // UV channel.
ext_buffer.pitches[1] = ext_buffer.pitches[0] / 2;
ext_buffer.pitches[2] = ext_buffer.pitches[0] / 2;
ext_buffer.num_planes = 3;
break;
case VA_FOURCC_AYUV:
ext_buffer.pitches[0] = ((surf_info.width + pitch_align -1) /
pitch_align) *
Expand Down
3 changes: 2 additions & 1 deletion samples/sample_encode/include/pipeline_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct sInputParams
mfxU32 CodecId;
mfxU32 FileInputFourCC;
mfxU32 EncodeFourCC;
mfxU16 nI420toNV12HWFlag;
mfxU16 nPicStruct;
mfxU16 nWidth; // source picture width
mfxU16 nHeight; // source picture height
Expand Down Expand Up @@ -391,7 +392,7 @@ class CEncodingPipeline
mfxU16 m_MVCflags; // MVC codec is in use

mfxU32 m_InputFourCC;

mfxU32 m_I420toNV12HWFlag;
std::unique_ptr<MFXVideoUSER> m_pUserModule;
std::unique_ptr<MFXPlugin> m_pPlugin;
std::unique_ptr<MFXPlugin> m_pPreEncPlugin;
Expand Down
Loading

0 comments on commit 0c0ad0d

Please sign in to comment.