Skip to content

Commit

Permalink
MPCVideoDec: косметика кода
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Jun 28, 2024
1 parent b04c671 commit 2e1b74c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 140 deletions.
74 changes: 31 additions & 43 deletions src/filters/transform/MPCVideoDec/FormatConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,18 @@ MPCPixFmtType GetPixFmtType(AVPixelFormat av_pix_fmt)
// CFormatConverter

CFormatConverter::CFormatConverter()
: m_pSwsContext(nullptr)
, m_out_pixfmt(PixFmt_None)
, m_dstRGBRange(0)
, m_dstStride(0)
, m_planeHeight(0)
, m_OutHeight(0)
, m_nAlignedBufferSize(0)
, m_pAlignedBuffer(nullptr)
, m_nCPUFlag(0)
, m_RequiredAlignment(0)
, m_NumThreads(1)
, pConvertFn(nullptr)
{
ASSERT(PixFmt_count == std::size(s_sw_formats));

m_FProps.avpixfmt = AV_PIX_FMT_NONE;
m_FProps.width = 0;
m_FProps.height = 0;
m_FProps.lumabits = 0;
m_FProps.pftype = PFType_unspecified;
m_FProps.colorspace = AVCOL_SPC_UNSPECIFIED;
m_FProps.colorrange = AVCOL_RANGE_UNSPECIFIED;
m_FProps.avpixfmt = AV_PIX_FMT_NONE;
m_FProps.width = 0;
m_FProps.height = 0;
m_FProps.lumabits = 0;
m_FProps.pftype = PFType_unspecified;
m_FProps.colorspace = AVCOL_SPC_UNSPECIFIED;
m_FProps.colorrange = AVCOL_RANGE_UNSPECIFIED;

m_NumThreads = std::clamp(CPUInfo::GetProcessorNumber() / 2, 1uL, 8uL);
m_NumThreads = std::clamp(CPUInfo::GetProcessorNumber() / 2, 1uL, 8uL);
}

CFormatConverter::~CFormatConverter()
Expand Down Expand Up @@ -275,60 +263,60 @@ void CFormatConverter::UpdateSWSContext()

