Name Description Size
ContainerWriter.h ContainerWriter packs encoded track data into a specific media container. 2619
EncodedFrame.h 2206
MediaEncoder.cpp 37460
MediaEncoder.h MediaEncoder is the framework of encoding module, it controls and manages procedures between Muxer, ContainerWriter and TrackEncoder. ContainerWriter writes the encoded track data into a specific container (e.g. ogg, webm). AudioTrackEncoder and VideoTrackEncoder are subclasses of TrackEncoder, and are responsible for encoding raw data coming from MediaStreamTracks. 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 MediaEncoder automatically encodes incoming data, muxes it, writes it into a container and stores the container data into a MutableBlobStorage. It is timeslice-aware so that it can notify listeners when it's time to expose a blob due to filling the timeslice. 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. Note that there are more configuration options, see the docs on MediaEncoder::CreateEncoder. => encoder = MediaEncoder::CreateEncoder(aMIMEType); It then creates track encoders and the appropriate ContainerWriter according to the MIME type 2) Connect handlers through MediaEventListeners to the MediaEncoder's MediaEventSources, StartedEvent(), DataAvailableEvent(), ErrorEvent() and ShutdownEvent(). => listener = encoder->DataAvailableEvent().Connect(mainThread, &OnBlob); 3) Connect the sources to be recorded. Either through: => encoder->ConnectAudioNode(node); or => encoder->ConnectMediaStreamTrack(track); These should not be mixed. When connecting MediaStreamTracks there is support for at most one of each kind. 4) MediaEncoder automatically encodes data from the connected tracks, muxes them and writes it all into a blob, including metadata. When the blob contains at least `timeslice` worth of data it notifies the DataAvailableEvent that was connected in step 2. => void OnBlob(RefPtr<BlobImpl> aBlob) { => DispatchBlobEvent(Blob::Create(GetOwnerGlobal(), aBlob)); => }; 5) To stop encoding, there are multiple options: 5.1) Stop() for a graceful stop. => encoder->Stop(); 5.2) Cancel() for an immediate stop, if you don't need the data currently buffered. => encoder->Cancel(); 5.3) When all input tracks end, the MediaEncoder will automatically stop and shut down. 14550
moz.build 1159
Muxer.cpp 6568
Muxer.h 2583
OpusTrackEncoder.cpp 16398
OpusTrackEncoder.h The encoder lookahead at 48k rate. 3215
TrackEncoder.cpp 26561
TrackEncoder.h Called when the TrackEncoder has received its first real data. 15231
TrackMetadataBase.h 2495
VP8TrackEncoder.cpp std::min(10U, mKeyFrameInterval / 200) 25145
VP8TrackEncoder.h 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 Encode(). 5794