From 47f2f5b349d0b9a3e28da0b7eeafb4cb5d711da7 Mon Sep 17 00:00:00 2001 From: monktan Date: Tue, 29 Dec 2020 11:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91unsport=20code=E6=89=93?= =?UTF-8?q?=E5=8D=B0=EF=BC=8C=E6=96=B0=E5=A2=9Egit=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ server/main.cpp | 13 +++++++++++++ src/Rtp/Decoder.cpp | 5 ++++- src/Rtp/Decoder.h | 1 + version.h.ini | 11 +++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 version.h.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index aec266ac..9c160617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,40 @@ else() message(STATUS "Debug版本") endif() +# 添加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}) + #设置bin和lib库目录 set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release) if (CMAKE_SYSTEM_NAME MATCHES "Linux") diff --git a/server/main.cpp b/server/main.cpp index 1b7e6f41..5baa7003 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -27,6 +27,7 @@ #include "Rtp/RtpServer.h" #include "WebApi.h" #include "WebHook.h" +#include "Version.h" #if !defined(_WIN32) #include "System.h" @@ -154,6 +155,18 @@ public: false,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/ "MediaServerId自定义值",/*该选项说明文字*/ nullptr); + (*_parser) << Option('v', "version", Option::ArgNone, nullptr ,false, "显示版本号", + [this](const std::shared_ptr &stream, const string &arg){ + //版本信息 + *stream << "当前版本信息:" << std::endl; + *stream << "编译日期: " << build_time << std::endl; + *stream << "当前git分支: " << branch_name << std::endl; + *stream << "当前git hash值: " << commit_hash << std::endl; + stringstream ss; + ss << "\n输入\"-h\"选项获取更详细帮助"; + throw std::invalid_argument(ss.str()); + return false; + }); } virtual ~CMD_main() {} diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index 35a6663d..95f67dc5 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -216,7 +216,10 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d default: if(codecid != 0){ - WarnL<< "unsupported codec type:" << getCodecName(codecid) << " " << (int)codecid; + if(_last_unsported_print.elapsedTime()/1000 > 5){ + _last_unsported_print.resetTime(); + WarnL<< "unsupported codec type:" << getCodecName(codecid) << " " << (int)codecid; + } } break; } diff --git a/src/Rtp/Decoder.h b/src/Rtp/Decoder.h index 6234a876..3340a2b9 100644 --- a/src/Rtp/Decoder.h +++ b/src/Rtp/Decoder.h @@ -72,6 +72,7 @@ private: Decoder::Ptr _decoder; MediaSinkInterface *_sink; FrameMerger _merger; + Ticker _last_unsported_print; }; }//namespace mediakit diff --git a/version.h.ini b/version.h.ini new file mode 100644 index 00000000..5d0b7e27 --- /dev/null +++ b/version.h.ini @@ -0,0 +1,11 @@ +#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__ +