gecko-dev/dom/media/GraphRunner.cpp
Andreas Pehrson 1bdb34c6ec Bug 1454998 - Rename streams to tracks. r=padenot,karlt,smaug
This renames the following (in alphabetical order, non-exhaustive):

AudioCaptureStream -> AudioCaptureTrack
AudioNodeStream -> AudioNodeTrack
AudioNodeExternalInputStream -> AudioNodeExternalInputTrack
DirectMediaStreamTrackListener -> DirectMediaTrackListener
MediaStream -> MediaTrack
  - Note that there's also dom::MediaTrack. Namespaces differentiate them.
MediaStreamGraph -> MediaTrackGraph
MediaStreamTrackListener -> MediaTrackListener
MSG -> MTG (in comments)
ProcessedMediaStream -> ProcessedMediaTrack
SharedDummyStream -> SharedDummyTrack
SourceMediaStream -> SourceMediaTrack
StreamTime -> TrackTime
TrackUnionStream -> ForwardedInputTrack
  - Because this no longer takes a union of anything, but only a single track
    as input.

Other minor classes, members and comments have been updated to reflect these
name changes.

Differential Revision: https://phabricator.services.mozilla.com/D46146

--HG--
rename : dom/media/AudioCaptureStream.cpp => dom/media/AudioCaptureTrack.cpp
rename : dom/media/AudioCaptureStream.h => dom/media/AudioCaptureTrack.h
rename : dom/media/TrackUnionStream.cpp => dom/media/ForwardedInputTrack.cpp
rename : dom/media/TrackUnionStream.h => dom/media/ForwardedInputTrack.h
rename : dom/media/MediaStreamGraph.cpp => dom/media/MediaTrackGraph.cpp
rename : dom/media/MediaStreamGraph.h => dom/media/MediaTrackGraph.h
rename : dom/media/MediaStreamGraphImpl.h => dom/media/MediaTrackGraphImpl.h
rename : dom/media/MediaStreamListener.cpp => dom/media/MediaTrackListener.cpp
rename : dom/media/MediaStreamListener.h => dom/media/MediaTrackListener.h
rename : dom/media/webaudio/AudioNodeExternalInputStream.cpp => dom/media/webaudio/AudioNodeExternalInputTrack.cpp
rename : dom/media/webaudio/AudioNodeExternalInputStream.h => dom/media/webaudio/AudioNodeExternalInputTrack.h
rename : dom/media/webaudio/AudioNodeStream.cpp => dom/media/webaudio/AudioNodeTrack.cpp
rename : dom/media/webaudio/AudioNodeStream.h => dom/media/webaudio/AudioNodeTrack.h
extra : moz-landing-system : lando
2019-10-02 10:23:02 +00:00

142 lines
4.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "GraphRunner.h"
#include "GraphDriver.h"
#include "MediaTrackGraph.h"
#include "MediaTrackGraphImpl.h"
#include "mozilla/dom/WorkletThread.h"
#include "nsISupportsImpl.h"
#include "prthread.h"
#include "Tracing.h"
#include "audio_thread_priority.h"
namespace mozilla {
static void Start(void* aArg) {
NS_SetCurrentThreadName("GraphRunner");
GraphRunner* th = static_cast<GraphRunner*>(aArg);
th->Run();
}
GraphRunner::GraphRunner(MediaTrackGraphImpl* aGraph)
: mMonitor("GraphRunner::mMonitor"),
mGraph(aGraph),
mStateEnd(0),
mStillProcessing(true),
mThreadState(ThreadState::Wait),
// Note that mThread needs to be initialized last, as it may pre-empt the
// thread running this ctor and enter Run() with uninitialized members.
mThread(PR_CreateThread(PR_SYSTEM_THREAD, &Start, this,
PR_PRIORITY_URGENT, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0)) {
MOZ_COUNT_CTOR(GraphRunner);
}
GraphRunner::~GraphRunner() {
MOZ_COUNT_DTOR(GraphRunner);
MOZ_ASSERT(mThreadState == ThreadState::Shutdown);
}
void GraphRunner::Shutdown() {
{
MonitorAutoLock lock(mMonitor);
MOZ_ASSERT(mThreadState == ThreadState::Wait);
mThreadState = ThreadState::Shutdown;
mMonitor.Notify();
}
// We need to wait for runner thread shutdown here for the sake of the
// xpcomWillShutdown case, so that the main thread is not shut down before
// cleanup messages are sent for objects destroyed in
// CycleCollectedJSContext shutdown.
PR_JoinThread(mThread);
mThread = nullptr;
}
bool GraphRunner::OneIteration(GraphTime aStateEnd) {
TRACE_AUDIO_CALLBACK();
MonitorAutoLock lock(mMonitor);
MOZ_ASSERT(mThreadState == ThreadState::Wait);
mStateEnd = aStateEnd;
#ifdef DEBUG
if (auto audioDriver = mGraph->CurrentDriver()->AsAudioCallbackDriver()) {
mAudioDriverThreadId = audioDriver->ThreadId();
} else if (auto clockDriver =
mGraph->CurrentDriver()->AsSystemClockDriver()) {
mClockDriverThread = clockDriver->Thread();
} else {
MOZ_CRASH("Unknown GraphDriver");
}
#endif
// Signal that mStateEnd was updated
mThreadState = ThreadState::Run;
mMonitor.Notify();
// Wait for mStillProcessing to update
do {
mMonitor.Wait();
} while (mThreadState == ThreadState::Run);
#ifdef DEBUG
mAudioDriverThreadId = std::thread::id();
mClockDriverThread = nullptr;
#endif
return mStillProcessing;
}
void GraphRunner::Run() {
PR_SetCurrentThreadName("GraphRunner");
atp_handle* handle =
atp_promote_current_thread_to_real_time(0, mGraph->GraphRate());
MonitorAutoLock lock(mMonitor);
while (true) {
while (mThreadState == ThreadState::Wait) {
mMonitor.Wait(); // Wait for mStateEnd to update or for shutdown
}
if (mThreadState == ThreadState::Shutdown) {
break;
}
TRACE();
mStillProcessing = mGraph->OneIterationImpl(mStateEnd);
// Signal that mStillProcessing was updated
mThreadState = ThreadState::Wait;
mMonitor.Notify();
}
if (handle) {
atp_demote_current_thread_from_real_time(handle);
}
dom::WorkletThread::DeleteCycleCollectedJSContext();
}
bool GraphRunner::OnThread() { return PR_GetCurrentThread() == mThread; }
#ifdef DEBUG
bool GraphRunner::RunByGraphDriver(GraphDriver* aDriver) {
if (!OnThread()) {
return false;
}
if (auto audioDriver = aDriver->AsAudioCallbackDriver()) {
return audioDriver->ThreadId() == mAudioDriverThreadId;
}
if (auto clockDriver = aDriver->AsSystemClockDriver()) {
return clockDriver->Thread() == mClockDriverThread;
}
MOZ_CRASH("Unknown driver");
}
#endif
} // namespace mozilla