From fbecb7f5f416574aa1d2bee028ca307691fb2a01 Mon Sep 17 00:00:00 2001 From: monktan Date: Sun, 27 Sep 2020 16:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0rtp=20pause=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E7=9B=AE=E5=89=8D=E9=BB=98=E8=AE=A43=E5=88=86?= =?UTF-8?q?=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 14 ++++++++++++++ src/Rtp/RtpProcess.cpp | 15 +++++++++++++++ src/Rtp/RtpProcess.h | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 7790aaf0..e15ba753 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -903,6 +903,20 @@ void installWebApi() { val["local_ip"] = process->get_local_ip(); }); + api_regist1("/index/api/setRtpPause", [](API_ARGS1){ + CHECK_SECRET(); + CHECK_ARGS("stream_id", "pause"); + + auto process = RtpSelector::Instance().getProcess(allArgs["stream_id"], false); + if (!process) { + val["code"] = "-1"; + return; + } + + auto pause = allArgs["pause"]; + process->setRtpPause(pause); + }); + api_regist1("/index/api/openRtpServer",[](API_ARGS1){ CHECK_SECRET(); CHECK_ARGS("port", "enable_tcp", "stream_id"); diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 23b4c754..6ee5fa30 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -180,6 +180,15 @@ void RtpProcess::addTrack(const Track::Ptr & track){ } bool RtpProcess::alive() { + if(_paused) { + if(_pause_rtp_time.elapsedTime()/ 1000 < 180){ + return true; + }else { + WarnL << _media_info._streamid << ", pause timeout."; + return false; + } + } + GET_CONFIG(int,timeoutSec,RtpProxy::kTimeoutSec) if(_last_rtp_time.elapsedTime() / 1000 < timeoutSec){ return true; @@ -241,6 +250,12 @@ void RtpProcess::setListener(const std::weak_ptr &listener){ } } +void RtpProcess::setRtpPause(bool pause) +{ + _paused = pause; + _pause_rtp_time.resetTime(); +} + void RtpProcess::emitOnPublish() { weak_ptr weak_self = shared_from_this(); Broadcast::PublishAuthInvoker invoker = [weak_self](const string &err, bool enableHls, bool enableMP4) { diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 7715eda0..30d9f404 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -66,6 +66,11 @@ public: int totalReaderCount(); void setListener(const std::weak_ptr &listener); + /* + * 设置rtp流暂停 + */ + void setRtpPause(bool pause); + protected: void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ; void inputFrame(const Frame::Ptr &frame) override; @@ -95,6 +100,9 @@ private: uint64_t _total_bytes = 0; Socket::Ptr _sock; function _on_detach; + + bool _paused = false; + Ticker _pause_rtp_time; }; }//namespace mediakit