Bug 1281632 - P2: Reduce GMPAudioDecoder/GMPVideoDecoder ctor count. r=gerald
authorDan Glastonbury <dglastonbury@mozilla.com>
Tue, 28 Jun 2016 17:56:55 +1200
changeset 302827 6c41aac9acf85bdd94552b9b0322214b88f72f5f
parent 302826 cf174e130188f36c8e0dd333ebb378df64b06fe9
child 302828 df7e221563819faabe7b6f3177443ac38d46ab23
push id30376
push usercbook@mozilla.com
push dateTue, 28 Jun 2016 14:09:36 +0000
treeherdermozilla-central@e45890951ce7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1281632
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1281632 - P2: Reduce GMPAudioDecoder/GMPVideoDecoder ctor count. r=gerald This means we expose fewer constructors, and the definition is in the .cpp file so changing it won't cause lots of things to recompile. MozReview-Commit-ID: DY7UCYfOb25
dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPAudioDecoder.h
dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPVideoDecoder.h
--- a/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.cpp
@@ -121,16 +121,31 @@ AudioCallbackAdapter::Error(GMPErr aErr)
 
 void
 AudioCallbackAdapter::Terminated()
 {
   NS_WARNING("AAC GMP decoder terminated.");
   mCallback->Error(MediaDataDecoderError::FATAL_ERROR);
 }
 
