# Prefer client-side codecs order

**URL:** https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167
**Category:** mediasoup libraries
**Created:** [December 22, 2020, 12:08pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167 "2020-12-22T12:08:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [December 22, 2020, 12:08pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/1 "2020-12-22T12:08:27Z")

</div>

Currently `getExtendedRtpCapabilities` in mediasoup-client iterates through codecs in the order they are on the server.  
This may be desirable in some cases and not in others, like when browser prefers H264 because it has hardware acceleration for it.  
Would be nice to have an option to prefer codecs order from the browser instead. Thoughts?  
I can make a PR with this change if it is something that looks useful to others.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [December 22, 2020, 12:30pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/2 "2020-12-22T12:30:04Z")

</div>

The app can call `transport.produce()` with the desired codec:

> **[mediasoup :: API](https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions)**
>
> Cutting Edge WebRTC Video Conferencing

---

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [December 22, 2020, 12:39pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/3 "2020-12-22T12:39:41Z")

</div>

Yes, but you need to know what desired codec is. Currently it is the first codec in server’s capabilities list that browser supports, but what I’m interested in is the first codec in browser’s capabilities list that server supports.

So if server returns:

```auto
VP8
RTX
VP9
RTX
H264
RTX

```

And browser:

```auto
H264
RTX
VP8
RTX

```

Current result is `VP8`, while I’d expect `H264`, at least as an option.

So currently to achieve this one has to copy-paste a bunch of code from mediasoup-client or manually create and parse SDP to see what browser supports and prefers.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [December 22, 2020, 12:54pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/4 "2020-12-22T12:54:06Z")

</div>

Is this really a so important feature to have? I’ve never needed this. Typically you don’t want to let the client choose the codec but, instead, decide it via application logic. This is not just about encoder capabilities but also about decoders (receivers).

---

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [December 22, 2020, 1:00pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/5 "2020-12-22T13:00:57Z")

</div>

In my case I want to follow browser decision. If browser prefers H264, it often indicates hardware acceleration, like on iOS, which makes a huge difference for user experience on low-power devices. But I don’t want to force H264 either if browser likes VP8 more.

Ability to get native RTP capabilities (possibly filtered according to router capabilities) out of device instance to make this decision on application level would be sufficient as well. I just want to avoid adding separate SDP parser to the app if possible.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [December 22, 2020, 1:08pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/6 "2020-12-22T13:08:24Z")

</div>

I’d accept a PR that adds a `localOrder: number` in each codec capability in mediasoup-client, pointing to the order of such a codec in the client capabilities, so the app can layer choose it based on that field and use the `codec` field in ProducerOptions. Good?

---

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [December 22, 2020, 1:59pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/7 "2020-12-22T13:59:07Z")

</div>

That could work, but it doesn’t fit well into the `RtpCodecCapability` type

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [December 22, 2020, 2:07pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/8 "2020-12-22T14:07:19Z")

</div>

We can modify the type 🙂

---

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [January 4, 2021, 3:22pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/9 "2021-01-04T15:22:27Z")

</div>

I ended up doing the ugly thing: accessing `device._handlerFactory` to get my hands on `getNativeRtpCapabilities()`.  
I really don’t like adding properties to `RtpCodecCapability` just for this, it makes data structure awkward.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [January 4, 2021, 4:11pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/10 "2021-01-04T16:11:39Z")

</div>

I don’t really see how adding a `nativeOrder` in `RtpCodecCapability` is that ugly.

---

<div class="post-metadata">

### Author: ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)
#### Post date: [January 4, 2021, 4:29pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/11 "2021-01-04T16:29:00Z")

</div>

It has nothing to do with with RTP or codec or capability, it is a higher level concept of ordering between codecs. And corresponding data structure on backend will not have `localOrder` property. So for nicer API it must be somewhere else. It would work that way of course, it is just awkward to me.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [January 4, 2021, 4:41pm UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/12 "2021-01-04T16:41:32Z")

</div>

Yes, agreed. However this is complex. Having a separate “locally ordered” array of `codecs` is not that easy. For example, RTX codecs must be placed **after** their corresponding video codecs.

---

<div class="post-metadata">

### Author: ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)
#### Post date: [May 14, 2025, 10:52am UTC](https://mediasoup.discourse.group/t/prefer-client-side-codecs-order/2167/13 "2025-05-14T10:52:28Z")

</div>

It’s never too late: [Option to prefer local codecs order by ibc · Pull Request #327 · versatica/mediasoup-client · GitHub](https://github.com/versatica/mediasoup-client/pull/327)
