Bug 1216895 - assert that decoder methods are run on correct thread. r=jya

This commit is contained in:
John Lin 2015-11-09 18:58:00 +01:00
parent f10040b2ed
commit c931bd1038
2 changed files with 50 additions and 3 deletions

View File

@ -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 <utils/AndroidThreads.h>
#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<AMessage> 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> &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> &aMessage)
}
}
#ifdef DEBUG
bool
GonkDecoderManager::OnTaskLooper()
{
return androidGetThreadId() == mTaskLooperId;
}
#endif
GonkMediaDataDecoder::GonkMediaDataDecoder(GonkDecoderManager* aManager,
FlushableTaskQueue* aTaskQueue,
MediaDataDecoderCallback* aCallback)

View File

@ -70,7 +70,7 @@ protected:
RefPtr<MediaData>& 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<android::ALooper> 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<InitPromise> mInitPromise;
@ -106,10 +110,11 @@ protected:
// Samples are queued in caller's thread and dequeued in mTaskLooper.
nsTArray<RefPtr<MediaRawData>> 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