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

- Allow the app specify preferredPayloadType in Router media codecs

- Limit DynamicPayloadTypes to the 96-127 range.
上级 dd18309f
......@@ -5,11 +5,9 @@ const supportedRtpCapabilities = require('./supportedRtpCapabilities');
const DynamicPayloadTypes =
[
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 96, 97, 98, 99, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 96, 97, 98, 99
];
const ScalabilityModeRegex = new RegExp('^L(\\d+)T(\\d+)');
......@@ -31,6 +29,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
else if (mediaCodecs.length === 0)
throw new TypeError('mediaCodecs cannot be empty');
const dynamicPayloadTypes = utils.clone(DynamicPayloadTypes);
const supportedCodecs = supportedRtpCapabilities.codecs;
const caps =
{
......@@ -39,8 +38,6 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
fecMechanisms : supportedRtpCapabilities.fecMechanisms
};
let dynamicPayloadTypeIdx = 0;
for (const mediaCodec of mediaCodecs)
{
assertCodecCapability(mediaCodec);
......@@ -59,6 +56,38 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
// Clone the supported codec.
const codec = utils.clone(matchedSupportedCodec);
// If the given media codec has preferredPayloadType, keep it.
if (typeof mediaCodec.preferredPayloadType === 'number')
{
codec.preferredPayloadType = mediaCodec.preferredPayloadType;
// Also remove the pt from the list of available dynamic values.
const idx = dynamicPayloadTypes.indexOf(codec.preferredPayloadType);
if (idx > -1)
dynamicPayloadTypes.splice(idx, 1);
}
// Otherwise if the supported codec has preferredPayloadType, use it.
else if (typeof codec.preferredPayloadType === 'number')
{
// No need to remove it from the list since it's not a dynamic value.
}
// Otherwise choose a dynamic one.
else
{
// Take the first available pt and remove it from the list.
const pt = dynamicPayloadTypes.shift();
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
codec.preferredPayloadType = pt;
}
// Ensure there is not duplicated preferredPayloadType values.
if (caps.codecs.some((c) => c.preferredPayloadType === codec.preferredPayloadType))
throw new Error('duplicated codec.preferredPayloadType');
// Normalize channels.
if (codec.kind !== 'audio')
delete codec.channels;
......@@ -71,24 +100,14 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
// Make rtcpFeedback an array.
codec.rtcpFeedback = codec.rtcpFeedback || [];
// Assign a payload type.
if (typeof codec.preferredPayloadType !== 'number')
{
const pt = DynamicPayloadTypes[dynamicPayloadTypeIdx++];
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
codec.preferredPayloadType = pt;
}
// Append to the codec list.
caps.codecs.push(codec);
// Add a RTX video codec if video.
if (codec.kind === 'video')
{
const pt = DynamicPayloadTypes[dynamicPayloadTypeIdx++];
// Take the first available pt and remove it from the list.
const pt = dynamicPayloadTypes.shift();
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
......
......@@ -20,9 +20,10 @@ test('generateRouterRtpCapabilities() succeeds', () =>
}
},
{
kind : 'video',
mimeType : 'video/VP8',
clockRate : 90000
kind : 'video',
preferredPayloadType : 125, // Let's force it.
mimeType : 'video/VP8',
clockRate : 90000
},
{
kind : 'video',
......@@ -47,7 +48,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
{
kind : 'audio',
mimeType : 'audio/opus',
preferredPayloadType : 100, // 100 is the first PT chosen.
preferredPayloadType : 100, // 100 is the first available dynamic PT.
clockRate : 48000,
channels : 2,
rtcpFeedback : [],
......@@ -63,7 +64,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
{
kind : 'video',
mimeType : 'video/VP8',
preferredPayloadType : 101,
preferredPayloadType : 125,
clockRate : 90000,
rtcpFeedback :
[
......@@ -81,12 +82,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
{
kind : 'video',
mimeType : 'video/rtx',
preferredPayloadType : 102,
preferredPayloadType : 101, // 101 is the second available dynamic PT.
clockRate : 90000,
rtcpFeedback : [],
parameters :
{
apt : 101
apt : 125
}
});
......@@ -95,7 +96,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
{
kind : 'video',
mimeType : 'video/H264',
preferredPayloadType : 103,
preferredPayloadType : 102, // 102 is the second available dynamic PT.
clockRate : 90000,
rtcpFeedback :
[
......@@ -120,12 +121,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
{
kind : 'video',
mimeType : 'video/rtx',
preferredPayloadType : 104,
preferredPayloadType : 103,
clockRate : 90000,
rtcpFeedback : [],
parameters :
{
apt : 103
apt : 102
}
});
});
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论