How can I change the default codec used in WebRTC?

I was looking for a way to change the codec in the Chrome WebRTC implementation, but it seems like it is not.

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

+7
webrtc sdp
source share
1 answer

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

To use any of these default codecs, you must modify the SDP before installing it locally in your peerconnection and submitting your offer / response. I successfully tested the Chrome app to send PCMA instead of OPUS by default.

As an example:

Suppose you have a default default SDP section that looks like this (the notes in parentheses are not part of 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 want to ONLY use PCMA, you will change the line m=audio to the following: m=audio 49353 RTP/SAVPF 8 thus only the PCMA payload is considered. Then you need to delete all rtpmap lines that do not match this payload, i.e. any a=rtpmap: where the next character is NOT 8. If you install this modified sdp locally and send it to your peer (and if they SUPPORT PCMA .. .not necessarily for them by default, since negotiations will force PCMA, if you only offer it), then PCMA will be your audio codec, not OPUS.

A pair of aids:

  • The SDP I'm talking about is the one generated and passed through the success createOffer and createAnswer peerconnection functions
  • This type of idea will work for ADDING codecs, which, as you know, are supported by backing systems (H264, SPEEX, etc.). Just remember to add the payload and the corresponding mappings and parameters ( fmtp necessary for h264, since profiles are important and possibly sprop-parameter-sets ).
  • This will work with any properly encoded WebRTC system, i.e. with Firefox, Opera, etc. Not just chrome.
+10
source share

All Articles