Bug 1272232. Part 3 - constify some members and make them private when possible. r=jya.
authorJW Wang <jwwang@mozilla.com>
Sun, 15 May 2016 20:14:55 +0800
changeset 367763 f158ef82936c7a2990444471a5e6936fd33260d5
parent 367762 64bf09ce35338cf812f6764ccbff834866975fc0
child 367764 d7c63a0d98a23337c96b6af21f24d61aab1e7a1b
push id18344
push userdburns@mozilla.com
push dateTue, 17 May 2016 10:11:20 +0000
reviewersjya
bugs1272232
milestone49.0a1
Bug 1272232. Part 3 - constify some members and make them private when possible. r=jya. MozReview-Commit-ID: LTFFBRTB9Pr
dom/media/platforms/apple/AppleVDADecoder.cpp
dom/media/platforms/apple/AppleVDADecoder.h
dom/media/platforms/apple/AppleVTDecoder.h
--- a/dom/media/platforms/apple/AppleVDADecoder.cpp
+++ b/dom/media/platforms/apple/AppleVDADecoder.cpp
@@ -29,57 +29,62 @@
 #endif
 
 extern mozilla::LogModule* GetPDMLog();
 #define LOG(...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
 //#define LOG_MEDIA_SHA1
 
 namespace mozilla {
 
+static uint32_t ComputeMaxRefFrames(const MediaByteBuffer* aExtraData)
+{
+  uint32_t maxRefFrames = 4;
+  // Retrieve video dimensions from H264 SPS NAL.
+  mp4_demuxer::SPSData spsdata;
+  if (mp4_demuxer::H264::DecodeSPSFromExtraData(aExtraData, spsdata)) {
+    // max_num_ref_frames determines the size of the sliding window
+    // we need to queue that many frames in order to guarantee proper
+    // pts frames ordering. Use a minimum of 4 to ensure proper playback of
+    // non compliant videos.
+    maxRefFrames =
+      std::min(std::max(maxRefFrames, spsdata.max_num_ref_frames + 1), 16u);
+  }
+  return maxRefFrames;
+}
+
 AppleVDADecoder::AppleVDADecoder(const VideoInfo& aConfig,
                                FlushableTaskQueue* aVideoTaskQueue,
                                MediaDataDecoderCallback* aCallback,
                                layers::ImageContainer* aImageContainer)
-  : mCallback(aCallback)
-  , mImageContainer(aImageContainer)
+  : mExtraData(aConfig.mExtraData)
+  , mCallback(aCallback)
   , mPictureWidth(aConfig.mImage.width)
   , mPictureHeight(aConfig.mImage.height)
   , mDisplayWidth(aConfig.mDisplay.width)
   , mDisplayHeight(aConfig.mDisplay.height)
+  , mQueuedSamples(0)
+  , mTaskQueue(aVideoTaskQueue)
+  , mDecoder(nullptr)
+  , mMaxRefFrames(ComputeMaxRefFrames(aConfig.mExtraData))
+  , mImageContainer(aImageContainer)
   , mInputIncoming(0)
   , mIsShutDown(false)
 #ifdef MOZ_WIDGET_UIKIT
   , mUseSoftwareImages(true)
   , mIs106(false)
 #else
   , mUseSoftwareImages(false)
   , mIs106(!nsCocoaFeatures::OnLionOrLater())
-  #endif
-  , mQueuedSamples(0)
+#endif
   , mMonitor("AppleVideoDecoder")
   , mIsFlushing(false)
-  , mTaskQueue(aVideoTaskQueue)
-  , mDecoder(nullptr)
 {
   MOZ_COUNT_CTOR(AppleVDADecoder);
   // TODO: Verify aConfig.mime_type.
 
-  mExtraData = aConfig.mExtraData;
-  mMaxRefFrames = 4;
-  // Retrieve video dimensions from H264 SPS NAL.
-  mp4_demuxer::SPSData spsdata;
-  if (mp4_demuxer::H264::DecodeSPSFromExtraData(mExtraData, spsdata)) {
-    // max_num_ref_frames determines the size of the sliding window
-    // we need to queue that many frames in order to guarantee proper
-    // pts frames ordering. Use a minimum of 4 to ensure proper playback of
-    // non compliant videos.
-    mMaxRefFrames =
-      std::min(std::max(mMaxRefFrames, spsdata.max_num_ref_frames + 1), 16u);
-  }
-
   LOG("Creating AppleVDADecoder for %dx%d (%dx%d) h.264 video",
       mPictureWidth,
       mPictureHeight,
       mDisplayWidth,
       mDisplayHeight
      );
 }
 
--- a/dom/media/platforms/apple/AppleVDADecoder.h
+++ b/dom/media/platforms/apple/AppleVDADecoder.h
@@ -61,91 +61,91 @@ public:
   // Return a new created AppleVDADecoder or nullptr if media or hardware is
   // not supported by current configuration.
   static already_AddRefed<AppleVDADecoder> CreateVDADecoder(
     const VideoInfo& aConfig,
     FlushableTaskQueue* aVideoTaskQueue,
     MediaDataDecoderCallback* aCallback,
     layers::ImageContainer* aImageContainer);
 
-  AppleVDADecoder(const VideoInfo& aConfig,
-                  FlushableTaskQueue* aVideoTaskQueue,
-                  MediaDataDecoderCallback* aCallback,
-                  layers::ImageContainer* aImageContainer);
-  virtual ~AppleVDADecoder();
+  // Access from the taskqueue and the decoder's thread.
+  // OutputFrame is thread-safe.
+  nsresult OutputFrame(CVPixelBufferRef aImage,
+                       AppleFrameRef aFrameRef);
+
+private:
   RefPtr<InitPromise> Init() override;
   nsresult Input(MediaRawData* aSample) override;
   nsresult Flush() override;
   nsresult Drain() override;
   nsresult Shutdown() override;
   bool IsHardwareAccelerated(nsACString& aFailureReason) const override
   {
     return true;
   }
 
   const char* GetDescriptionName() const override
   {
     return "apple VDA decoder";
   }
 
-  // Access from the taskqueue and the decoder's thread.
-  // OutputFrame is thread-safe.
-  nsresult OutputFrame(CVPixelBufferRef aImage,
-                       AppleFrameRef aFrameRef);
+protected:
+  AppleVDADecoder(const VideoInfo& aConfig,
+                  FlushableTaskQueue* aVideoTaskQueue,
+                  MediaDataDecoderCallback* aCallback,
+                  layers::ImageContainer* aImageContainer);
+  virtual ~AppleVDADecoder();
 
-protected:
   void AssertOnTaskQueueThread()
   {
     MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
   }
 
-  // Flush and Drain operation, always run
-  virtual void ProcessFlush();
-  virtual void ProcessDrain();
-  virtual void ProcessShutdown();
-
   AppleFrameRef* CreateAppleFrameRef(const MediaRawData* aSample);
   void DrainReorderedFrames();
   void ClearReorderedFrames();
   CFDictionaryRef CreateOutputConfiguration();
 
-  RefPtr<MediaByteBuffer> mExtraData;
+  const RefPtr<MediaByteBuffer> mExtraData;
   MediaDataDecoderCallback* mCallback;
-  RefPtr<layers::ImageContainer> mImageContainer;
-  uint32_t mPictureWidth;
-  uint32_t mPictureHeight;
-  uint32_t mDisplayWidth;
-  uint32_t mDisplayHeight;
-  // Accessed on multiple threads, but only set in constructor.
-  uint32_t mMaxRefFrames;
-  // Increased when Input is called, and decreased when ProcessFrame runs.
-  // Reaching 0 indicates that there's no pending Input.
-  Atomic<uint32_t> mInputIncoming;
-  Atomic<bool> mIsShutDown;
-
-  const bool mUseSoftwareImages;
-  const bool mIs106;
+  const uint32_t mPictureWidth;
+  const uint32_t mPictureHeight;
+  const uint32_t mDisplayWidth;
+  const uint32_t mDisplayHeight;
 
   // Number of times a sample was queued via Input(). Will be decreased upon
   // the decoder's callback being invoked.
   // This is used to calculate how many frames has been buffered by the decoder.
   Atomic<uint32_t> mQueuedSamples;
 
+private:
+  // Flush and Drain operation, always run
+  virtual void ProcessFlush();
+  virtual void ProcessDrain();
+  virtual void ProcessShutdown();
+
+  const RefPtr<FlushableTaskQueue> mTaskQueue;
+  VDADecoder mDecoder;
+  const uint32_t mMaxRefFrames;
+  const RefPtr<layers::ImageContainer> mImageContainer;
+  // Increased when Input is called, and decreased when ProcessFrame runs.
+  // Reaching 0 indicates that there's no pending Input.
+  Atomic<uint32_t> mInputIncoming;
+  Atomic<bool> mIsShutDown;
+  const bool mUseSoftwareImages;
+  const bool mIs106;
+
   // Protects mReorderQueue.
   Monitor mMonitor;
   // Set on reader/decode thread calling Flush() to indicate that output is
   // not required and so input samples on mTaskQueue need not be processed.
   // Cleared on mTaskQueue in ProcessDrain().
   Atomic<bool> mIsFlushing;
   ReorderQueue mReorderQueue;
 
-private:
-  const RefPtr<FlushableTaskQueue> mTaskQueue;
-  VDADecoder mDecoder;
-
   // Method to set up the decompression session.
   nsresult InitializeSession();
 
   // Method to pass a frame to VideoToolbox for decoding.
   nsresult ProcessDecode(MediaRawData* aSample);
   virtual nsresult DoDecode(MediaRawData* aSample);
   CFDictionaryRef CreateDecoderSpecification();
 };
