Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
f462f5c4
提交
f462f5c4
authored
2月 29, 2020
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SRTP in PlainRtpTransport may be done. Not tested.
上级
5dd9a605
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
277 行增加
和
129 行删除
+277
-129
PlainRtpTransport.d.ts
lib/PlainRtpTransport.d.ts
+7
-3
PlainRtpTransport.d.ts.map
lib/PlainRtpTransport.d.ts.map
+2
-2
PlainRtpTransport.js
lib/PlainRtpTransport.js
+26
-2
PlainRtpTransport.ts
src/PlainRtpTransport.ts
+41
-5
PlainRtpTransport.hpp
worker/include/RTC/PlainRtpTransport.hpp
+2
-0
PipeTransport.cpp
worker/src/RTC/PipeTransport.cpp
+20
-18
PlainRtpTransport.cpp
worker/src/RTC/PlainRtpTransport.cpp
+179
-99
没有找到文件。
lib/PlainRtpTransport.d.ts
浏览文件 @
f462f5c4
...
...
@@ -85,6 +85,8 @@ export declare type PlainRtpTransportStat = {
export
declare
class
PlainRtpTransport
extends
Transport
{
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -96,7 +98,7 @@ export declare class PlainRtpTransport extends Transport {
/**
* Transport RTCP tuple.
*/
get
rtcpTuple
():
TransportTuple
;
get
rtcpTuple
():
TransportTuple
|
undefined
;
/**
* SCTP parameters.
*/
...
...
@@ -118,6 +120,8 @@ export declare class PlainRtpTransport extends Transport {
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -147,8 +151,8 @@ export declare class PlainRtpTransport extends Transport {
* @override
*/
connect
({
ip
,
port
,
rtcpPort
,
srtpParameters
}:
{
ip
:
string
;
port
:
number
;
ip
?
:
string
;
port
?
:
number
;
rtcpPort
?:
number
;
srtpParameters
?:
SrtpParameters
;
}):
Promise
<
void
>
;
...
...
lib/PlainRtpTransport.d.ts.map
浏览文件 @
f462f5c4
{"version":3,"file":"PlainRtpTransport.d.ts","sourceRoot":"","sources":["../src/PlainRtpTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnE,oBAAY,wBAAwB,GACpC;IACC;;OAEG;IACH,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,cA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AG;IAoBvB;;OAEG;IACH,IAAI,KAAK,IAAI,cAAc,CAG1B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,cAAc,CAG9B;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,GAAG,SAAS,CAG/C;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,SAAS,CAGzB;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,GAAG,SAAS,CAG/C;IAED;;;;;;;;;;;OAWG;IACH,IAAI,QAAQ,IAAI,oBAAoB,CAGnC;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAWb;;;;;OAKG;IACH,YAAY,IAAI,IAAI;IAWpB;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAOlD;;;;OAIG;IACG,OAAO,CACZ,EACC,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,EACD;QACC,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,cAAc,CAAC;KAChC,GACC,OAAO,CAAC,IAAI,CAAC;IAehB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQzD,OAAO,CAAC,0BAA0B;CAuClC"}
\ No newline at end of file
{"version":3,"file":"PlainRtpTransport.d.ts","sourceRoot":"","sources":["../src/PlainRtpTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE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AmElC"}
\ No newline at end of file
lib/PlainRtpTransport.js
浏览文件 @
f462f5c4
...
...
@@ -31,6 +31,8 @@ class PlainRtpTransport extends Transport_1.Transport {
// - .keyBase64
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -87,6 +89,8 @@ class PlainRtpTransport extends Transport_1.Transport {
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -137,8 +141,10 @@ class PlainRtpTransport extends Transport_1.Transport {
const
reqData
=
{
ip
,
port
,
rtcpPort
,
srtpParameters
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
if
(
data
.
tuple
)
this
.
_data
.
tuple
=
data
.
tuple
;
if
(
data
.
rtcpTuple
)
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
srtpParameters
=
data
.
srtpParameters
;
}
/**
...
...
@@ -154,6 +160,24 @@ class PlainRtpTransport extends Transport_1.Transport {
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
switch
(
event
)
{
case
'tuple'
:
{
const
tuple
=
data
.
tuple
;
this
.
_data
.
tuple
=
tuple
;
this
.
safeEmit
(
'tuple'
,
tuple
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'tuple'
,
tuple
);
break
;
}
case
'rtcpTuple'
:
{
const
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
rtcpTuple
=
rtcpTuple
;
this
.
safeEmit
(
'rtcpTuple'
,
rtcpTuple
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'rtcpTuple'
,
rtcpTuple
);
break
;
}
case
'sctpstatechange'
:
{
const
sctpState
=
data
.
sctpState
;
...
...
src/PlainRtpTransport.ts
浏览文件 @
f462f5c4
...
...
@@ -138,6 +138,8 @@ export class PlainRtpTransport extends Transport
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -172,7 +174,7 @@ export class PlainRtpTransport extends Transport
/**
* Transport RTCP tuple.
*/
get
rtcpTuple
():
TransportTuple
get
rtcpTuple
():
TransportTuple
|
undefined
{
return
this
.
_data
.
rtcpTuple
;
}
...
...
@@ -210,6 +212,8 @@ export class PlainRtpTransport extends Transport
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
...
...
@@ -276,8 +280,8 @@ export class PlainRtpTransport extends Transport
srtpParameters
}:
{
ip
:
string
;
port
:
number
;
ip
?
:
string
;
port
?
:
number
;
rtcpPort
?:
number
;
srtpParameters
?:
SrtpParameters
;
}
...
...
@@ -291,8 +295,12 @@ export class PlainRtpTransport extends Transport
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
if
(
data
.
tuple
)
this
.
_data
.
tuple
=
data
.
tuple
;
if
(
data
.
rtcpTuple
)
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
srtpParameters
=
data
.
srtpParameters
;
}
...
...
@@ -315,6 +323,34 @@ export class PlainRtpTransport extends Transport
{
switch
(
event
)
{
case
'tuple'
:
{
const
tuple
=
data
.
tuple
as
TransportTuple
;
this
.
_data
.
tuple
=
tuple
;
this
.
safeEmit
(
'tuple'
,
tuple
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'tuple'
,
tuple
);
break
;
}
case
'rtcpTuple'
:
{
const
rtcpTuple
=
data
.
rtcpTuple
as
TransportTuple
;
this
.
_data
.
rtcpTuple
=
rtcpTuple
;
this
.
safeEmit
(
'rtcpTuple'
,
rtcpTuple
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'rtcpTuple'
,
rtcpTuple
);
break
;
}
case
'sctpstatechange'
:
{
const
sctpState
=
data
.
sctpState
as
SctpState
;
...
...
worker/include/RTC/PlainRtpTransport.hpp
浏览文件 @
f462f5c4
...
...
@@ -35,6 +35,7 @@ namespace RTC
private
:
bool
IsConnected
()
const
override
;
bool
HasSrtp
()
const
;
bool
IsSrtpReady
()
const
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
=
nullptr
)
override
;
void
SendRtcpPacket
(
RTC
::
RTCP
::
Packet
*
packet
)
override
;
void
SendRtcpCompoundPacket
(
RTC
::
RTCP
::
CompoundPacket
*
packet
)
override
;
...
...
@@ -69,6 +70,7 @@ namespace RTC
};
std
::
string
srtpKey
;
std
::
string
srtpKeyBase64
;
bool
connectCalled
{
false
};
// Whether connect() was succesfully called.
};
}
// namespace RTC
...
...
worker/src/RTC/PipeTransport.cpp
浏览文件 @
f462f5c4
...
...
@@ -115,7 +115,7 @@ namespace RTC
RTC
::
Transport
::
FillJson
(
jsonObject
);
// Add tuple.
if
(
this
->
tuple
!=
nullptr
)
if
(
this
->
tuple
)
{
this
->
tuple
->
FillJson
(
jsonObject
[
"tuple"
]);
}
...
...
@@ -159,7 +159,7 @@ namespace RTC
// Add type.
jsonObject
[
"type"
]
=
"pipe-transport"
;
if
(
this
->
tuple
!=
nullptr
)
if
(
this
->
tuple
)
{
this
->
tuple
->
FillJson
(
jsonObject
[
"tuple"
]);
}
...
...
@@ -188,7 +188,7 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
TRANSPORT_CONNECT
:
{
// Ensure this method is not called twice.
if
(
this
->
tuple
!=
nullptr
)
if
(
this
->
tuple
)
MS_THROW_ERROR
(
"connect() already called"
);
try
...
...
@@ -333,7 +333,7 @@ namespace RTC
reinterpret_cast
<
struct
sockaddr_in
*>
(
&
this
->
remoteAddrStorage
));
if
(
err
!=
0
)
MS_
ABORT
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
));
MS_
THROW_ERROR
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
...
...
@@ -346,7 +346,7 @@ namespace RTC
reinterpret_cast
<
struct
sockaddr_in6
*>
(
&
this
->
remoteAddrStorage
));
if
(
err
!=
0
)
MS_
ABORT
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
MS_
THROW_ERROR
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
...
...
@@ -402,7 +402,7 @@ namespace RTC
inline
bool
PipeTransport
::
IsConnected
()
const
{
return
this
->
tuple
!=
nullptr
;
return
this
->
tuple
;
}
inline
bool
PipeTransport
::
HasSrtp
()
const
...
...
@@ -533,14 +533,6 @@ namespace RTC
if
(
!
IsConnected
())
return
;
// Verify that the packet's tuple matches our tuple.
if
(
!
this
->
tuple
->
Compare
(
tuple
))
{
MS_DEBUG_TAG
(
rtp
,
"ignoring RTP packet from unknown IP:port"
);
return
;
}
// Decrypt the SRTP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
{
...
...
@@ -565,6 +557,14 @@ namespace RTC
return
;
}
// Verify that the packet's tuple matches our tuple.
if
(
!
this
->
tuple
->
Compare
(
tuple
))
{
MS_DEBUG_TAG
(
rtp
,
"ignoring RTP packet from unknown IP:port"
);
return
;
}
RTC
::
RtpPacket
*
packet
=
RTC
::
RtpPacket
::
Parse
(
data
,
len
);
if
(
packet
==
nullptr
)
...
...
@@ -586,6 +586,12 @@ namespace RTC
if
(
!
IsConnected
())
return
;
// Decrypt the SRTCP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtcp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
{
return
;
}
// Verify that the packet's tuple matches our tuple.
if
(
!
this
->
tuple
->
Compare
(
tuple
))
{
...
...
@@ -594,10 +600,6 @@ namespace RTC
return
;
}
// Decrypt the SRTCP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtcp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
return
;
RTC
::
RTCP
::
Packet
*
packet
=
RTC
::
RTCP
::
Packet
::
Parse
(
data
,
len
);
if
(
packet
==
nullptr
)
...
...
worker/src/RTC/PlainRtpTransport.cpp
浏览文件 @
f462f5c4
...
...
@@ -5,6 +5,7 @@
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Channel/Notifier.hpp"
namespace
RTC
{
...
...
@@ -192,7 +193,7 @@ namespace RTC
jsonObject
[
"multiSource"
]
=
this
->
multiSource
;
// Add tuple.
if
(
this
->
tuple
!=
nullptr
)
if
(
this
->
tuple
)
{
this
->
tuple
->
FillJson
(
jsonObject
[
"tuple"
]);
}
...
...
@@ -213,7 +214,7 @@ namespace RTC
// Add rtcpTuple.
if
(
!
this
->
rtcpMux
)
{
if
(
this
->
rtcpTuple
!=
nullptr
)
if
(
this
->
rtcpTuple
)
{
this
->
rtcpTuple
->
FillJson
(
jsonObject
[
"rtcpTuple"
]);
}
...
...
@@ -265,7 +266,7 @@ namespace RTC
// Add multiSource.
jsonObject
[
"multiSource"
]
=
this
->
multiSource
;
if
(
this
->
tuple
!=
nullptr
)
if
(
this
->
tuple
)
{
// Add tuple.
this
->
tuple
->
FillJson
(
jsonObject
[
"tuple"
]);
...
...
@@ -286,7 +287,7 @@ namespace RTC
}
// Add rtcpTuple.
if
(
!
this
->
rtcpMux
&&
this
->
rtcpTuple
!=
nullptr
)
if
(
!
this
->
rtcpMux
&&
this
->
rtcpTuple
)
this
->
rtcpTuple
->
FillJson
(
jsonObject
[
"rtcpTuple"
]);
}
...
...
@@ -298,16 +299,16 @@ namespace RTC
{
case
Channel
:
:
Request
::
MethodId
::
TRANSPORT_CONNECT
:
{
// Ensure this method is not called twice.
if
(
this
->
connectCalled
)
MS_THROW_ERROR
(
"connect() already called"
);
// Reject if comedia mode or multiSource is set.
if
(
this
->
comedia
)
MS_THROW_ERROR
(
"cannot call connect() when comedia mode is set"
);
else
if
(
this
->
multiSource
)
MS_THROW_ERROR
(
"cannot call connect() when multiSource is set"
);
// Ensure this method is not called twice.
if
(
this
->
tuple
!=
nullptr
)
MS_THROW_ERROR
(
"connect() already called"
);
try
{
std
::
string
ip
;
...
...
@@ -315,50 +316,6 @@ namespace RTC
uint16_t
rtcpPort
{
0u
};
std
::
string
srtpKeyBase64
;
auto
jsonIpIt
=
request
->
data
.
find
(
"ip"
);
if
(
jsonIpIt
==
request
->
data
.
end
()
||
!
jsonIpIt
->
is_string
())
MS_THROW_TYPE_ERROR
(
"missing ip"
);
ip
=
jsonIpIt
->
get
<
std
::
string
>
();
// This may throw.
Utils
::
IP
::
NormalizeIp
(
ip
);
auto
jsonPortIt
=
request
->
data
.
find
(
"port"
);
// clang-format off
if
(
jsonPortIt
==
request
->
data
.
end
()
||
!
Utils
::
Json
::
IsPositiveInteger
(
*
jsonPortIt
)
)
// clang-format on
{
MS_THROW_TYPE_ERROR
(
"missing port"
);
}
port
=
jsonPortIt
->
get
<
uint16_t
>
();
auto
jsonRtcpPortIt
=
request
->
data
.
find
(
"rtcpPort"
);
// clang-format off
if
(
jsonRtcpPortIt
!=
request
->
data
.
end
()
&&
Utils
::
Json
::
IsPositiveInteger
(
*
jsonRtcpPortIt
)
)
// clang-format on
{
if
(
this
->
rtcpMux
)
MS_THROW_TYPE_ERROR
(
"cannot set rtcpPort with rtcpMux enabled"
);
rtcpPort
=
jsonRtcpPortIt
->
get
<
uint16_t
>
();
}
else
{
if
(
!
this
->
rtcpMux
)
MS_THROW_TYPE_ERROR
(
"missing rtcpPort (required with rtcpMux disabled)"
);
}
auto
jsonSrtpParametersIt
=
request
->
data
.
find
(
"srtpParameters"
);
if
(
!
HasSrtp
()
&&
jsonSrtpParametersIt
!=
request
->
data
.
end
())
...
...
@@ -462,62 +419,65 @@ namespace RTC
delete
[]
srtpRemoteKey
;
}
int
err
;
switch
(
Utils
::
IP
::
GetFamily
(
ip
))
if
(
!
this
->
comedia
&&
!
this
->
multiSource
)
{
case
AF_INET
:
{
err
=
uv_ip4_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
port
),
reinterpret_cast
<
struct
sockaddr_in
*>
(
&
this
->
remoteAddrStorage
));
auto
jsonIpIt
=
request
->
data
.
find
(
"ip"
);
if
(
err
!=
0
)
MS_ABORT
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
)
);
if
(
jsonIpIt
==
request
->
data
.
end
()
||
!
jsonIpIt
->
is_string
()
)
MS_THROW_TYPE_ERROR
(
"missing ip"
);
break
;
}
ip
=
jsonIpIt
->
get
<
std
::
string
>
();
case
AF_INET6
:
{
err
=
uv_ip6_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
port
),
reinterpret_cast
<
struct
sockaddr_in6
*>
(
&
this
->
remoteAddrStorage
));
// This may throw.
Utils
::
IP
::
NormalizeIp
(
ip
);
if
(
err
!=
0
)
MS_ABORT
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
auto
jsonPortIt
=
request
->
data
.
find
(
"port"
);
break
;
// clang-format off
if
(
jsonPortIt
==
request
->
data
.
end
()
||
!
Utils
::
Json
::
IsPositiveInteger
(
*
jsonPortIt
)
)
// clang-format on
{
MS_THROW_TYPE_ERROR
(
"missing port"
);
}
default
:
port
=
jsonPortIt
->
get
<
uint16_t
>
();
auto
jsonRtcpPortIt
=
request
->
data
.
find
(
"rtcpPort"
);
// clang-format off
if
(
jsonRtcpPortIt
!=
request
->
data
.
end
()
&&
Utils
::
Json
::
IsPositiveInteger
(
*
jsonRtcpPortIt
)
)
// clang-format on
{
MS_THROW_ERROR
(
"invalid IP '%s'"
,
ip
.
c_str
());
}
}
if
(
this
->
rtcpMux
)
MS_THROW_TYPE_ERROR
(
"cannot set rtcpPort with rtcpMux enabled"
);
// Create the tuple.
this
->
tuple
=
new
RTC
::
TransportTuple
(
this
->
udpSocket
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
this
->
remoteAddrStorage
));
rtcpPort
=
jsonRtcpPortIt
->
get
<
uint16_t
>
();
}
else
{
if
(
!
this
->
rtcpMux
)
MS_THROW_TYPE_ERROR
(
"missing rtcpPort (required with rtcpMux disabled)"
);
}
if
(
!
this
->
listenIp
.
announcedIp
.
empty
())
this
->
tuple
->
SetLocalAnnouncedIp
(
this
->
listenIp
.
announcedIp
);
int
err
;
if
(
!
this
->
rtcpMux
)
{
switch
(
Utils
::
IP
::
GetFamily
(
ip
))
{
case
AF_INET
:
{
err
=
uv_ip4_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
rtcpP
ort
),
reinterpret_cast
<
struct
sockaddr_in
*>
(
&
this
->
r
tcpR
emoteAddrStorage
));
static_cast
<
int
>
(
p
ort
),
reinterpret_cast
<
struct
sockaddr_in
*>
(
&
this
->
remoteAddrStorage
));
if
(
err
!=
0
)
MS_
ABORT
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
));
MS_
THROW_ERROR
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
...
...
@@ -526,11 +486,11 @@ namespace RTC
{
err
=
uv_ip6_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
rtcpP
ort
),
reinterpret_cast
<
struct
sockaddr_in6
*>
(
&
this
->
r
tcpR
emoteAddrStorage
));
static_cast
<
int
>
(
p
ort
),
reinterpret_cast
<
struct
sockaddr_in6
*>
(
&
this
->
remoteAddrStorage
));
if
(
err
!=
0
)
MS_
ABORT
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
MS_
THROW_ERROR
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
...
...
@@ -542,11 +502,56 @@ namespace RTC
}
// Create the tuple.
this
->
rtcpT
uple
=
new
RTC
::
TransportTuple
(
this
->
rtcpUdpSocket
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
this
->
rtcpR
emoteAddrStorage
));
this
->
t
uple
=
new
RTC
::
TransportTuple
(
this
->
udpSocket
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
this
->
r
emoteAddrStorage
));
if
(
!
this
->
listenIp
.
announcedIp
.
empty
())
this
->
rtcpTuple
->
SetLocalAnnouncedIp
(
this
->
listenIp
.
announcedIp
);
this
->
tuple
->
SetLocalAnnouncedIp
(
this
->
listenIp
.
announcedIp
);
if
(
!
this
->
rtcpMux
)
{
switch
(
Utils
::
IP
::
GetFamily
(
ip
))
{
case
AF_INET
:
{
err
=
uv_ip4_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
rtcpPort
),
reinterpret_cast
<
struct
sockaddr_in
*>
(
&
this
->
rtcpRemoteAddrStorage
));
if
(
err
!=
0
)
MS_THROW_ERROR
(
"uv_ip4_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
case
AF_INET6
:
{
err
=
uv_ip6_addr
(
ip
.
c_str
(),
static_cast
<
int
>
(
rtcpPort
),
reinterpret_cast
<
struct
sockaddr_in6
*>
(
&
this
->
rtcpRemoteAddrStorage
));
if
(
err
!=
0
)
MS_THROW_ERROR
(
"uv_ip6_addr() failed: %s"
,
uv_strerror
(
err
));
break
;
}
default
:
{
MS_THROW_ERROR
(
"invalid IP '%s'"
,
ip
.
c_str
());
}
}
// Create the tuple.
this
->
rtcpTuple
=
new
RTC
::
TransportTuple
(
this
->
rtcpUdpSocket
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
this
->
rtcpRemoteAddrStorage
));
if
(
!
this
->
listenIp
.
announcedIp
.
empty
())
this
->
rtcpTuple
->
SetLocalAnnouncedIp
(
this
->
listenIp
.
announcedIp
);
}
}
}
catch
(
const
MediaSoupError
&
error
)
...
...
@@ -566,12 +571,15 @@ namespace RTC
throw
;
}
this
->
connectCalled
=
true
;
// Tell the caller about the selected local DTLS role.
json
data
=
json
::
object
();
this
->
tuple
->
FillJson
(
data
[
"tuple"
]);
if
(
this
->
tuple
)
this
->
tuple
->
FillJson
(
data
[
"tuple"
]);
if
(
!
this
->
rtcpMux
)
if
(
!
this
->
rtcpMux
&&
this
->
rtcpTuple
)
this
->
rtcpTuple
->
FillJson
(
data
[
"rtcpTuple"
]);
if
(
HasSrtp
())
...
...
@@ -603,7 +611,7 @@ namespace RTC
inline
bool
PlainRtpTransport
::
IsConnected
()
const
{
return
this
->
tuple
!=
nullptr
;
return
this
->
tuple
;
}
inline
bool
PlainRtpTransport
::
HasSrtp
()
const
...
...
@@ -611,6 +619,11 @@ namespace RTC
return
!
this
->
srtpKey
.
empty
();
}
inline
bool
PlainRtpTransport
::
IsSrtpReady
()
const
{
return
HasSrtp
()
&&
this
->
srtpSendSession
&&
this
->
srtpRecvSession
;
}
void
PlainRtpTransport
::
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
)
{
MS_TRACE
();
...
...
@@ -739,8 +752,32 @@ namespace RTC
{
MS_TRACE
();
// TODO: Check SRTP and connect() called, but may be it was called just to provide
// us with the remote SRTP parameters, etc.
if
(
HasSrtp
()
&&
!
IsSrtpReady
())
return
;
// Decrypt the SRTP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
{
RTC
::
RtpPacket
*
packet
=
RTC
::
RtpPacket
::
Parse
(
data
,
len
);
if
(
!
packet
)
{
MS_WARN_TAG
(
srtp
,
"DecryptSrtp() failed due to an invalid RTP packet"
);
}
else
{
MS_WARN_TAG
(
srtp
,
"DecryptSrtp() failed [ssrc:%"
PRIu32
", payloadType:%"
PRIu8
", seq:%"
PRIu16
"]"
,
packet
->
GetSsrc
(),
packet
->
GetPayloadType
(),
packet
->
GetSequenceNumber
());
delete
packet
;
}
return
;
}
// If multiSource is set allow it without any checking.
if
(
this
->
multiSource
)
...
...
@@ -769,7 +806,16 @@ namespace RTC
// If not yet connected do it now.
if
(
!
wasConnected
)
{
// Notify the Node PlainRtpTransport.
json
data
=
json
::
object
();
this
->
tuple
->
FillJson
(
data
[
"tuple"
]);
Channel
::
Notifier
::
Emit
(
this
->
id
,
"tuple"
,
data
);
RTC
::
Transport
::
Connected
();
}
}
// Otherwise, if RTP tuple is set, verify that it matches the origin
// of the packet.
...
...
@@ -798,6 +844,15 @@ namespace RTC
{
MS_TRACE
();
if
(
HasSrtp
()
&&
!
IsSrtpReady
())
return
;
// Decrypt the SRTCP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtcp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
{
return
;
}
// If multiSource is set allow it without any checking.
if
(
this
->
multiSource
)
{
...
...
@@ -825,7 +880,16 @@ namespace RTC
// If not yet connected do it now.
if
(
!
wasConnected
)
{
// Notify the Node PlainRtpTransport.
json
data
=
json
::
object
();
this
->
tuple
->
FillJson
(
data
[
"tuple"
]);
Channel
::
Notifier
::
Emit
(
this
->
id
,
"tuple"
,
data
);
RTC
::
Transport
::
Connected
();
}
}
// Otherwise, if RTCP-mux is unset and RTCP tuple is unset, set it if we
// are in comedia mode.
...
...
@@ -844,6 +908,13 @@ namespace RTC
if
(
!
this
->
listenIp
.
announcedIp
.
empty
())
this
->
rtcpTuple
->
SetLocalAnnouncedIp
(
this
->
listenIp
.
announcedIp
);
// Notify the Node PlainRtpTransport.
json
data
=
json
::
object
();
this
->
rtcpTuple
->
FillJson
(
data
[
"rtcpTuple"
]);
Channel
::
Notifier
::
Emit
(
this
->
id
,
"rtcpTuple"
,
data
);
}
// If RTCP-mux verify that the packet's tuple matches our RTP tuple.
else
if
(
this
->
rtcpMux
&&
!
this
->
tuple
->
Compare
(
tuple
))
...
...
@@ -907,7 +978,16 @@ namespace RTC
// If not yet connected do it now.
if
(
!
wasConnected
)
{
// Notify the Node PlainRtpTransport.
json
data
=
json
::
object
();
this
->
tuple
->
FillJson
(
data
[
"tuple"
]);
Channel
::
Notifier
::
Emit
(
this
->
id
,
"tuple"
,
data
);
RTC
::
Transport
::
Connected
();
}
}
// Otherwise, if RTP tuple is set, verify that it matches the origin
// of the packet.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论