diff --git a/constrain-bandwidth.js b/constrain-bandwidth.js index 520e4af..bcc01fc 100644 --- a/constrain-bandwidth.js +++ b/constrain-bandwidth.js @@ -27,7 +27,7 @@ module.exports = function(value, mediaType) { // remove existing b=AS lines lines = lines.filter(function(line) { - return line.slice(0, 3) !== 'b=AS' + return line.slice(0, 4) !== 'b=AS' }); // find the splice locations for the bandwidth lines diff --git a/test/constrain-bandwidth.js b/test/constrain-bandwidth.js index 5ccda23..9fc15f0 100644 --- a/test/constrain-bandwidth.js +++ b/test/constrain-bandwidth.js @@ -1,13 +1,21 @@ var fs = require('fs'); var test = require('tape'); var constrainBW = require('../constrain-bandwidth'); -var baseSdp = fs.readFileSync(__dirname + '/fragments/test-answer-nocandidates.txt', 'utf8'); +var baseSdp = [ + fs.readFileSync(__dirname + '/fragments/test-answer-nocandidates.txt', 'utf8'), + fs.readFileSync(__dirname + '/fragments/test-audio-video.txt', 'utf8') +]; var refSdp = [ - fs.readFileSync(__dirname + '/output/constrain-bandwidth-session.txt', 'utf8') -// fs.readFileSync(__dirname + '/output/test-answer-addvideoice2.txt', 'utf8') + fs.readFileSync(__dirname + '/output/constrain-bandwidth-session.txt', 'utf8'), + fs.readFileSync(__dirname + '/output/constrain-bandwidth-video.txt', 'utf8') ]; test('can add a bandwidth constraint to the session line', function(t) { t.plan(1); - t.equal(constrainBW(128)(baseSdp), refSdp[0]); + t.equal(constrainBW(128)(baseSdp[0]), refSdp[0]); +}); + +test('can replace video bandwidth constraint', function(t) { + t.plan(1); + t.equal(constrainBW(128, 'video')(baseSdp[1]), refSdp[1]); }); diff --git a/test/output/constrain-bandwidth-video.txt b/test/output/constrain-bandwidth-video.txt new file mode 100644 index 0000000..b30ef9f --- /dev/null +++ b/test/output/constrain-bandwidth-video.txt @@ -0,0 +1,95 @@ +v=0 +o=- 6100221552656226068 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE audio video data +a=msid-semantic: WMS h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R +m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 126 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:iRrAkD4GFX9OersM +a=ice-pwd:1lkz6OYbhrhmH7B53ccCeG+L +a=fingerprint:sha-256 0C:51:8E:5F:72:72:19:00:F4:66:27:5D:EC:BA:72:5A:59:7D:D7:CB:03:50:9B:1C:F8:B6:23:5C:38:E4:22:D4 +a=setup:active +a=mid:audio +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=sendrecv +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +a=rtpmap:103 ISAC/16000 +a=rtpmap:104 ISAC/32000 +a=rtpmap:9 G722/8000 +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=ssrc:2464355705 cname:D6daqc7p6+slHA48 +a=ssrc:2464355705 msid:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R cf956916-b2f0-4396-8e1c-ef868918c7f3 +a=ssrc:2464355705 mslabel:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R +a=ssrc:2464355705 label:cf956916-b2f0-4396-8e1c-ef868918c7f3 +m=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96 97 99 98 +b=AS:128 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:iRrAkD4GFX9OersM +a=ice-pwd:1lkz6OYbhrhmH7B53ccCeG+L +a=fingerprint:sha-256 0C:51:8E:5F:72:72:19:00:F4:66:27:5D:EC:BA:72:5A:59:7D:D7:CB:03:50:9B:1C:F8:B6:23:5C:38:E4:22:D4 +a=setup:active +a=mid:video +a=extmap:2 urn:ietf:params:rtp-hdrext:toffset +a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:4 urn:3gpp:video-orientation +a=sendrecv +a=rtcp-mux +a=rtcp-rsize +a=rtpmap:100 VP8/90000 +a=rtcp-fb:100 ccm fir +a=rtcp-fb:100 nack +a=rtcp-fb:100 nack pli +a=rtcp-fb:100 goog-remb +a=rtcp-fb:100 transport-cc +a=rtpmap:101 VP9/90000 +a=rtcp-fb:101 ccm fir +a=rtcp-fb:101 nack +a=rtcp-fb:101 nack pli +a=rtcp-fb:101 goog-remb +a=rtcp-fb:101 transport-cc +a=rtpmap:107 H264/90000 +a=rtcp-fb:107 ccm fir +a=rtcp-fb:107 nack +a=rtcp-fb:107 nack pli +a=rtcp-fb:107 goog-remb +a=rtcp-fb:107 transport-cc +a=fmtp:107 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f +a=rtpmap:116 red/90000 +a=rtpmap:117 ulpfec/90000 +a=rtpmap:96 rtx/90000 +a=fmtp:96 apt=100 +a=rtpmap:97 rtx/90000 +a=fmtp:97 apt=101 +a=rtpmap:99 rtx/90000 +a=fmtp:99 apt=107 +a=rtpmap:98 rtx/90000 +a=fmtp:98 apt=116 +a=ssrc-group:FID 1605580382 3794581275 +a=ssrc:1605580382 cname:D6daqc7p6+slHA48 +a=ssrc:1605580382 msid:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R ef684928-5143-4e2a-9ac7-e2a4e2278e10 +a=ssrc:1605580382 mslabel:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R +a=ssrc:1605580382 label:ef684928-5143-4e2a-9ac7-e2a4e2278e10 +a=ssrc:3794581275 cname:D6daqc7p6+slHA48 +a=ssrc:3794581275 msid:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R ef684928-5143-4e2a-9ac7-e2a4e2278e10 +a=ssrc:3794581275 mslabel:h888ZGNbE0nghXOfNtrZLUg7ZTgvc0kpMx5R +a=ssrc:3794581275 label:ef684928-5143-4e2a-9ac7-e2a4e2278e10 +m=application 9 DTLS/SCTP 5000 +c=IN IP4 0.0.0.0 +a=ice-ufrag:iRrAkD4GFX9OersM +a=ice-pwd:1lkz6OYbhrhmH7B53ccCeG+L +a=fingerprint:sha-256 0C:51:8E:5F:72:72:19:00:F4:66:27:5D:EC:BA:72:5A:59:7D:D7:CB:03:50:9B:1C:F8:B6:23:5C:38:E4:22:D4 +a=setup:active +a=mid:data +a=sctpmap:5000 webrtc-datachannel 1024