From 2e86a941c3f2bff936acb808f208be82af96329a Mon Sep 17 00:00:00 2001 From: cqm Date: Thu, 18 Jan 2024 14:22:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=9B=86FFMPEG=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E8=B1=A1=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/FFmpegSource.cpp | 2 +- server/FFmpegSource.h | 1 + server/WebApi.cpp | 13 ++++++++++++- src/Codec/Transcode.cpp | 6 ++++++ src/Codec/Transcode.h | 7 ++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 511a7e566f..1965c8ea67 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -20,7 +20,7 @@ using namespace std; using namespace toolkit; using namespace mediakit; - +StatisticImp(FFmpegSource); namespace FFmpeg { #define FFmpeg_FIELD "ffmpeg." const string kBin = FFmpeg_FIELD"bin"; diff --git a/server/FFmpegSource.h b/server/FFmpegSource.h index 067e2e83ac..10bd5fc725 100644 --- a/server/FFmpegSource.h +++ b/server/FFmpegSource.h @@ -93,6 +93,7 @@ class FFmpegSource : public std::enable_shared_from_this , public std::string _ffmpeg_cmd_key; std::function _onClose; toolkit::Ticker _replay_ticker; + toolkit::ObjectStatistic _counter; }; diff --git a/server/WebApi.cpp b/server/WebApi.cpp index aa3df33728..14a0533c37 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -29,7 +29,7 @@ #include "Network/TcpServer.h" #include "Network/UdpServer.h" #include "Thread/WorkThreadPool.h" - +#include "Codec/Transcode.h" #ifdef ENABLE_MYSQL #include "Util/SqlPool.h" #endif //ENABLE_MYSQL @@ -480,6 +480,17 @@ void getStatisticJson(const function &cb) { val["RtpPacket"] = (Json::UInt64)(ObjectStatistic::count()); val["RtmpPacket"] = (Json::UInt64)(ObjectStatistic::count()); + + val["FFmpegSource"] = (Json::UInt64)(ObjectStatistic::count()); +#ifdef ENABLE_FFMPEG + val["FFmpegFrame"] = (Json::UInt64)(ObjectStatistic::count()); + val["FFmpegSwr"] = (Json::UInt64)(ObjectStatistic::count()); + val["FFmpegSws"] = (Json::UInt64)(ObjectStatistic::count()); + val["FFmpegAudioFifo"] = (Json::UInt64)(ObjectStatistic::count()); + val["FFmpegDecoder"] = (Json::UInt64)(ObjectStatistic::count()); + val["FFmpegEncoder"] = (Json::UInt64)(ObjectStatistic::count()); +#endif // ENABLE_FFMPEG + #ifdef ENABLE_MEM_DEBUG auto bytes = getTotalMemUsage(); val["totalMemUsage"] = (Json::UInt64) bytes; diff --git a/src/Codec/Transcode.cpp b/src/Codec/Transcode.cpp index 99a0ba2b30..7a917273ca 100644 --- a/src/Codec/Transcode.cpp +++ b/src/Codec/Transcode.cpp @@ -24,6 +24,12 @@ using namespace std; using namespace toolkit; +StatisticImp(mediakit::FFmpegFrame); +StatisticImp(mediakit::FFmpegSwr); +StatisticImp(mediakit::FFmpegSws); +StatisticImp(mediakit::FFmpegAudioFifo); +StatisticImp(mediakit::FFmpegDecoder); +StatisticImp(mediakit::FFmpegEncoder); namespace mediakit { // 配置项目 diff --git a/src/Codec/Transcode.h b/src/Codec/Transcode.h index c99a117b66..e8c8b17c1e 100644 --- a/src/Codec/Transcode.h +++ b/src/Codec/Transcode.h @@ -12,7 +12,7 @@ #define ZLMEDIAKIT_TRANSCODE_H #if defined(ENABLE_FFMPEG) - +#include "Util/util.h" #include "Util/TimeTicker.h" #include "Common/MediaSink.h" @@ -45,6 +45,7 @@ class FFmpegFrame { private: char *_data = nullptr; std::shared_ptr _frame; + toolkit::ObjectStatistic _counter; }; class FFmpegSwr { @@ -61,6 +62,7 @@ class FFmpegSwr { int _target_samplerate; AVSampleFormat _target_format; SwrContext *_ctx = nullptr; + toolkit::ObjectStatistic _statistic; }; class FFmpegAudioFifo { @@ -143,6 +145,7 @@ class FFmpegDecoder : public TaskManager, public CodecInfo { onDec _cb; std::shared_ptr _context; FrameMerger _merger{FrameMerger::h264_prefix}; + toolkit::ObjectStatistic _counter; }; class FFmpegSws { @@ -165,6 +168,7 @@ class FFmpegSws { SwsContext *_ctx = nullptr; AVPixelFormat _src_format = AV_PIX_FMT_NONE; AVPixelFormat _target_format = AV_PIX_FMT_NONE; + toolkit::ObjectStatistic _counter; }; class FFmpegEncoder : public TaskManager, public CodecInfo { @@ -196,6 +200,7 @@ class FFmpegEncoder : public TaskManager, public CodecInfo { std::unique_ptr _sws; std::unique_ptr _swr; std::unique_ptr _fifo; + toolkit::ObjectStatistic _counter; }; }//namespace mediakit #endif// ENABLE_FFMPEG