Bug 1299515 - Signal SetPullEnabled with a message. r=padenot

With the added invariant that NotifyPull() needs a MediaStreamListener present
to not underrun, we need SetPullEnabled() and AddListener() to stay in sync by
using the same signaling mechanism.

MozReview-Commit-ID: 49KWdiTOG98

--HG--
extra : rebase_source : d0ad44d7ce431aa792c4908f96baf0c0920dbe90
This commit is contained in:
Andreas Pehrson 2018-01-03 11:59:41 +01:00
Родитель 1eb21f16e5
Коммит 2b25cd7258
3 изменённых файлов: 32 добавлений и 18 удалений

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

@ -1289,7 +1289,8 @@ public:
RefPtr<GetUserMediaStreamRunnable> self = this;
MediaManager::PostTask(NewTaskFrom([self, domStream, callback]() mutable {
MOZ_ASSERT(MediaManager::IsInMediaThread());
SourceMediaStream* source = self->mSourceListener->GetSourceStream();
RefPtr<SourceMediaStream> source =
self->mSourceListener->GetSourceStream();
RefPtr<MediaMgrError> error = nullptr;
if (self->mAudioDevice) {
@ -1334,7 +1335,6 @@ public:
// Start() queued the tracks to be added synchronously to avoid races
source->FinishAddTracks();
source->SetPullEnabled(true);
source->AdvanceKnownTracksTime(STREAM_TIME_MAX);
LOG(("started all sources"));
@ -1342,7 +1342,9 @@ public:
// onTracksAvailableCallback must be added to domStream on the main thread.
uint64_t windowID = self->mWindowID;
NS_DispatchToMainThread(NS_NewRunnableFunction("MediaManager::NotifyChromeOfStart",
[domStream, callback, windowID]() mutable {
[source, domStream, callback, windowID]() mutable {
source->SetPullEnabled(true);
MediaManager* manager = MediaManager::GetIfExists();
if (!manager) {
return;

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

@ -2730,11 +2730,22 @@ SourceMediaStream::DestroyImpl()
void
SourceMediaStream::SetPullEnabled(bool aEnabled)
{
MutexAutoLock lock(mMutex);
mPullEnabled = aEnabled;
if (mPullEnabled && GraphImpl()) {
GraphImpl()->EnsureNextIteration();
}
class Message : public ControlMessage {
public:
Message(SourceMediaStream* aStream, bool aEnabled)
: ControlMessage(nullptr)
, mStream(aStream)
, mEnabled(aEnabled)
{}
void Run() override
{
MutexAutoLock lock(mStream->mMutex);
mStream->mPullEnabled = mEnabled;
}
SourceMediaStream* mStream;
bool mEnabled;
};
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aEnabled));
}
bool

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

@ -676,7 +676,16 @@ public:
SourceMediaStream* AsSourceStream() override { return this; }
// Media graph thread only
// Main thread only
/**
* Enable or disable pulling. When pulling is enabled, NotifyPull
* gets called on MediaStreamListeners for this stream during the
* MediaStreamGraph control loop. Pulling is initially disabled.
* Due to unavoidable race conditions, after a call to SetPullEnabled(false)
* it is still possible for a NotifyPull to occur.
*/
void SetPullEnabled(bool aEnabled);
// Users of audio inputs go through the stream so it can track when the
// last stream referencing an input goes away, so it can close the cubeb
@ -687,18 +696,10 @@ public:
// Note: also implied when Destroy() happens
void CloseAudioInput();
// MediaStreamGraph thread only
void DestroyImpl() override;
// Call these on any thread.
/**
* Enable or disable pulling. When pulling is enabled, NotifyPull
* gets called on MediaStreamListeners for this stream during the
* MediaStreamGraph control loop. Pulling is initially disabled.
* Due to unavoidable race conditions, after a call to SetPullEnabled(false)
* it is still possible for a NotifyPull to occur.
*/
void SetPullEnabled(bool aEnabled);
/**
* Call all MediaStreamListeners to request new data via the NotifyPull API
* (if enabled).