Bug 1259831 - Remove the auto-suspend logic for AudioContext. r=karlt

MozReview-Commit-ID: JoSMPVfbgJb
This commit is contained in:
Paul Adenot 2016-03-29 16:57:19 +02:00
Родитель 7f8f6ca509
Коммит 1011bcc2a0
3 изменённых файлов: 1 добавлений и 99 удалений

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

@ -126,15 +126,11 @@ AudioContext::AudioContext(nsPIDOMWindowInner* aWindow,
nsresult
AudioContext::Init()
{
// We skip calling SetIsOnlyNodeForContext and the creation of the
// audioChannelAgent during mDestination's constructor, because we can only
// call them after mDestination has been set up.
if (!mIsOffline) {
nsresult rv = mDestination->CreateAudioChannelAgent();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mDestination->SetIsOnlyNodeForContext(true);
}
return NS_OK;
@ -682,8 +678,7 @@ double
AudioContext::CurrentTime() const
{
MediaStream* stream = Destination()->Stream();
return stream->StreamTimeToSeconds(stream->GetCurrentTime() +
Destination()->ExtraCurrentTime());
return stream->StreamTimeToSeconds(stream->GetCurrentTime());
}
void
@ -993,13 +988,6 @@ AudioContext::RegisterNode(AudioNode* aNode)
{
MOZ_ASSERT(!mAllNodes.Contains(aNode));
mAllNodes.PutEntry(aNode);
// mDestinationNode may be null when we're destroying nodes unlinked by CC.
// Skipping unnecessary calls after shutdown avoids RunInStableState events
// getting stuck in CycleCollectedJSRuntime during final cycle collection
// (bug 1200514).
if (mDestination && !mIsShutDown) {
mDestination->SetIsOnlyNodeForContext(mAllNodes.Count() == 1);
}
}
void
@ -1007,10 +995,6 @@ AudioContext::UnregisterNode(AudioNode* aNode)
{
MOZ_ASSERT(mAllNodes.Contains(aNode));
mAllNodes.RemoveEntry(aNode);
// mDestinationNode may be null when we're destroying nodes unlinked by CC
if (mDestination) {
mDestination->SetIsOnlyNodeForContext(mAllNodes.Count() == 1);
}
}
JSObject*

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

@ -332,8 +332,6 @@ AudioDestinationNode::AudioDestinationNode(AudioContext* aContext,
, mAudioChannel(AudioChannel::Normal)
, mIsOffline(aIsOffline)
, mAudioChannelAgentPlaying(false)
, mExtraCurrentTimeSinceLastStartedBlocking(0)
, mExtraCurrentTimeUpdatedSinceLastStableState(false)
, mCaptured(false)
{
MediaStreamGraph* graph = aIsOffline ?
@ -648,73 +646,6 @@ AudioDestinationNode::CreateAudioChannelAgent()
return NS_OK;
}
void
AudioDestinationNode::NotifyStableState()
{
mExtraCurrentTimeUpdatedSinceLastStableState = false;
}
void
AudioDestinationNode::ScheduleStableStateNotification()
{
// Dispatch will fail if this is called on AudioNode destruction during
// shutdown, in which case failure can be ignored.
nsContentUtils::RunInStableState(NewRunnableMethod(this,
&AudioDestinationNode::NotifyStableState));
}
StreamTime
AudioDestinationNode::ExtraCurrentTime()
{
if (!mStartedBlockingDueToBeingOnlyNode.IsNull() &&
!mExtraCurrentTimeUpdatedSinceLastStableState) {
mExtraCurrentTimeUpdatedSinceLastStableState = true;
// Round to nearest processing block.
double seconds =
(TimeStamp::Now() - mStartedBlockingDueToBeingOnlyNode).ToSeconds();
mExtraCurrentTimeSinceLastStartedBlocking = WEBAUDIO_BLOCK_SIZE *
StreamTime(seconds * Context()->SampleRate() / WEBAUDIO_BLOCK_SIZE + 0.5);
ScheduleStableStateNotification();
}
return mExtraCurrentTimeSinceLastStartedBlocking;
}
void
AudioDestinationNode::SetIsOnlyNodeForContext(bool aIsOnlyNode)
{
if (!mStartedBlockingDueToBeingOnlyNode.IsNull() == aIsOnlyNode) {
// Nothing changed.
return;
}
if (!mStream) {
// DestroyMediaStream has been called, presumably during CC Unlink().
return;
}
if (mIsOffline) {
// Don't block the destination stream for offline AudioContexts, since
// we expect the zero data produced when there are no other nodes to
// show up in its result buffer. Also, we would get confused by adding
// ExtraCurrentTime before StartRendering has even been called.
return;
}
if (aIsOnlyNode) {
mStream->Suspend();
mStartedBlockingDueToBeingOnlyNode = TimeStamp::Now();
// Don't do an update of mExtraCurrentTimeSinceLastStartedBlocking until the next stable state.
mExtraCurrentTimeUpdatedSinceLastStableState = true;
ScheduleStableStateNotification();
} else {
// Force update of mExtraCurrentTimeSinceLastStartedBlocking if necessary
ExtraCurrentTime();
mStream->AdvanceAndResume(mExtraCurrentTimeSinceLastStartedBlocking);
mExtraCurrentTimeSinceLastStartedBlocking = 0;
mStartedBlockingDueToBeingOnlyNode = TimeStamp();
}
}
void
AudioDestinationNode::InputMuted(bool aMuted)
{

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

@ -65,13 +65,6 @@ public:
void NotifyMainThreadStreamFinished() override;
void FireOfflineCompletionEvent();
// An amount that should be added to the MediaStream's current time to
// get the AudioContext.currentTime.
StreamTime ExtraCurrentTime();
// When aIsOnlyNode is true, this is the only node for the AudioContext.
void SetIsOnlyNodeForContext(bool aIsOnlyNode);
nsresult CreateAudioChannelAgent();
void DestroyAudioChannelAgent();
@ -101,9 +94,6 @@ private:
void SetCanPlay(float aVolume, bool aMuted);
void NotifyStableState();
void ScheduleStableStateNotification();
SelfReference<AudioDestinationNode> mOfflineRenderingRef;
uint32_t mFramesToProduce;
@ -117,9 +107,6 @@ private:
bool mIsOffline;
bool mAudioChannelAgentPlaying;
TimeStamp mStartedBlockingDueToBeingOnlyNode;
StreamTime mExtraCurrentTimeSinceLastStartedBlocking;
bool mExtraCurrentTimeUpdatedSinceLastStableState;
bool mCaptured;
};