RTCRtpTransceiver.setCodecPreferences() - Web APIs 编辑

The RTCRtpTransceiver method 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.

Syntax

rtcRtpTransceiver.setCodecPreferences(codecs)

Parameters

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.

Note: 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.

Return value

undefined

Exceptions

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

Usage notes

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 or the 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;

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpTransceiver.setCodecPreferences()' in that specification.
Candidate Recommendation

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:93 次

字数:5986

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文