void CFormatConverter::SetConvertFunc()
{
pConvertFn = &CFormatConverter::ConvertGeneric;
m_pConvertFn = &CFormatConverter::ConvertGeneric;
m_RequiredAlignment = 16;

switch (m_out_pixfmt) {
case PixFmt_AYUV:
if (m_FProps.pftype == PFType_YUV444Px) {
pConvertFn = &CFormatConverter::convert_yuv444_ayuv_dither_le;
m_pConvertFn = &CFormatConverter::convert_yuv444_ayuv_dither_le;
}
break;
case PixFmt_P010:
case PixFmt_P016:
if (m_FProps.pftype == PFType_YUV420Px) {
pConvertFn = &CFormatConverter::convert_yuv420_px1x_le;
m_pConvertFn = &CFormatConverter::convert_yuv420_px1x_le;
}
break;
case PixFmt_Y410:
if (m_FProps.pftype == PFType_YUV444Px && m_FProps.lumabits <= 10) {
pConvertFn = &CFormatConverter::convert_yuv444_y410;
m_pConvertFn = &CFormatConverter::convert_yuv444_y410;
}
break;
case PixFmt_P210:
case PixFmt_P216:
if (m_FProps.pftype == PFType_YUV422Px) {
pConvertFn = &CFormatConverter::convert_yuv420_px1x_le;
m_pConvertFn = &CFormatConverter::convert_yuv420_px1x_le;
}
break;
case PixFmt_YUY2:
if (m_FProps.pftype == PFType_YUV422Px) {
pConvertFn = &CFormatConverter::convert_yuv422_yuy2_uyvy_dither_le;
m_pConvertFn = &CFormatConverter::convert_yuv422_yuy2_uyvy_dither_le;
m_RequiredAlignment = 8;
} else if (m_FProps.pftype == PFType_YUV420
|| (m_FProps.pftype == PFType_YUV420Px && m_FProps.lumabits <= 14)
|| m_FProps.pftype == PFType_NV12) {
pConvertFn = &CFormatConverter::convert_yuv420_yuy2;
m_pConvertFn = &CFormatConverter::convert_yuv420_yuy2;
m_RequiredAlignment = 8;
}
break;
case PixFmt_NV12:
if (m_FProps.pftype == PFType_NV12) {
pConvertFn = &CFormatConverter::plane_copy_sse2;
m_pConvertFn = &CFormatConverter::plane_copy_sse2;
break;
} else if (m_FProps.pftype == PFType_YUV420) {
pConvertFn = &CFormatConverter::convert_yuv420_nv12;
m_pConvertFn = &CFormatConverter::convert_yuv420_nv12;
m_RequiredAlignment = 32;
}
case PixFmt_YV12:
if (m_FProps.pftype == PFType_YUV420Px) {
pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_RequiredAlignment = 32;
} else if (m_FProps.pftype == PFType_NV12) {
pConvertFn = &CFormatConverter::convert_nv12_yv12;
m_pConvertFn = &CFormatConverter::convert_nv12_yv12;
m_RequiredAlignment = 32;
} else if (m_FProps.pftype == PFType_P01x) {
pConvertFn = &CFormatConverter::convert_p010_nv12_sse2;
m_pConvertFn = &CFormatConverter::convert_p010_nv12_sse2;
}
#if (0) // disabled because not increase performance
else if (m_FProps.pftype == PFType_YUV420) {
Expand All @@ -338,7 +326,7 @@ void CFormatConverter::SetConvertFunc()
break;
case PixFmt_YV16:
if (m_FProps.pftype == PFType_YUV422Px) {
pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_RequiredAlignment = 32;
}
#if (0) // disabled because not increase performance
Expand All @@ -349,10 +337,10 @@ void CFormatConverter::SetConvertFunc()
break;
case PixFmt_YV24:
if (m_FProps.pftype == PFType_YUV444Px) {
pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_pConvertFn = &CFormatConverter::convert_yuv_yv_nv12_dither_le;
m_RequiredAlignment = 32;
} else if (m_FProps.pftype == PFType_YUV444) {
pConvertFn = &CFormatConverter::convert_yuv_yv;
m_pConvertFn = &CFormatConverter::convert_yuv_yv;
m_RequiredAlignment = 0;
}
break;
Expand All @@ -366,7 +354,7 @@ void CFormatConverter::SetConvertFunc()
case PFType_YUV444Px:
case PFType_NV12:
case PFType_P01x:
pConvertFn = &CFormatConverter::convert_yuv_rgb;
m_pConvertFn = &CFormatConverter::convert_yuv_rgb;
m_RequiredAlignment = 4;
}
break;
Expand All @@ -375,18 +363,18 @@ void CFormatConverter::SetConvertFunc()
if (CPUInfo::HaveSSE4()) {
if (m_FProps.pftype == PFType_NV12) {
if (m_out_pixfmt == PixFmt_NV12) {
pConvertFn = &CFormatConverter::plane_copy_direct_sse4;
m_pConvertFn = &CFormatConverter::plane_copy_direct_sse4;
}
else if (m_out_pixfmt == PixFmt_YV12) {
pConvertFn = &CFormatConverter::convert_nv12_yv12_direct_sse4;
m_pConvertFn = &CFormatConverter::convert_nv12_yv12_direct_sse4;
}
}
else if (m_FProps.pftype == PFType_P01x) {
if (m_out_pixfmt == PixFmt_P010 || m_out_pixfmt == PixFmt_P016) {
pConvertFn = &CFormatConverter::plane_copy_direct_sse4;
m_pConvertFn = &CFormatConverter::plane_copy_direct_sse4;
}
else if (m_out_pixfmt == PixFmt_NV12) {
pConvertFn = &CFormatConverter::convert_p010_nv12_direct_sse4;
m_pConvertFn = &CFormatConverter::convert_p010_nv12_direct_sse4;
}
}
}
Expand Down Expand Up @@ -435,7 +423,7 @@ bool CFormatConverter::Converting(BYTE* dst, AVFrame* pFrame)
Cleanup();
}

if (!pConvertFn) {
if (!m_pConvertFn) {
SetConvertFunc();
}

Expand Down Expand Up @@ -472,7 +460,7 @@ bool CFormatConverter::Converting(BYTE* dst, AVFrame* pFrame)
srcStride[i] = pFrame->linesize[i];
}

(this->*pConvertFn)(pFrame->data, srcStride, dstArray, m_FProps.width, m_FProps.height, dstStrideArray);
(this->*m_pConvertFn)(pFrame->data, srcStride, dstArray, m_FProps.width, m_FProps.height, dstStrideArray);

if (out != dst) {
int line = 0;
Expand Down Expand Up @@ -521,7 +509,7 @@ void CFormatConverter::Cleanup()
m_rgbCoeffs = nullptr;
}

pConvertFn = nullptr;
m_pConvertFn = nullptr;
}

