addStreamProxy新增force,支持强制重试拉流

This commit is contained in:
xia-chu
2026-03-17 19:30:08 +08:00
parent a13063c5e4
commit 4e170e9281
6 changed files with 43 additions and 22 deletions

View File

@@ -583,7 +583,7 @@ void getStatisticJson(const function<void(Value &val)> &cb) {
#endif
}
void addStreamProxy(const MediaTuple &tuple, const string &url, int retry_count,
void addStreamProxy(const MediaTuple &tuple, const string &url, int retry_count, bool force,
const ProtocolOption &option, int rtp_type, float timeout_sec, const mINI &args,
const function<void(const SockException &ex, const string &key)> &cb) {
auto key = tuple.shortUrl();
@@ -615,11 +615,18 @@ void addStreamProxy(const MediaTuple &tuple, const string &url, int retry_count,
// 开始播放,如果播放失败或者播放中止,将会自动重试若干次,默认一直重试 [AUTO-TRANSLATED:ac8499e5]
// Start playing. If playback fails or is stopped, it will automatically retry several times, by default it will retry indefinitely
player->setPlayCallbackOnce([cb, key](const SockException &ex) {
if (ex) {
s_player_proxy.erase(key);
player->setPlayCallbackOnce([cb, key, force](const SockException &ex) {
if (force) {
// 强制添加成功
cb(SockException(), key);
} else {
// 非强制添加
if (ex) {
// 失败则移除记录
s_player_proxy.erase(key);
}
cb(ex, key);
}
cb(ex, key);
});
// 被主动关闭拉流 [AUTO-TRANSLATED:41a19476]
@@ -1264,6 +1271,7 @@ void installWebApi() {
addStreamProxy(tuple,
allArgs["url"],
retry_count,
allArgs["force"],
option,
allArgs["rtp_type"],
allArgs["timeout_sec"],

View File

@@ -248,7 +248,7 @@ uint16_t openRtpServer(uint16_t local_port, const mediakit::MediaTuple &tuple, i
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
ApiArgsType getAllArgs(const mediakit::Parser &parser);
void getStatisticJson(const std::function<void(Json::Value &val)> &cb);
void addStreamProxy(const mediakit::MediaTuple &tuple, const std::string &url, int retry_count,
void addStreamProxy(const mediakit::MediaTuple &tuple, const std::string &url, int retry_count, bool force,
const mediakit::ProtocolOption &option, int rtp_type, float timeout_sec, const toolkit::mINI &args,
const std::function<void(const toolkit::SockException &ex, const std::string &key)> &cb);

View File

@@ -321,7 +321,7 @@ static void pullStreamFromOrigin(const vector<string> &urls, size_t index, size_
option.enable_hls = option.enable_hls || (args.schema == HLS_SCHEMA);
option.enable_mp4 = false;
addStreamProxy(args, url, retry_count, option, Rtsp::RTP_TCP, timeout_sec, mINI{}, [=](const SockException &ex, const string &key) mutable {
addStreamProxy(args, url, retry_count, false, option, Rtsp::RTP_TCP, timeout_sec, mINI{}, [=](const SockException &ex, const string &key) mutable {
if (!ex) {
return;
}