提交 96f259e4 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Some work done on SDP/ORTC params

上级 5d485623
...@@ -29,7 +29,7 @@ const nodeTests = ...@@ -29,7 +29,7 @@ const nodeTests =
'test/test-Peer.js', 'test/test-Peer.js',
'test/test-Transport.js', 'test/test-Transport.js',
'test/test-RtpReceiver.js', 'test/test-RtpReceiver.js',
'test/test-extra.js' 'test/test-utils.js'
]; ];
const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json'; const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json';
const workerHeaderFilterRegex = const workerHeaderFilterRegex =
......
'use strict';
// SDP codec parameters that don't follow the camelcase convention of ORTC.
const WELL_KNOWN_SDP_PARAMS_TO_ORTC = new Map([
// OPUS parameters.
// https://tools.ietf.org/html/draft-ietf-payload-rtp-opus
[ 'maxplaybackrate', 'maxPlaybackRate' ],
[ 'sprop-maxcapturerate', 'spropMaxCaptureRate' ],
[ 'maxaveragebitrate', 'maxAverageBitrate' ],
[ 'useinbandfec', 'useInbandFec' ],
[ 'usedtx', 'useDtx' ],
[ 'sprop-maxcapturerate', 'spropMaxCaptureRate' ],
// FLEXFEC parameters.
// https://tools.ietf.org/html/draft-ietf-payload-flexible-fec-scheme
[ 'L', 'l' ],
[ 'D', 'd' ],
[ 'ToP', 'toP' ]
]);
// NOTE: SDP params are converted to lowcase.
const WELL_KNOWN_FROM_SDP_PARAMS = new Map();
// NOTE: ORTC params are converted to lowcase.
const WELL_KNOWN_TO_SDP_PARAMS = new Map();
for (let pair of WELL_KNOWN_SDP_PARAMS_TO_ORTC)
{
let key = pair[0];
let value = pair[1];
WELL_KNOWN_FROM_SDP_PARAMS.set(key.toLowerCase(), value);
WELL_KNOWN_TO_SDP_PARAMS.set(value.toLowerCase(), key);
}
module.exports =
{
/**
* Generate a raw DTLS fingerprint.
* @param {String} sdpFingerprint - SDP fingerprint (uppercase with colons).
* @return {String} Raw fingerprint (lowercase without colons).
*/
fingerprintFromSDP: (sdpFingerprint) =>
{
if (typeof sdpFingerprint !== 'string' || !sdpFingerprint)
throw new TypeError('wrong argument');
return sdpFingerprint
.replace(/:/g, '')
.toLowerCase();
},
/**
* Generate a SDP DTLS fingerprint.
* @param {String} rawFingerprint - Raw fingerprint (lowercase without colons).
* @return {String} SDP fingerprint (uppercase with colons).
*/
fingerprintToSDP: (rawFingerprint) =>
{
if (typeof rawFingerprint !== 'string' || !rawFingerprint)
throw new TypeError('wrong argument');
return rawFingerprint
.replace(/../g, (xx) => xx + ':')
.slice(0, -1)
.toUpperCase();
},
/**
* Generate a mediasoup normalized parameter.
* @param {String} param - SDP parameter name.
* @return {String} Normalized parameter name.
*/
paramFromSDP: (param) =>
{
if (typeof param !== 'string' || !param)
throw new TypeError('wrong argument');
let wellKnownParam = WELL_KNOWN_FROM_SDP_PARAMS.get(param.toLowerCase());
if (wellKnownParam)
return wellKnownParam;
let newParam = '';
for (let i = 0, len = param.length; i < len; i++)
{
let c = param[i];
if (c !== '-')
newParam += c.toLowerCase();
else if (i < len - 1)
newParam += param[++i].toUpperCase();
}
return newParam;
},
/**
* Generate a SDP normalized parameter.
* @param {String} param - mediasoup parameter name.
* @return {String} SDP parameter name.
*/
paramToSDP: (param) =>
{
if (typeof param !== 'string' || !param)
throw new TypeError('wrong argument');
let wellKnownParam = WELL_KNOWN_TO_SDP_PARAMS.get(param.toLowerCase());
if (wellKnownParam)
return wellKnownParam;
let newParam = '';
for (let i = 0, len = param.length; i < len; i++)
{
let c = param[i];
if (c === c.toLowerCase())
{
newParam += c;
}
else
{
if (i)
newParam += '-';
newParam += c.toLowerCase();
}
}
return newParam;
}
};
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
const logger = require('./logger')(); const logger = require('./logger')();
const Server = require('./Server'); const Server = require('./Server');
const errors = require('./errors'); const errors = require('./errors');
const extra = require('./extra');
const webrtc = require('./webrtc'); const webrtc = require('./webrtc');
const PKG = require('../package.json'); const PKG = require('../package.json');
...@@ -55,11 +54,6 @@ module.exports = ...@@ -55,11 +54,6 @@ module.exports =
*/ */
errors: errors, errors: errors,
/**
* Export the extra module.
*/
extra: extra,
/** /**
* Export the webrtc module. * Export the webrtc module.
*/ */
......
...@@ -11,6 +11,35 @@ const randomNumberGenerator = randomNumber.generator( ...@@ -11,6 +11,35 @@ const randomNumberGenerator = randomNumber.generator(
integer : true integer : true
}); });
// In ORTC, codec parameters use camelCase but that provides zero benefit.
// Let keep them for backward compatibility.
const ORTC_TO_SDP_PARAMETERS = new Map([
// OPUS parameters.
// https://tools.ietf.org/html/draft-ietf-payload-rtp-opus
[ 'maxPlaybackRate', 'maxplaybackrate' ],
[ 'spropMaxCaptureRate', 'sprop-maxcapturerate' ],
[ 'maxAverageBitrate', 'maxaveragebitrate' ],
[ 'useInbandFec', 'useinbandfec' ],
[ 'useDtx', 'usedtx' ],
[ 'spropMaxCaptureRate', 'sprop-maxcapturerate' ],
// FLEXFEC parameters.
// https://tools.ietf.org/html/draft-ietf-payload-flexible-fec-scheme
[ 'l', 'L' ],
[ 'd', 'D' ],
[ 'toP', 'ToP' ]
]);
// Covert ORTC codec parameters to lowercase.
const ORTC_TO_SDP_PARAMETERS_LOWERCASE = new Map();
for (let pair of ORTC_TO_SDP_PARAMETERS)
{
let key = pair[0];
let value = pair[1];
ORTC_TO_SDP_PARAMETERS_LOWERCASE.set(key.toLowerCase(), value);
}
module.exports = module.exports =
{ {
randomString(length) randomString(length)
...@@ -26,5 +55,41 @@ module.exports = ...@@ -26,5 +55,41 @@ module.exports =
return {}; return {};
else else
return clone(obj, false); return clone(obj, false);
},
/**
* Generate a SDP normalized parameter.
* @param {String} param - ORTC parameter name.
* @return {String} SDP parameter name.
*/
paramToSDP(param)
{
if (typeof param !== 'string' || !param)
throw new TypeError('wrong argument');
let wellKnownParam = ORTC_TO_SDP_PARAMETERS_LOWERCASE.get(param.toLowerCase());
if (wellKnownParam)
return wellKnownParam;
let newParam = '';
for (let i = 0, len = param.length; i < len; i++)
{
let c = param[i];
if (c === c.toLowerCase())
{
newParam += c;
}
else
{
if (i)
newParam += '-';
newParam += c.toLowerCase();
}
}
return newParam;
} }
}; };
'use strict'; 'use strict';
const sdpTransform = require('sdp-transform'); const sdpTransform = require('sdp-transform');
const extra = require('../../extra'); const utils = require('../../utils');
const RTCPeerConnectionCommon = require('./RTCPeerConnectionCommon'); const RTCPeerConnectionCommon = require('./RTCPeerConnectionCommon');
const RTCSessionDescription = require('../RTCSessionDescription'); const RTCSessionDescription = require('../RTCSessionDescription');
const sdpUtils = require('./sdpUtils'); const sdpUtils = require('./sdpUtils');
...@@ -257,7 +257,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon ...@@ -257,7 +257,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon
obj.fingerprint = obj.fingerprint =
{ {
type : 'sha-256', type : 'sha-256',
hash : extra.fingerprintToSDP(transport.dtlsLocalParameters.fingerprints['sha-256']) hash : transport.dtlsLocalParameters.fingerprints['sha-256']
}; };
// Create a SDP media section for each media kind. // Create a SDP media section for each media kind.
...@@ -365,7 +365,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon ...@@ -365,7 +365,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon
for (let key of Object.keys(codec.parameters)) for (let key of Object.keys(codec.parameters))
{ {
let normalizedKey = extra.paramToSDP(key); let normalizedKey = utils.paramToSDP(key);
if (paramFmtp.config) if (paramFmtp.config)
paramFmtp.config += ';'; paramFmtp.config += ';';
...@@ -507,12 +507,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon ...@@ -507,12 +507,7 @@ class RTCPeerConnectionPlanB extends RTCPeerConnectionCommon
if (!codec) if (!codec)
continue; continue;
for (let key of Object.keys(params)) codec.parameters = params;
{
let normalizedKey = extra.paramFromSDP(key);
codec.parameters[normalizedKey] = params[key];
}
} }
} }
......
'use strict'; 'use strict';
const sdpTransform = require('sdp-transform'); const sdpTransform = require('sdp-transform');
const extra = require('../../extra');
const RTCPeerConnectionCommon = require('./RTCPeerConnectionCommon'); const RTCPeerConnectionCommon = require('./RTCPeerConnectionCommon');
const RTCSessionDescription = require('../RTCSessionDescription'); const RTCSessionDescription = require('../RTCSessionDescription');
const RTCRtpTransceiver = require('./RTCRtpTransceiver'); const RTCRtpTransceiver = require('./RTCRtpTransceiver');
...@@ -324,7 +323,7 @@ class RTCPeerConnectionUnifiedPlan extends RTCPeerConnectionCommon ...@@ -324,7 +323,7 @@ class RTCPeerConnectionUnifiedPlan extends RTCPeerConnectionCommon
obj.fingerprint = obj.fingerprint =
{ {
type : 'sha-256', type : 'sha-256',
hash : extra.fingerprintToSDP(transport.dtlsLocalParameters.fingerprints['sha-256']) hash : transport.dtlsLocalParameters.fingerprints['sha-256']
}; };
// Iterate all the transceivers and add a m= section for each one. // Iterate all the transceivers and add a m= section for each one.
...@@ -389,12 +388,7 @@ class RTCPeerConnectionUnifiedPlan extends RTCPeerConnectionCommon ...@@ -389,12 +388,7 @@ class RTCPeerConnectionUnifiedPlan extends RTCPeerConnectionCommon
if (!codec) if (!codec)
continue; continue;
for (let key of Object.keys(params)) codec.parameters = params;
{
let normalizedKey = extra.paramFromSDP(key);
codec.parameters[normalizedKey] = params[key];
}
} }
} }
......
'use strict'; 'use strict';
const extra = require('../../extra'); const utils = require('../../utils');
class RTCRtpTransceiver class RTCRtpTransceiver
{ {
...@@ -228,7 +228,7 @@ class RTCRtpTransceiver ...@@ -228,7 +228,7 @@ class RTCRtpTransceiver
for (let key of Object.keys(codec.parameters)) for (let key of Object.keys(codec.parameters))
{ {
let normalizedKey = extra.paramToSDP(key); let normalizedKey = utils.paramToSDP(key);
if (paramFmtp.config) if (paramFmtp.config)
paramFmtp.config += ';'; paramFmtp.config += ';';
......
'use strict'; 'use strict';
const sdpTransform = require('sdp-transform'); const sdpTransform = require('sdp-transform');
const extra = require('../../extra');
module.exports = module.exports =
{ {
...@@ -58,12 +57,7 @@ module.exports = ...@@ -58,12 +57,7 @@ module.exports =
if (!codec) if (!codec)
continue; continue;
for (let key of Object.keys(params)) codec.parameters = params;
{
let normalizedKey = extra.paramFromSDP(key);
codec.parameters[normalizedKey] = params[key];
}
} }
} }
...@@ -166,7 +160,7 @@ module.exports = ...@@ -166,7 +160,7 @@ module.exports =
fingerprint : fingerprint :
{ {
algorithm : remoteFingerprint.type, algorithm : remoteFingerprint.type,
value : extra.fingerprintFromSDP(remoteFingerprint.hash) value : remoteFingerprint.hash
} }
}; };
......
'use strict';
const tap = require('tap');
const extra = require('../').extra;
const sdpFingerprint1 = '75:1B:81:93:B7:ED:27:7E:42:BE:D6:C4:8E:F7:04:3A:49:CE:3F:EE';
const rawFingerprint1 = '751b8193b7ed277e42bed6c48ef7043a49ce3fee';
const sdpFingerprint2 = '46:6D:6F:3D:09:A6:19:B2:27:C3:37:08:A7:CD:91:AE:0F:67:C4:BB:9A:A7:97:FD:40:BA:DF:3B:2C:C2:38:8A:38:5F:61:C2:A6:70:01:0C:7F:4D:C6:27:FF:31:5A:20:21:4B:F2:1D:B5:60:E2:4A:2E:67:31:B2:B0:2D:48:47';
const rawFingerprint2 = '466d6f3d09a619b227c33708a7cd91ae0f67c4bb9aa797fd40badf3b2cc2388a385f61c2a670010c7f4dc627ff315a20214bf21db560e24a2e6731b2b02d4847';
tap.test('extra.fingerprintFromSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.fingerprintFromSDP(sdpFingerprint1), rawFingerprint1);
t.equal(extra.fingerprintFromSDP(sdpFingerprint2), rawFingerprint2);
t.end();
});
tap.test('extra.fingerprintToSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.fingerprintToSDP(rawFingerprint1), sdpFingerprint1);
t.equal(extra.fingerprintToSDP(rawFingerprint2), sdpFingerprint2);
t.end();
});
tap.test('extra.paramFromSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.paramFromSDP('profile-level-id'), 'profileLevelId');
t.equal(extra.paramFromSDP('Packetization-MODE'), 'packetizationMode');
t.equal(extra.paramFromSDP('foo'), 'foo');
t.equal(extra.paramFromSDP('wrong-param-'), 'wrongParam');
// Test SDP codec parameters that don't follow the camelcase convention of ORTC.
t.equal(extra.paramFromSDP('maxplaybackrate'), 'maxPlaybackRate');
t.equal(extra.paramFromSDP('MAXPLAYBACKRATE'), 'maxPlaybackRate');
t.equal(extra.paramFromSDP('sprop-maxcapturerate'), 'spropMaxCaptureRate');
t.equal(extra.paramFromSDP('maxaveragebitrate'), 'maxAverageBitrate');
t.equal(extra.paramFromSDP('useinbandfec'), 'useInbandFec');
t.equal(extra.paramFromSDP('usedtx'), 'useDtx');
t.equal(extra.paramFromSDP('sprop-maxcapturerate'), 'spropMaxCaptureRate');
t.equal(extra.paramFromSDP('L'), 'l');
t.equal(extra.paramFromSDP('l'), 'l');
t.equal(extra.paramFromSDP('D'), 'd');
t.equal(extra.paramFromSDP('ToP'), 'toP');
t.end();
});
tap.test('extra.paramToSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.paramToSDP('profileLevelId'), 'profile-level-id');
t.equal(extra.paramToSDP('packetizationMode'), 'packetization-mode');
t.equal(extra.paramToSDP('Foo'), 'foo');
t.equal(extra.paramToSDP('WrongParam'), 'wrong-param');
// Test SDP codec parameters that don't follow the camelcase convention of ORTC.
t.equal(extra.paramToSDP('maxPlaybackRate'), 'maxplaybackrate');
t.equal(extra.paramToSDP('MAXPLAYBACKRATE'), 'maxplaybackrate');
t.equal(extra.paramToSDP('spropMaxCaptureRate'), 'sprop-maxcapturerate');
t.equal(extra.paramToSDP('maxAverageBitrate'), 'maxaveragebitrate');
t.equal(extra.paramToSDP('useInbandFec'), 'useinbandfec');
t.equal(extra.paramToSDP('useDtx'), 'usedtx');
t.equal(extra.paramToSDP('spropMaxCaptureRate'), 'sprop-maxcapturerate');
t.equal(extra.paramToSDP('l'), 'L');
t.equal(extra.paramToSDP('L'), 'L');
t.equal(extra.paramToSDP('d'), 'D');
t.equal(extra.paramToSDP('toP'), 'ToP');
t.end();
});
'use strict';
const tap = require('tap');
const utils = require('../lib/utils');
tap.test('utils.paramToSDP()', { timeout: 1000 }, (t) =>
{
t.equal(utils.paramToSDP('profileLevelId'), 'profile-level-id');
t.equal(utils.paramToSDP('packetizationMode'), 'packetization-mode');
t.equal(utils.paramToSDP('Foo'), 'foo');
t.equal(utils.paramToSDP('WrongParam'), 'wrong-param');
// Test SDP codec parameters that don't follow the camelcase convention of ORTC.
t.equal(utils.paramToSDP('maxPlaybackRate'), 'maxplaybackrate');
t.equal(utils.paramToSDP('MAXPLAYBACKRATE'), 'maxplaybackrate');
t.equal(utils.paramToSDP('spropMaxCaptureRate'), 'sprop-maxcapturerate');
t.equal(utils.paramToSDP('maxAverageBitrate'), 'maxaveragebitrate');
t.equal(utils.paramToSDP('useInbandFec'), 'useinbandfec');
t.equal(utils.paramToSDP('useDtx'), 'usedtx');
t.equal(utils.paramToSDP('spropMaxCaptureRate'), 'sprop-maxcapturerate');
t.equal(utils.paramToSDP('l'), 'L');
t.equal(utils.paramToSDP('L'), 'L');
t.equal(utils.paramToSDP('d'), 'D');
t.equal(utils.paramToSDP('toP'), 'ToP');
t.end();
});
...@@ -455,7 +455,7 @@ namespace RTC ...@@ -455,7 +455,7 @@ namespace RTC
FingerprintAlgorithm algorithm = it->second; FingerprintAlgorithm algorithm = it->second;
uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE];
unsigned int size{ 0 }; unsigned int size{ 0 };
char hexFingerprint[(EVP_MAX_MD_SIZE * 2) + 1]; char hexFingerprint[(EVP_MAX_MD_SIZE * 3) + 1];
const EVP_MD* hashFunction; const EVP_MD* hashFunction;
int ret; int ret;
...@@ -487,12 +487,12 @@ namespace RTC ...@@ -487,12 +487,12 @@ namespace RTC
MS_THROW_ERROR("Fingerprints generation failed"); MS_THROW_ERROR("Fingerprints generation failed");
} }
// Convert to hexadecimal format in lowecase without colons. // Convert to hexadecimal format in uppercase with colons.
for (unsigned int i{ 0 }; i < size; ++i) for (unsigned int i{ 0 }; i < size; ++i)
{ {
std::sprintf(hexFingerprint + (i * 2), "%.2x", binaryFingerprint[i]); std::sprintf(hexFingerprint + (i * 3), "%.2X:", binaryFingerprint[i]);
} }
hexFingerprint[size * 2] = '\0'; hexFingerprint[(size * 3) - 1] = '\0';
MS_DEBUG_TAG(dtls, "%-7s fingerprint: %s", algorithmString.c_str(), hexFingerprint); MS_DEBUG_TAG(dtls, "%-7s fingerprint: %s", algorithmString.c_str(), hexFingerprint);
...@@ -1014,7 +1014,7 @@ namespace RTC ...@@ -1014,7 +1014,7 @@ namespace RTC
X509* certificate; X509* certificate;
uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE];
unsigned int size{ 0 }; unsigned int size{ 0 };
char hexFingerprint[(EVP_MAX_MD_SIZE * 2) + 1]; char hexFingerprint[(EVP_MAX_MD_SIZE * 3) + 1];
const EVP_MD* hashFunction; const EVP_MD* hashFunction;
int ret; int ret;
...@@ -1048,7 +1048,6 @@ namespace RTC ...@@ -1048,7 +1048,6 @@ namespace RTC
} }
// Compare the remote fingerprint with the value given via signaling. // Compare the remote fingerprint with the value given via signaling.
ret = X509_digest(certificate, hashFunction, binaryFingerprint, &size); ret = X509_digest(certificate, hashFunction, binaryFingerprint, &size);
if (ret == 0) if (ret == 0)
{ {
...@@ -1059,12 +1058,12 @@ namespace RTC ...@@ -1059,12 +1058,12 @@ namespace RTC
return false; return false;
} }
// Convert to hexadecimal format in lowecase without colons. // Convert to hexadecimal format in uppercase with colons.
for (unsigned int i{ 0 }; i < size; ++i) for (unsigned int i{ 0 }; i < size; ++i)
{ {
std::sprintf(hexFingerprint + (i * 2), "%.2x", binaryFingerprint[i]); std::sprintf(hexFingerprint + (i * 3), "%.2X:", binaryFingerprint[i]);
} }
hexFingerprint[size * 2] = '\0'; hexFingerprint[(size * 3) - 1] = '\0';
if (this->remoteFingerprint.value != hexFingerprint) if (this->remoteFingerprint.value != hexFingerprint)
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论