Bug 1241499 - Initialize the HRTF database lazily. r=karlt

--HG--
extra : commitid : CR6URDULVd6
This commit is contained in:
Paul Adenot 2016-01-21 16:15:57 +01:00
parent ccede1b3ba
commit 6190ea3fb0
2 changed files with 26 additions and 7 deletions

View File

@ -62,10 +62,18 @@ public:
, mListenerSpeedOfSound(0.)
, mLeftOverData(INT_MIN)
{
}
void CreateHRTFPanner()
{
MOZ_ASSERT(NS_IsMainThread());
if (mHRTFPanner) {
return;
}
// HRTFDatabaseLoader needs to be fetched on the main thread.
already_AddRefed<HRTFDatabaseLoader> loader =
HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(aNode->Context()->SampleRate());
mHRTFPanner = new HRTFPanner(aNode->Context()->SampleRate(), Move(loader));
HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(NodeMainThread()->Context()->SampleRate());
mHRTFPanner = new HRTFPanner(NodeMainThread()->Context()->SampleRate(), Move(loader));
}
void SetInt32Parameter(uint32_t aIndex, int32_t aParam) override
@ -206,6 +214,9 @@ public:
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
// This member is set on the main thread, but is not accessed on the rendering
// thread untile mPanningModelFunction has changed, and this happens strictly
// later, via a MediaStreamGraph ControlMessage.
nsAutoPtr<HRTFPanner> mHRTFPanner;
typedef void (PannerNodeEngine::*PanningModelFunction)(const AudioBlock& aInput, AudioBlock* aOutput);
PanningModelFunction mPanningModelFunction;
@ -261,6 +272,18 @@ PannerNode::~PannerNode()
}
}
void PannerNode::SetPanningModel(PanningModelType aPanningModel)
{
mPanningModel = aPanningModel;
if (mPanningModel == PanningModelType::HRTF) {
// We can set the engine's `mHRTFPanner` member here from the main thread,
// because the engine will not touch it from the MediaStreamGraph
// thread until the PANNING_MODEL message sent below is received.
static_cast<PannerNodeEngine*>(mStream->Engine())->CreateHRTFPanner();
}
SendInt32ParameterToStream(PANNING_MODEL, int32_t(mPanningModel));
}
size_t
PannerNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{

View File

@ -56,11 +56,7 @@ public:
{
return mPanningModel;
}
void SetPanningModel(PanningModelType aPanningModel)
{
mPanningModel = aPanningModel;
SendInt32ParameterToStream(PANNING_MODEL, int32_t(mPanningModel));
}
void SetPanningModel(PanningModelType aPanningModel);
DistanceModelType DistanceModel() const
{