From d8d7fe9144fb3e17e19748859fac9a5bcecd15bb Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 28 Oct 2023 11:09:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87getMediaList=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=AF=E8=BF=94=E5=9B=9ETrack=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E5=A2=9E=E9=87=8F=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 1 + src/Extension/Frame.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 784782b9..5c63c943 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -370,6 +370,7 @@ Value makeMediaSourceJson(MediaSource &media){ obj["loss"] = loss; } obj["frames"] = track->getFrames(); + obj["duration"] = track->getDuration(); switch(codec_type){ case TrackAudio : { auto audio_track = dynamic_pointer_cast(track); diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index 3609ff41..a1b2b6dc 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -16,6 +16,7 @@ #include #include "Util/List.h" #include "Util/TimeTicker.h" +#include "Common/Stamp.h" #include "Network/Buffer.h" namespace mediakit { @@ -361,11 +362,18 @@ public: return _gop_interval_ms; } + int64_t getDuration() const { + std::lock_guard lck(_mtx); + return _stamp.getRelativeStamp(); + } + private: void doStatistics(const Frame::Ptr &frame) { if (!frame->configFrame() && !frame->dropAble()) { // 忽略配置帧与可丢弃的帧 ++_frames; + int64_t out; + _stamp.revise(frame->dts(), frame->pts(), out, out); if (frame->keyFrame() && frame->getTrackType() == TrackVideo) { // 遇视频关键帧时统计 ++_video_key_frames; @@ -384,6 +392,7 @@ private: uint64_t _last_frames = 0; uint64_t _frames = 0; uint64_t _video_key_frames = 0; + Stamp _stamp; mutable std::recursive_mutex _mtx; std::map _delegates; };