Bug 1360334 - Improve error handling. r=padenot

MozReview-Commit-ID: 5tIXzzisg0V

--HG--
extra : source : 0dc85355af3d166038ccf6e0fd161bd614b0ead2
This commit is contained in:
Andreas Pehrson 2017-09-08 16:41:36 +02:00
Родитель 24e13c5d2e
Коммит 3e7a54981e
2 изменённых файлов: 37 добавлений и 10 удалений

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

@ -35,7 +35,8 @@ GraphDriver::GraphDriver(MediaStreamGraphImpl* aGraphImpl)
mWaitState(WAITSTATE_RUNNING),
mCurrentTimeStamp(TimeStamp::Now()),
mPreviousDriver(nullptr),
mNextDriver(nullptr)
mNextDriver(nullptr),
mScheduled(false)
{ }
void GraphDriver::SetGraphTime(GraphDriver* aPreviousDriver,
@ -135,6 +136,12 @@ void GraphDriver::SetPreviousDriver(GraphDriver* aPreviousDriver)
mPreviousDriver = aPreviousDriver;
}
bool GraphDriver::Scheduled()
{
GraphImpl()->GetMonitor().AssertCurrentThreadOwns();
return mScheduled;
}
ThreadedDriver::ThreadedDriver(MediaStreamGraphImpl* aGraphImpl)
: GraphDriver(aGraphImpl)
{ }
@ -181,7 +188,7 @@ public:
LOG(LogLevel::Debug,
("Starting a new system driver for graph %p", mDriver->mGraphImpl));
GraphDriver* previousDriver = nullptr;
RefPtr<GraphDriver> previousDriver;
{
MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
previousDriver = mDriver->PreviousDriver();
@ -190,7 +197,7 @@ public:
LOG(LogLevel::Debug,
("%p releasing an AudioCallbackDriver(%p), for graph %p",
mDriver.get(),
previousDriver,
previousDriver.get(),
mDriver->GraphImpl()));
MOZ_ASSERT(!mDriver->AsAudioCallbackDriver());
RefPtr<AsyncCubebTask> releaseEvent =
@ -224,7 +231,8 @@ ThreadedDriver::Start()
// Note: mThread may be null during event->Run() if we pass to NewNamedThread! See AudioInitTask
nsresult rv = NS_NewNamedThread("MediaStreamGrph", getter_AddRefs(mThread));
if (NS_SUCCEEDED(rv)) {
mThread->EventTarget()->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
rv = mThread->EventTarget()->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
mScheduled = NS_SUCCEEDED(rv);
}
}
}
@ -796,7 +804,8 @@ AudioCallbackDriver::Start()
"to ensure it runs after previous shutdown."));
RefPtr<AsyncCubebTask> initEvent =
new AsyncCubebTask(AsAudioCallbackDriver(), AsyncCubebOperation::INIT);
initEvent->Dispatch();
nsresult rv = initEvent->Dispatch();
mScheduled = NS_SUCCEEDED(rv);
}
bool
@ -1069,13 +1078,25 @@ void
AudioCallbackDriver::StateCallback(cubeb_state aState)
{
LOG(LogLevel::Debug, ("AudioCallbackDriver State: %d", aState));
// If we don't have an audio stream here, this means that the stream
// initialization has failed. A fallback on a SystemCallDriver will happen at
// the callsite of `cubeb_stream_init`.
if (aState == CUBEB_STATE_ERROR && mAudioStream) {
if (aState == CUBEB_STATE_ERROR) {
if (!mAudioStream) {
// If we don't have an audio stream here, this means that the stream
// initialization has failed. A fallback on a SystemCallDriver will happen at
// the callsite of `cubeb_stream_init`.
return;
}
MonitorAutoLock lock(GraphImpl()->GetMonitor());
if (NextDriver() && NextDriver()->Scheduled()) {
// We are switching to another driver that has already been scheduled
// to be initialized and started. There's nothing for us to do here.
return;
}
// Fall back to a driver using a normal thread. If needed,
// the graph will try to re-open an audio stream later.
MonitorAutoLock lock(GraphImpl()->GetMonitor());
SystemClockDriver* nextDriver = new SystemClockDriver(GraphImpl());
SetNextDriver(nextDriver);
RemoveCallback();

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

@ -150,6 +150,9 @@ public:
void SetNextDriver(GraphDriver* aNextDriver);
void SetPreviousDriver(GraphDriver* aPreviousDriver);
/* Return whether we have been scheduled to start. */
bool Scheduled();
/**
* If we are running a real time graph, get the current time stamp to schedule
* video frames. This has to be reimplemented by real time drivers.
@ -253,6 +256,9 @@ protected:
// driver at the end of this iteration.
// This must be accessed using the {Set,Get}NextDriver methods.
RefPtr<GraphDriver> mNextDriver;
// This is initially false, but set to true as soon the driver has been
// scheduled to start through GraphDriver::Start().
bool mScheduled;
virtual ~GraphDriver()
{ }
};