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

Working on Producer

上级 97b0e4ce
...@@ -432,6 +432,17 @@ class Peer extends EnhancedEventEmitter ...@@ -432,6 +432,17 @@ class Peer extends EnhancedEventEmitter
{ {
// TODO // TODO
const { rtpParameters } = request;
console.log('------ createProducer: original rtpParameters:');
console.log(JSON.stringify(rtpParameters, null, ' '));
const rtpMap =
this._sandbox.createProducerRtpParametersMapping(rtpParameters);
console.log('------ rtp mapping::');
console.log(JSON.stringify(rtpMap, null, ' '));
return; return;
} }
......
...@@ -366,6 +366,12 @@ class Room extends EnhancedEventEmitter ...@@ -366,6 +366,12 @@ class Room extends EnhancedEventEmitter
getProducerById : (producerId) => getProducerById : (producerId) =>
{ {
return this._producers.get(producerId); return this._producers.get(producerId);
},
createProducerRtpParametersMapping : (rtpParameters) =>
{
return ortc.createProducerRtpParametersMapping(
rtpParameters, this.rtpCapabilities);
} }
}; };
......
...@@ -38,13 +38,12 @@ exports.generateRoomRtpCapabilities = function(mediaCodecs) ...@@ -38,13 +38,12 @@ exports.generateRoomRtpCapabilities = function(mediaCodecs)
for (const mediaCodec of mediaCodecs) for (const mediaCodec of mediaCodecs)
{ {
if (!isValidCodecCapability(mediaCodec)) assertCodecCapability(mediaCodec);
throw new TypeError('invalid mediaCodec');
const matchedSupportedCodec = supportedCodecs const matchedSupportedCodec = supportedCodecs
.find((supportedCodec) => .find((supportedCodec) =>
{ {
return matchCodecCapabilities(mediaCodec, supportedCodec); return matchCodec(mediaCodec, supportedCodec);
}); });
if (!matchedSupportedCodec) if (!matchedSupportedCodec)
...@@ -124,7 +123,7 @@ exports.assertCapabilitiesSubset = function(capsA, capsB) ...@@ -124,7 +123,7 @@ exports.assertCapabilitiesSubset = function(capsA, capsB)
{ {
return ( return (
codecA.preferredPayloadType === codecB.preferredPayloadType && codecA.preferredPayloadType === codecB.preferredPayloadType &&
matchCodecCapabilities(codecA, codecB) matchCodec(codecA, codecB)
); );
}); });
...@@ -155,20 +154,63 @@ exports.assertCapabilitiesSubset = function(capsA, capsB) ...@@ -155,20 +154,63 @@ exports.assertCapabilitiesSubset = function(capsA, capsB)
} }
}; };
function isValidCodecCapability(codec) /**
* Generate a mapping of RTP parameters in order to use the ids in the given
* RTP capabilities.
*
* @param {RTCRtpParameters} params
* @param {RTCRtpCapabilities} caps
*
* @return {Object}
*/
exports.createProducerRtpParametersMapping = function(params, caps)
{ {
return ( const codecPayloadTypeMap = {};
for (const codec of params.codecs)
{
const matchedCapCodec = caps.codecs
.find((capCodec) =>
{
// TODO: This is not enough for RTX since there could be multiple RTX codecs
// if simulcast.
return matchCodec(codec, capCodec, true);
});
if (!matchedCapCodec)
{
throw new Error(
'unsupported codec ' +
`[name:${codec.name}, payloadType:${codec.payloadType}]`);
}
codecPayloadTypeMap[codec.payloadType] = matchedCapCodec.preferredPayloadType;
}
return {
codecPayloadTypeMap
};
};
function assertCodecCapability(codec)
{
const valid =
(typeof codec === 'object' && !Array.isArray(codec)) && (typeof codec === 'object' && !Array.isArray(codec)) &&
(typeof codec.kind === 'string' && codec.kind) && (typeof codec.kind === 'string' && codec.kind) &&
(typeof codec.name === 'string' && codec.name) && (typeof codec.name === 'string' && codec.name) &&
(typeof codec.clockRate === 'number' && codec.clockRate) (typeof codec.clockRate === 'number' && codec.clockRate);
);
if (!valid)
throw new TypeError('invalid RTCCodecCapability');
} }
function matchCodecCapabilities(codecA, codecB) function matchCodec(codecA, codecB, isParamCodecA = false)
{ {
if (codecA.kind !== codecB.kind) if (!isParamCodecA)
return false; {
if (codecA.kind !== codecB.kind)
return false;
}
if (codecA.name.toLowerCase() !== codecB.name.toLowerCase()) if (codecA.name.toLowerCase() !== codecB.name.toLowerCase())
return false; return false;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论