1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_GraphRunner_h
8 #define mozilla_GraphRunner_h
10 #include "MediaSegment.h"
11 #include "mozilla/Monitor.h"
20 class MediaStreamGraphImpl
;
24 explicit GraphRunner(MediaStreamGraphImpl
* aGraph
);
28 * Marks us as shut down and signals mThread, so that it runs until the end.
33 * Signals one iteration of mGraph. Hands aStateEnd over to mThread and runs
34 * the iteration there.
36 bool OneIteration(GraphTime aStateEnd
);
39 * Runs mGraph until it shuts down.
44 * Returns true if called on mThread.
50 * Returns true if called on mThread, and aDriver was the driver that called
51 * OneIteration() last.
53 bool RunByGraphDriver(GraphDriver
* aDriver
);
57 // Monitor used for yielding mThread through Wait(), and scheduling mThread
58 // through Signal() from a GraphDriver.
60 // The MediaStreamGraph we're running. Weakptr beecause this graph owns us and
61 // guarantees that our lifetime will not go beyond that of itself.
62 MediaStreamGraphImpl
* const mGraph
;
63 // GraphTime being handed over to the graph through OneIteration. Protected by
66 // Reply from mGraph's OneIteration. Protected by mMonitor.
67 bool mStillProcessing
;
69 enum class ThreadState
{
70 Wait
, // Waiting for a message. This is the initial state.
71 // A transition from Run back to Wait occurs on the runner
72 // thread after it processes as far as mStateEnd and sets
74 Run
, // Set on driver thread after each mStateEnd update.
75 Shutdown
, // Set when Shutdown() is called on main thread.
77 // Protected by mMonitor until set to Shutdown, after which this is not
79 ThreadState mThreadState
;
81 // The thread running mGraph. Set on construction, after other members are
82 // initialized. Cleared at the end of Shutdown().
86 // Set to mGraph's audio callback driver's thread id, if run by an
87 // AudioCallbackDriver, while OneIteration() is running.
88 std::thread::id mAudioDriverThreadId
= std::thread::id();
89 // Set to mGraph's system clock driver's thread, if run by a
90 // SystemClockDriver, while OneIteration() is running.
91 nsIThread
* mClockDriverThread
= nullptr;
95 } // namespace mozilla