diff --git a/3rdpart/media-server b/3rdpart/media-server index 678678b2..358b7bd3 160000 --- a/3rdpart/media-server +++ b/3rdpart/media-server @@ -1 +1 @@ -Subproject commit 678678b2ee7118d21d33a90a303698e0da02790c +Subproject commit 358b7bd3bf89564371fed48797ad396882f9d130 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cec4ab8..db0117e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,29 +30,15 @@ endif () LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH}) - #设置工程源码根目录 set(ToolKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/ZLToolKit/src) set(MediaKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/src) set(MediaServer_Root ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/media-server) - #设置头文件目录 INCLUDE_DIRECTORIES(${ToolKit_Root}) INCLUDE_DIRECTORIES(${MediaKit_Root}) -#收集源代码 -file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c) -file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c) - -#去除win32的适配代码 -if (NOT WIN32) - list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c) -else() - #防止Windows.h包含Winsock.h - add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS) -endif () - set(ENABLE_HLS true) set(ENABLE_OPENSSL true) set(ENABLE_MYSQL false) @@ -60,6 +46,7 @@ set(ENABLE_MP4V2 true) set(ENABLE_FAAC false) set(ENABLE_X264 false) set(ENABLE_MP4RECORD true) +set(ENABLE_RTPPROXY true) set(LINK_LIB_LIST zlmediakit zltoolkit) @@ -109,6 +96,15 @@ if (FAAC_FOUND AND ENABLE_FAAC) list(APPEND LINK_LIB_LIST ${FAAC_LIBRARIES}) endif () +if(${CMAKE_BUILD_TYPE} MATCHES "Release") + #查找jemalloc是否安装 + find_package(JEMALLOC QUIET) + if(JEMALLOC_FOUND) + message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"") + include_directories(${JEMALLOC_INCLUDE_DIR}) + list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES}) + endif() +endif() set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573" ) @@ -151,24 +147,28 @@ if(ENABLE_MP4RECORD) endif(WIN32) endif() -if(${CMAKE_BUILD_TYPE} MATCHES "Release") - #查找jemalloc是否安装 - find_package(JEMALLOC QUIET) - if(JEMALLOC_FOUND) - message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"") - include_directories(${JEMALLOC_INCLUDE_DIR}) - list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES}) - endif() +if(ENABLE_RTPPROXY) + #添加rtp库用于rtp转ps/ts + aux_source_directory(${MediaServer_Root}/librtp/include src_rtp) + aux_source_directory(${MediaServer_Root}/librtp/source src_rtp) + aux_source_directory(${MediaServer_Root}/librtp/payload src_rtp) + include_directories(${MediaServer_Root}/librtp/include) + add_library(rtp STATIC ${src_rtp}) + add_definitions(-DENABLE_RTPPROXY) + list(APPEND LINK_LIB_LIST rtp) endif() +#收集源代码 +file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c) +file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c) -#添加rtp库用于rtp转ps/ts -aux_source_directory(${MediaServer_Root}/librtp/include src_rtp) -aux_source_directory(${MediaServer_Root}/librtp/source src_rtp) -aux_source_directory(${MediaServer_Root}/librtp/payload src_rtp) -include_directories(${MediaServer_Root}/librtp/include) -add_library(rtp STATIC ${src_rtp}) -list(APPEND LINK_LIB_LIST rtp) +#去除win32的适配代码 +if (NOT WIN32) + list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c) +else() + #防止Windows.h包含Winsock.h + add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS) +endif () #添加库 add_library(zltoolkit STATIC ${ToolKit_src_list}) @@ -182,34 +182,8 @@ elseif(NOT ANDROID OR IOS) list(APPEND LINK_LIB_LIST pthread) endif () - #测试程序 add_subdirectory(tests) #主服务器 add_subdirectory(server) - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LICENSE b/LICENSE index d4008608..367501b6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ MIT License Copyright (c) 2016-2019 xiongziliang <771730766@qq.com> +Copyright (c) 2019 Gemfield +Copyright (c) 2018 huohuo <913481084@qq.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d02ad8e3..e3c0c950 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,8 @@ docker build -t zlmediakit . MIT License Copyright (c) 2016-2019 xiongziliang <771730766@qq.com> +Copyright (c) 2019 Gemfield +Copyright (c) 2018 huohuo <913481084@qq.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -349,6 +351,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ``` diff --git a/conf/config.ini b/conf/config.ini index 8df1dd3b..a7588b80 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -161,6 +161,18 @@ maxRtpCount=50 #视频mtu大小,该参数限制rtp最大字节数,推荐不要超过1400 videoMtuSize=1400 +[rtp_proxy] +#udp类型的代理服务器是否检查rtp源地址,地址不配备将丢弃数据 +checkSource=1 +#导出调试数据(包括rtp/ps/h264)至该目录,置空则关闭数据导出 +dumpDir= +#udp和tcp代理服务器,支持rtp(必须是ts或ps类型)代理 +port=10000 +#rtp如果是ts/ps类型则选择MP2P,还可以设置为MP4V-ES +rtp_type=MP2P +#rtp超时时间,单位秒 +timeoutSec=15 + [rtsp] #rtsp专有鉴权方式是采用base64还是md5方式 authBasic=0 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 6fdf6192..64402ad8 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -693,6 +693,7 @@ void installWebApi() { invoker.responseFile(headerIn,StrCaseMap(),exePath()); }); +#if defined(ENABLE_RTPPROXY) API_REGIST(api,getSsrcInfo,{ CHECK_SECRET(); CHECK_ARGS("ssrc"); @@ -705,6 +706,7 @@ void installWebApi() { val["peer_ip"] = process->get_peer_ip(); val["peer_port"] = process->get_peer_port(); }); +#endif//ENABLE_RTPPROXY // 开始录制hls或MP4 API_REGIST(api,startRecord,{ diff --git a/server/main.cpp b/server/main.cpp index 40126969..6d26bbe9 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -38,11 +38,11 @@ #include "Common/config.h" #include "Rtsp/UDPServer.h" #include "Rtsp/RtspSession.h" +#include "Rtp/RtpSession.h" #include "Rtmp/RtmpSession.h" #include "Shell/ShellSession.h" -#include "Rtmp/FlvMuxer.h" -#include "Player/PlayerProxy.h" #include "Http/WebSocketSession.h" +#include "Rtp/UdpRecver.h" #include "WebApi.h" #include "WebHook.h" @@ -58,36 +58,31 @@ namespace mediakit { ////////////HTTP配置/////////// namespace Http { #define HTTP_FIELD "http." -#define HTTP_PORT 80 const string kPort = HTTP_FIELD"port"; -#define HTTPS_PORT 443 const string kSSLPort = HTTP_FIELD"sslport"; onceToken token1([](){ - mINI::Instance()[kPort] = HTTP_PORT; - mINI::Instance()[kSSLPort] = HTTPS_PORT; + mINI::Instance()[kPort] = 80; + mINI::Instance()[kSSLPort] = 443; },nullptr); }//namespace Http ////////////SHELL配置/////////// namespace Shell { #define SHELL_FIELD "shell." -#define SHELL_PORT 9000 const string kPort = SHELL_FIELD"port"; onceToken token1([](){ - mINI::Instance()[kPort] = SHELL_PORT; + mINI::Instance()[kPort] = 9000; },nullptr); } //namespace Shell ////////////RTSP服务器配置/////////// namespace Rtsp { #define RTSP_FIELD "rtsp." -#define RTSP_PORT 554 -#define RTSPS_PORT 322 const string kPort = RTSP_FIELD"port"; const string kSSLPort = RTSP_FIELD"sslport"; onceToken token1([](){ - mINI::Instance()[kPort] = RTSP_PORT; - mINI::Instance()[kSSLPort] = RTSPS_PORT; + mINI::Instance()[kPort] = 554; + mINI::Instance()[kSSLPort] = 332; },nullptr); } //namespace Rtsp @@ -95,12 +90,21 @@ onceToken token1([](){ ////////////RTMP服务器配置/////////// namespace Rtmp { #define RTMP_FIELD "rtmp." -#define RTMP_PORT 1935 const string kPort = RTMP_FIELD"port"; onceToken token1([](){ - mINI::Instance()[kPort] = RTMP_PORT; + mINI::Instance()[kPort] = 1935; },nullptr); } //namespace RTMP + +////////////Rtp代理相关配置/////////// +namespace RtpProxy { +#define RTP_PROXY_FIELD "rtp_proxy." +const string kPort = RTP_PROXY_FIELD"port"; +onceToken token1([](){ + mINI::Instance()[kPort] = 10000; +},nullptr); +} //namespace RtpProxy + } // namespace mediakit @@ -269,6 +273,7 @@ int start_main(int argc,char *argv[]) { uint16_t rtmpPort = mINI::Instance()[Rtmp::kPort]; uint16_t httpPort = mINI::Instance()[Http::kPort]; uint16_t httpsPort = mINI::Instance()[Http::kSSLPort]; + uint16_t rtp_proxy = mINI::Instance()[RtpProxy::kPort]; //设置poller线程数,该函数必须在使用ZLToolKit网络相关对象之前调用才能生效 EventPollerPool::setPoolSize(threads); @@ -284,6 +289,11 @@ int start_main(int argc,char *argv[]) { //支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问 TcpServer::Ptr rtspSSLSrv(new TcpServer()); +#if defined(ENABLE_RTPPROXY) + UdpRecver recver; + TcpServer::Ptr tcpRtpServer(new TcpServer()); +#endif//defined(ENABLE_RTPPROXY) + try { //rtsp服务器,端口默认554 rtspSrv->start(rtspPort);//默认554 @@ -297,6 +307,14 @@ int start_main(int argc,char *argv[]) { httpsSrv->start(httpsPort); //telnet远程调试服务器 shellSrv->start(shellPort); + +#if defined(ENABLE_RTPPROXY) + //创建rtp udp服务器 + recver.initSock(rtp_proxy); + //创建rtp tcp服务器 + tcpRtpServer->start(rtp_proxy); +#endif//defined(ENABLE_RTPPROXY) + }catch (std::exception &ex){ WarnL << "端口占用或无权限:" << ex.what() << endl; ErrorL << "程序启动失败,请修改配置文件中端口号后重试!" << endl; diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 426bb082..d4f08373 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -275,6 +275,28 @@ onceToken token([](){ },nullptr); } //namespace Hls + +////////////Rtp代理相关配置/////////// +namespace RtpProxy { +#define RTP_PROXY_FIELD "rtp_proxy." +//rtp调试数据保存目录 +const string kDumpDir = RTP_PROXY_FIELD"dumpDir"; +//是否限制udp数据来源ip和端口 +const string kCheckSource = RTP_PROXY_FIELD"checkSource"; +//rtp类型,支持MP2P/MP4V-ES +const string kRtpType = RTP_PROXY_FIELD"rtp_type"; +//rtp接收超时时间 +const string kTimeoutSec = RTP_PROXY_FIELD"timeoutSec"; + +onceToken token([](){ + mINI::Instance()[kDumpDir] = ""; + mINI::Instance()[kCheckSource] = 1; + mINI::Instance()[kRtpType] = "MP2P"; + mINI::Instance()[kTimeoutSec] = 15; +},nullptr); +} //namespace RtpProxy + + namespace Client { const string kNetAdapter = "net_adapter"; const string kRtpType = "rtp_type"; diff --git a/src/Common/config.h b/src/Common/config.h index 9a090144..8eb447b3 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -159,11 +159,6 @@ extern const string kBroadcastReloadConfig; static type arg = mINI::Instance()[key]; \ LISTEN_RELOAD_KEY(arg,key); - -//兼容老代码 -#define GET_CONFIG_AND_REGISTER GET_CONFIG -#define BroadcastRtmpPublishArgs BroadcastMediaPublishArgs -#define kBroadcastRtmpPublish kBroadcastMediaPublish } //namespace Broadcast ////////////通用配置/////////// @@ -301,6 +296,17 @@ extern const string kFileBufSize; extern const string kFilePath; } //namespace Hls +////////////Rtp代理相关配置/////////// +namespace RtpProxy { +//rtp调试数据保存目录,置空则不生成 +extern const string kDumpDir; +//是否限制udp数据来源ip和端口 +extern const string kCheckSource; +//rtp类型,支持MP2P/MP4V-ES +extern const string kRtpType; +//rtp接收超时时间 +extern const string kTimeoutSec; +} //namespace RtpProxy /** * rtsp/rtmp播放器、推流器相关设置名, diff --git a/src/Rtp/PSDecoder.cpp b/src/Rtp/PSDecoder.cpp index 835bc068..47abb768 100644 --- a/src/Rtp/PSDecoder.cpp +++ b/src/Rtp/PSDecoder.cpp @@ -1,30 +1,34 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) #include "PSDecoder.h" +#include "mpeg-ps.h" + +namespace mediakit{ PSDecoder::PSDecoder() { _ps_demuxer = ps_demuxer_create([](void* param, @@ -41,9 +45,13 @@ PSDecoder::PSDecoder() { } PSDecoder::~PSDecoder() { - ps_demuxer_destroy(_ps_demuxer); + ps_demuxer_destroy((struct ps_demuxer_t*)_ps_demuxer); } -int PSDecoder::decodePS(const uint8_t *data, size_t bytes) { - return ps_demuxer_input(_ps_demuxer,data,bytes); +int PSDecoder::decodePS(const uint8_t *data, int bytes) { + return ps_demuxer_input((struct ps_demuxer_t*)_ps_demuxer,data,bytes); } + +}//namespace mediakit + +#endif//#if defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/PSDecoder.h b/src/Rtp/PSDecoder.h index 63d50008..c8a73872 100644 --- a/src/Rtp/PSDecoder.h +++ b/src/Rtp/PSDecoder.h @@ -1,46 +1,42 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef RTPPROXY_PSDECODER_H -#define RTPPROXY_PSDECODER_H +#ifndef ZLMEDIAKIT_PSDECODER_H +#define ZLMEDIAKIT_PSDECODER_H -#ifdef __cplusplus -extern "C" { -#endif +#if defined(ENABLE_RTPPROXY) +#include -#include "mpeg-ps.h" -#ifdef __cplusplus -} -#endif +namespace mediakit{ class PSDecoder { public: PSDecoder(); virtual ~PSDecoder(); - int decodePS(const uint8_t *data, size_t bytes); + int decodePS(const uint8_t *data, int bytes); protected: virtual void onPSDecode(int stream, int codecid, @@ -48,10 +44,12 @@ protected: int64_t pts, int64_t dts, const void *data, - size_t bytes) = 0; + int bytes) = 0; private: - struct ps_demuxer_t *_ps_demuxer = nullptr; + void *_ps_demuxer = nullptr; }; +}//namespace mediakit -#endif //RTPPROXY_PSDECODER_H +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_PSDECODER_H diff --git a/src/Rtp/RtpDecoder.cpp b/src/Rtp/RtpDecoder.cpp index a5d40aa8..5f78cd7c 100644 --- a/src/Rtp/RtpDecoder.cpp +++ b/src/Rtp/RtpDecoder.cpp @@ -1,34 +1,39 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) #include #include "Util/logger.h" #include "RtpDecoder.h" +#include "rtp-payload.h" + using namespace toolkit; +namespace mediakit{ + RtpDecoder::RtpDecoder() { _buffer = std::make_shared(); } @@ -68,3 +73,6 @@ void RtpDecoder::decodeRtp(const void *data, int bytes,const char *type_name) { rtp_payload_decode_input(_rtp_decoder,data,bytes); } } + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpDecoder.h b/src/Rtp/RtpDecoder.h index de2ad240..845dbdbd 100644 --- a/src/Rtp/RtpDecoder.h +++ b/src/Rtp/RtpDecoder.h @@ -1,43 +1,37 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef IPTV_RTPTOTS_H -#define IPTV_RTPTOTS_H +#ifndef ZLMEDIAKIT_RTPDECODER_H +#define ZLMEDIAKIT_RTPDECODER_H +#if defined(ENABLE_RTPPROXY) #include "Network/Buffer.h" using namespace toolkit; -#ifdef __cplusplus -extern "C" { -#endif -#include "rtp-payload.h" -#include "mpeg-ts.h" -#ifdef __cplusplus -} -#endif +namespace mediakit{ class RtpDecoder { public: @@ -51,5 +45,6 @@ private: BufferRaw::Ptr _buffer; }; - -#endif //IPTV_RTPTOTS_H +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_RTPDECODER_H diff --git a/src/Rtp/RtpFileLoader.cpp b/src/Rtp/RtpFileLoader.cpp deleted file mode 100644 index 785304fc..00000000 --- a/src/Rtp/RtpFileLoader.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -#include -#include -#include -#include "RtpFileLoader.h" -#include "Util/logger.h" -#include "RtpSelector.h" -using namespace toolkit; - -bool RtpFileLoader::loadFile(const char *path) { - FILE *fp = fopen(path, "rb"); - if (!fp) { - WarnL << "open file failed:" << path; - return false; - } - - uint32_t timeStamp_last = 0; - uint16_t len; - char rtp[2 * 1024]; - while (true) { - if (2 != fread(&len, 1, 2, fp)) { - WarnL; - break; - } - len = ntohs(len); - if (len < 12 || len > sizeof(rtp)) { - WarnL << len; - break; - } - - if (len != fread(rtp, 1, len, fp)) { - WarnL; - break; - } - - uint32_t timeStamp; - memcpy(&timeStamp, rtp + 4, 4); - timeStamp = ntohl(timeStamp); - timeStamp /= 90; - - if(timeStamp_last){ - auto diff = timeStamp - timeStamp_last; - if(diff > 0){ - usleep(diff * 1000); - } - } - - timeStamp_last = timeStamp; - RtpSelector::Instance().inputRtp(rtp,len, nullptr); - } - - fclose(fp); - return true; -} diff --git a/src/Rtp/RtpFileLoader.h b/src/Rtp/RtpFileLoader.h deleted file mode 100644 index a715d618..00000000 --- a/src/Rtp/RtpFileLoader.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - -#ifndef RTPPROXY_RTPFILELOADER_H -#define RTPPROXY_RTPFILELOADER_H - - -class RtpFileLoader { -public: - RtpFileLoader(){}; - ~RtpFileLoader(){}; - static bool loadFile(const char *path); -}; - - -#endif //RTPPROXY_RTPFILELOADER_H diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index f74cb8da..b19c43c9 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -1,57 +1,37 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) +#include "mpeg-ps.h" #include "RtpProcess.h" #include "Util/File.h" -#include "Util/logger.h" #include "Extension/H265.h" -#include "Extension/H264.h" #include "Extension/AAC.h" -using namespace toolkit; - -namespace dump { -const string kEnable = "dump.enable"; -const string kDir = "dump.dir"; -const string kChcekSource = "dump.checkSource"; -onceToken token([](){ - mINI::Instance()[kEnable] = 0; - mINI::Instance()[kDir] = "./dump/"; - mINI::Instance()[kChcekSource] = 1; -}); -}//namespace dump - -namespace Rtp { -const string kRtpType = "rtp.rtp_type"; -const string kTimeoutSec = "rtp.timeoutSec"; -onceToken token([](){ - mINI::Instance()[kRtpType] = "MP2P"; - mINI::Instance()[kTimeoutSec] = 15; -}); -}//namespace dump +namespace mediakit{ /** * 合并一些时间戳相同的frame @@ -106,10 +86,9 @@ RtpProcess::RtpProcess(uint32_t ssrc) { DebugL << printSSRC(_ssrc); _muxer = std::make_shared(DEFAULT_VHOST,"rtp",printSSRC(_ssrc)); - GET_CONFIG(bool,dump_enable,dump::kEnable); - GET_CONFIG(string,dump_dir,dump::kDir); + GET_CONFIG(string,dump_dir,RtpProxy::kDumpDir); { - FILE *fp = dump_enable ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".rtp",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".rtp",dump_dir).data(),"wb") : nullptr; if(fp){ _save_file_rtp.reset(fp,[](FILE *fp){ fclose(fp); @@ -118,7 +97,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) { } { - FILE *fp = dump_enable ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".mp2",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".mp2",dump_dir).data(),"wb") : nullptr; if(fp){ _save_file_ps.reset(fp,[](FILE *fp){ fclose(fp); @@ -127,7 +106,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) { } { - FILE *fp = dump_enable ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".video",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(printSSRC(_ssrc) + ".video",dump_dir).data(),"wb") : nullptr; if(fp){ _save_file_video.reset(fp,[](FILE *fp){ fclose(fp); @@ -147,7 +126,7 @@ RtpProcess::~RtpProcess() { } bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *addr) { - GET_CONFIG(bool,check_source,dump::kChcekSource); + GET_CONFIG(bool,check_source,RtpProxy::kCheckSource); //检查源是否合法 if(!_addr){ _addr = new struct sockaddr; @@ -177,7 +156,7 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) { fwrite((uint8_t *) rtp->data() + 4, rtp->size() - 4, 1, _save_file_rtp.get()); } - GET_CONFIG(string,rtp_type,::Rtp::kRtpType); + GET_CONFIG(string,rtp_type,::RtpProxy::kRtpType); decodeRtp(rtp->data() + 4 ,rtp->size() - 4,rtp_type.data()); } @@ -198,7 +177,7 @@ void RtpProcess::onPSDecode(int stream, int64_t pts, int64_t dts, const void *data, - size_t bytes) { + int bytes) { switch (codecid) { case STREAM_VIDEO_H264: { @@ -270,7 +249,7 @@ void RtpProcess::onPSDecode(int stream, } bool RtpProcess::alive() { - GET_CONFIG(int,timeoutSec,::Rtp::kTimeoutSec) + GET_CONFIG(int,timeoutSec,RtpProxy::kTimeoutSec) if(_last_rtp_time.elapsedTime() / 1000 < timeoutSec){ return true; } @@ -284,3 +263,6 @@ string RtpProcess::get_peer_ip() { uint16_t RtpProcess::get_peer_port() { return ntohs(((struct sockaddr_in *) _addr)->sin_port); } + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index ac1c4874..13ddfbeb 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -1,31 +1,33 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef RTPPROXY_RTPDECODER_H -#define RTPPROXY_RTPDECODER_H +#ifndef ZLMEDIAKIT_RTPPROCESS_H +#define ZLMEDIAKIT_RTPPROCESS_H + +#if defined(ENABLE_RTPPROXY) #include "Rtsp/RtpReceiver.h" #include "RtpDecoder.h" @@ -33,6 +35,8 @@ #include "Common/Device.h" using namespace mediakit; +namespace mediakit{ + string printSSRC(uint32_t ui32Ssrc); class FrameMerger; @@ -54,7 +58,7 @@ protected: int64_t pts, int64_t dts, const void *data, - size_t bytes) override ; + int bytes) override ; private: std::shared_ptr _save_file_rtp; std::shared_ptr _save_file_ps; @@ -70,5 +74,6 @@ private: Ticker _last_rtp_time; }; - -#endif //RTPPROXY_RTPDECODER_H +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_RTPPROCESS_H diff --git a/src/Rtp/RtpSelector.cpp b/src/Rtp/RtpSelector.cpp index a407ef7a..2ff997a7 100644 --- a/src/Rtp/RtpSelector.cpp +++ b/src/Rtp/RtpSelector.cpp @@ -1,31 +1,34 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) #include "RtpSelector.h" +namespace mediakit{ + INSTANCE_IMP(RtpSelector); bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr *addr) { @@ -97,3 +100,6 @@ RtpSelector::RtpSelector() { RtpSelector::~RtpSelector() { } + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpSelector.h b/src/Rtp/RtpSelector.h index e7011c4a..872d3ada 100644 --- a/src/Rtp/RtpSelector.h +++ b/src/Rtp/RtpSelector.h @@ -1,37 +1,39 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef RTPPROXY_RTPSELECTOR_H -#define RTPPROXY_RTPSELECTOR_H +#ifndef ZLMEDIAKIT_RTPSELECTOR_H +#define ZLMEDIAKIT_RTPSELECTOR_H -#include +#if defined(ENABLE_RTPPROXY) +#include #include #include #include "RtpProcess.h" +namespace mediakit{ class RtpSelector : public std::enable_shared_from_this{ public: @@ -51,5 +53,6 @@ private: Ticker _last_rtp_time; }; - -#endif //RTPPROXY_RTPSELECTOR_H +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_RTPSELECTOR_H diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index a7faa4a7..b1ad9137 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -1,30 +1,33 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(ENABLE_RTPPROXY) #include "RtpSession.h" #include "RtpSelector.h" +namespace mediakit{ RtpSession::RtpSession(const Socket::Ptr &sock) : TcpSession(sock) { DebugP(this); @@ -70,3 +73,6 @@ void RtpSession::onRtpPacket(const char *data, uint64_t len) { _process->inputRtp(data + 2,len - 2,&addr); _ticker.resetTime(); } + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpSession.h b/src/Rtp/RtpSession.h index 68ce863c..ff8771a1 100644 --- a/src/Rtp/RtpSession.h +++ b/src/Rtp/RtpSession.h @@ -1,39 +1,41 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef RTPPROXY_RTPSESSION_H -#define RTPPROXY_RTPSESSION_H +#ifndef ZLMEDIAKIT_RTPSESSION_H +#define ZLMEDIAKIT_RTPSESSION_H +#if defined(ENABLE_RTPPROXY) #include "Network/TcpSession.h" #include "RtpSplitter.h" #include "RtpProcess.h" #include "Util/TimeTicker.h" - using namespace toolkit; +namespace mediakit{ + class RtpSession : public TcpSession , public RtpSplitter{ public: RtpSession(const Socket::Ptr &sock); @@ -50,5 +52,6 @@ private: struct sockaddr addr; }; - -#endif //RTPPROXY_RTPSESSION_H +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_RTPSESSION_H diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index b28697b6..2317f68b 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -1,30 +1,32 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) #include "RtpSplitter.h" +namespace mediakit{ RtpSplitter::RtpSplitter() { } @@ -50,4 +52,7 @@ const char *RtpSplitter::onSearchPacketTail(const char *data, int len) { int64_t RtpSplitter::onRecvHeader(const char *data, uint64_t len) { onRtpPacket(data,len); return 0; -} \ No newline at end of file +} + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index 66dc1c88..34a026a4 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -1,34 +1,36 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -#ifndef RTPPROXY_RTPSPLITTER_H -#define RTPPROXY_RTPSPLITTER_H +#ifndef ZLMEDIAKIT_RTPSPLITTER_H +#define ZLMEDIAKIT_RTPSPLITTER_H +#if defined(ENABLE_RTPPROXY) #include "Http/HttpRequestSplitter.h" -using namespace mediakit; + +namespace mediakit{ class RtpSplitter : public HttpRequestSplitter{ public: @@ -46,5 +48,6 @@ protected: int64_t onRecvHeader(const char *data,uint64_t len) override; }; - -#endif //RTPPROXY_RTPSPLITTER_H +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) +#endif //ZLMEDIAKIT_RTPSPLITTER_H diff --git a/src/Rtp/UdpRecver.cpp b/src/Rtp/UdpRecver.cpp index 5ac3ecd5..79995a85 100644 --- a/src/Rtp/UdpRecver.cpp +++ b/src/Rtp/UdpRecver.cpp @@ -1,31 +1,34 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(ENABLE_RTPPROXY) #include "UdpRecver.h" #include "RtpSelector.h" +namespace mediakit{ + UdpRecver::UdpRecver() { } @@ -48,3 +51,6 @@ bool UdpRecver::initSock(uint16_t local_port,const char *local_ip) { EventPoller::Ptr UdpRecver::getPoller() { return _sock->getPoller(); } + +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/UdpRecver.h b/src/Rtp/UdpRecver.h index 4f412a49..f2a19a36 100644 --- a/src/Rtp/UdpRecver.h +++ b/src/Rtp/UdpRecver.h @@ -1,37 +1,40 @@ /* -* MIT License -* -* Copyright (c) 2016-2019 Gemfield -* -* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ + * MIT License + * + * Copyright (c) 2019 Gemfield + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ #ifndef ZLMEDIAKIT_UDPRECVER_H #define ZLMEDIAKIT_UDPRECVER_H +#if defined(ENABLE_RTPPROXY) #include #include "Network/Socket.h" - using namespace std; using namespace toolkit; + +namespace mediakit{ + /** * 组播接收器 */ @@ -48,5 +51,6 @@ protected: Socket::Ptr _sock; }; - +}//namespace mediakit +#endif//defined(ENABLE_RTPPROXY) #endif //ZLMEDIAKIT_UDPRECVER_H diff --git a/tests/test_rtp.cpp b/tests/test_rtp.cpp index 864e1655..1be10ceb 100644 --- a/tests/test_rtp.cpp +++ b/tests/test_rtp.cpp @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2016-2019 Gemfield + * Copyright (c) 2019 Gemfield * * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). * @@ -36,29 +36,78 @@ #include "Rtsp/RtspSession.h" #include "Rtmp/RtmpSession.h" #include "Http/HttpSession.h" -#include "Rtp/RtpFileLoader.h" +#include "Rtp/RtpSelector.h" using namespace std; using namespace toolkit; using namespace mediakit; -int main(int argc,char *argv[]) { - { - //设置日志 - Logger::Instance().add(std::make_shared("ConsoleChannel")); - //启动异步日志线程 - Logger::Instance().setWriter(std::make_shared()); - loadIniConfig((exeDir() + "config.ini").data()); - TcpServer::Ptr rtspSrv(new TcpServer()); - TcpServer::Ptr rtmpSrv(new TcpServer()); - TcpServer::Ptr httpSrv(new TcpServer()); - rtspSrv->start(554);//默认554 - rtmpSrv->start(1935);//默认1935 - httpSrv->start(80);//默认80 - RtpFileLoader::loadFile(argv[1]); +#if defined(ENABLE_RTPPROXY) +static bool loadFile(const char *path){ + FILE *fp = fopen(path, "rb"); + if (!fp) { + WarnL << "open file failed:" << path; + return false; } + + uint32_t timeStamp_last = 0; + uint16_t len; + char rtp[2 * 1024]; + while (true) { + if (2 != fread(&len, 1, 2, fp)) { + WarnL; + break; + } + len = ntohs(len); + if (len < 12 || len > sizeof(rtp)) { + WarnL << len; + break; + } + + if (len != fread(rtp, 1, len, fp)) { + WarnL; + break; + } + + uint32_t timeStamp; + memcpy(&timeStamp, rtp + 4, 4); + timeStamp = ntohl(timeStamp); + timeStamp /= 90; + + if(timeStamp_last){ + auto diff = timeStamp - timeStamp_last; + if(diff > 0){ + usleep(diff * 1000); + } + } + + timeStamp_last = timeStamp; + + RtpSelector::Instance().inputRtp(rtp,len, nullptr); + } + fclose(fp); + return true; +} +#endif//#if defined(ENABLE_RTPPROXY) + +int main(int argc,char *argv[]) { + //设置日志 + Logger::Instance().add(std::make_shared("ConsoleChannel")); +#if defined(ENABLE_RTPPROXY) + //启动异步日志线程 + Logger::Instance().setWriter(std::make_shared()); + loadIniConfig((exeDir() + "config.ini").data()); + TcpServer::Ptr rtspSrv(new TcpServer()); + TcpServer::Ptr rtmpSrv(new TcpServer()); + TcpServer::Ptr httpSrv(new TcpServer()); + rtspSrv->start(554);//默认554 + rtmpSrv->start(1935);//默认1935 + httpSrv->start(80);//默认80 + loadFile(argv[1]); +#else + ErrorL << "please ENABLE_RTPPROXY and then test"; +#endif//#if defined(ENABLE_RTPPROXY) return 0; } -