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

Producer: allow RTP parameters with MID and single encoding without RID and SSRC

上级 8b7715a6
......@@ -99,7 +99,8 @@ test('webRtcTransport.produce() succeeds', async () =>
id : 12
}
],
encodings : [ { ssrc: 11111111, dtx: true } ],
// Single encoding without ssrc and rid on purpose.
encodings : [ { dtx: true } ],
rtcp :
{
cname : 'audio-1'
......@@ -398,7 +399,7 @@ test('webRtcTransport.produce() with unsupported codecs rejects with Unsupported
.toThrow(UnsupportedError);
}, 2000);
test('webRtcTransport.produce() with already used MID or SSRC rejects with Error', async () =>
test('transport.produce() with already used MID or SSRC rejects with Error', async () =>
{
await expect(webRtcTransport.produce(
{
......@@ -426,12 +427,53 @@ test('webRtcTransport.produce() with already used MID or SSRC rejects with Error
.rejects
.toThrow(Error);
await expect(plainRtpTransport.produce(
{
kind : 'video',
rtpParameters :
{
mid : 'VIDEO2',
codecs :
[
{
mimeType : 'video/h264',
payloadType : 112,
clockRate : 90000,
parameters :
{
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
}
],
headerExtensions :
[
{
uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
id : 10
}
],
encodings :
[
{ ssrc: 22222222 }
],
rtcp :
{
cname : 'video-1'
}
}
}))
.rejects
.toThrow(Error);
}, 2000);
test('transport.produce() with no MID and with single encoding without RID or SSRC rejects with Error', async () =>
{
await expect(webRtcTransport.produce(
{
kind : 'audio',
rtpParameters :
{
mid : 'AUDIO-2',
codecs :
[
{
......@@ -441,9 +483,8 @@ test('webRtcTransport.produce() with already used MID or SSRC rejects with Error
channels : 2
}
],
headerExtensions : [],
encodings : [ { ssrc: 11111111 } ],
rtcp :
encodings : [ { dtx: true } ],
rtcp :
{
cname : 'audio-2'
}
......@@ -498,7 +539,7 @@ test('producer.dump() succeeds', async () =>
expect(data.rtpParameters.encodings.length).toBe(1);
expect(data.rtpParameters.encodings).toEqual(
[
{ codecPayloadType: 111, ssrc: 11111111, dtx: true }
{ codecPayloadType: 111, dtx: true }
]);
expect(data.type).toBe('simple');
......
......@@ -58,12 +58,16 @@ namespace RTC
auto jsonPayloadTypeIt = codec.find("payloadType");
if (jsonPayloadTypeIt == codec.end() || !jsonPayloadTypeIt->is_number_unsigned())
{
MS_THROW_TYPE_ERROR("wrong entry in rtpMapping.codecs (missing payloadType)");
}
auto jsonMappedPayloadTypeIt = codec.find("mappedPayloadType");
if (jsonMappedPayloadTypeIt == codec.end() || !jsonMappedPayloadTypeIt->is_number_unsigned())
{
MS_THROW_TYPE_ERROR("wrong entry in rtpMapping.codecs (missing mappedPayloadType)");
}
this->rtpMapping.codecs[jsonPayloadTypeIt->get<uint8_t>()] =
jsonMappedPayloadTypeIt->get<uint8_t>();
......@@ -72,7 +76,9 @@ namespace RTC
auto jsonEncodingsIt = jsonRtpMappingIt->find("encodings");
if (jsonEncodingsIt == jsonRtpMappingIt->end() || !jsonEncodingsIt->is_array())
{
MS_THROW_TYPE_ERROR("missing rtpMapping.encodings");
}
this->rtpMapping.encodings.reserve(jsonEncodingsIt->size());
......@@ -97,9 +103,25 @@ namespace RTC
if (jsonRidIt != encoding.end() && jsonRidIt->is_string())
encodingMapping.rid = jsonRidIt->get<std::string>();
// However ssrc or rid must be present.
if (jsonSsrcIt == encoding.end() && jsonRidIt == encoding.end())
// However ssrc or rid must be present (if more than 1 encoding).
if (jsonEncodingsIt->size() > 1 && jsonSsrcIt == encoding.end() && jsonRidIt == encoding.end())
{
MS_THROW_TYPE_ERROR("wrong entry in rtpMapping.encodings (missing ssrc or rid)");
}
// If there is no mid and a single encoding, ssrc or rid must be present.
// clang-format off
if (
this->rtpParameters.mid.empty() &&
jsonEncodingsIt->size() == 1 &&
jsonSsrcIt == encoding.end() &&
jsonRidIt == encoding.end()
)
// clang-format on
{
MS_THROW_TYPE_ERROR(
"wrong entry in rtpMapping.encodings (missing ssrc or rid, or rtpParameters.mid)");
}
// mappedSsrc is mandatory.
auto jsonMappedSsrcIt = encoding.find("mappedSsrc");
......@@ -727,6 +749,71 @@ namespace RTC
return nullptr;
}
// If not found, and there is a single encoding, this may be a media or RTX
// stream and the single encoding does not signal nor SSRC nor RID.
//
// clang-format off
if (
this->rtpParameters.encodings.size() == 1 &&
this->mapSsrcRtpStream.size() <= 1
)
// clang-format on
{
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
bool isMediaPacket = (mediaCodec->payloadType == payloadType);
bool isRtxPacket = (rtxCodec && rtxCodec->payloadType == payloadType);
if (isMediaPacket)
{
// Ensure there is no other RTP stream already.
if (!this->mapSsrcRtpStream.empty())
{
MS_WARN_TAG(
rtp,
"ignoring packet with unknown ssrc not matching the already existing stream (single RtpStream lookup)");
return nullptr;
}
auto* rtpStream = CreateRtpStream(packet, *mediaCodec, 0);
return rtpStream;
}
else if (isRtxPacket)
{
// There must be already a media RTP stream.
auto it = this->mapSsrcRtpStream.begin();
if (it == this->mapSsrcRtpStream.end())
{
MS_DEBUG_2TAGS(
rtp, rtx, "ignoring RTX packet for not yet created RtpStream (single stream lookup)");
return nullptr;
}
auto* rtpStream = it->second;
// Ensure no RTX SSRC was previously detected.
if (rtpStream->HasRtx())
{
MS_DEBUG_2TAGS(rtp, rtx, "ignoring RTX packet with new SSRC (single stream lookup)");
return nullptr;
}
// Update the stream RTX data.
rtpStream->SetRtx(payloadType, ssrc);
// Insert the new RTX SSRC into the map.
this->mapRtxSsrcRtpStream[ssrc] = rtpStream;
return rtpStream;
}
}
return nullptr;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论