Skip to content

Commit

Permalink
通过getMediaList接口可返回Track时间戳增量信息
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-chu committed Oct 31, 2023
1 parent c1b8296 commit d8d7fe9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/WebApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioTrack>(track);
Expand Down
9 changes: 9 additions & 0 deletions src/Extension/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <functional>
#include "Util/List.h"
#include "Util/TimeTicker.h"
#include "Common/Stamp.h"
#include "Network/Buffer.h"

namespace mediakit {
Expand Down Expand Up @@ -361,11 +362,18 @@ class FrameDispatcher : public FrameWriterInterface {
return _gop_interval_ms;
}

int64_t getDuration() const {
std::lock_guard<std::recursive_mutex> 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;
Expand All @@ -384,6 +392,7 @@ class FrameDispatcher : public FrameWriterInterface {
uint64_t _last_frames = 0;
uint64_t _frames = 0;
uint64_t _video_key_frames = 0;
Stamp _stamp;
mutable std::recursive_mutex _mtx;
std::map<void *, FrameWriterInterface::Ptr> _delegates;
};
Expand Down

0 comments on commit d8d7fe9

Please sign in to comment.