From c931bd1038fee9c67ca84037fa664390ce46bcad Mon Sep 17 00:00:00 2001 From: John Lin Date: Mon, 9 Nov 2015 18:58:00 +0100 Subject: [PATCH] Bug 1216895 - assert that decoder methods are run on correct thread. r=jya --- .../platforms/gonk/GonkMediaDataDecoder.cpp | 35 +++++++++++++++++++ .../platforms/gonk/GonkMediaDataDecoder.h | 18 ++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp index 858c423d79c..1d91516f10b 100644 --- a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp +++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp @@ -16,6 +16,10 @@ #define INPUT_TIMEOUT_US 0LL // Don't wait for buffer if none is available. #define MIN_QUEUED_SAMPLES 2 +#ifdef DEBUG +#include +#endif + extern PRLogModuleInfo* GetPDMLog(); #define LOG(...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__)) @@ -41,6 +45,11 @@ GonkDecoderManager::InitLoopers(MediaData::Type aType) mTaskLooper->setName(name.c_str()); mTaskLooper->registerHandler(this); +#ifdef DEBUG + sp findThreadId(new AMessage(kNotifyFindLooperId, id())); + findThreadId->post(); +#endif + return mDecodeLooper->start() == OK && mTaskLooper->start() == OK; } @@ -71,6 +80,8 @@ GonkDecoderManager::Input(MediaRawData* aSample) int32_t GonkDecoderManager::ProcessQueuedSamples() { + MOZ_ASSERT(OnTaskLooper()); + MutexAutoLock lock(mMutex); status_t rv; while (mQueuedSamples.Length()) { @@ -146,6 +157,8 @@ GonkDecoderManager::NumQueuedSamples() void GonkDecoderManager::ProcessInput(bool aEndOfStream) { + MOZ_ASSERT(OnTaskLooper()); + status_t rv = ProcessQueuedSamples(); if (rv >= 0) { if (!aEndOfStream && rv <= MIN_QUEUED_SAMPLES) { @@ -170,6 +183,8 @@ GonkDecoderManager::ProcessInput(bool aEndOfStream) void GonkDecoderManager::ProcessFlush() { + MOZ_ASSERT(OnTaskLooper()); + mLastTime = INT64_MIN; MonitorAutoLock lock(mFlushMonitor); mWaitOutput.Clear(); @@ -188,6 +203,8 @@ GonkDecoderManager::ProcessFlush() void GonkDecoderManager::UpdateWaitingList(int64_t aForgetUpTo) { + MOZ_ASSERT(OnTaskLooper()); + size_t i; for (i = 0; i < mWaitOutput.Length(); i++) { const auto& item = mWaitOutput.ElementAt(i); @@ -203,6 +220,8 @@ GonkDecoderManager::UpdateWaitingList(int64_t aForgetUpTo) void GonkDecoderManager::ProcessToDo(bool aEndOfStream) { + MOZ_ASSERT(OnTaskLooper()); + MOZ_ASSERT(mToDo.get() != nullptr); mToDo.clear(); @@ -274,6 +293,14 @@ GonkDecoderManager::onMessageReceived(const sp &aMessage) ProcessToDo(aMessage->findInt32("input-eos", &eos) && eos); break; } +#ifdef DEBUG + case kNotifyFindLooperId: + { + mTaskLooperId = androidGetThreadId(); + MOZ_ASSERT(mTaskLooperId); + break; + } +#endif default: { TRESPASS(); @@ -282,6 +309,14 @@ GonkDecoderManager::onMessageReceived(const sp &aMessage) } } +#ifdef DEBUG +bool +GonkDecoderManager::OnTaskLooper() +{ + return androidGetThreadId() == mTaskLooperId; +} +#endif + GonkMediaDataDecoder::GonkMediaDataDecoder(GonkDecoderManager* aManager, FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback) diff --git a/dom/media/platforms/gonk/GonkMediaDataDecoder.h b/dom/media/platforms/gonk/GonkMediaDataDecoder.h index e5a0e59f6e6..334679e942d 100644 --- a/dom/media/platforms/gonk/GonkMediaDataDecoder.h +++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.h @@ -70,7 +70,7 @@ protected: RefPtr& aOutput) = 0; // Send queued samples to OMX. It returns how many samples are still in - // queue after processing, or negtive error code if failed. + // queue after processing, or negative error code if failed. int32_t ProcessQueuedSamples(); void ProcessInput(bool aEndOfStream); @@ -88,6 +88,7 @@ protected: // Looper to run decode tasks such as processing input, output, flush, and // recycling output buffers. android::sp mTaskLooper; + // Message codes for tasks running on mTaskLooper. enum { // Decoder will send this to indicate internal state change such as input or // output buffers availability. Used to run pending input & output tasks. @@ -96,6 +97,9 @@ protected: kNotifyProcessFlush = 'npf ', // Used to process queued samples when there is new input. kNotifyProcessInput = 'npi ', +#ifdef DEBUG + kNotifyFindLooperId = 'nfli', +#endif }; MozPromiseHolder mInitPromise; @@ -106,10 +110,11 @@ protected: // Samples are queued in caller's thread and dequeued in mTaskLooper. nsTArray> mQueuedSamples; - int64_t mLastTime; // The last decoded frame presentation time. + // The last decoded frame presentation time. Only accessed on mTaskLooper. + int64_t mLastTime; Monitor mFlushMonitor; // Waits for flushing to complete. - bool mIsFlushing; + bool mIsFlushing; // Protected by mFlushMonitor. // Remembers the notification that is currently waiting for the decoder event // to avoid requesting more than one notification at the time, which is @@ -134,6 +139,13 @@ protected: private: void UpdateWaitingList(int64_t aForgetUpTo); + +#ifdef DEBUG + typedef void* LooperId; + + bool OnTaskLooper(); + LooperId mTaskLooperId; +#endif }; class AutoReleaseMediaBuffer