Bug 1331862. Part 2 - add functions to collect debugging info asynchronously.
MozReview-Commit-ID: 4btaZqUqyLn
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1750,16 +1750,37 @@ MediaDecoder::DumpDebugInfo()
DUMP_LOG("reader data:\n%s", str.get());
}
if (GetStateMachine()) {
GetStateMachine()->DumpDebugInfo();
}
}
+RefPtr<MediaDecoder::DebugInfoPromise>
+MediaDecoder::RequestDebugInfo()
+{
+ MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
+
+ auto str = GetDebugInfo();
+ if (!GetStateMachine()) {
+ return DebugInfoPromise::CreateAndResolve(str, __func__);
+ }
+
+ return GetStateMachine()->RequestDebugInfo()->Then(
+ AbstractThread::MainThread(), __func__,
+ [str] (const nsACString& aString) {
+ nsCString result = str + nsCString("\n") + aString;
+ return DebugInfoPromise::CreateAndResolve(result, __func__);
+ },
+ [str] () {
+ return DebugInfoPromise::CreateAndResolve(str, __func__);
+ });
+}
+
void
MediaDecoder::NotifyAudibleStateChanged()
{
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
mOwner->SetAudibleState(mIsAudioDataAudible);
}
MediaMemoryTracker::MediaMemoryTracker()
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -472,16 +472,19 @@ private:
virtual MediaDecoderOwner::NextFrameStatus NextFrameBufferedStatus();
// Returns a string describing the state of the media player internal
// data. Used for debugging purposes.
virtual void GetMozDebugReaderData(nsACString& aString) {}
virtual void DumpDebugInfo();
+ using DebugInfoPromise = MozPromise<nsCString, bool, true>;
+ RefPtr<DebugInfoPromise> RequestDebugInfo();
+
protected:
virtual ~MediaDecoder();
// Called when the first audio and/or video from the media file has been loaded
// by the state machine. Call on the main thread only.
virtual void FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility);
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -3678,16 +3678,27 @@ MediaDecoderStateMachine::DumpDebugInfo(
// Since the task is run asynchronously, it is possible other tasks get first
// and change the object states before we print them. Therefore we want to
// dispatch this task immediately without waiting for the tail dispatching
// phase so object states are less likely to change before being printed.
OwnerThread()->Dispatch(r.forget(),
AbstractThread::AssertDispatchSuccess, AbstractThread::TailDispatch);
}
+RefPtr<MediaDecoder::DebugInfoPromise>
+MediaDecoderStateMachine::RequestDebugInfo()
+{
+ using PromiseType = MediaDecoder::DebugInfoPromise;
+ RefPtr<PromiseType::Private> p = new PromiseType::Private(__func__);
+ OwnerThread()->Dispatch(NS_NewRunnableFunction([this, p] () {
+ p->Resolve(GetDebugInfo(), __func__);
+ }), AbstractThread::AssertDispatchSuccess, AbstractThread::TailDispatch);
+ return p.forget();
+}
+
void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
bool aFinishWhenEnded)
{
MOZ_ASSERT(NS_IsMainThread());
DECODER_LOG("AddOutputStream aStream=%p!", aStream);
mOutputStreamManager->Add(aStream, aFinishWhenEnded);
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<bool>(
this, &MediaDecoderStateMachine::SetAudioCaptured, true);
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -157,16 +157,17 @@ public:
DECODER_STATE_DECODING,
DECODER_STATE_SEEKING,
DECODER_STATE_BUFFERING,
DECODER_STATE_COMPLETED,
DECODER_STATE_SHUTDOWN
};
void DumpDebugInfo();
+ RefPtr<MediaDecoder::DebugInfoPromise> RequestDebugInfo();
void AddOutputStream(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
// Remove an output stream added with AddOutputStream.
void RemoveOutputStream(MediaStream* aStream);
// Seeks to the decoder to aTarget asynchronously.
RefPtr<MediaDecoder::SeekPromise> InvokeSeek(const SeekTarget& aTarget);