添加rtp pause接口,目前默认3分钟

This commit is contained in:
monktan
2020-09-27 16:51:35 +08:00
parent 09d2472f6b
commit fbecb7f5f4
3 changed files with 37 additions and 0 deletions

View File

@@ -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");

View File

@@ -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<MediaSourceEvent> &listener){
}
}
void RtpProcess::setRtpPause(bool pause)
{
_paused = pause;
_pause_rtp_time.resetTime();
}
void RtpProcess::emitOnPublish() {
weak_ptr<RtpProcess> weak_self = shared_from_this();
Broadcast::PublishAuthInvoker invoker = [weak_self](const string &err, bool enableHls, bool enableMP4) {

View File

@@ -66,6 +66,11 @@ public:
int totalReaderCount();
void setListener(const std::weak_ptr<MediaSourceEvent> &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<void()> _on_detach;
bool _paused = false;
Ticker _pause_rtp_time;
};
}//namespace mediakit