Bug 1646348 - Use the AudioThreadRegistry in GraphDriver.cpp. r=achronop

This patch changes the type of mAudioThreadId because `std:🧵:id` is
non-memovable and AudioThreadRegistry uses an nsTArray, that needs elements to
be memovable.

Differential Revision: https://phabricator.services.mozilla.com/D80466
This commit is contained in:
Paul Adenot 2020-06-23 16:43:40 +00:00
Родитель ddee5175d5
Коммит f2a2fb7d24
2 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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<std::thread::id> mAudioThreadId;
/* Contains the id of the audio thread, from profiler_get_thread_id. */
std::atomic<int> 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.
*/