Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the default Codec used in WebRTC?

Tags:

webrtc

sdp

I've been googling a way to change codec in Chrome's implementation of WebRTC, but there doesn't seem to be a way.

How can I change the default codec used(audio or video) in a WebRTCpeer connection in Chrome?

like image 257
Tony Avatar asked Nov 14 '14 06:11

Tony


People also ask

What is WebRTC and how does it work?

The WebRTC API makes it possible to construct web sites and apps that let users communicate in real time, using audio and/or video as well as optional data and other information. To communicate, the two devices need to be able to agree upon a mutually-understood codec for each track so they can successfully communicate and present the shared media.

What WebRTC codecs are required?

WebRTC establishes a baseline set of codecs which all compliant browsers are required to support. Some browsers may choose to allow other codecs as well. Below are the video codecs which are required in any fully WebRTC-compliant browser, as well as the profiles which are required and the browsers which actually meet the requirement.

Why doesn't Firefox support WebRTC on my Device?

This is due to a change in Google Play store requirements that prevent Firefox from downloading and installing the OpenH264 codec needed to handle H.264 in WebRTC connections. See this article on SUMO for details. For details on WebRTC-related considerations for each codec, see the sub-sections below by following the links on each codec's name.

What is VP8 and how do I use it with WebRTC?

VP8, which we describe in general in the main guide to video codecs used on the web, has some specific requirements that must be followed when using it to encode or decode a video track on a WebRTC connection. Unless signaled otherwise, VP8 will use square pixels (that is, pixels with an aspect ratio of 1:1).


1 Answers

Yes, you can change the codec to be anything you want...as long as Chrome supports it. Right now, audio wise, the only supported codecs are PCMA, PCMU, ISAC, and OPUS(the default). For Video you have VP8(also H264 on some systems with FireFox).

To use any of these codecs as default, you must modify your SDP before setting it locally in your peerconnection and sending your offer/answer. I have tested successfully forcing Chrome to send PCMA instead of OPUS by default.

As an example:

Say you have your default audio SDP section that looks like the following(notes are in brackets are are not part of the sdp)

m=audio<media> 49353<port> RTP/SAVPF<proto> 111 103 104 0 8 106 105 13 126 <rtpformats>

c=IN<nettype> IP4<addrtype> 192.168.0.13<address>

a=rtcp:49353<port> IN<nettype> IP4<addresstype> privateIP<connection address>

a=candidate:1204296370 1 udp 2122260223 privateIP 49353 typ host generation 0 <audioIceCandidate>
a=candidate:1204296370 2 udp 2122260223 privateIP 49353 typ host generation 0
a=candidate:155969090 1 tcp 1518280447 privateIP  0 typ host generation 0
a=candidate:155969090 2 tcp 1518280447 privateIP  0 typ host generation 0
a=ice-ufrag:E7VFzFythTIOaQ6X <ice username>
a=ice-pwd:ZMHFqqXEA8JLjItZcRN4FZDJ <ice-password>
a=ice-options:google-ice <iceoptions>
a=fingerprint:sha-256<encryptType> 66:2D:43:3A:31:7B:46:56:50:D7:CC:75:80:79:5D:88:7D:5D:1B:0E:C7:E6:F9:C4:68:6D:51:7F:4B:32:97:A1<print>
a=setup:actpass <dtls setup mode>
a=mid:audio   
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level <extention map>
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=sendrecv <mediamode>
a=rtcp-mux <says rtcp mux>
a=rtpmap:111 opus/48000/2
a=fmtp:111 minptime=10
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:126 telephone-event/8000
a=maxptime:60

If you wanted to ONLY use PCMA, you would change the m=audio line to the following: m=audio 49353 RTP/SAVPF 8 this way only the PCMA payload is considered. Then you need to remove all the rtpmap lines that do not correspond with that payload, i.e. any a=rtpmap: where the next character is NOT an 8. If you set that modified sdp locally and send it to your peer(and if they SUPPORT PCMA...does not have to be default for them as the negotiation will force PCMA if you only offer it), then PCMA will be your audio codec and not OPUS.

Couple of asides:

  • The SDP I am talking about is the one generated and passed through the success callback of the createOffer and createAnswer functions of the peerconnection
  • This type of idea will work for ADDING codecs that you know are supported by the underlaying systems(H264, SPEEX, etc.). Just make sure to add the payload and the appropriate mappings and options(fmtp is needed for h264 as profiles are important and possibly sprop-parameter-sets).
  • This will work with any appropriately coded WebRTC system, i.e. Firefox, Opera, etc. Not just chrome.
like image 151
Benjamin Trent Avatar answered Sep 17 '22 14:09

Benjamin Trent