--- a/dom/media/platforms/apple/AppleVTDecoder.h
+++ b/dom/media/platforms/apple/AppleVTDecoder.h
@@ -14,36 +14,36 @@
 namespace mozilla {
 
 class AppleVTDecoder : public AppleVDADecoder {
 public:
   AppleVTDecoder(const VideoInfo& aConfig,
                  FlushableTaskQueue* aVideoTaskQueue,
                  MediaDataDecoderCallback* aCallback,
                  layers::ImageContainer* aImageContainer);
+
+private:
   virtual ~AppleVTDecoder();
   RefPtr<InitPromise> Init() override;
   bool IsHardwareAccelerated(nsACString& aFailureReason) const override
   {
     return mIsHardwareAccelerated;
   }
 
   const char* GetDescriptionName() const override
   {
     return mIsHardwareAccelerated
       ? "apple hardware VT decoder"
       : "apple software VT decoder";
   }
 
-protected:
   void ProcessFlush() override;
   void ProcessDrain() override;
   void ProcessShutdown() override;
 
-private:
   CMVideoFormatDescriptionRef mFormat;
   VTDecompressionSessionRef mSession;
 
   // Method to pass a frame to VideoToolbox for decoding.
   nsresult DoDecode(MediaRawData* aSample) override;
   // Method to set up the decompression session.
   nsresult InitializeSession();
   nsresult WaitForAsynchronousFrames();