Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
1912b7fa
Unverified
提交
1912b7fa
authored
2月 24, 2023
作者:
Iñaki Baz Castillo
提交者:
GitHub
2月 24, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for RTCP NACK in OPUS (#1015)
上级
443ccf08
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
276 行增加
和
80 行删除
+276
-80
CHANGELOG.md
CHANGELOG.md
+1
-0
Consumer.ts
node/src/Consumer.ts
+10
-0
PipeTransport.ts
node/src/PipeTransport.ts
+5
-1
Transport.ts
node/src/Transport.ts
+14
-1
ortc.ts
node/src/ortc.ts
+47
-24
supportedRtpCapabilities.ts
node/src/supportedRtpCapabilities.ts
+4
-0
test-Consumer.ts
node/src/tests/test-Consumer.ts
+35
-1
test-ortc.ts
node/src/tests/test-ortc.ts
+15
-4
ortc.rs
rust/src/ortc.rs
+32
-20
tests.rs
rust/src/ortc/tests.rs
+8
-4
consumer.rs
rust/src/router/consumer.rs
+7
-0
transport.rs
rust/src/router/transport.rs
+5
-1
supported_rtp_capabilities.rs
rust/src/supported_rtp_capabilities.rs
+4
-4
consumer.rs
rust/tests/integration/consumer.rs
+44
-1
RtpStreamSend.hpp
worker/include/RTC/RtpStreamSend.hpp
+6
-3
RtpStreamSend.cpp
worker/src/RTC/RtpStreamSend.cpp
+35
-12
TestRtpStreamSend.cpp
worker/test/src/RTC/TestRtpStreamSend.cpp
+4
-4
没有找到文件。
CHANGELOG.md
浏览文件 @
1912b7fa
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
### Next
### Next
*
Add support for RTCP NACK in OPUS (
[
PR #1015
](
https://github.com/versatica/mediasoup/pull/1015
)
).
*
Update NPM deps.
*
Update NPM deps.
...
...
node/src/Consumer.ts
浏览文件 @
1912b7fa
...
@@ -50,6 +50,16 @@ export type ConsumerOptions =
...
@@ -50,6 +50,16 @@ export type ConsumerOptions =
*/
*/
preferredLayers
?:
ConsumerLayers
;
preferredLayers
?:
ConsumerLayers
;
/**
* Whether this Consumer should enable RTP retransmissions, storing sent RTP
* and processing the incoming RTCP NACK from the remote Consumer. If not set
* it's true by default for video codecs and false for audio codecs. If set
* to true, NACK will be enabled if both endpoints (mediasoup and the remote
* Consumer) support NACK for this codec. When it comes to audio codecs, just
* OPUS supports NACK.
*/
enableRtx
?:
boolean
;
/**
/**
* Whether this Consumer should ignore DTX packets (only valid for Opus codec).
* Whether this Consumer should ignore DTX packets (only valid for Opus codec).
* If set, DTX packets are not forwarded to the remote Consumer.
* If set, DTX packets are not forwarded to the remote Consumer.
...
...
node/src/PipeTransport.ts
浏览文件 @
1912b7fa
...
@@ -307,7 +307,11 @@ export class PipeTransport
...
@@ -307,7 +307,11 @@ export class PipeTransport
// This may throw.
// This may throw.
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
this
.
#
data
.
rtx
);
{
consumableRtpParameters
:
producer
.
consumableRtpParameters
,
enableRtx
:
this
.
#
data
.
rtx
}
);
const
reqData
=
const
reqData
=
{
{
...
...
node/src/Transport.ts
浏览文件 @
1912b7fa
...
@@ -660,6 +660,7 @@ export class Transport<Events extends TransportEvents = TransportEvents,
...
@@ -660,6 +660,7 @@ export class Transport<Events extends TransportEvents = TransportEvents,
mid
,
mid
,
preferredLayers
,
preferredLayers
,
ignoreDtx
=
false
,
ignoreDtx
=
false
,
enableRtx
,
pipe
=
false
,
pipe
=
false
,
appData
appData
}:
ConsumerOptions
}:
ConsumerOptions
...
@@ -690,9 +691,21 @@ export class Transport<Events extends TransportEvents = TransportEvents,
...
@@ -690,9 +691,21 @@ export class Transport<Events extends TransportEvents = TransportEvents,
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
}
}
// If enableRtx is not given, set it to true if video and false if audio.
if
(
enableRtx
===
undefined
)
{
enableRtx
=
producer
.
kind
===
'video'
;
}
// This may throw.
// This may throw.
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
rtpCapabilities
!
,
pipe
);
{
consumableRtpParameters
:
producer
.
consumableRtpParameters
,
remoteRtpCapabilities
:
rtpCapabilities
!
,
pipe
,
enableRtx
}
);
// Set MID.
// Set MID.
if
(
!
pipe
)
if
(
!
pipe
)
...
...
node/src/ortc.ts
浏览文件 @
1912b7fa
...
@@ -1109,12 +1109,21 @@ export function canConsume(
...
@@ -1109,12 +1109,21 @@ export function canConsume(
*
*
* It reduces encodings to just one and takes into account given RTP capabilities
* It reduces encodings to just one and takes into account given RTP capabilities
* to reduce codecs, codecs' RTCP feedback and header extensions, and also enables
* to reduce codecs, codecs' RTCP feedback and header extensions, and also enables
* or disable
d
RTX.
* or disable
s
RTX.
*/
*/
export
function
getConsumerRtpParameters
(
export
function
getConsumerRtpParameters
(
consumableParams
:
RtpParameters
,
{
caps
:
RtpCapabilities
,
consumableRtpParameters
,
pipe
:
boolean
remoteRtpCapabilities
,
pipe
,
enableRtx
}:
{
consumableRtpParameters
:
RtpParameters
;
remoteRtpCapabilities
:
RtpCapabilities
;
pipe
:
boolean
;
enableRtx
:
boolean
;
}
):
RtpParameters
):
RtpParameters
{
{
const
consumerParams
:
RtpParameters
=
const
consumerParams
:
RtpParameters
=
...
@@ -1122,22 +1131,27 @@ export function getConsumerRtpParameters(
...
@@ -1122,22 +1131,27 @@ export function getConsumerRtpParameters(
codecs
:
[],
codecs
:
[],
headerExtensions
:
[],
headerExtensions
:
[],
encodings
:
[],
encodings
:
[],
rtcp
:
consumable
Param
s
.
rtcp
rtcp
:
consumable
RtpParameter
s
.
rtcp
};
};
for
(
const
capCodec
of
cap
s
.
codecs
!
)
for
(
const
capCodec
of
remoteRtpCapabilitie
s
.
codecs
!
)
{
{
validateRtpCodecCapability
(
capCodec
);
validateRtpCodecCapability
(
capCodec
);
}
}
const
consumableCodecs
=
const
consumableCodecs
=
utils
.
clone
(
consumable
Param
s
.
codecs
)
as
RtpCodecParameters
[];
utils
.
clone
(
consumable
RtpParameter
s
.
codecs
)
as
RtpCodecParameters
[];
let
rtxSupported
=
false
;
let
rtxSupported
=
false
;
for
(
const
codec
of
consumableCodecs
)
for
(
const
codec
of
consumableCodecs
)
{
{
const
matchedCapCodec
=
caps
.
codecs
!
if
(
!
enableRtx
&&
isRtxCodec
(
codec
))
{
continue
;
}
const
matchedCapCodec
=
remoteRtpCapabilities
.
codecs
!
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
if
(
!
matchedCapCodec
)
if
(
!
matchedCapCodec
)
...
@@ -1145,7 +1159,10 @@ export function getConsumerRtpParameters(
...
@@ -1145,7 +1159,10 @@ export function getConsumerRtpParameters(
continue
;
continue
;
}
}
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
;
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
!
.
filter
((
fb
)
=>
(
(
enableRtx
||
fb
.
type
!==
'nack'
||
fb
.
parameter
)
));
consumerParams
.
codecs
.
push
(
codec
);
consumerParams
.
codecs
.
push
(
codec
);
}
}
...
@@ -1178,9 +1195,9 @@ export function getConsumerRtpParameters(
...
@@ -1178,9 +1195,9 @@ export function getConsumerRtpParameters(
throw
new
UnsupportedError
(
'no compatible media codecs'
);
throw
new
UnsupportedError
(
'no compatible media codecs'
);
}
}
consumerParams
.
headerExtensions
=
consumable
Param
s
.
headerExtensions
!
consumerParams
.
headerExtensions
=
consumable
RtpParameter
s
.
headerExtensions
!
.
filter
((
ext
)
=>
(
.
filter
((
ext
)
=>
(
cap
s
.
headerExtensions
!
remoteRtpCapabilitie
s
.
headerExtensions
!
.
some
((
capExt
)
=>
(
.
some
((
capExt
)
=>
(
capExt
.
preferredId
===
ext
.
id
&&
capExt
.
preferredId
===
ext
.
id
&&
capExt
.
uri
===
ext
.
uri
capExt
.
uri
===
ext
.
uri
...
@@ -1236,21 +1253,21 @@ export function getConsumerRtpParameters(
...
@@ -1236,21 +1253,21 @@ export function getConsumerRtpParameters(
consumerEncoding
.
rtx
=
{
ssrc
:
consumerEncoding
.
ssrc
!
+
1
};
consumerEncoding
.
rtx
=
{
ssrc
:
consumerEncoding
.
ssrc
!
+
1
};
}
}
// If any of the consumable
Params.encodings has scalabilityMode, process it
// If any of the consumable
RtpParameters.encodings has scalabilityMode,
// (assume all encodings have the same value).
//
process it
(assume all encodings have the same value).
const
encodingWithScalabilityMode
=
const
encodingWithScalabilityMode
=
consumable
Param
s
.
encodings
!
.
find
((
encoding
)
=>
encoding
.
scalabilityMode
);
consumable
RtpParameter
s
.
encodings
!
.
find
((
encoding
)
=>
encoding
.
scalabilityMode
);
let
scalabilityMode
=
encodingWithScalabilityMode
let
scalabilityMode
=
encodingWithScalabilityMode
?
encodingWithScalabilityMode
.
scalabilityMode
?
encodingWithScalabilityMode
.
scalabilityMode
:
undefined
;
:
undefined
;
// If there is simulast, mangle spatial layers in scalabilityMode.
// If there is simulast, mangle spatial layers in scalabilityMode.
if
(
consumable
Param
s
.
encodings
!
.
length
>
1
)
if
(
consumable
RtpParameter
s
.
encodings
!
.
length
>
1
)
{
{
const
{
temporalLayers
}
=
parseScalabilityMode
(
scalabilityMode
);
const
{
temporalLayers
}
=
parseScalabilityMode
(
scalabilityMode
);
scalabilityMode
=
`L
${
consumable
Param
s
.
encodings
!
.
length
}
T
${
temporalLayers
}
`
;
scalabilityMode
=
`L
${
consumable
RtpParameter
s
.
encodings
!
.
length
}
T
${
temporalLayers
}
`
;
}
}
if
(
scalabilityMode
)
if
(
scalabilityMode
)
...
@@ -1261,7 +1278,7 @@ export function getConsumerRtpParameters(
...
@@ -1261,7 +1278,7 @@ export function getConsumerRtpParameters(
// Use the maximum maxBitrate in any encoding and honor it in the Consumer's
// Use the maximum maxBitrate in any encoding and honor it in the Consumer's
// encoding.
// encoding.
const
maxEncodingMaxBitrate
=
const
maxEncodingMaxBitrate
=
consumable
Param
s
.
encodings
!
.
reduce
((
maxBitrate
,
encoding
)
=>
(
consumable
RtpParameter
s
.
encodings
!
.
reduce
((
maxBitrate
,
encoding
)
=>
(
encoding
.
maxBitrate
&&
encoding
.
maxBitrate
>
maxBitrate
encoding
.
maxBitrate
&&
encoding
.
maxBitrate
>
maxBitrate
?
encoding
.
maxBitrate
?
encoding
.
maxBitrate
:
maxBitrate
:
maxBitrate
...
@@ -1278,7 +1295,7 @@ export function getConsumerRtpParameters(
...
@@ -1278,7 +1295,7 @@ export function getConsumerRtpParameters(
else
else
{
{
const
consumableEncodings
=
const
consumableEncodings
=
utils
.
clone
(
consumable
Param
s
.
encodings
)
as
RtpEncodingParameters
[];
utils
.
clone
(
consumable
RtpParameter
s
.
encodings
)
as
RtpEncodingParameters
[];
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
...
@@ -1311,8 +1328,14 @@ export function getConsumerRtpParameters(
...
@@ -1311,8 +1328,14 @@ export function getConsumerRtpParameters(
* enableRtx is false, it also removes RTX and NACK support.
* enableRtx is false, it also removes RTX and NACK support.
*/
*/
export
function
getPipeConsumerRtpParameters
(
export
function
getPipeConsumerRtpParameters
(
consumableParams
:
RtpParameters
,
{
enableRtx
=
false
consumableRtpParameters
,
enableRtx
}:
{
consumableRtpParameters
:
RtpParameters
;
enableRtx
:
boolean
;
}
):
RtpParameters
):
RtpParameters
{
{
const
consumerParams
:
RtpParameters
=
const
consumerParams
:
RtpParameters
=
...
@@ -1320,11 +1343,11 @@ export function getPipeConsumerRtpParameters(
...
@@ -1320,11 +1343,11 @@ export function getPipeConsumerRtpParameters(
codecs
:
[],
codecs
:
[],
headerExtensions
:
[],
headerExtensions
:
[],
encodings
:
[],
encodings
:
[],
rtcp
:
consumable
Param
s
.
rtcp
rtcp
:
consumable
RtpParameter
s
.
rtcp
};
};
const
consumableCodecs
=
const
consumableCodecs
=
utils
.
clone
(
consumable
Param
s
.
codecs
)
as
RtpCodecParameters
[];
utils
.
clone
(
consumable
RtpParameter
s
.
codecs
)
as
RtpCodecParameters
[];
for
(
const
codec
of
consumableCodecs
)
for
(
const
codec
of
consumableCodecs
)
{
{
...
@@ -1344,7 +1367,7 @@ export function getPipeConsumerRtpParameters(
...
@@ -1344,7 +1367,7 @@ export function getPipeConsumerRtpParameters(
}
}
// Reduce RTP extensions by disabling transport MID and BWE related ones.
// Reduce RTP extensions by disabling transport MID and BWE related ones.
consumerParams
.
headerExtensions
=
consumable
Param
s
.
headerExtensions
!
consumerParams
.
headerExtensions
=
consumable
RtpParameter
s
.
headerExtensions
!
.
filter
((
ext
)
=>
(
.
filter
((
ext
)
=>
(
ext
.
uri
!==
'urn:ietf:params:rtp-hdrext:sdes:mid'
&&
ext
.
uri
!==
'urn:ietf:params:rtp-hdrext:sdes:mid'
&&
ext
.
uri
!==
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
&&
ext
.
uri
!==
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
&&
...
@@ -1352,7 +1375,7 @@ export function getPipeConsumerRtpParameters(
...
@@ -1352,7 +1375,7 @@ export function getPipeConsumerRtpParameters(
));
));
const
consumableEncodings
=
const
consumableEncodings
=
utils
.
clone
(
consumable
Param
s
.
encodings
)
as
RtpEncodingParameters
[];
utils
.
clone
(
consumable
RtpParameter
s
.
encodings
)
as
RtpEncodingParameters
[];
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
...
...
node/src/supportedRtpCapabilities.ts
浏览文件 @
1912b7fa
...
@@ -11,6 +11,7 @@ const supportedRtpCapabilities: RtpCapabilities =
...
@@ -11,6 +11,7 @@ const supportedRtpCapabilities: RtpCapabilities =
channels
:
2
,
channels
:
2
,
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
}
]
]
},
},
...
@@ -28,6 +29,7 @@ const supportedRtpCapabilities: RtpCapabilities =
...
@@ -28,6 +29,7 @@ const supportedRtpCapabilities: RtpCapabilities =
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
}
]
]
},
},
...
@@ -45,6 +47,7 @@ const supportedRtpCapabilities: RtpCapabilities =
...
@@ -45,6 +47,7 @@ const supportedRtpCapabilities: RtpCapabilities =
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
}
]
]
},
},
...
@@ -62,6 +65,7 @@ const supportedRtpCapabilities: RtpCapabilities =
...
@@ -62,6 +65,7 @@ const supportedRtpCapabilities: RtpCapabilities =
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
}
]
]
},
},
...
...
node/src/tests/test-Consumer.ts
浏览文件 @
1912b7fa
...
@@ -152,7 +152,11 @@ const consumerDeviceCapabilities: mediasoup.types.RtpCapabilities =
...
@@ -152,7 +152,11 @@ const consumerDeviceCapabilities: mediasoup.types.RtpCapabilities =
kind
:
'audio'
,
kind
:
'audio'
,
preferredPayloadType
:
100
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
clockRate
:
48000
,
channels
:
2
channels
:
2
,
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
}
]
},
},
{
{
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
...
@@ -495,6 +499,36 @@ test('transport.consume() succeeds', async () =>
...
@@ -495,6 +499,36 @@ test('transport.consume() succeeds', async () =>
});
});
},
2000
);
},
2000
);
test
(
'transport.consume() with enableRtx succeeds'
,
async
()
=>
{
const
audioConsumer2
=
await
transport2
.
consume
(
{
producerId
:
audioProducer
.
id
,
rtpCapabilities
:
consumerDeviceCapabilities
,
enableRtx
:
true
});
expect
(
audioConsumer2
.
kind
).
toBe
(
'audio'
);
expect
(
audioConsumer2
.
rtpParameters
.
codecs
.
length
).
toBe
(
1
);
expect
(
audioConsumer2
.
rtpParameters
.
codecs
[
0
]).
toEqual
(
{
mimeType
:
'audio/opus'
,
payloadType
:
100
,
clockRate
:
48000
,
channels
:
2
,
parameters
:
{
useinbandfec
:
1
,
usedtx
:
1
,
foo
:
222.222
,
bar
:
'333'
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
}
]
});
audioConsumer2
.
close
();
},
2000
);
test
(
'transport.consume() can be created with user provided mid'
,
async
()
=>
test
(
'transport.consume() can be created with user provided mid'
,
async
()
=>
{
{
const
audioConsumer1
=
await
transport2
.
consume
(
const
audioConsumer1
=
await
transport2
.
consume
(
...
...
node/src/tests/test-ortc.ts
浏览文件 @
1912b7fa
...
@@ -56,6 +56,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -56,6 +56,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'transport-cc'
,
parameter
:
''
}
{
type
:
'transport-cc'
,
parameter
:
''
}
]
]
});
});
...
@@ -431,8 +432,14 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -431,8 +432,14 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
]
]
};
};
const
consumerRtpParameters
=
const
consumerRtpParameters
=
ortc
.
getConsumerRtpParameters
(
ortc
.
getConsumerRtpParameters
(
consumableRtpParameters
,
remoteRtpCapabilities
,
false
);
{
consumableRtpParameters
,
remoteRtpCapabilities
,
pipe
:
false
,
enableRtx
:
true
}
);
expect
(
consumerRtpParameters
.
codecs
.
length
).
toEqual
(
2
);
expect
(
consumerRtpParameters
.
codecs
.
length
).
toEqual
(
2
);
expect
(
consumerRtpParameters
.
codecs
[
0
]).
toEqual
(
expect
(
consumerRtpParameters
.
codecs
[
0
]).
toEqual
(
...
@@ -501,8 +508,12 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -501,8 +508,12 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mux
:
true
mux
:
true
});
});
const
pipeConsumerRtpParameters
=
const
pipeConsumerRtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
ortc
.
getPipeConsumerRtpParameters
(
consumableRtpParameters
);
{
consumableRtpParameters
,
enableRtx
:
false
}
);
expect
(
pipeConsumerRtpParameters
.
codecs
.
length
).
toEqual
(
1
);
expect
(
pipeConsumerRtpParameters
.
codecs
.
length
).
toEqual
(
1
);
expect
(
pipeConsumerRtpParameters
.
codecs
[
0
]).
toEqual
(
expect
(
pipeConsumerRtpParameters
.
codecs
[
0
]).
toEqual
(
...
...
rust/src/ortc.rs
浏览文件 @
1912b7fa
...
@@ -641,29 +641,40 @@ pub(crate) fn can_consume(
...
@@ -641,29 +641,40 @@ pub(crate) fn can_consume(
/// codecs' RTCP feedback and header extensions, and also enables or disabled RTX.
/// codecs' RTCP feedback and header extensions, and also enables or disabled RTX.
#[allow(clippy
::
suspicious_operation_groupings)]
#[allow(clippy
::
suspicious_operation_groupings)]
pub
(
crate
)
fn
get_consumer_rtp_parameters
(
pub
(
crate
)
fn
get_consumer_rtp_parameters
(
consumable_
param
s
:
&
RtpParameters
,
consumable_
rtp_parameter
s
:
&
RtpParameters
,
cap
s
:
&
RtpCapabilities
,
remote_rtp_capabilitie
s
:
&
RtpCapabilities
,
pipe
:
bool
,
pipe
:
bool
,
enable_rtx
:
bool
,
)
->
Result
<
RtpParameters
,
ConsumerRtpParametersError
>
{
)
->
Result
<
RtpParameters
,
ConsumerRtpParametersError
>
{
let
mut
consumer_params
=
RtpParameters
{
let
mut
consumer_params
=
RtpParameters
{
rtcp
:
consumable_
param
s
.rtcp
.clone
(),
rtcp
:
consumable_
rtp_parameter
s
.rtcp
.clone
(),
..
RtpParameters
::
default
()
..
RtpParameters
::
default
()
};
};
for
cap_codec
in
&
cap
s
.codecs
{
for
cap_codec
in
&
remote_rtp_capabilitie
s
.codecs
{
validate_rtp_codec_capability
(
cap_codec
)
validate_rtp_codec_capability
(
cap_codec
)
.map_err
(
ConsumerRtpParametersError
::
InvalidCapabilities
)
?
;
.map_err
(
ConsumerRtpParametersError
::
InvalidCapabilities
)
?
;
}
}
let
mut
rtx_supported
=
false
;
let
mut
rtx_supported
=
false
;
for
mut
codec
in
consumable_params
.codecs
.clone
()
{
for
mut
codec
in
consumable_rtp_parameters
.codecs
.clone
()
{
if
let
Some
(
matched_cap_codec
)
=
caps
if
!
enable_rtx
&&
codec
.is_rtx
()
{
continue
;
}
if
let
Some
(
matched_cap_codec
)
=
remote_rtp_capabilities
.codecs
.codecs
.iter
()
.iter
()
.find
(|
cap_codec
|
match_codecs
(
cap_codec
.deref
()
.into
(),
(
&
codec
)
.into
(),
true
)
.is_ok
())
.find
(|
cap_codec
|
match_codecs
(
cap_codec
.deref
()
.into
(),
(
&
codec
)
.into
(),
true
)
.is_ok
())
{
{
*
codec
.rtcp_feedback_mut
()
=
matched_cap_codec
.rtcp_feedback
()
.clone
();
*
codec
.rtcp_feedback_mut
()
=
matched_cap_codec
.rtcp_feedback
()
.iter
()
.filter
(|
&&
fb
|
enable_rtx
||
fb
!=
RtcpFeedback
::
Nack
)
.copied
()
.collect
();
consumer_params
.codecs
.push
(
codec
);
consumer_params
.codecs
.push
(
codec
);
}
}
}
}
...
@@ -697,11 +708,12 @@ pub(crate) fn get_consumer_rtp_parameters(
...
@@ -697,11 +708,12 @@ pub(crate) fn get_consumer_rtp_parameters(
return
Err
(
ConsumerRtpParametersError
::
NoCompatibleMediaCodecs
);
return
Err
(
ConsumerRtpParametersError
::
NoCompatibleMediaCodecs
);
}
}
consumer_params
.header_extensions
=
consumable_
param
s
consumer_params
.header_extensions
=
consumable_
rtp_parameter
s
.header_extensions
.header_extensions
.iter
()
.iter
()
.filter
(|
ext
|
{
.filter
(|
ext
|
{
caps
.header_extensions
remote_rtp_capabilities
.header_extensions
.iter
()
.iter
()
.any
(|
cap_ext
|
cap_ext
.preferred_id
==
ext
.id
&&
cap_ext
.uri
==
ext
.uri
)
.any
(|
cap_ext
|
cap_ext
.preferred_id
==
ext
.id
&&
cap_ext
.uri
==
ext
.uri
)
})
})
...
@@ -738,7 +750,7 @@ pub(crate) fn get_consumer_rtp_parameters(
...
@@ -738,7 +750,7 @@ pub(crate) fn get_consumer_rtp_parameters(
}
}
if
pipe
{
if
pipe
{
for
((
encoding
,
ssrc
),
rtx_ssrc
)
in
consumable_
param
s
for
((
encoding
,
ssrc
),
rtx_ssrc
)
in
consumable_
rtp_parameter
s
.encodings
.encodings
.iter
()
.iter
()
.zip
(
generate_ssrc
()
..
)
.zip
(
generate_ssrc
()
..
)
...
@@ -766,19 +778,19 @@ pub(crate) fn get_consumer_rtp_parameters(
...
@@ -766,19 +778,19 @@ pub(crate) fn get_consumer_rtp_parameters(
});
});
}
}
// If any of the consumable_
param
s.encodings has scalability_mode, process it
// If any of the consumable_
rtp_parameter
s.encodings has scalability_mode, process it
// (assume all encodings have the same value).
// (assume all encodings have the same value).
let
mut
scalability_mode
=
consumable_
param
s
let
mut
scalability_mode
=
consumable_
rtp_parameter
s
.encodings
.encodings
.get
(
0
)
.get
(
0
)
.map
(|
encoding
|
encoding
.scalability_mode
.clone
())
.map
(|
encoding
|
encoding
.scalability_mode
.clone
())
.unwrap_or_default
();
.unwrap_or_default
();
// If there is simulcast, mangle spatial layers in scalabilityMode.
// If there is simulcast, mangle spatial layers in scalabilityMode.
if
consumable_
param
s
.encodings
.len
()
>
1
{
if
consumable_
rtp_parameter
s
.encodings
.len
()
>
1
{
scalability_mode
=
format!
(
scalability_mode
=
format!
(
"L{}T{}"
,
"L{}T{}"
,
consumable_
param
s
.encodings
.len
(),
consumable_
rtp_parameter
s
.encodings
.len
(),
scalability_mode
.temporal_layers
()
scalability_mode
.temporal_layers
()
)
)
.parse
()
.parse
()
...
@@ -788,7 +800,7 @@ pub(crate) fn get_consumer_rtp_parameters(
...
@@ -788,7 +800,7 @@ pub(crate) fn get_consumer_rtp_parameters(
consumer_encoding
.scalability_mode
=
scalability_mode
;
consumer_encoding
.scalability_mode
=
scalability_mode
;
// Use the maximum max_bitrate in any encoding and honor it in the Consumer's encoding.
// Use the maximum max_bitrate in any encoding and honor it in the Consumer's encoding.
consumer_encoding
.max_bitrate
=
consumable_
param
s
consumer_encoding
.max_bitrate
=
consumable_
rtp_parameter
s
.encodings
.encodings
.iter
()
.iter
()
.map
(|
encoding
|
encoding
.max_bitrate
)
.map
(|
encoding
|
encoding
.max_bitrate
)
...
@@ -807,7 +819,7 @@ pub(crate) fn get_consumer_rtp_parameters(
...
@@ -807,7 +819,7 @@ pub(crate) fn get_consumer_rtp_parameters(
/// It keeps all original consumable encodings and removes support for BWE. If
/// It keeps all original consumable encodings and removes support for BWE. If
/// enableRtx is false, it also removes RTX and NACK support.
/// enableRtx is false, it also removes RTX and NACK support.
pub
(
crate
)
fn
get_pipe_consumer_rtp_parameters
(
pub
(
crate
)
fn
get_pipe_consumer_rtp_parameters
(
consumable_
param
s
:
&
RtpParameters
,
consumable_
rtp_parameter
s
:
&
RtpParameters
,
enable_rtx
:
bool
,
enable_rtx
:
bool
,
)
->
RtpParameters
{
)
->
RtpParameters
{
let
mut
consumer_params
=
RtpParameters
{
let
mut
consumer_params
=
RtpParameters
{
...
@@ -815,10 +827,10 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
...
@@ -815,10 +827,10 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
codecs
:
vec!
[],
codecs
:
vec!
[],
header_extensions
:
vec!
[],
header_extensions
:
vec!
[],
encodings
:
vec!
[],
encodings
:
vec!
[],
rtcp
:
consumable_
param
s
.rtcp
.clone
(),
rtcp
:
consumable_
rtp_parameter
s
.rtcp
.clone
(),
};
};
for
codec
in
&
consumable_
param
s
.codecs
{
for
codec
in
&
consumable_
rtp_parameter
s
.codecs
{
if
!
enable_rtx
&&
codec
.is_rtx
()
{
if
!
enable_rtx
&&
codec
.is_rtx
()
{
continue
;
continue
;
}
}
...
@@ -834,7 +846,7 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
...
@@ -834,7 +846,7 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
}
}
// Reduce RTP extensions by disabling transport MID and BWE related ones.
// Reduce RTP extensions by disabling transport MID and BWE related ones.
consumer_params
.header_extensions
=
consumable_
param
s
consumer_params
.header_extensions
=
consumable_
rtp_parameter
s
.header_extensions
.header_extensions
.iter
()
.iter
()
.filter
(|
ext
|
{
.filter
(|
ext
|
{
...
@@ -848,7 +860,7 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
...
@@ -848,7 +860,7 @@ pub(crate) fn get_pipe_consumer_rtp_parameters(
.cloned
()
.cloned
()
.collect
();
.collect
();
for
((
encoding
,
ssrc
),
rtx_ssrc
)
in
consumable_
param
s
for
((
encoding
,
ssrc
),
rtx_ssrc
)
in
consumable_
rtp_parameter
s
.encodings
.encodings
.iter
()
.iter
()
.zip
(
generate_ssrc
()
..
)
.zip
(
generate_ssrc
()
..
)
...
...
rust/src/ortc/tests.rs
浏览文件 @
1912b7fa
...
@@ -51,7 +51,7 @@ fn generate_router_rtp_capabilities_succeeds() {
...
@@ -51,7 +51,7 @@ fn generate_router_rtp_capabilities_succeeds() {
(
"useinbandfec"
,
1
_u32
.into
()),
(
"useinbandfec"
,
1
_u32
.into
()),
(
"foo"
,
"bar"
.into
()),
(
"foo"
,
"bar"
.into
()),
]),
]),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
TransportCc
],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
,
RtcpFeedback
::
TransportCc
,
],
},
},
RtpCodecCapabilityFinalized
::
Video
{
RtpCodecCapabilityFinalized
::
Video
{
mime_type
:
MimeTypeVideo
::
Vp8
,
mime_type
:
MimeTypeVideo
::
Vp8
,
...
@@ -451,9 +451,13 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
...
@@ -451,9 +451,13 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
],
],
};
};
let
consumer_rtp_parameters
=
let
consumer_rtp_parameters
=
get_consumer_rtp_parameters
(
get_consumer_rtp_parameters
(
&
consumable_rtp_parameters
,
&
remote_rtp_capabilities
,
false
)
&
consumable_rtp_parameters
,
.expect
(
"Failed to get consumer RTP parameters"
);
&
remote_rtp_capabilities
,
false
,
true
,
)
.expect
(
"Failed to get consumer RTP parameters"
);
assert_eq!
(
assert_eq!
(
consumer_rtp_parameters
.codecs
,
consumer_rtp_parameters
.codecs
,
...
...
rust/src/router/consumer.rs
浏览文件 @
1912b7fa
...
@@ -77,6 +77,12 @@ pub struct ConsumerOptions {
...
@@ -77,6 +77,12 @@ pub struct ConsumerOptions {
/// Preferred spatial and temporal layer for simulcast or SVC media sources.
/// Preferred spatial and temporal layer for simulcast or SVC media sources.
/// If `None`, the highest ones are selected.
/// If `None`, the highest ones are selected.
pub
preferred_layers
:
Option
<
ConsumerLayers
>
,
pub
preferred_layers
:
Option
<
ConsumerLayers
>
,
/// Whether this Consumer should enable RTP retransmissions, storing sent RTP and processing the
/// incoming RTCP NACK from the remote Consumer. If not set it's true by default for video codecs
/// and false for audio codecs. If set to true, NACK will be enabled if both endpoints (mediasoup
/// and the remote Consumer) support NACK for this codec. When it comes to audio codecs, just
/// OPUS supports NACK.
pub
enable_rtx
:
Option
<
bool
>
,
/// Whether this Consumer should ignore DTX packets (only valid for Opus codec).
/// Whether this Consumer should ignore DTX packets (only valid for Opus codec).
/// If set, DTX packets are not forwarded to the remote Consumer.
/// If set, DTX packets are not forwarded to the remote Consumer.
pub
ignore_dtx
:
bool
,
pub
ignore_dtx
:
bool
,
...
@@ -96,6 +102,7 @@ impl ConsumerOptions {
...
@@ -96,6 +102,7 @@ impl ConsumerOptions {
paused
:
false
,
paused
:
false
,
preferred_layers
:
None
,
preferred_layers
:
None
,
ignore_dtx
:
false
,
ignore_dtx
:
false
,
enable_rtx
:
None
,
pipe
:
false
,
pipe
:
false
,
mid
:
None
,
mid
:
None
,
app_data
:
AppData
::
default
(),
app_data
:
AppData
::
default
(),
...
...
rust/src/router/transport.rs
浏览文件 @
1912b7fa
...
@@ -13,7 +13,7 @@ pub use crate::ortc::{
...
@@ -13,7 +13,7 @@ pub use crate::ortc::{
};
};
use
crate
::
producer
::{
Producer
,
ProducerId
,
ProducerOptions
};
use
crate
::
producer
::{
Producer
,
ProducerId
,
ProducerOptions
};
use
crate
::
router
::
Router
;
use
crate
::
router
::
Router
;
use
crate
::
rtp_parameters
::
RtpEncodingParameters
;
use
crate
::
rtp_parameters
::
{
MediaKind
,
RtpEncodingParameters
}
;
use
crate
::
sctp_parameters
::
SctpStreamParameters
;
use
crate
::
sctp_parameters
::
SctpStreamParameters
;
use
crate
::
worker
::{
Channel
,
PayloadChannel
,
RequestError
};
use
crate
::
worker
::{
Channel
,
PayloadChannel
,
RequestError
};
use
crate
::{
ortc
,
uuid_based_wrapper_type
};
use
crate
::{
ortc
,
uuid_based_wrapper_type
};
...
@@ -508,6 +508,7 @@ pub(super) trait TransportImpl: TransportGeneric {
...
@@ -508,6 +508,7 @@ pub(super) trait TransportImpl: TransportGeneric {
paused
,
paused
,
mid
,
mid
,
preferred_layers
,
preferred_layers
,
enable_rtx
,
ignore_dtx
,
ignore_dtx
,
pipe
,
pipe
,
app_data
,
app_data
,
...
@@ -522,6 +523,8 @@ pub(super) trait TransportImpl: TransportGeneric {
...
@@ -522,6 +523,8 @@ pub(super) trait TransportImpl: TransportGeneric {
}
}
};
};
let
enable_rtx
=
enable_rtx
.unwrap_or
(
producer
.kind
()
==
MediaKind
::
Video
);
let
rtp_parameters
=
if
transport_type
==
TransportType
::
Pipe
{
let
rtp_parameters
=
if
transport_type
==
TransportType
::
Pipe
{
ortc
::
get_pipe_consumer_rtp_parameters
(
producer
.consumable_rtp_parameters
(),
rtx
)
ortc
::
get_pipe_consumer_rtp_parameters
(
producer
.consumable_rtp_parameters
(),
rtx
)
}
else
{
}
else
{
...
@@ -529,6 +532,7 @@ pub(super) trait TransportImpl: TransportGeneric {
...
@@ -529,6 +532,7 @@ pub(super) trait TransportImpl: TransportGeneric {
producer
.consumable_rtp_parameters
(),
producer
.consumable_rtp_parameters
(),
&
rtp_capabilities
,
&
rtp_capabilities
,
pipe
,
pipe
,
enable_rtx
,
)
)
.map_err
(
ConsumeError
::
BadConsumerRtpParameters
)
?
;
.map_err
(
ConsumeError
::
BadConsumerRtpParameters
)
?
;
...
...
rust/src/supported_rtp_capabilities.rs
浏览文件 @
1912b7fa
...
@@ -26,7 +26,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
...
@@ -26,7 +26,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
clock_rate
:
NonZeroU32
::
new
(
48000
)
.unwrap
(),
clock_rate
:
NonZeroU32
::
new
(
48000
)
.unwrap
(),
channels
:
NonZeroU8
::
new
(
2
)
.unwrap
(),
channels
:
NonZeroU8
::
new
(
2
)
.unwrap
(),
parameters
:
RtpCodecParametersParameters
::
default
(),
parameters
:
RtpCodecParametersParameters
::
default
(),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
TransportCc
],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
,
RtcpFeedback
::
TransportCc
],
},
},
RtpCodecCapability
::
Audio
{
RtpCodecCapability
::
Audio
{
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
...
@@ -39,7 +39,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
...
@@ -39,7 +39,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
(
"num_streams"
,
2
_u32
.into
()),
(
"num_streams"
,
2
_u32
.into
()),
(
"coupled_streams"
,
2
_u32
.into
()),
(
"coupled_streams"
,
2
_u32
.into
()),
]),
]),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
TransportCc
],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
,
RtcpFeedback
::
TransportCc
],
},
},
RtpCodecCapability
::
Audio
{
RtpCodecCapability
::
Audio
{
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
...
@@ -52,7 +52,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
...
@@ -52,7 +52,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
(
"num_streams"
,
4
_u32
.into
()),
(
"num_streams"
,
4
_u32
.into
()),
(
"coupled_streams"
,
2
_u32
.into
()),
(
"coupled_streams"
,
2
_u32
.into
()),
]),
]),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
TransportCc
],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
,
RtcpFeedback
::
TransportCc
],
},
},
RtpCodecCapability
::
Audio
{
RtpCodecCapability
::
Audio
{
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
mime_type
:
MimeTypeAudio
::
MultiChannelOpus
,
...
@@ -65,7 +65,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
...
@@ -65,7 +65,7 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
(
"num_streams"
,
5
_u32
.into
()),
(
"num_streams"
,
5
_u32
.into
()),
(
"coupled_streams"
,
3
_u32
.into
()),
(
"coupled_streams"
,
3
_u32
.into
()),
]),
]),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
TransportCc
],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
,
RtcpFeedback
::
TransportCc
],
},
},
RtpCodecCapability
::
Audio
{
RtpCodecCapability
::
Audio
{
mime_type
:
MimeTypeAudio
::
Pcmu
,
mime_type
:
MimeTypeAudio
::
Pcmu
,
...
...
rust/tests/integration/consumer.rs
浏览文件 @
1912b7fa
...
@@ -199,7 +199,7 @@ fn consumer_device_capabilities() -> RtpCapabilities {
...
@@ -199,7 +199,7 @@ fn consumer_device_capabilities() -> RtpCapabilities {
clock_rate
:
NonZeroU32
::
new
(
48000
)
.unwrap
(),
clock_rate
:
NonZeroU32
::
new
(
48000
)
.unwrap
(),
channels
:
NonZeroU8
::
new
(
2
)
.unwrap
(),
channels
:
NonZeroU8
::
new
(
2
)
.unwrap
(),
parameters
:
RtpCodecParametersParameters
::
default
(),
parameters
:
RtpCodecParametersParameters
::
default
(),
rtcp_feedback
:
vec!
[],
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
],
},
},
RtpCodecCapability
::
Video
{
RtpCodecCapability
::
Video
{
mime_type
:
MimeTypeVideo
::
H264
,
mime_type
:
MimeTypeVideo
::
H264
,
...
@@ -698,6 +698,49 @@ fn consume_succeeds() {
...
@@ -698,6 +698,49 @@ fn consume_succeeds() {
});
});
}
}
#[test]
fn
consume_with_enable_rtx_succeeds
()
{
future
::
block_on
(
async
move
{
let
(
_executor_guard
,
_worker
,
_router
,
transport_1
,
transport_2
)
=
init
()
.await
;
let
audio_producer
=
transport_1
.produce
(
audio_producer_options
())
.await
.expect
(
"Failed to produce audio"
);
let
consumer_device_capabilities
=
consumer_device_capabilities
();
let
audio_consumer
=
transport_2
.consume
({
let
mut
options
=
ConsumerOptions
::
new
(
audio_producer
.id
(),
consumer_device_capabilities
.clone
());
options
.enable_rtx
=
Some
(
true
);
options
})
.await
.expect
(
"Failed to consume audio"
);
assert_eq!
(
audio_consumer
.kind
(),
MediaKind
::
Audio
);
assert_eq!
(
audio_consumer
.rtp_parameters
()
.mid
,
Some
(
"0"
.to_string
()));
assert_eq!
(
audio_consumer
.rtp_parameters
()
.codecs
,
vec!
[
RtpCodecParameters
::
Audio
{
mime_type
:
MimeTypeAudio
::
Opus
,
payload_type
:
100
,
clock_rate
:
NonZeroU32
::
new
(
48000
)
.unwrap
(),
channels
:
NonZeroU8
::
new
(
2
)
.unwrap
(),
parameters
:
RtpCodecParametersParameters
::
from
([
(
"useinbandfec"
,
1
_u32
.into
()),
(
"usedtx"
,
1
_u32
.into
()),
(
"foo"
,
"222.222"
.into
()),
(
"bar"
,
"333"
.into
()),
]),
rtcp_feedback
:
vec!
[
RtcpFeedback
::
Nack
],
}]
);
});
}
#[test]
#[test]
fn
consumer_with_user_defined_mid
()
{
fn
consumer_with_user_defined_mid
()
{
future
::
block_on
(
async
move
{
future
::
block_on
(
async
move
{
...
...
worker/include/RTC/RtpStreamSend.hpp
浏览文件 @
1912b7fa
...
@@ -12,8 +12,10 @@ namespace RTC
...
@@ -12,8 +12,10 @@ namespace RTC
public
:
public
:
// Minimum retransmission buffer size (ms).
// Minimum retransmission buffer size (ms).
const
static
uint32_t
MinRetransmissionDelayMs
;
const
static
uint32_t
MinRetransmissionDelayMs
;
// Maximum retransmission buffer size (ms).
// Maximum retransmission buffer size for video (ms).
const
static
uint32_t
MaxRetransmissionDelayMs
;
const
static
uint32_t
MaxRetransmissionDelayForVideoMs
;
// Maximum retransmission buffer size for audio (ms).
const
static
uint32_t
MaxRetransmissionDelayForAudioMs
;
public
:
public
:
class
Listener
:
public
RTC
::
RtpStream
::
Listener
class
Listener
:
public
RTC
::
RtpStream
::
Listener
...
@@ -46,7 +48,7 @@ namespace RTC
...
@@ -46,7 +48,7 @@ namespace RTC
// Special container that stores `StorageItem*` elements addressable by
// Special container that stores `StorageItem*` elements addressable by
// their `uint16_t` sequence number, while only taking as little memory as
// their `uint16_t` sequence number, while only taking as little memory as
// necessary to store the range covering a maximum of
// necessary to store the range covering a maximum of
// MaxRetransmissionDelay
Ms millisecond
s.
// MaxRetransmissionDelay
ForVideoMs or MaxRetransmissionDelayForAudioMs m
s.
class
StorageItemBuffer
class
StorageItemBuffer
{
{
public
:
public
:
...
@@ -101,6 +103,7 @@ namespace RTC
...
@@ -101,6 +103,7 @@ namespace RTC
uint32_t
sentPriorScore
{
0u
};
// Packets sent at last interval for score calculation.
uint32_t
sentPriorScore
{
0u
};
// Packets sent at last interval for score calculation.
StorageItemBuffer
storageItemBuffer
;
StorageItemBuffer
storageItemBuffer
;
std
::
string
mid
;
std
::
string
mid
;
uint32_t
maxRetransmissionDelayMs
;
uint32_t
retransmissionBufferSize
;
uint32_t
retransmissionBufferSize
;
uint16_t
rtxSeq
{
0u
};
uint16_t
rtxSeq
{
0u
};
RTC
::
RtpDataCounter
transmissionCounter
;
RTC
::
RtpDataCounter
transmissionCounter
;
...
...
worker/src/RTC/RtpStreamSend.cpp
浏览文件 @
1912b7fa
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "RTC/RtpStreamSend.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "Logger.hpp"
#include "Logger.hpp"
#include "Utils.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/SeqManager.hpp"
#include "RTC/SeqManager.hpp"
namespace
RTC
namespace
RTC
...
@@ -19,10 +20,9 @@ namespace RTC
...
@@ -19,10 +20,9 @@ namespace RTC
/* Class Static. */
/* Class Static. */
// Minimum retransmission buffer size (ms).
const
uint32_t
RtpStreamSend
::
MinRetransmissionDelayMs
{
200u
};
const
uint32_t
RtpStreamSend
::
MinRetransmissionDelayMs
{
200u
};
// Maximum retransmission buffer size (ms).
const
uint32_t
RtpStreamSend
::
MaxRetransmissionDelayForVideoMs
{
2000u
};
const
uint32_t
RtpStreamSend
::
MaxRetransmissionDelay
Ms
{
2
000u
};
const
uint32_t
RtpStreamSend
::
MaxRetransmissionDelay
ForAudioMs
{
1
000u
};
void
RtpStreamSend
::
StorageItem
::
Reset
()
void
RtpStreamSend
::
StorageItem
::
Reset
()
{
{
...
@@ -168,10 +168,33 @@ namespace RTC
...
@@ -168,10 +168,33 @@ namespace RTC
RtpStreamSend
::
RtpStreamSend
(
RtpStreamSend
::
RtpStreamSend
(
RTC
::
RtpStreamSend
::
Listener
*
listener
,
RTC
::
RtpStream
::
Params
&
params
,
std
::
string
&
mid
)
RTC
::
RtpStreamSend
::
Listener
*
listener
,
RTC
::
RtpStream
::
Params
&
params
,
std
::
string
&
mid
)
:
RTC
::
RtpStream
::
RtpStream
(
listener
,
params
,
10
),
mid
(
mid
),
:
RTC
::
RtpStream
::
RtpStream
(
listener
,
params
,
10
),
mid
(
mid
)
retransmissionBufferSize
(
RtpStreamSend
::
MaxRetransmissionDelayMs
)
{
{
MS_TRACE
();
MS_TRACE
();
switch
(
params
.
mimeType
.
type
)
{
case
RTC
:
:
RtpCodecMimeType
::
Type
::
VIDEO
:
{
this
->
maxRetransmissionDelayMs
=
RtpStreamSend
::
MaxRetransmissionDelayForVideoMs
;
this
->
retransmissionBufferSize
=
RtpStreamSend
::
MaxRetransmissionDelayForVideoMs
;
break
;
}
case
RTC
:
:
RtpCodecMimeType
::
Type
::
AUDIO
:
{
this
->
maxRetransmissionDelayMs
=
RtpStreamSend
::
MaxRetransmissionDelayForAudioMs
;
this
->
retransmissionBufferSize
=
RtpStreamSend
::
MaxRetransmissionDelayForAudioMs
;
break
;
}
case
RTC
:
:
RtpCodecMimeType
::
Type
::
UNSET
:
{
MS_ABORT
(
"codec mimeType not set"
);
}
}
}
}
RtpStreamSend
::~
RtpStreamSend
()
RtpStreamSend
::~
RtpStreamSend
()
...
@@ -329,13 +352,13 @@ namespace RTC
...
@@ -329,13 +352,13 @@ namespace RTC
this
->
hasRtt
=
true
;
this
->
hasRtt
=
true
;
}
}
// Smoothly change retransmission buffer size towards RTT + 100ms, but not
more than
// Smoothly change retransmission buffer size towards RTT + 100ms, but not
//
M
axRetransmissionDelayMs.
//
more than this->m
axRetransmissionDelayMs.
auto
newRetransmissionBufferSize
=
static_cast
<
uint32_t
>
(
this
->
rtt
+
100.0
);
auto
newRetransmissionBufferSize
=
static_cast
<
uint32_t
>
(
this
->
rtt
+
100.0
);
auto
avgRetransmissionBufferSize
=
auto
avgRetransmissionBufferSize
=
(
this
->
retransmissionBufferSize
*
7
+
newRetransmissionBufferSize
)
/
8
;
(
this
->
retransmissionBufferSize
*
7
+
newRetransmissionBufferSize
)
/
8
;
this
->
retransmissionBufferSize
=
std
::
max
(
this
->
retransmissionBufferSize
=
std
::
max
(
std
::
min
(
avgRetransmissionBufferSize
,
RtpStreamSend
::
M
axRetransmissionDelayMs
),
std
::
min
(
avgRetransmissionBufferSize
,
this
->
m
axRetransmissionDelayMs
),
RtpStreamSend
::
MinRetransmissionDelayMs
);
RtpStreamSend
::
MinRetransmissionDelayMs
);
this
->
packetsLost
=
report
->
GetTotalLost
();
this
->
packetsLost
=
report
->
GetTotalLost
();
...
@@ -543,7 +566,7 @@ namespace RTC
...
@@ -543,7 +566,7 @@ namespace RTC
const
auto
bufferSize
=
this
->
storageItemBuffer
.
GetBufferSize
();
const
auto
bufferSize
=
this
->
storageItemBuffer
.
GetBufferSize
();
// Go through all buffer items starting with the first and free all storage
// Go through all buffer items starting with the first and free all storage
// items that contain packets older than
M
axRetransmissionDelayMs.
// items that contain packets older than
this->m
axRetransmissionDelayMs.
for
(
size_t
i
{
0
};
i
<
bufferSize
&&
this
->
storageItemBuffer
.
GetBufferSize
()
!=
0
;
++
i
)
for
(
size_t
i
{
0
};
i
<
bufferSize
&&
this
->
storageItemBuffer
.
GetBufferSize
()
!=
0
;
++
i
)
{
{
auto
*
storageItem
=
this
->
storageItemBuffer
.
GetFirst
();
auto
*
storageItem
=
this
->
storageItemBuffer
.
GetFirst
();
...
@@ -645,8 +668,8 @@ namespace RTC
...
@@ -645,8 +668,8 @@ namespace RTC
{
{
// Do nothing.
// Do nothing.
}
}
// Don't resend the packet if older than
M
axRetransmissionDelayMs ms.
// Don't resend the packet if older than
this->m
axRetransmissionDelayMs ms.
else
if
(
diffMs
>
M
axRetransmissionDelayMs
)
else
if
(
diffMs
>
this
->
m
axRetransmissionDelayMs
)
{
{
if
(
!
tooOldPacketFound
)
if
(
!
tooOldPacketFound
)
{
{
...
@@ -655,7 +678,7 @@ namespace RTC
...
@@ -655,7 +678,7 @@ namespace RTC
"ignoring retransmission for too old packet "
"ignoring retransmission for too old packet "
"[seq:%"
PRIu16
", max age:%"
PRIu32
"ms, packet age:%"
PRIu32
"ms]"
,
"[seq:%"
PRIu16
", max age:%"
PRIu32
"ms, packet age:%"
PRIu32
"ms]"
,
packet
->
GetSequenceNumber
(),
packet
->
GetSequenceNumber
(),
M
axRetransmissionDelayMs
,
this
->
m
axRetransmissionDelayMs
,
diffMs
);
diffMs
);
tooOldPacketFound
=
true
;
tooOldPacketFound
=
true
;
...
...
worker/test/src/RTC/TestRtpStreamSend.cpp
浏览文件 @
1912b7fa
...
@@ -319,11 +319,11 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
...
@@ -319,11 +319,11 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
delete
stream2
;
delete
stream2
;
}
}
SECTION
(
"packets get retransmitted as long as they don't exceed MaxRetransmissionDelayMs"
)
SECTION
(
"packets get retransmitted as long as they don't exceed MaxRetransmissionDelay
ForVideo
Ms"
)
{
{
uint32_t
clockRate
=
90000
;
uint32_t
clockRate
=
90000
;
uint32_t
firstTs
=
1533790901
;
uint32_t
firstTs
=
1533790901
;
uint32_t
diffTs
=
RtpStreamSend
::
MaxRetransmissionDelayMs
*
clockRate
/
1000
;
uint32_t
diffTs
=
RtpStreamSend
::
MaxRetransmissionDelay
ForVideo
Ms
*
clockRate
/
1000
;
uint32_t
secondTs
=
firstTs
+
diffTs
;
uint32_t
secondTs
=
firstTs
+
diffTs
;
auto
*
packet1
=
CreateRtpPacket
(
rtpBuffer1
,
21006
,
firstTs
);
auto
*
packet1
=
CreateRtpPacket
(
rtpBuffer1
,
21006
,
firstTs
);
...
@@ -371,11 +371,11 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
...
@@ -371,11 +371,11 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
delete
stream
;
delete
stream
;
}
}
SECTION
(
"packets don't get retransmitted if MaxRetransmissionDelayMs is exceeded"
)
SECTION
(
"packets don't get retransmitted if MaxRetransmissionDelay
ForVideo
Ms is exceeded"
)
{
{
uint32_t
clockRate
=
90000
;
uint32_t
clockRate
=
90000
;
uint32_t
firstTs
=
1533790901
;
uint32_t
firstTs
=
1533790901
;
uint32_t
diffTs
=
RtpStreamSend
::
MaxRetransmissionDelayMs
*
clockRate
/
1000
;
uint32_t
diffTs
=
RtpStreamSend
::
MaxRetransmissionDelay
ForVideo
Ms
*
clockRate
/
1000
;
uint32_t
secondTs
=
firstTs
+
diffTs
;
uint32_t
secondTs
=
firstTs
+
diffTs
;
auto
*
packet1
=
CreateRtpPacket
(
rtpBuffer1
,
21006
,
firstTs
);
auto
*
packet1
=
CreateRtpPacket
(
rtpBuffer1
,
21006
,
firstTs
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论