修改服务器版本信息声明相关代码

This commit is contained in:
ziyue 2021-06-29 11:16:05 +08:00
parent dfbfd65ab3
commit 3165a2f81c
12 changed files with 102 additions and 96 deletions

View File

@ -7,13 +7,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
#set(CMAKE_BUILD_TYPE "Release") #set(CMAKE_BUILD_TYPE "Release")
if(${CMAKE_BUILD_TYPE} MATCHES "Release") if (${CMAKE_BUILD_TYPE} MATCHES "Release")
message(STATUS "Release版本") message(STATUS "Release版本")
set(BuildType "Release") set(BuildType "Release")
else() else ()
set(BuildType "Debug") set(BuildType "Debug")
message(STATUS "Debug版本") message(STATUS "Debug版本")
endif() endif ()
#binlib #binlib
set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release) 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_ASAN "Enable Address Sanitize" false)
option(ENABLE_WEBRTC "Enable WebRTC" 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) 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_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") 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 #jemalloc
find_package(JEMALLOC QUIET) find_package(JEMALLOC QUIET)
if(JEMALLOC_FOUND) if (JEMALLOC_FOUND)
message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"") message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"")
include_directories(${JEMALLOC_INCLUDE_DIR}) include_directories(${JEMALLOC_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES}) list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES})
endif() endif ()
#openssl #openssl
find_package(OpenSSL QUIET) find_package(OpenSSL QUIET)
@ -89,9 +124,9 @@ if (OPENSSL_FOUND AND ENABLE_OPENSSL)
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES}) list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS) if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
list(APPEND LINK_LIB_LIST dl) list(APPEND LINK_LIB_LIST dl)
endif() endif ()
else() else ()
message(WARNING "openssl未找到rtmp将不支持flash播放器https/wss/rtsps/rtmps也将失效") message(WARNING "openssl未找到rtmp将不支持flash播放器https/wss/rtsps/rtmps也将失效")
endif () endif ()
@ -124,10 +159,10 @@ if (FAAC_FOUND AND ENABLE_FAAC)
endif () endif ()
#set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" ) #set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" )
set(VS_FALGS "/wd4819" ) set(VS_FALGS "/wd4819")
#mpegts #mpegts
if(ENABLE_HLS) if (ENABLE_HLS)
message(STATUS "ENABLE_HLS defined") message(STATUS "ENABLE_HLS defined")
add_definitions(-DENABLE_HLS) add_definitions(-DENABLE_HLS)
@ -139,13 +174,13 @@ if(ENABLE_HLS)
list(APPEND LINK_LIB_LIST mpeg) list(APPEND LINK_LIB_LIST mpeg)
list(APPEND CXX_API_TARGETS mpeg) list(APPEND CXX_API_TARGETS mpeg)
if(WIN32) if (WIN32)
set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS})
endif(WIN32) endif (WIN32)
endif() endif ()
#movflvMP4 #movflvMP4
if(ENABLE_MP4) if (ENABLE_MP4)
message(STATUS "ENABLE_MP4 defined") message(STATUS "ENABLE_MP4 defined")
add_definitions(-DENABLE_MP4) add_definitions(-DENABLE_MP4)
@ -163,29 +198,29 @@ if(ENABLE_MP4)
list(APPEND LINK_LIB_LIST mov flv) list(APPEND LINK_LIB_LIST mov flv)
list(APPEND CXX_API_TARGETS mov flv) list(APPEND CXX_API_TARGETS mov flv)
if(WIN32) if (WIN32)
set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS})
endif(WIN32) endif (WIN32)
endif() endif ()
#rtprtpps/ts #rtprtpps/ts
if(ENABLE_RTPPROXY AND ENABLE_HLS) if (ENABLE_RTPPROXY AND ENABLE_HLS)
message(STATUS "ENABLE_RTPPROXY defined") message(STATUS "ENABLE_RTPPROXY defined")
add_definitions(-DENABLE_RTPPROXY) add_definitions(-DENABLE_RTPPROXY)
endif() endif ()
# #
file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c) 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) 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) file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c)
#win32 #win32
if (NOT WIN32) if (NOT WIN32)
list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c) list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c)
else() else ()
#Windows.hWinsock.h #Windows.hWinsock.h
add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif () endif ()
@ -205,18 +240,18 @@ else ()
set(INSTALL_PATH_EXECUTABLE bin) set(INSTALL_PATH_EXECUTABLE bin)
endif () 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(DIRECTORY ${MediaKit_Root}/ DESTINATION ${INSTALL_PATH_INCLUDE}/ZLMediaKit REGEX ".*[.](md|cpp)$" EXCLUDE)
install(TARGETS ${CXX_API_TARGETS} DESTINATION ${INSTALL_PATH_LIB}) install(TARGETS ${CXX_API_TARGETS} DESTINATION ${INSTALL_PATH_LIB})
endif() endif ()
if (WIN32) if (WIN32)
list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi) list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi)
set_target_properties(zltoolkit PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) set_target_properties(zltoolkit PROPERTIES COMPILE_FLAGS ${VS_FALGS})
set_target_properties(zlmediakit PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) set_target_properties(zlmediakit PROPERTIES COMPILE_FLAGS ${VS_FALGS})
elseif(NOT ANDROID OR IOS) elseif (NOT ANDROID OR IOS)
list(APPEND LINK_LIB_LIST pthread) list(APPEND LINK_LIB_LIST pthread)
endif () 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}/) execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/conf/config.ini ${EXECUTABLE_OUTPUT_PATH}/)
#c #c
if(ENABLE_API) if (ENABLE_API)
add_subdirectory(api) add_subdirectory(api)
endif() endif ()
if (ENABLE_WEBRTC) if (ENABLE_WEBRTC)
#srtp #srtp
@ -249,11 +284,11 @@ endif ()
if (NOT IOS) if (NOT IOS)
# #
if(ENABLE_TESTS) if (ENABLE_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif ()
# #
if(ENABLE_SERVER) if (ENABLE_SERVER)
add_subdirectory(server) add_subdirectory(server)
endif() endif ()
endif () endif ()

View File

@ -142,7 +142,7 @@ keepAliveSecond=30
#http请求体最大字节数如果post的body太大则不适合缓存body在内存 #http请求体最大字节数如果post的body太大则不适合缓存body在内存
maxReqSize=40960 maxReqSize=40960
#404网页内容用户可以自定义404网页 #404网页内容用户可以自定义404网页
notFound=<html><head><title>404 Not Found</title></head><body bgcolor="white"><center><h1>您访问的资源不存在!</h1></center><hr><center>ZLMediaKit-4.0</center></body></html> #notFound=<html><head><title>404 Not Found</title></head><body bgcolor="white"><center><h1>您访问的资源不存在!</h1></center><hr><center>ZLMediaKit-4.0</center></body></html>
#http服务器监听端口 #http服务器监听端口
port=80 port=80
#http文件服务器根目录 #http文件服务器根目录

View File

@ -1,44 +1,7 @@
include_directories(../3rdpart) include_directories(../3rdpart)
file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h ) file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h )
add_library(jsoncpp STATIC ${jsoncpp_src_list}) add_library(jsoncpp STATIC ${jsoncpp_src_list})
file(GLOB MediaServer_src_list ./*.cpp ./*.h) 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}) add_executable(MediaServer ${MediaServer_src_list})

View File

@ -154,9 +154,9 @@ public:
(*_parser) << Option('v', "version", Option::ArgNone, nullptr, false, "显示版本号", (*_parser) << Option('v', "version", Option::ArgNone, nullptr, false, "显示版本号",
[](const std::shared_ptr<ostream> &stream, const string &arg) -> bool { [](const std::shared_ptr<ostream> &stream, const string &arg) -> bool {
//版本信息 //版本信息
*stream << "编译日期: " << build_time << std::endl; *stream << "编译日期: " << BUILD_TIME << std::endl;
*stream << "当前git分支: " << branch_name << std::endl; *stream << "当前git分支: " << BRANCH_TIME << std::endl;
*stream << "当前git hash值: " << commit_hash << std::endl; *stream << "当前git hash值: " << COMMIT_HASH << std::endl;
throw ExitException(); throw ExitException();
}); });
#endif #endif

View File

@ -1,11 +0,0 @@
#ifndef __GIT_VERSION_H__
#define __GIT_VERSION_H__
#include <string>
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__

View File

@ -11,6 +11,10 @@
#ifndef ZLMEDIAKIT_MACROS_H #ifndef ZLMEDIAKIT_MACROS_H
#define ZLMEDIAKIT_MACROS_H #define ZLMEDIAKIT_MACROS_H
#if defined(ENABLE_VERSION)
#include "Version.h"
#endif
#if defined(__MACH__) #if defined(__MACH__)
#include <arpa/inet.h> #include <arpa/inet.h>
#include <machine/endian.h> #include <machine/endian.h>
@ -53,7 +57,13 @@
#define CLEAR_ARR(arr) for(auto &item : arr){ item = 0;} #define CLEAR_ARR(arr) for(auto &item : arr){ item = 0;}
#endif //CLEAR_ARR #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 VHOST_KEY "vhost"
#define HTTP_SCHEMA "http" #define HTTP_SCHEMA "http"
#define RTSP_SCHEMA "rtsp" #define RTSP_SCHEMA "rtsp"

View File

@ -266,7 +266,7 @@ public:
size_t fileSize = 0, size_t fileSize = 0,
const map<string,string> &header = map<string,string>()){ const map<string,string> &header = map<string,string>()){
_metadata.set("duration", dur_sec); _metadata.set("duration", dur_sec);
_metadata.set("fileSize", 0); _metadata.set("fileSize", (int)fileSize);
_metadata.set("server",SERVER_NAME); _metadata.set("server",SERVER_NAME);
for (auto &pr : header){ for (auto &pr : header){
_metadata.set(pr.first, pr.second); _metadata.set(pr.first, pr.second);

View File

@ -101,6 +101,7 @@ public:
*/ */
virtual void setMetaData(const AMFValue &metadata) { virtual void setMetaData(const AMFValue &metadata) {
_metadata = metadata; _metadata = metadata;
_metadata.set("server", SERVER_NAME);
if (_ring) { if (_ring) {
regist(); regist();
} }

View File

@ -141,11 +141,11 @@ public:
* sdp * sdp
*/ */
virtual void setSdp(const string &sdp) { virtual void setSdp(const string &sdp) {
_sdp = sdp;
SdpParser sdp_parser(sdp); SdpParser sdp_parser(sdp);
_tracks[TrackVideo] = sdp_parser.getTrack(TrackVideo); _tracks[TrackVideo] = sdp_parser.getTrack(TrackVideo);
_tracks[TrackAudio] = sdp_parser.getTrack(TrackAudio); _tracks[TrackAudio] = sdp_parser.getTrack(TrackAudio);
_have_video = (bool) _tracks[TrackVideo]; _have_video = (bool) _tracks[TrackVideo];
_sdp = sdp_parser.toString();
if (_ring) { if (_ring) {
regist(); regist();
} }

View File

@ -257,7 +257,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
_push_src = std::make_shared<RtspMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid); _push_src = std::make_shared<RtspMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
_push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this())); _push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
_push_src->setProtocolTranslation(enableHls, enableMP4); _push_src->setProtocolTranslation(enableHls, enableMP4);
_push_src->setSdp(sdpParser.toString()); _push_src->setSdp(parser.Content());
sendRtspResponse("200 OK"); sendRtspResponse("200 OK");
}; };

9
version.h.ini Normal file
View File

@ -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__

View File

@ -1043,7 +1043,6 @@ string RtcSession::toRtspSdp() const{
} }
} }
copy.session_name = "zlmediakit rtsp stream from webrtc";
auto sdp = copy.toRtcSessionSdp(); auto sdp = copy.toRtcSessionSdp();
toRtsp(sdp->items); toRtsp(sdp->items);
int i = 0; int i = 0;