From a1de3bfd306ac3388f207f3c1621093ca3662bbd Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 1 Oct 2020 18:57:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=81=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E3=80=81=E5=9C=A8=E7=BA=BF=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- server/WebApi.cpp | 4 +++- src/Common/MediaSource.cpp | 10 ++++++++++ src/Common/MediaSource.h | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) 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;