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

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

@ -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")

View File

@ -142,7 +142,7 @@ keepAliveSecond=30
#http请求体最大字节数如果post的body太大则不适合缓存body在内存
maxReqSize=40960
#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服务器监听端口
port=80
#http文件服务器根目录

View File

@ -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})

View File

@ -154,9 +154,9 @@ public:
(*_parser) << Option('v', "version", Option::ArgNone, nullptr, false, "显示版本号",
[](const std::shared_ptr<ostream> &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

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
#define ZLMEDIAKIT_MACROS_H
#if defined(ENABLE_VERSION)
#include "Version.h"
#endif
#if defined(__MACH__)
#include <arpa/inet.h>
#include <machine/endian.h>
@ -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"

View File

@ -266,7 +266,7 @@ public:
size_t fileSize = 0,
const map<string,string> &header = map<string,string>()){
_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);

View File

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

View File

@ -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();
}

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->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
_push_src->setProtocolTranslation(enableHls, enableMP4);
_push_src->setSdp(sdpParser.toString());
_push_src->setSdp(parser.Content());
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();
toRtsp(sdp->items);
int i = 0;