RTCRtpTransceiver 方法 setCodecPreferences() configures the transceiver's codecs given a list of RTCRtpCodecCapability objects specifying the new preferences for each codec . The specified set of codecs and configurations will be used for all future connections including this transceiver until this method is called again.

When preparing to open an RTCPeerConnection , you can change the codec parameters from the user agent's default configuration by calling setCodecParameters() before calling either RTCPeerConnection.createOffer() or createAnswer() .

A guide to codecs supported by WebRTC—and each codec's positive and negative characteristics—can be found in Codecs used by WebRTC .

句法

rtcRtpTransceiver.setCodecPreferences(codecs)
					

参数

codecs

An array of RTCRtpCodecCapability objects, in order of preference, each providing the parameters for one of the transceiver's supported codecs. If codecs is empty, the codec configurations are all returned to the user agent's defaults.

注意: Any codecs not included in codecs will not be considered during the process of negotiating a connection. This lets you prevent the use of codecs you don't wish to use.

返回值

undefined

异常

InvalidAccessError
codecs list includes one or more codecs which are not supported by the transceiver.

用法注意事项

Getting a list of supported codecs

You can only include in the codecs list codecs which the transceiver actually supports. That means that either the associated RTCRtpSender RTCRtpReceiver needs to support every codec in the list. If any unsupported codecs are listed, the browser will throw an InvalidAccessError exception when you call this method.

A good approach to setting codec preferences is to first get the list of codecs that are actually supported, then modify that list to match what you want. Pass the altered list into setCodecPreferences() to specify your preferences.

To determine which codecs are supported by the transceiver, call the sender's getCapabilities() and the receiver's getCapabilities() methods and get the codecs list from the results of each.

The following code snippet demonstrates how to get both the list of codecs supported by the transceiver's RTCRtpSender and RTCRtpReceiver .

var availSendCodecs = transceiver.sender.getCapabilities("video").codecs;
var availReceiveCodecs = transceiver.receiver.getCapabilities("video").codecs;
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpTransceiver.setCodecPreferences()' in that specification.
候选推荐

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
setCodecPreferences() Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS ? Samsung Internet Android 不支持 No

图例

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: