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

Modify RtpListener rules to deal with…

Modify RtpListener rules to deal with https://github.com/openpeer/ortc/pull/557#issuecomment-223127011 (solution 2 implemented)
上级 6872bd62
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
const tap = require('tap'); const tap = require('tap');
const mediasoup = require('../'); const mediasoup = require('../');
const promiseSeries = require('./utils/promiseSeries');
function initTest(t) function initTest(t)
{ {
...@@ -57,13 +58,13 @@ tap.test('rtpReceiver.receive() with no encodings must succeed', { timeout: 2000 ...@@ -57,13 +58,13 @@ tap.test('rtpReceiver.receive() with no encodings must succeed', { timeout: 2000
t.assert(rtpParameters.encodings, 'computed rtpParameters has encodings'); t.assert(rtpParameters.encodings, 'computed rtpParameters has encodings');
t.equal(rtpParameters.encodings.length, 1, 'encodings has 1 encoding'); t.equal(rtpParameters.encodings.length, 1, 'encodings has 1 encoding');
t.equal(rtpParameters.encodings[0].codecPayloadType, 100, 'encoding has matching codecPayloadType'); t.equal(rtpParameters.encodings[0].codecPayloadType, 100, 'encoding has codecPayloadType 100');
}) })
.catch((error) => t.fail(`rtpReceiver.receive() failed: ${error}`)); .catch((error) => t.fail(`rtpReceiver.receive() failed: ${error}`));
}); });
}); });
tap.test('rtpReceiver.receive() with one encoding without codecPayloadType must succeed', { timeout: 2000 }, (t) => tap.test('rtpReceiver.receive() with encodings without codecPayloadType must succeed', { timeout: 2000 }, (t) =>
{ {
return initTest(t) return initTest(t)
.then((data) => .then((data) =>
...@@ -79,12 +80,22 @@ tap.test('rtpReceiver.receive() with one encoding without codecPayloadType must ...@@ -79,12 +80,22 @@ tap.test('rtpReceiver.receive() with one encoding without codecPayloadType must
{ {
name : 'video/H264', name : 'video/H264',
payloadType : 101 payloadType : 101
},
{
name : 'video/H265',
payloadType : 102
} }
], ],
encodings : encodings :
[ [
{ {
ssrc : 1234 ssrc : 1111
},
{
codecPayloadType : 102
},
{
ssrc : 3333
} }
] ]
}) })
...@@ -94,8 +105,10 @@ tap.test('rtpReceiver.receive() with one encoding without codecPayloadType must ...@@ -94,8 +105,10 @@ tap.test('rtpReceiver.receive() with one encoding without codecPayloadType must
let rtpParameters = rtpReceiver.rtpParameters; let rtpParameters = rtpReceiver.rtpParameters;
t.equal(rtpParameters.encodings.length, 1, 'computed rtpParameters has 1 encoding'); t.equal(rtpParameters.encodings.length, 3, 'computed rtpParameters has 3 encodings');
t.equal(rtpParameters.encodings[0].codecPayloadType, 101, 'encoding has matching codecPayloadType'); t.equal(rtpParameters.encodings[0].codecPayloadType, 101, 'first encoding has codecPayloadType 101');
t.equal(rtpParameters.encodings[1].codecPayloadType, 102, 'second encoding has codecPayloadType 102');
t.equal(rtpParameters.encodings[2].codecPayloadType, 101, 'third encoding has codecPayloadType 101');
}) })
.catch((error) => t.fail(`rtpReceiver.receive() failed: ${error}`)); .catch((error) => t.fail(`rtpReceiver.receive() failed: ${error}`));
}); });
...@@ -303,9 +316,11 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -303,9 +316,11 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
let peer = data.peer; let peer = data.peer;
let transport = data.transport; let transport = data.transport;
let rtpReceiver = peer.RtpReceiver('audio', transport); let rtpReceiver = peer.RtpReceiver('audio', transport);
let promises = []; let funcs = [];
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -318,10 +333,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -318,10 +333,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() with an invalid codec.name failed: ${error}`);
})); });
});
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -333,10 +351,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -333,10 +351,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() without codec.name failed: ${error}`);
})); });
});
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -348,10 +369,36 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -348,10 +369,36 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() without codec.payloadType failed: ${error}`);
})); });
});
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 101
},
{
name : 'audio/opus',
payloadType : 101
}
]
})
.then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) =>
{
t.pass(`rtpReceiver.receive() with duplicated codec.payloadType failed: ${error}`);
});
});
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -368,10 +415,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -368,10 +415,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() with incomplete RTX codec failed: ${error}`);
})); });
});
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -392,10 +442,42 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 }, ...@@ -392,10 +442,42 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() with wrong RTX codec failed: ${error}`);
})); });
});
return Promise.all(promises); funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 100
},
{
name : 'audio/ulpfec',
payloadType : 101
},
{
name : 'audio/rtx',
payloadType : 97,
parameters :
{
apt : 101
}
}
]
})
.then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) =>
{
t.pass(`rtpReceiver.receive() with RTX codec pointing to a ULPFEC codec failed: ${error}`);
});
});
return promiseSeries(funcs);
}); });
}); });
...@@ -407,9 +489,11 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000 ...@@ -407,9 +489,11 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
let peer = data.peer; let peer = data.peer;
let transport = data.transport; let transport = data.transport;
let rtpReceiver = peer.RtpReceiver('audio', transport); let rtpReceiver = peer.RtpReceiver('audio', transport);
let promises = []; let funcs = [];
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -428,10 +512,13 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000 ...@@ -428,10 +512,13 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() with unknown encoding.codecPayloadType failed: ${error}`);
})); });
});
promises.push(rtpReceiver.receive( funcs.push(function()
{
return rtpReceiver.receive(
{ {
codecs : codecs :
[ [
...@@ -451,13 +538,14 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000 ...@@ -451,13 +538,14 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
} }
] ]
}) })
.then(() => t.fail('rtpReceiver.receive() succeeded')) .then(() => t.fail('rtpReceiver.receive() with invalid encoding.codecPayloadType succeeded'))
.catch((error) => .catch((error) =>
{ {
t.pass(`rtpReceiver.receive() failed: ${error}`); t.pass(`rtpReceiver.receive() failed: ${error}`);
})); });
});
return Promise.all(promises); return promiseSeries(funcs);
}); });
}); });
...@@ -509,6 +597,255 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu ...@@ -509,6 +597,255 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
}); });
}); });
tap.test('rtpReceiver.receive() should produce the expected RTP listener routing tables', { timeout: 2000 }, (t) =>
{
return initTest(t)
.then((data) =>
{
let peer = data.peer;
let transport = data.transport;
let rtpReceiver = peer.RtpReceiver('audio', transport);
let funcs = [];
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 100
}
]
})
.then(() =>
{
return transport.dump();
})
.then((data) =>
{
let id = rtpReceiver._internal.rtpReceiverId;
t.same(data.rtpListener,
{
muxIdTable : {},
ptTable :
{
100 : id
},
ssrcTable : {}
},
'rtpListener tables match expected ones');
});
});
funcs.push(function()
{
return rtpReceiver.receive(
{
muxId : 'qwerty1234',
codecs :
[
{
name : 'audio/opus',
payloadType : 100
},
{
name : 'audio/ulaw',
payloadType : 0
}
]
})
.then(() =>
{
return transport.dump();
})
.then((data) =>
{
let id = rtpReceiver._internal.rtpReceiverId;
t.same(data.rtpListener,
{
muxIdTable :
{
'qwerty1234' : id
},
ptTable :
{
100 : id,
0 : id
},
ssrcTable : {}
},
'rtpListener tables match expected ones');
});
});
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 100
},
{
name : 'audio/ulaw',
payloadType : 0
}
],
encodings :
[
{
codecPayloadType : 100,
ssrc : 1111
},
{
codecPayloadType : 0
}
]
})
.then(() =>
{
return transport.dump();
})
.then((data) =>
{
let id = rtpReceiver._internal.rtpReceiverId;
t.same(data.rtpListener,
{
muxIdTable : {},
ptTable :
{
100 : id,
0 : id
},
ssrcTable :
{
1111 : id
}
},
'rtpListener tables match expected ones');
});
});
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 100
},
{
name : 'audio/ulaw',
payloadType : 0
}
],
encodings :
[
{
codecPayloadType : 100,
ssrc : 1111
},
{
codecPayloadType : 0,
ssrc : 2222
}
]
})
.then(() =>
{
return transport.dump();
})
.then((data) =>
{
let id = rtpReceiver._internal.rtpReceiverId;
t.same(data.rtpListener,
{
muxIdTable : {},
ptTable : {},
ssrcTable :
{
1111 : id,
2222 : id
}
},
'rtpListener tables match expected ones');
});
});
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 100
},
{
name : 'audio/ulaw',
payloadType : 0
}
],
encodings :
[
{
codecPayloadType : 100,
ssrc : 1111,
rtx : {}
},
{
codecPayloadType : 0,
ssrc : 2222,
fec :
{
mechanism : 'flexfec',
ssrc : 3333
}
}
]
})
.then(() =>
{
return transport.dump();
})
.then((data) =>
{
let id = rtpReceiver._internal.rtpReceiverId;
t.same(data.rtpListener,
{
muxIdTable : {},
ptTable :
{
100 : id,
0 : id
},
ssrcTable :
{
1111 : id,
2222 : id,
3333 : id
}
},
'rtpListener tables match expected ones');
});
});
return promiseSeries(funcs);
});
});
tap.test('rtpReceiver.close() must succeed', { timeout: 2000 }, (t) => tap.test('rtpReceiver.close() must succeed', { timeout: 2000 }, (t) =>
{ {
return initTest(t) return initTest(t)
......
...@@ -187,7 +187,10 @@ namespace RTC ...@@ -187,7 +187,10 @@ namespace RTC
} }
} }
// Add entries into ptTable (just if no encoding.ssrc is given). // Add entries into ptTable just if:
// - Not all the encoding.ssrc are given, or
// - Not all the encoding.rtx.ssrc are given, or
// - Not all the encoding.fec.ssrc are given.
{ {
auto it = rtpParameters->encodings.begin(); auto it = rtpParameters->encodings.begin();
...@@ -195,19 +198,20 @@ namespace RTC ...@@ -195,19 +198,20 @@ namespace RTC
{ {
auto encoding = *it; auto encoding = *it;
if (encoding.ssrc) if (
!encoding.ssrc ||
(encoding.hasRtx && !encoding.rtx.ssrc) ||
(encoding.hasFec && !encoding.fec.ssrc))
{
break; break;
} }
}
if (it == rtpParameters->encodings.end()) if (it != rtpParameters->encodings.end())
{ {
for (auto& codec : rtpParameters->codecs) for (auto& codec : rtpParameters->codecs)
{ {
uint8_t payloadType; uint8_t payloadType = codec.payloadType;
// Check encoding.ssrc.
payloadType = codec.payloadType;
if (!this->HasPayloadType(payloadType, rtpReceiver)) if (!this->HasPayloadType(payloadType, rtpReceiver))
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论