b=923301 add MediaStreamGraph::RunAfterPendingUpdates() r=roc

--HG--
extra : transplant_source : %89%21%AE%87%C7%9C%07%28%3D%60T%83%16n%DC%C9O%87iy
This commit is contained in:
Karl Tomlinson 2013-10-25 12:07:29 +13:00
parent 3d4ea8ba0a
commit 139a3037ef
3 changed files with 50 additions and 2 deletions

View File

@ -1919,6 +1919,40 @@ MediaStream::RemoveListener(MediaStreamListener* aListener)
}
}
void
MediaStream::RunAfterPendingUpdates(nsRefPtr<nsIRunnable> aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
MediaStreamGraphImpl* graph = GraphImpl();
// Special case when a non-realtime graph has not started, to ensure the
// runnable will run in finite time.
if (!(graph->mRealtime || graph->mNonRealtimeProcessing)) {
aRunnable->Run();
}
class Message : public ControlMessage {
public:
explicit Message(MediaStream* aStream,
already_AddRefed<nsIRunnable> aRunnable)
: ControlMessage(aStream)
, mRunnable(aRunnable) {}
virtual void Run() MOZ_OVERRIDE
{
mStream->Graph()->
DispatchToMainThreadAfterStreamStateUpdate(mRunnable.forget());
}
virtual void RunDuringShutdown() MOZ_OVERRIDE
{
mRunnable->Run();
}
private:
nsRefPtr<nsIRunnable> mRunnable;
};
graph->AppendMessage(new Message(this, aRunnable.forget()));
}
void
MediaStream::SetTrackEnabledImpl(TrackID aTrackID, bool aEnabled)
{

View File

@ -346,6 +346,20 @@ public:
NS_ASSERTION(NS_IsMainThread(), "Call only on main thread");
mMainThreadListeners.RemoveElement(aListener);
}
/**
* Ensure a runnable will run on the main thread after running all pending
* updates that were sent from the graph thread or will be sent before the
* graph thread receives the next graph update.
*
* If the graph has been shutdown or destroyed, or if it is non-realtime
* and has not started, then the runnable will be run
* synchronously/immediately. (There are no pending updates in these
* situations.)
*
* Main thread only.
*/
void RunAfterPendingUpdates(nsRefPtr<nsIRunnable> aRunnable);
// Signal that the client is done with this MediaStream. It will be deleted later.
virtual void Destroy();
// Returns the main-thread's view of how much data has been processed by

View File

@ -72,11 +72,11 @@ struct StreamUpdate {
/**
* This represents a message passed from the main thread to the graph thread.
* A ControlMessage always references a particular affected stream.
* A ControlMessage always has a weak reference a particular affected stream.
*/
class ControlMessage {
public:
ControlMessage(MediaStream* aStream) : mStream(aStream)
explicit ControlMessage(MediaStream* aStream) : mStream(aStream)
{
MOZ_COUNT_CTOR(ControlMessage);
}