webrtc MediaCapabilities indexed by getCapabilities
by jib1
HTML
<div id="div" style="white-space: pre;"></div>
JavaScript
const console = { log: msg => div.innerHTML += msg + "<br>" };
const dump = f => console.log(`${f.toString().slice(6)} = ${JSON.stringify(f(), null, 2)}`);
(async () => {
try {
const {codecs} = RTCRtpReceiver.getCapabilities("video");
for (const {mimeType, sdpFmtpLine} of codecs) {
const contentType = sdpFmtpLine?.length? `${mimeType}; ${sdpFmtpLine}` : mimeType;
const info = await navigator.mediaCapabilities.encodingInfo({
type: 'webrtc',
video: {
contentType,
width: 640,
height: 480,
bitrate: 10000,
framerate: 29.97,
}
});
if (!info.supported) {
console.log(`${contentType} is NOT supported.`);
} else {
console.log(`${contentType} is supported (${info.smooth? "" : 'NOT '}smooth and ` +
`${info.powerEfficient? "" : 'NOT '}power efficient)`);
}
}
} catch (e) {
console.log(e);
}
})();