Skip to main content

derive_consumable_rtp_parameters

Function derive_consumable_rtp_parameters 

Source
pub fn derive_consumable_rtp_parameters(
    producer_parameters: &MediaStream,
    capabilities: &MediaCapabilities,
) -> Result<MediaStream, RtpNegotiationError>
Expand description

Derives the router-consumable media stream from producer parameters.

§Two-Pass Codec Resolution

Retransmission (RTX) formats depend on an associated primary codec via RFC 4588 apt. Negotiation therefore executes in two passes:

  1. Pass 1 (Primary Codecs): Match primary media formats against router capabilities, assigning router-normalized payload types and building a translation map.
  2. Pass 2 (RTX Codecs): Match RTX repair formats, resolve their apt references against the translation map, and omit valid formats with no matching router RTX capability.
Incoming Producer Formats:
  [ Format 0: RTX (PT 97, apt=96) ] <---+ (references PT 96)
  [ Format 1: VP8 (PT 96)         ] ----+

Pass 1: Primary Codec Matching (Skip RTX)
  Format 1 (VP8, PT 96) matches Router Capability (VP8, PT 100)
    ==> Consumable Primary: VP8 (PT 100)
    ==> Translation Map: [ Producer PT 96 -> Router PT 100 ]

Pass 2: RTX Matching & `apt` Rewriting
  Format 0 (RTX, PT 97, apt=96):
    - Lookup `apt=96` in Translation Map ==> matches Router PT 100
    - Match Router Capability for RTX with apt=100 ==> Router PT 101
    ==> Consumable Repair: RTX (PT 101, apt=100)

Final Consumable Stream:
  [ Primary: VP8 (PT 100) ] + [ Repair: RTX (PT 101, apt=100) ]

The final repair pair is retained only when the primary format also retains Generic NACK.

§Errors

Returns RtpNegotiationError::UnsupportedProducerCodec when a producer media codec does not match any router media codec capability, RtpNegotiationError::InvalidAptParameter when a RTX codec carries an invalid apt parameter, or RtpNegotiationError::MissingAssociatedMediaCodecForRtx when a RTX codec references a media payload that is not part of the negotiated media codec set.