mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
保证rtp服务器tcp模式下线程安全
This commit is contained in:
parent
2ead272187
commit
2bf16e63e1
@ -1 +1 @@
|
|||||||
Subproject commit 5144e2aa521df6d473308bfb31172054772a634f
|
Subproject commit 79c10fe4773819d99efe905bb2fecf3446f3b36c
|
@ -124,8 +124,9 @@ private:
|
|||||||
|
|
||||||
void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_mode, const char *local_ip, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex) {
|
void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_mode, const char *local_ip, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex) {
|
||||||
//创建udp服务器
|
//创建udp服务器
|
||||||
Socket::Ptr rtp_socket = Socket::createSocket(nullptr, true);
|
auto poller = EventPollerPool::Instance().getPoller();
|
||||||
Socket::Ptr rtcp_socket = Socket::createSocket(nullptr, true);
|
Socket::Ptr rtp_socket = Socket::createSocket(poller, true);
|
||||||
|
Socket::Ptr rtcp_socket = Socket::createSocket(poller, true);
|
||||||
if (local_port == 0) {
|
if (local_port == 0) {
|
||||||
//随机端口,rtp端口采用偶数
|
//随机端口,rtp端口采用偶数
|
||||||
auto pair = std::make_pair(rtp_socket, rtcp_socket);
|
auto pair = std::make_pair(rtp_socket, rtcp_socket);
|
||||||
@ -181,14 +182,14 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_
|
|||||||
|
|
||||||
TcpServer::Ptr tcp_server;
|
TcpServer::Ptr tcp_server;
|
||||||
if (tcp_mode == PASSIVE || tcp_mode == ACTIVE) {
|
if (tcp_mode == PASSIVE || tcp_mode == ACTIVE) {
|
||||||
//创建tcp服务器
|
auto processor = helper ? helper->getProcess() : nullptr;
|
||||||
tcp_server = std::make_shared<TcpServer>();
|
// 如果共享同一个processor对象,那么tcp server深圳为单线程模式确保线程安全
|
||||||
|
tcp_server = std::make_shared<TcpServer>(processor ? poller : nullptr);
|
||||||
(*tcp_server)[RtpSession::kStreamID] = stream_id;
|
(*tcp_server)[RtpSession::kStreamID] = stream_id;
|
||||||
(*tcp_server)[RtpSession::kSSRC] = ssrc;
|
(*tcp_server)[RtpSession::kSSRC] = ssrc;
|
||||||
(*tcp_server)[RtpSession::kOnlyTrack] = only_track;
|
(*tcp_server)[RtpSession::kOnlyTrack] = only_track;
|
||||||
if (tcp_mode == PASSIVE) {
|
if (tcp_mode == PASSIVE) {
|
||||||
weak_ptr<RtpServer> weak_self = shared_from_this();
|
weak_ptr<RtpServer> weak_self = shared_from_this();
|
||||||
auto processor = helper ? helper->getProcess() : nullptr;
|
|
||||||
tcp_server->start<RtpSession>(local_port, local_ip, 1024, [weak_self, processor](std::shared_ptr<RtpSession> &session) {
|
tcp_server->start<RtpSession>(local_port, local_ip, 1024, [weak_self, processor](std::shared_ptr<RtpSession> &session) {
|
||||||
session->setRtpProcess(processor);
|
session->setRtpProcess(processor);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user