Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
df46fccb
Unverified
提交
df46fccb
authored
8月 25, 2022
作者:
Iñaki Baz Castillo
提交者:
GitHub
8月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New ChannelMessageHandlers class (fixes issue #892) (#894)
上级
ed15a863
隐藏空白字符变更
内嵌
并排
正在显示
29 个修改的文件
包含
543 行增加
和
242 行删除
+543
-242
test-Router.js
node/tests/test-Router.js
+12
-1
test-WebRtcServer.js
node/tests/test-WebRtcServer.js
+24
-2
test-Worker.js
node/tests/test-Worker.js
+12
-1
ChannelSocket.hpp
worker/include/Channel/ChannelSocket.hpp
+5
-3
ChannelMessageHandlers.hpp
worker/include/ChannelMessageHandlers.hpp
+36
-0
Logger.hpp
worker/include/Logger.hpp
+1
-1
PayloadChannelSocket.hpp
worker/include/PayloadChannel/PayloadChannelSocket.hpp
+3
-3
Router.hpp
worker/include/RTC/Router.hpp
+0
-9
Worker.hpp
worker/include/Worker.hpp
+0
-15
meson.build
worker/meson.build
+52
-53
ChannelSocket.cpp
worker/src/Channel/ChannelSocket.cpp
+15
-4
ChannelMessageHandlers.cpp
worker/src/ChannelMessageHandlers.cpp
+172
-0
PayloadChannelSocket.cpp
worker/src/PayloadChannel/PayloadChannelSocket.cpp
+11
-5
ActiveSpeakerObserver.cpp
worker/src/RTC/ActiveSpeakerObserver.cpp
+12
-0
AudioLevelObserver.cpp
worker/src/RTC/AudioLevelObserver.cpp
+10
-0
DataConsumer.cpp
worker/src/RTC/DataConsumer.cpp
+10
-0
DataProducer.cpp
worker/src/RTC/DataProducer.cpp
+10
-0
DirectTransport.cpp
worker/src/RTC/DirectTransport.cpp
+10
-0
PipeConsumer.cpp
worker/src/RTC/PipeConsumer.cpp
+10
-0
PipeTransport.cpp
worker/src/RTC/PipeTransport.cpp
+10
-0
PlainTransport.cpp
worker/src/RTC/PlainTransport.cpp
+10
-1
Producer.cpp
worker/src/RTC/Producer.cpp
+10
-0
Router.cpp
worker/src/RTC/Router.cpp
+10
-50
SimpleConsumer.cpp
worker/src/RTC/SimpleConsumer.cpp
+10
-0
SimulcastConsumer.cpp
worker/src/RTC/SimulcastConsumer.cpp
+10
-0
SvcConsumer.cpp
worker/src/RTC/SvcConsumer.cpp
+10
-0
WebRtcServer.cpp
worker/src/RTC/WebRtcServer.cpp
+10
-0
WebRtcTransport.cpp
worker/src/RTC/WebRtcTransport.cpp
+17
-0
Worker.cpp
worker/src/Worker.cpp
+41
-94
没有找到文件。
node/tests/test-Router.js
浏览文件 @
df46fccb
...
...
@@ -63,7 +63,18 @@ test('worker.createRouter() succeeds', async () =>
await
expect
(
worker
.
dump
())
.
resolves
.
toEqual
({
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[
router
.
id
]
});
.
toEqual
(
{
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[
router
.
id
],
channelMessageHandlers
:
{
channelRequestHandlers
:
[
router
.
id
],
payloadChannelRequestHandlers
:
[],
payloadChannelNotificationHandlers
:
[]
}
});
await
expect
(
router
.
dump
())
.
resolves
...
...
node/tests/test-WebRtcServer.js
浏览文件 @
df46fccb
...
...
@@ -49,7 +49,18 @@ test('worker.createWebRtcServer() succeeds', async () =>
await
expect
(
worker
.
dump
())
.
resolves
.
toEqual
({
pid
:
worker
.
pid
,
webRtcServerIds
:
[
webRtcServer
.
id
],
routerIds
:
[]
});
.
toEqual
(
{
pid
:
worker
.
pid
,
webRtcServerIds
:
[
webRtcServer
.
id
],
routerIds
:
[],
channelMessageHandlers
:
{
channelRequestHandlers
:
[
webRtcServer
.
id
],
payloadChannelRequestHandlers
:
[],
payloadChannelNotificationHandlers
:
[]
}
});
await
expect
(
webRtcServer
.
dump
())
.
resolves
...
...
@@ -473,7 +484,18 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer
await
expect
(
worker
.
dump
())
.
resolves
.
toEqual
({
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[
router
.
id
]
});
.
toEqual
(
{
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[
router
.
id
],
channelMessageHandlers
:
{
channelRequestHandlers
:
[
router
.
id
],
payloadChannelRequestHandlers
:
[],
payloadChannelNotificationHandlers
:
[]
}
});
await
expect
(
router
.
dump
())
.
resolves
...
...
node/tests/test-Worker.js
浏览文件 @
df46fccb
...
...
@@ -124,7 +124,18 @@ test('worker.dump() succeeds', async () =>
await
expect
(
worker
.
dump
())
.
resolves
.
toEqual
({
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[]
});
.
toEqual
(
{
pid
:
worker
.
pid
,
webRtcServerIds
:
[],
routerIds
:
[],
channelMessageHandlers
:
{
channelRequestHandlers
:
[],
payloadChannelRequestHandlers
:
[],
payloadChannelNotificationHandlers
:
[]
}
});
worker
.
close
();
},
2000
);
...
...
worker/include/Channel/ChannelSocket.hpp
浏览文件 @
df46fccb
#ifndef MS_CHANNEL_
UNIX_STREAM_
SOCKET_HPP
#define MS_CHANNEL_
UNIX_STREAM_
SOCKET_HPP
#ifndef MS_CHANNEL_SOCKET_HPP
#define MS_CHANNEL_SOCKET_HPP
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
...
...
@@ -26,6 +26,8 @@ namespace Channel
public
:
ConsumerSocket
(
int
fd
,
size_t
bufferSize
,
Listener
*
listener
);
~
ConsumerSocket
();
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public
:
void
UserOnUnixStreamRead
()
override
;
...
...
@@ -84,10 +86,10 @@ namespace Channel
public
:
void
Close
();
void
SetListener
(
Listener
*
listener
);
bool
CallbackRead
();
void
Send
(
json
&
jsonMessage
);
void
Send
(
const
std
::
string
&
message
);
void
SendLog
(
const
char
*
message
,
uint32_t
messageLen
);
bool
CallbackRead
();
private
:
void
SendImpl
(
const
uint8_t
*
payload
,
uint32_t
payloadLen
);
...
...
worker/include/ChannelMessageHandlers.hpp
0 → 100644
浏览文件 @
df46fccb
#ifndef MS_CHANNEL_MESSAGE_HANDLERS_HPP
#define MS_CHANNEL_MESSAGE_HANDLERS_HPP
#include "common.hpp"
#include "Channel/ChannelSocket.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp"
#include <absl/container/flat_hash_map.h>
#include <nlohmann/json.hpp>
#include <string>
class
ChannelMessageHandlers
{
public
:
static
void
FillJson
(
json
&
jsonObject
);
static
void
RegisterHandler
(
const
std
::
string
&
id
,
Channel
::
ChannelSocket
::
RequestHandler
*
channelRequestHandler
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
payloadChannelRequestHandler
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
payloadChannelNotificationHandler
);
static
void
UnregisterHandler
(
const
std
::
string
&
id
);
static
Channel
::
ChannelSocket
::
RequestHandler
*
GetChannelRequestHandler
(
const
std
::
string
&
id
);
static
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
GetPayloadChannelRequestHandler
(
const
std
::
string
&
id
);
static
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
GetPayloadChannelNotificationHandler
(
const
std
::
string
&
id
);
private
:
thread_local
static
absl
::
flat_hash_map
<
std
::
string
,
Channel
::
ChannelSocket
::
RequestHandler
*>
mapChannelRequestHandlers
;
thread_local
static
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*>
mapPayloadChannelRequestHandlers
;
thread_local
static
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*>
mapPayloadChannelNotificationHandlers
;
};
#endif
worker/include/Logger.hpp
浏览文件 @
df46fccb
...
...
@@ -6,7 +6,7 @@
* files (.hpp) MUST NOT include Logger.hpp.
*
* All the logging macros use the same format as printf(). The XXX_STD() version
* of a macro logs to stdoud/stderr instead of using the Channel instance.
* of a macro logs to stdoud/stderr instead of using the Channel
Socket
instance.
* However some macros such as MS_ABORT() and MS_ASSERT() always log to stderr.
*
* If the macro MS_LOG_STD is defined, all the macros log to stdout/stderr.
...
...
worker/include/PayloadChannel/PayloadChannelSocket.hpp
浏览文件 @
df46fccb
#ifndef MS_PAYLOAD_CHANNEL_
UNIX_STREAM_
SOCKET_HPP
#define MS_PAYLOAD_CHANNEL_
UNIX_STREAM_
SOCKET_HPP
#ifndef MS_PAYLOAD_CHANNEL_SOCKET_HPP
#define MS_PAYLOAD_CHANNEL_SOCKET_HPP
#include "common.hpp"
#include "PayloadChannel/PayloadChannelNotification.hpp"
...
...
@@ -96,11 +96,11 @@ namespace PayloadChannel
public
:
void
Close
();
void
SetListener
(
Listener
*
listener
);
bool
CallbackRead
();
void
Send
(
json
&
jsonMessage
,
const
uint8_t
*
payload
,
size_t
payloadLen
);
void
Send
(
const
std
::
string
&
message
,
const
uint8_t
*
payload
,
size_t
payloadLen
);
void
Send
(
json
&
jsonMessage
);
void
Send
(
const
std
::
string
&
message
);
bool
CallbackRead
();
private
:
void
SendImpl
(
const
uint8_t
*
message
,
uint32_t
messageLen
);
...
...
worker/include/RTC/Router.hpp
浏览文件 @
df46fccb
...
...
@@ -34,15 +34,6 @@ namespace RTC
virtual
~
Listener
()
=
default
;
public
:
virtual
void
OnChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
Channel
::
ChannelSocket
::
RequestHandler
*
handler
)
=
0
;
virtual
void
OnChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
=
0
;
virtual
void
OnPayloadChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
handler
)
=
0
;
virtual
void
OnPayloadChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
=
0
;
virtual
void
OnPayloadChannelNotificationHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
handler
)
=
0
;
virtual
void
OnPayloadChannelNotificationHandlerRemoved
(
const
std
::
string
&
id
)
=
0
;
virtual
RTC
::
WebRtcServer
*
OnRouterNeedWebRtcServer
(
RTC
::
Router
*
router
,
std
::
string
&
webRtcServerId
)
=
0
;
};
...
...
worker/include/Worker.hpp
浏览文件 @
df46fccb
...
...
@@ -60,16 +60,6 @@ public:
/* Pure virtual methods inherited from RTC::Router::Listener. */
public
:
void
OnChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
Channel
::
ChannelSocket
::
RequestHandler
*
handler
)
override
;
void
OnChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
override
;
void
OnPayloadChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
handler
)
override
;
void
OnPayloadChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
override
;
void
OnPayloadChannelNotificationHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
handler
)
override
;
void
OnPayloadChannelNotificationHandlerRemoved
(
const
std
::
string
&
id
)
override
;
RTC
::
WebRtcServer
*
OnRouterNeedWebRtcServer
(
RTC
::
Router
*
router
,
std
::
string
&
webRtcServerId
)
override
;
private
:
...
...
@@ -80,11 +70,6 @@ private:
SignalsHandler
*
signalsHandler
{
nullptr
};
absl
::
flat_hash_map
<
std
::
string
,
RTC
::
WebRtcServer
*>
mapWebRtcServers
;
absl
::
flat_hash_map
<
std
::
string
,
RTC
::
Router
*>
mapRouters
;
absl
::
flat_hash_map
<
std
::
string
,
Channel
::
ChannelSocket
::
RequestHandler
*>
mapChannelRequestHandlers
;
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*>
mapPayloadChannelRequestHandlers
;
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*>
mapPayloadChannelNotificationHandlers
;
// Others.
bool
closed
{
false
};
};
...
...
worker/meson.build
浏览文件 @
df46fccb
...
...
@@ -49,6 +49,7 @@ common_sources = [
'src/MediaSoupErrors.cpp',
'src/Settings.cpp',
'src/Worker.cpp',
'src/ChannelMessageHandlers.cpp',
'src/Utils/Crypto.cpp',
'src/Utils/File.cpp',
'src/Utils/IP.cpp',
...
...
@@ -338,56 +339,54 @@ test(
workdir: meson.project_source_root(),
)
if host_machine.system() == 'linux'
executable(
'mediasoup-worker-fuzzer',
build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-fuzzer',
dependencies: dependencies,
sources: common_sources + [
'fuzzer/src/fuzzer.cpp',
'fuzzer/src/FuzzerUtils.cpp',
'fuzzer/src/RTC/FuzzerStunPacket.cpp',
'fuzzer/src/RTC/FuzzerRtpPacket.cpp',
'fuzzer/src/RTC/FuzzerRtpStreamSend.cpp',
'fuzzer/src/RTC/FuzzerTrendCalculator.cpp',
'fuzzer/src/RTC/RTCP/FuzzerBye.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPs.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsAfb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsFir.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsLei.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsPli.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsRemb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsRpsi.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsSli.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsTst.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsVbcm.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtp.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpEcn.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpNack.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpSrReq.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTllei.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTmmb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerPacket.cpp',
'fuzzer/src/RTC/RTCP/FuzzerReceiverReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSdes.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSenderReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerXr.cpp',
],
include_directories: include_directories(
'include',
'fuzzer/include',
),
cpp_args: cpp_args + [
'-g',
'-O0',
'-fsanitize=address,fuzzer',
'-DMS_LOG_STD',
],
link_args: [
'-fsanitize=address,fuzzer',
],
)
endif
executable(
'mediasoup-worker-fuzzer',
build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-fuzzer',
dependencies: dependencies,
sources: common_sources + [
'fuzzer/src/fuzzer.cpp',
'fuzzer/src/FuzzerUtils.cpp',
'fuzzer/src/RTC/FuzzerStunPacket.cpp',
'fuzzer/src/RTC/FuzzerRtpPacket.cpp',
'fuzzer/src/RTC/FuzzerRtpStreamSend.cpp',
'fuzzer/src/RTC/FuzzerTrendCalculator.cpp',
'fuzzer/src/RTC/RTCP/FuzzerBye.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPs.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsAfb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsFir.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsLei.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsPli.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsRemb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsRpsi.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsSli.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsTst.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsVbcm.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtp.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpEcn.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpNack.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpSrReq.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTllei.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTmmb.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerPacket.cpp',
'fuzzer/src/RTC/RTCP/FuzzerReceiverReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSdes.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSenderReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerXr.cpp',
],
include_directories: include_directories(
'include',
'fuzzer/include',
),
cpp_args: cpp_args + [
'-g',
'-O0',
'-fsanitize=address,fuzzer',
'-DMS_LOG_STD',
],
link_args: [
'-fsanitize=address,fuzzer',
],
)
worker/src/Channel/ChannelSocket.cpp
浏览文件 @
df46fccb
...
...
@@ -11,7 +11,12 @@
namespace
Channel
{
// Binary length for a 4194304 bytes payload.
static
constexpr
size_t
MessageMaxLen
{
4194308
};
static
constexpr
size_t
PayloadMaxLen
{
4194304
};
/* Static methods for UV callbacks. */
inline
static
void
onAsync
(
uv_handle_t
*
handle
)
{
while
(
static_cast
<
ChannelSocket
*>
(
handle
->
data
)
->
CallbackRead
())
...
...
@@ -25,11 +30,8 @@ namespace Channel
delete
handle
;
}
// Binary length for a 4194304 bytes payload.
static
constexpr
size_t
MessageMaxLen
{
4194308
};
static
constexpr
size_t
PayloadMaxLen
{
4194304
};
/* Instance methods. */
ChannelSocket
::
ChannelSocket
(
int
consumerFd
,
int
producerFd
)
:
consumerSocket
(
new
ConsumerSocket
(
consumerFd
,
MessageMaxLen
,
this
)),
producerSocket
(
new
ProducerSocket
(
producerFd
,
MessageMaxLen
)),
...
...
@@ -258,12 +260,19 @@ namespace Channel
this
->
listener
->
OnChannelClosed
(
this
);
}
/* Instance methods. */
ConsumerSocket
::
ConsumerSocket
(
int
fd
,
size_t
bufferSize
,
Listener
*
listener
)
:
::
UnixStreamSocket
(
fd
,
bufferSize
,
::
UnixStreamSocket
::
Role
::
CONSUMER
),
listener
(
listener
)
{
MS_TRACE_STD
();
}
ConsumerSocket
::~
ConsumerSocket
()
{
MS_TRACE_STD
();
}
void
ConsumerSocket
::
UserOnUnixStreamRead
()
{
MS_TRACE_STD
();
...
...
@@ -321,6 +330,8 @@ namespace Channel
this
->
listener
->
OnConsumerSocketClosed
(
this
);
}
/* Instance methods. */
ProducerSocket
::
ProducerSocket
(
int
fd
,
size_t
bufferSize
)
:
::
UnixStreamSocket
(
fd
,
bufferSize
,
::
UnixStreamSocket
::
Role
::
PRODUCER
)
{
...
...
worker/src/ChannelMessageHandlers.cpp
0 → 100644
浏览文件 @
df46fccb
#define MS_CLASS "ChannelMessageHandlers"
// #define MS_LOG_DEV_LEVEL 3
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
/* Class variables. */
thread_local
absl
::
flat_hash_map
<
std
::
string
,
Channel
::
ChannelSocket
::
RequestHandler
*>
ChannelMessageHandlers
::
mapChannelRequestHandlers
;
thread_local
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*>
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
;
thread_local
absl
::
flat_hash_map
<
std
::
string
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*>
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
;
/* Class methods. */
void
ChannelMessageHandlers
::
FillJson
(
json
&
jsonObject
)
{
MS_TRACE
();
// Add channelRequestHandlers.
jsonObject
[
"channelRequestHandlers"
]
=
json
::
array
();
auto
jsonChannelRequestHandlersIt
=
jsonObject
.
find
(
"channelRequestHandlers"
);
for
(
const
auto
&
kv
:
ChannelMessageHandlers
::
mapChannelRequestHandlers
)
{
const
auto
&
handlerId
=
kv
.
first
;
jsonChannelRequestHandlersIt
->
emplace_back
(
handlerId
);
}
// Add payloadChannelRequestHandlers.
jsonObject
[
"payloadChannelRequestHandlers"
]
=
json
::
array
();
auto
jsonPayloadChannelRequestHandlersIt
=
jsonObject
.
find
(
"payloadChannelRequestHandlers"
);
for
(
const
auto
&
kv
:
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
)
{
const
auto
&
handlerId
=
kv
.
first
;
jsonPayloadChannelRequestHandlersIt
->
emplace_back
(
handlerId
);
}
// Add payloadChannelNotificationHandlers.
jsonObject
[
"payloadChannelNotificationHandlers"
]
=
json
::
array
();
auto
jsonPayloadChannelNotificationHandlersIt
=
jsonObject
.
find
(
"payloadChannelNotificationHandlers"
);
for
(
const
auto
&
kv
:
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
)
{
const
auto
&
handlerId
=
kv
.
first
;
jsonPayloadChannelNotificationHandlersIt
->
emplace_back
(
handlerId
);
}
}
void
ChannelMessageHandlers
::
RegisterHandler
(
const
std
::
string
&
id
,
Channel
::
ChannelSocket
::
RequestHandler
*
channelRequestHandler
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
payloadChannelRequestHandler
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
payloadChannelNotificationHandler
)
{
MS_TRACE
();
try
{
if
(
channelRequestHandler
!=
nullptr
)
{
if
(
ChannelMessageHandlers
::
mapChannelRequestHandlers
.
find
(
id
)
!=
ChannelMessageHandlers
::
mapChannelRequestHandlers
.
end
())
{
MS_THROW_ERROR
(
"Channel request handler with ID %s already exists"
,
id
.
c_str
());
}
ChannelMessageHandlers
::
mapChannelRequestHandlers
[
id
]
=
channelRequestHandler
;
}
if
(
payloadChannelRequestHandler
!=
nullptr
)
{
if
(
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
.
find
(
id
)
!=
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
.
end
())
{
MS_THROW_ERROR
(
"PayloadChannel request handler with ID %s already exists"
,
id
.
c_str
());
}
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
[
id
]
=
payloadChannelRequestHandler
;
}
if
(
payloadChannelNotificationHandler
!=
nullptr
)
{
if
(
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
.
find
(
id
)
!=
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
.
end
())
{
MS_THROW_ERROR
(
"PayloadChannel notification handler with ID %s already exists"
,
id
.
c_str
());
}
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
[
id
]
=
payloadChannelNotificationHandler
;
}
}
catch
(
const
MediaSoupError
&
error
)
{
// In case of error unregister everything.
ChannelMessageHandlers
::
UnregisterHandler
(
id
);
throw
;
}
}
void
ChannelMessageHandlers
::
UnregisterHandler
(
const
std
::
string
&
id
)
{
MS_TRACE
();
ChannelMessageHandlers
::
mapChannelRequestHandlers
.
erase
(
id
);
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
.
erase
(
id
);
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
.
erase
(
id
);
}
Channel
::
ChannelSocket
::
RequestHandler
*
ChannelMessageHandlers
::
GetChannelRequestHandler
(
const
std
::
string
&
id
)
{
MS_TRACE
();
auto
it
=
ChannelMessageHandlers
::
mapChannelRequestHandlers
.
find
(
id
);
if
(
it
!=
ChannelMessageHandlers
::
mapChannelRequestHandlers
.
end
())
{
return
it
->
second
;
}
else
{
return
nullptr
;
}
}
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
ChannelMessageHandlers
::
GetPayloadChannelRequestHandler
(
const
std
::
string
&
id
)
{
MS_TRACE
();
auto
it
=
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
.
find
(
id
);
if
(
it
!=
ChannelMessageHandlers
::
mapPayloadChannelRequestHandlers
.
end
())
{
return
it
->
second
;
}
else
{
return
nullptr
;
}
}
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
ChannelMessageHandlers
::
GetPayloadChannelNotificationHandler
(
const
std
::
string
&
id
)
{
MS_TRACE
();
auto
it
=
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
.
find
(
id
);
if
(
it
!=
ChannelMessageHandlers
::
mapPayloadChannelNotificationHandlers
.
end
())
{
return
it
->
second
;
}
else
{
return
nullptr
;
}
}
worker/src/PayloadChannel/PayloadChannelSocket.cpp
浏览文件 @
df46fccb
...
...
@@ -12,7 +12,12 @@
namespace
PayloadChannel
{
/* Static. */
// Binary length for a 4194304 bytes payload.
static
constexpr
size_t
MessageMaxLen
{
4194308
};
static
constexpr
size_t
PayloadMaxLen
{
4194304
};
/* Static methods for UV callbacks. */
inline
static
void
onAsync
(
uv_handle_t
*
handle
)
{
while
(
static_cast
<
PayloadChannelSocket
*>
(
handle
->
data
)
->
CallbackRead
())
...
...
@@ -26,11 +31,8 @@ namespace PayloadChannel
delete
handle
;
}
// Binary length for a 4194304 bytes payload.
static
constexpr
size_t
MessageMaxLen
{
4194308
};
static
constexpr
size_t
PayloadMaxLen
{
4194304
};
/* Instance methods. */
PayloadChannelSocket
::
PayloadChannelSocket
(
int
consumerFd
,
int
producerFd
)
:
consumerSocket
(
new
ConsumerSocket
(
consumerFd
,
MessageMaxLen
,
this
)),
producerSocket
(
new
ProducerSocket
(
producerFd
,
MessageMaxLen
)),
...
...
@@ -361,6 +363,8 @@ namespace PayloadChannel
this
->
listener
->
OnPayloadChannelClosed
(
this
);
}
/* Instance methods. */
ConsumerSocket
::
ConsumerSocket
(
int
fd
,
size_t
bufferSize
,
Listener
*
listener
)
:
::
UnixStreamSocket
(
fd
,
bufferSize
,
::
UnixStreamSocket
::
Role
::
CONSUMER
),
listener
(
listener
)
{
...
...
@@ -429,6 +433,8 @@ namespace PayloadChannel
this
->
listener
->
OnConsumerSocketClosed
(
this
);
}
/* Instance methods. */
ProducerSocket
::
ProducerSocket
(
int
fd
,
size_t
bufferSize
)
:
::
UnixStreamSocket
(
fd
,
bufferSize
,
::
UnixStreamSocket
::
Role
::
PRODUCER
)
{
...
...
worker/src/RTC/ActiveSpeakerObserver.cpp
浏览文件 @
df46fccb
#define MS_CLASS "RTC::ActiveSpeakerObserver"
#include "RTC/ActiveSpeakerObserver.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -101,7 +102,9 @@ namespace RTC
auto
jsonIntervalIt
=
data
.
find
(
"interval"
);
if
(
jsonIntervalIt
==
data
.
end
()
||
!
jsonIntervalIt
->
is_number
())
{
MS_THROW_TYPE_ERROR
(
"missing interval"
);
}
this
->
interval
=
jsonIntervalIt
->
get
<
int16_t
>
();
...
...
@@ -113,12 +116,21 @@ namespace RTC
this
->
periodicTimer
=
new
Timer
(
this
);
this
->
periodicTimer
->
Start
(
interval
,
interval
);
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
ActiveSpeakerObserver
::~
ActiveSpeakerObserver
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
periodicTimer
;
}
...
...
worker/src/RTC/AudioLevelObserver.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/AudioLevelObserver.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -62,12 +63,21 @@ namespace RTC
this
->
periodicTimer
=
new
Timer
(
this
);
this
->
periodicTimer
->
Start
(
this
->
interval
,
this
->
interval
);
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
AudioLevelObserver
::~
AudioLevelObserver
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
periodicTimer
;
}
...
...
worker/src/RTC/DataConsumer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/DataConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -64,11 +65,20 @@ namespace RTC
if
(
jsonProtocolIt
!=
data
.
end
()
&&
jsonProtocolIt
->
is_string
())
this
->
protocol
=
jsonProtocolIt
->
get
<
std
::
string
>
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
DataConsumer
::~
DataConsumer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
}
void
DataConsumer
::
FillJson
(
json
&
jsonObject
)
const
...
...
worker/src/RTC/DataProducer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/DataProducer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -56,11 +57,20 @@ namespace RTC
if
(
jsonProtocolIt
!=
data
.
end
()
&&
jsonProtocolIt
->
is_string
())
this
->
protocol
=
jsonProtocolIt
->
get
<
std
::
string
>
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
this
);
}
DataProducer
::~
DataProducer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
}
void
DataProducer
::
FillJson
(
json
&
jsonObject
)
const
...
...
worker/src/RTC/DirectTransport.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/DirectTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
...
...
@@ -15,11 +16,20 @@ namespace RTC
:
RTC
::
Transport
::
Transport
(
id
,
listener
,
data
)
{
MS_TRACE
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
this
);
}
DirectTransport
::~
DirectTransport
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
}
void
DirectTransport
::
FillJson
(
json
&
jsonObject
)
const
...
...
worker/src/RTC/PipeConsumer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/PipeConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -28,12 +29,21 @@ namespace RTC
// Create RtpStreamSend instances.
CreateRtpStreams
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
PipeConsumer
::~
PipeConsumer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
for
(
auto
*
rtpStream
:
this
->
rtpStreams
)
{
delete
rtpStream
;
...
...
worker/src/RTC/PipeTransport.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/PipeTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -93,6 +94,13 @@ namespace RTC
this
->
udpSocket
=
new
RTC
::
UdpSocket
(
this
,
this
->
listenIp
.
ip
,
port
);
else
this
->
udpSocket
=
new
RTC
::
UdpSocket
(
this
,
this
->
listenIp
.
ip
);
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
this
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -109,6 +117,8 @@ namespace RTC
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
udpSocket
;
this
->
udpSocket
=
nullptr
;
...
...
worker/src/RTC/PlainTransport.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/PlainTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -172,7 +173,6 @@ namespace RTC
try
{
// This may throw.
// This may throw.
if
(
port
!=
0
)
this
->
udpSocket
=
new
RTC
::
UdpSocket
(
this
,
this
->
listenIp
.
ip
,
port
);
...
...
@@ -184,6 +184,13 @@ namespace RTC
// This may throw.
this
->
rtcpUdpSocket
=
new
RTC
::
UdpSocket
(
this
,
this
->
listenIp
.
ip
);
}
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
this
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -201,6 +208,8 @@ namespace RTC
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
udpSocket
;
this
->
udpSocket
=
nullptr
;
...
...
worker/src/RTC/Producer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/Producer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -313,12 +314,21 @@ namespace RTC
this
->
keyFrameRequestManager
=
new
RTC
::
KeyFrameRequestManager
(
this
,
keyFrameRequestDelay
);
}
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
this
);
}
Producer
::~
Producer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
// Delete all streams.
for
(
auto
&
kv
:
this
->
mapSsrcRtpStream
)
{
...
...
worker/src/RTC/Router.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/Router.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -19,12 +20,21 @@ namespace RTC
Router
::
Router
(
const
std
::
string
&
id
,
Listener
*
listener
)
:
id
(
id
),
listener
(
listener
)
{
MS_TRACE
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
Router
::~
Router
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
// Close all Transports.
for
(
auto
&
kv
:
this
->
mapTransports
)
{
...
...
@@ -191,10 +201,6 @@ namespace RTC
// Insert into the map.
this
->
mapTransports
[
transportId
]
=
webRtcTransport
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
transportId
,
webRtcTransport
);
this
->
listener
->
OnPayloadChannelRequestHandlerAdded
(
transportId
,
webRtcTransport
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
transportId
,
webRtcTransport
);
MS_DEBUG_DEV
(
"WebRtcTransport created [transportId:%s]"
,
transportId
.
c_str
());
json
data
=
json
::
object
();
...
...
@@ -281,10 +287,6 @@ namespace RTC
// Insert into the map.
this
->
mapTransports
[
transportId
]
=
webRtcTransport
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
transportId
,
webRtcTransport
);
this
->
listener
->
OnPayloadChannelRequestHandlerAdded
(
transportId
,
webRtcTransport
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
transportId
,
webRtcTransport
);
MS_DEBUG_DEV
(
"WebRtcTransport with WebRtcServer created [transportId:%s]"
,
transportId
.
c_str
());
...
...
@@ -309,10 +311,6 @@ namespace RTC
// Insert into the map.
this
->
mapTransports
[
transportId
]
=
plainTransport
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
transportId
,
plainTransport
);
this
->
listener
->
OnPayloadChannelRequestHandlerAdded
(
transportId
,
plainTransport
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
transportId
,
plainTransport
);
MS_DEBUG_DEV
(
"PlainTransport created [transportId:%s]"
,
transportId
.
c_str
());
json
data
=
json
::
object
();
...
...
@@ -336,10 +334,6 @@ namespace RTC
// Insert into the map.
this
->
mapTransports
[
transportId
]
=
pipeTransport
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
transportId
,
pipeTransport
);
this
->
listener
->
OnPayloadChannelRequestHandlerAdded
(
transportId
,
pipeTransport
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
transportId
,
pipeTransport
);
MS_DEBUG_DEV
(
"PipeTransport created [transportId:%s]"
,
transportId
.
c_str
());
json
data
=
json
::
object
();
...
...
@@ -363,10 +357,6 @@ namespace RTC
// Insert into the map.
this
->
mapTransports
[
transportId
]
=
directTransport
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
transportId
,
directTransport
);
this
->
listener
->
OnPayloadChannelRequestHandlerAdded
(
transportId
,
directTransport
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
transportId
,
directTransport
);
MS_DEBUG_DEV
(
"DirectTransport created [transportId:%s]"
,
transportId
.
c_str
());
json
data
=
json
::
object
();
...
...
@@ -391,8 +381,6 @@ namespace RTC
// Insert into the map.
this
->
mapRtpObservers
[
rtpObserverId
]
=
activeSpeakerObserver
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
rtpObserverId
,
activeSpeakerObserver
);
MS_DEBUG_DEV
(
"ActiveSpeakerObserver created [rtpObserverId:%s]"
,
rtpObserverId
.
c_str
());
request
->
Accept
();
...
...
@@ -412,8 +400,6 @@ namespace RTC
// Insert into the map.
this
->
mapRtpObservers
[
rtpObserverId
]
=
audioLevelObserver
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
rtpObserverId
,
audioLevelObserver
);
MS_DEBUG_DEV
(
"AudioLevelObserver created [rtpObserverId:%s]"
,
rtpObserverId
.
c_str
());
request
->
Accept
();
...
...
@@ -433,10 +419,6 @@ namespace RTC
// Remove it from the map.
this
->
mapTransports
.
erase
(
transport
->
id
);
this
->
listener
->
OnChannelRequestHandlerRemoved
(
transport
->
id
);
this
->
listener
->
OnPayloadChannelRequestHandlerRemoved
(
transport
->
id
);
this
->
listener
->
OnPayloadChannelNotificationHandlerRemoved
(
transport
->
id
);
MS_DEBUG_DEV
(
"Transport closed [transportId:%s]"
,
transport
->
id
.
c_str
());
// Delete it.
...
...
@@ -463,8 +445,6 @@ namespace RTC
rtpObservers
.
erase
(
rtpObserver
);
}
this
->
listener
->
OnChannelRequestHandlerRemoved
(
rtpObserver
->
id
);
MS_DEBUG_DEV
(
"RtpObserver closed [rtpObserverId:%s]"
,
rtpObserver
->
id
.
c_str
());
// Delete it.
...
...
@@ -579,9 +559,6 @@ namespace RTC
this
->
mapProducers
[
producer
->
id
]
=
producer
;
this
->
mapProducerConsumers
[
producer
];
this
->
mapProducerRtpObservers
[
producer
];
this
->
listener
->
OnChannelRequestHandlerAdded
(
producer
->
id
,
producer
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
producer
->
id
,
producer
);
}
inline
void
Router
::
OnTransportProducerClosed
(
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
)
...
...
@@ -627,9 +604,6 @@ namespace RTC
this
->
mapProducers
.
erase
(
mapProducersIt
);
this
->
mapProducerConsumers
.
erase
(
mapProducerConsumersIt
);
this
->
mapProducerRtpObservers
.
erase
(
mapProducerRtpObserversIt
);
this
->
listener
->
OnChannelRequestHandlerRemoved
(
producer
->
id
);
this
->
listener
->
OnPayloadChannelNotificationHandlerRemoved
(
producer
->
id
);
}
inline
void
Router
::
OnTransportProducerPaused
(
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
)
...
...
@@ -819,8 +793,6 @@ namespace RTC
// Provide the Consumer with the scores of all streams in the Producer.
consumer
->
ProducerRtpStreamScores
(
producer
->
GetRtpStreamScores
());
this
->
listener
->
OnChannelRequestHandlerAdded
(
consumer
->
id
,
consumer
);
}
inline
void
Router
::
OnTransportConsumerClosed
(
RTC
::
Transport
*
/*transport*/
,
RTC
::
Consumer
*
consumer
)
...
...
@@ -852,8 +824,6 @@ namespace RTC
// Remove the Consumer from the map.
this
->
mapConsumerProducer
.
erase
(
mapConsumerProducerIt
);
this
->
listener
->
OnChannelRequestHandlerRemoved
(
consumer
->
id
);
}
inline
void
Router
::
OnTransportConsumerProducerClosed
(
...
...
@@ -906,9 +876,6 @@ namespace RTC
// Insert the DataProducer in the maps.
this
->
mapDataProducers
[
dataProducer
->
id
]
=
dataProducer
;
this
->
mapDataProducerDataConsumers
[
dataProducer
];
this
->
listener
->
OnChannelRequestHandlerAdded
(
dataProducer
->
id
,
dataProducer
);
this
->
listener
->
OnPayloadChannelNotificationHandlerAdded
(
dataProducer
->
id
,
dataProducer
);
}
inline
void
Router
::
OnTransportDataProducerClosed
(
...
...
@@ -945,9 +912,6 @@ namespace RTC
// Remove the DataProducer from the maps.
this
->
mapDataProducers
.
erase
(
mapDataProducersIt
);
this
->
mapDataProducerDataConsumers
.
erase
(
mapDataProducerDataConsumersIt
);
this
->
listener
->
OnChannelRequestHandlerRemoved
(
dataProducer
->
id
);
this
->
listener
->
OnPayloadChannelNotificationHandlerRemoved
(
dataProducer
->
id
);
}
inline
void
Router
::
OnTransportDataProducerMessageReceived
(
...
...
@@ -992,8 +956,6 @@ namespace RTC
dataConsumers
.
insert
(
dataConsumer
);
this
->
mapDataConsumerDataProducer
[
dataConsumer
]
=
dataProducer
;
this
->
listener
->
OnChannelRequestHandlerAdded
(
dataConsumer
->
id
,
dataConsumer
);
}
inline
void
Router
::
OnTransportDataConsumerClosed
(
...
...
@@ -1027,8 +989,6 @@ namespace RTC
// Remove the DataConsumer from the map.
this
->
mapDataConsumerDataProducer
.
erase
(
mapDataConsumerDataProducerIt
);
this
->
listener
->
OnChannelRequestHandlerRemoved
(
dataConsumer
->
id
);
}
inline
void
Router
::
OnTransportDataConsumerDataProducerClosed
(
...
...
worker/src/RTC/SimpleConsumer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/SimpleConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -50,12 +51,21 @@ namespace RTC
this
->
encodingContext
->
SetIgnoreDtx
(
ignoreDtx
);
}
}
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
SimpleConsumer
::~
SimpleConsumer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
rtpStream
;
}
...
...
worker/src/RTC/SimulcastConsumer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/SimulcastConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -119,12 +120,21 @@ namespace RTC
// Create RtpStreamSend instance for sending a single stream to the remote.
CreateRtpStream
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
SimulcastConsumer
::~
SimulcastConsumer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
rtpStream
;
}
...
...
worker/src/RTC/SvcConsumer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/SvcConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
...
...
@@ -102,12 +103,21 @@ namespace RTC
// Create RtpStreamSend instance for sending a single stream to the remote.
CreateRtpStream
();
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
SvcConsumer
::~
SvcConsumer
()
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
delete
this
->
rtpStream
;
}
...
...
worker/src/RTC/WebRtcServer.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/WebRtcServer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -122,6 +123,13 @@ namespace RTC
this
->
udpSocketOrTcpServers
.
emplace_back
(
nullptr
,
tcpServer
,
listenInfo
.
announcedIp
);
}
}
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
nullptr
,
/*payloadChannelNotificationHandler*/
nullptr
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -145,6 +153,8 @@ namespace RTC
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
for
(
auto
&
item
:
this
->
udpSocketOrTcpServers
)
{
delete
item
.
udpSocket
;
...
...
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/WebRtcTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
...
...
@@ -203,6 +204,13 @@ namespace RTC
// Create a DTLS transport.
this
->
dtlsTransport
=
new
RTC
::
DtlsTransport
(
this
);
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
this
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -264,6 +272,13 @@ namespace RTC
// Notify the webRtcTransportListener.
this
->
webRtcTransportListener
->
OnWebRtcTransportCreated
(
this
);
// NOTE: This may throw.
ChannelMessageHandlers
::
RegisterHandler
(
this
->
id
,
/*channelRequestHandler*/
this
,
/*payloadChannelRequestHandler*/
this
,
/*payloadChannelNotificationHandler*/
this
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -285,6 +300,8 @@ namespace RTC
{
MS_TRACE
();
ChannelMessageHandlers
::
UnregisterHandler
(
this
->
id
);
// Must delete the DTLS transport first since it will generate a DTLS alert
// to be sent.
delete
this
->
dtlsTransport
;
...
...
worker/src/Worker.cpp
浏览文件 @
df46fccb
...
...
@@ -2,6 +2,7 @@
// #define MS_LOG_DEV_LEVEL 3
#include "Worker.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp"
#include "DepUsrSCTP.hpp"
#include "Logger.hpp"
...
...
@@ -90,11 +91,6 @@ void Worker::Close()
// Close the PayloadChannel.
this
->
payloadChannel
->
Close
();
// Clear all request and notification handlers.
this
->
mapChannelRequestHandlers
.
clear
();
this
->
mapPayloadChannelRequestHandlers
.
clear
();
this
->
mapPayloadChannelNotificationHandlers
.
clear
();
}
void
Worker
::
FillJson
(
json
&
jsonObject
)
const
...
...
@@ -125,6 +121,12 @@ void Worker::FillJson(json& jsonObject) const
jsonRouterIdsIt
->
emplace_back
(
routerId
);
}
// Add channelMessageHandlers.
jsonObject
[
"channelMessageHandlers"
]
=
json
::
object
();
auto
jsonChannelMessageHandlersIt
=
jsonObject
.
find
(
"channelMessageHandlers"
);
ChannelMessageHandlers
::
FillJson
(
*
jsonChannelMessageHandlersIt
);
}
void
Worker
::
FillJsonResourceUsage
(
json
&
jsonObject
)
const
...
...
@@ -319,7 +321,6 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
auto
*
webRtcServer
=
new
RTC
::
WebRtcServer
(
webRtcServerId
,
request
->
data
);
this
->
mapWebRtcServers
[
webRtcServerId
]
=
webRtcServer
;
this
->
OnChannelRequestHandlerAdded
(
webRtcServerId
,
webRtcServer
);
MS_DEBUG_DEV
(
"WebRtcServer created [webRtcServerId:%s]"
,
webRtcServerId
.
c_str
());
...
...
@@ -352,7 +353,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
// Remove it from the map and delete it.
this
->
mapWebRtcServers
.
erase
(
webRtcServer
->
id
);
this
->
OnChannelRequestHandlerRemoved
(
webRtcServer
->
id
);
delete
webRtcServer
;
MS_DEBUG_DEV
(
"WebRtcServer closed [id:%s]"
,
webRtcServer
->
id
.
c_str
());
...
...
@@ -378,7 +379,6 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
auto
*
router
=
new
RTC
::
Router
(
routerId
,
this
);
this
->
mapRouters
[
routerId
]
=
router
;
this
->
OnChannelRequestHandlerAdded
(
routerId
,
router
);
MS_DEBUG_DEV
(
"Router created [routerId:%s]"
,
routerId
.
c_str
());
...
...
@@ -402,7 +402,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
// Remove it from the map and delete it.
this
->
mapRouters
.
erase
(
router
->
id
);
this
->
OnChannelRequestHandlerRemoved
(
router
->
id
);
delete
router
;
MS_DEBUG_DEV
(
"Router closed [id:%s]"
,
router
->
id
.
c_str
());
...
...
@@ -417,12 +417,14 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
{
try
{
auto
it
=
this
->
mapChannelRequestHandlers
.
find
(
request
->
handlerId
);
auto
*
handler
=
ChannelMessageHandlers
::
GetChannelRequestHandler
(
request
->
handlerId
);
if
(
it
==
this
->
mapChannelRequestHandlers
.
end
())
MS_THROW_ERROR
(
"Channel handler with ID %s not found"
,
request
->
handlerId
.
c_str
());
if
(
handler
==
nullptr
)
{
MS_THROW_ERROR
(
"Channel request handler with ID %s not found"
,
request
->
handlerId
.
c_str
());
}
it
->
second
->
HandleRequest
(
request
);
handler
->
HandleRequest
(
request
);
}
catch
(
const
MediaSoupTypeError
&
error
)
{
...
...
@@ -452,56 +454,63 @@ inline void Worker::OnChannelClosed(Channel::ChannelSocket* /*socket*/)
Close
();
}
inline
void
Worker
::
Handle
Notification
(
PayloadChannel
::
PayloadChannelNotification
*
notification
)
inline
void
Worker
::
Handle
Request
(
PayloadChannel
::
PayloadChannelRequest
*
request
)
{
MS_TRACE
();
MS_DEBUG_DEV
(
"PayloadChannel notification received [event:%s]"
,
notification
->
event
.
c_str
());
MS_DEBUG_DEV
(
"PayloadChannel request received [method:%s, id:%"
PRIu32
"]"
,
request
->
method
.
c_str
(),
request
->
id
);
try
{
auto
it
=
this
->
mapPayloadChannelNotificationHandlers
.
find
(
notification
->
handlerId
);
auto
*
handler
=
ChannelMessageHandlers
::
GetPayloadChannelRequestHandler
(
request
->
handlerId
);
if
(
it
==
this
->
mapPayloadChannelNotificationHandlers
.
end
())
MS_THROW_ERROR
(
"Notification handler with ID %s not found"
,
notification
->
handlerId
.
c_str
());
if
(
handler
==
nullptr
)
{
MS_THROW_ERROR
(
"PayloadChannel request handler with ID %s not found"
,
request
->
handlerId
.
c_str
());
}
it
->
second
->
HandleNotification
(
notification
);
handler
->
HandleRequest
(
request
);
}
catch
(
const
MediaSoupTypeError
&
error
)
{
MS_THROW_TYPE_ERROR
(
"%s [
event:%s]"
,
error
.
what
(),
notification
->
event
.
c_str
());
MS_THROW_TYPE_ERROR
(
"%s [
method:%s]"
,
error
.
what
(),
request
->
method
.
c_str
());
}
catch
(
const
MediaSoupError
&
error
)
{
MS_THROW_ERROR
(
"%s [method:%s]"
,
error
.
what
(),
notification
->
event
.
c_str
());
MS_THROW_ERROR
(
"%s [method:%s]"
,
error
.
what
(),
request
->
method
.
c_str
());
}
}
inline
void
Worker
::
Handle
Request
(
PayloadChannel
::
PayloadChannelRequest
*
request
)
inline
void
Worker
::
Handle
Notification
(
PayloadChannel
::
PayloadChannelNotification
*
notification
)
{
MS_TRACE
();
MS_DEBUG_DEV
(
"PayloadChannel request received [method:%s, id:%"
PRIu32
"]"
,
request
->
method
.
c_str
(),
request
->
id
);
MS_DEBUG_DEV
(
"PayloadChannel notification received [event:%s]"
,
notification
->
event
.
c_str
());
try
{
auto
it
=
this
->
mapPayloadChannelRequestHandlers
.
find
(
request
->
handlerId
);
auto
*
handler
=
ChannelMessageHandlers
::
GetPayloadChannelNotificationHandler
(
notification
->
handlerId
);
if
(
it
==
this
->
mapPayloadChannelRequestHandlers
.
end
())
MS_THROW_ERROR
(
"Payload channel handler with ID %s not found"
,
request
->
handlerId
.
c_str
());
if
(
handler
==
nullptr
)
{
MS_THROW_ERROR
(
"PayloadChannel notification handler with ID %s not found"
,
notification
->
handlerId
.
c_str
());
}
it
->
second
->
HandleRequest
(
request
);
handler
->
HandleNotification
(
notification
);
}
catch
(
const
MediaSoupTypeError
&
error
)
{
MS_THROW_TYPE_ERROR
(
"%s [
method:%s]"
,
error
.
what
(),
request
->
method
.
c_str
());
MS_THROW_TYPE_ERROR
(
"%s [
event:%s]"
,
error
.
what
(),
notification
->
event
.
c_str
());
}
catch
(
const
MediaSoupError
&
error
)
{
MS_THROW_ERROR
(
"%s [method:%s]"
,
error
.
what
(),
request
->
method
.
c_str
());
MS_THROW_ERROR
(
"%s [method:%s]"
,
error
.
what
(),
notification
->
event
.
c_str
());
}
}
...
...
@@ -559,68 +568,6 @@ inline void Worker::OnSignal(SignalsHandler* /*signalsHandler*/, int signum)
}
}
inline
void
Worker
::
OnChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
Channel
::
ChannelSocket
::
RequestHandler
*
handler
)
{
MS_TRACE
();
if
(
this
->
mapChannelRequestHandlers
.
find
(
id
)
!=
this
->
mapChannelRequestHandlers
.
end
())
{
MS_THROW_ERROR
(
"Channel request handler with ID %s already exists"
,
id
.
c_str
());
}
this
->
mapChannelRequestHandlers
[
id
]
=
handler
;
}
inline
void
Worker
::
OnChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
{
MS_TRACE
();
this
->
mapChannelRequestHandlers
.
erase
(
id
);
}
inline
void
Worker
::
OnPayloadChannelRequestHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
RequestHandler
*
handler
)
{
MS_TRACE
();
if
(
this
->
mapPayloadChannelRequestHandlers
.
find
(
id
)
!=
this
->
mapPayloadChannelRequestHandlers
.
end
())
{
MS_THROW_ERROR
(
"PayloadChannel request handler with ID %s already exists"
,
id
.
c_str
());
}
this
->
mapPayloadChannelRequestHandlers
[
id
]
=
handler
;
}
inline
void
Worker
::
OnPayloadChannelRequestHandlerRemoved
(
const
std
::
string
&
id
)
{
MS_TRACE
();
this
->
mapPayloadChannelRequestHandlers
.
erase
(
id
);
}
inline
void
Worker
::
OnPayloadChannelNotificationHandlerAdded
(
const
std
::
string
&
id
,
PayloadChannel
::
PayloadChannelSocket
::
NotificationHandler
*
handler
)
{
MS_TRACE
();
if
(
this
->
mapPayloadChannelNotificationHandlers
.
find
(
id
)
!=
this
->
mapPayloadChannelNotificationHandlers
.
end
())
{
MS_THROW_ERROR
(
"PayloadChannel notification handler with ID %s already exists"
,
id
.
c_str
());
}
this
->
mapPayloadChannelNotificationHandlers
[
id
]
=
handler
;
}
inline
void
Worker
::
OnPayloadChannelNotificationHandlerRemoved
(
const
std
::
string
&
id
)
{
MS_TRACE
();
this
->
mapPayloadChannelNotificationHandlers
.
erase
(
id
);
}
inline
RTC
::
WebRtcServer
*
Worker
::
OnRouterNeedWebRtcServer
(
RTC
::
Router
*
/*router*/
,
std
::
string
&
webRtcServerId
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论