增加平均fps统计
This commit is contained in:
parent
88dc59ec68
commit
a78ca2ea5b
|
|
@ -334,6 +334,7 @@ Value makeMediaSourceJson(MediaSource &media){
|
|||
item["createStamp"] = (Json::UInt64) media.getCreateStamp();
|
||||
item["aliveSecond"] = (Json::UInt64) media.getAliveSecond();
|
||||
item["bytesSpeed"] = media.getBytesSpeed();
|
||||
item["avgFps"] = media.getAvgFps();
|
||||
item["readerCount"] = media.readerCount();
|
||||
item["totalReaderCount"] = media.totalReaderCount();
|
||||
item["originType"] = (int) media.getOriginType();
|
||||
|
|
|
|||
|
|
@ -159,6 +159,10 @@ int MediaSource::getBytesSpeed(TrackType type){
|
|||
return _speed[type].getSpeed();
|
||||
}
|
||||
|
||||
int MediaSource::getAvgFps() {
|
||||
return getMuxer()->getAvgFps();
|
||||
}
|
||||
|
||||
uint64_t MediaSource::getAliveSecond() const {
|
||||
//使用Ticker对象获取存活时间的目的是防止修改系统时间导致回退
|
||||
return _ticker.createdTime() / 1000;
|
||||
|
|
|
|||
|
|
@ -299,6 +299,38 @@ public:
|
|||
|
||||
bool equalMediaTuple(const MediaTuple& a, const MediaTuple& b);
|
||||
|
||||
class FrameFps {
|
||||
public:
|
||||
FrameFps() = default;
|
||||
~FrameFps() = default;
|
||||
|
||||
void inputFrame() {
|
||||
++frameCount;
|
||||
|
||||
}
|
||||
int getDynamicFPS() {
|
||||
if (_ticker.elapsedTime() < 1000) {
|
||||
//获取频率小于1秒,那么返回上次计算结果
|
||||
return _fps;
|
||||
}
|
||||
return computeFps();
|
||||
}
|
||||
private:
|
||||
int computeFps() {
|
||||
auto elapsed = _ticker.elapsedTime();
|
||||
if (!elapsed) {
|
||||
return _fps;
|
||||
}
|
||||
_fps = (int)(frameCount * 1000 / elapsed);
|
||||
_ticker.resetTime();
|
||||
frameCount = 0;
|
||||
return _fps;
|
||||
}
|
||||
private:
|
||||
long frameCount = 0;
|
||||
int _fps = 0;
|
||||
toolkit::Ticker _ticker;
|
||||
};
|
||||
/**
|
||||
* 媒体源,任何rtsp/rtmp的直播流都源自该对象
|
||||
*/
|
||||
|
|
@ -340,7 +372,8 @@ public:
|
|||
uint64_t getCreateStamp() const { return _create_stamp; }
|
||||
// 获取流上线时间,单位秒
|
||||
uint64_t getAliveSecond() const;
|
||||
|
||||
// 获取平均fps
|
||||
int getAvgFps();
|
||||
////////////////MediaSourceEvent相关接口实现////////////////
|
||||
|
||||
// 设置监听者
|
||||
|
|
|
|||
|
|
@ -539,6 +539,9 @@ bool MultiMediaSourceMuxer::onTrackFrame(const Frame::Ptr &frame_in) {
|
|||
_ring->write(frame, !haveVideo());
|
||||
}
|
||||
}
|
||||
if(frame->getTrackType()==TrackVideo && !frame->dropAble()){
|
||||
_dynamicFPS.inputFrame();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -564,4 +567,8 @@ bool MultiMediaSourceMuxer::isEnabled(){
|
|||
return _is_enable;
|
||||
}
|
||||
|
||||
int MultiMediaSourceMuxer::getAvgFps() {
|
||||
return _dynamicFPS.getDynamicFPS();
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ public:
|
|||
const ProtocolOption &getOption() const;
|
||||
const MediaTuple &getMediaTuple() const;
|
||||
std::string shortUrl() const;
|
||||
|
||||
// 获取平均fps
|
||||
int getAvgFps();
|
||||
protected:
|
||||
/////////////////////////////////MediaSink override/////////////////////////////////
|
||||
|
||||
|
|
@ -178,7 +179,7 @@ private:
|
|||
HlsFMP4Recorder::Ptr _hls_fmp4;
|
||||
toolkit::EventPoller::Ptr _poller;
|
||||
RingType::Ptr _ring;
|
||||
|
||||
FrameFps _dynamicFPS;
|
||||
//对象个数统计
|
||||
toolkit::ObjectStatistic<MultiMediaSourceMuxer> _statistic;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue