Skip to content

Commit

Permalink
[r3128] Изменение : MPCVideoDec - добавлен "хак" когда декодер не мож…
Browse files Browse the repository at this point in the history
…ет определить параметры видео-потока при открытии файла и использовании DXVA декодера для видео 8 бит, а поток 10 бит - при этом пытаемся переключиться на "правильный" DXVA декодер, если устройство не поддерживается - переключаемся в софт.
  • Loading branch information
Aleksoid1978 committed Nov 18, 2017
1 parent 1ca4e0d commit 68e6751
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/filters/transform/MPCVideoDec/MPCVideoDec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "../../../DSUtil/SysVersion.h"
#include "../../parser/AviSplitter/AviSplitter.h"
#include "../../Lock.h"
#include "../../renderer/VideoRenderers/IPinHook.h"
#include <moreuuids.h>
#include <FilterInterfaces.h>

Expand Down Expand Up @@ -959,6 +960,7 @@ CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
, m_iMvcOutputMode(MVC_OUTPUT_Auto)
, m_bMvcSwapLR(false)
, m_MVC_Base_View_R_flag(FALSE)
, m_dxva_pix_fmt(AV_PIX_FMT_NONE)
{
if (phr) {
*phr = S_OK;
Expand Down Expand Up @@ -1903,6 +1905,7 @@ HRESULT CMPCVideoDecFilter::InitDecoder(const CMediaType *pmt)
|| (m_nCodecId == AV_CODEC_ID_VP9 && m_pAVCtx->profile == FF_PROFILE_VP9_2));

m_dxvaExtFormat = GetDXVA2ExtendedFormat(m_pAVCtx, m_pFrame);
m_dxva_pix_fmt = m_pAVCtx->pix_fmt;

if (bChangeType && IsDXVASupported()) {
do {
Expand Down Expand Up @@ -2002,7 +2005,7 @@ void CMPCVideoDecFilter::BuildOutputFormat()
int nSwIndex[PixFmt_count] = { 0 };
int nSwCount = 0;

const enum AVPixelFormat pix_fmt = m_pMSDKDecoder ? AV_PIX_FMT_NV12 : m_pAVCtx->pix_fmt;
const enum AVPixelFormat pix_fmt = m_pMSDKDecoder ? AV_PIX_FMT_NV12 : (m_pAVCtx->sw_pix_fmt != AV_PIX_FMT_NONE ? m_pAVCtx->sw_pix_fmt : m_pAVCtx->pix_fmt);

if (pix_fmt != AV_PIX_FMT_NONE) {
const AVPixFmtDescriptor* av_pfdesc = av_pix_fmt_desc_get(pix_fmt);
Expand Down Expand Up @@ -2394,7 +2397,7 @@ HRESULT CMPCVideoDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pRece

if (IsDXVASupported()) {
HRESULT hr;
if (FAILED(hr = InitDecoder(&m_pInput->CurrentMediaType()))) {
if (FAILED(hr = InitDecoder(&m_pCurrentMediaType))) {
return hr;
}

Expand Down Expand Up @@ -2500,7 +2503,7 @@ HRESULT CMPCVideoDecFilter::NewSegment(REFERENCE_TIME rtStart, REFERENCE_TIME rt

if (m_bDecodingStart && m_pAVCtx) {
if (m_nCodecId == AV_CODEC_ID_H264 || m_nCodecId == AV_CODEC_ID_MPEG2VIDEO) {
InitDecoder(&m_pInput->CurrentMediaType());
InitDecoder(&m_pCurrentMediaType);
}

if (UseDXVA2()
Expand Down Expand Up @@ -2805,6 +2808,34 @@ HRESULT CMPCVideoDecFilter::DecodeInternal(AVPacket *avpkt, REFERENCE_TIME rtSta
UpdateAspectRatio();

if (UseDXVA2()) {
if ((m_nCodecId == AV_CODEC_ID_HEVC || m_nCodecId == AV_CODEC_ID_VP9)
&& m_dxva_pix_fmt != m_pAVCtx->sw_pix_fmt) {
const int depth = GetLumaBits(m_pAVCtx->sw_pix_fmt);
const BOOL bHighBitdepth = (depth == 10) && ((m_nCodecId == AV_CODEC_ID_HEVC && m_pAVCtx->profile == FF_PROFILE_HEVC_MAIN_10)
|| (m_nCodecId == AV_CODEC_ID_VP9 && m_pAVCtx->profile == FF_PROFILE_VP9_2));

if (bHighBitdepth != m_bHighBitdepth) {
m_bHighBitdepth = bHighBitdepth;
if (SUCCEEDED(FindDecoderConfiguration())) {
ChangeOutputMediaFormat(2);
RecommitAllocator();
} else {
SAFE_DELETE(m_pDXVADecoder);
m_nDecoderMode = MODE_SOFTWARE;
DXVAState::ClearState();

HRESULT hr;
if (FAILED(hr = InitDecoder(&m_pCurrentMediaType))) {
return hr;
}

ChangeOutputMediaFormat(2);
return hr;
}
}
}
m_dxva_pix_fmt = m_pAVCtx->sw_pix_fmt;

hr = m_pDXVADecoder->DeliverFrame();
Continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/filters/transform/MPCVideoDec/MPCVideoDec.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class __declspec(uuid("008BAC12-FBAF-497b-9670-BC6F6FBAE2C4"))
int m_nSurfaceWidth = 0;
int m_nSurfaceHeight = 0;

AVPixelFormat m_dxva_pix_fmt;

static int av_get_buffer(struct AVCodecContext *c, AVFrame *pic, int flags);
static enum AVPixelFormat av_get_format(struct AVCodecContext *s, const enum AVPixelFormat * pix_fmts);

Expand Down

0 comments on commit 68e6751

Please sign in to comment.