Skip to content

Commit

Permalink
收集FFMPEG相关的对象计数
Browse files Browse the repository at this point in the history
  • Loading branch information
cqm committed Jan 18, 2024
1 parent c3d1270 commit 2e86a94
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/FFmpegSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions server/FFmpegSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class FFmpegSource : public std::enable_shared_from_this<FFmpegSource> , public
std::string _ffmpeg_cmd_key;
std::function<void()> _onClose;
toolkit::Ticker _replay_ticker;
toolkit::ObjectStatistic<FFmpegSource> _counter;
};


Expand Down
13 changes: 12 additions & 1 deletion server/WebApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -480,6 +480,17 @@ void getStatisticJson(const function<void(Value &val)> &cb) {

val["RtpPacket"] = (Json::UInt64)(ObjectStatistic<RtpPacket>::count());
val["RtmpPacket"] = (Json::UInt64)(ObjectStatistic<RtmpPacket>::count());

val["FFmpegSource"] = (Json::UInt64)(ObjectStatistic<FFmpegSource>::count());
#ifdef ENABLE_FFMPEG
val["FFmpegFrame"] = (Json::UInt64)(ObjectStatistic<FFmpegFrame>::count());
val["FFmpegSwr"] = (Json::UInt64)(ObjectStatistic<FFmpegSwr>::count());
val["FFmpegSws"] = (Json::UInt64)(ObjectStatistic<FFmpegSws>::count());
val["FFmpegAudioFifo"] = (Json::UInt64)(ObjectStatistic<FFmpegAudioFifo>::count());
val["FFmpegDecoder"] = (Json::UInt64)(ObjectStatistic<FFmpegDecoder>::count());
val["FFmpegEncoder"] = (Json::UInt64)(ObjectStatistic<FFmpegEncoder>::count());
#endif // ENABLE_FFMPEG

#ifdef ENABLE_MEM_DEBUG
auto bytes = getTotalMemUsage();
val["totalMemUsage"] = (Json::UInt64) bytes;
Expand Down
6 changes: 6 additions & 0 deletions src/Codec/Transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// 配置项目
Expand Down
7 changes: 6 additions & 1 deletion src/Codec/Transcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define ZLMEDIAKIT_TRANSCODE_H

#if defined(ENABLE_FFMPEG)

#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Common/MediaSink.h"

Expand Down Expand Up @@ -45,6 +45,7 @@ class FFmpegFrame {
private:
char *_data = nullptr;
std::shared_ptr<AVFrame> _frame;
toolkit::ObjectStatistic<FFmpegFrame> _counter;
};

class FFmpegSwr {
Expand All @@ -61,6 +62,7 @@ class FFmpegSwr {
int _target_samplerate;
AVSampleFormat _target_format;
SwrContext *_ctx = nullptr;
toolkit::ObjectStatistic<FFmpegSwr> _statistic;
};

class FFmpegAudioFifo {
Expand Down Expand Up @@ -143,6 +145,7 @@ class FFmpegDecoder : public TaskManager, public CodecInfo {
onDec _cb;
std::shared_ptr<AVCodecContext> _context;
FrameMerger _merger{FrameMerger::h264_prefix};
toolkit::ObjectStatistic<FFmpegDecoder> _counter;
};

class FFmpegSws {
Expand All @@ -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<FFmpegSws> _counter;
};

class FFmpegEncoder : public TaskManager, public CodecInfo {
Expand Down Expand Up @@ -196,6 +200,7 @@ class FFmpegEncoder : public TaskManager, public CodecInfo {
std::unique_ptr<FFmpegSws> _sws;
std::unique_ptr<FFmpegSwr> _swr;
std::unique_ptr<FFmpegAudioFifo> _fifo;
toolkit::ObjectStatistic<FFmpegEncoder> _counter;
};
}//namespace mediakit
#endif// ENABLE_FFMPEG
Expand Down

0 comments on commit 2e86a94

Please sign in to comment.