From 3165a2f81c7d1a598c2d50be8736dc2226f4ac12 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 29 Jun 2021 11:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=A3=B0=E6=98=8E=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 113 ++++++++++++++++++++++++------------- conf/config.ini | 2 +- server/CMakeLists.txt | 37 ------------ server/main.cpp | 6 +- server/version.h.ini | 11 ---- src/Common/macros.h | 12 +++- src/Rtmp/Rtmp.h | 2 +- src/Rtmp/RtmpMediaSource.h | 1 + src/Rtsp/RtspMediaSource.h | 2 +- src/Rtsp/RtspSession.cpp | 2 +- version.h.ini | 9 +++ webrtc/Sdp.cpp | 1 - 12 files changed, 102 insertions(+), 96 deletions(-) delete mode 100644 server/version.h.ini create mode 100644 version.h.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index 451baeba..12cc7550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") #set(CMAKE_BUILD_TYPE "Release") -if(${CMAKE_BUILD_TYPE} MATCHES "Release") +if (${CMAKE_BUILD_TYPE} MATCHES "Release") message(STATUS "Release版本") set(BuildType "Release") -else() +else () set(BuildType "Debug") message(STATUS "Debug版本") -endif() +endif () #设置bin和lib库目录 set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release) @@ -57,6 +57,41 @@ option(ENABLE_MEM_DEBUG "Enable Memory Debug" false) option(ENABLE_ASAN "Enable Address Sanitize" false) option(ENABLE_WEBRTC "Enable WebRTC" false) +# 添加git版本信息 +set(COMMIT_HASH "Git_NotFound_Unkown_commit") +set(BRANCH_NAME "Git_NotFound_Unkown_branch") +set(BUILD_TIME "") + +string(TIMESTAMP BUILD_TIME "%Y/%m/%d-%H:%M:%S") + +find_package(Git QUIET) +if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h + OUTPUT_VARIABLE COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + execute_process( + COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD + OUTPUT_VARIABLE BRANCH_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endif () + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini + ${CMAKE_BINARY_DIR}/Version.h + @ONLY +) + +add_definitions(-DENABLE_VERSION) +include_directories(${CMAKE_BINARY_DIR}) +message(STATUS "Git version is ${BRANCH_NAME}:${COMMIT_HASH}:${BUILD_TIME}") + if (ENABLE_MEM_DEBUG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-wrap,free -Wl,-wrap,malloc -Wl,-wrap,realloc -Wl,-wrap,calloc") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-wrap,free -Wl,-wrap,malloc -Wl,-wrap,realloc -Wl,-wrap,calloc") @@ -74,11 +109,11 @@ set(LINK_LIB_LIST zlmediakit zltoolkit) #默认链接jemalloc库避免内存碎片 find_package(JEMALLOC QUIET) -if(JEMALLOC_FOUND) +if (JEMALLOC_FOUND) message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"") include_directories(${JEMALLOC_INCLUDE_DIR}) - list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES}) -endif() + list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES}) +endif () #查找openssl是否安装 find_package(OpenSSL QUIET) @@ -89,9 +124,9 @@ if (OPENSSL_FOUND AND ENABLE_OPENSSL) list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES}) if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS) list(APPEND LINK_LIB_LIST dl) - endif() + endif () -else() +else () message(WARNING "openssl未找到,rtmp将不支持flash播放器,https/wss/rtsps/rtmps也将失效") endif () @@ -124,10 +159,10 @@ if (FAAC_FOUND AND ENABLE_FAAC) endif () #set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" ) -set(VS_FALGS "/wd4819" ) +set(VS_FALGS "/wd4819") #添加mpeg用于支持ts生成 -if(ENABLE_HLS) +if (ENABLE_HLS) message(STATUS "ENABLE_HLS defined") add_definitions(-DENABLE_HLS) @@ -139,13 +174,13 @@ if(ENABLE_HLS) list(APPEND LINK_LIB_LIST mpeg) list(APPEND CXX_API_TARGETS mpeg) - if(WIN32) - set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) - endif(WIN32) -endif() + if (WIN32) + set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS}) + endif (WIN32) +endif () #添加mov、flv库用于MP4录制 -if(ENABLE_MP4) +if (ENABLE_MP4) message(STATUS "ENABLE_MP4 defined") add_definitions(-DENABLE_MP4) @@ -153,39 +188,39 @@ if(ENABLE_MP4) include_directories(${MediaServer_Root}/libflv/include) aux_source_directory(${MediaServer_Root}/libmov/include src_mov) - aux_source_directory(${MediaServer_Root}/libmov/source src_mov) + aux_source_directory(${MediaServer_Root}/libmov/source src_mov) aux_source_directory(${MediaServer_Root}/libflv/include src_flv) - aux_source_directory(${MediaServer_Root}/libflv/source src_flv) + aux_source_directory(${MediaServer_Root}/libflv/source src_flv) add_library(mov STATIC ${src_mov}) - add_library(flv STATIC ${src_flv}) + add_library(flv STATIC ${src_flv}) list(APPEND LINK_LIB_LIST mov flv) list(APPEND CXX_API_TARGETS mov flv) - if(WIN32) - set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) - endif(WIN32) -endif() + if (WIN32) + set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS}) + endif (WIN32) +endif () #添加rtp库用于rtp转ps/ts -if(ENABLE_RTPPROXY AND ENABLE_HLS) +if (ENABLE_RTPPROXY AND ENABLE_HLS) message(STATUS "ENABLE_RTPPROXY defined") add_definitions(-DENABLE_RTPPROXY) -endif() +endif () #收集源代码 file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c) -if(IOS) +if (IOS) list(APPEND ToolKit_src_list ${ToolKit_Root}/Network/Socket_ios.mm) -endif() +endif () 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() +else () #防止Windows.h包含Winsock.h add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) endif () @@ -205,18 +240,18 @@ else () set(INSTALL_PATH_EXECUTABLE bin) endif () -if(ENABLE_CXX_API) +if (ENABLE_CXX_API) # 保留目录结构 - install(DIRECTORY ${ToolKit_Root}/ DESTINATION ${INSTALL_PATH_INCLUDE}/ZLToolKit REGEX "(.*[.](md|cpp)|win32)$" EXCLUDE) + install(DIRECTORY ${ToolKit_Root}/ DESTINATION ${INSTALL_PATH_INCLUDE}/ZLToolKit REGEX "(.*[.](md|cpp)|win32)$" EXCLUDE) install(DIRECTORY ${MediaKit_Root}/ DESTINATION ${INSTALL_PATH_INCLUDE}/ZLMediaKit REGEX ".*[.](md|cpp)$" EXCLUDE) install(TARGETS ${CXX_API_TARGETS} DESTINATION ${INSTALL_PATH_LIB}) -endif() +endif () if (WIN32) list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi) - set_target_properties(zltoolkit PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) - set_target_properties(zlmediakit PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) -elseif(NOT ANDROID OR IOS) + set_target_properties(zltoolkit PROPERTIES COMPILE_FLAGS ${VS_FALGS}) + set_target_properties(zlmediakit PROPERTIES COMPILE_FLAGS ${VS_FALGS}) +elseif (NOT ANDROID OR IOS) list(APPEND LINK_LIB_LIST pthread) endif () @@ -225,9 +260,9 @@ execute_process(COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/www ${EXECUTABLE_OUTPU execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/conf/config.ini ${EXECUTABLE_OUTPUT_PATH}/) #添加c库 -if(ENABLE_API) +if (ENABLE_API) add_subdirectory(api) -endif() +endif () if (ENABLE_WEBRTC) #查找srtp是否安装 @@ -249,11 +284,11 @@ endif () if (NOT IOS) #测试程序 - if(ENABLE_TESTS) + if (ENABLE_TESTS) add_subdirectory(tests) - endif() + endif () #主服务器 - if(ENABLE_SERVER) + if (ENABLE_SERVER) add_subdirectory(server) - endif() + endif () endif () diff --git a/conf/config.ini b/conf/config.ini index 3826090d..899e57b8 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -142,7 +142,7 @@ keepAliveSecond=30 #http请求体最大字节数,如果post的body太大,则不适合缓存body在内存 maxReqSize=40960 #404网页内容,用户可以自定义404网页 -notFound=404 Not Found

