From 6eb36ec88389cc6a081d7e79d5cb3697658e539d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 5 Feb 2023 22:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96MediaSource=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=B8=A7?= =?UTF-8?q?=E6=95=B0=E7=9B=B8=E5=85=B3=E5=AD=97=E6=AE=B5=EF=BC=9A#1570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 2 ++ src/Extension/Frame.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 217ff4d9..4c9063ce 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -365,6 +365,7 @@ Value makeMediaSourceJson(MediaSource &media){ } obj["loss"] = loss; } + obj["frames"] = track->getFrames(); switch(codec_type){ case TrackAudio : { auto audio_track = dynamic_pointer_cast(track); @@ -378,6 +379,7 @@ Value makeMediaSourceJson(MediaSource &media){ obj["width"] = video_track->getVideoWidth(); obj["height"] = video_track->getVideoHeight(); obj["fps"] = round(video_track->getVideoFps()); + obj["key_frames"] = video_track->getVideoKeyFrames(); break; } default: diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index 0f95a780..6060c355 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -311,6 +311,10 @@ public: */ bool inputFrame(const Frame::Ptr &frame) override { std::lock_guard lck(_mtx); + ++_frames; + if (frame->keyFrame() && frame->getTrackType() == TrackVideo) { + ++_video_key_frames; + } bool ret = false; for (auto &pr : _delegates) { if (pr.second->inputFrame(frame)) { @@ -333,7 +337,25 @@ public: _delegates.clear(); } + /** + * 获取累计关键帧数 + */ + uint64_t getVideoKeyFrames() const { + std::lock_guard lck(_mtx); + return _video_key_frames; + } + + /** + * 获取帧数 + */ + uint64_t getFrames() const { + std::lock_guard lck(_mtx); + return _frames; + } + private: + uint64_t _frames = 0; + uint64_t _video_key_frames = 0; mutable std::mutex _mtx; std::map _delegates; };