From be5d98b968c8735584246f48325e9f2d3962b44c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 18 Dec 2019 14:53:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mk=5Frtp=5Fserver=5Fstart?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/common.h | 7 +++++++ api/include/httpdownloader.h | 1 - api/include/proxyplayer.h | 1 - api/source/common.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/api/include/common.h b/api/include/common.h index 8a451d73..da39e557 100755 --- a/api/include/common.h +++ b/api/include/common.h @@ -102,6 +102,13 @@ API_EXPORT uint16_t API_CALL mk_rtsp_server_start(uint16_t port, int ssl); */ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl); +/** + * 创建rtp服务器 + * @param port rtp监听端口(包括udp/tcp) + * @return 0:失败,非0:端口号 + */ +API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port); + /** * 打印日志 * @param level 日志级别,支持0~4 diff --git a/api/include/httpdownloader.h b/api/include/httpdownloader.h index 0354ec62..0e8f85fd 100755 --- a/api/include/httpdownloader.h +++ b/api/include/httpdownloader.h @@ -65,7 +65,6 @@ API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader ctx); */ API_EXPORT void API_CALL mk_http_downloader_start(mk_http_downloader ctx, const char *url, const char *file, on_mk_download_complete cb, void *user_data); - #ifdef __cplusplus } #endif diff --git a/api/include/proxyplayer.h b/api/include/proxyplayer.h index d1230f7f..24652e2e 100644 --- a/api/include/proxyplayer.h +++ b/api/include/proxyplayer.h @@ -53,7 +53,6 @@ API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *vhost, co */ API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx); - /** * 设置代理播放器配置选项 * @param ctx 代理播放器指针 diff --git a/api/source/common.cpp b/api/source/common.cpp index 8f6d79b6..0b566645 100755 --- a/api/source/common.cpp +++ b/api/source/common.cpp @@ -43,6 +43,13 @@ static TcpServer::Ptr rtsp_server[2]; static TcpServer::Ptr rtmp_server[2]; static TcpServer::Ptr http_server[2]; +#ifdef ENABLE_RTPPROXY +#include "Rtp/UdpRecver.h" +#include "Rtp/RtpSession.h" +static std::shared_ptr udpRtpServer; +static TcpServer::Ptr tcpRtpServer(new TcpServer()); +#endif + //////////////////////////environment init/////////////////////////// API_EXPORT void API_CALL mk_env_init(const config *cfg) { assert(cfg); @@ -129,6 +136,28 @@ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl) { } } +API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port){ +#ifdef ENABLE_RTPPROXY + try { + //创建rtp tcp服务器 + tcpRtpServer->start(port); + auto ret = tcpRtpServer->getPort(); + udpRtpServer = std::make_shared(); + //创建rtp udp服务器 + udpRtpServer->initSock(port); + return ret; + } catch (std::exception &ex) { + tcpRtpServer.reset(); + udpRtpServer.reset(); + WarnL << ex.what(); + return 0; + } +#else + WarnL << "未启用该功能!"; + return 0; +#endif +} + API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) { assert(file && function && fmt); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line);