bool CFormatConverter::FormatChanged(AVPixelFormat* fmt1, AVPixelFormat* fmt2)
Expand Down
28 changes: 14 additions & 14 deletions src/filters/transform/MPCVideoDec/FormatConverter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2014-2021 see Authors.txt
* (C) 2014-2024 see Authors.txt
*
* This file is part of MPC-BE.
*
Expand Down Expand Up @@ -109,25 +109,25 @@ class CFormatConverter
#define CONV_FUNC_PARAMS const uint8_t* const src[4], const ptrdiff_t srcStride[4], uint8_t* dst[], int width, int height, const ptrdiff_t dstStride[]

protected:
SwsContext* m_pSwsContext;
FrameProps m_FProps;
SwsContext* m_pSwsContext = nullptr;
FrameProps m_FProps;

MPCPixelFormat m_out_pixfmt;
MPCPixelFormat m_out_pixfmt = PixFmt_None;

int m_dstRGBRange;
int m_dstRGBRange = 0;

int m_dstStride;
int m_planeHeight;
int m_OutHeight;
int m_dstStride = 0;
int m_planeHeight = 0;
int m_OutHeight = 0;

size_t m_nAlignedBufferSize;
uint8_t* m_pAlignedBuffer;
size_t m_nAlignedBufferSize = 0;
uint8_t* m_pAlignedBuffer = nullptr;

int m_nCPUFlag;
int m_nCPUFlag = 0;

unsigned m_RequiredAlignment;
unsigned m_RequiredAlignment = 0;

int m_NumThreads;
int m_NumThreads = 1;

bool InitSWSContext();
void UpdateSWSContext();
Expand All @@ -146,7 +146,7 @@ class CFormatConverter

// Conversion function pointer
typedef HRESULT (CFormatConverter::*ConverterFn)(CONV_FUNC_PARAMS);
ConverterFn pConvertFn;
ConverterFn m_pConvertFn = nullptr;

// from LAV Filters
HRESULT ConvertGeneric(CONV_FUNC_PARAMS);
Expand Down
42 changes: 0 additions & 42 deletions src/filters/transform/MPCVideoDec/MPCVideoDec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,47 +1053,9 @@ BOOL CALLBACK EnumFindProcessWnd (HWND hwnd, LPARAM lParam)

CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CBaseVideoFilter(L"MPC - Video decoder", lpunk, phr, __uuidof(this))
, m_nThreadNumber(0)
, m_nDiscardMode(AVDISCARD_DEFAULT)
, m_nScanType(SCAN_AUTO)
, m_nARMode(2)
, m_nHwDecoder(SysVersion::IsWin8orLater() ? HWDec_D3D11 : HWDec_DXVA2)
, m_nDXVACheckCompatibility(1)
, m_nDXVA_SD(0)
, m_nSwRGBLevels(0)
, m_pAVCodec(nullptr)
, m_pAVCtx(nullptr)
, m_pFrame(nullptr)
, m_pParser(nullptr)
, m_CodecId(AV_CODEC_ID_NONE)
, m_bCalculateStopTime(false)
, m_bReorderBFrame(false)
, m_nBFramePos(0)
, m_bWaitKeyFrame(false)
, m_DXVADecoderGUID(GUID_NULL)
, m_nActiveCodecs(CODECS_ALL & ~CODEC_H264_MVC)
, m_rtAvrTimePerFrame(0)
, m_rtLastStart(INVALID_TIME)
, m_rtLastStop(0)
, m_rtStartCache(INVALID_TIME)
, m_bDXVACompatible(true)
, m_nARX(0)
, m_nARY(0)
, m_bUseDXVA(true)
, m_bUseD3D11(true)
, m_bUseFFmpeg(true)
, m_pDXVADecoder(nullptr)
, m_hDevice(INVALID_HANDLE_VALUE)
, m_bWaitingForKeyFrame(TRUE)
, m_bRVDropBFrameTimings(FALSE)
, m_dwSYNC(0)
, m_dwSYNC2(0)
, m_bDecodingStart(FALSE)
, m_dRate(1.0)
, m_pMSDKDecoder(nullptr)
, m_iMvcOutputMode(MVC_OUTPUT_Auto)
, m_bMvcSwapLR(false)
, m_MVC_Base_View_R_flag(FALSE)
, m_dxva_pix_fmt(AV_PIX_FMT_NONE)
, m_HWPixFmt(AV_PIX_FMT_NONE)
{
Expand Down Expand Up @@ -1128,10 +1090,6 @@ CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
}
}

memset(&m_DDPixelFormat, 0, sizeof(m_DDPixelFormat));
memset(&m_VideoFilters, false, sizeof(m_VideoFilters));
m_VideoFilters[VDEC_UNCOMPRESSED] = true;

#ifdef REGISTER_FILTER
CRegKey key;
WCHAR buff[256];
Expand Down
Loading

0 comments on commit 2e1b74c

Please sign in to comment.