您访问的资源不存在!


ZLMediaKit-4.0
+#notFound=404 Not Found

您访问的资源不存在!


ZLMediaKit-4.0
#http服务器监听端口 port=80 #http文件服务器根目录 diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 8ae6ff28..37554d01 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,44 +1,7 @@ include_directories(../3rdpart) file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h ) add_library(jsoncpp STATIC ${jsoncpp_src_list}) - file(GLOB MediaServer_src_list ./*.cpp ./*.h) -#message(STATUS ${MediaServer_src_list}) - -# 添加git版本信息 -set(COMMIT_HASH "Git_NotFound_Unkown_commit") -set(BRANCH_NAME "Git_NotFound_Unkown_branch") -set(BUILD_TIME "") - -string(TIMESTAMP BUILD_TIME "%Y/%m/%d-%H:%M:%S") - -find_package(Git QUIET) -if(GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H - OUTPUT_VARIABLE COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../ - ) - execute_process( - COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD - OUTPUT_VARIABLE BRANCH_NAME - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../ - ) -endif() - -message(STATUS "Git version is ${BRANCH_NAME}:${COMMIT_HASH}:${BUILD_TIME}") - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini - ${CMAKE_BINARY_DIR}/Version.h - @ONLY -) -include_directories(${CMAKE_BINARY_DIR}) -add_definitions(-DENABLE_VERSION) add_executable(MediaServer ${MediaServer_src_list}) diff --git a/server/main.cpp b/server/main.cpp index 4bbf189f..e0e2bd67 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -154,9 +154,9 @@ public: (*_parser) << Option('v', "version", Option::ArgNone, nullptr, false, "显示版本号", [](const std::shared_ptr &stream, const string &arg) -> bool { //版本信息 - *stream << "编译日期: " << build_time << std::endl; - *stream << "当前git分支: " << branch_name << std::endl; - *stream << "当前git hash值: " << commit_hash << std::endl; + *stream << "编译日期: " << BUILD_TIME << std::endl; + *stream << "当前git分支: " << BRANCH_TIME << std::endl; + *stream << "当前git hash值: " << COMMIT_HASH << std::endl; throw ExitException(); }); #endif diff --git a/server/version.h.ini b/server/version.h.ini deleted file mode 100644 index 5d0b7e27..00000000 --- a/server/version.h.ini +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __GIT_VERSION_H__ -#define __GIT_VERSION_H__ - -#include - -const std::string commit_hash = "@COMMIT_HASH@"; -const std::string branch_name = "@BRANCH_NAME@"; -const std::string build_time = "@BUILD_TIME@"; - -#endif //__GIT_VERSION_H__ - diff --git a/src/Common/macros.h b/src/Common/macros.h index 8f3ead22..839e096b 100644 --- a/src/Common/macros.h +++ b/src/Common/macros.h @@ -11,6 +11,10 @@ #ifndef ZLMEDIAKIT_MACROS_H #define ZLMEDIAKIT_MACROS_H +#if defined(ENABLE_VERSION) +#include "Version.h" +#endif + #if defined(__MACH__) #include #include @@ -53,7 +57,13 @@ #define CLEAR_ARR(arr) for(auto &item : arr){ item = 0;} #endif //CLEAR_ARR -#define SERVER_NAME "ZLMediaKit-5.0(build in " __DATE__ " " __TIME__ ")" +//请遵循MIT协议,勿修改服务器声明 +#if !defined(ENABLE_VERSION) +#define SERVER_NAME "ZLMediaKit-6.0(build in " __DATE__ " " __TIME__ ")" +#else +#define SERVER_NAME "ZLMediaKit(git hash:" COMMIT_HASH ",branch:" BRANCH_TIME ",build time:" BUILD_TIME ")" +#endif + #define VHOST_KEY "vhost" #define HTTP_SCHEMA "http" #define RTSP_SCHEMA "rtsp" diff --git a/src/Rtmp/Rtmp.h b/src/Rtmp/Rtmp.h index 8f240953..5934a3cd 100644 --- a/src/Rtmp/Rtmp.h +++ b/src/Rtmp/Rtmp.h @@ -266,7 +266,7 @@ public: size_t fileSize = 0, const map &header = map()){ _metadata.set("duration", dur_sec); - _metadata.set("fileSize", 0); + _metadata.set("fileSize", (int)fileSize); _metadata.set("server",SERVER_NAME); for (auto &pr : header){ _metadata.set(pr.first, pr.second); diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index a510f240..045ee046 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -101,6 +101,7 @@ public: */ virtual void setMetaData(const AMFValue &metadata) { _metadata = metadata; + _metadata.set("server", SERVER_NAME); if (_ring) { regist(); } diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index 828a3de3..5783ce1d 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -141,11 +141,11 @@ public: * 设置sdp */ virtual void setSdp(const string &sdp) { - _sdp = sdp; SdpParser sdp_parser(sdp); _tracks[TrackVideo] = sdp_parser.getTrack(TrackVideo); _tracks[TrackAudio] = sdp_parser.getTrack(TrackAudio); _have_video = (bool) _tracks[TrackVideo]; + _sdp = sdp_parser.toString(); if (_ring) { regist(); } diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index e86eb399..dae2987f 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -257,7 +257,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { _push_src = std::make_shared(_media_info._vhost, _media_info._app, _media_info._streamid); _push_src->setListener(dynamic_pointer_cast(shared_from_this())); _push_src->setProtocolTranslation(enableHls, enableMP4); - _push_src->setSdp(sdpParser.toString()); + _push_src->setSdp(parser.Content()); sendRtspResponse("200 OK"); }; diff --git a/version.h.ini b/version.h.ini new file mode 100644 index 00000000..debf0207 --- /dev/null +++ b/version.h.ini @@ -0,0 +1,9 @@ +#ifndef __GIT_VERSION_H__ +#define __GIT_VERSION_H__ + +#define COMMIT_HASH "@COMMIT_HASH@" +#define BRANCH_TIME "@BRANCH_NAME@" +#define BUILD_TIME "@BUILD_TIME@" + +#endif //__GIT_VERSION_H__ + diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 4842db03..8b5930c3 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1043,7 +1043,6 @@ string RtcSession::toRtspSdp() const{ } } - copy.session_name = "zlmediakit rtsp stream from webrtc"; auto sdp = copy.toRtcSessionSdp(); toRtsp(sdp->items); int i = 0;