Bug 1315631 - Don't dispatch |this| in the constructor. r=jya

Because it will change the ref-count which might cause destructor to run before exiting the constructor.

MozReview-Commit-ID: MMIea970Dv

--HG--
extra : rebase_source : faf898a3107706bc0ea750e738d8c3a7a3824264
This commit is contained in:
JW Wang 2016-11-08 23:09:34 +08:00
parent c839abc03c
commit 114ec342ad
4 changed files with 10 additions and 5 deletions

View File

@ -80,14 +80,18 @@ MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder)
{
MOZ_COUNT_CTOR(MediaDecoderReader);
MOZ_ASSERT(NS_IsMainThread());
}
nsresult
MediaDecoderReader::Init()
{
if (mDecoder && mDecoder->DataArrivedEvent()) {
mDataArrivedListener = mDecoder->DataArrivedEvent()->Connect(
mTaskQueue, this, &MediaDecoderReader::NotifyDataArrived);
}
// Dispatch initialization that needs to happen on that task queue.
mTaskQueue->Dispatch(NewRunnableMethod(this, &MediaDecoderReader::InitializationTask));
return InitInternal();
}
void

View File

@ -87,7 +87,7 @@ public:
// Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
// on failure.
virtual nsresult Init() { return NS_OK; }
nsresult Init();
// Called by MDSM in dormant state to release resources allocated by this
// reader. The reader can resume decoding by calling Seek() to a specific
@ -325,6 +325,8 @@ protected:
MediaEventProducer<void> mOnMediaNotSeekable;
private:
virtual nsresult InitInternal() { return NS_OK; }
// Does any spinup that needs to happen on this task queue. This runs on a
// different thread than Init, and there should not be ordering dependencies
// between the two (even though in practice, Init will always run first right

View File

@ -558,7 +558,7 @@ MediaFormatReader::InitLayersBackendType()
}
nsresult
MediaFormatReader::Init()
MediaFormatReader::InitInternal()
{
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");

View File

@ -33,8 +33,6 @@ public:
virtual ~MediaFormatReader();
nsresult Init() override;
size_t SizeOfVideoQueueInFrames() override;
size_t SizeOfAudioQueueInFrames() override;
@ -86,6 +84,7 @@ public:
void SetVideoBlankDecode(bool aIsBlankDecode) override;
private:
nsresult InitInternal() override;
bool HasVideo() const { return mVideo.mTrackDemuxer; }
bool HasAudio() const { return mAudio.mTrackDemuxer; }