зеркало из https://github.com/mozilla/gecko-dev.git
Bug 836599 - Part 8: Add a non-realtime media graph API to produce a given number of ticks; r=roc
This commit is contained in:
Родитель
23bebc9642
Коммит
8d5f66955c
|
@ -953,6 +953,15 @@ MediaStreamGraphImpl::RunThread()
|
|||
NS_ASSERTION(!messageQueue.IsEmpty(),
|
||||
"Shouldn't have started a graph with empty message queue!");
|
||||
|
||||
uint32_t ticksProcessed = 0;
|
||||
if (!mRealtime) {
|
||||
NS_ASSERTION(!mNonRealtimeIsRunning,
|
||||
"We should not be running in non-realtime mode already");
|
||||
NS_ASSERTION(mNonRealtimeTicksToProcess,
|
||||
"We should have a non-zero number of ticks to process");
|
||||
mNonRealtimeIsRunning = true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
// Update mCurrentTime to the min of the playing audio times, or using the
|
||||
// wall-clock time change if no audio is playing.
|
||||
|
@ -1032,6 +1041,13 @@ MediaStreamGraphImpl::RunThread()
|
|||
allBlockedForever = false;
|
||||
}
|
||||
}
|
||||
if (!mRealtime) {
|
||||
ticksProcessed += TimeToTicksRoundDown(IdealAudioRate(), mStateComputedTime - prevComputedTime);
|
||||
// Terminate processing if we've produce enough non-realtime ticks.
|
||||
if (ticksProcessed >= mNonRealtimeTicksToProcess) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ensureNextIteration || !allBlockedForever || audioStreamsActive > 0) {
|
||||
EnsureNextIteration();
|
||||
}
|
||||
|
@ -1082,6 +1098,10 @@ MediaStreamGraphImpl::RunThread()
|
|||
messageQueue.SwapElements(mMessageQueue);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mRealtime) {
|
||||
mNonRealtimeIsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1370,7 +1390,11 @@ MediaStreamGraphImpl::AppendMessage(ControlMessage* aMessage)
|
|||
}
|
||||
|
||||
mCurrentTaskMessageQueue.AppendElement(aMessage);
|
||||
EnsureRunInStableState();
|
||||
// Do not start running the non-realtime graph unless processing has
|
||||
// explicitly started.
|
||||
if (mRealtime || mNonRealtimeProcessing) {
|
||||
EnsureRunInStableState();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1958,12 +1982,15 @@ MediaStreamGraphImpl::MediaStreamGraphImpl(bool aRealtime)
|
|||
, mMonitor("MediaStreamGraphImpl")
|
||||
, mLifecycleState(LIFECYCLE_THREAD_NOT_STARTED)
|
||||
, mWaitState(WAITSTATE_RUNNING)
|
||||
, mNonRealtimeTicksToProcess(0)
|
||||
, mNeedAnotherIteration(false)
|
||||
, mForceShutDown(false)
|
||||
, mPostedRunInStableStateEvent(false)
|
||||
, mNonRealtimeIsRunning(false)
|
||||
, mDetectedNotRunning(false)
|
||||
, mPostedRunInStableState(false)
|
||||
, mRealtime(aRealtime)
|
||||
, mNonRealtimeProcessing(false)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
if (!gMediaStreamGraphLog) {
|
||||
|
@ -2071,4 +2098,19 @@ MediaStreamGraph::CreateAudioNodeStream(AudioNodeEngine* aEngine,
|
|||
return stream;
|
||||
}
|
||||
|
||||
void
|
||||
MediaStreamGraph::StartNonRealtimeProcessing(uint32_t aTicksToProcess)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "main thread only");
|
||||
|
||||
MediaStreamGraphImpl* graph = static_cast<MediaStreamGraphImpl*>(this);
|
||||
NS_ASSERTION(!graph->mRealtime, "non-realtime only");
|
||||
|
||||
if (graph->mNonRealtimeProcessing)
|
||||
return;
|
||||
graph->mNonRealtimeTicksToProcess = aTicksToProcess;
|
||||
graph->mNonRealtimeProcessing = true;
|
||||
graph->EnsureRunInStableState();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -939,6 +939,10 @@ public:
|
|||
* in main-thread stream state.
|
||||
*/
|
||||
int64_t GetCurrentGraphUpdateIndex() { return mGraphUpdatesSent; }
|
||||
/**
|
||||
* Start processing non-realtime for a specific number of ticks.
|
||||
*/
|
||||
void StartNonRealtimeProcessing(uint32_t aTicksToProcess);
|
||||
|
||||
/**
|
||||
* Media graph thread only.
|
||||
|
|
|
@ -480,6 +480,10 @@ public:
|
|||
WAITSTATE_WAKING_UP
|
||||
};
|
||||
WaitState mWaitState;
|
||||
/**
|
||||
* How many non-realtime ticks the graph should process.
|
||||
*/
|
||||
uint32_t mNonRealtimeTicksToProcess;
|
||||
/**
|
||||
* True when another iteration of the control loop is required.
|
||||
*/
|
||||
|
@ -493,6 +497,13 @@ public:
|
|||
* RunInStableState() and the event hasn't run yet.
|
||||
*/
|
||||
bool mPostedRunInStableStateEvent;
|
||||
/**
|
||||
* True when the non-realtime graph thread is processing, as a result of
|
||||
* a request from the main thread. When processing is finished, we post
|
||||
* a message to the main thread in order to set mNonRealtimeProcessing
|
||||
* back to false.
|
||||
*/
|
||||
bool mNonRealtimeIsRunning;
|
||||
|
||||
// Main thread only
|
||||
|
||||
|
@ -519,6 +530,11 @@ public:
|
|||
* audio.
|
||||
*/
|
||||
bool mRealtime;
|
||||
/**
|
||||
* True when a non-realtime MediaStreamGraph has started to process input. This
|
||||
* value is only accessed on the main thread.
|
||||
*/
|
||||
bool mNonRealtimeProcessing;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче