Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
6262224c
提交
6262224c
authored
11月 22, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New C++ style.
上级
9fbdf500
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
95 个修改的文件
包含
1199 行增加
和
1309 行删除
+1199
-1309
Message.h
include/ControlProtocol/Message.h
+44
-48
Parser.h
include/ControlProtocol/Parser.h
+54
-59
Request.h
include/ControlProtocol/Request.h
+21
-25
TCPConnection.h
include/ControlProtocol/TCPConnection.h
+23
-27
TCPServer.h
include/ControlProtocol/TCPServer.h
+23
-27
UnixStreamSocket.h
include/ControlProtocol/UnixStreamSocket.h
+25
-29
messages.h
include/ControlProtocol/messages.h
+0
-2
RequestAuthenticate.h
include/ControlProtocol/messages/RequestAuthenticate.h
+14
-19
RequestCreateConference.h
include/ControlProtocol/messages/RequestCreateConference.h
+9
-14
RequestHello.h
include/ControlProtocol/messages/RequestHello.h
+9
-14
Daemon.h
include/Daemon.h
+2
-3
Dispatcher.h
include/Dispatcher.h
+0
-3
LibSRTP.h
include/LibSRTP.h
+6
-8
LibUV.h
include/LibUV.h
+4
-6
Logger.h
include/Logger.h
+66
-42
MediaSoup.h
include/MediaSoup.h
+2
-3
MediaSoupError.h
include/MediaSoupError.h
+7
-10
OpenSSL.h
include/OpenSSL.h
+4
-6
DTLSHandler.h
include/RTC/DTLSHandler.h
+120
-125
DTLSRole.h
include/RTC/DTLSRole.h
+6
-11
FingerprintHash.h
include/RTC/FingerprintHash.h
+11
-15
ICEServer.h
include/RTC/ICEServer.h
+56
-60
Peer.h
include/RTC/Peer.h
+40
-48
RTCPPacket.h
include/RTC/RTCPPacket.h
+72
-76
RTPPacket.h
include/RTC/RTPPacket.h
+192
-195
Room.h
include/RTC/Room.h
+19
-26
SRTPProfile.h
include/RTC/SRTPProfile.h
+8
-12
SRTPSession.h
include/RTC/SRTPSession.h
+45
-49
STUNMessage.h
include/RTC/STUNMessage.h
+0
-0
Stream.h
include/RTC/Stream.h
+12
-17
TCPConnection.h
include/RTC/TCPConnection.h
+25
-29
TCPServer.h
include/RTC/TCPServer.h
+47
-51
Transport.h
include/RTC/Transport.h
+0
-0
TransportSource.h
include/RTC/TransportSource.h
+102
-105
UDPSocket.h
include/RTC/UDPSocket.h
+45
-49
Settings.h
include/Settings.h
+12
-9
Utils.h
include/Utils.h
+0
-0
Version.h
include/Version.h
+2
-4
Worker.h
include/Worker.h
+0
-3
common.h
include/common.h
+0
-3
SignalsHandler.h
include/handles/SignalsHandler.h
+4
-5
TCPConnection.h
include/handles/TCPConnection.h
+24
-24
TCPServer.h
include/handles/TCPServer.h
+10
-12
Timer.h
include/handles/Timer.h
+4
-5
UDPSocket.h
include/handles/UDPSocket.h
+18
-19
UnixStreamSocket.h
include/handles/UnixStreamSocket.h
+10
-11
Message.cpp
src/ControlProtocol/Message.cpp
+0
-0
Parser.cpp
src/ControlProtocol/Parser.cpp
+0
-0
Parser.rl
src/ControlProtocol/Parser.rl
+0
-0
Request.cpp
src/ControlProtocol/Request.cpp
+0
-0
TCPConnection.cpp
src/ControlProtocol/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/ControlProtocol/TCPServer.cpp
+0
-0
UnixStreamSocket.cpp
src/ControlProtocol/UnixStreamSocket.cpp
+0
-0
RequestAuthenticate.rl
src/ControlProtocol/grammar/RequestAuthenticate.rl
+0
-0
RequestCreateConference.rl
src/ControlProtocol/grammar/RequestCreateConference.rl
+2
-1
RequestHello.rl
src/ControlProtocol/grammar/RequestHello.rl
+0
-0
RequestAuthenticate.cpp
src/ControlProtocol/messages/RequestAuthenticate.cpp
+0
-0
RequestCreateConference.cpp
src/ControlProtocol/messages/RequestCreateConference.cpp
+0
-0
RequestHello.cpp
src/ControlProtocol/messages/RequestHello.cpp
+0
-0
Daemon.cpp
src/Daemon.cpp
+0
-0
Dispatcher.cpp
src/Dispatcher.cpp
+0
-0
LibSRTP.cpp
src/LibSRTP.cpp
+0
-0
LibUV.cpp
src/LibUV.cpp
+0
-0
Logger.cpp
src/Logger.cpp
+0
-0
MediaSoup.cpp
src/MediaSoup.cpp
+0
-0
OpenSSL.cpp
src/OpenSSL.cpp
+0
-0
DTLSHandler.cpp
src/RTC/DTLSHandler.cpp
+0
-0
ICEServer.cpp
src/RTC/ICEServer.cpp
+0
-0
Peer.cpp
src/RTC/Peer.cpp
+0
-0
RTCPPacket.cpp
src/RTC/RTCPPacket.cpp
+0
-0
RTPPacket.cpp
src/RTC/RTPPacket.cpp
+0
-0
Room.cpp
src/RTC/Room.cpp
+0
-0
SRTPSession.cpp
src/RTC/SRTPSession.cpp
+0
-0
STUNMessage.cpp
src/RTC/STUNMessage.cpp
+0
-0
Stream.cpp
src/RTC/Stream.cpp
+0
-0
TCPConnection.cpp
src/RTC/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/RTC/TCPServer.cpp
+0
-0
Transport.cpp
src/RTC/Transport.cpp
+0
-0
TransportSource.cpp
src/RTC/TransportSource.cpp
+0
-0
UDPSocket.cpp
src/RTC/UDPSocket.cpp
+0
-0
Settings.cpp
src/Settings.cpp
+0
-0
Crypto.cpp
src/Utils/Crypto.cpp
+0
-0
File.cpp
src/Utils/File.cpp
+0
-0
IP.cpp
src/Utils/IP.cpp
+0
-0
IP.rl
src/Utils/IP.rl
+0
-0
Socket.cpp
src/Utils/Socket.cpp
+0
-0
Version.cpp
src/Version.cpp
+0
-0
Worker.cpp
src/Worker.cpp
+0
-0
SignalsHandler.cpp
src/handles/SignalsHandler.cpp
+0
-0
TCPConnection.cpp
src/handles/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/handles/TCPServer.cpp
+0
-0
Timer.cpp
src/handles/Timer.cpp
+0
-0
UDPSocket.cpp
src/handles/UDPSocket.cpp
+0
-0
UnixStreamSocket.cpp
src/handles/UnixStreamSocket.cpp
+0
-0
main.cpp
src/main.cpp
+0
-0
没有找到文件。
include/ControlProtocol/Message.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_MESSAGE_H
#define MS_CONTROL_PROTOCOL_MESSAGE_H
#include "common.h"
namespace
ControlProtocol
{
class
Message
{
public
:
enum
class
Kind
{
Request
=
1
,
Response
,
Notification
namespace
ControlProtocol
{
class
Message
{
public
:
enum
class
Kind
{
Request
=
1
,
Response
,
Notification
};
public
:
Message
(
Kind
);
virtual
~
Message
();
Kind
GetKind
();
virtual
bool
IsValid
();
// TODO: Must be pure virtual.
void
SetTransaction
(
int32_t
transaction
);
int32_t
GetTransaction
();
virtual
void
Dump
()
=
0
;
protected
:
Kind
kind
;
int32_t
transaction
=
0
;
};
public
:
Message
(
Kind
);
virtual
~
Message
();
Kind
GetKind
();
virtual
bool
IsValid
();
// TODO: Must be pure virtual.
void
SetTransaction
(
int32_t
transaction
);
int32_t
GetTransaction
();
virtual
void
Dump
()
=
0
;
protected
:
Kind
kind
;
int32_t
transaction
=
0
;
};
/* Inlime methods. */
inline
Message
::
Kind
Message
::
GetKind
()
{
return
this
->
kind
;
}
inline
void
Message
::
SetTransaction
(
int32_t
transaction
)
{
this
->
transaction
=
transaction
;
}
inline
int32_t
Message
::
GetTransaction
()
{
return
this
->
transaction
;
}
/* Inlime methods. */
inline
Message
::
Kind
Message
::
GetKind
()
{
return
this
->
kind
;
}
inline
void
Message
::
SetTransaction
(
int32_t
transaction
)
{
this
->
transaction
=
transaction
;
}
inline
int32_t
Message
::
GetTransaction
()
{
return
this
->
transaction
;
}
}
// namespace ControlProtocol
#endif
include/ControlProtocol/Parser.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_PARSER_H
#define MS_CONTROL_PROTOCOL_PARSER_H
#include "common.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
Parser
{
public
:
Parser
();
virtual
~
Parser
();
/**
* Parses the given buffer.
*
* @param buffer The buffer to parse.
* @param len The lenght of the buffer.
*
* @return Returns a pointer to ControlProtocol::Message if parsing succeded,
* or nullptr if the message is not completed or parsing failed.
*/
Message
*
Parse
(
const
MS_BYTE
*
buffer
,
size_t
len
);
/**
* Checks whether the ongoing parsing has error or not.
*
* @return true if there is parsing error, false otherwise.
*/
bool
HasError
();
/**
* Get the length of the complete or uncomplete message parsed or being parsed.
*
* @return The number of chars parsed in the current message.
*/
size_t
GetParsedLen
();
/**
* Resets the parser internals. Must be called before parsing a new message
* (regardless the previous one succeded or not).
*/
void
Reset
();
/**
* Prints current status of the parser.
*/
void
Dump
();
protected
:
size_t
parsedLen
;
private
:
// Allocated by this:
ControlProtocol
::
Message
*
msg
=
nullptr
;
// Others:
size_t
cs
=
0
;
// Needed for Ragel.
size_t
mark
=
0
;
};
namespace
ControlProtocol
{
class
Parser
{
public
:
Parser
();
virtual
~
Parser
();
/**
* Parses the given buffer.
*
* @param buffer The buffer to parse.
* @param len The lenght of the buffer.
*
* @return Returns a pointer to ControlProtocol::Message if parsing succeded,
* or nullptr if the message is not completed or parsing failed.
*/
Message
*
Parse
(
const
MS_BYTE
*
buffer
,
size_t
len
);
/**
* Checks whether the ongoing parsing has error or not.
*
* @return true if there is parsing error, false otherwise.
*/
bool
HasError
();
/**
* Get the length of the complete or uncomplete message parsed or being parsed.
*
* @return The number of chars parsed in the current message.
*/
size_t
GetParsedLen
();
/**
* Resets the parser internals. Must be called before parsing a new message
* (regardless the previous one succeded or not).
*/
void
Reset
();
/**
* Prints current status of the parser.
*/
void
Dump
();
protected
:
size_t
parsedLen
;
private
:
// Allocated by this:
ControlProtocol
::
Message
*
msg
=
nullptr
;
// Others:
size_t
cs
=
0
;
// Needed for Ragel.
size_t
mark
=
0
;
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/Request.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_H
#define MS_CONTROL_PROTOCOL_REQUEST_H
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
Request
:
public
ControlProtocol
::
Message
{
public
:
enum
class
Type
{
Hello
=
1
,
Authenticate
,
CreateConference
namespace
ControlProtocol
{
class
Request
:
public
ControlProtocol
::
Message
{
public
:
enum
class
Type
{
Hello
=
1
,
Authenticate
,
CreateConference
};
public
:
Request
(
Type
);
virtual
~
Request
();
virtual
void
Dump
()
=
0
;
public
:
// Allow fast access to type.
Type
type
;
};
public
:
Request
(
Type
);
virtual
~
Request
();
virtual
void
Dump
()
=
0
;
public
:
// Allow fast access to type.
Type
type
;
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#define MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#include "common.h"
#include "handles/TCPConnection.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
TCPConnection
:
public
::
TCPConnection
{
public
:
class
Reader
{
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
TCPConnection
*
connection
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
};
namespace
ControlProtocol
{
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
class
TCPConnection
:
public
::
TCPConnection
{
public
:
class
Reader
{
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
TCPConnection
*
connection
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_TCP_SERVER_H
#define MS_CONTROL_PROTOCOL_TCP_SERVER_H
#include "common.h"
#include "handles/TCPServer.h"
#include "handles/TCPConnection.h"
...
...
@@ -9,36 +8,33 @@
#include "ControlProtocol/Message.h"
#include <string>
namespace
ControlProtocol
{
class
TCPServer
:
public
::
TCPServer
{
public
:
class
Listener
{
public
:
virtual
void
onControlProtocolNewTCPConnection
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
)
=
0
;
virtual
void
onControlProtocolTCPConnectionClosed
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
namespace
ControlProtocol
{
public
:
TCPServer
(
Listener
*
listener
,
ControlProtocol
::
TCPConnection
::
Reader
*
reader
,
const
std
::
string
&
ip
,
MS_PORT
port
);
class
TCPServer
:
public
::
TCPServer
{
public
:
class
Listener
{
/* Pure virtual methods inherited from ::TCPServer. */
public
:
virtual
void
onControlProtocolNewTCPConnection
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
)
=
0
;
virtual
void
onControlProtocolTCPConnectionClosed
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
ControlProtocol
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
public
:
TCPServer
(
Listener
*
listener
,
ControlProtocol
::
TCPConnection
::
Reader
*
reader
,
const
std
::
string
&
ip
,
MS_PORT
port
);
/* Pure virtual methods inherited from ::TCPServer. */
public
:
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
ControlProtocol
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/UnixStreamSocket.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#define MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#include "common.h"
#include "handles/UnixStreamSocket.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
UnixStreamSocket
:
public
::
UnixStreamSocket
{
public
:
class
Listener
{
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
onControlProtocolUnixStreamSocketClosed
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
bool
is_closed_by_peer
)
=
0
;
};
namespace
ControlProtocol
{
public
:
UnixStreamSocket
(
Listener
*
listener
,
int
fd
);
virtual
~
UnixStreamSocket
();
class
UnixStreamSocket
:
public
::
UnixStreamSocket
{
public
:
class
Listener
{
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
onControlProtocolUnixStreamSocketClosed
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnUnixStreamRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
public
:
UnixStreamSocket
(
Listener
*
listener
,
int
fd
);
virtual
~
UnixStreamSocket
();
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public
:
virtual
void
userOnUnixStreamRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/messages.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_MESSAGES_H
#define MS_CONTROL_PROTOCOL_MESSAGES_H
#include "messages/RequestHello.h"
#include "messages/RequestAuthenticate.h"
#include "messages/RequestCreateConference.h"
#endif
include/ControlProtocol/messages/RequestAuthenticate.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#define MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#include "ControlProtocol/Request.h"
#include <string>
namespace
ControlProtocol
{
class
RequestAuthenticate
:
public
ControlProtocol
::
Request
{
public
:
RequestAuthenticate
();
virtual
~
RequestAuthenticate
();
namespace
ControlProtocol
{
class
RequestAuthenticate
:
public
ControlProtocol
::
Request
{
public
:
RequestAuthenticate
();
virtual
~
RequestAuthenticate
();
void
SetUser
(
const
char
*
str
,
size_t
len
);
void
SetPasswd
(
const
char
*
str
,
size_t
len
);
virtual
void
Dump
()
override
;
private
:
std
::
string
user
;
std
::
string
passwd
;
};
void
SetUser
(
const
char
*
str
,
size_t
len
);
void
SetPasswd
(
const
char
*
str
,
size_t
len
);
virtual
void
Dump
()
override
;
private
:
std
::
string
user
;
std
::
string
passwd
;
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/messages/RequestCreateConference.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#define MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#include "ControlProtocol/Request.h"
namespace
ControlProtocol
{
class
RequestCreateConference
:
public
ControlProtocol
::
Request
{
public
:
RequestCreateConference
();
virtual
~
RequestCreateConference
();
namespace
ControlProtocol
{
class
RequestCreateConference
:
public
ControlProtocol
::
Request
{
public
:
RequestCreateConference
();
virtual
~
RequestCreateConference
();
virtual
void
Dump
()
override
;
};
virtual
void
Dump
()
override
;
};
}
// namespace ControlProtocol
#endif
include/ControlProtocol/messages/RequestHello.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#define MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#include "ControlProtocol/Request.h"
namespace
ControlProtocol
{
class
RequestHello
:
public
ControlProtocol
::
Request
{
public
:
RequestHello
();
virtual
~
RequestHello
();
namespace
ControlProtocol
{
class
RequestHello
:
public
ControlProtocol
::
Request
{
public
:
RequestHello
();
virtual
~
RequestHello
();
virtual
void
Dump
()
override
;
};
virtual
void
Dump
()
override
;
};
}
// namespace ControlProtocol
#endif
include/Daemon.h
浏览文件 @
6262224c
#ifndef MS_DAEMON_H
#define MS_DAEMON_H
class
Daemon
{
class
Daemon
{
public
:
static
void
Daemonize
();
static
void
SendOKStatusToAncestor
();
...
...
@@ -22,5 +22,4 @@ private:
static
bool
hasWrittenPIDFile
;
};
#endif
include/Dispatcher.h
浏览文件 @
6262224c
#ifndef MS_DISPATCHER_H
#define MS_DISPATCHER_H
#include "common.h"
#include "handles/SignalsHandler.h"
#include "ControlProtocol/TCPServer.h"
...
...
@@ -10,7 +9,6 @@
#include "ControlProtocol/Message.h"
#include <vector>
class
Dispatcher
:
public
SignalsHandler
::
Listener
,
public
ControlProtocol
::
TCPServer
::
Listener
,
...
...
@@ -52,5 +50,4 @@ private:
bool
closed
=
false
;
};
#endif
include/LibSRTP.h
浏览文件 @
6262224c
#ifndef MS_LIBSRTP_H
#define MS_LIBSRTP_H
#include <vector>
#include <srtp/srtp.h>
class
LibSRTP
{
class
LibSRTP
{
public
:
static
void
ClassInit
();
static
void
ClassDestroy
();
...
...
@@ -17,20 +16,19 @@ private:
static
std
::
vector
<
const
char
*>
errors
;
};
/* Inline static methods. */
inline
bool
LibSRTP
::
IsError
(
err_status_t
code
)
{
bool
LibSRTP
::
IsError
(
err_status_t
code
)
{
return
(
code
!=
err_status_ok
);
}
inline
const
char
*
LibSRTP
::
GetErrorString
(
err_status_t
code
)
{
const
char
*
LibSRTP
::
GetErrorString
(
err_status_t
code
)
{
// This throws out_of_range if the given index is not in the vector.
return
LibSRTP
::
errors
.
at
(
code
);
}
#endif
include/LibUV.h
浏览文件 @
6262224c
#ifndef MS_LIBUV_H
#define MS_LIBUV_H
#include "common.h"
#include <uv.h>
class
LibUV
{
class
LibUV
{
public
:
static
void
ClassInit
();
static
void
ThreadInit
();
...
...
@@ -18,13 +17,12 @@ private:
static
__thread
uv_loop_t
*
loop
;
};
/* Inline static methods. */
inline
uv_loop_t
*
LibUV
::
GetLoop
()
{
uv_loop_t
*
LibUV
::
GetLoop
()
{
return
LibUV
::
loop
;
}
#endif
include/Logger.h
浏览文件 @
6262224c
#ifndef MS_LOGGER_H
#define MS_LOGGER_H
#include "common.h"
#include "Settings.h"
#include <string>
...
...
@@ -9,11 +8,11 @@
#include <cstring>
#include <cstdlib> // std::_Exit(), std::abort()
#include <uv.h>
extern
"C"
{
extern
"C"
{
#include <syslog.h>
}
/*
* Logger facility for MediaSoup.
*
...
...
@@ -55,8 +54,8 @@ extern "C" {
*/
#define MS_GET_LOG_LEVEL Settings::configuration.logLevel
class
Logger
{
class
Logger
{
public
:
static
void
ThreadInit
(
const
std
::
string
name
);
static
const
char
*
GetThreadName
();
...
...
@@ -73,27 +72,26 @@ private:
static
bool
isSyslogEnabled
;
};
/* Inline static methods. */
inline
const
char
*
Logger
::
GetThreadName
()
{
const
char
*
Logger
::
GetThreadName
()
{
return
Logger
::
threadNamePtr
;
}
inline
bool
Logger
::
IsSyslogEnabled
()
{
bool
Logger
::
IsSyslogEnabled
()
{
return
Logger
::
isSyslogEnabled
;
}
inline
bool
Logger
::
HasDebugLevel
()
{
bool
Logger
::
HasDebugLevel
()
{
return
(
LOG_DEBUG
==
MS_GET_LOG_LEVEL
);
}
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
#ifdef MS_DEVEL
...
...
@@ -108,19 +106,22 @@ bool Logger::HasDebugLevel() {
#endif
#define _MS_TO_STDOUT(prefix) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stdout, prefix _MS_LOG_STR "\n", _MS_LOG_ARG); \
fflush(stdout); \
}
#define _MS_TO_STDOUT_DESC(prefix, desc, ...) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stdout, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stdout); \
}
#define _MS_TO_STDERR_DESC(prefix, desc, ...) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stderr, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stderr); \
}
...
...
@@ -133,7 +134,6 @@ bool Logger::HasDebugLevel() {
if (Logger::IsSyslogEnabled()) \
syslog(severity, prefix _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__);
/*
* Log levels in syslog.h:
*
...
...
@@ -150,80 +150,104 @@ bool Logger::HasDebugLevel() {
#ifdef MS_DEVEL
#define MS_TRACE() \
do { \
do \
{ \
_MS_TO_STDOUT("TRACE: "); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE: "); \
} while(0)
} \
while (0)
#else
#define MS_TRACE()
#endif
#define MS_DEBUG(desc, ...) \
do { \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) { \
do \
{ \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG: ", desc, ##__VA_ARGS__); \
} \
} while(0)
} \
while (0)
#define MS_INFO(desc, ...) \
do { \
if (LOG_INFO <= MS_GET_LOG_LEVEL) { \
do \
{ \
if (LOG_INFO <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO: ", desc, ##__VA_ARGS__); \
} \
} while(0)
} \
while (0)
#define MS_NOTICE(desc, ...) \
do { \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) { \
do \
{ \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE: ", desc, ##__VA_ARGS__); \
} \
} while(0)
} \
while (0)
#define MS_WARN(desc, ...) \
do { \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) { \
do \
{ \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDERR_DESC("WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN: ", desc, ##__VA_ARGS__); \
} \
} while(0)
} \
while (0)
#define MS_ERROR(desc, ...) \
do { \
do \
{ \
_MS_TO_STDERR_DESC("ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR: ", desc, ##__VA_ARGS__); \
} while(0)
} \
while (0)
#define MS_CRIT(desc, ...) \
do { \
do \
{ \
_MS_TO_STDERR_DESC("CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT: ", desc, ##__VA_ARGS__); \
} while(0)
} \
while (0)
#define MS_EXIT_SUCCESS(desc, ...) \
do { \
do \
{ \
MS_NOTICE("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_SUCCESS); \
} while(0)
} \
while (0)
#define MS_EXIT_FAILURE(desc, ...) \
do { \
do \
{ \
MS_CRIT("FAILURE EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_FAILURE); \
} while(0)
} \
while (0)
#define MS_ABORT(desc, ...) \
do { \
do \
{ \
MS_CRIT("ABORT | " desc, ##__VA_ARGS__); \
std::abort(); \
} while(0)
} \
while (0)
#define MS_ASSERT(condition, desc, ...) \
if (! (condition)) { \
if (!(condition)) \
{ \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
}
#endif
include/MediaSoup.h
浏览文件 @
6262224c
#ifndef MS_MEDIASOUP_H
#define MS_MEDIASOUP_H
/*
* MediaSoup top class.
*
* Entry point of the application.
*/
class
MediaSoup
{
class
MediaSoup
{
public
:
// Set the process.
static
void
SetProcess
();
...
...
@@ -27,5 +27,4 @@ private:
static
void
RunWorkerThread
(
void
*
data
);
};
#endif
include/MediaSoupError.h
浏览文件 @
6262224c
#ifndef MS_MEDIASOUP_ERROR_H
#define MS_MEDIASOUP_ERROR_H
#include "Logger.h"
#include <stdexcept>
#include <string>
#include <cstdio> // std::snprintf
class
MediaSoupError
:
public
std
::
runtime_error
{
class
MediaSoupError
:
public
std
::
runtime_error
{
public
:
MediaSoupError
(
const
char
*
description
);
};
/* Inline methods. */
inline
MediaSoupError
::
MediaSoupError
(
const
char
*
description
)
:
std
::
runtime_error
(
description
)
MediaSoupError
::
MediaSoupError
(
const
char
*
description
)
:
std
::
runtime_error
(
description
)
{}
#define MS_THROW_ERROR(desc, ...) \
do { \
do \
{ \
MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \
char buffer[1000]; \
std::snprintf(buffer, 1000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \
}
while(0)
}
\
while (0)
#endif
include/OpenSSL.h
浏览文件 @
6262224c
#ifndef MS_OPENSSL_H
#define MS_OPENSSL_H
#include "common.h"
#include <openssl/ssl.h>
#include <openssl/crypto.h>
/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
struct
CRYPTO_dynlock_value
{
struct
CRYPTO_dynlock_value
{
pthread_mutex_t
mutex
;
};
class
OpenSSL
{
class
OpenSSL
{
public
:
static
void
ClassInit
();
static
void
ClassDestroy
();
...
...
@@ -30,5 +29,4 @@ private:
static
int
numMutexes
;
};
#endif
include/RTC/DTLSHandler.h
浏览文件 @
6262224c
#ifndef MS_RTC_DTLS_HANDLER_H
#define MS_RTC_DTLS_HANDLER_H
#include "common.h"
#include "handles/Timer.h"
#include "RTC/DTLSRole.h"
...
...
@@ -14,137 +13,133 @@
#include <openssl/bio.h>
#include <openssl/x509.h>
namespace
RTC
{
class
DTLSHandler
:
public
Timer
::
Listener
{
private
:
struct
SrtpProfileMapEntry
{
SRTPProfile
profile
;
const
char
*
name
;
};
namespace
RTC
{
public
:
class
Listener
{
public
:
// NOTE: The caller MUST NOT call Reset() or Close() during the
// onOutgoingDTLSData() callback.
virtual
void
onOutgoingDTLSData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// onDTLSDisconnected or onDTLSFailed callbacks.
virtual
void
onDTLSConnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSDisconnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSFailed
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onSRTPKeyMaterial
(
DTLSHandler
*
dtlsHandler
,
RTC
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
public
:
static
void
ClassInit
();
static
void
ClassDestroy
();
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
static
const
std
::
string
&
GetFingerprint
(
RTC
::
FingerprintHash
hash
);
private
:
static
void
GenerateCertificateAndPrivateKey
();
static
void
ReadCertificateAndPrivateKeyFromFiles
();
static
void
CreateSSL_CTX
();
static
void
GenerateFingerprints
();
private
:
static
X509
*
certificate
;
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
typedef
std
::
map
<
RTC
::
FingerprintHash
,
std
::
string
>
Fingerprints
;
static
Fingerprints
fingerprints
;
typedef
std
::
vector
<
SrtpProfileMapEntry
>
SRTPProfiles
;
static
SRTPProfiles
srtpProfiles
;
static
__thread
MS_BYTE
sslReadBuffer
[];
class
DTLSHandler
:
public
Timer
::
Listener
{
private
:
struct
SrtpProfileMapEntry
{
SRTPProfile
profile
;
const
char
*
name
;
};
public
:
DTLSHandler
(
Listener
*
listener
);
virtual
~
DTLSHandler
();
void
Run
(
RTC
::
DTLSRole
role
);
void
SetRemoteFingerprint
(
RTC
::
FingerprintHash
hash
,
std
::
string
&
fingerprint
);
void
Reset
();
void
Close
();
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
IsRunning
();
bool
IsConnected
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Dump
();
private
:
bool
CheckStatus
(
int
return_code
);
void
SendPendingOutgoingDTLSData
();
void
SetTimeout
();
void
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
RTC
::
SRTPProfile
GetNegotiatedSRTPProfile
();
void
ExtractSRTPKeys
(
RTC
::
SRTPProfile
srtp_profile
);
/* Callbacks fired by OpenSSL events. */
public
:
void
onSSLInfo
(
int
where
,
int
ret
);
public
:
class
Listener
{
/* Pure virtual methods inherited from Timer::Listener. */
public
:
// NOTE: The caller MUST NOT call Reset() or Close() during the
// onOutgoingDTLSData() callback.
virtual
void
onOutgoingDTLSData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// onDTLSDisconnected or onDTLSFailed callbacks.
virtual
void
onDTLSConnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSDisconnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSFailed
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onSRTPKeyMaterial
(
DTLSHandler
*
dtlsHandler
,
RTC
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onTimer
(
Timer
*
timer
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Allocated by this:
SSL
*
ssl
=
nullptr
;
BIO
*
sslBioFromNetwork
=
nullptr
;
// The BIO from which ssl reads.
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
Timer
*
timer
=
nullptr
;
// Others:
RTC
::
DTLSRole
role
;
RTC
::
FingerprintHash
remoteFingerprintHash
=
RTC
::
FingerprintHash
::
NONE
;
std
::
string
remoteFingerprint
;
bool
isRunning
=
false
;
bool
isHandshakeDone
=
false
;
bool
isHandshakeDoneNow
=
false
;
bool
isConnected
=
false
;
bool
isCheckingStatus
=
false
;
bool
doReset
=
false
;
bool
doClose
=
false
;
};
public
:
static
void
ClassInit
();
static
void
ClassDestroy
();
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
static
const
std
::
string
&
GetFingerprint
(
RTC
::
FingerprintHash
hash
);
private
:
static
void
GenerateCertificateAndPrivateKey
();
static
void
ReadCertificateAndPrivateKeyFromFiles
();
static
void
CreateSSL_CTX
();
static
void
GenerateFingerprints
();
private
:
static
X509
*
certificate
;
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
typedef
std
::
map
<
RTC
::
FingerprintHash
,
std
::
string
>
Fingerprints
;
static
Fingerprints
fingerprints
;
typedef
std
::
vector
<
SrtpProfileMapEntry
>
SRTPProfiles
;
static
SRTPProfiles
srtpProfiles
;
static
__thread
MS_BYTE
sslReadBuffer
[];
public
:
DTLSHandler
(
Listener
*
listener
);
virtual
~
DTLSHandler
();
void
Run
(
RTC
::
DTLSRole
role
);
void
SetRemoteFingerprint
(
RTC
::
FingerprintHash
hash
,
std
::
string
&
fingerprint
);
void
Reset
();
void
Close
();
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
IsRunning
();
bool
IsConnected
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Dump
();
private
:
bool
CheckStatus
(
int
return_code
);
void
SendPendingOutgoingDTLSData
();
void
SetTimeout
();
void
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
RTC
::
SRTPProfile
GetNegotiatedSRTPProfile
();
void
ExtractSRTPKeys
(
RTC
::
SRTPProfile
srtp_profile
);
/* Callbacks fired by OpenSSL events. */
public
:
void
onSSLInfo
(
int
where
,
int
ret
);
/* Pure virtual methods inherited from Timer::Listener. */
public
:
virtual
void
onTimer
(
Timer
*
timer
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Allocated by this:
SSL
*
ssl
=
nullptr
;
BIO
*
sslBioFromNetwork
=
nullptr
;
// The BIO from which ssl reads.
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
Timer
*
timer
=
nullptr
;
// Others:
RTC
::
DTLSRole
role
;
RTC
::
FingerprintHash
remoteFingerprintHash
=
RTC
::
FingerprintHash
::
NONE
;
std
::
string
remoteFingerprint
;
bool
isRunning
=
false
;
bool
isHandshakeDone
=
false
;
bool
isHandshakeDoneNow
=
false
;
bool
isConnected
=
false
;
bool
isCheckingStatus
=
false
;
bool
doReset
=
false
;
bool
doClose
=
false
;
};
/* Inline static methods. */
inline
bool
DTLSHandler
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
{
return
(
// Minimum DTLS record length is 13 bytes.
(
len
>=
13
)
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
19
&&
data
[
0
]
<
64
)
);
}
/* Inline instance methods. */
inline
bool
DTLSHandler
::
IsConnected
()
{
return
this
->
isConnected
;
}
inline
bool
DTLSHandler
::
IsRunning
()
{
return
this
->
isRunning
;
}
/* Inline static methods. */
inline
bool
DTLSHandler
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
{
return
(
// Minimum DTLS record length is 13 bytes.
(
len
>=
13
)
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
19
&&
data
[
0
]
<
64
)
);
}
/* Inline instance methods. */
inline
bool
DTLSHandler
::
IsConnected
()
{
return
this
->
isConnected
;
}
inline
bool
DTLSHandler
::
IsRunning
()
{
return
this
->
isRunning
;
}
}
// namespace RTC
#endif
include/RTC/DTLSRole.h
浏览文件 @
6262224c
#ifndef MS_RTC_DTLS_ROLE_H
#define MS_RTC_DTLS_ROLE_H
namespace
RTC
{
enum
class
DTLSRole
{
NONE
=
0
,
SERVER
=
1
,
CLIENT
};
enum
class
DTLSRole
{
NONE
=
0
,
SERVER
=
1
,
CLIENT
};
}
// namespace RTC
#endif
include/RTC/FingerprintHash.h
浏览文件 @
6262224c
#ifndef MS_RTC_FINGERPRINT_HASH_H
#define MS_RTC_FINGERPRINT_HASH_H
namespace
RTC
{
enum
class
FingerprintHash
{
NONE
=
0
,
SHA1
=
1
,
SHA224
,
SHA256
,
SHA384
,
SHA512
};
namespace
RTC
{
enum
class
FingerprintHash
{
NONE
=
0
,
SHA1
=
1
,
SHA224
,
SHA256
,
SHA384
,
SHA512
};
}
// namespace RTC
#endif
include/RTC/ICEServer.h
浏览文件 @
6262224c
#ifndef MS_RTC_ICE_SERVER_H
#define MS_RTC_ICE_SERVER_H
#include "common.h"
#include "RTC/TransportSource.h"
#include "RTC/STUNMessage.h"
...
...
@@ -9,69 +8,66 @@
#include "RTC/TCPConnection.h"
#include <string>
namespace
RTC
{
class
ICEServer
{
public
:
class
Listener
{
public
:
/**
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* returns, so the given pointers are still usable.
*/
virtual
void
onOutgoingSTUNMessage
(
ICEServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
=
0
;
virtual
void
onICEValidPair
(
ICEServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
=
0
;
};
namespace
RTC
{
class
ICEServer
{
public
:
class
Listener
{
public
:
/**
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* returns, so the given pointers are still usable.
*/
virtual
void
onOutgoingSTUNMessage
(
ICEServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
=
0
;
virtual
void
onICEValidPair
(
ICEServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
=
0
;
ICEServer
(
Listener
*
listener
);
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
);
std
::
string
&
GetLocalUsername
();
std
::
string
&
GetLocalPassword
();
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
std
::
string
localUsername
;
std
::
string
localPassword
;
};
public
:
ICEServer
(
Listener
*
listener
);
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
);
std
::
string
&
GetLocalUsername
();
std
::
string
&
GetLocalPassword
();
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
std
::
string
localUsername
;
std
::
string
localPassword
;
};
/* Inline methods. */
inline
std
::
string
&
ICEServer
::
GetLocalUsername
()
{
return
this
->
localUsername
;
}
inline
std
::
string
&
ICEServer
::
GetLocalPassword
()
{
return
this
->
localPassword
;
}
inline
void
ICEServer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
ICEServer
::
GetUserData
()
{
return
this
->
userData
;
}
/* Inline methods. */
inline
std
::
string
&
ICEServer
::
GetLocalUsername
()
{
return
this
->
localUsername
;
}
inline
std
::
string
&
ICEServer
::
GetLocalPassword
()
{
return
this
->
localPassword
;
}
inline
void
ICEServer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
ICEServer
::
GetUserData
()
{
return
this
->
userData
;
}
}
// namespace RTC
#endif
include/RTC/Peer.h
浏览文件 @
6262224c
#ifndef MS_RTC_PEER_H
#define MS_RTC_PEER_H
#include "RTC/Transport.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include <vector>
namespace
RTC
{
class
Peer
:
RTC
::
Transport
::
Listener
namespace
RTC
{
public
:
class
Listener
{
class
Peer
:
RTC
::
Transport
::
Listener
{
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
=
0
;
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
=
0
;
};
public
:
Peer
(
Listener
*
listener
);
virtual
~
Peer
();
void
SendRTPPacket
(
RTC
::
RTPPacket
*
packet
);
void
SendRTCPPacket
(
RTC
::
RTCPPacket
*
packet
);
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
RTC
::
Transport
*
transport
=
nullptr
;
};
/* Inline methods. */
inline
void
Peer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
class
Listener
{
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
=
0
;
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
=
0
;
};
public
:
Peer
(
Listener
*
listener
);
virtual
~
Peer
();
inline
void
*
Peer
::
GetUserData
()
{
return
this
->
userData
;
}
void
SendRTPPacket
(
RTC
::
RTPPacket
*
packet
);
void
SendRTCPPacket
(
RTC
::
RTCPPacket
*
packet
);
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
RTC
::
Transport
*
transport
=
nullptr
;
};
/* Inline methods. */
inline
void
Peer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
Peer
::
GetUserData
()
{
return
this
->
userData
;
}
}
// namespace RTC
#endif
include/RTC/RTCPPacket.h
浏览文件 @
6262224c
#ifndef MS_RTC_RTCP_PACKET_H
#define MS_RTC_RTCP_PACKET_H
#include "common.h"
namespace
RTC
{
class
RTCPPacket
{
public
:
/* Struct for RTCP common header. */
typedef
struct
CommonHeader
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
count
:
5
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
count
:
5
;
#endif
MS_BYTE
packet_type
:
8
;
MS_2BYTES
length
:
16
;
}
CommonHeader
;
public
:
static
bool
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTCPPacket
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
private
:
// Passed by argument:
CommonHeader
*
header
=
nullptr
;
MS_BYTE
*
raw
=
nullptr
;
size_t
length
=
0
;
};
/* Inline static methods. */
inline
bool
RTCPPacket
::
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
return
(
(
len
>=
sizeof
(
CommonHeader
))
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// RTP Version must be 2.
(
header
->
version
==
2
)
&&
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(
header
->
packet_type
>=
192
&&
header
->
packet_type
<=
223
)
);
}
/* Inline instance methods. */
inline
const
MS_BYTE
*
RTCPPacket
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
RTCPPacket
::
GetLength
()
{
return
this
->
length
;
}
namespace
RTC
{
class
RTCPPacket
{
public
:
/* Struct for RTCP common header. */
typedef
struct
CommonHeader
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
count
:
5
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
count
:
5
;
#endif
MS_BYTE
packet_type
:
8
;
MS_2BYTES
length
:
16
;
}
CommonHeader
;
public
:
static
bool
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTCPPacket
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
private
:
// Passed by argument:
CommonHeader
*
header
=
nullptr
;
MS_BYTE
*
raw
=
nullptr
;
size_t
length
=
0
;
};
/* Inline static methods. */
inline
bool
RTCPPacket
::
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
return
(
(
len
>=
sizeof
(
CommonHeader
))
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// RTP Version must be 2.
(
header
->
version
==
2
)
&&
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(
header
->
packet_type
>=
192
&&
header
->
packet_type
<=
223
)
);
}
/* Inline instance methods. */
inline
const
MS_BYTE
*
RTCPPacket
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
RTCPPacket
::
GetLength
()
{
return
this
->
length
;
}
}
// namespace RTC
#endif
include/RTC/RTPPacket.h
浏览文件 @
6262224c
#ifndef MS_RTC_RTP_PACKET_H
#define MS_RTC_RTP_PACKET_H
#include "common.h"
namespace
RTC
{
class
RTPPacket
{
public
:
/* Struct for RTP header. */
typedef
struct
Header
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
csrc_count
:
4
;
MS_BYTE
extension
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
MS_BYTE
payload_type
:
7
;
MS_BYTE
marker
:
1
;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
extension
:
1
;
MS_BYTE
csrc_count
:
4
;
MS_BYTE
marker
:
1
;
MS_BYTE
payload_type
:
7
;
#endif
MS_2BYTES
sequence_number
;
MS_4BYTES
timestamp
;
MS_4BYTES
ssrc
;
}
Header
;
/* Struct for RTP header extension. */
typedef
struct
ExtensionHeader
{
MS_2BYTES
id
;
MS_2BYTES
length
;
// Size of value in multiples of 4 bytes.
MS_BYTE
*
value
;
}
ExtensionHeader
;
public
:
static
bool
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLen
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTPPacket
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
MS_BYTE
GetPayloadType
();
void
SetPayloadType
(
MS_BYTE
payload_type
);
bool
HasMarker
();
void
SetMarker
(
bool
marker
);
MS_2BYTES
GetSequenceNumber
();
MS_4BYTES
GetTimestamp
();
MS_4BYTES
GetSSRC
();
void
SetSSRC
(
MS_4BYTES
ssrc
);
bool
HasExtensionHeader
();
MS_2BYTES
GetExtensionHeaderId
();
size_t
GetExtensionHeaderLength
();
MS_BYTE
*
GetPayload
();
size_t
GetPayloadLength
();
void
Serialize
();
void
Dump
();
private
:
// Passed by argument:
Header
*
header
=
nullptr
;
MS_BYTE
*
csrcList
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
MS_BYTE
*
payload
=
nullptr
;
size_t
payloadLength
=
0
;
MS_BYTE
payloadPadding
=
0
;
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
size_t
length
=
0
;
// Others:
bool
isSerialized
=
false
;
};
/* Inline static methods. */
inline
bool
RTPPacket
::
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
Header
*
header
=
(
Header
*
)
data
;
return
(
(
len
>=
sizeof
(
Header
))
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// RTP Version must be 2.
(
header
->
version
==
2
)
);
}
/* Inline instance methods. */
inline
const
MS_BYTE
*
RTPPacket
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
RTPPacket
::
GetLength
()
{
return
this
->
length
;
}
inline
MS_BYTE
RTPPacket
::
GetPayloadType
()
{
return
this
->
header
->
payload_type
;
}
inline
void
RTPPacket
::
SetPayloadType
(
MS_BYTE
payload_type
)
{
this
->
header
->
payload_type
=
payload_type
;
}
inline
bool
RTPPacket
::
HasMarker
()
{
return
this
->
header
->
marker
;
}
inline
void
RTPPacket
::
SetMarker
(
bool
marker
)
{
this
->
header
->
marker
=
marker
;
}
inline
MS_2BYTES
RTPPacket
::
GetSequenceNumber
()
{
return
ntohs
(
this
->
header
->
sequence_number
);
}
inline
MS_4BYTES
RTPPacket
::
GetTimestamp
()
{
return
ntohl
(
this
->
header
->
timestamp
);
}
inline
MS_4BYTES
RTPPacket
::
GetSSRC
()
{
return
ntohl
(
this
->
header
->
ssrc
);
}
// TODO temp
inline
void
RTPPacket
::
SetSSRC
(
MS_4BYTES
ssrc
)
{
this
->
header
->
ssrc
=
htonl
(
ssrc
);
}
inline
bool
RTPPacket
::
HasExtensionHeader
()
{
return
(
this
->
extensionHeader
?
true
:
false
);
}
inline
MS_2BYTES
RTPPacket
::
GetExtensionHeaderId
()
{
if
(
this
->
extensionHeader
)
return
MS_2BYTES
(
ntohs
(
this
->
extensionHeader
->
id
));
else
return
0
;
}
inline
size_t
RTPPacket
::
GetExtensionHeaderLength
()
{
if
(
this
->
extensionHeader
)
return
size_t
(
ntohs
(
this
->
extensionHeader
->
length
)
*
4
);
else
return
0
;
}
inline
MS_BYTE
*
RTPPacket
::
GetPayload
()
{
return
this
->
payload
;
}
inline
size_t
RTPPacket
::
GetPayloadLength
()
{
return
this
->
payloadLength
;
}
namespace
RTC
{
class
RTPPacket
{
public
:
/* Struct for RTP header. */
typedef
struct
Header
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
csrc_count
:
4
;
MS_BYTE
extension
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
MS_BYTE
payload_type
:
7
;
MS_BYTE
marker
:
1
;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
extension
:
1
;
MS_BYTE
csrc_count
:
4
;
MS_BYTE
marker
:
1
;
MS_BYTE
payload_type
:
7
;
#endif
MS_2BYTES
sequence_number
;
MS_4BYTES
timestamp
;
MS_4BYTES
ssrc
;
}
Header
;
/* Struct for RTP header extension. */
typedef
struct
ExtensionHeader
{
MS_2BYTES
id
;
MS_2BYTES
length
;
// Size of value in multiples of 4 bytes.
MS_BYTE
*
value
;
}
ExtensionHeader
;
public
:
static
bool
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLen
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTPPacket
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
MS_BYTE
GetPayloadType
();
void
SetPayloadType
(
MS_BYTE
payload_type
);
bool
HasMarker
();
void
SetMarker
(
bool
marker
);
MS_2BYTES
GetSequenceNumber
();
MS_4BYTES
GetTimestamp
();
MS_4BYTES
GetSSRC
();
void
SetSSRC
(
MS_4BYTES
ssrc
);
bool
HasExtensionHeader
();
MS_2BYTES
GetExtensionHeaderId
();
size_t
GetExtensionHeaderLength
();
MS_BYTE
*
GetPayload
();
size_t
GetPayloadLength
();
void
Serialize
();
void
Dump
();
private
:
// Passed by argument:
Header
*
header
=
nullptr
;
MS_BYTE
*
csrcList
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
MS_BYTE
*
payload
=
nullptr
;
size_t
payloadLength
=
0
;
MS_BYTE
payloadPadding
=
0
;
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
size_t
length
=
0
;
// Others:
bool
isSerialized
=
false
;
};
/* Inline static methods. */
inline
bool
RTPPacket
::
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
Header
*
header
=
(
Header
*
)
data
;
return
(
(
len
>=
sizeof
(
Header
))
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// RTP Version must be 2.
(
header
->
version
==
2
)
);
}
/* Inline instance methods. */
inline
const
MS_BYTE
*
RTPPacket
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
RTPPacket
::
GetLength
()
{
return
this
->
length
;
}
inline
MS_BYTE
RTPPacket
::
GetPayloadType
()
{
return
this
->
header
->
payload_type
;
}
inline
void
RTPPacket
::
SetPayloadType
(
MS_BYTE
payload_type
)
{
this
->
header
->
payload_type
=
payload_type
;
}
inline
bool
RTPPacket
::
HasMarker
()
{
return
this
->
header
->
marker
;
}
inline
void
RTPPacket
::
SetMarker
(
bool
marker
)
{
this
->
header
->
marker
=
marker
;
}
inline
MS_2BYTES
RTPPacket
::
GetSequenceNumber
()
{
return
ntohs
(
this
->
header
->
sequence_number
);
}
inline
MS_4BYTES
RTPPacket
::
GetTimestamp
()
{
return
ntohl
(
this
->
header
->
timestamp
);
}
inline
MS_4BYTES
RTPPacket
::
GetSSRC
()
{
return
ntohl
(
this
->
header
->
ssrc
);
}
// TODO temp
inline
void
RTPPacket
::
SetSSRC
(
MS_4BYTES
ssrc
)
{
this
->
header
->
ssrc
=
htonl
(
ssrc
);
}
inline
bool
RTPPacket
::
HasExtensionHeader
()
{
return
(
this
->
extensionHeader
?
true
:
false
);
}
inline
MS_2BYTES
RTPPacket
::
GetExtensionHeaderId
()
{
if
(
this
->
extensionHeader
)
return
MS_2BYTES
(
ntohs
(
this
->
extensionHeader
->
id
));
else
return
0
;
}
inline
size_t
RTPPacket
::
GetExtensionHeaderLength
()
{
if
(
this
->
extensionHeader
)
return
size_t
(
ntohs
(
this
->
extensionHeader
->
length
)
*
4
);
else
return
0
;
}
inline
MS_BYTE
*
RTPPacket
::
GetPayload
()
{
return
this
->
payload
;
}
inline
size_t
RTPPacket
::
GetPayloadLength
()
{
return
this
->
payloadLength
;
}
}
// namespace RTC
#endif
include/RTC/Room.h
浏览文件 @
6262224c
#ifndef MS_RTC_ROOM_H
#define MS_RTC_ROOM_H
#include "RTC/Peer.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include <vector>
namespace
RTC
{
class
Room
:
RTC
::
Peer
::
Listener
namespace
RTC
{
public
:
Room
();
virtual
~
Room
();
void
Close
();
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Others:
typedef
std
::
vector
<
RTC
::
Peer
*>
Peers
;
Peers
peers
;
}
;
class
Room
:
RTC
::
Peer
::
Listener
{
public
:
Room
();
virtual
~
Room
();
void
Close
();
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Others:
typedef
std
::
vector
<
RTC
::
Peer
*>
Peers
;
Peers
peers
;
};
}
// namespace RTC
#endif
include/RTC/SRTPProfile.h
浏览文件 @
6262224c
#ifndef MS_RTC_SRTP_PROFILE_H
#define MS_RTC_SRTP_PROFILE_H
namespace
RTC
{
enum
class
SRTPProfile
{
NONE
=
0
,
AES_CM_128_HMAC_SHA1_80
=
1
,
AES_CM_128_HMAC_SHA1_32
};
namespace
RTC
{
enum
class
SRTPProfile
{
NONE
=
0
,
AES_CM_128_HMAC_SHA1_80
=
1
,
AES_CM_128_HMAC_SHA1_32
};
}
// namespace RTC
#endif
include/RTC/SRTPSession.h
浏览文件 @
6262224c
#ifndef MS_RTC_SRTP_SESSION_H
#define MS_RTC_SRTP_SESSION_H
#include "common.h"
#include "LibSRTP.h"
#include "RTC/SRTPProfile.h"
#include <srtp/srtp.h>
namespace
RTC
{
class
SRTPSession
{
public
:
enum
class
Type
{
INBOUND
=
1
,
OUTBOUND
namespace
RTC
{
class
SRTPSession
{
public
:
enum
class
Type
{
INBOUND
=
1
,
OUTBOUND
};
public
:
static
void
ClassInit
();
private
:
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
private
:
static
__thread
MS_BYTE
encryptBuffer
[];
public
:
SRTPSession
(
Type
type
,
RTC
::
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
);
~
SRTPSession
();
bool
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
bool
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
const
char
*
GetLastErrorDesc
();
void
Close
();
private
:
// Allocated by this:
srtp_t
session
=
nullptr
;
// Others:
err_status_t
lastError
=
(
err_status_t
)
0
;
};
public
:
static
void
ClassInit
();
private
:
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
private
:
static
__thread
MS_BYTE
encryptBuffer
[];
public
:
SRTPSession
(
Type
type
,
RTC
::
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
);
~
SRTPSession
();
/* Inline instance methods. */
bool
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
bool
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
const
char
*
GetLastErrorDesc
();
void
Close
();
private
:
// Allocated by this:
srtp_t
session
=
nullptr
;
// Others:
err_status_t
lastError
=
(
err_status_t
)
0
;
};
/* Inline instance methods. */
inline
const
char
*
SRTPSession
::
GetLastErrorDesc
()
{
const
char
*
error_string
;
error_string
=
LibSRTP
::
GetErrorString
(
this
->
lastError
);
this
->
lastError
=
(
err_status_t
)
0
;
// Reset it.
return
error_string
;
}
inline
const
char
*
SRTPSession
::
GetLastErrorDesc
()
{
const
char
*
error_string
;
error_string
=
LibSRTP
::
GetErrorString
(
this
->
lastError
);
this
->
lastError
=
(
err_status_t
)
0
;
// Reset it.
return
error_string
;
}
}
// namespace RTC
#endif
include/RTC/STUNMessage.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/RTC/Stream.h
浏览文件 @
6262224c
#ifndef MS_RTC_STREAM_H
#define MS_RTC_STREAM_H
#include "common.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include <unordered_set>
namespace
RTC
{
class
Stream
{
public
:
Stream
();
~
Stream
();
namespace
RTC
{
class
Stream
{
public
:
Stream
();
~
Stream
();
void
Close
();
private
:
MS_4BYTES
ssrc
=
0
;
std
::
unordered_set
<
MS_BYTE
>
payloads
;
};
void
Close
();
private
:
MS_4BYTES
ssrc
=
0
;
std
::
unordered_set
<
MS_BYTE
>
payloads
;
};
}
// namespace RTC
#endif
include/RTC/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_RTC_TCP_CONNECTION_H
#define MS_RTC_TCP_CONNECTION_H
#include "common.h"
#include "handles/TCPConnection.h"
namespace
RTC
{
class
TCPConnection
:
public
::
TCPConnection
{
public
:
class
Reader
{
namespace
RTC
{
class
TCPConnection
:
public
::
TCPConnection
{
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
class
Reader
{
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
private
:
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
frameStart
=
0
;
// Where the latest frame starts.
};
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
frameStart
=
0
;
// Where the latest frame starts.
};
}
// namespace RTC
#endif
include/RTC/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_RTC_TCP_SERVER_H
#define MS_RTC_TCP_SERVER_H
#include "common.h"
#include "handles/TCPServer.h"
#include "handles/TCPConnection.h"
...
...
@@ -9,63 +8,60 @@
#include <unordered_map>
#include <uv.h>
namespace
RTC
{
class
TCPServer
:
public
::
TCPServer
{
public
:
class
Listener
{
namespace
RTC
{
class
TCPServer
:
public
::
TCPServer
{
public
:
virtual
void
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
public
:
static
void
ClassInit
();
static
RTC
::
TCPServer
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
TCPServer
*
servers
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_tcp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
class
Listener
{
public
:
virtual
void
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
public
:
TCPServer
(
uv_tcp_t
*
uvHandle
);
void
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
);
/* Pure virtual methods inherited from ::TCPServer. */
public
:
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
RTC
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
public
:
static
void
ClassInit
();
static
RTC
::
TCPServer
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
TCPServer
*
servers
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_tcp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
public
:
TCPServer
(
uv_tcp_t
*
uvHandle
);
/* Inline methods. */
void
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
);
inline
void
TCPServer
::
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
)
{
this
->
listener
=
listener
;
this
->
reader
=
reader
;
}
/* Pure virtual methods inherited from ::TCPServer. */
public
:
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
RTC
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
/* Inline methods. */
inline
void
TCPServer
::
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
)
{
this
->
listener
=
listener
;
this
->
reader
=
reader
;
}
}
// namespace RTC
#endif
include/RTC/Transport.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/RTC/TransportSource.h
浏览文件 @
6262224c
#ifndef MS_RTC_TRANSPORT_SOURCE_H
#define MS_RTC_TRANSPORT_SOURCE_H
#include "common.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPConnection.h"
#include "Utils.h"
#include <string>
namespace
RTC
{
class
TransportSource
{
public
:
enum
class
Type
{
UDP
=
1
,
TCP
namespace
RTC
{
class
TransportSource
{
public
:
enum
class
Type
{
UDP
=
1
,
TCP
};
public
:
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
);
void
StoreUdpRemoteAddress
();
bool
IsUDP
();
bool
IsTCP
();
bool
Compare
(
TransportSource
*
source
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
const
struct
sockaddr
*
GetRemoteAddress
();
void
Close
();
void
Dump
();
private
:
// Passed by argument:
RTC
::
UDPSocket
*
udpSocket
=
nullptr
;
struct
sockaddr
*
udpRemoteAddr
=
nullptr
;
sockaddr_storage
udpRemoteAddrStorage
;
RTC
::
TCPConnection
*
tcpConnection
=
nullptr
;
// Others:
Type
type
;
};
public
:
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
);
void
StoreUdpRemoteAddress
();
bool
IsUDP
();
bool
IsTCP
();
bool
Compare
(
TransportSource
*
source
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
const
struct
sockaddr
*
GetRemoteAddress
();
void
Close
();
void
Dump
();
private
:
// Passed by argument:
RTC
::
UDPSocket
*
udpSocket
=
nullptr
;
struct
sockaddr
*
udpRemoteAddr
=
nullptr
;
sockaddr_storage
udpRemoteAddrStorage
;
RTC
::
TCPConnection
*
tcpConnection
=
nullptr
;
// Others:
Type
type
;
};
/* Inline methods. */
inline
TransportSource
::
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
udpSocket
(
udpSocket
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
type
(
Type
::
UDP
)
{}
inline
TransportSource
::
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
)
:
tcpConnection
(
tcpConnection
),
type
(
Type
::
TCP
)
{}
inline
void
TransportSource
::
StoreUdpRemoteAddress
()
{
// Clone the given address into our address storage and make the sockaddr
// pointer point to it.
this
->
udpRemoteAddrStorage
=
Utils
::
IP
::
CopyAddress
(
udpRemoteAddr
);
this
->
udpRemoteAddr
=
(
struct
sockaddr
*
)
&
this
->
udpRemoteAddrStorage
;
}
inline
bool
TransportSource
::
IsUDP
()
{
return
(
this
->
type
==
Type
::
UDP
);
}
inline
bool
TransportSource
::
IsTCP
()
{
return
(
this
->
type
==
Type
::
TCP
);
}
inline
bool
TransportSource
::
Compare
(
TransportSource
*
source
)
{
if
(
this
->
type
==
Type
::
UDP
&&
source
->
IsUDP
())
{
return
(
this
->
udpSocket
==
source
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
source
->
GetRemoteAddress
()));
/* Inline methods. */
inline
TransportSource
::
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
udpSocket
(
udpSocket
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
type
(
Type
::
UDP
)
{}
inline
TransportSource
::
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
)
:
tcpConnection
(
tcpConnection
),
type
(
Type
::
TCP
)
{}
inline
void
TransportSource
::
StoreUdpRemoteAddress
()
{
// Clone the given address into our address storage and make the sockaddr
// pointer point to it.
this
->
udpRemoteAddrStorage
=
Utils
::
IP
::
CopyAddress
(
udpRemoteAddr
);
this
->
udpRemoteAddr
=
(
struct
sockaddr
*
)
&
this
->
udpRemoteAddrStorage
;
}
else
if
(
this
->
type
==
Type
::
TCP
&&
source
->
IsTCP
())
{
return
(
this
->
tcpConnection
==
source
->
tcpConnection
);
}
else
{
return
false
;
}
}
inline
void
TransportSource
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
{
if
(
this
->
type
==
Type
::
UDP
)
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
else
this
->
tcpConnection
->
Send
(
data
,
len
);
}
inline
bool
TransportSource
::
IsUDP
()
{
return
(
this
->
type
==
Type
::
UDP
);
}
inline
const
struct
sockaddr
*
TransportSource
::
GetRemoteAddress
()
{
if
(
this
->
type
==
Type
::
UDP
)
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
else
return
this
->
tcpConnection
->
GetPeerAddress
();
}
inline
bool
TransportSource
::
IsTCP
()
{
return
(
this
->
type
==
Type
::
TCP
);
}
inline
bool
TransportSource
::
Compare
(
TransportSource
*
source
)
{
if
(
this
->
type
==
Type
::
UDP
&&
source
->
IsUDP
())
{
return
(
this
->
udpSocket
==
source
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
source
->
GetRemoteAddress
()));
}
else
if
(
this
->
type
==
Type
::
TCP
&&
source
->
IsTCP
())
{
return
(
this
->
tcpConnection
==
source
->
tcpConnection
);
}
else
{
return
false
;
}
}
inline
void
TransportSource
::
Close
()
{
if
(
this
->
type
==
Type
::
TCP
)
this
->
tcpConnection
->
Close
();
}
inline
void
TransportSource
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
{
if
(
this
->
type
==
Type
::
UDP
)
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
else
this
->
tcpConnection
->
Send
(
data
,
len
);
}
inline
const
struct
sockaddr
*
TransportSource
::
GetRemoteAddress
()
{
if
(
this
->
type
==
Type
::
UDP
)
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
else
return
this
->
tcpConnection
->
GetPeerAddress
();
}
inline
void
TransportSource
::
Close
()
{
if
(
this
->
type
==
Type
::
TCP
)
this
->
tcpConnection
->
Close
();
}
}
// namespace RTC
#endif
include/RTC/UDPSocket.h
浏览文件 @
6262224c
#ifndef MS_RTC_UDP_SOCKET_H
#define MS_RTC_UDP_SOCKET_H
#include "common.h"
#include "handles/UDPSocket.h"
#include <unordered_map>
#include <uv.h>
namespace
RTC
{
class
UDPSocket
:
public
::
UDPSocket
{
public
:
class
Listener
{
namespace
RTC
{
class
UDPSocket
:
public
::
UDPSocket
{
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
};
public
:
static
void
ClassInit
();
static
RTC
::
UDPSocket
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
UDPSocket
*
sockets
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_udp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
class
Listener
{
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
};
public
:
UDPSocket
(
uv_udp_t
*
uvHandle
);
void
SetListener
(
Listener
*
listener
);
/* Pure virtual methods inherited from ::UDPSocket. */
public
:
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
public
:
static
void
ClassInit
();
static
RTC
::
UDPSocket
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
UDPSocket
*
sockets
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_udp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
};
public
:
UDPSocket
(
uv_udp_t
*
uvHandle
);
void
SetListener
(
Listener
*
listener
);
/* Inline methods. */
/* Pure virtual methods inherited from ::UDPSocket. */
public
:
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
inline
void
UDPSocket
::
SetListener
(
Listener
*
listener
)
{
this
->
listener
=
listene
r
;
}
private
:
// Passed by argument:
Listener
*
listener
=
nullpt
r
;
};
/* Inline methods. */
inline
void
UDPSocket
::
SetListener
(
Listener
*
listener
)
{
this
->
listener
=
listener
;
}
}
// namespace RTC
#endif
include/Settings.h
浏览文件 @
6262224c
#ifndef MS_SETTINGS_H
#define MS_SETTINGS_H
#include "common.h"
#include <map>
#include <string>
#include <vector>
#include <libconfig.h++>
extern
"C"
{
extern
"C"
{
#include <syslog.h>
}
class
Settings
{
class
Settings
{
public
:
// Struct holding command line arguments.
struct
Arguments
{
struct
Arguments
{
std
::
string
configFile
;
bool
daemonize
{
false
};
std
::
string
pidFile
;
...
...
@@ -24,17 +25,20 @@ public:
};
// Struct holding the configuration (can be overriden by a config file).
struct
Configuration
{
struct
Configuration
{
unsigned
int
logLevel
{
LOG_DEBUG
};
unsigned
int
syslogFacility
{
LOG_USER
};
int
numWorkers
{
0
};
struct
{
struct
{
std
::
string
listenIP
{
"127.0.0.1"
};
MS_PORT
listenPort
{
4080
};
}
ControlProtocol
;
struct
{
struct
{
std
::
string
listenIPv4
;
std
::
string
listenIPv6
;
MS_PORT
minPort
{
10000
};
...
...
@@ -83,5 +87,4 @@ private:
static
std
::
map
<
unsigned
int
,
std
::
string
>
syslogFacility2String
;
};
#endif
include/Utils.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/Version.h
浏览文件 @
6262224c
#ifndef MS_VERSION_H
#define MS_VERSION_H
#include <string>
class
Version
{
class
Version
{
public
:
static
const
std
::
string
GetVersion
();
static
const
std
::
string
GetNameAndVersion
();
...
...
@@ -19,5 +18,4 @@ public:
static
const
std
::
string
copyright
;
};
#endif
include/Worker.h
浏览文件 @
6262224c
#ifndef MS_WORKER_H
#define MS_WORKER_H
#include "common.h"
#include "ControlProtocol/UnixStreamSocket.h"
#include "ControlProtocol/Message.h"
...
...
@@ -10,7 +9,6 @@
// TMP
#include "RTC/Room.h"
class
Worker
:
public
ControlProtocol
::
UnixStreamSocket
::
Listener
{
...
...
@@ -53,5 +51,4 @@ private:
RTC
::
Room
*
room
=
nullptr
;
};
#endif
include/common.h
浏览文件 @
6262224c
#ifndef MS_COMMON_H
#define MS_COMMON_H
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
...
...
@@ -9,14 +8,12 @@
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <pthread.h> // __thread
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
#define MS_4BYTES uint32_t
#define MS_8BYTES uint64_t
#define MS_PORT uint16_t
// Detect Little-Endian or Big-Endian CPU.
// NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined
// then don't autodetect it.
...
...
include/handles/SignalsHandler.h
浏览文件 @
6262224c
#ifndef MS_SIGNALS_HANDLER_H
#define MS_SIGNALS_HANDLER_H
#include <vector>
#include <string>
#include <uv.h>
class
SignalsHandler
{
class
SignalsHandler
{
public
:
class
Listener
{
class
Listener
{
public
:
virtual
void
onSignal
(
SignalsHandler
*
signalsHandler
,
int
signum
)
=
0
;
virtual
void
onSignalsHandlerClosed
(
SignalsHandler
*
signalsHandler
)
=
0
;
...
...
@@ -33,5 +33,4 @@ private:
Listener
*
listener
=
nullptr
;
};
#endif
include/handles/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_TCP_CONNECTION_H
#define MS_TCP_CONNECTION_H
#include "common.h"
#include <string>
#include <uv.h>
class
TCPConnection
{
class
TCPConnection
{
public
:
class
Listener
{
class
Listener
{
public
:
virtual
void
onTCPConnectionClosed
(
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
public
:
/* Struct for the data field of uv_req_t when writing into the connection. */
typedef
struct
UvWriteData
{
typedef
struct
UvWriteData
{
TCPConnection
*
connection
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
...
...
@@ -82,61 +83,60 @@ protected:
MS_PORT
peerPort
=
0
;
};
/* Inline methods. */
inline
uv_tcp_t
*
TCPConnection
::
GetUvHandle
()
{
uv_tcp_t
*
TCPConnection
::
GetUvHandle
()
{
return
this
->
uvHandle
;
}
inline
void
TCPConnection
::
Write
(
const
std
::
string
&
data
)
{
void
TCPConnection
::
Write
(
const
std
::
string
&
data
)
{
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
}
inline
const
std
::
string
&
TCPConnection
::
GetLocalIP
()
{
const
std
::
string
&
TCPConnection
::
GetLocalIP
()
{
return
this
->
localIP
;
}
inline
MS_PORT
TCPConnection
::
GetLocalPort
()
{
MS_PORT
TCPConnection
::
GetLocalPort
()
{
return
this
->
localPort
;
}
inline
const
struct
sockaddr
*
TCPConnection
::
GetPeerAddress
()
{
const
struct
sockaddr
*
TCPConnection
::
GetPeerAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
peerAddr
;
}
inline
const
std
::
string
&
TCPConnection
::
GetPeerIP
()
{
const
std
::
string
&
TCPConnection
::
GetPeerIP
()
{
return
this
->
peerIP
;
}
inline
MS_PORT
TCPConnection
::
GetPeerPort
()
{
MS_PORT
TCPConnection
::
GetPeerPort
()
{
return
this
->
peerPort
;
}
inline
void
TCPConnection
::
SetUserData
(
void
*
userData
)
{
void
TCPConnection
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
TCPConnection
::
GetUserData
()
{
void
*
TCPConnection
::
GetUserData
()
{
return
this
->
userData
;
}
#endif
include/handles/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_TCP_SERVER_H
#define MS_TCP_SERVER_H
#include "common.h"
#include "handles/TCPConnection.h"
#include <string>
#include <unordered_set>
#include <uv.h>
class
TCPServer
:
public
TCPConnection
::
Listener
{
class
TCPServer
:
public
TCPConnection
::
Listener
{
public
:
TCPServer
(
const
std
::
string
&
ip
,
MS_PORT
port
,
int
backlog
);
/**
...
...
@@ -63,31 +62,30 @@ protected:
MS_PORT
localPort
=
0
;
};
/* Inline methods. */
inline
void
TCPServer
::
SetUserData
(
void
*
userData
)
{
void
TCPServer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
TCPServer
::
GetUserData
()
{
void
*
TCPServer
::
GetUserData
()
{
return
this
->
userData
;
}
inline
size_t
TCPServer
::
GetNumConnections
()
{
size_t
TCPServer
::
GetNumConnections
()
{
return
this
->
connections
.
size
();
}
inline
bool
TCPServer
::
IsClosing
()
{
bool
TCPServer
::
IsClosing
()
{
return
this
->
isClosing
;
}
#endif
include/handles/Timer.h
浏览文件 @
6262224c
#ifndef MS_TIMER_H
#define MS_TIMER_H
#include "common.h"
#include <uv.h>
class
Timer
{
class
Timer
{
public
:
class
Listener
{
class
Listener
{
public
:
virtual
void
onTimer
(
Timer
*
timer
)
=
0
;
};
...
...
@@ -31,5 +31,4 @@ private:
Listener
*
listener
=
nullptr
;
};
#endif
include/handles/UDPSocket.h
浏览文件 @
6262224c
#ifndef MS_UDP_SOCKET_H
#define MS_UDP_SOCKET_H
#include "common.h"
#include <string>
#include <uv.h>
class
UDPSocket
{
class
UDPSocket
{
public
:
/* Struct for the data field of uv_req_t when sending a datagram. */
typedef
struct
UvSendData
{
typedef
struct
UvSendData
{
UDPSocket
*
socket
;
uv_udp_send_t
req
;
MS_BYTE
store
[
1
];
...
...
@@ -68,49 +68,48 @@ protected:
MS_PORT
localPort
=
0
;
};
/* Inline methods. */
inline
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
{
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
{
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
addr
);
}
inline
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
MS_PORT
port
)
{
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
MS_PORT
port
)
{
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
}
inline
const
struct
sockaddr
*
UDPSocket
::
GetLocalAddress
()
{
const
struct
sockaddr
*
UDPSocket
::
GetLocalAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
localAddr
;
}
inline
const
std
::
string
&
UDPSocket
::
GetLocalIP
()
{
const
std
::
string
&
UDPSocket
::
GetLocalIP
()
{
return
this
->
localIP
;
}
inline
MS_PORT
UDPSocket
::
GetLocalPort
()
{
MS_PORT
UDPSocket
::
GetLocalPort
()
{
return
this
->
localPort
;
}
inline
void
UDPSocket
::
SetUserData
(
void
*
userData
)
{
void
UDPSocket
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
UDPSocket
::
GetUserData
()
{
void
*
UDPSocket
::
GetUserData
()
{
return
this
->
userData
;
}
#endif
include/handles/UnixStreamSocket.h
浏览文件 @
6262224c
#ifndef MS_UNIX_STREAM_SOCKET_H
#define MS_UNIX_STREAM_SOCKET_H
#include "common.h"
#include <string>
#include <uv.h>
class
UnixStreamSocket
{
class
UnixStreamSocket
{
public
:
/* Struct for the data field of uv_req_t when writing data. */
typedef
struct
UvWriteData
{
typedef
struct
UvWriteData
{
UnixStreamSocket
*
socket
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
...
...
@@ -59,25 +59,24 @@ protected:
size_t
bufferDataLen
=
0
;
};
/* Inline methods. */
inline
void
UnixStreamSocket
::
Write
(
const
std
::
string
&
data
)
{
void
UnixStreamSocket
::
Write
(
const
std
::
string
&
data
)
{
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
}
inline
void
UnixStreamSocket
::
SetUserData
(
void
*
userData
)
{
void
UnixStreamSocket
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
UnixStreamSocket
::
GetUserData
()
{
void
*
UnixStreamSocket
::
GetUserData
()
{
return
this
->
userData
;
}
#endif
src/ControlProtocol/Message.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Parser.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Parser.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Request.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/UnixStreamSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/grammar/RequestAuthenticate.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/grammar/RequestCreateConference.rl
浏览文件 @
6262224c
%%{
machine RequestCreateConference;
action on_request_type_CreateConference {
action on_request_type_CreateConference
{
this->msg = new ControlProtocol::RequestCreateConference();
}
...
...
src/ControlProtocol/grammar/RequestHello.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestAuthenticate.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestCreateConference.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestHello.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Daemon.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Dispatcher.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/LibSRTP.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/LibUV.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Logger.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/MediaSoup.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/OpenSSL.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/DTLSHandler.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/ICEServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Peer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/RTCPPacket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/RTPPacket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Room.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/SRTPSession.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/STUNMessage.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Stream.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Transport.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TransportSource.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/UDPSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Settings.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/Crypto.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/File.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/IP.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/IP.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/Socket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Version.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Worker.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/SignalsHandler.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/Timer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/UDPSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/UnixStreamSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/main.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论