diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 64a61db7..6a21c58f 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 64a61db77b1adeada5e6229b83fec655b1cc09bc +Subproject commit 6a21c58fa2e21416306c5a9cc88f943b882253e6 diff --git a/postman/ZLMediaKit.postman_collection.json b/postman/ZLMediaKit.postman_collection.json index 25dda654..a06d22fb 100644 --- a/postman/ZLMediaKit.postman_collection.json +++ b/postman/ZLMediaKit.postman_collection.json @@ -58,6 +58,32 @@ }, "response": [] }, + { + "name": "获取主要对象个数(getStatistic)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{ZLMediaKit_URL}}/index/api/getStatistic?secret={{ZLMediaKit_secret}}", + "host": [ + "{{ZLMediaKit_URL}}" + ], + "path": [ + "index", + "api", + "getStatistic" + ], + "query": [ + { + "key": "secret", + "value": "{{ZLMediaKit_secret}}", + "description": "api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数" + } + ] + } + }, + "response": [] + }, { "name": "获取后台线程负载(getWorkThreadsLoad)", "request": { @@ -568,6 +594,12 @@ "key": "enable_mp4", "value": "0", "description": "是否开启mp4录制" + }, + { + "key": "ffmpeg_cmd_key", + "value": "ffmpeg.cmd_hd", + "description": "FFmpeg命名参数模板,置空则采用配置项:ffmpeg.cmd", + "disabled": true } ] } diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 5e431161..169cad41 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1026,6 +1026,24 @@ void installWebApi() { }); }); + api_regist("/index/api/getStatistic",[](API_ARGS_MAP){ + CHECK_SECRET(); + val["data"]["MediaSource"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["MultiMediaSourceMuxer"] = (Json::UInt64)(ObjectStatistic::count()); + + val["data"]["TcpSession"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["TcpClient"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["Socket"] = (Json::UInt64)(ObjectStatistic::count()); + + val["data"]["FrameImp"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["Frame"] = (Json::UInt64)(ObjectStatistic::count()); + + val["data"]["Buffer"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["BufferRaw"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["BufferLikeString"] = (Json::UInt64)(ObjectStatistic::count()); + val["data"]["BufferList"] = (Json::UInt64)(ObjectStatistic::count()); + }); + ////////////以下是注册的Hook API//////////// api_regist("/index/hook/on_publish",[](API_ARGS_MAP){ //开始推流事件 diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index f46122f2..28d13ccd 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -14,6 +14,11 @@ #include "Network/sockutil.h" #include "Network/TcpSession.h" using namespace toolkit; + +namespace toolkit { + StatisticImp(mediakit::MediaSource); +} + namespace mediakit { recursive_mutex s_media_source_mtx; diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index dd5308da..029b5f87 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -296,6 +296,8 @@ private: string _app; string _stream_id; std::weak_ptr _listener; + //对象个数统计 + ObjectStatistic _statistic; }; ///缓存刷新策略类 diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index cbd87b26..f176e88e 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -11,6 +11,11 @@ #include #include "Common/config.h" #include "MultiMediaSourceMuxer.h" + +namespace toolkit { + StatisticImp(mediakit::MultiMediaSourceMuxer); +} + namespace mediakit { ///////////////////////////////MultiMuxerPrivate////////////////////////////////// diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index a2caacf3..422c9e30 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -192,6 +192,8 @@ private: mutex _rtp_sender_mtx; unordered_map _rtp_sender; #endif //ENABLE_RTPPROXY + //对象个数统计 + ObjectStatistic _statistic; }; }//namespace mediakit diff --git a/src/Extension/Frame.cpp b/src/Extension/Frame.cpp index ba8a6a9d..ec5bb3b6 100644 --- a/src/Extension/Frame.cpp +++ b/src/Extension/Frame.cpp @@ -13,6 +13,11 @@ using namespace std; using namespace toolkit; +namespace toolkit { + StatisticImp(mediakit::Frame); + StatisticImp(mediakit::FrameImp); +} + namespace mediakit{ /** diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index b9628698..e7b87035 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -122,6 +122,10 @@ public: * 返回可缓存的frame */ static Ptr getCacheAbleFrame(const Ptr &frame); + +private: + //对象个数统计 + ObjectStatistic _statistic; }; class FrameImp : public Frame { @@ -166,6 +170,8 @@ public: uint32_t _pts = 0; size_t _prefix_size = 0; BufferLikeString _buffer; + //对象个数统计 + ObjectStatistic _statistic; }; /**