Hi! I’m trying to use a Router that handles all default codecs supported by mediasoup; for this, the docs are not too explicit (or I’m blind and didn’t see it) because they always show examples where some specific codecs are passed to worker.createRouter(RouterOptions), but I wasn’t able to find some example where no codecs are specified (“use everything you can”)
First attempt: worker.createRouter({})
So first I saw that RouterOptions.mediaCodecs is optional, but RouterOptions itself is required in worker.createRouter(RouterOptions), hence I pass an empty object:
let router = await worker.createRouter({});
This doesn’t work; what it does is the same as if an empty array had been passed, i.e. it is equivalent to this:
let router = await worker.createRouter({ mediaCodecs: [] });
which means the opposite of what I wanted: now mediasoup is configured to work without any codec.
This causes an error later down the way, while trying to produce on some transport:
mediasoup:Transport produce()
mediasoup:Channel request() [method:transport.produce, id:4]
mediasoup:ERROR:Channel [pid:75547 RTC::RtpParameters::RtpParameters() | throwing MediaSoupTypeError: empty codecs
mediasoup:ERROR:Channel [pid:75547 Worker::OnChannelRequest() | throwing MediaSoupTypeError: empty codecs [method:transport.produce]
mediasoup:WARN:Channel request failed [method:transport.produce, id:4]: [method:transport.produce]
Notice the error: empty codecs.
- Q: Is that how it should work? I expected that the
mediaCodecsfield is not required precisely to be able to not restrict the set of codecs used by mediasoup. If this is however working as expected, maybe a line in the docs could be helpful to clarify that.
Second attempt: getSupportedRtpCapabilities()
I found this function, so now I’m trying to call
worker.createRouter({
mediaCodecs: Mediasoup.getSupportedRtpCapabilities().codecs
});
but it throws an error:
mediasoup:Worker createRouter()
TypeError: duplicated codec.preferredPayloadType: 13
(the original code doesn’t print the problematic value, that’s something I added to the .js)
Fair enough, as I know the default capabilities come with some repeated PTs.
However, removing all preferredPayloadType fields also causes the same error, with the same PT number:
worker.createRouter({
mediaCodecs: Mediasoup.getSupportedRtpCapabilities().codecs?.map((c) => {
delete c.preferredPayloadType;
return c;
})
});
mediasoup:Worker createRouter()
TypeError: duplicated codec.preferredPayloadType: 13
(and the resulting object doesn’t contain any PTs, I verified)
So this also doesn’t work 
- Q: Is there a recommended way to tell mediasoup “just use everything” instead of having to be explicit about the codecs that should be used? Is it maybe considered a bad practice to do so?
Thanks
well for now it seemed to be enough by removing the most repeated audio codec combinations. In reality I just want something simple: that when mediasoup implements AV1, the app doesn’t need to be changed, that’s all.
as solution because that’s basically what it is. Maybe mediasoup is missing a small helper tool that provides all the latest and greatest capabilities in some useful shape that can be used directly by application, kind of how web browsers do when you ask them to generate a default SDP Offer without any other parameter. But then that’d be a proper feature request. For now, each app wanting such behavior needs to build such utility by itself.