Bug 1341549 - Label runnables in dom/media/webaudio/ r?billm
MozReview-Commit-ID: 1SG1KoVjivS
--- a/dom/media/webaudio/AnalyserNode.cpp
+++ b/dom/media/webaudio/AnalyserNode.cpp
@@ -80,17 +80,17 @@ public:
} else {
// This many null chunks will be required to empty AnalyserNode::mChunks.
mChunksToProcess = CHUNK_COUNT;
}
RefPtr<TransferBuffer> transfer =
new TransferBuffer(aStream, aInput.AsAudioChunk());
- NS_DispatchToMainThread(transfer);
+ mAbstractMainThread->Dispatch(transfer.forget());
}
virtual bool IsActive() const override
{
return mChunksToProcess != 0;
}
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
--- a/dom/media/webaudio/AudioBufferSourceNode.cpp
+++ b/dom/media/webaudio/AudioBufferSourceNode.cpp
@@ -822,17 +822,20 @@ AudioBufferSourceNode::NotifyMainThreadS
// Release stream resources.
mNode->DestroyMediaStream();
return NS_OK;
}
private:
RefPtr<AudioBufferSourceNode> mNode;
};
- NS_DispatchToMainThread(new EndedEventDispatcher(this));
+ RefPtr<AbstractThread> mainThread =
+ Context()->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
+ RefPtr<EndedEventDispatcher> endedEvent = new EndedEventDispatcher(this);
+ mainThread->Dispatch(endedEvent.forget());
// Drop the playing reference
// Warning: The below line might delete this.
MarkInactive();
}
void
AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift)
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -823,17 +823,25 @@ AudioContext::OnStateChanged(void* aProm
DebugOnly<bool> rv = mPromiseGripArray.RemoveElement(promise);
MOZ_ASSERT(rv, "Promise wasn't in the grip array?");
}
}
if (mAudioContextState != aNewState) {
RefPtr<OnStateChangeTask> onStateChangeTask =
new OnStateChangeTask(this);
- NS_DispatchToMainThread(onStateChangeTask);
+ nsCOMPtr<nsIGlobalObject> parentObject =
+ do_QueryInterface(GetParentObject());
+ // Since this just did a round trip from the main thread down in the
+ // MediaStreamGraph and even below, it's very possible the global is not
+ // there anymore.
+ if (parentObject) {
+ parentObject->AbstractMainThreadFor(TaskCategory::Other)
+ ->Dispatch(onStateChangeTask.forget());
+ }
}
mAudioContextState = aNewState;
}
nsTArray<MediaStream*>
AudioContext::GetAllStreams() const
{
--- a/dom/media/webaudio/AudioDestinationNode.cpp
+++ b/dom/media/webaudio/AudioDestinationNode.cpp
@@ -164,17 +164,17 @@ public:
rv.SuppressException();
return;
}
aNode->ResolvePromise(renderedBuffer);
RefPtr<OnCompleteTask> onCompleteTask =
new OnCompleteTask(context, renderedBuffer);
- NS_DispatchToMainThread(onCompleteTask);
+ mAbstractMainThread->Dispatch(onCompleteTask.forget());
context->OnStateChanged(nullptr, AudioContextState::Closed);
}
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
{
size_t amount = AudioNodeEngine::SizeOfExcludingThis(aMallocSizeOf);
if (mBuffer) {
--- a/dom/media/webaudio/ConstantSourceNode.cpp
+++ b/dom/media/webaudio/ConstantSourceNode.cpp
@@ -270,17 +270,20 @@ ConstantSourceNode::NotifyMainThreadStre
// Release stream resources.
mNode->DestroyMediaStream();
return NS_OK;
}
private:
RefPtr<ConstantSourceNode> mNode;
};
- NS_DispatchToMainThread(new EndedEventDispatcher(this));
+ RefPtr<AbstractThread> mainThread =
+ Context()->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
+ RefPtr<EndedEventDispatcher> endedEvent = new EndedEventDispatcher(this);
+ mainThread->Dispatch(endedEvent.forget());
// Drop the playing reference
// Warning: The below line might delete this.
MarkInactive();
}
} // namespace dom
} // namespace mozilla
--- a/dom/media/webaudio/DynamicsCompressorNode.cpp
+++ b/dom/media/webaudio/DynamicsCompressorNode.cpp
@@ -164,17 +164,18 @@ private:
return NS_OK;
}
private:
RefPtr<AudioNodeStream> mStream;
float mReduction;
};
- NS_DispatchToMainThread(new Command(aStream, aReduction));
+ RefPtr<Command> command = new Command(aStream, aReduction);
+ mAbstractMainThread->Dispatch(command.forget());
}
private:
AudioNodeStream* mDestination;
AudioParamTimeline mThreshold;
AudioParamTimeline mKnee;
AudioParamTimeline mRatio;
AudioParamTimeline mAttack;
--- a/dom/media/webaudio/MediaBufferDecoder.cpp
+++ b/dom/media/webaudio/MediaBufferDecoder.cpp
@@ -99,21 +99,22 @@ public:
private:
void ReportFailureOnMainThread(WebAudioDecodeJob::ErrorCode aErrorCode) {
if (NS_IsMainThread()) {
Cleanup();
mDecodeJob.OnFailure(aErrorCode);
} else {
// Take extra care to cleanup on the main thread
- NS_DispatchToMainThread(NewRunnableMethod(this, &MediaDecodeTask::Cleanup));
+ mMainThread->Dispatch(NewRunnableMethod(this, &MediaDecodeTask::Cleanup));
+
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(mDecodeJob, &WebAudioDecodeJob::OnFailure, aErrorCode);
- NS_DispatchToMainThread(event);
+ mMainThread->Dispatch(event.forget());
}
}
void Decode();
void OnMetadataRead(MetadataHolder* aMetadata);
void OnMetadataNotRead(const MediaResult& aError);
void RequestSample();
void SampleDecoded(AudioData* aData);
@@ -137,16 +138,17 @@ private:
uint8_t* mBuffer;
uint32_t mLength;
WebAudioDecodeJob& mDecodeJob;
PhaseEnum mPhase;
RefPtr<BufferDecoder> mBufferDecoder;
RefPtr<MediaDecoderReader> mDecoderReader;
MediaInfo mMediaInfo;
MediaQueue<AudioData> mAudioQueue;
+ RefPtr<AbstractThread> mMainThread;
bool mFirstFrameDecoded;
};
NS_IMETHODIMP
MediaDecodeTask::Run()
{
MOZ_ASSERT(mBufferDecoder);
MOZ_ASSERT(mDecoderReader);
@@ -196,19 +198,19 @@ MediaDecodeTask::CreateReader()
principal = sop->GetPrincipal();
}
RefPtr<BufferMediaResource> resource =
new BufferMediaResource(static_cast<uint8_t*> (mBuffer),
mLength, principal, mContainerType);
MOZ_ASSERT(!mBufferDecoder);
- RefPtr<AbstractThread> mainThread =
+ mMainThread =
mDecodeJob.mContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
- mBufferDecoder = new BufferDecoder(resource, mainThread,
+ mBufferDecoder = new BufferDecoder(resource, mMainThread,
new BufferDecoderGMPCrashHelper(parent));
// If you change this list to add support for new decoders, please consider
// updating HTMLMediaElement::CreateDecoder as well.
mDecoderReader = DecoderTraits::CreateReader(mContainerType, mBufferDecoder);
if (!mDecoderReader) {
@@ -436,17 +438,18 @@ MediaDecodeTask::FinishDecode()
mDecodeJob.mWriteIndex += outSamples;
MOZ_ASSERT(mDecodeJob.mWriteIndex <= resampledFrames);
MOZ_ASSERT(inSamples == inputLatency);
}
}
}
mPhase = PhaseEnum::AllocateBuffer;
- NS_DispatchToMainThread(this);
+ RefPtr<MediaDecodeTask> task(this);
+ mMainThread->Dispatch(task.forget());
}
void
MediaDecodeTask::AllocateBuffer()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mDecodeJob.AllocateBuffer()) {
@@ -494,28 +497,32 @@ AsyncDecodeWebAudio(const char* aContent
if (!*aContentType ||
strcmp(aContentType, APPLICATION_OCTET_STREAM) == 0 ||
!containerType) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob,
&WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownContent);
JS_free(nullptr, aBuffer);
- NS_DispatchToMainThread(event);
+ RefPtr<AbstractThread> mainThread =
+ aDecodeJob.mContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
+ mainThread->Dispatch(event.forget());
return;
}
RefPtr<MediaDecodeTask> task =
new MediaDecodeTask(*containerType, aBuffer, aLength, aDecodeJob);
if (!task->CreateReader()) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob,
&WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownError);
- NS_DispatchToMainThread(event);
+ RefPtr<AbstractThread> mainThread =
+ aDecodeJob.mContext->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other);
+ mainThread->Dispatch(event.forget());
} else {
// If we did this without a temporary:
// task->Reader()->OwnerThread()->Dispatch(task.forget())
// we might evaluate the task.forget() before calling Reader(). Enforce
// a non-crashy order-of-operations.
TaskQueue* taskQueue = task->Reader()->OwnerThread();
taskQueue->Dispatch(task.forget());
}
--- a/dom/media/webaudio/OscillatorNode.cpp
+++ b/dom/media/webaudio/OscillatorNode.cpp
@@ -593,17 +593,18 @@ OscillatorNode::NotifyMainThreadStreamFi
// Release stream resources.
mNode->DestroyMediaStream();
return NS_OK;
}
private:
RefPtr<OscillatorNode> mNode;
};
- NS_DispatchToMainThread(new EndedEventDispatcher(this));
+ RefPtr<EndedEventDispatcher> endedEvent = new EndedEventDispatcher(this);
+ Context()->GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)->Dispatch(endedEvent.forget());
// Drop the playing reference
// Warning: The below line might delete this.
MarkInactive();
}
} // namespace dom
} // namespace mozilla
--- a/dom/media/webaudio/ScriptProcessorNode.cpp
+++ b/dom/media/webaudio/ScriptProcessorNode.cpp
@@ -463,18 +463,19 @@ private:
return nullptr;
}
private:
RefPtr<AudioNodeStream> mStream;
RefPtr<ThreadSharedFloatArrayBufferList> mInputBuffer;
double mPlaybackTime;
};
- NS_DispatchToMainThread(new Command(aStream, mInputBuffer.forget(),
- playbackTime));
+ RefPtr<Command> command = new Command(aStream, mInputBuffer.forget(),
+ playbackTime);
+ mAbstractMainThread->Dispatch(command.forget());
}
friend class ScriptProcessorNode;
AudioNodeStream* mDestination;
nsAutoPtr<SharedBuffers> mSharedBuffers;
RefPtr<ThreadSharedFloatArrayBufferList> mInputBuffer;
const uint32_t mBufferSize;