From f2a2fb7d24f57dab3385be250d498a80731c4dcc Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 23 Jun 2020 16:43:40 +0000 Subject: [PATCH] Bug 1646348 - Use the AudioThreadRegistry in GraphDriver.cpp. r=achronop This patch changes the type of mAudioThreadId because `std::thread::id` is non-memovable and AudioThreadRegistry uses an nsTArray, that needs elements to be memovable. Differential Revision: https://phabricator.services.mozilla.com/D80466 --- dom/media/GraphDriver.cpp | 15 +++++++++------ dom/media/GraphDriver.h | 6 ++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index 7de61174ed13..d62b27ee3fe1 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -17,6 +17,7 @@ #include "mozilla/MathAlgorithms.h" #include "CubebDeviceEnumerator.h" #include "MediaTrackGraphImpl.h" +#include "AudioThreadRegistry.h" #include "Tracing.h" #ifdef MOZ_WEBRTC @@ -502,7 +503,7 @@ AudioCallbackDriver::AudioCallbackDriver( mStarted(false), mInitShutdownThread( SharedThreadPool::Get(NS_LITERAL_CSTRING("CubebOperation"), 1)), - mAudioThreadId(std::thread::id()), + mAudioThreadId(0), mAudioThreadIdInCb(std::thread::id()), mAudioStreamState(AudioStreamState::None), mFallback("AudioCallbackDriver::mFallback"), @@ -856,11 +857,13 @@ AudioCallbackDriver::AutoInCallback::~AutoInCallback() { } bool AudioCallbackDriver::CheckThreadIdChanged() { - auto id = std::this_thread::get_id(); +#ifdef MOZ_GECKO_PROFILER + auto id = profiler_current_thread_id(); if (id != mAudioThreadId) { mAudioThreadId = id; return true; } +#endif return false; } @@ -868,7 +871,7 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, AudioDataValue* aOutputBuffer, long aFrames) { if (!mSandboxed && CheckThreadIdChanged()) { - PROFILER_REGISTER_THREAD("NativeAudioCallback"); + CubebUtils::GetAudioThreadRegistry()->Register(mAudioThreadId); } FallbackDriverState fallbackState = mFallbackDriverState; if (MOZ_UNLIKELY(fallbackState == FallbackDriverState::Running)) { @@ -883,7 +886,7 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, // We're supposed to stop. PodZero(aOutputBuffer, aFrames * mOutputChannelCount); if (!mSandboxed) { - PROFILER_UNREGISTER_THREAD(); + CubebUtils::GetAudioThreadRegistry()->Unregister(mAudioThreadId); } return aFrames - 1; } @@ -1016,7 +1019,7 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, // Update the flag before handing over the graph and going to drain. mAudioStreamState = AudioStreamState::Stopping; if (!mSandboxed) { - PROFILER_UNREGISTER_THREAD(); + CubebUtils::GetAudioThreadRegistry()->Unregister(mAudioThreadId); } return aFrames - 1; } @@ -1030,7 +1033,7 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer, nextDriver->SetState(mIterationStart, mIterationEnd, mStateComputedTime); nextDriver->Start(); if (!mSandboxed) { - PROFILER_UNREGISTER_THREAD(); + CubebUtils::GetAudioThreadRegistry()->Unregister(mAudioThreadId); } // Returning less than aFrames starts the draining and eventually stops the // audio thread. This function will never get called again. diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h index 4263789b0595..33e3bb7cc47b 100644 --- a/dom/media/GraphDriver.h +++ b/dom/media/GraphDriver.h @@ -737,10 +737,8 @@ class AudioCallbackDriver : public GraphDriver, /* The mixer that the graph mixes into during an iteration. Audio thread only. */ AudioMixer mMixer; - /* Contains the id of the audio thread id. When this changed, - * OnAudioThreadChanged is called. */ - std::atomic mAudioThreadId; - + /* Contains the id of the audio thread, from profiler_get_thread_id. */ + std::atomic mAudioThreadId; /* This allows implementing AutoInCallback. This is equal to the current * thread id when in an audio callback, and is an invalid thread id otherwise. */