Add Hardware Accelerated VP9 Support

This is Windows 10+ only for now due to a vp9 decoder mft being needed
Fix for older windows is being worked on.
This commit is contained in:
EAZYBLACK 2026-09-13 10:42:24 +03:00
commit 6ad01d940b
9 changed files with 74 additions and 9 deletions

View file

@ -30,6 +30,9 @@
#ifdef MOZ_FMP4
#include "MP4Decoder.h"
#endif
#include "WMFDecoderModule.h"
#include "MediaPrefs.h"
#include "mozilla/gfx/gfxVars.h"
#include "CubebUtils.h"
#include "nsIScrollableFrame.h"
@ -2360,6 +2363,39 @@ nsDOMWindowUtils::GetSupportsHardwareH264Decoding(JS::MutableHandle<JS::Value> a
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetSupportsHardwareVP9Decoding(JS::MutableHandle<JS::Value> aPromise)
{
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsCOMPtr<nsIGlobalObject> parentObject =
do_QueryInterface(window->GetCurrentInnerWindow());
NS_ENSURE_STATE(parentObject);
ErrorResult rv;
RefPtr<Promise> promise = Promise::Create(parentObject, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
#if defined(XP_WIN) && defined(MOZ_WMF)
if (!MediaPrefs::PDMWMFVP9DecoderEnabled()) {
promise->MaybeResolve(NS_LITERAL_STRING("No; media.wmf.vp9.enabled is false"));
} else if (!gfx::gfxVars::CanUseHardwareVideoDecoding()) {
promise->MaybeResolve(NS_LITERAL_STRING("No; hardware video decoding disabled"));
} else if (WMFDecoderModule::HasVP9()) {
promise->MaybeResolve(NS_LITERAL_STRING("Yes"));
} else {
promise->MaybeResolve(NS_LITERAL_STRING("No; MFT unavailable"));
}
#else
promise->MaybeResolve(NS_LITERAL_STRING("No; not supported on this platform"));
#endif
aPromise.setObject(*promise->PromiseObj());
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetCurrentAudioBackend(nsAString& aBackend)
{

View file

@ -1419,6 +1419,13 @@ interface nsIDOMWindowUtils : nsISupports {
* in hardware.
*/
readonly attribute jsval supportsHardwareH264Decoding;
/**
* Returns a Promise that will be resolved with a string once the capabilities
* of the vp9 decoder have been determined.
* Success does not mean that all vp9 video decoding will be done
* in hardware.
*/
readonly attribute jsval supportsHardwareVP9Decoding;
/**
* Returns the current audio backend as a free-form string.

View file

@ -185,6 +185,10 @@ static const GUID DXVA2_Intel_ModeH264_E = {
0x604F8E68, 0x4951, 0x4c54, { 0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6 }
};
static const GUID DXVA2_ModeVP9_VLD_Profile0 = {
0x463707f8, 0xa1d0, 0x4585, { 0x87, 0x6d, 0x83, 0xaa, 0x6d, 0x60, 0xb8, 0x9e }
};
// This tests if a DXVA video decoder can be created for the given media type/resolution.
// It uses the same decoder device (DXVA2_ModeH264_E - DXVA2_ModeH264_VLD_NoFGT) as the H264
// decoder MFT provided by windows (CLSID_CMSH264DecoderMFT) uses, so we can use it to determine
@ -388,7 +392,8 @@ D3D9DXVA2Manager::Init(layers::KnowsCompositor* aKnowsCompositor,
decoderDevices[i] == DXVA2_Intel_ModeH264_E) {
mDecoderGUID = decoderDevices[i];
found = true;
break;
} else if (decoderDevices[i] == DXVA2_ModeVP9_VLD_Profile0) {
found = true;
}
}
CoTaskMemFree(decoderDevices);
@ -690,10 +695,13 @@ 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)) {
mDecoderGUID = id;
found = true;
break;
if (SUCCEEDED(hr)) {
if (id == DXVA2_ModeH264_E || id == DXVA2_Intel_ModeH264_E) {
mDecoderGUID = id;
found = true;
} else if (id == DXVA2_ModeVP9_VLD_Profile0) {
found = true;
}
}
}
if (!found) {

View file

@ -191,6 +191,12 @@ WMFDecoderModule::HasH264()
return CanCreateWMFDecoder<CLSID_CMSH264DecoderMFT>();
}
/* static */ bool
WMFDecoderModule::HasVP9()
{
return CanCreateWMFDecoder<CLSID_WebmMfVpxDec>();
}
/* static */ bool
WMFDecoderModule::HasAAC()
{

View file

@ -43,6 +43,7 @@ public:
// require a "Media Feature Pack" to be installed.
static bool HasAAC();
static bool HasH264();
static bool HasVP9();
private:
bool mWMFInitialized;