From 17ca0b45f8a54f8910f38dc6c334e5ba4285baac Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Wed, 13 Dec 2017 17:10:14 -0600 Subject: [PATCH] Bug 1425150 - Register AudioCallbackDriver to the Gecko Profiler. r=jya MozReview-Commit-ID: 3rJbF8Kq0zx --HG-- extra : rebase_source : 49719ea92da9c1c556b1c3d10a06d3f2cdc3b08f --- dom/media/GraphDriver.cpp | 11 +++++++++++ dom/media/GraphDriver.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index 347f91da0046..e15e52d94272 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -539,6 +539,7 @@ AudioCallbackDriver::AudioCallbackDriver(MediaStreamGraphImpl* aGraphImpl) , mMicrophoneActive(false) , mShouldFallbackIfError(false) , mFromFallback(false) + , mProfilerRegistered(false) { LOG(LogLevel::Debug, ("AudioCallbackDriver ctor for graph %p", aGraphImpl)); #if defined(XP_WIN) @@ -897,6 +898,11 @@ AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, AutoInCallback aic(this); #endif + if (!mProfilerRegistered) { + mProfilerRegistered = true; + PROFILER_REGISTER_THREAD("AudioCallback"); + } + GraphTime stateComputedTime = StateComputedTime(); if (stateComputedTime == 0) { MonitorAutoLock mon(mGraphImpl->GetMonitor()); @@ -1002,6 +1008,8 @@ AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, // Enter shutdown mode. The stable-state handler will detect this // and complete shutdown if the graph does not get restarted. mGraphImpl->SignalMainThreadCleanup(); + + PROFILER_UNREGISTER_THREAD(); return aFrames - 1; } @@ -1024,6 +1032,7 @@ AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, NextDriver()->SetGraphTime(this, mIterationStart, mIterationEnd); mGraphImpl->SetCurrentDriver(NextDriver()); NextDriver()->Start(); + PROFILER_UNREGISTER_THREAD(); // Returning less than aFrames starts the draining and eventually stops the // audio thread. This function will never get called again. return aFrames - 1; @@ -1115,6 +1124,8 @@ AudioCallbackDriver::DeviceChangedCallback() { #ifdef XP_MACOSX PanOutputIfNeeded(mMicrophoneActive); #endif + + mProfilerRegistered = false; } void diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h index 69829b3ee79d..304c81c64d7f 100644 --- a/dom/media/GraphDriver.h +++ b/dom/media/GraphDriver.h @@ -566,6 +566,12 @@ private: /* True if this driver was created from a driver created because of a previous * AudioCallbackDriver failure. */ bool mFromFallback; + /* Whether or not the Gecko profiler has been registered for this thread. + * We reset this on device change, because the underlying thread is going to + * change. + * We de-register on the last iteration, and re-register on the first + * iteration of a new driver. */ + Atomic mProfilerRegistered; }; class AsyncCubebTask : public Runnable