mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-30 23:02:24 +08:00
Merge remote-tracking branch 'upstream/master' into master
This commit is contained in:
@@ -197,8 +197,8 @@ void FFmpegSource::startTimer(int timeout_ms) {
|
||||
strongSelf->findAsync(0, [&](const MediaSource::Ptr &src) {
|
||||
//同步查找流
|
||||
if (!src) {
|
||||
//流不在线,重新拉流
|
||||
if(strongSelf->_replay_ticker.elapsedTime() > 10 * 1000){
|
||||
//流不在线,重新拉流, 这里原先是10秒超时,实际发现10秒不够,改成20秒了
|
||||
if(strongSelf->_replay_ticker.elapsedTime() > 20 * 1000){
|
||||
//上次重试时间超过10秒,那么再重试FFmpeg拉流
|
||||
strongSelf->_replay_ticker.resetTime();
|
||||
strongSelf->play(strongSelf->_src_url, strongSelf->_dst_url, timeout_ms, [](const SockException &) {});
|
||||
@@ -276,20 +276,27 @@ void FFmpegSnap::makeSnap(const string &play_url, const string &save_path, float
|
||||
GET_CONFIG(string,ffmpeg_bin,FFmpeg::kBin);
|
||||
GET_CONFIG(string,ffmpeg_snap,FFmpeg::kSnap);
|
||||
GET_CONFIG(string,ffmpeg_log,FFmpeg::kLog);
|
||||
|
||||
std::shared_ptr<Process> process = std::make_shared<Process>();
|
||||
auto delayTask = EventPollerPool::Instance().getPoller()->doDelayTask(timeout_sec * 1000,[process,cb](){
|
||||
if(process->wait(false)){
|
||||
//FFmpeg进程还在运行,超时就关闭它
|
||||
process->kill(2000);
|
||||
Ticker ticker;
|
||||
WorkThreadPool::Instance().getPoller()->async([timeout_sec, play_url,save_path,cb, ticker](){
|
||||
auto elapsed_ms = ticker.elapsedTime();
|
||||
if (elapsed_ms > timeout_sec * 1000) {
|
||||
//超时,后台线程负载太高,当代太久才启动该任务
|
||||
cb(false);
|
||||
return;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
WorkThreadPool::Instance().getPoller()->async([process,play_url,save_path,delayTask,cb](){
|
||||
char cmd[1024] = {0};
|
||||
snprintf(cmd, sizeof(cmd),ffmpeg_snap.data(),ffmpeg_bin.data(),play_url.data(),save_path.data());
|
||||
std::shared_ptr<Process> process = std::make_shared<Process>();
|
||||
process->run(cmd,ffmpeg_log.empty() ? "" : File::absolutePath("",ffmpeg_log));
|
||||
//定时器延时应该减去后台任务启动的延时
|
||||
auto delayTask = EventPollerPool::Instance().getPoller()->doDelayTask(timeout_sec * 1000 - elapsed_ms,[process,cb](){
|
||||
if(process->wait(false)){
|
||||
//FFmpeg进程还在运行,超时就关闭它
|
||||
process->kill(2000);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
//等待FFmpeg进程退出
|
||||
process->wait(true);
|
||||
//FFmpeg进程退出了可以取消定时器了
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "Util/File.h"
|
||||
#include "Util/logger.h"
|
||||
#include "Util/uv_errno.h"
|
||||
#include "Thread/WorkThreadPool.h"
|
||||
#include "Poller/EventPoller.h"
|
||||
#include "Process.h"
|
||||
using namespace toolkit;
|
||||
|
||||
@@ -261,7 +261,7 @@ static void s_kill(pid_t pid, void *handle, int max_delay, bool force) {
|
||||
}
|
||||
|
||||
//发送SIGTERM信号后,2秒后检查子进程是否已经退出
|
||||
WorkThreadPool::Instance().getPoller()->doDelayTask(max_delay, [pid, handle]() {
|
||||
EventPollerPool::Instance().getPoller()->doDelayTask(max_delay, [pid, handle]() {
|
||||
if (!s_wait(pid, handle, nullptr, false)) {
|
||||
//进程已经退出了
|
||||
return 0;
|
||||
|
||||
@@ -403,6 +403,9 @@ void installWebApi() {
|
||||
item["vhost"] = media->getVhost();
|
||||
item["app"] = media->getApp();
|
||||
item["stream"] = media->getId();
|
||||
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();
|
||||
|
||||
@@ -134,6 +134,9 @@ const char *getContentType(const HttpArgs &value){
|
||||
}
|
||||
|
||||
static void do_http_hook(const string &url,const ArgsType &body,const function<void(const Value &,const string &)> &fun){
|
||||
GET_CONFIG(string,mediaServerId,General::kMediaServerId);
|
||||
const_cast<ArgsType &>(body)["mediaServerId"] = mediaServerId;
|
||||
|
||||
GET_CONFIG(float,hook_timeoutSec,Hook::kTimeoutSec);
|
||||
HttpRequester::Ptr requester(new HttpRequester);
|
||||
requester->setMethod("POST");
|
||||
|
||||
Reference in New Issue
Block a user