Bug 1272553. Part 3 - make mTaskQueue private. r=jya. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 13 May 2016 11:19:21 +0800
changeset 366652 ef13fd3b458b4536dbb7ad2dbd5443069461ca38
parent 366651 466327c20c88ebc12dfe2ef5d13f3452d2221987
child 520825 3da593e84b7d9488827ce60d0c7911b61b0d6cf6
push id18040
push userjwwang@mozilla.com
push dateFri, 13 May 2016 03:31:38 +0000
reviewersjya
bugs1272553
milestone49.0a1
Bug 1272553. Part 3 - make mTaskQueue private. r=jya. MozReview-Commit-ID: CbZz7oPNKnp
dom/media/platforms/apple/AppleVDADecoder.cpp
dom/media/platforms/apple/AppleVDADecoder.h
dom/media/platforms/apple/AppleVTDecoder.cpp
--- a/dom/media/platforms/apple/AppleVDADecoder.cpp
+++ b/dom/media/platforms/apple/AppleVDADecoder.cpp
@@ -33,18 +33,17 @@ extern mozilla::LogModule* GetPDMLog();
 //#define LOG_MEDIA_SHA1
 
 namespace mozilla {
 
 AppleVDADecoder::AppleVDADecoder(const VideoInfo& aConfig,
                                FlushableTaskQueue* aVideoTaskQueue,
                                MediaDataDecoderCallback* aCallback,
                                layers::ImageContainer* aImageContainer)
-  : mTaskQueue(aVideoTaskQueue)
-  , mCallback(aCallback)
+  : mCallback(aCallback)
   , mImageContainer(aImageContainer)
   , mPictureWidth(aConfig.mImage.width)
   , mPictureHeight(aConfig.mImage.height)
   , mDisplayWidth(aConfig.mDisplay.width)
   , mDisplayHeight(aConfig.mDisplay.height)
   , mInputIncoming(0)
   , mIsShutDown(false)
 #ifdef MOZ_WIDGET_UIKIT
@@ -52,16 +51,17 @@ AppleVDADecoder::AppleVDADecoder(const V
   , mIs106(false)
 #else
   , mUseSoftwareImages(false)
   , mIs106(!nsCocoaFeatures::OnLionOrLater())
   #endif
   , mQueuedSamples(0)
   , 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.
@@ -160,30 +160,30 @@ AppleVDADecoder::Drain()
     NewRunnableMethod(this, &AppleVDADecoder::ProcessDrain);
   mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 void
 AppleVDADecoder::ProcessFlush()
 {
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
 
   OSStatus rv = VDADecoderFlush(mDecoder, 0 /*dont emit*/);
   if (rv != noErr) {
     LOG("AppleVDADecoder::Flush failed waiting for platform decoder "
         "with error:%d.", rv);
   }
   ClearReorderedFrames();
 }
 
 void
 AppleVDADecoder::ProcessDrain()
 {
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
 
   OSStatus rv = VDADecoderFlush(mDecoder, kVDADecoderFlush_EmitFrames);
   if (rv != noErr) {
     LOG("AppleVDADecoder::Drain failed waiting for platform decoder "
         "with error:%d.", rv);
   }
   DrainReorderedFrames();
   mCallback->DrainComplete();
@@ -422,17 +422,17 @@ AppleVDADecoder::OutputFrame(CVPixelBuff
       static_cast<unsigned long long>(mReorderQueue.Length()));
 
   return NS_OK;
 }
 
 nsresult
 AppleVDADecoder::ProcessDecode(MediaRawData* aSample)
 {
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
 
   mInputIncoming--;
 
   AutoCFRelease<CFDataRef> block =
     CFDataCreate(kCFAllocatorDefault, aSample->Data(), aSample->Size());
   if (!block) {
     NS_ERROR("Couldn't create CFData");
     return NS_ERROR_FAILURE;
--- a/dom/media/platforms/apple/AppleVDADecoder.h
+++ b/dom/media/platforms/apple/AppleVDADecoder.h
@@ -87,28 +87,32 @@ public:
   }
 
   // Access from the taskqueue and the decoder's thread.
   // OutputFrame is thread-safe.
   nsresult OutputFrame(CVPixelBufferRef aImage,
                        AppleFrameRef aFrameRef);
 
 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;
-  RefPtr<FlushableTaskQueue> mTaskQueue;
   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;
@@ -129,16 +133,17 @@ protected:
   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:
+  RefPtr<FlushableTaskQueue> mTaskQueue;
   VDADecoder mDecoder;
 
   // Method to set up the decompression session.
   nsresult InitializeSession();
 
   // Method to pass a frame to VideoToolbox for decoding.
   virtual nsresult ProcessDecode(MediaRawData* aSample);
   CFDictionaryRef CreateDecoderSpecification();
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -78,29 +78,29 @@ AppleVTDecoder::ProcessShutdown()
     CFRelease(mFormat);
     mFormat = nullptr;
   }
 }
 
 void
 AppleVTDecoder::ProcessFlush()
 {
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
   nsresult rv = WaitForAsynchronousFrames();
   if (NS_FAILED(rv)) {
     LOG("AppleVTDecoder::Flush failed waiting for platform decoder "
         "with error:%d.", rv);
   }
   ClearReorderedFrames();
 }
 
 void
 AppleVTDecoder::ProcessDrain()
 {
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
   nsresult rv = WaitForAsynchronousFrames();
   if (NS_FAILED(rv)) {
     LOG("AppleVTDecoder::Drain failed waiting for platform decoder "
         "with error:%d.", rv);
   }
   DrainReorderedFrames();
   mCallback->DrainComplete();
 }
@@ -178,17 +178,17 @@ AppleVTDecoder::ProcessDecode(MediaRawDa
   hash.finish(digest_buf);
   nsAutoCString digest;
   for (size_t i = 0; i < sizeof(digest_buf); i++) {
     digest.AppendPrintf("%02x", digest_buf[i]);
   }
   LOG("    sha1 %s", digest.get());
 #endif // LOG_MEDIA_SHA1
 
-  MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  AssertOnTaskQueueThread();
   mInputIncoming--;
   // For some reason this gives me a double-free error with stagefright.
   AutoCFRelease<CMBlockBufferRef> block = nullptr;
   AutoCFRelease<CMSampleBufferRef> sample = nullptr;
   VTDecodeInfoFlags infoFlags;
   OSStatus rv;
 
   // FIXME: This copies the sample data. I think we can provide