Skip to content

Negotiating codecs when sender supports multiple options #737

@wkozyra95

Description

@wkozyra95

I want to send media over WHIP. My app supports multiple encoders, so I don't want to enforce a specific codec when creating a track. I want to resolve which codec to use based on the result of the codec negotiation. I would be grateful for any suggestions on how to approach it.

Current scenario with webrtc-rs 0.13

  • create peer connection
  • create audio and video transceiver
  • create offer, send it to WHIP endpoint, receive answer
  • set_local_description
  • set_remote_description (fails at this point)
  • replace both tracks with negotiated values based on RTCRtpSendParameters from RTCRtpSender

Failure scenario: For example, if the server supports only H264, but VP8 is first on our list of codecs (in MediaEngine), then set_remote_description will fail. If H264 is first on the list of codecs, it would work.

It looks like here https://github.com/webrtc-rs/webrtc/blob/master/webrtc/src/peer_connection/peer_connection_internal.rs when creating a transceiver, some codec is already assigned. My understanding is that behavior like that is expected for tracks, but not transceivers.

I'm able to make it work if, before calling set_remote_description, I call replace_track. However, this would require me to parse the offer and answer on my own and resolve what codec should be used. This would basically duplicate a resolution logic that is already in webrtc-rs, so I'm assuming that is not an intended approach.

Current scenario with webrtc-rs 0.11

We have this scenario working with webrtc-rs 0.11

We were able to make it work by:

  • create peer connection
  • create audio and video tracks
  • create offer, send it to WHIP endpoint, receive answer
  • set_local_description
  • replace both tracks with None
  • set_remote_description
  • replace both tracks with negotiated values based on RTCRtpSendParameters from RTCRtpSender

In that version, creating tracks was necessary because if we used a transceiver ssrc was not included in the sdp offer. However, this approach does not work in the latest webrtc-rs because setting track track to None clears encodings and final replace_track fails with

ErrRTPSenderNewTrackHasIncorrectEnvelope,

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions