Closed Bug 1650696 Opened 5 years ago Closed 5 years ago

Move threading management away from the MediaDataDecoder

Categories

(Core :: Audio/Video, enhancement, P3)

Desktop
Unspecified
enhancement

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox81 --- fixed

People

(Reporter: shravanrn, Assigned: jya)

Details

Attachments

(4 files, 1 obsolete file)

Calls to switch threads/InvokeAsync can be removed from MediaDataDecoders except for the decoders that actually requires multi-threading. Instead for single threaded decoders, the work would be done on the current thread, so the caller is expected to invoke the MediaDataDecoder functions on the right thread.

This architecture would allow for a more straightforward port for wasm sandboxed media decoders.

Flags: needinfo?(jyavenard)
Assignee: nobody → jyavenard
Flags: needinfo?(jyavenard)

Ok.

Here is the plan:

MediaDataDecoder will no longer be expected to work on a given TaskQueue; they will perform the job whereever they want it to. So for audio decoder this will typically be a sync job immediately returning a resolved promise as usual.

All the video decoders using multi-threaded framework will have to deal with thread as needed.

From an implementation point of you, it will be up to the user of the MediaDataDecoder (e.g. MediaFormatReader) to dispatch the given decoding operation on the thread/taskqueue it wants.

This will likely result in a much easier implementation for all decoders and simplify how to deal with the decoding TaskQueue life cycle.

Once upon a time, having an AbstractThread was required in order to use MozPromise; this is no longer the case.

Also, now all nsIThread support DirectTask dispatching making the need to wrap a nsIThread in a XPCOMThreadWrapper unecessary.

We probably don't need a dedicated GMPThread and could likely use a BackgroundTaskqueue instead.

It will now be up to the caller to determine where the decoder is going to run. This allows to simplify the audio decoders so that they can run synchronously and be wrapped in a Wasm sandbox (which doesn't support multi-threading)

The structure guarantees that all MediaDataDecoder methods are called on the same thread it's been initialised.

To achieve this, wherever a MediaDataDecoder was created, we wrap it in a MediaDataDemuxerProxy that ensures that all methods are running on the given thread.

We keep the behaviour of all methods in all MediaDataDecoder to assert that they are running on the expected thread for diagnostic purposes. It could go in the future.

Depends on D86928

Attachment #9169798 - Attachment description: Bug 1650696 - P4. Add missing methods to AllocationPolicy. r?jolin → Bug 1650696 - P3. Add missing methods to AllocationPolicy. r?jolin
Attachment #9169797 - Attachment description: Bug 1650696 - P3. Remove the expectation for a MediaDataDecoder to work on a specified TaskQueue. r?jolin → Bug 1650696 - P4. Remove the expectation for a MediaDataDecoder to work on a specified TaskQueue. r?jolin

Upon further thinking, I believe we should still make individual decoders behave in a way that they never block the thread on which they are called for too long. So we revert the earlier change for the video decoders and have them dispatch on their own taskqueue.

The Apple decoder is mostly entirely asynchronous, with the exception of the drain method which could block.
We exclude the android and omx decoders are the framework they use is 100% asynchronous and already operate on another thread.

Depends on D86929

Attachment #9169822 - Attachment is obsolete: true
Pushed by jyavenard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/52cfcbf99785 P1. Remove remnant of AbstractThread in EME and GMP decoders. r=jolin https://hg.mozilla.org/integration/autoland/rev/3ddc585f69cf P2. Add missing methods to MediaDataDecoderProxy. r=jolin https://hg.mozilla.org/integration/autoland/rev/aee9055c07c2 P3. Add missing methods to AllocationPolicy. r=jolin https://hg.mozilla.org/integration/autoland/rev/f7243c8b4772 P4. Remove the expectation for a MediaDataDecoder to work on a specified TaskQueue. r=jolin
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: