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