||ContainerWriter packs encoded track data into a specific media container.
||MediaEncoder is the framework of encoding module, it controls and manages
procedures between ContainerWriter and TrackEncoder. ContainerWriter packs
the encoded track data with a specific container (e.g. ogg, webm).
AudioTrackEncoder and VideoTrackEncoder are subclasses of TrackEncoder, and
are responsible for encoding raw data coming from MediaTrackGraph.
MediaEncoder solves threading issues by doing message passing to a TaskQueue
(the "encoder thread") as passed in to the constructor. Each
MediaStreamTrack to be recorded is set up with a MediaTrackListener.
Typically there are a non-direct track listeners for audio, direct listeners
for video, and there is always a non-direct listener on each track for
time-keeping. The listeners forward data to their corresponding TrackEncoders
on the encoder thread.
The MediaEncoder listens to events from all TrackEncoders, and in turn
signals events to interested parties. Typically a MediaRecorder::Session.
The event that there's data available in the TrackEncoders is what typically
drives the extraction and muxing of data.
MediaEncoder is designed to be a passive component, neither does it own or is
in charge of managing threads. Instead this is done by its owner.
For example, usage from MediaRecorder of this component would be:
1) Create an encoder with a valid MIME type.
=> encoder = MediaEncoder::CreateEncoder(aMIMEType);
It then creates a ContainerWriter according to the MIME type
2) Connect a MediaEncoderListener to be notified when the MediaEncoder has
been initialized and when there's data available.
3) Connect the sources to be recorded. Either through:
These should not be mixed. When connecting MediaStreamTracks there is
support for at most one of each kind.
4) When the MediaEncoderListener is notified that the MediaEncoder has
data available, we can encode data. This also encodes metadata on its
5) To stop encoding, there are multiple options:
5.1) Stop() for a graceful stop.
5.2) Cancel() for an immediate stop, if you don't need the data currently
5.3) When all input tracks end, the MediaEncoder will automatically stop
and shut down.
||Get the samplerate of the data to be fed to the Opus encoder. This might be
different from the input samplerate if resampling occurs.
||Called when the TrackEncoder's underlying encoder has been successfully
initialized and there's non-null data ready to be encoded.
||VP8TrackEncoder implements VideoTrackEncoder by using the libvpx library.
We implement a realtime and variable frame rate encoder. In order to achieve
that, there is a frame-drop encoding policy implemented in GetEncodedTrack.