Bug 1764823 - When attempting to hardware decode H264 video, the D3D9 DXVA support check will now correctly use the input media type. r=alwu

Improved the debug description of WMF video decoders to list the DXVA version used as well as the correct output type.

Differential Revision: https://phabricator.services.mozilla.com/D143775
This commit is contained in:
Zaggy1024 2022-04-15 04:21:48 +00:00
parent c40c17bfa2
commit 28b46457ec
2 changed files with 62 additions and 22 deletions

View File

@ -210,19 +210,19 @@ HRESULT ConvertMFTypeToDXVAType(IMFMediaType* pType, DXVA2_VideoDesc* pDesc) {
UINT32 fpsNumerator = 0;
UINT32 fpsDenominator = 0;
hr = MFGetAttributeRatio(pType, MF_MT_FRAME_RATE, &fpsNumerator,
&fpsDenominator);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
pDesc->InputSampleFreq.Numerator = fpsNumerator;
pDesc->InputSampleFreq.Denominator = fpsDenominator;
if (SUCCEEDED(MFGetAttributeRatio(pType, MF_MT_FRAME_RATE, &fpsNumerator,
&fpsDenominator))) {
pDesc->InputSampleFreq.Numerator = fpsNumerator;
pDesc->InputSampleFreq.Denominator = fpsDenominator;
GetDXVA2ExtendedFormatFromMFMediaType(pType, &pDesc->SampleFormat);
pDesc->OutputFrameFreq = pDesc->InputSampleFreq;
if ((pDesc->SampleFormat.SampleFormat ==
DXVA2_SampleFieldInterleavedEvenFirst) ||
(pDesc->SampleFormat.SampleFormat ==
DXVA2_SampleFieldInterleavedOddFirst)) {
pDesc->OutputFrameFreq.Numerator *= 2;
GetDXVA2ExtendedFormatFromMFMediaType(pType, &pDesc->SampleFormat);
pDesc->OutputFrameFreq = pDesc->InputSampleFreq;
if ((pDesc->SampleFormat.SampleFormat ==
DXVA2_SampleFieldInterleavedEvenFirst) ||
(pDesc->SampleFormat.SampleFormat ==
DXVA2_SampleFieldInterleavedOddFirst)) {
pDesc->OutputFrameFreq.Numerator *= 2;
}
}
return S_OK;
@ -275,9 +275,7 @@ bool D3D9DXVA2Manager::SupportsConfig(IMFMediaType* aInputType,
}
DXVA2_VideoDesc desc;
// TODO Bug 1764823: ConvertMFTypeToDXVAType should accept the input type
// instead.
hr = ConvertMFTypeToDXVAType(aOutputType, &desc);
hr = ConvertMFTypeToDXVAType(aInputType, &desc);
NS_ENSURE_TRUE(SUCCEEDED(hr), false);
return CanCreateDecoder(desc, aFramerate);
}

View File

@ -526,6 +526,12 @@ WMFVideoMFTManager::SetDecoderMediaTypes() {
mVideoInfo.ImageRect().height);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
UINT32 fpsDenominator = 1000;
UINT32 fpsNumerator = static_cast<uint32_t>(mFramerate * fpsDenominator);
hr = MFSetAttributeRatio(inputType, MF_MT_FRAME_RATE, fpsNumerator,
fpsDenominator);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
RefPtr<IMFMediaType> outputType;
hr = wmf::MFCreateMediaType(getter_AddRefs(outputType));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
@ -538,6 +544,10 @@ WMFVideoMFTManager::SetDecoderMediaTypes() {
mVideoInfo.ImageRect().height);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
hr = MFSetAttributeRatio(outputType, MF_MT_FRAME_RATE, fpsNumerator,
fpsDenominator);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
GUID outputSubType = mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12;
hr = outputType->SetGUID(MF_MT_SUBTYPE, outputSubType);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
@ -990,14 +1000,46 @@ bool WMFVideoMFTManager::IsHardwareAccelerated(
nsCString WMFVideoMFTManager::GetDescriptionName() const {
nsCString failureReason;
bool hw = IsHardwareAccelerated(failureReason);
return nsPrintfCString("wmf %s codec %s video decoder - %s",
const char* formatName = [&]() {
GUID format = mDecoder->GetOutputMediaSubType();
if (format == MFVideoFormat_NV12) {
if (!gfx::DeviceManagerDx::Get()->CanUseNV12()) {
return "nv12->argb32";
}
return "nv12";
}
if (format == MFVideoFormat_P010) {
if (!gfx::DeviceManagerDx::Get()->CanUseP010()) {
return "p010->argb32";
}
return "p010";
}
if (format == MFVideoFormat_P016) {
if (!gfx::DeviceManagerDx::Get()->CanUseP016()) {
return "p016->argb32";
}
return "p016";
}
if (format == MFVideoFormat_YV12) {
return "yv12";
}
return "unknown";
}();
const char* dxvaName = [&]() {
if (!mDXVA2Manager) {
return "no DXVA";
}
if (mDXVA2Manager->IsD3D11()) {
return "D3D11";
}
return "D3D9";
}();
return nsPrintfCString("wmf %s codec %s video decoder - %s, %s",
WMFDecoderModule::StreamTypeToString(mStreamType),
hw ? "hardware" : "software",
hw ? StaticPrefs::media_wmf_use_nv12_format() &&
gfx::DeviceManagerDx::Get()->CanUseNV12()
? "nv12"
: "rgba32"
: "yuv420");
hw ? "hardware" : "software", dxvaName, formatName);
}
} // namespace mozilla