Files
palemoon27/dom/media/platforms/wmf/WMFDecoderModule.cpp
T
roytam1 c1485b21e1 import changes from `dev' branch of rmottola/Arctic-Fox:
- bug 1179662 rename AudioNode::Stream() to GetStream() as it may return null r=padenot (d2d7e5f90)
-  bug 1197043 remove unnecessary aSampleRate parameter for AudioNodeStream creation r=padenot (3733ceb56)
- bug 1197043 rename Add/RemoveStream to Add/RemoveStreamGraphThread r=padenot (f648b8251)
- bug 1197043 introduce MediaStreamGraph::AddStream() r=padenot (ac021d4b2)
- bug 1197043 move AudioNodeStream creation to stream class r=padenot (a90a05910)
- bug 1197043 use flags to distinguish between external streams and events r=padenot (024dd96f1)
- Bug 1176300 - Move libsoundtouch to lgpllibs; r=glandium (99a546adf)
- Bug 1176300 - Add lgpllibs library to build system; r=glandium (bb4d07670)
- Bug 1176300 - Update libsoundtouch to patched r222; r=padenot (hg rev 8c32c900cb48)
- Bug 1176300 - Add soundtouch factory functions for DLL memory handling on windows; r=padenot (hg rev 84a1ffbc2db8)
- Bug 901633 - Part 1 - Implement a generic audio packetizer. r=jesup (a38c2d70b)
- Bug 901633 - Part 2 - Make AudioChannelFormat and AudioSegment more generic. r=roc (556b7349f)
- Bug 901633 - Part 3 - Fix TrackEncoder to use the new AudioChunk methods. r=jesup (56e018f83)
- Bug 901633 - Part 4 - Update AudioNodeStream to use new chunk methods. r=roc (9df19b894)
- Bug 901633 - Part 6 - Update DelayBuffer to use the new AudioChunk methods. r=karlt (6d5684334)
- Bug 901633 - Part 7 - Update AudioNodeExternalInputStream to use the new AudioChunk methods. r=karlt (caa3afa01)
- Bug 1155089: Fix hazard analysis bustage on a CLOSED TREE. r=bustage (8d23ccf39)
- Bug 1166183 - Back out the direct listener removal landed by mistake in bug 1141781. r=jesup (745d683d4)
- Bug 1166183 - Reset PipelineListener's flag after ReplaceTrack(). r=bwc (2fb38ca01)
- Bug 1170059 - Fix -Wunreachable-code clang warnings in webrtc/signaling. r=jesup (0d99b30ca)
- Bug 1139144 - Remove unused empty() definition from databuffer.h. r=mt (2fef64e3c)
- Bug 822129: don't alloc/free on every packet send in MediaPipeline r=bwc (ddfdc9455)
- Bug 1172397 - Check for Conduit/Type mismatch on every frame. r=jesup, r=bwc (a399a3336)
- Bug 1137169 - Uninitialised value uses related to mozilla::dom::WebAdioUtils::SpeexResamplerProcess. r=rjesup. (ce14ac278)
- Bug 901633 - Part 5 - Make MediaPipeline downmix and properly convert audio for webrtc.org code. r=jesup (89138b5d5)
- Bug 901633 - Part 8 - Use our new generic packetizer in the MediaPipeline so that we can packetize stereo easily. r=jesup (fb5d075b6)
- Bug 901633 - Part 9 - Make the necessary changes to VoEExternalMediaImpl::ExternalRecordingInsertData so that it the number of channels is forwarded down the webrtc.org code. r=jesup (d5d7dd4ca)
- Bug 901633 - Part 10 - Change the receiving side of the MediaPipeline so that it can detect and handle stereo. r=jesup (a73c1520f)
- Bug 901633 - Part 11 - Add an API in webrtc.org's output mixer to get the output channel count. r=jesup (4b396b85e)
- Bug 901633 - Part 12 - Add a function to deinterleave and convert an audio buffer. r=jesup (47ce3c7a5)
- Bug 901633 - Part 13 - Teach the resampler at the input of the MSG to dynamically change its channel count if needed. r=jesup (120c8d037)
- Bug 901633 - Part 14 - Add testing for our audio processing functions. r=jesup (5aa95b82e)
- Bug 901633 - Part 15 - Remove an allocation on the sending side, out of the packetizer. r=jesup (df8aed252)
- Bug 901633 - Part 16 - Remove another allocation in the sending side r=jesup (1e2fc8bca)
- Bug 1196408 - Make sure we only report a corrupt/slow video frame once. r=cpearce (5bae2f17a)
- bug 1162364 report telemetry on WMFMediaDataDecoder errors r=cpearce,f=vladan,bsmedberg (e217618ef)
- Bug 1193864 - Fixed dom/media/platforms/wmf/ compilation on mingw. r=cpearce (4e8c0ecd7)
- Bug 1141139: Enable low latency decoding on Windows. r=cpearce (9e0a36e27)
- Bug 1193547 - Fallback to software decoding explicitly if the GPU doesn't support decoding the current resolution in hardware. r=cpearce,jya (7fbab8784)
- Bug 1196417 - Make video software fallback only affect the current video instead of the entire browser. r=cpearce (3e83f0677)
2021-10-12 10:01:23 +08:00

194 lines
5.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/Preferences.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Services.h"
#include "WMFMediaDataDecoder.h"
#include "nsIWindowsRegKey.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsIGfxInfo.h"
#include "GfxDriverInfo.h"
#include "gfxWindowsPlatform.h"
#include "nsServiceManagerUtils.h" // for do_GetService
#include "MediaInfo.h"
#include "prsystem.h"
namespace mozilla {
static bool sDXVAEnabled = false;
static int sNumDecoderThreads = -1;
static bool sIsIntelDecoderEnabled = false;
WMFDecoderModule::WMFDecoderModule()
: mWMFInitialized(false)
{
}
WMFDecoderModule::~WMFDecoderModule()
{
if (mWMFInitialized) {
DebugOnly<HRESULT> hr = wmf::MFShutdown();
NS_ASSERTION(SUCCEEDED(hr), "MFShutdown failed");
}
}
static void
SetNumOfDecoderThreads()
{
MOZ_ASSERT(NS_IsMainThread(), "Preferences can only be read on main thread");
int32_t numCores = PR_GetNumberOfProcessors();
// If we have more than 4 cores, let the decoder decide how many threads.
// On an 8 core machine, WMF chooses 4 decoder threads
const int WMF_DECODER_DEFAULT = -1;
int32_t prefThreadCount = Preferences::GetInt("media.wmf.decoder.thread-count", -1);
if (prefThreadCount != WMF_DECODER_DEFAULT) {
sNumDecoderThreads = std::max(prefThreadCount, 1);
} else if (numCores > 4) {
sNumDecoderThreads = WMF_DECODER_DEFAULT;
} else {
sNumDecoderThreads = std::max(numCores - 1, 1);
}
}
/* static */
void
WMFDecoderModule::Init()
{
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
sDXVAEnabled = gfxPlatform::GetPlatform()->CanUseHardwareVideoDecoding();
sIsIntelDecoderEnabled = Preferences::GetBool("media.webm.intel_decoder.enabled", false);
SetNumOfDecoderThreads();
}
/* static */
int
WMFDecoderModule::GetNumDecoderThreads()
{
return sNumDecoderThreads;
}
nsresult
WMFDecoderModule::Startup()
{
mWMFInitialized = SUCCEEDED(wmf::MFStartup());
return mWMFInitialized ? NS_OK : NS_ERROR_FAILURE;
}
already_AddRefed<MediaDataDecoder>
WMFDecoderModule::CreateVideoDecoder(const VideoInfo& aConfig,
layers::LayersBackend aLayersBackend,
layers::ImageContainer* aImageContainer,
FlushableTaskQueue* aVideoTaskQueue,
MediaDataDecoderCallback* aCallback)
{
nsAutoPtr<WMFVideoMFTManager> manager(
new WMFVideoMFTManager(aConfig,
aLayersBackend,
aImageContainer,
sDXVAEnabled));
nsRefPtr<MFTDecoder> mft = manager->Init();
if (!mft) {
return nullptr;
}
nsRefPtr<MediaDataDecoder> decoder =
new WMFMediaDataDecoder(manager.forget(), mft, aVideoTaskQueue, aCallback);
return decoder.forget();
}
already_AddRefed<MediaDataDecoder>
WMFDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig,
FlushableTaskQueue* aAudioTaskQueue,
MediaDataDecoderCallback* aCallback)
{
nsAutoPtr<WMFAudioMFTManager> manager(new WMFAudioMFTManager(aConfig));
nsRefPtr<MFTDecoder> mft = manager->Init();
if (!mft) {
return nullptr;
}
nsRefPtr<MediaDataDecoder> decoder =
new WMFMediaDataDecoder(manager.forget(), mft, aAudioTaskQueue, aCallback);
return decoder.forget();
}
bool
WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType)
{
return aMimeType.EqualsLiteral("video/mp4") ||
aMimeType.EqualsLiteral("video/avc") ||
aMimeType.EqualsLiteral("audio/mp4a-latm") ||
aMimeType.EqualsLiteral("audio/mpeg") ||
(sIsIntelDecoderEnabled &&
(aMimeType.EqualsLiteral("video/webm; codecs=vp8") ||
aMimeType.EqualsLiteral("video/webm; codecs=vp9")));
}
PlatformDecoderModule::ConversionRequired
WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
if (aConfig.IsVideo() &&
(aConfig.mMimeType.EqualsLiteral("video/avc") ||
aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
return kNeedAnnexB;
} else {
return kNeedNone;
}
}
static bool
ClassesRootRegKeyExists(const nsAString& aRegKeyPath)
{
nsresult rv;
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
aRegKeyPath,
nsIWindowsRegKey::ACCESS_READ);
if (NS_FAILED(rv)) {
return false;
}
regKey->Close();
return true;
}
/* static */ bool
WMFDecoderModule::HasH264()
{
// CLSID_CMSH264DecoderMFT
return ClassesRootRegKeyExists(
NS_LITERAL_STRING("CLSID\\{32D186A7-218F-4C75-8876-DD77273A8999}"));
}
/* static */ bool
WMFDecoderModule::HasAAC()
{
// CLSID_CMSAACDecMFT
return ClassesRootRegKeyExists(
NS_LITERAL_STRING("CLSID\\{62CE7E72-4C71-4D20-B15D-452831A87D9D}"));
}
} // namespace mozilla