Media
The engine is a transport. It negotiates codecs, carries RTP and RTCP over SRTP and runs the RTCP session; encoding, decoding, capture and playout are the application's.
Add a track
use rtci::media_stream::MediaStreamTrack;
use rtci::peer_connection::RTCPeerConnection;
use rtci::rtp_transceiver::RTCRtpSenderId;
use rtci::rtp_transceiver::rtp_sender::{
RTCRtpCodec, RTCRtpCodingParameters, RTCRtpEncodingParameters, RtpCodecKind,
};
fn add_video(
pc: &mut RTCPeerConnection,
ssrc: u32,
) -> Result<RTCRtpSenderId, Box<dyn std::error::Error>> {
let track = MediaStreamTrack::new(
"stream-id".to_string(),
"track-id".to_string(),
"Camera".to_string(),
RtpCodecKind::Video,
vec![RTCRtpEncodingParameters {
rtp_coding_parameters: RTCRtpCodingParameters {
ssrc: Some(ssrc),
..Default::default()
},
codec: RTCRtpCodec::default(),
..Default::default()
}],
);
Ok(pc.add_track(track)?)
}
From README.md, “Media Tracks” at v0.5.0.
add_track returns an RTCRtpSenderId; rtp_sender(id) gives the sender, rtp_receiver(id) a receiver, and get_senders(), get_receivers() and get_transceivers() list them. add_transceiver_from_kind and add_transceiver_from_track add a transceiver the W3C way, and remove_track(sender_id) removes one.
Sending: you write RTP
The engine does not encode: the application writes RTP with RTCRtpSender::write_rtp(now, packet). What it sends is the codec negotiated for the sender, the first media codec of RTCRtpSender::get_parameters().rtp_parameters.codecs, with that codec's payload type (the remote description's number, RFC 3264 section 5.1). A remote description changes it, so after applying an answer (or, when answering, an offer) read it again and encode that codec.
A packet written with a payload type that is not negotiated is sent with the negotiated one: write_rtp rewrites the number, never the payload. Each rewrite is counted: RTCRtpSender::rewritten_payload_type_rtp_packets() (every rewrite) and RTCRtpSender::rewritten_from_another_codec_rtp_packets() (the written number names a different format), summed on the connection by the RTCPeerConnection methods of the same names. An application's tests can assert the second stays 0.
The sender also has write_rtp_with_capture_time, write_rtp_with_audio_level and write_rtp_with_video_orientation (the header extensions those name), replace_track, set_parameters and, with the default interceptors, target_bitrates(): the congestion controller's target per encoding, for your encoder (Congestion control).
Receiving
Inbound RTP and RTCP arrive from poll_read() as RTCMessage::RtpPacket(track_id, packet) and RTCMessage::RtcpPacket(receiver_id, packets); a new remote track is RTCPeerConnectionEvent::OnTrack(RTCTrackEvent::OnOpen(init)). The engine's RTCP session takes sender and receiver reports in itself: they do not reach poll_read, and their figures appear in the statistics instead. Inbound key-frame requests (PLI, FIR) are OnKeyFrameRequest events.
Codecs
MediaEngine::register_default_codecs() registers the default codecs; the media engine's MIME constants name what it knows: Opus, G.722, PCMU, PCMA, VP8, VP9, H.264, H.265, AV1, RTX, FlexFEC (RFC 8627 and draft-03), ULPFEC, RED, telephone-event, comfort noise and SMPTE 336M (see the media_engine module). An application registers others with MediaEngine::register_codec. Payload types are negotiated.
Simulcast and SVC
RID-based simulcast is implemented, sending and receiving. rtci-rtp has the SVC signalling: the W3C scalability modes and their layer structures, VP8 / VP9 layer descriptors, the AV1 Dependency Descriptor and forwarder-side layer selectors (scalabilityMode on an encoding, RTCRtpSender::set_configured_scalability_mode). The repository's simulcast (three simulcast encodings received in one track) and simulcast_bidirection examples show it.
Payload formats and containers
rtci-rtp has the RTP packets, header extensions and codec payload formats (packetizers and depacketizers); rtci-media has media samples and container readers and writers (IVF, Ogg Opus, H.264 / H.265 Annex B), which the play-from-disk-* and save-to-disk-* examples use.
DTMF, SFrame and encoded transforms
- DTMF:
rtp_transceiver::rtp_sender::dtmf(RFC 4733 telephone-event). - SFrame end-to-end media encryption (RFC 9605):
rtci-sframeencrypts and decrypts, andrtp_transceiver::sframe_transformhas the W3C webrtc-encoded-transform SFrame transforms,RTCRtpSFrameEncryptorandRTCRtpSFrameDecryptor, over it.
Not in the engine
Encoding, decoding, capture and playout. The receive-side video pipeline (rtci-video: frame assembly, a jitter buffer with playout timing, key-frame requests, decoders behind a trait) is in development in the repository and is not part of the 0.5.0 release.