+GMPAudioDecoder::GMPAudioDecoder(const AudioInfo& aConfig,
+                                 TaskQueue* aTaskQueue,
+                                 MediaDataDecoderCallbackProxy* aCallback,
+                                 AudioCallbackAdapter* aAdapter)
+  : mConfig(aConfig)
+  , mCallback(aCallback)
+  , mGMP(nullptr)
+  , mAdapter(aAdapter)
+{
+  MOZ_ASSERT(!aAdapter || aCallback == aAdapter->Callback());
+  if (!aAdapter) {
+    mAdapter = new AudioCallbackAdapter(aCallback);
+  }
+}
+
 void
 GMPAudioDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
   aTags.AppendElement(NS_LITERAL_CSTRING("aac"));
   const Maybe<nsCString> gmp(
     GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("audio/mp4a-latm")));
   if (gmp.isSome()) {
     aTags.AppendElement(gmp.value());
--- a/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.h
+++ b/dom/media/platforms/agnostic/gmp/GMPAudioDecoder.h
@@ -20,16 +20,18 @@ public:
   explicit AudioCallbackAdapter(MediaDataDecoderCallbackProxy* aCallback)
    : mCallback(aCallback)
    , mLastStreamOffset(0)
    , mAudioFrameSum(0)
    , mAudioFrameOffset(0)
    , mMustRecaptureAudioPosition(true)
   {}
 
+  MediaDataDecoderCallbackProxy* Callback() const { return mCallback; }
+
   // GMPAudioDecoderCallbackProxy
   void Decoded(const nsTArray<int16_t>& aPCM, uint64_t aTimeStamp, uint32_t aChannels, uint32_t aRate) override;
   void InputDataExhausted() override;
   void DrainComplete() override;
   void ResetComplete() override;
   void Error(GMPErr aErr) override;
   void Terminated() override;
 
@@ -42,38 +44,21 @@ private:
   int64_t mLastStreamOffset;
 
   int64_t mAudioFrameSum;
   int64_t mAudioFrameOffset;
   bool mMustRecaptureAudioPosition;
 };
 
 class GMPAudioDecoder : public MediaDataDecoder {
-protected:
+public:
   GMPAudioDecoder(const AudioInfo& aConfig,
                   TaskQueue* aTaskQueue,
                   MediaDataDecoderCallbackProxy* aCallback,
-                  AudioCallbackAdapter* aAdapter)
-   : mConfig(aConfig)
-   , mCallback(aCallback)
-   , mGMP(nullptr)
-   , mAdapter(aAdapter)
-  {
-  }
-
-public:
-  GMPAudioDecoder(const AudioInfo& aConfig,
-                  TaskQueue* aTaskQueue,
-                  MediaDataDecoderCallbackProxy* aCallback)
-   : mConfig(aConfig)
-   , mCallback(aCallback)
-   , mGMP(nullptr)
-   , mAdapter(new AudioCallbackAdapter(aCallback))
-  {
-  }
+                  AudioCallbackAdapter* aAdapter);
 
   RefPtr<InitPromise> Init() override;
   nsresult Input(MediaRawData* aSample) override;
   nsresult Flush() override;
   nsresult Drain() override;
   nsresult Shutdown() override;
   const char* GetDescriptionName() const override
   {
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -59,17 +59,18 @@ GMPDecoderModule::CreateVideoDecoder(con
     }
   }
 
   RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper(aParams.mCallback);
   wrapper->SetProxyTarget(new GMPVideoDecoder(aParams.VideoConfig(),
                                               aParams.mLayersBackend,
                                               aParams.mImageContainer,
                                               aParams.mTaskQueue,
-                                              wrapper->Callback()));
+                                              wrapper->Callback(),
+                                              nullptr));
   return wrapper.forget();
 }
 
 already_AddRefed<MediaDataDecoder>
 GMPDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
 {
   if (!aParams.mConfig.mMimeType.EqualsLiteral("audio/mp4a-latm")) {
     return nullptr;
@@ -80,17 +81,18 @@ GMPDecoderModule::CreateAudioDecoder(con
     if (preferredGMP.isSome()) {
       aParams.mDiagnostics->SetGMP(preferredGMP.value());
     }
   }
 
   RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper(aParams.mCallback);
   wrapper->SetProxyTarget(new GMPAudioDecoder(aParams.AudioConfig(),
                                               aParams.mTaskQueue,
-                                              wrapper->Callback()));
+                                              wrapper->Callback(),
+                                              nullptr));
   return wrapper.forget();
 }
 
 PlatformDecoderModule::ConversionRequired
 GMPDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
 {
   // GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
   if (aConfig.IsVideo()) {
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
@@ -99,16 +99,38 @@ VideoCallbackAdapter::Error(GMPErr aErr)
 void
 VideoCallbackAdapter::Terminated()
 {
   // Note that this *may* be called from the proxy thread also.
   NS_WARNING("H.264 GMP decoder terminated.");
   mCallback->Error(MediaDataDecoderError::FATAL_ERROR);
 }
 
+GMPVideoDecoder::GMPVideoDecoder(const VideoInfo& aConfig,
+                                 layers::LayersBackend aLayersBackend,
+                                 layers::ImageContainer* aImageContainer,
+                                 TaskQueue* aTaskQueue,
+                                 MediaDataDecoderCallbackProxy* aCallback,
+                                 VideoCallbackAdapter* aAdapter)
+  : mConfig(aConfig)
+  , mCallback(aCallback)
+  , mGMP(nullptr)
+  , mHost(nullptr)
+  , mAdapter(aAdapter)
+  , mConvertNALUnitLengths(false)
+{
+  MOZ_ASSERT(!aAdapter || mCallback == aAdapter->Callback());
+  if (!aAdapter) {
+    mAdapter = new VideoCallbackAdapter(aCallback,
+                                        VideoInfo(aConfig.mDisplay.width,
+                                                  aConfig.mDisplay.height),
+                                        aImageContainer);
+  }
+}
+
 void
 GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
   aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
   const Maybe<nsCString> gmp(
     GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
   if (gmp.isSome()) {
     aTags.AppendElement(gmp.value());
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.h
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.h
@@ -22,16 +22,18 @@ public:
                        VideoInfo aVideoInfo,
                        layers::ImageContainer* aImageContainer)
    : mCallback(aCallback)
    , mLastStreamOffset(0)
    , mVideoInfo(aVideoInfo)
    , mImageContainer(aImageContainer)
   {}
 
+  MediaDataDecoderCallbackProxy* Callback() const { return mCallback; }
+
   // GMPVideoDecoderCallbackProxy
   void Decoded(GMPVideoi420Frame* aDecodedFrame) override;
   void ReceivedDecodedReferenceFrame(const uint64_t aPictureId) override;
   void ReceivedDecodedFrame(const uint64_t aPictureId) override;
   void InputDataExhausted() override;
   void DrainComplete() override;
   void ResetComplete() override;
   void Error(GMPErr aErr) override;
@@ -51,43 +53,17 @@ private:
 
 class GMPVideoDecoder : public MediaDataDecoder {
 protected:
   GMPVideoDecoder(const VideoInfo& aConfig,
                   layers::LayersBackend aLayersBackend,
                   layers::ImageContainer* aImageContainer,
                   TaskQueue* aTaskQueue,
                   MediaDataDecoderCallbackProxy* aCallback,
-                  VideoCallbackAdapter* aAdapter)
-   : mConfig(aConfig)
-   , mCallback(aCallback)
-   , mGMP(nullptr)
-   , mHost(nullptr)
-   , mAdapter(aAdapter)
-   , mConvertNALUnitLengths(false)
-  {
-  }
-
-public:
-  GMPVideoDecoder(const VideoInfo& aConfig,
-                  layers::LayersBackend aLayersBackend,
-                  layers::ImageContainer* aImageContainer,
-                  TaskQueue* aTaskQueue,
-                  MediaDataDecoderCallbackProxy* aCallback)
-   : mConfig(aConfig)
-   , mCallback(aCallback)
-   , mGMP(nullptr)
-   , mHost(nullptr)
-   , mAdapter(new VideoCallbackAdapter(aCallback,
-                                       VideoInfo(aConfig.mDisplay.width,
-                                                 aConfig.mDisplay.height),
-                                       aImageContainer))
-   , mConvertNALUnitLengths(false)
-  {
-  }
+                  VideoCallbackAdapter* aAdapter);
 
   RefPtr<InitPromise> Init() override;
   nsresult Input(MediaRawData* aSample) override;
   nsresult Flush() override;
   nsresult Drain() override;
   nsresult Shutdown() override;
   const char* GetDescriptionName() const override
   {