Bug 1295921 - P9: NullDecoderModule returns null VideoData. r?jwwang draft
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 21 Sep 2016 15:36:48 +1000
changeset 495124 9fa75d6adb8540525283361375ea2984683f4ec0
parent 495123 6904d4502648fb1e393d2a7dd8bcfb4b35df0be0
child 495125 61fe2f0c76511e2867c02f144d5f342baf874e60
push id48245
push userbmo:kaku@mozilla.com
push dateWed, 08 Mar 2017 09:46:17 +0000
reviewersjwwang
bugs1295921
milestone53.0a1
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
dom/media/platforms/PDMFactory.cpp
dom/media/platforms/PDMFactory.h
dom/media/platforms/agnostic/NullDecoderModule.cpp
dom/media/platforms/moz.build
--- 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'