mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
支持绑定到指定网卡 (#3760)
This commit is contained in:
parent
81aef25583
commit
e3cad7f8fa
@ -18,13 +18,15 @@ using namespace mediakit;
|
|||||||
|
|
||||||
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int tcp_mode, const char *stream_id) {
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int tcp_mode, const char *stream_id) {
|
||||||
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
||||||
(*server)->start(port, MediaTuple { DEFAULT_VHOST, kRtpAppName, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
GET_CONFIG(std::string, local_ip, General::kListenIP)
|
||||||
|
(*server)->start(port, local_ip.c_str(), MediaTuple { DEFAULT_VHOST, kRtpAppName, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
||||||
return (mk_rtp_server)server;
|
return (mk_rtp_server)server;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create2(uint16_t port, int tcp_mode, const char *vhost, const char *app, const char *stream_id) {
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create2(uint16_t port, int tcp_mode, const char *vhost, const char *app, const char *stream_id) {
|
||||||
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
||||||
(*server)->start(port, MediaTuple { vhost, app, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
GET_CONFIG(std::string, local_ip, General::kListenIP)
|
||||||
|
(*server)->start(port, local_ip.c_str(), MediaTuple { vhost, app, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
||||||
return (mk_rtp_server)server;
|
return (mk_rtp_server)server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +128,8 @@ wait_add_track_ms=3000
|
|||||||
unready_frame_cache=100
|
unready_frame_cache=100
|
||||||
#是否启用观看人数变化事件广播,置1则启用,置0则关闭
|
#是否启用观看人数变化事件广播,置1则启用,置0则关闭
|
||||||
broadcast_player_count_changed=0
|
broadcast_player_count_changed=0
|
||||||
|
#绑定的本地网卡ip
|
||||||
|
listen_ip=::
|
||||||
|
|
||||||
[hls]
|
[hls]
|
||||||
#hls写文件的buf大小,调整参数可以提高文件io性能
|
#hls写文件的buf大小,调整参数可以提高文件io性能
|
||||||
|
@ -482,7 +482,7 @@ uint16_t openRtpServer(uint16_t local_port, const mediakit::MediaTuple &tuple, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto server = s_rtp_server.makeWithAction(key, [&](RtpServer::Ptr server) {
|
auto server = s_rtp_server.makeWithAction(key, [&](RtpServer::Ptr server) {
|
||||||
server->start(local_port, tuple, (RtpServer::TcpMode)tcp_mode, local_ip.c_str(), re_use_port, ssrc, only_track, multiplex);
|
server->start(local_port, local_ip.c_str(), tuple, (RtpServer::TcpMode)tcp_mode, re_use_port, ssrc, only_track, multiplex);
|
||||||
});
|
});
|
||||||
server->setOnDetach([key](const SockException &ex) {
|
server->setOnDetach([key](const SockException &ex) {
|
||||||
//设置rtp超时移除事件
|
//设置rtp超时移除事件
|
||||||
@ -1242,7 +1242,7 @@ void installWebApi() {
|
|||||||
// 兼容老版本请求,新版本去除only_audio参数并新增only_track参数
|
// 兼容老版本请求,新版本去除only_audio参数并新增only_track参数
|
||||||
only_track = 1;
|
only_track = 1;
|
||||||
}
|
}
|
||||||
std::string local_ip = "::";
|
GET_CONFIG(std::string, local_ip, General::kListenIP)
|
||||||
if (!allArgs["local_ip"].empty()) {
|
if (!allArgs["local_ip"].empty()) {
|
||||||
local_ip = allArgs["local_ip"];
|
local_ip = allArgs["local_ip"];
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,7 @@ int start_main(int argc,char *argv[]) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string listen_ip = mINI::Instance()[General::kListenIP];
|
||||||
uint16_t shellPort = mINI::Instance()[Shell::kPort];
|
uint16_t shellPort = mINI::Instance()[Shell::kPort];
|
||||||
uint16_t rtspPort = mINI::Instance()[Rtsp::kPort];
|
uint16_t rtspPort = mINI::Instance()[Rtsp::kPort];
|
||||||
uint16_t rtspsPort = mINI::Instance()[Rtsp::kSSLPort];
|
uint16_t rtspsPort = mINI::Instance()[Rtsp::kSSLPort];
|
||||||
@ -362,39 +363,39 @@ int start_main(int argc,char *argv[]) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
//rtsp服务器,端口默认554
|
//rtsp服务器,端口默认554
|
||||||
if (rtspPort) { rtspSrv->start<RtspSession>(rtspPort); }
|
if (rtspPort) { rtspSrv->start<RtspSession>(rtspPort, listen_ip); }
|
||||||
//rtsps服务器,端口默认322
|
//rtsps服务器,端口默认322
|
||||||
if (rtspsPort) { rtspSSLSrv->start<RtspSessionWithSSL>(rtspsPort); }
|
if (rtspsPort) { rtspSSLSrv->start<RtspSessionWithSSL>(rtspsPort, listen_ip); }
|
||||||
|
|
||||||
//rtmp服务器,端口默认1935
|
//rtmp服务器,端口默认1935
|
||||||
if (rtmpPort) { rtmpSrv->start<RtmpSession>(rtmpPort); }
|
if (rtmpPort) { rtmpSrv->start<RtmpSession>(rtmpPort, listen_ip); }
|
||||||
//rtmps服务器,端口默认19350
|
//rtmps服务器,端口默认19350
|
||||||
if (rtmpsPort) { rtmpsSrv->start<RtmpSessionWithSSL>(rtmpsPort); }
|
if (rtmpsPort) { rtmpsSrv->start<RtmpSessionWithSSL>(rtmpsPort, listen_ip); }
|
||||||
|
|
||||||
//http服务器,端口默认80
|
//http服务器,端口默认80
|
||||||
if (httpPort) { httpSrv->start<HttpSession>(httpPort); }
|
if (httpPort) { httpSrv->start<HttpSession>(httpPort, listen_ip); }
|
||||||
//https服务器,端口默认443
|
//https服务器,端口默认443
|
||||||
if (httpsPort) { httpsSrv->start<HttpsSession>(httpsPort); }
|
if (httpsPort) { httpsSrv->start<HttpsSession>(httpsPort, listen_ip); }
|
||||||
|
|
||||||
//telnet远程调试服务器
|
//telnet远程调试服务器
|
||||||
if (shellPort) { shellSrv->start<ShellSession>(shellPort); }
|
if (shellPort) { shellSrv->start<ShellSession>(shellPort, listen_ip); }
|
||||||
|
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
//创建rtp服务器
|
//创建rtp服务器
|
||||||
if (rtpPort) { rtpServer->start(rtpPort); }
|
if (rtpPort) { rtpServer->start(rtpPort, listen_ip.c_str()); }
|
||||||
#endif//defined(ENABLE_RTPPROXY)
|
#endif//defined(ENABLE_RTPPROXY)
|
||||||
|
|
||||||
#if defined(ENABLE_WEBRTC)
|
#if defined(ENABLE_WEBRTC)
|
||||||
//webrtc udp服务器
|
//webrtc udp服务器
|
||||||
if (rtcPort) { rtcSrv_udp->start<WebRtcSession>(rtcPort);}
|
if (rtcPort) { rtcSrv_udp->start<WebRtcSession>(rtcPort, listen_ip);}
|
||||||
|
|
||||||
if (rtcTcpPort) { rtcSrv_tcp->start<WebRtcSession>(rtcTcpPort);}
|
if (rtcTcpPort) { rtcSrv_tcp->start<WebRtcSession>(rtcTcpPort, listen_ip);}
|
||||||
|
|
||||||
#endif//defined(ENABLE_WEBRTC)
|
#endif//defined(ENABLE_WEBRTC)
|
||||||
|
|
||||||
#if defined(ENABLE_SRT)
|
#if defined(ENABLE_SRT)
|
||||||
// srt udp服务器
|
// srt udp服务器
|
||||||
if (srtPort) { srtSrv->start<SRT::SrtSession>(srtPort); }
|
if (srtPort) { srtSrv->start<SRT::SrtSession>(srtPort, listen_ip); }
|
||||||
#endif//defined(ENABLE_SRT)
|
#endif//defined(ENABLE_SRT)
|
||||||
|
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
|
@ -84,6 +84,7 @@ const string kWaitTrackReadyMS = GENERAL_FIELD "wait_track_ready_ms";
|
|||||||
const string kWaitAddTrackMS = GENERAL_FIELD "wait_add_track_ms";
|
const string kWaitAddTrackMS = GENERAL_FIELD "wait_add_track_ms";
|
||||||
const string kUnreadyFrameCache = GENERAL_FIELD "unready_frame_cache";
|
const string kUnreadyFrameCache = GENERAL_FIELD "unready_frame_cache";
|
||||||
const string kBroadcastPlayerCountChanged = GENERAL_FIELD "broadcast_player_count_changed";
|
const string kBroadcastPlayerCountChanged = GENERAL_FIELD "broadcast_player_count_changed";
|
||||||
|
const string kListenIP = GENERAL_FIELD "listen_ip";
|
||||||
|
|
||||||
static onceToken token([]() {
|
static onceToken token([]() {
|
||||||
mINI::Instance()[kFlowThreshold] = 1024;
|
mINI::Instance()[kFlowThreshold] = 1024;
|
||||||
@ -99,6 +100,7 @@ static onceToken token([]() {
|
|||||||
mINI::Instance()[kWaitAddTrackMS] = 3000;
|
mINI::Instance()[kWaitAddTrackMS] = 3000;
|
||||||
mINI::Instance()[kUnreadyFrameCache] = 100;
|
mINI::Instance()[kUnreadyFrameCache] = 100;
|
||||||
mINI::Instance()[kBroadcastPlayerCountChanged] = 0;
|
mINI::Instance()[kBroadcastPlayerCountChanged] = 0;
|
||||||
|
mINI::Instance()[kListenIP] = "::";
|
||||||
});
|
});
|
||||||
|
|
||||||
} // namespace General
|
} // namespace General
|
||||||
|
@ -202,6 +202,8 @@ extern const std::string kWaitAddTrackMS;
|
|||||||
extern const std::string kUnreadyFrameCache;
|
extern const std::string kUnreadyFrameCache;
|
||||||
// 是否启用观看人数变化事件广播,置1则启用,置0则关闭
|
// 是否启用观看人数变化事件广播,置1则启用,置0则关闭
|
||||||
extern const std::string kBroadcastPlayerCountChanged;
|
extern const std::string kBroadcastPlayerCountChanged;
|
||||||
|
// 绑定的本地网卡ip
|
||||||
|
extern const std::string kListenIP;
|
||||||
} // namespace General
|
} // namespace General
|
||||||
|
|
||||||
namespace Protocol {
|
namespace Protocol {
|
||||||
|
@ -122,7 +122,7 @@ private:
|
|||||||
std::shared_ptr<struct sockaddr_storage> _rtcp_addr;
|
std::shared_ptr<struct sockaddr_storage> _rtcp_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RtpServer::start(uint16_t local_port, const MediaTuple &tuple, 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 char *local_ip, const MediaTuple &tuple, TcpMode tcp_mode, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex) {
|
||||||
//创建udp服务器
|
//创建udp服务器
|
||||||
auto poller = EventPollerPool::Instance().getPoller();
|
auto poller = EventPollerPool::Instance().getPoller();
|
||||||
Socket::Ptr rtp_socket = Socket::createSocket(poller, true);
|
Socket::Ptr rtp_socket = Socket::createSocket(poller, true);
|
||||||
|
@ -36,15 +36,15 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 开启服务器,可能抛异常
|
* 开启服务器,可能抛异常
|
||||||
* @param local_port 本地端口,0时为随机端口
|
* @param local_port 本地端口,0时为随机端口
|
||||||
|
* @param local_ip 绑定的本地网卡ip
|
||||||
* @param stream_id 流id,置空则使用ssrc
|
* @param stream_id 流id,置空则使用ssrc
|
||||||
* @param tcp_mode tcp服务模式
|
* @param tcp_mode tcp服务模式
|
||||||
* @param local_ip 绑定的本地网卡ip
|
|
||||||
* @param re_use_port 是否设置socket为re_use属性
|
* @param re_use_port 是否设置socket为re_use属性
|
||||||
* @param ssrc 指定的ssrc
|
* @param ssrc 指定的ssrc
|
||||||
* @param multiplex 多路复用
|
* @param multiplex 多路复用
|
||||||
*/
|
*/
|
||||||
void start(uint16_t local_port, const MediaTuple &tuple = MediaTuple{DEFAULT_VHOST, kRtpAppName, "", ""}, TcpMode tcp_mode = PASSIVE,
|
void start(uint16_t local_port, const char *local_ip = "::", const MediaTuple &tuple = MediaTuple{DEFAULT_VHOST, kRtpAppName, "", ""}, TcpMode tcp_mode = PASSIVE,
|
||||||
const char *local_ip = "::", bool re_use_port = true, uint32_t ssrc = 0, int only_track = 0, bool multiplex = false);
|
bool re_use_port = true, uint32_t ssrc = 0, int only_track = 0, bool multiplex = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接到tcp服务(tcp主动模式)
|
* 连接到tcp服务(tcp主动模式)
|
||||||
|
Loading…
Reference in New Issue
Block a user