diff --git a/dom/media/platforms/wmf/DXVA2Manager.cpp b/dom/media/platforms/wmf/DXVA2Manager.cpp index d4d0ca3118d9..5bb54f5dd7f8 100644 --- a/dom/media/platforms/wmf/DXVA2Manager.cpp +++ b/dom/media/platforms/wmf/DXVA2Manager.cpp @@ -4,24 +4,24 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "DXVA2Manager.h" #include -#include "nsThreadUtils.h" -#include "ImageContainer.h" -#include "gfxWindowsPlatform.h" +#include "DXVA2Manager.h" #include "D3D9SurfaceImage.h" +#include "DriverCrashGuard.h" +#include "ImageContainer.h" +#include "MFTDecoder.h" +#include "MediaTelemetryConstants.h" +#include "gfxCrashReporterUtils.h" +#include "gfxPrefs.h" +#include "gfxWindowsPlatform.h" +#include "mfapi.h" +#include "mozilla/Telemetry.h" #include "mozilla/gfx/DeviceManagerDx.h" #include "mozilla/layers/D3D11ShareHandleImage.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/TextureForwarder.h" -#include "mozilla/Telemetry.h" -#include "MediaTelemetryConstants.h" -#include "mfapi.h" -#include "gfxPrefs.h" -#include "MFTDecoder.h" -#include "DriverCrashGuard.h" #include "nsPrintfCString.h" -#include "gfxCrashReporterUtils.h" +#include "nsThreadUtils.h" const CLSID CLSID_VideoProcessorMFT = { @@ -122,35 +122,35 @@ private: RefPtr mSyncSurface; RefPtr mDecoder; GUID mDecoderGUID; - UINT32 mResetToken; - bool mFirstFrame; + UINT32 mResetToken = 0; + bool mFirstFrame = true; }; void GetDXVA2ExtendedFormatFromMFMediaType(IMFMediaType *pType, DXVA2_ExtendedFormat *pFormat) { // Get the interlace mode. - MFVideoInterlaceMode interlace = - (MFVideoInterlaceMode)MFGetAttributeUINT32(pType, MF_MT_INTERLACE_MODE, MFVideoInterlace_Unknown); + MFVideoInterlaceMode interlace = MFVideoInterlaceMode(MFGetAttributeUINT32( + pType, MF_MT_INTERLACE_MODE, MFVideoInterlace_Unknown)); if (interlace == MFVideoInterlace_MixedInterlaceOrProgressive) { pFormat->SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst; } else { - pFormat->SampleFormat = (UINT)interlace; + pFormat->SampleFormat = UINT(interlace); } - pFormat->VideoChromaSubsampling = - MFGetAttributeUINT32(pType, MF_MT_VIDEO_CHROMA_SITING, MFVideoChromaSubsampling_Unknown); - pFormat->NominalRange = - MFGetAttributeUINT32(pType, MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_Unknown); - pFormat->VideoTransferMatrix = - MFGetAttributeUINT32(pType, MF_MT_YUV_MATRIX, MFVideoTransferMatrix_Unknown); + pFormat->VideoChromaSubsampling = MFGetAttributeUINT32( + pType, MF_MT_VIDEO_CHROMA_SITING, MFVideoChromaSubsampling_Unknown); + pFormat->NominalRange = MFGetAttributeUINT32( + pType, MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_Unknown); + pFormat->VideoTransferMatrix = MFGetAttributeUINT32( + pType, MF_MT_YUV_MATRIX, MFVideoTransferMatrix_Unknown); pFormat->VideoLighting = MFGetAttributeUINT32(pType, MF_MT_VIDEO_LIGHTING, MFVideoLighting_Unknown); pFormat->VideoPrimaries = MFGetAttributeUINT32(pType, MF_MT_VIDEO_PRIMARIES, MFVideoPrimaries_Unknown); - pFormat->VideoTransferFunction = - MFGetAttributeUINT32(pType, MF_MT_TRANSFER_FUNCTION, MFVideoTransFunc_Unknown); + pFormat->VideoTransferFunction = MFGetAttributeUINT32( + pType, MF_MT_TRANSFER_FUNCTION, MFVideoTransFunc_Unknown); } HRESULT ConvertMFTypeToDXVAType(IMFMediaType *pType, DXVA2_VideoDesc *pDesc) @@ -172,15 +172,18 @@ HRESULT ConvertMFTypeToDXVAType(IMFMediaType *pType, DXVA2_VideoDesc *pDesc) UINT32 fpsNumerator = 0; UINT32 fpsDenominator = 0; - hr = MFGetAttributeRatio(pType, MF_MT_FRAME_RATE, &fpsNumerator, &fpsDenominator); + hr = MFGetAttributeRatio( + pType, MF_MT_FRAME_RATE, &fpsNumerator, &fpsDenominator); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); 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)) { + if ((pDesc->SampleFormat.SampleFormat + == DXVA2_SampleFieldInterleavedEvenFirst) + || (pDesc->SampleFormat.SampleFormat + == DXVA2_SampleFieldInterleavedOddFirst)) { pDesc->OutputFrameFreq.Numerator *= 2; } @@ -210,8 +213,6 @@ D3D9DXVA2Manager::SupportsConfig(IMFMediaType* aType, float aFramerate) } D3D9DXVA2Manager::D3D9DXVA2Manager() - : mResetToken(0) - , mFirstFrame(true) { MOZ_COUNT_CTOR(D3D9DXVA2Manager); MOZ_ASSERT(NS_IsMainThread()); @@ -249,10 +250,11 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, HMODULE d3d9lib = LoadLibraryW(L"d3d9.dll"); NS_ENSURE_TRUE(d3d9lib, E_FAIL); decltype(Direct3DCreate9Ex)* d3d9Create = - (decltype(Direct3DCreate9Ex)*) GetProcAddress(d3d9lib, "Direct3DCreate9Ex"); + (decltype(Direct3DCreate9Ex)*)GetProcAddress(d3d9lib, "Direct3DCreate9Ex"); if (!d3d9Create) { NS_WARNING("Couldn't find Direct3DCreate9Ex symbol in d3d9.dll"); - aFailureReason.AssignLiteral("Couldn't find Direct3DCreate9Ex symbol in d3d9.dll"); + aFailureReason.AssignLiteral( + "Couldn't find Direct3DCreate9Ex symbol in d3d9.dll"); return E_FAIL; } RefPtr d3d9Ex; @@ -265,12 +267,14 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, // Ensure we can do the YCbCr->RGB conversion in StretchRect. // Fail if we can't. - hr = d3d9Ex->CheckDeviceFormatConversion(D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - (D3DFORMAT)MAKEFOURCC('N','V','1','2'), - D3DFMT_X8R8G8B8); + hr = d3d9Ex->CheckDeviceFormatConversion( + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'), + D3DFMT_X8R8G8B8); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("CheckDeviceFormatConversion failed with error %X", hr); + aFailureReason = + nsPrintfCString("CheckDeviceFormatConversion failed with error %X", hr); return hr; } @@ -291,9 +295,9 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, hr = d3d9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, nullptr, - D3DCREATE_FPU_PRESERVE | - D3DCREATE_MULTITHREADED | - D3DCREATE_MIXED_VERTEXPROCESSING, + D3DCREATE_FPU_PRESERVE + | D3DCREATE_MULTITHREADED + | D3DCREATE_MIXED_VERTEXPROCESSING, ¶ms, nullptr, getter_AddRefs(device)); @@ -321,12 +325,14 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, hr = wmf::DXVA2CreateDirect3DDeviceManager9(&resetToken, getter_AddRefs(deviceManager)); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("DXVA2CreateDirect3DDeviceManager9 failed with error %X", hr); + aFailureReason = nsPrintfCString( + "DXVA2CreateDirect3DDeviceManager9 failed with error %X", hr); return hr; } hr = deviceManager->ResetDevice(device, resetToken); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDirect3DDeviceManager9::ResetDevice failed with error %X", hr); + aFailureReason = nsPrintfCString( + "IDirect3DDeviceManager9::ResetDevice failed with error %X", hr); return hr; } @@ -334,14 +340,17 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, RefPtr decoderService; hr = deviceManager->OpenDeviceHandle(&deviceHandle); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDirect3DDeviceManager9::OpenDeviceHandle failed with error %X", hr); + aFailureReason = nsPrintfCString( + "IDirect3DDeviceManager9::OpenDeviceHandle failed with error %X", hr); return hr; } - hr = deviceManager->GetVideoService(deviceHandle, IID_PPV_ARGS(decoderService.StartAssignment())); + hr = deviceManager->GetVideoService( + deviceHandle, IID_PPV_ARGS(decoderService.StartAssignment())); deviceManager->CloseDeviceHandle(deviceHandle); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDirectXVideoDecoderServer::GetVideoService failed with error %X", hr); + aFailureReason = nsPrintfCString( + "IDirectXVideoDecoderServer::GetVideoService failed with error %X", hr); return hr; } @@ -349,14 +358,16 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, GUID* decoderDevices = nullptr; hr = decoderService->GetDecoderDeviceGuids(&deviceCount, &decoderDevices); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDirectXVideoDecoderServer::GetDecoderDeviceGuids failed with error %X", hr); + aFailureReason = nsPrintfCString( + "IDirectXVideoDecoderServer::GetDecoderDeviceGuids failed with error %X", + hr); return hr; } bool found = false; for (UINT i = 0; i < deviceCount; i++) { - if (decoderDevices[i] == DXVA2_ModeH264_E || - decoderDevices[i] == DXVA2_Intel_ModeH264_E) { + if (decoderDevices[i] == DXVA2_ModeH264_E + || decoderDevices[i] == DXVA2_Intel_ModeH264_E) { mDecoderGUID = decoderDevices[i]; found = true; break; @@ -372,13 +383,14 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, D3DADAPTER_IDENTIFIER9 adapter; hr = d3d9Ex->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &adapter); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDirect3D9Ex::GetAdapterIdentifier failed with error %X", hr); + aFailureReason = nsPrintfCString( + "IDirect3D9Ex::GetAdapterIdentifier failed with error %X", hr); return hr; } if (adapter.VendorId == 0x1022 && !gfxPrefs::PDMWMFSkipBlacklist()) { - for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sAMDPreUVD4); i++) { - if (adapter.DeviceId == sAMDPreUVD4[i]) { + for (const auto& model : sAMDPreUVD4) { + if (adapter.DeviceId == model) { mIsAMDPreUVD4 = true; break; } @@ -402,11 +414,11 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, if (layers::ImageBridgeChild::GetSingleton()) { // There's no proper KnowsCompositor for ImageBridge currently (and it // implements the interface), so just use that if it's available. - mTextureClientAllocator = new D3D9RecycleAllocator(layers::ImageBridgeChild::GetSingleton().get(), - mDevice); + mTextureClientAllocator = new D3D9RecycleAllocator( + layers::ImageBridgeChild::GetSingleton().get(), mDevice); } else { - mTextureClientAllocator = new D3D9RecycleAllocator(aKnowsCompositor, - mDevice); + mTextureClientAllocator = + new D3D9RecycleAllocator(aKnowsCompositor, mDevice); } mTextureClientAllocator->SetMaxPoolSize(5); @@ -443,7 +455,8 @@ D3D9DXVA2Manager::CopyToImage(IMFSample* aSample, // Copy a small rect into our sync surface, and then map it // to block until decoding/color conversion completes. RECT copyRect = { 0, 0, kSyncSurfaceSize, kSyncSurfaceSize }; - hr = mDevice->StretchRect(sourceSurf, ©Rect, mSyncSurface, ©Rect, D3DTEXF_NONE); + hr = mDevice->StretchRect( + sourceSurf, ©Rect, mSyncSurface, ©Rect, D3DTEXF_NONE); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); D3DLOCKED_RECT lockedRect; @@ -500,13 +513,14 @@ D3D9DXVA2Manager::CreateDXVA2Decoder(const VideoInfo& aVideoInfo, // Assume the current duration is representative for the entire video. float framerate = 1000000.0 / aVideoInfo.mDuration; - if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight , framerate)) { + if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight, framerate)) { return false; } mDecoder = CreateDecoder(desc); if (!mDecoder) { - aFailureReason = nsPrintfCString("Fail to create video decoder in D3D9DXVA2Manager."); + aFailureReason = + nsPrintfCString("Fail to create video decoder in D3D9DXVA2Manager."); return false; } return true; @@ -517,7 +531,8 @@ D3D9DXVA2Manager::CanCreateDecoder(const DXVA2_VideoDesc& aDesc, const float aFramerate) const { MOZ_ASSERT(NS_IsMainThread()); - if (IsUnsupportedResolution(aDesc.SampleWidth, aDesc.SampleHeight, aFramerate)) { + if (IsUnsupportedResolution( + aDesc.SampleWidth, aDesc.SampleHeight, aFramerate)) { return false; } RefPtr decoder = CreateDecoder(aDesc); @@ -536,13 +551,20 @@ D3D9DXVA2Manager::CreateDecoder(const DXVA2_VideoDesc& aDesc) const UINT configCount; DXVA2_ConfigPictureDecode* configs = nullptr; - HRESULT hr = mDecoderService->GetDecoderConfigurations(mDecoderGUID, &aDesc, nullptr, &configCount, &configs); + HRESULT hr = mDecoderService->GetDecoderConfigurations( + mDecoderGUID, &aDesc, nullptr, &configCount, &configs); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); RefPtr surface; - hr = mDecoderService->CreateSurface(aDesc.SampleWidth, aDesc.SampleHeight, 0, (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'), - D3DPOOL_DEFAULT, 0, DXVA2_VideoDecoderRenderTarget, - surface.StartAssignment(), NULL); + hr = mDecoderService->CreateSurface(aDesc.SampleWidth, + aDesc.SampleHeight, + 0, + (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'), + D3DPOOL_DEFAULT, + 0, + DXVA2_VideoDecoderRenderTarget, + surface.StartAssignment(), + NULL); if (!SUCCEEDED(hr)) { CoTaskMemFree(configs); return nullptr; @@ -551,7 +573,12 @@ D3D9DXVA2Manager::CreateDecoder(const DXVA2_VideoDesc& aDesc) const for (UINT i = 0; i < configCount; i++) { RefPtr decoder; IDirect3DSurface9* surfaces = surface; - hr = mDecoderService->CreateVideoDecoder(mDecoderGUID, &aDesc, &configs[i], &surfaces, 1, decoder.StartAssignment()); + hr = mDecoderService->CreateVideoDecoder(mDecoderGUID, + &aDesc, + &configs[i], + &surfaces, + 1, + decoder.StartAssignment()); CoTaskMemFree(configs); return decoder.forget(); } @@ -563,7 +590,6 @@ D3D9DXVA2Manager::CreateDecoder(const DXVA2_VideoDesc& aDesc) const class D3D11DXVA2Manager : public DXVA2Manager { public: - D3D11DXVA2Manager(); virtual ~D3D11DXVA2Manager(); HRESULT Init(layers::KnowsCompositor* aKnowsCompositor, @@ -606,9 +632,9 @@ private: RefPtr mSyncSurface; RefPtr mDecoder; GUID mDecoderGUID; - uint32_t mWidth; - uint32_t mHeight; - UINT mDeviceManagerToken; + uint32_t mWidth = 0; + uint32_t mHeight = 0; + UINT mDeviceManagerToken = 0; }; bool @@ -623,16 +649,7 @@ D3D11DXVA2Manager::SupportsConfig(IMFMediaType* aType, float aFramerate) return CanCreateDecoder(desc, aFramerate); } -D3D11DXVA2Manager::D3D11DXVA2Manager() - : mWidth(0) - , mHeight(0) - , mDeviceManagerToken(0) -{ -} - -D3D11DXVA2Manager::~D3D11DXVA2Manager() -{ -} +D3D11DXVA2Manager::~D3D11DXVA2Manager() { } IUnknown* D3D11DXVA2Manager::GetDXVADeviceManager() @@ -664,39 +681,49 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, mDevice->GetImmediateContext(getter_AddRefs(mContext)); if (!mContext) { - aFailureReason.AssignLiteral("Failed to get immediate context for d3d11 device"); + aFailureReason.AssignLiteral( + "Failed to get immediate context for d3d11 device"); return E_FAIL; } - hr = wmf::MFCreateDXGIDeviceManager(&mDeviceManagerToken, getter_AddRefs(mDXGIDeviceManager)); + hr = wmf::MFCreateDXGIDeviceManager(&mDeviceManagerToken, + getter_AddRefs(mDXGIDeviceManager)); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("MFCreateDXGIDeviceManager failed with code %X", hr); + aFailureReason = + nsPrintfCString("MFCreateDXGIDeviceManager failed with code %X", hr); return hr; } hr = mDXGIDeviceManager->ResetDevice(mDevice, mDeviceManagerToken); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IMFDXGIDeviceManager::ResetDevice failed with code %X", hr); + aFailureReason = nsPrintfCString( + "IMFDXGIDeviceManager::ResetDevice failed with code %X", hr); return hr; } mTransform = new MFTDecoder(); hr = mTransform->Create(CLSID_VideoProcessorMFT); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("MFTDecoder::Create(CLSID_VideoProcessorMFT) failed with code %X", hr); + aFailureReason = nsPrintfCString( + "MFTDecoder::Create(CLSID_VideoProcessorMFT) failed with code %X", hr); return hr; } - hr = mTransform->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, ULONG_PTR(mDXGIDeviceManager.get())); + hr = mTransform->SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER, + ULONG_PTR(mDXGIDeviceManager.get())); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("MFTDecoder::SendMFTMessage(MFT_MESSAGE_SET_D3D_MANAGER) failed with code %X", hr); + aFailureReason = nsPrintfCString("MFTDecoder::SendMFTMessage(MFT_MESSAGE_" + "SET_D3D_MANAGER) failed with code %X", + hr); return hr; } RefPtr videoDevice; - hr = mDevice->QueryInterface(static_cast(getter_AddRefs(videoDevice))); + hr = mDevice->QueryInterface( + static_cast(getter_AddRefs(videoDevice))); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("QI to ID3D11VideoDevice failed with code %X", hr); + aFailureReason = + nsPrintfCString("QI to ID3D11VideoDevice failed with code %X", hr); return hr; } @@ -705,7 +732,8 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, for (UINT i = 0; i < profileCount; i++) { GUID id; hr = videoDevice->GetVideoDecoderProfile(i, &id); - if (SUCCEEDED(hr) && (id == DXVA2_ModeH264_E || id == DXVA2_Intel_ModeH264_E)) { + if (SUCCEEDED(hr) + && (id == DXVA2_ModeH264_E || id == DXVA2_Intel_ModeH264_E)) { mDecoderGUID = id; found = true; break; @@ -717,9 +745,11 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, } BOOL nv12Support = false; - hr = videoDevice->CheckVideoDecoderFormat(&mDecoderGUID, DXGI_FORMAT_NV12, &nv12Support); + hr = videoDevice->CheckVideoDecoderFormat( + &mDecoderGUID, DXGI_FORMAT_NV12, &nv12Support); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("CheckVideoDecoderFormat failed with code %X", hr); + aFailureReason = + nsPrintfCString("CheckVideoDecoderFormat failed with code %X", hr); return hr; } if (!nv12Support) { @@ -728,29 +758,33 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, } RefPtr dxgiDevice; - hr = mDevice->QueryInterface(static_cast(getter_AddRefs(dxgiDevice))); + hr = mDevice->QueryInterface( + static_cast(getter_AddRefs(dxgiDevice))); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("QI to IDXGIDevice failed with code %X", hr); + aFailureReason = + nsPrintfCString("QI to IDXGIDevice failed with code %X", hr); return hr; } RefPtr adapter; hr = dxgiDevice->GetAdapter(adapter.StartAssignment()); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDXGIDevice::GetAdapter failed with code %X", hr); + aFailureReason = + nsPrintfCString("IDXGIDevice::GetAdapter failed with code %X", hr); return hr; } DXGI_ADAPTER_DESC adapterDesc; hr = adapter->GetDesc(&adapterDesc); if (!SUCCEEDED(hr)) { - aFailureReason = nsPrintfCString("IDXGIAdapter::GetDesc failed with code %X", hr); + aFailureReason = + nsPrintfCString("IDXGIAdapter::GetDesc failed with code %X", hr); return hr; } if (adapterDesc.VendorId == 0x1022 && !gfxPrefs::PDMWMFSkipBlacklist()) { - for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sAMDPreUVD4); i++) { - if (adapterDesc.DeviceId == sAMDPreUVD4[i]) { + for (const auto& model : sAMDPreUVD4) { + if (adapterDesc.DeviceId == model) { mIsAMDPreUVD4 = true; break; } @@ -776,11 +810,11 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, if (layers::ImageBridgeChild::GetSingleton()) { // There's no proper KnowsCompositor for ImageBridge currently (and it // implements the interface), so just use that if it's available. - mTextureClientAllocator = new D3D11RecycleAllocator(layers::ImageBridgeChild::GetSingleton().get(), - mDevice); + mTextureClientAllocator = new D3D11RecycleAllocator( + layers::ImageBridgeChild::GetSingleton().get(), mDevice); } else { - mTextureClientAllocator = new D3D11RecycleAllocator(aKnowsCompositor, - mDevice); + mTextureClientAllocator = + new D3D11RecycleAllocator(aKnowsCompositor, mDevice); } mTextureClientAllocator->SetMaxPoolSize(5); @@ -793,14 +827,16 @@ D3D11DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor, } HRESULT -D3D11DXVA2Manager::CreateOutputSample(RefPtr& aSample, ID3D11Texture2D* aTexture) +D3D11DXVA2Manager::CreateOutputSample(RefPtr& aSample, + ID3D11Texture2D* aTexture) { RefPtr sample; HRESULT hr = wmf::MFCreateSample(getter_AddRefs(sample)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); RefPtr buffer; - hr = wmf::MFCreateDXGISurfaceBuffer(__uuidof(ID3D11Texture2D), aTexture, 0, FALSE, getter_AddRefs(buffer)); + hr = wmf::MFCreateDXGISurfaceBuffer( + __uuidof(ID3D11Texture2D), aTexture, 0, FALSE, getter_AddRefs(buffer)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); sample->AddBuffer(buffer); @@ -857,7 +893,8 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample, HRESULT ConfigureOutput(IMFMediaType* aOutput, void* aData) { - HRESULT hr = aOutput->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); + HRESULT hr = + aOutput->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = aOutput->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); @@ -933,13 +970,14 @@ D3D11DXVA2Manager::CreateDXVA2Decoder(const VideoInfo& aVideoInfo, // Assume the current duration is representative for the entire video. float framerate = 1000000.0 / aVideoInfo.mDuration; - if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight , framerate)) { + if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight, framerate)) { return false; } mDecoder = CreateDecoder(desc); if (!mDecoder) { - aFailureReason = nsPrintfCString("Fail to create video decoder in D3D11DXVA2Manager."); + aFailureReason = + nsPrintfCString("Fail to create video decoder in D3D11DXVA2Manager."); return false; } return true; @@ -950,7 +988,8 @@ D3D11DXVA2Manager::CanCreateDecoder(const D3D11_VIDEO_DECODER_DESC& aDesc, const float aFramerate) const { MOZ_ASSERT(NS_IsMainThread()); - if (IsUnsupportedResolution(aDesc.SampleWidth, aDesc.SampleHeight, aFramerate)) { + if (IsUnsupportedResolution( + aDesc.SampleWidth, aDesc.SampleHeight, aFramerate)) { return false; } RefPtr decoder = CreateDecoder(aDesc); @@ -968,7 +1007,8 @@ D3D11DXVA2Manager::CreateDecoder(const D3D11_VIDEO_DECODER_DESC& aDesc) const } RefPtr videoDevice; - HRESULT hr = mDevice->QueryInterface(static_cast(getter_AddRefs(videoDevice))); + HRESULT hr = mDevice->QueryInterface( + static_cast(getter_AddRefs(videoDevice))); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); UINT configCount = 0; @@ -980,7 +1020,8 @@ D3D11DXVA2Manager::CreateDecoder(const D3D11_VIDEO_DECODER_DESC& aDesc) const hr = videoDevice->GetVideoDecoderConfig(&aDesc, i, &config); if (SUCCEEDED(hr)) { RefPtr decoder; - hr = videoDevice->CreateVideoDecoder(&aDesc, &config, decoder.StartAssignment()); + hr = videoDevice->CreateVideoDecoder( + &aDesc, &config, decoder.StartAssignment()); return decoder.forget(); } } @@ -1010,7 +1051,6 @@ DXVA2Manager::CreateD3D11DXVA(layers::KnowsCompositor* aKnowsCompositor, DXVA2Manager::DXVA2Manager() : mLock("DXVA2Manager") - , mIsAMDPreUVD4(false) { MOZ_ASSERT(NS_IsMainThread()); ++sDXVAVideosCount; @@ -1030,9 +1070,9 @@ DXVA2Manager::IsUnsupportedResolution(const uint32_t& aWidth, // AMD cards with UVD3 or earlier perform poorly trying to decode 1080p60 in // hardware, so use software instead. Pick 45 as an arbitrary upper bound for // the framerate we can handle. - return (mIsAMDPreUVD4 && - (aWidth >= 1920 || aHeight >= 1088) && - aFramerate > 45); + return mIsAMDPreUVD4 + && (aWidth >= 1920 || aHeight >= 1088) + && aFramerate > 45; } } // namespace mozilla diff --git a/dom/media/platforms/wmf/DXVA2Manager.h b/dom/media/platforms/wmf/DXVA2Manager.h index 0c5a647fcce9..b907359d4f64 100644 --- a/dom/media/platforms/wmf/DXVA2Manager.h +++ b/dom/media/platforms/wmf/DXVA2Manager.h @@ -6,10 +6,10 @@ #if !defined(DXVA2Manager_h_) #define DXVA2Manager_h_ -#include "WMF.h" #include "MediaInfo.h" -#include "nsAutoPtr.h" +#include "WMF.h" #include "mozilla/Mutex.h" +#include "nsAutoPtr.h" #include "nsRect.h" namespace mozilla { @@ -20,15 +20,18 @@ class ImageContainer; class KnowsCompositor; } -class DXVA2Manager { +class DXVA2Manager +{ public: // Creates and initializes a DXVA2Manager. We can use DXVA2 via either // D3D9Ex or D3D11. - static DXVA2Manager* CreateD3D9DXVA(layers::KnowsCompositor* aKnowsCompositor, - nsACString& aFailureReason); - static DXVA2Manager* CreateD3D11DXVA(layers::KnowsCompositor* aKnowsCompositor, - nsACString& aFailureReason); + static DXVA2Manager* CreateD3D9DXVA( + layers::KnowsCompositor* aKnowsCompositor, + nsACString& aFailureReason); + static DXVA2Manager* CreateD3D11DXVA( + layers::KnowsCompositor* aKnowsCompositor, + nsACString& aFailureReason); // Returns a pointer to the D3D device manager responsible for managing the // device we're using for hardware accelerated video decoding. If we're using @@ -41,7 +44,10 @@ public: const nsIntRect& aRegion, layers::Image** aOutImage) = 0; - virtual HRESULT ConfigureForSize(uint32_t aWidth, uint32_t aHeight) { return S_OK; } + virtual HRESULT ConfigureForSize(uint32_t aWidth, uint32_t aHeight) + { + return S_OK; + } virtual bool IsD3D11() { return false; } @@ -63,7 +69,7 @@ protected: const uint32_t& aHeight, const float& aFramerate) const; - bool mIsAMDPreUVD4; + bool mIsAMDPreUVD4 = false; }; } // namespace mozilla diff --git a/dom/media/platforms/wmf/MFTDecoder.cpp b/dom/media/platforms/wmf/MFTDecoder.cpp index e634fcff94b0..a8f4004f0c18 100644 --- a/dom/media/platforms/wmf/MFTDecoder.cpp +++ b/dom/media/platforms/wmf/MFTDecoder.cpp @@ -5,17 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MFTDecoder.h" -#include "nsThreadUtils.h" #include "WMFUtils.h" #include "mozilla/Logging.h" +#include "nsThreadUtils.h" #define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__)) namespace mozilla { MFTDecoder::MFTDecoder() - : mMFTProvidesOutputSamples(false) - , mDiscontinuity(true) { memset(&mInputStreamInfo, 0, sizeof(MFT_INPUT_STREAM_INFO)); memset(&mOutputStreamInfo, 0, sizeof(MFT_OUTPUT_STREAM_INFO)); @@ -34,7 +32,8 @@ MFTDecoder::Create(const GUID& aMFTClsID) nullptr, CLSCTX_INPROC_SERVER, IID_IMFTransform, - reinterpret_cast(static_cast(getter_AddRefs(mDecoder)))); + reinterpret_cast(static_cast( + getter_AddRefs(mDecoder)))); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); return S_OK; @@ -86,9 +85,11 @@ MFTDecoder::SetDecoderOutputType(ConfigureOutputCallback aCallback, void* aData) HRESULT hr; RefPtr outputType; UINT32 typeIndex = 0; - while (SUCCEEDED(mDecoder->GetOutputAvailableType(0, typeIndex++, getter_AddRefs(outputType)))) { + while (SUCCEEDED(mDecoder->GetOutputAvailableType( + 0, typeIndex++, getter_AddRefs(outputType)))) { BOOL resultMatch; - hr = mOutputType->Compare(outputType, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &resultMatch); + hr = mOutputType->Compare( + outputType, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &resultMatch); if (SUCCEEDED(hr) && resultMatch == TRUE) { if (aCallback) { hr = aCallback(outputType, aData); @@ -100,7 +101,8 @@ MFTDecoder::SetDecoderOutputType(ConfigureOutputCallback aCallback, void* aData) hr = mDecoder->GetOutputStreamInfo(0, &mOutputStreamInfo); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - mMFTProvidesOutputSamples = IsFlagSet(mOutputStreamInfo.dwFlags, MFT_OUTPUT_STREAM_PROVIDES_SAMPLES); + mMFTProvidesOutputSamples = IsFlagSet(mOutputStreamInfo.dwFlags, + MFT_OUTPUT_STREAM_PROVIDES_SAMPLES); return S_OK; } @@ -132,9 +134,12 @@ MFTDecoder::CreateInputSample(const uint8_t* aData, NS_ENSURE_TRUE(SUCCEEDED(hr), hr); RefPtr buffer; - int32_t bufferSize = std::max(uint32_t(mInputStreamInfo.cbSize), aDataSize); - UINT32 alignment = (mInputStreamInfo.cbAlignment > 1) ? mInputStreamInfo.cbAlignment - 1 : 0; - hr = wmf::MFCreateAlignedMemoryBuffer(bufferSize, alignment, getter_AddRefs(buffer)); + int32_t bufferSize = + std::max(uint32_t(mInputStreamInfo.cbSize), aDataSize); + UINT32 alignment = + (mInputStreamInfo.cbAlignment > 1) ? mInputStreamInfo.cbAlignment - 1 : 0; + hr = wmf::MFCreateAlignedMemoryBuffer( + bufferSize, alignment, getter_AddRefs(buffer)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); DWORD maxLength = 0; @@ -175,8 +180,10 @@ MFTDecoder::CreateOutputSample(RefPtr* aOutSample) RefPtr buffer; int32_t bufferSize = mOutputStreamInfo.cbSize; - UINT32 alignment = (mOutputStreamInfo.cbAlignment > 1) ? mOutputStreamInfo.cbAlignment - 1 : 0; - hr = wmf::MFCreateAlignedMemoryBuffer(bufferSize, alignment, getter_AddRefs(buffer)); + UINT32 alignment = + (mOutputStreamInfo.cbAlignment > 1) ? mOutputStreamInfo.cbAlignment - 1 : 0; + hr = wmf::MFCreateAlignedMemoryBuffer( + bufferSize, alignment, getter_AddRefs(buffer)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); hr = sample->AddBuffer(buffer); diff --git a/dom/media/platforms/wmf/MFTDecoder.h b/dom/media/platforms/wmf/MFTDecoder.h index 91c18f18c0bc..e2cc2b3dc044 100644 --- a/dom/media/platforms/wmf/MFTDecoder.h +++ b/dom/media/platforms/wmf/MFTDecoder.h @@ -8,13 +8,14 @@ #define MFTDecoder_h_ #include "WMF.h" -#include "mozilla/RefPtr.h" #include "mozilla/ReentrantMonitor.h" +#include "mozilla/RefPtr.h" #include "nsIThread.h" namespace mozilla { -class MFTDecoder final { +class MFTDecoder final +{ ~MFTDecoder(); public: @@ -36,7 +37,8 @@ public: // - aOutputType needs at least major and minor types set. // This is used to select the matching output type out // of all the available output types of the MFT. - typedef HRESULT (*ConfigureOutputCallback)(IMFMediaType* aOutputType, void* aData); + typedef HRESULT (*ConfigureOutputCallback)(IMFMediaType* aOutputType, + void* aData); HRESULT SetMediaTypes(IMFMediaType* aInputType, IMFMediaType* aOutputType, ConfigureOutputCallback aCallback = nullptr, @@ -100,10 +102,10 @@ private: RefPtr mOutputType; // True if the IMFTransform allocates the samples that it returns. - bool mMFTProvidesOutputSamples; + bool mMFTProvidesOutputSamples = false; // True if we need to mark the next sample as a discontinuity. - bool mDiscontinuity; + bool mDiscontinuity = true; }; } // namespace mozilla diff --git a/dom/media/platforms/wmf/WMFAudioMFTManager.cpp b/dom/media/platforms/wmf/WMFAudioMFTManager.cpp index 3ef3f33f3b5c..70b281fd39ad 100644 --- a/dom/media/platforms/wmf/WMFAudioMFTManager.cpp +++ b/dom/media/platforms/wmf/WMFAudioMFTManager.cpp @@ -6,13 +6,13 @@ #include "WMFAudioMFTManager.h" #include "MediaInfo.h" +#include "TimeUnits.h" #include "VideoUtils.h" #include "WMFUtils.h" -#include "nsTArray.h" -#include "TimeUnits.h" #include "mozilla/AbstractThread.h" -#include "mozilla/Telemetry.h" #include "mozilla/Logging.h" +#include "mozilla/Telemetry.h" +#include "nsTArray.h" #define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__)) @@ -86,8 +86,6 @@ WMFAudioMFTManager::WMFAudioMFTManager( const AudioInfo& aConfig) : mAudioChannels(aConfig.mChannels) , mAudioRate(aConfig.mRate) - , mAudioFrameSum(0) - , mMustRecaptureAudioPosition(true) { MOZ_COUNT_CTOR(WMFAudioMFTManager); @@ -264,7 +262,8 @@ WMFAudioMFTManager::Output(int64_t aStreamOffset, hr = sample->ConvertToContiguousBuffer(getter_AddRefs(buffer)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - BYTE* data = nullptr; // Note: *data will be owned by the IMFMediaBuffer, we don't need to free it. + BYTE* data = nullptr; // Note: *data will be owned by the IMFMediaBuffer, we + // don't need to free it. DWORD maxLength = 0, currentLength = 0; hr = buffer->Lock(&data, &maxLength, ¤tLength); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); diff --git a/dom/media/platforms/wmf/WMFAudioMFTManager.h b/dom/media/platforms/wmf/WMFAudioMFTManager.h index e294b234dc41..1002bd28cb0a 100644 --- a/dom/media/platforms/wmf/WMFAudioMFTManager.h +++ b/dom/media/platforms/wmf/WMFAudioMFTManager.h @@ -7,10 +7,10 @@ #if !defined(WMFAudioOutputSource_h_) #define WMFAudioOutputSource_h_ -#include "WMF.h" #include "MFTDecoder.h" -#include "mozilla/RefPtr.h" +#include "WMF.h" #include "WMFMediaDataDecoder.h" +#include "mozilla/RefPtr.h" extern const GUID CLSID_WebmMfVpxDec; @@ -55,7 +55,7 @@ private: media::TimeUnit mAudioTimeOffset; // The number of audio frames that we've played since the last // discontinuity. - int64_t mAudioFrameSum; + int64_t mAudioFrameSum = 0; enum StreamType { @@ -71,7 +71,7 @@ private: // True if we need to re-initialize mAudioTimeOffset and mAudioFrameSum // from the next audio packet we decode. This happens after a seek, since // WMF doesn't mark a stream as having a discontinuity after a seek(0). - bool mMustRecaptureAudioPosition; + bool mMustRecaptureAudioPosition = true; }; } // namespace mozilla diff --git a/dom/media/platforms/wmf/WMFDecoderModule.cpp b/dom/media/platforms/wmf/WMFDecoderModule.cpp index 8d5c5b053c3f..1cc425b23b7e 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.cpp +++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp @@ -4,40 +4,35 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "WMF.h" #include "WMFDecoderModule.h" -#include "WMFVideoMFTManager.h" -#include "WMFAudioMFTManager.h" -#include "MFTDecoder.h" -#include "mozilla/DebugOnly.h" -#include "mozilla/Services.h" -#include "WMFMediaDataDecoder.h" -#include "nsAutoPtr.h" -#include "nsIWindowsRegKey.h" -#include "nsComponentManagerUtils.h" -#include "nsServiceManagerUtils.h" -#include "nsIGfxInfo.h" -#include "nsWindowsHelpers.h" #include "GfxDriverInfo.h" -#include "mozilla/gfx/gfxVars.h" +#include "MFTDecoder.h" +#include "MP4Decoder.h" #include "MediaInfo.h" #include "MediaPrefs.h" -#include "prsystem.h" +#include "VPXDecoder.h" +#include "WMF.h" +#include "WMFAudioMFTManager.h" +#include "WMFMediaDataDecoder.h" +#include "WMFVideoMFTManager.h" +#include "mozilla/DebugOnly.h" #include "mozilla/Maybe.h" +#include "mozilla/Services.h" #include "mozilla/StaticMutex.h" #include "mozilla/WindowsVersion.h" -#include "MP4Decoder.h" -#include "VPXDecoder.h" +#include "mozilla/gfx/gfxVars.h" +#include "nsAutoPtr.h" +#include "nsComponentManagerUtils.h" +#include "nsIGfxInfo.h" +#include "nsIWindowsRegKey.h" +#include "nsServiceManagerUtils.h" +#include "nsWindowsHelpers.h" +#include "prsystem.h" namespace mozilla { static Atomic sDXVAEnabled(false); -WMFDecoderModule::WMFDecoderModule() - : mWMFInitialized(false) -{ -} - WMFDecoderModule::~WMFDecoderModule() { if (mWMFInitialized) { @@ -103,7 +98,8 @@ WMFDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams) already_AddRefed WMFDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams) { - nsAutoPtr manager(new WMFAudioMFTManager(aParams.AudioConfig())); + nsAutoPtr manager( + new WMFAudioMFTManager(aParams.AudioConfig())); if (!manager->Init()) { return nullptr; @@ -191,8 +187,9 @@ WMFDecoderModule::HasAAC() } bool -WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType, - DecoderDoctorDiagnostics* aDiagnostics) const +WMFDecoderModule::SupportsMimeType( + const nsACString& aMimeType, + DecoderDoctorDiagnostics* aDiagnostics) const { UniquePtr trackInfo = CreateTrackInfoWithMIMEType(aMimeType); if (!trackInfo) { @@ -210,7 +207,8 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo, WMFDecoderModule::HasAAC()) { return true; } - if (MP4Decoder::IsH264(aTrackInfo.mMimeType) && WMFDecoderModule::HasH264()) { + if (MP4Decoder::IsH264(aTrackInfo.mMimeType) + && WMFDecoderModule::HasH264()) { if (!MediaPrefs::PDMWMFAllowUnsupportedResolutions()) { const VideoInfo* videoInfo = aTrackInfo.GetAsVideoInfo(); MOZ_ASSERT(videoInfo); @@ -218,12 +216,14 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo, // https://msdn.microsoft.com/en-us/library/windows/desktop/dd797815(v=vs.85).aspx if (IsWin8OrLater()) { // Windows >7 supports at most 4096x2304. - if (videoInfo->mImage.width > 4096 || videoInfo->mImage.height > 2304) { + if (videoInfo->mImage.width > 4096 + || videoInfo->mImage.height > 2304) { return false; } } else { // Windows <=7 supports at most 1920x1088. - if (videoInfo->mImage.width > 1920 || videoInfo->mImage.height > 1088) { + if (videoInfo->mImage.width > 1920 + || videoInfo->mImage.height > 1088) { return false; } } @@ -235,9 +235,9 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo, return true; } if (MediaPrefs::PDMWMFVP9DecoderEnabled() && sDXVAEnabled) { - if ((VPXDecoder::IsVP8(aTrackInfo.mMimeType) || - VPXDecoder::IsVP9(aTrackInfo.mMimeType)) && - CanCreateWMFDecoder()) { + if ((VPXDecoder::IsVP8(aTrackInfo.mMimeType) + || VPXDecoder::IsVP9(aTrackInfo.mMimeType)) + && CanCreateWMFDecoder()) { return true; } } @@ -251,9 +251,8 @@ WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const { if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) { return ConversionRequired::kNeedAnnexB; - } else { - return ConversionRequired::kNeedNone; } + return ConversionRequired::kNeedNone; } } // namespace mozilla diff --git a/dom/media/platforms/wmf/WMFDecoderModule.h b/dom/media/platforms/wmf/WMFDecoderModule.h index 9746ba29c91e..8f7bbcca969b 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.h +++ b/dom/media/platforms/wmf/WMFDecoderModule.h @@ -14,9 +14,6 @@ namespace mozilla { class WMFDecoderModule : public PlatformDecoderModule { public: - WMFDecoderModule(); - virtual ~WMFDecoderModule(); - // Initializes the module, loads required dynamic libraries, etc. nsresult Startup() override; @@ -49,7 +46,9 @@ public: static bool HasH264(); private: - bool mWMFInitialized; + virtual ~WMFDecoderModule(); + + bool mWMFInitialized = false; }; } // namespace mozilla diff --git a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp index 1d490a302185..67d61ce45ec8 100644 --- a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp +++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp @@ -7,8 +7,8 @@ #include "WMFMediaDataDecoder.h" #include "VideoUtils.h" #include "WMFUtils.h" -#include "nsTArray.h" #include "mozilla/Telemetry.h" +#include "nsTArray.h" #include "mozilla/Logging.h" #include "mozilla/SyncRunnable.h" @@ -21,7 +21,6 @@ WMFMediaDataDecoder::WMFMediaDataDecoder(MFTManager* aMFTManager, TaskQueue* aTaskQueue) : mTaskQueue(aTaskQueue) , mMFTManager(aMFTManager) - , mIsShutDown(false) { } diff --git a/dom/media/platforms/wmf/WMFMediaDataDecoder.h b/dom/media/platforms/wmf/WMFMediaDataDecoder.h index c6ef8d956084..8ba22fe97aad 100644 --- a/dom/media/platforms/wmf/WMFMediaDataDecoder.h +++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.h @@ -7,12 +7,11 @@ #if !defined(WMFMediaDataDecoder_h_) #define WMFMediaDataDecoder_h_ - -#include "WMF.h" #include "MFTDecoder.h" +#include "PlatformDecoderModule.h" +#include "WMF.h" #include "mozilla/RefPtr.h" #include "nsAutoPtr.h" -#include "PlatformDecoderModule.h" namespace mozilla { @@ -22,7 +21,7 @@ namespace mozilla { class MFTManager { public: - virtual ~MFTManager() {} + virtual ~MFTManager() { } // Submit a compressed sample for decoding. // This should forward to the MFTDecoder after performing @@ -54,7 +53,10 @@ public: // Destroys all resources. virtual void Shutdown() = 0; - virtual bool IsHardwareAccelerated(nsACString& aFailureReason) const { return false; } + virtual bool IsHardwareAccelerated(nsACString& aFailureReason) const + { + return false; + } virtual TrackInfo::TrackType GetType() = 0; @@ -80,8 +82,7 @@ protected: class WMFMediaDataDecoder : public MediaDataDecoder { public: - WMFMediaDataDecoder(MFTManager* aOutputSource, - TaskQueue* aTaskQueue); + WMFMediaDataDecoder(MFTManager* aOutputSource, TaskQueue* aTaskQueue); ~WMFMediaDataDecoder(); RefPtr Init() override; @@ -131,7 +132,7 @@ private: // This is used to approximate the decoder's position in the media resource. int64_t mLastStreamOffset; - bool mIsShutDown; + bool mIsShutDown = false; MozPromiseHolder mDecodePromise; MozPromiseHolder mDrainPromise; diff --git a/dom/media/platforms/wmf/WMFUtils.cpp b/dom/media/platforms/wmf/WMFUtils.cpp index b61ac2664831..64f43ea736b3 100644 --- a/dom/media/platforms/wmf/WMFUtils.cpp +++ b/dom/media/platforms/wmf/WMFUtils.cpp @@ -5,16 +5,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WMFUtils.h" -#include +#include "VideoUtils.h" #include "mozilla/ArrayUtils.h" -#include "mozilla/RefPtr.h" +#include "mozilla/CheckedInt.h" #include "mozilla/Logging.h" +#include "mozilla/RefPtr.h" +#include "nsTArray.h" #include "nsThreadUtils.h" #include "nsWindowsHelpers.h" -#include "mozilla/CheckedInt.h" -#include "VideoUtils.h" #include -#include "nsTArray.h" +#include #ifdef WMF_MUST_DEFINE_AAC_MFT_CLSID // Some SDK versions don't define the AAC decoder CLSID. @@ -52,7 +52,8 @@ GetDefaultStride(IMFMediaType *aType, uint32_t aWidth, uint32_t* aOutStride) hr = aType->GetGUID(MF_MT_SUBTYPE, &subtype); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - hr = wmf::MFGetStrideForBitmapInfoHeader(subtype.Data1, aWidth, (LONG*)(aOutStride)); + hr = wmf::MFGetStrideForBitmapInfoHeader( + subtype.Data1, aWidth, (LONG*)(aOutStride)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); return hr; @@ -90,7 +91,8 @@ GetPictureRegion(IMFMediaType* aMediaType, nsIntRect& aOutPictureRegion) { // Determine if "pan and scan" is enabled for this media. If it is, we // only display a region of the video frame, not the entire frame. - BOOL panScan = MFGetAttributeUINT32(aMediaType, MF_MT_PAN_SCAN_ENABLED, FALSE); + BOOL panScan = + MFGetAttributeUINT32(aMediaType, MF_MT_PAN_SCAN_ENABLED, FALSE); // If pan and scan mode is enabled. Try to get the display region. HRESULT hr = E_FAIL; @@ -179,24 +181,26 @@ LoadDLLs() return S_OK; } -#define ENSURE_FUNCTION_PTR_HELPER(FunctionType, FunctionName, DLL) \ - static FunctionType FunctionName##Ptr = nullptr; \ - if (!FunctionName##Ptr) { \ - FunctionName##Ptr = (FunctionType) GetProcAddress(GetModuleHandleW(L ## #DLL), #FunctionName); \ - if (!FunctionName##Ptr) { \ - NS_WARNING("Failed to get GetProcAddress of " #FunctionName " from " #DLL); \ - return E_FAIL; \ - } \ +#define ENSURE_FUNCTION_PTR_HELPER(FunctionType, FunctionName, DLL) \ + static FunctionType FunctionName##Ptr = nullptr; \ + if (!FunctionName##Ptr) { \ + FunctionName##Ptr = \ + (FunctionType)GetProcAddress(GetModuleHandleW(L## #DLL), #FunctionName); \ + if (!FunctionName##Ptr) { \ + NS_WARNING("Failed to get GetProcAddress of " #FunctionName \ + " from " #DLL); \ + return E_FAIL; \ + } \ } -#define ENSURE_FUNCTION_PTR(FunctionName, DLL) \ - ENSURE_FUNCTION_PTR_HELPER(decltype(::FunctionName)*, FunctionName, DLL) \ +#define ENSURE_FUNCTION_PTR(FunctionName, DLL) \ + ENSURE_FUNCTION_PTR_HELPER(decltype(::FunctionName)*, FunctionName, DLL) -#define ENSURE_FUNCTION_PTR_(FunctionName, DLL) \ - ENSURE_FUNCTION_PTR_HELPER(FunctionName##Ptr_t, FunctionName, DLL) \ +#define ENSURE_FUNCTION_PTR_(FunctionName, DLL) \ + ENSURE_FUNCTION_PTR_HELPER(FunctionName##Ptr_t, FunctionName, DLL) -#define DECL_FUNCTION_PTR(FunctionName, ...) \ - typedef HRESULT (STDMETHODCALLTYPE * FunctionName##Ptr_t)(__VA_ARGS__) +#define DECL_FUNCTION_PTR(FunctionName, ...) \ + typedef HRESULT(STDMETHODCALLTYPE* FunctionName##Ptr_t)(__VA_ARGS__) HRESULT MFStartup() @@ -268,11 +272,13 @@ MFCreateAlignedMemoryBuffer(DWORD cbMaxLength, IMFMediaBuffer **ppBuffer) { ENSURE_FUNCTION_PTR(MFCreateAlignedMemoryBuffer, mfplat.dll) - return (MFCreateAlignedMemoryBufferPtr)(cbMaxLength, fAlignmentFlags, ppBuffer); + return (MFCreateAlignedMemoryBufferPtr)( + cbMaxLength, fAlignmentFlags, ppBuffer); } HRESULT -MFCreateDXGIDeviceManager(UINT *pResetToken, IMFDXGIDeviceManager **ppDXVAManager) +MFCreateDXGIDeviceManager(UINT* pResetToken, + IMFDXGIDeviceManager** ppDXVAManager) { ENSURE_FUNCTION_PTR(MFCreateDXGIDeviceManager, mfplat.dll) return (MFCreateDXGIDeviceManagerPtr)(pResetToken, ppDXVAManager); @@ -286,7 +292,8 @@ MFCreateDXGISurfaceBuffer(REFIID riid, IMFMediaBuffer **ppBuffer) { ENSURE_FUNCTION_PTR(MFCreateDXGISurfaceBuffer, mfplat.dll) - return (MFCreateDXGISurfaceBufferPtr)(riid, punkSurface, uSubresourceIndex, fButtomUpWhenLinear, ppBuffer); + return (MFCreateDXGISurfaceBufferPtr)( + riid, punkSurface, uSubresourceIndex, fButtomUpWhenLinear, ppBuffer); } } // end namespace wmf diff --git a/dom/media/platforms/wmf/WMFUtils.h b/dom/media/platforms/wmf/WMFUtils.h index ac877977489c..58dc705390fd 100644 --- a/dom/media/platforms/wmf/WMFUtils.h +++ b/dom/media/platforms/wmf/WMFUtils.h @@ -7,11 +7,11 @@ #ifndef WMFUtils_h #define WMFUtils_h -#include "WMF.h" -#include "nsString.h" -#include "nsRect.h" #include "TimeUnits.h" #include "VideoUtils.h" +#include "WMF.h" +#include "nsRect.h" +#include "nsString.h" // Various utilities shared by WMF backend files. @@ -21,7 +21,8 @@ namespace mozilla { // We use microseconds for our timestamps, whereas WMF uses // hundreds of nanoseconds. inline int64_t -UsecsToHNs(int64_t aUsecs) { +UsecsToHNs(int64_t aUsecs) +{ return aUsecs * 10; } @@ -29,18 +30,17 @@ UsecsToHNs(int64_t aUsecs) { // We use microseconds for our timestamps, whereas WMF uses // hundreds of nanoseconds. inline int64_t -HNsToUsecs(int64_t hNanoSecs) { +HNsToUsecs(int64_t hNanoSecs) +{ return hNanoSecs / 10; } -HRESULT -HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames); +HRESULT HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames); HRESULT -GetDefaultStride(IMFMediaType *aType, uint32_t aWidth, uint32_t* aOutStride); +GetDefaultStride(IMFMediaType* aType, uint32_t aWidth, uint32_t* aOutStride); -int32_t -MFOffsetToInt32(const MFOffset& aOffset); +int32_t MFOffsetToInt32(const MFOffset& aOffset); // Gets the sub-region of the video frame that should be displayed. // See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx @@ -49,16 +49,15 @@ GetPictureRegion(IMFMediaType* aMediaType, nsIntRect& aOutPictureRegion); // Returns the duration of a IMFSample in TimeUnit. // Returns media::TimeUnit::Invalid() on failure. -media::TimeUnit -GetSampleDuration(IMFSample* aSample); +media::TimeUnit GetSampleDuration(IMFSample* aSample); // Returns the presentation time of a IMFSample in TimeUnit. // Returns media::TimeUnit::Invalid() on failure. -media::TimeUnit -GetSampleTime(IMFSample* aSample); +media::TimeUnit GetSampleTime(IMFSample* aSample); inline bool -IsFlagSet(DWORD flags, DWORD pattern) { +IsFlagSet(DWORD flags, DWORD pattern) +{ return (flags & pattern) == pattern; } diff --git a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp index 227f9415b254..3727a6c58831 100644 --- a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp +++ b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp @@ -5,34 +5,35 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include -#include #include +#include + #include "WMFVideoMFTManager.h" -#include "MediaDecoderReader.h" -#include "gfxPrefs.h" -#include "WMFUtils.h" -#include "ImageContainer.h" -#include "VideoUtils.h" #include "DXVA2Manager.h" -#include "nsThreadUtils.h" +#include "GMPUtils.h" // For SplitAt. TODO: Move SplitAt to a central place. +#include "IMFYCbCrImage.h" +#include "ImageContainer.h" #include "Layers.h" +#include "MP4Decoder.h" +#include "MediaDecoderReader.h" +#include "MediaInfo.h" +#include "MediaTelemetryConstants.h" +#include "VPXDecoder.h" +#include "VideoUtils.h" +#include "WMFUtils.h" +#include "gfx2DGlue.h" +#include "gfxPrefs.h" +#include "gfxWindowsPlatform.h" #include "mozilla/AbstractThread.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/layers/LayersTypes.h" -#include "MediaInfo.h" #include "mozilla/Logging.h" -#include "nsWindowsHelpers.h" -#include "gfx2DGlue.h" -#include "gfxWindowsPlatform.h" -#include "IMFYCbCrImage.h" -#include "mozilla/WindowsVersion.h" -#include "mozilla/Telemetry.h" -#include "nsPrintfCString.h" -#include "MediaTelemetryConstants.h" -#include "GMPUtils.h" // For SplitAt. TODO: Move SplitAt to a central place. -#include "MP4Decoder.h" -#include "VPXDecoder.h" #include "mozilla/SyncRunnable.h" +#include "mozilla/Telemetry.h" +#include "mozilla/WindowsVersion.h" +#include "mozilla/layers/LayersTypes.h" +#include "nsPrintfCString.h" +#include "nsThreadUtils.h" +#include "nsWindowsHelpers.h" #define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__)) @@ -90,10 +91,6 @@ WMFVideoMFTManager::WMFVideoMFTManager( , mImageContainer(aImageContainer) , mDXVAEnabled(aDXVAEnabled) , mKnowsCompositor(aKnowsCompositor) - , mNullOutputCount(0) - , mGotValidOutputAfterNullOutput(false) - , mGotExcessiveNullOutput(false) - , mIsValid(true) // mVideoStride, mVideoWidth, mVideoHeight, mUseHwAccel are initialized in // Init(). { @@ -121,15 +118,21 @@ WMFVideoMFTManager::~WMFVideoMFTManager() // Record whether the video decoder successfully decoded, or output null // samples but did/didn't recover. - uint32_t telemetry = (mNullOutputCount == 0) ? 0 : - (mGotValidOutputAfterNullOutput && mGotExcessiveNullOutput) ? 1 : - mGotExcessiveNullOutput ? 2 : - mGotValidOutputAfterNullOutput ? 3 : - 4; + uint32_t telemetry = + (mNullOutputCount == 0) + ? 0 + : (mGotValidOutputAfterNullOutput && mGotExcessiveNullOutput) + ? 1 + : mGotExcessiveNullOutput + ? 2 + : mGotValidOutputAfterNullOutput ? 3 : 4; nsCOMPtr task = NS_NewRunnableFunction([=]() -> void { - LOG(nsPrintfCString("Reporting telemetry VIDEO_MFT_OUTPUT_NULL_SAMPLES=%d", telemetry).get()); - Telemetry::Accumulate(Telemetry::ID::VIDEO_MFT_OUTPUT_NULL_SAMPLES, telemetry); + LOG(nsPrintfCString("Reporting telemetry VIDEO_MFT_OUTPUT_NULL_SAMPLES=%d", + telemetry) + .get()); + Telemetry::Accumulate(Telemetry::ID::VIDEO_MFT_OUTPUT_NULL_SAMPLES, + telemetry); }); // Non-DocGroup version of AbstractThread::MainThread is fine for Telemetry. AbstractThread::MainThread()->Dispatch(task.forget()); @@ -171,9 +174,10 @@ StaticAutoPtr sD3D9BlacklistingCache; // If a blacklisted DLL is found, return its information, otherwise "". static const nsCString& -FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingCache, - const nsCString& aBlacklist, - const char* aDLLBlacklistPrefName) +FindDXVABlacklistedDLL( + StaticAutoPtr& aDLLBlacklistingCache, + const nsCString& aBlacklist, + const char* aDLLBlacklistPrefName) { NS_ASSERTION(NS_IsMainThread(), "Must be on main thread."); @@ -207,7 +211,8 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC EnumProcessModules(hProcess, nullptr, 0, &modulesSize); modulesNum = modulesSize / sizeof(HMODULE); hMods = mozilla::MakeUnique(modulesNum); - EnumProcessModules(hProcess, hMods.get(), modulesNum * sizeof(HMODULE), &modulesSize); + EnumProcessModules( + hProcess, hMods.get(), modulesNum * sizeof(HMODULE), &modulesSize); } // media.wmf.disable-d3d*-for-dlls format: (whitespace is trimmed) @@ -230,12 +235,14 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC WCHAR dllPath[MAX_PATH + 1]; if (i < modulesNum) { - if (!GetModuleFileNameEx(hProcess, hMods[i], dllPath, sizeof(dllPath) / sizeof(WCHAR))) { + if (!GetModuleFileNameEx( + hProcess, hMods[i], dllPath, sizeof(dllPath) / sizeof(WCHAR))) { continue; } nsCOMPtr file; - if (NS_WARN_IF(NS_FAILED(NS_NewLocalFile(nsDependentString(dllPath), false, getter_AddRefs(file))))) { + if (NS_WARN_IF(NS_FAILED(NS_NewLocalFile( + nsDependentString(dllPath), false, getter_AddRefs(file))))) { continue; } @@ -277,8 +284,10 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC nsTArray numberStrings; SplitAt(".", version, numberStrings); if (numberStrings.Length() != 4) { - NS_WARNING(nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format", - aDLLBlacklistPrefName).get()); + NS_WARNING( + nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format", + aDLLBlacklistPrefName) + .get()); continue; } DWORD numbers[4]; @@ -296,8 +305,10 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC } if (NS_FAILED(errorCode)) { - NS_WARNING(nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format", - aDLLBlacklistPrefName).get()); + NS_WARNING( + nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format", + aDLLBlacklistPrefName) + .get()); continue; } @@ -307,7 +318,11 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC aDLLBlacklistingCache->mBlacklistedDLL.SetLength(0); aDLLBlacklistingCache->mBlacklistedDLL.AppendPrintf( "%s (%lu.%lu.%lu.%lu)", - nameAndVersions[0].get(), numbers[0], numbers[1], numbers[2], numbers[3]); + nameAndVersions[0].get(), + numbers[0], + numbers[1], + numbers[2], + numbers[3]); return aDLLBlacklistingCache->mBlacklistedDLL; } } @@ -320,20 +335,23 @@ FindDXVABlacklistedDLL(StaticAutoPtr& aDLLBlacklistingC } static const nsCString& -FindD3D11BlacklistedDLL() { +FindD3D11BlacklistedDLL() +{ return FindDXVABlacklistedDLL(sD3D11BlacklistingCache, gfx::gfxVars::PDMWMFDisableD3D11Dlls(), "media.wmf.disable-d3d11-for-dlls"); } static const nsCString& -FindD3D9BlacklistedDLL() { +FindD3D9BlacklistedDLL() +{ return FindDXVABlacklistedDLL(sD3D9BlacklistingCache, gfx::gfxVars::PDMWMFDisableD3D9Dlls(), "media.wmf.disable-d3d9-for-dlls"); } -class CreateDXVAManagerEvent : public Runnable { +class CreateDXVAManagerEvent : public Runnable +{ public: CreateDXVAManagerEvent(LayersBackend aBackend, layers::KnowsCompositor* aKnowsCompositor, @@ -341,7 +359,8 @@ public: : mBackend(aBackend) , mKnowsCompositor(aKnowsCompositor) , mFailureReason(aFailureReason) - {} + { + } NS_IMETHOD Run() override { NS_ASSERTION(NS_IsMainThread(), "Must be on main thread."); @@ -354,7 +373,8 @@ public: failureReason->AppendPrintf("D3D11 blacklisted with DLL %s", blacklistedDLL.get()); } else { - mDXVA2Manager = DXVA2Manager::CreateD3D11DXVA(mKnowsCompositor, *failureReason); + mDXVA2Manager = + DXVA2Manager::CreateD3D11DXVA(mKnowsCompositor, *failureReason); if (mDXVA2Manager) { return NS_OK; } @@ -370,7 +390,8 @@ public: mFailureReason.AppendPrintf("D3D9 blacklisted with DLL %s", blacklistedDLL.get()); } else { - mDXVA2Manager = DXVA2Manager::CreateD3D9DXVA(mKnowsCompositor, *failureReason); + mDXVA2Manager = + DXVA2Manager::CreateD3D9DXVA(mKnowsCompositor, *failureReason); // Make sure we include the messages from both attempts (if applicable). mFailureReason.Append(secondFailureReason); } @@ -389,13 +410,14 @@ WMFVideoMFTManager::InitializeDXVA(bool aForceD3D9) // readback of decoded video frames from GPU to CPU memory grinds painting // to a halt, and makes playback performance *worse*. if (!mDXVAEnabled) { - mDXVAFailureReason.AssignLiteral("Hardware video decoding disabled or blacklisted"); + mDXVAFailureReason.AssignLiteral( + "Hardware video decoding disabled or blacklisted"); return false; } MOZ_ASSERT(!mDXVA2Manager); LayersBackend backend = GetCompositorBackendType(mKnowsCompositor); - if (backend != LayersBackend::LAYERS_D3D9 && - backend != LayersBackend::LAYERS_D3D11) { + if (backend != LayersBackend::LAYERS_D3D9 + && backend != LayersBackend::LAYERS_D3D11) { mDXVAFailureReason.AssignLiteral("Unsupported layers backend"); return false; } @@ -428,9 +450,9 @@ WMFVideoMFTManager::ValidateVideoInfo() // we just reject streams which are less than the documented minimum. // https://msdn.microsoft.com/en-us/library/windows/desktop/dd797815(v=vs.85).aspx static const int32_t MIN_H264_FRAME_DIMENSION = 48; - if (mStreamType == H264 && - (mVideoInfo.mImage.width < MIN_H264_FRAME_DIMENSION || - mVideoInfo.mImage.height < MIN_H264_FRAME_DIMENSION)) { + if (mStreamType == H264 + && (mVideoInfo.mImage.width < MIN_H264_FRAME_DIMENSION + || mVideoInfo.mImage.height < MIN_H264_FRAME_DIMENSION)) { LogToBrowserConsole(NS_LITERAL_STRING( "Can't decode H.264 stream with width or height less than 48 pixels.")); mIsValid = false; @@ -500,11 +522,13 @@ WMFVideoMFTManager::InitInternal(bool aForceD3D9) mUseHwAccel = true; } else { DeleteOnMainThread(mDXVA2Manager); - mDXVAFailureReason = nsPrintfCString("MFT_MESSAGE_SET_D3D_MANAGER failed with code %X", hr); + mDXVAFailureReason = nsPrintfCString( + "MFT_MESSAGE_SET_D3D_MANAGER failed with code %X", hr); } } else { - mDXVAFailureReason.AssignLiteral("Decoder returned false for MF_SA_D3D_AWARE"); + mDXVAFailureReason.AssignLiteral( + "Decoder returned false for MF_SA_D3D_AWARE"); } } @@ -521,7 +545,8 @@ WMFVideoMFTManager::InitInternal(bool aForceD3D9) hr = SetDecoderMediaTypes(); NS_ENSURE_TRUE(SUCCEEDED(hr), false); - LOG("Video Decoder initialized, Using DXVA: %s", (mUseHwAccel ? "Yes" : "No")); + LOG("Video Decoder initialized, Using DXVA: %s", + (mUseHwAccel ? "Yes" : "No")); return true; } @@ -540,15 +565,20 @@ WMFVideoMFTManager::SetDecoderMediaTypes() hr = inputType->SetGUID(MF_MT_SUBTYPE, GetMediaSubtypeGUID()); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - hr = inputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_MixedInterlaceOrProgressive); + hr = inputType->SetUINT32(MF_MT_INTERLACE_MODE, + MFVideoInterlace_MixedInterlaceOrProgressive); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); // MSFT MFT needs this frame size set for VP9? if (mStreamType == VP9 || mStreamType == VP8) { - hr = inputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); + hr = + inputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - hr = MFSetAttributeSize(inputType, MF_MT_FRAME_SIZE, mVideoInfo.ImageRect().width, mVideoInfo.ImageRect().height); + hr = MFSetAttributeSize(inputType, + MF_MT_FRAME_SIZE, + mVideoInfo.ImageRect().width, + mVideoInfo.ImageRect().height); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); } @@ -594,14 +624,18 @@ WMFVideoMFTManager::Input(MediaRawData* aSample) class SupportsConfigEvent : public Runnable { public: - SupportsConfigEvent(DXVA2Manager* aDXVA2Manager, IMFMediaType* aMediaType, float aFramerate) + SupportsConfigEvent(DXVA2Manager* aDXVA2Manager, + IMFMediaType* aMediaType, + float aFramerate) : mDXVA2Manager(aDXVA2Manager) , mMediaType(aMediaType) , mFramerate(aFramerate) , mSupportsConfig(false) - {} + { + } - NS_IMETHOD Run() { + NS_IMETHOD Run() + { MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread."); mSupportsConfig = mDXVA2Manager->SupportsConfig(mMediaType, mFramerate); return NS_OK; @@ -743,7 +777,8 @@ WMFVideoMFTManager::CreateBasicVideoFrame(IMFSample* aSample, BYTE* data = nullptr; LONG stride = 0; RefPtr twoDBuffer; - hr = buffer->QueryInterface(static_cast(getter_AddRefs(twoDBuffer))); + hr = buffer->QueryInterface( + static_cast(getter_AddRefs(twoDBuffer))); if (SUCCEEDED(hr)) { hr = twoDBuffer->Lock2D(&data, &stride); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); @@ -941,7 +976,8 @@ WMFVideoMFTManager::Output(int64_t aStreamOffset, // not work in this situation. ++mNullOutputCount; if (mNullOutputCount > 250) { - LOG("Excessive Video MFTDecoder returning success but no output; giving up"); + LOG("Excessive Video MFTDecoder returning success but no output; " + "giving up"); mGotExcessiveNullOutput = true; return E_FAIL; } diff --git a/dom/media/platforms/wmf/WMFVideoMFTManager.h b/dom/media/platforms/wmf/WMFVideoMFTManager.h index 99331982c8b2..e2ee46ffeb1b 100644 --- a/dom/media/platforms/wmf/WMFVideoMFTManager.h +++ b/dom/media/platforms/wmf/WMFVideoMFTManager.h @@ -7,18 +7,19 @@ #if !defined(WMFVideoMFTManager_h_) #define WMFVideoMFTManager_h_ -#include "WMF.h" #include "MFTDecoder.h" -#include "nsAutoPtr.h" -#include "nsRect.h" +#include "WMF.h" #include "WMFMediaDataDecoder.h" #include "mozilla/RefPtr.h" +#include "nsAutoPtr.h" +#include "nsRect.h" namespace mozilla { class DXVA2Manager; -class WMFVideoMFTManager : public MFTManager { +class WMFVideoMFTManager : public MFTManager +{ public: WMFVideoMFTManager(const VideoInfo& aConfig, layers::KnowsCompositor* aKnowsCompositor, @@ -36,9 +37,7 @@ public: bool IsHardwareAccelerated(nsACString& aFailureReason) const override; - TrackInfo::TrackType GetType() override { - return TrackInfo::kVideoTrack; - } + TrackInfo::TrackType GetType() override { return TrackInfo::kVideoTrack; } const char* GetDescriptionName() const override { @@ -61,7 +60,6 @@ public: } private: - bool ValidateVideoInfo(); bool InitializeDXVA(bool aForceD3D9); @@ -102,7 +100,8 @@ private: nsCString mDXVAFailureReason; - enum StreamType { + enum StreamType + { Unknown, H264, VP8, @@ -114,10 +113,10 @@ private: const GUID& GetMFTGUID(); const GUID& GetMediaSubtypeGUID(); - uint32_t mNullOutputCount; - bool mGotValidOutputAfterNullOutput; - bool mGotExcessiveNullOutput; - bool mIsValid; + uint32_t mNullOutputCount = 0; + bool mGotValidOutputAfterNullOutput = false; + bool mGotExcessiveNullOutput = false; + bool mIsValid = true; }; } // namespace mozilla