mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1457427 - Improve OnThread method of AudioCallbackDriver to track the thread id of the audio thread so be more accurate. r=padenot
The class has been enhanced to store the thread id at the beginning of the callback and use it in order to compare with the current thread id when OnThread method is called. The old mechanism which includes the mInCallback flag has been removed. MozReview-Commit-ID: DWSbFQfvKzX --HG-- extra : rebase_source : e6c011da563b8f1d562ca7a394433e1e53fcffa4
This commit is contained in:
parent
10f5acd2cc
commit
7271873512
@ -540,7 +540,7 @@ AudioCallbackDriver::AudioCallbackDriver(MediaStreamGraphImpl* aGraphImpl)
|
||||
, mStarted(false)
|
||||
, mAudioInput(nullptr)
|
||||
, mAddedMixer(false)
|
||||
, mInCallback(false)
|
||||
, mAudioThreadId(std::thread::id())
|
||||
, mMicrophoneActive(false)
|
||||
, mShouldFallbackIfError(false)
|
||||
, mFromFallback(false)
|
||||
@ -863,18 +863,14 @@ AudioCallbackDriver::DeviceChangedCallback_s(void* aUser)
|
||||
driver->DeviceChangedCallback();
|
||||
}
|
||||
|
||||
bool AudioCallbackDriver::InCallback() {
|
||||
return mInCallback;
|
||||
}
|
||||
|
||||
AudioCallbackDriver::AutoInCallback::AutoInCallback(AudioCallbackDriver* aDriver)
|
||||
: mDriver(aDriver)
|
||||
{
|
||||
mDriver->mInCallback = true;
|
||||
mDriver->mAudioThreadId = std::this_thread::get_id();
|
||||
}
|
||||
|
||||
AudioCallbackDriver::AutoInCallback::~AutoInCallback() {
|
||||
mDriver->mInCallback = false;
|
||||
mDriver->mAudioThreadId = std::thread::id();
|
||||
}
|
||||
|
||||
long
|
||||
@ -884,19 +880,16 @@ AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer,
|
||||
TRACE_AUDIO_CALLBACK_BUDGET(aFrames, mSampleRate);
|
||||
TRACE_AUDIO_CALLBACK();
|
||||
|
||||
#ifdef DEBUG
|
||||
AutoInCallback aic(this);
|
||||
#endif
|
||||
|
||||
// Don't add the callback until we're inited and ready
|
||||
if (!mAddedMixer) {
|
||||
mGraphImpl->mMixer.AddCallback(this);
|
||||
mAddedMixer = true;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// DebugOnly<> doesn't work here... it forces an initialization that will cause
|
||||
// mInCallback to be set back to false before we exit the statement. Do it by
|
||||
// hand instead.
|
||||
AutoInCallback aic(this);
|
||||
#endif
|
||||
|
||||
GraphTime stateComputedTime = StateComputedTime();
|
||||
if (stateComputedTime == 0) {
|
||||
MonitorAutoLock mon(mGraphImpl->GetMonitor());
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "mozilla/SharedThreadPool.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include "mozilla/audio/AudioNotificationReceiver.h"
|
||||
#endif
|
||||
@ -448,12 +450,10 @@ public:
|
||||
void* aPromise,
|
||||
dom::AudioContextOperation aOperation);
|
||||
|
||||
/**
|
||||
* Whether the audio callback is processing. This is for asserting only.
|
||||
*/
|
||||
bool InCallback();
|
||||
|
||||
bool OnThread() override { return !mStarted || InCallback(); }
|
||||
bool OnThread() override
|
||||
{
|
||||
return mAudioThreadId.load() == std::this_thread::get_id();
|
||||
}
|
||||
|
||||
/* Whether the underlying cubeb stream has been started. See comment for
|
||||
* mStarted for details. */
|
||||
@ -548,9 +548,9 @@ private:
|
||||
/* Used to queue us to add the mixer callback on first run. */
|
||||
bool mAddedMixer;
|
||||
|
||||
/* This is atomic and is set by the audio callback thread. It can be read by
|
||||
* any thread safely. */
|
||||
Atomic<bool> mInCallback;
|
||||
/* Contains the id of the audio thread for as long as the callback
|
||||
* is taking place, after that it is reseted to an invalid value. */
|
||||
std::atomic<std::thread::id> mAudioThreadId;
|
||||
/**
|
||||
* True if microphone is being used by this process. This is synchronized by
|
||||
* the graph's monitor. */
|
||||
|
Loading…
Reference in New Issue
Block a user