Compare commits

...

2 Commits

Author SHA1 Message Date
ljx0305
1ead079af4
修正判断Json::Value::find函数返回值 (#4347)
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
修正Json::Value::find函数返回值并非iterator而是Value指针
2025-07-10 14:15:52 +08:00
PioLing
47fd8e9fc3
Add exception handling for FFmpeg cmd checked. (#4343) 2025-07-10 14:14:57 +08:00
2 changed files with 86 additions and 80 deletions

View File

@ -84,10 +84,6 @@ void FFmpegSource::play(const string &ffmpeg_cmd_key, const string &src_url, con
try { try {
_media_info.parse(dst_url); _media_info.parse(dst_url);
} catch (std::exception &ex) {
cb(SockException(Err_other, ex.what()));
return;
}
auto ffmpeg_cmd = ffmpeg_cmd_default; auto ffmpeg_cmd = ffmpeg_cmd_default;
if (!ffmpeg_cmd_key.empty()) { if (!ffmpeg_cmd_key.empty()) {
@ -98,6 +94,9 @@ void FFmpegSource::play(const string &ffmpeg_cmd_key, const string &src_url, con
WarnL << "配置文件中,ffmpeg命令模板(" << ffmpeg_cmd_key << ")不存在,已采用默认模板(" << ffmpeg_cmd_default << ")"; WarnL << "配置文件中,ffmpeg命令模板(" << ffmpeg_cmd_key << ")不存在,已采用默认模板(" << ffmpeg_cmd_default << ")";
} }
} }
if (!toolkit::start_with(ffmpeg_cmd, "%s")) {
throw std::invalid_argument("ffmpeg cmd template must start with '%s'");
}
char cmd[2048] = { 0 }; char cmd[2048] = { 0 };
snprintf(cmd, sizeof(cmd), ffmpeg_cmd.data(), File::absolutePath("", ffmpeg_bin).data(), src_url.data(), dst_url.data()); snprintf(cmd, sizeof(cmd), ffmpeg_cmd.data(), File::absolutePath("", ffmpeg_bin).data(), src_url.data(), dst_url.data());
@ -109,8 +108,8 @@ void FFmpegSource::play(const string &ffmpeg_cmd_key, const string &src_url, con
if (is_local_ip(_media_info.host)) { if (is_local_ip(_media_info.host)) {
// 推流给自己的,通过判断流是否注册上来判断是否正常 [AUTO-TRANSLATED:423f2be6] // 推流给自己的,通过判断流是否注册上来判断是否正常 [AUTO-TRANSLATED:423f2be6]
// Push stream to yourself, judge whether the stream is registered to determine whether it is normal // Push stream to yourself, judge whether the stream is registered to determine whether it is normal
if (_media_info.schema != RTSP_SCHEMA && _media_info.schema != RTMP_SCHEMA) { if (_media_info.schema != RTSP_SCHEMA && _media_info.schema != RTMP_SCHEMA && _media_info.schema != "srt") {
cb(SockException(Err_other, "本服务只支持rtmp/rtsp推流")); cb(SockException(Err_other, "本服务只支持rtmp/rtsp/srt推流"));
return; return;
} }
weak_ptr<FFmpegSource> weakSelf = shared_from_this(); weak_ptr<FFmpegSource> weakSelf = shared_from_this();
@ -145,7 +144,9 @@ void FFmpegSource::play(const string &ffmpeg_cmd_key, const string &src_url, con
// 推流给其他服务器的通过判断FFmpeg进程是否在线判断是否成功 [AUTO-TRANSLATED:9b963da5] // 推流给其他服务器的通过判断FFmpeg进程是否在线判断是否成功 [AUTO-TRANSLATED:9b963da5]
// Push stream to other servers, judge whether it is successful by judging whether the FFmpeg process is online // Push stream to other servers, judge whether it is successful by judging whether the FFmpeg process is online
weak_ptr<FFmpegSource> weakSelf = shared_from_this(); weak_ptr<FFmpegSource> weakSelf = shared_from_this();
_timer = std::make_shared<Timer>(timeout_ms / 1000.0f, [weakSelf, cb, timeout_ms]() { _timer = std::make_shared<Timer>(
timeout_ms / 1000.0f,
[weakSelf, cb, timeout_ms]() {
auto strongSelf = weakSelf.lock(); auto strongSelf = weakSelf.lock();
if (!strongSelf) { if (!strongSelf) {
// 自身已经销毁 [AUTO-TRANSLATED:5f954f8a] // 自身已经销毁 [AUTO-TRANSLATED:5f954f8a]
@ -163,7 +164,12 @@ void FFmpegSource::play(const string &ffmpeg_cmd_key, const string &src_url, con
// ffmpeg process has exited // ffmpeg process has exited
cb(SockException(Err_other, StrPrinter << "ffmpeg已经退出,exit code = " << strongSelf->_process.exit_code())); cb(SockException(Err_other, StrPrinter << "ffmpeg已经退出,exit code = " << strongSelf->_process.exit_code()));
return false; return false;
}, _poller); },
_poller);
}
} catch (std::exception &ex) {
WarnL << ex.what();
cb(SockException(Err_other, ex.what()));
} }
} }

View File

@ -89,11 +89,11 @@ std::string getValue(Args &args, const Key &key) {
template<typename Key> template<typename Key>
std::string getValue(Json::Value &args, const Key &key) { std::string getValue(Json::Value &args, const Key &key) {
auto it = args.find(key); auto value = args.find(key);
if (it == args.end()) { if (value == nullptr) {
return ""; return "";
} }
return it->second.asString(); return value->asString();
} }
template<typename Key> template<typename Key>