From e72fa359b638b12f683b75d48e7769a4771e527e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 28 Dec 2019 16:57:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84hls=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=99=A8=E4=B8=AA=E6=95=B0=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events_objects.h | 2 ++ api/source/mk_events_objects.cpp | 7 +++++++ server/WebApi.cpp | 2 ++ src/Rtmp/RtmpMediaSource.h | 2 +- src/Rtmp/RtmpSession.cpp | 2 +- src/Rtsp/RtspMediaSource.h | 2 +- src/Rtsp/RtspSession.cpp | 2 +- 7 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index ee456bf5..30b4cb7c 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -109,6 +109,8 @@ API_EXPORT const char* API_CALL mk_media_source_get_app(const mk_media_source ct API_EXPORT const char* API_CALL mk_media_source_get_stream(const mk_media_source ctx); //MediaSource::readerCount() API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source ctx); +//MediaSource::totalReaderCount() +API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_source ctx); //MediaSource::close() API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force); //MediaSource::seekTo() diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index f959668a..cc341cc8 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -199,6 +199,13 @@ API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source c MediaSource *src = (MediaSource *)ctx; return src->readerCount(); } + +API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_source ctx){ + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->totalReaderCount(); +} + API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ assert(ctx); MediaSource *src = (MediaSource *)ctx; diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 7b48493d..0ce721b6 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -412,6 +412,7 @@ void installWebApi() { item["app"] = media->getApp(); item["stream"] = media->getId(); item["readerCount"] = media->readerCount(); + item["totalReaderCount"] = media->totalReaderCount(); for(auto &track : media->getTracks()){ Value obj; obj["codec_id"] = track->getCodecId(); @@ -441,6 +442,7 @@ void installWebApi() { } val["online"] = true; val["readerCount"] = src->readerCount(); + val["totalReaderCount"] = src->totalReaderCount(); for(auto &track : src->getTracks()){ Value obj; obj["codec_id"] = track->getCodecId(); diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index 12f8b10c..982d4401 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -175,7 +175,7 @@ private: void onReaderChanged(int size) { //我们记录最后一次活动时间 _reader_changed_ticker.resetTime(); - if (size != 0 || readerCount() != 0) { + if (size != 0 || totalReaderCount() != 0) { //还有消费者正在观看该流 _async_emit_none_reader = false; return; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 9db2c175..42518016 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -302,7 +302,7 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr strongSelf->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached")); }); _pPlayerSrc = src; - if (src->readerCount() == 1) { + if (src->totalReaderCount() == 1) { src->seekTo(0); } //提高服务器发送性能 diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index b63b7be8..f4354ae4 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -195,7 +195,7 @@ private: void onReaderChanged(int size) { //我们记录最后一次活动时间 _reader_changed_ticker.resetTime(); - if (size != 0 || readerCount() != 0) { + if (size != 0 || totalReaderCount() != 0) { //还有消费者正在观看该流 _async_emit_none_reader = false; return; diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index ef61f3e3..7d874cd8 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -773,7 +773,7 @@ void RtspSession::handleReq_Play(const Parser &parser) { auto iStartTime = 1000 * atof(strStart.data()); InfoP(this) << "rtsp seekTo(ms):" << iStartTime; useBuf = !pMediaSrc->seekTo(iStartTime); - }else if(pMediaSrc->readerCount() == 0){ + }else if(pMediaSrc->totalReaderCount() == 0){ //第一个消费者 pMediaSrc->seekTo(0); }