Bug 1295921 - P9: NullDecoderModule returns null VideoData. r?jwwang
Return a VideoData with dimension of zero size and no image data.
MozReview-Commit-ID: 59J4leiqSvP
--- a/dom/media/platforms/PDMFactory.cpp
+++ b/dom/media/platforms/PDMFactory.cpp
@@ -53,16 +53,17 @@
#include "mp4_demuxer/H264.h"
#include <functional>
namespace mozilla {
extern already_AddRefed<PlatformDecoderModule> CreateAgnosticDecoderModule();
extern already_AddRefed<PlatformDecoderModule> CreateBlankDecoderModule();
+extern already_AddRefed<PlatformDecoderModule> CreateNullDecoderModule();
class PDMFactoryImpl final {
public:
PDMFactoryImpl()
{
#ifdef XP_WIN
WMFDecoderModule::Init();
#endif
@@ -159,17 +160,17 @@ public:
private:
nsTArray<std::function<CheckResult()>> mCheckerList;
}; // SupportChecker
PDMFactory::PDMFactory()
{
EnsureInit();
CreatePDMs();
- CreateBlankPDM();
+ CreateNullPDM();
}
PDMFactory::~PDMFactory()
{
}
void
PDMFactory::EnsureInit() const
@@ -200,18 +201,18 @@ PDMFactory::EnsureInit() const
});
SyncRunnable::DispatchToThread(mainThread, runnable);
}
already_AddRefed<MediaDataDecoder>
PDMFactory::CreateDecoder(const CreateDecoderParams& aParams)
{
if (aParams.mUseBlankDecoder) {
- MOZ_ASSERT(mBlankPDM);
- return CreateDecoderWithPDM(mBlankPDM, aParams);
+ MOZ_ASSERT(mNullPDM);
+ return CreateDecoderWithPDM(mNullPDM, aParams);
}
const TrackInfo& config = aParams.mConfig;
bool isEncrypted = mEMEPDM && config.mCrypto.mValid;
if (isEncrypted) {
return CreateDecoderWithPDM(mEMEPDM, aParams);
}
@@ -419,20 +420,20 @@ PDMFactory::CreatePDMs()
m = new GMPDecoderModule();
mGMPPDMFailedToStartup = !StartupPDM(m);
} else {
mGMPPDMFailedToStartup = false;
}
}
void
-PDMFactory::CreateBlankPDM()
+PDMFactory::CreateNullPDM()
{
- mBlankPDM = CreateBlankDecoderModule();
- MOZ_ASSERT(mBlankPDM && NS_SUCCEEDED(mBlankPDM->Startup()));
+ mNullPDM = CreateNullDecoderModule();
+ MOZ_ASSERT(mNullPDM && NS_SUCCEEDED(mNullPDM->Startup()));
}
bool
PDMFactory::StartupPDM(PlatformDecoderModule* aPDM)
{
if (aPDM && NS_SUCCEEDED(aPDM->Startup())) {
mCurrentPDMs.AppendElement(aPDM);
return true;
--- a/dom/media/platforms/PDMFactory.h
+++ b/dom/media/platforms/PDMFactory.h
@@ -47,31 +47,31 @@ public:
static constexpr int kYUV400 = 0;
static constexpr int kYUV420 = 1;
static constexpr int kYUV422 = 2;
static constexpr int kYUV444 = 3;
private:
virtual ~PDMFactory();
void CreatePDMs();
- void CreateBlankPDM();
+ void CreateNullPDM();
// Startup the provided PDM and add it to our list if successful.
bool StartupPDM(PlatformDecoderModule* aPDM);
// Returns the first PDM in our list supporting the mimetype.
already_AddRefed<PlatformDecoderModule>
GetDecoder(const TrackInfo& aTrackInfo,
DecoderDoctorDiagnostics* aDiagnostics) const;
already_AddRefed<MediaDataDecoder>
CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
const CreateDecoderParams& aParams);
nsTArray<RefPtr<PlatformDecoderModule>> mCurrentPDMs;
RefPtr<PlatformDecoderModule> mEMEPDM;
- RefPtr<PlatformDecoderModule> mBlankPDM;
+ RefPtr<PlatformDecoderModule> mNullPDM;
bool mWMFFailedToLoad = false;
bool mFFmpegFailedToLoad = false;
bool mGMPPDMFailedToStartup = false;
void EnsureInit() const;
template<class T> friend class StaticAutoPtr;
static StaticAutoPtr<PDMFactoryImpl> sInstance;
new file mode 100644
--- /dev/null
+++ b/dom/media/platforms/agnostic/NullDecoderModule.cpp
@@ -0,0 +1,73 @@
+/* -*- 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 "DummyMediaDataDecoder.h"
+
+namespace mozilla {
+
+class NullVideoDataCreator : public DummyDataCreator {
+public:
+ NullVideoDataCreator()
+ { }
+
+ already_AddRefed<MediaData> Create(MediaRawData* aSample) override
+ {
+ // Create a dummy VideoData with no image. This gives us something to
+ // send to media streams if necessary.
+ RefPtr<VideoData> v(new VideoData(aSample->mOffset,
+ aSample->mTime,
+ aSample->mDuration,
+ aSample->mKeyframe,
+ aSample->mTimecode,
+ gfx::IntSize(),
+ 0));
+ return v.forget();
+ }
+};
+
+class NullDecoderModule : public PlatformDecoderModule {
+public:
+
+ // Decode thread.
+ already_AddRefed<MediaDataDecoder>
+ CreateVideoDecoder(const CreateDecoderParams& aParams) override {
+ auto creator = UniquePtr<DummyDataCreator>{
+ MakeUnique<NullVideoDataCreator>()
+ };
+ RefPtr<MediaDataDecoder> decoder =
+ new DummyMediaDataDecoder(Move(creator), "null media data decoder", aParams);
+ return decoder.forget();
+ }
+
+ // Decode thread.
+ already_AddRefed<MediaDataDecoder>
+ CreateAudioDecoder(const CreateDecoderParams& aParams) override {
+ MOZ_ASSERT(false, "Audio decoders are unsupported.");
+ return nullptr;
+ }
+
+ bool
+ SupportsMimeType(const nsACString& aMimeType,
+ DecoderDoctorDiagnostics* aDiagnostics) const override
+ {
+ return true;
+ }
+
+ ConversionRequired
+ DecoderNeedsConversion(const TrackInfo& aConfig) const override
+ {
+ return ConversionRequired::kNeedNone;
+ }
+
+};
+
+already_AddRefed<PlatformDecoderModule> CreateNullDecoderModule()
+{
+ RefPtr<PlatformDecoderModule> pdm = new NullDecoderModule();
+ return pdm.forget();
+}
+
+} // namespace mozilla
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -17,16 +17,17 @@ EXPORTS += [
'wrappers/FuzzingWrapper.h',
'wrappers/H264Converter.h'
]
UNIFIED_SOURCES += [
'agnostic/AgnosticDecoderModule.cpp',
'agnostic/BlankDecoderModule.cpp',
'agnostic/DummyMediaDataDecoder.cpp',
+ 'agnostic/NullDecoderModule.cpp',
'agnostic/OpusDecoder.cpp',
'agnostic/TheoraDecoder.cpp',
'agnostic/VorbisDecoder.cpp',
'agnostic/VPXDecoder.cpp',
'agnostic/WAVDecoder.cpp',
'PDMFactory.cpp',
'wrappers/FuzzingWrapper.cpp',
'wrappers/H264Converter.cpp'