Specify payloadType for consumer

In order to simplify negotiation, I would like to always match the client’s preferred payload types. In principle, this should be easy, mediasoup is already able to translate the payload types between the producer and consumer, and the rtpCapabilities option of WebRtcTransport#consume allows specifying a preferredPayloadType.
Unfortunately, this value seems to be completely ignored. The payload type returned in the rtp parameters of the consumer is always the one defined in the router’s mediaCodecs, be it an explicit preferredPayloadType or the default incremental ones.
Is this intended behavior? Is it not possible to override the payloadType for the consumer?

To exemplify,

const consumer = await this.transport?.consume({
            producerId,
            rtpCapabilities: {
                codecs: [
                    {
                        kind: 'audio',
                        mimeType: 'audio/opus',
                        preferredPayloadType: 111,
                        clockRate: 48000,
                        channels: 2,
                        parameters: {
                            'useinbandfec': 1,
                            'maxaveragebitrate': 64000,
                            'stereo': 1,
                        },
                    },
                ],
                headerExtensions: [],
            },
})!;
console.log(consumer.rtpParameters)
/* {
  codecs: [
    {
      mimeType: 'audio/opus',
      payloadType: 100,   <- 100, as it's the first value in the router's mediaCodecs
      clockRate: 48000,
      channels: 2,
      parameters: [Object],
      rtcpFeedback: []
    }
  ],
  headerExtensions: [],
  encodings: [ { ssrc: 504721282, maxBitrate: 64000 } ],
  rtcp: { cname: '51b0ba15', reducedSize: true },
  mid: '0'
} */

The preferredPayloadType in consume() is not what you expect it to be. Actually it MUST much the expected value. It’s only optional in the codecs given to worker.createRouter(). This is explained in the docs somewhere.

There is already a task to allow per consumer payload type and RTP extension ids. BTW this is far from “an easy task”:

Thanks for the reply and information. I have changed my approach to have the server inform the client of the payload types instead, which is working nicely. That leads me to a subsequent question, though: What are the strategies for managing a large variety of codecs?
As far as I know, it is not possible to add media codecs to an existing router, which, especially for codecs with many profile variations, leaves us in an awkward situation of trying to fill in ahead of time all codecs that a client may attempt to use. I was hoping for a more dynamic approach where, as long as agreed to by all participants, any sensible combination of parameters could be appended to the router and used.
Thank you again in advance.

It could be feasible but I don’t see how it would be useful. If router codecs could change dynamically then all connected clients should be notified about the new codecs, the RtpCapabilities in the Device of mediasoup-client should be recomputed, etc.

Typically in a SFU environment you want to specify the exact codecs you want to support to cover the capabilities of your users. If you add recording feature you also need to limit those codecs for your recording system to support them, etc.

I suppose my use is mostly out of scope as I’m not using mediasoup-client. I have somewhat inverted the negotiation process: When a new client connects, it informs the server of all it’s supported capabilities; the server then finds the best match across all clients in one room and broadcasts the new selected codec. Initially, I was handling all of the configuration on the client, and expecting the server to conform with the payload types selected, hence my initial post. I have since changed this so that the server also responds to the initial capability offer with it’s matching capabilities. While the majority of cases can be easily covered, there is still a gap in the event that all clients support, for example, a higher H264 profile, but the router was not configured to handle it.
For now, I am logging these ‘missed capabilities’ so I can complete the configuration over time, any widely supported ones should be quickly covered so it is not a concern, I was just wondering for a cleaner approach.

Please create a Feature Request ticket in mediasoup GitHub with the rationale above.

So many feature requests die here in the forum when I kindly ask for a feature request ticket in GitHub. It’s ok.

My apologies, it has been posted #1564

1 Like

I’m having issue with video/AV1 RTP streamed from ffmpeg (PT does not matter) and corresponding producer created, but then when I connect Chrome client it only works if preferredPayloadType in the router is set to 45 (this is what Chrome expects in SDP offer) but apparently does not work for FireFox which is expecting PT=99 (from SDP offer). Consequently, mediasoup sends RTP (PT=45, cpatured with Wireshark) to both Chrome and Firefox. RTP packets fly, but video frames are not decoded. Is AV1 more restrictive in the browsers as compared to other codecs?

As you can see in the mediasoup demo (which uses mediasoup-client in the browser app) this is not true. AV1 is properly received by Chrome despite payload type is 107:

v=0
o=mediasoup-client-v3.18.7 10000 2 IN IP4 0.0.0.0
s=-
t=0 0
a=extmap-allow-mixed
a=ice-lite
a=fingerprint:sha-384 C6:30:DD:DD:77:21:0C:F2:45:05:69:B3:31:ED:FB:E1:84:D7:AB:50:1D:84:61:F5:82:63:55:F9:1F:A0:20:6B:01:55:E5:46:AF:CC:FA:72:99:CC:B7:49:86:AE:2D:A8
a=ice-options:ice2
a=msid-semantic: WMS *
a=group:BUNDLE 0 1
m=audio 7 UDP/TLS/RTP/SAVPF 100
c=IN IP4 127.0.0.1
a=rtpmap:100 opus/48000/2
a=fmtp:100 minptime=10;useinbandfec=1;sprop-stereo=1;usedtx=1
a=rtcp-fb:100 nack 
a=extmap:1 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:6 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap-allow-mixed
a=setup:actpass
a=mid:0
a=msid:incswoew-audio-video 7d1452f1-94aa-438b-9f4c-41fee126df75
a=sendonly
a=ice-ufrag:4eggeu3faxoff7yaedy2rjs60mvpwabi
a=ice-pwd:kjdhgyi0bzd75v3j2axqckb5geh5fid1
a=candidate:udpcandidate 1 udp 1076302079 162.210.59.78 55560 typ host
a=candidate:tcpcandidate 1 tcp 1076276479 162.210.59.78 55560 typ host tcptype passive
a=end-of-candidates
a=ice-options:renomination
a=ssrc:739186730 cname:rmY4rEYUQqBiIpn6
a=rtcp-mux
a=rtcp-rsize
m=video 7 UDP/TLS/RTP/SAVPF 107 108
c=IN IP4 127.0.0.1
a=rtpmap:107 AV1/90000
a=rtpmap:108 rtx/90000
a=fmtp:107 level-idx=5;profile=0;tier=0
a=fmtp:108 apt=107
a=rtcp-fb:107 transport-cc 
a=rtcp-fb:107 ccm fir
a=rtcp-fb:107 nack 
a=rtcp-fb:107 nack pli
a=extmap:1 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:8 urn:3gpp:video-orientation
a=extmap:9 urn:ietf:params:rtp-hdrext:toffset
a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap-allow-mixed
a=setup:actpass
a=mid:1
a=msid:incswoew-audio-video 2d161aa8-ec5b-4a5d-b493-a9dbfa94645c
a=sendonly
a=ice-ufrag:4eggeu3faxoff7yaedy2rjs60mvpwabi
a=ice-pwd:kjdhgyi0bzd75v3j2axqckb5geh5fid1
a=candidate:udpcandidate 1 udp 1076302079 162.210.59.78 55560 typ host
a=candidate:tcpcandidate 1 tcp 1076276479 162.210.59.78 55560 typ host tcptype passive
a=end-of-candidates
a=ice-options:renomination
a=ssrc:789160174 cname:rmY4rEYUQqBiIpn6
a=ssrc:789160175 cname:rmY4rEYUQqBiIpn6
a=ssrc-group:FID 789160174 789160175
a=rtcp-mux
a=rtcp-rsize