diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index f564c7ed..735f194e 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit f564c7ed27f141a3b5f08d239970b24d700a1244 +Subproject commit 735f194e18d5fb576c0da03024226a6f38537e5a diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 44c4549d..8eb54174 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -395,7 +395,9 @@ void installWebApi() { item["vhost"] = media->getVhost(); item["app"] = media->getApp(); item["stream"] = media->getId(); - item["bytes_speed"] = media->getBytesSpeed(); + item["createStamp"] = (Json::UInt64) media->getCreateStamp(); + item["aliveSecond"] = (Json::UInt64) media->getAliveSecond(); + item["bytesSpeed"] = media->getBytesSpeed(); item["readerCount"] = media->readerCount(); item["totalReaderCount"] = media->totalReaderCount(); item["originType"] = (int) media->getOriginType(); diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 295f554f..d548a7d1 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -43,6 +43,7 @@ MediaSource::MediaSource(const string &schema, const string &vhost, const string _schema = schema; _app = app; _stream_id = stream_id; + _create_stamp = time(NULL); } MediaSource::~MediaSource() { @@ -70,6 +71,15 @@ int MediaSource::getBytesSpeed(){ return _speed.getSpeed(); } +uint64_t MediaSource::getCreateStamp() const { + return _create_stamp; +} + +uint64_t MediaSource::getAliveSecond() const { + //使用Ticker对象获取存活时间的目的是防止修改系统时间导致回退 + return _ticker.createdTime() / 1000; +} + vector MediaSource::getTracks(bool ready) const { auto listener = _listener.lock(); if(!listener){ diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index bd43b04c..1efd4b2b 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -218,6 +218,10 @@ public: // 获取数据速率,单位bytes/s int getBytesSpeed(); + // 获取流创建GMT unix时间戳,单位秒 + uint64_t getCreateStamp() const; + // 获取流上线时间,单位秒 + uint64_t getAliveSecond() const; ////////////////MediaSourceEvent相关接口实现//////////////// @@ -282,6 +286,8 @@ protected: BytesSpeed _speed; private: + time_t _create_stamp; + Ticker _ticker; string _schema; string _vhost; string _app;