Skip to content

Instantly share code, notes, and snippets.

@voluntas
Last active January 7, 2022 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voluntas/d4bed541e74a855446d170ea5a5b9b41 to your computer and use it in GitHub Desktop.
Save voluntas/d4bed541e74a855446d170ea5a5b9b41 to your computer and use it in GitHub Desktop.
rid 方式の Simulcast 生成方法
// Chrome Canary 75.0.3744.0 にて動作確認
(async () => {
// クライアント
const client = new RTCPeerConnection();
// カメラストリーム取得
const localStream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
// カメラストリームから音声トラックを取得
// const localAudioTrack = localStream.getAudioTracks()[0];
// カメラストリームから映像トラックを取得
const localVideoTrack = localStream.getVideoTracks()[0];
// sendEncodings 用のパラメータを用意
// ここの設定は間違っているかもしれない
// https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpEncodingParameters
// https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpEncodingParameters/maxBitrate
// https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpEncodingParameters/scaleResolutionDownBy
const encodings = [
// 1500kbps ?
{rid: 'high', maxBitrate: 1500000, active: true, priority: "high"},
// 500kbps ?
{rid: 'middle', maxBitrate: 500000, active: true, scaleResolutionDownBy: 2.0},
// 100kbps ?
{rid: 'low', maxBitrate: 100000, active: true, scaleResolutionDownBy: 4.0}
];
// streams を渡すことで msid が利用可能になる
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTransceiver
// 音声トラックを追加
// client.addTransceiver(localAudioTrack, {direction: 'sendonly', streams: [localStream]});
// 映像トラックを encodings 付きで追加
client.addTransceiver(localVideoTrack, {direction: 'sendonly', sendEncodings: encodings, streams: [localStream]});
// デバッグ用
// const sender = client.getSenders()[1];
// console.log(sender.getParameters().encodings);
// offer 生成
const offer = await client.createOffer();
console.log(offer.sdp);
})()
// v=0
// o=- 6712228291165896350 2 IN IP4 127.0.0.1
// s=-
// t=0 0
// a=group:BUNDLE 0
// a=msid-semantic: WMS enbYzmMbq7TqN35ebREbCtZzuBRFhPm8zjOI
// m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116
// c=IN IP4 0.0.0.0
// a=rtcp:9 IN IP4 0.0.0.0
// a=ice-ufrag:rYMA
// a=ice-pwd:0+fXD4tfi+5k7eQrQgcvK4Td
// a=ice-options:trickle
// a=fingerprint:sha-256 1F:9A:97:C9:29:BC:57:CC:CA:37:79:CA:44:40:8F:1F:69:80:1D:C4:E8:32:74:40:E6:40:31:01:44:BB:05:9F
// a=setup:actpass
// a=mid:0
// a=extmap:14 urn:ietf:params:rtp-hdrext:toffset
// a=extmap:13 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
// a=extmap:12 urn:3gpp:video-orientation
// a=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
// a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
// a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
// a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
// a=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
// a=extmap:9 http://www.webrtc.org/experiments/rtp-hdrext/color-space
// a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
// a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
// a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
// a=sendonly
// a=msid:enbYzmMbq7TqN35ebREbCtZzuBRFhPm8zjOI 0f2b97e6-4583-4d06-94bd-7ce2ccd90a93
// a=rtcp-mux
// a=rtcp-rsize
// a=rtpmap:96 VP8/90000
// a=rtcp-fb:96 goog-remb
// a=rtcp-fb:96 transport-cc
// a=rtcp-fb:96 ccm fir
// a=rtcp-fb:96 nack
// a=rtcp-fb:96 nack pli
// a=rtpmap:97 rtx/90000
// a=fmtp:97 apt=96
// a=rtpmap:98 VP9/90000
// a=rtcp-fb:98 goog-remb
// a=rtcp-fb:98 transport-cc
// a=rtcp-fb:98 ccm fir
// a=rtcp-fb:98 nack
// a=rtcp-fb:98 nack pli
// a=fmtp:98 profile-id=0
// a=rtpmap:99 rtx/90000
// a=fmtp:99 apt=98
// a=rtpmap:100 VP9/90000
// a=rtcp-fb:100 goog-remb
// a=rtcp-fb:100 transport-cc
// a=rtcp-fb:100 ccm fir
// a=rtcp-fb:100 nack
// a=rtcp-fb:100 nack pli
// a=fmtp:100 profile-id=2
// a=rtpmap:101 rtx/90000
// a=fmtp:101 apt=100
// a=rtpmap:102 H264/90000
// a=rtcp-fb:102 goog-remb
// a=rtcp-fb:102 transport-cc
// a=rtcp-fb:102 ccm fir
// a=rtcp-fb:102 nack
// a=rtcp-fb:102 nack pli
// a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
// a=rtpmap:122 rtx/90000
// a=fmtp:122 apt=102
// a=rtpmap:127 H264/90000
// a=rtcp-fb:127 goog-remb
// a=rtcp-fb:127 transport-cc
// a=rtcp-fb:127 ccm fir
// a=rtcp-fb:127 nack
// a=rtcp-fb:127 nack pli
// a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
// a=rtpmap:121 rtx/90000
// a=fmtp:121 apt=127
// a=rtpmap:125 H264/90000
// a=rtcp-fb:125 goog-remb
// a=rtcp-fb:125 transport-cc
// a=rtcp-fb:125 ccm fir
// a=rtcp-fb:125 nack
// a=rtcp-fb:125 nack pli
// a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
// a=rtpmap:107 rtx/90000
// a=fmtp:107 apt=125
// a=rtpmap:108 H264/90000
// a=rtcp-fb:108 goog-remb
// a=rtcp-fb:108 transport-cc
// a=rtcp-fb:108 ccm fir
// a=rtcp-fb:108 nack
// a=rtcp-fb:108 nack pli
// a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
// a=rtpmap:109 rtx/90000
// a=fmtp:109 apt=108
// a=rtpmap:124 H264/90000
// a=rtcp-fb:124 goog-remb
// a=rtcp-fb:124 transport-cc
// a=rtcp-fb:124 ccm fir
// a=rtcp-fb:124 nack
// a=rtcp-fb:124 nack pli
// a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032
// a=rtpmap:120 rtx/90000
// a=fmtp:120 apt=124
// a=rtpmap:123 H264/90000
// a=rtcp-fb:123 goog-remb
// a=rtcp-fb:123 transport-cc
// a=rtcp-fb:123 ccm fir
// a=rtcp-fb:123 nack
// a=rtcp-fb:123 nack pli
// a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032
// a=rtpmap:119 rtx/90000
// a=fmtp:119 apt=123
// a=rtpmap:114 red/90000
// a=rtpmap:115 rtx/90000
// a=fmtp:115 apt=114
// a=rtpmap:116 ulpfec/90000
// a=rid:high send
// a=rid:middle send
// a=rid:low send
// a=simulcast:send high;middle;low
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment