Open Bug 1239135 Opened 9 years ago Updated 2 years ago

Allow sending MediaStreamGraph control messages from off-mainthread

Categories

(Core :: Audio/Video: MediaStreamGraph, defect, P3)

defect

Tracking

()

Tracking Status
firefox46 --- affected

People

(Reporter: jesup, Unassigned)

Details

The MSG AppendMessage() is MainThread only, so to interact with MediaStreamGraph you have to often send a runnable to MainThread (and deal with UI/JS/etc jank). This is both annoying and hurts quality by delaying realtime actions. It should be possible to send control messages from any thread.
Right - I wanted to send it messages from the MediaManager thread (getUserMedia/etc)
Rank: 25
Priority: -- → P2
A short-term solution is to make MediaStreamGraphImpl::AppendMessage doing DispatchToMainThread instead of "MOZ_ASSERT(NS_IsMainThread(), "main thread only")"; Is that good enough?
I think the reason for the main thread limitation is that it provides stable state which allows changes to MSG happen in an indivisible fashion. Doing DispatchToMainThread internally will not provide this batch effect.
Well, my personal thought is that my doing DispatchToMainThread is not really different than someone else doing it. However, if you want to submit multiple messages one could do that from MainThread and they'd be batched up for MSG to process in one iteration (presuming this batching is handled via RunInStableState). So code that cares about batching would need to not run from other threads. Code that *doesn't* care about batching can run anywhere. There is another way to address this, which is to be explicit about what commands need to be synchronized - much as we have a 'queued' option to AddTrack and FinishAddTrack(). For commands, we could have a StartMessageGroup()/EndMessageGroup() option - but then we have to be able to reliably scope the grouping, which may be a pain. We could decide that grouping only applies to MainThread calls. Or provide a clearly-delineated off-main-thread-allowed call, but the problem is that the API generally hides the AppendMessage calls from the calling code, just exposing "AddTrack" etc. We could add an ForwardMessages() call to tell it forwarding is allowed, or default to forwarding off mainthread, with explicit StartMessageGroup/EndMessageGroup for use off-main-thread (for the rare case where we care) Alternatively, we could look at revising the entire way this works to try to reduce the reliance on MainThread as a synchronizing aspect except where it comes to syncing with JS state (in both directions). Perhaps my last proposal in the previous paragraph is best (allow, and allow off-main-thread code to explicitly group).
AbstractThread employs a tail dispatcher to provide run-to-completion which doesn't require explicit BeginTransaction/EndTransaction pairs to group messages. This might be something to consider about.
Mass change P2->P3 to align with new Mozilla triage process.
Priority: P2 → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.