mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
适配ZLToolKit
This commit is contained in:
parent
d555f6038a
commit
c12a6f0aed
@ -1 +1 @@
|
|||||||
Subproject commit 63d8521c31bdae6656d9ff0f5d55883618f5eaf1
|
Subproject commit e7cd1f3d1ec81014f92ab844915db60bb7e34bd5
|
@ -343,7 +343,7 @@ void FFmpegSnap::makeSnap(const string &play_url, const string &save_path, float
|
|||||||
// FFmpeg进程退出了可以取消定时器了
|
// FFmpeg进程退出了可以取消定时器了
|
||||||
delayTask->cancel();
|
delayTask->cancel();
|
||||||
// 执行回调函数
|
// 执行回调函数
|
||||||
bool success = process->exit_code() == 0 && File::fileSize(save_path.data());
|
bool success = process->exit_code() == 0 && File::fileSize(save_path);
|
||||||
cb(success, (!success && !log_file.empty()) ? File::loadFile(log_file.data()) : "");
|
cb(success, (!success && !log_file.empty()) ? File::loadFile(log_file) : "");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ static int runChildProcess(string cmd, string log_file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//重定向shell日志至文件
|
//重定向shell日志至文件
|
||||||
auto fp = File::create_file(log_file.data(), "ab");
|
auto fp = File::create_file(log_file, "ab");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
|
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
|
||||||
} else {
|
} else {
|
||||||
@ -121,7 +121,7 @@ void Process::run(const string &cmd, string log_file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//重定向shell日志至文件
|
//重定向shell日志至文件
|
||||||
auto fp = File::create_file(log_file.data(), "ab");
|
auto fp = File::create_file(log_file, "ab");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
|
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
|
||||||
} else {
|
} else {
|
||||||
|
@ -1547,7 +1547,7 @@ void installWebApi() {
|
|||||||
}
|
}
|
||||||
val["path"] = record_path;
|
val["path"] = record_path;
|
||||||
if (!recording) {
|
if (!recording) {
|
||||||
val["code"] = File::delete_file(record_path.data());
|
val["code"] = File::delete_file(record_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File::scanDir(record_path, [](const string &path, bool is_dir) {
|
File::scanDir(record_path, [](const string &path, bool is_dir) {
|
||||||
@ -1555,7 +1555,7 @@ void installWebApi() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (path.find("./") != std::string::npos) {
|
if (path.find("./") != std::string::npos) {
|
||||||
File::delete_file(path.data());
|
File::delete_file(path);
|
||||||
} else {
|
} else {
|
||||||
TraceL << "Ignore tmp mp4 file: " << path;
|
TraceL << "Ignore tmp mp4 file: " << path;
|
||||||
}
|
}
|
||||||
@ -1608,7 +1608,7 @@ void installWebApi() {
|
|||||||
static bool s_snap_success_once = false;
|
static bool s_snap_success_once = false;
|
||||||
StrCaseMap headerOut;
|
StrCaseMap headerOut;
|
||||||
GET_CONFIG(string, defaultSnap, API::kDefaultSnap);
|
GET_CONFIG(string, defaultSnap, API::kDefaultSnap);
|
||||||
if (!File::fileSize(snap_path.data())) {
|
if (!File::fileSize(snap_path)) {
|
||||||
if (!err_msg.empty() && (!s_snap_success_once || defaultSnap.empty())) {
|
if (!err_msg.empty() && (!s_snap_success_once || defaultSnap.empty())) {
|
||||||
//重来没截图成功过或者默认截图图片为空,那么直接返回FFmpeg错误日志
|
//重来没截图成功过或者默认截图图片为空,那么直接返回FFmpeg错误日志
|
||||||
headerOut["Content-Type"] = HttpFileManager::getContentType(".txt");
|
headerOut["Content-Type"] = HttpFileManager::getContentType(".txt");
|
||||||
@ -1670,7 +1670,7 @@ void installWebApi() {
|
|||||||
if (!have_old_snap) {
|
if (!have_old_snap) {
|
||||||
//无过期截图,生成一个空文件,目的是顺便创建文件夹路径
|
//无过期截图,生成一个空文件,目的是顺便创建文件夹路径
|
||||||
//同时防止在FFmpeg生成截图途中不停的尝试调用该api多次启动FFmpeg进程
|
//同时防止在FFmpeg生成截图途中不停的尝试调用该api多次启动FFmpeg进程
|
||||||
auto file = File::create_file(new_snap.data(), "wb");
|
auto file = File::create_file(new_snap, "wb");
|
||||||
if (file) {
|
if (file) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
@ -1681,10 +1681,10 @@ void installWebApi() {
|
|||||||
FFmpegSnap::makeSnap(allArgs["url"], new_snap_tmp, allArgs["timeout_sec"], [invoker, allArgs, new_snap, new_snap_tmp](bool success, const string &err_msg) {
|
FFmpegSnap::makeSnap(allArgs["url"], new_snap_tmp, allArgs["timeout_sec"], [invoker, allArgs, new_snap, new_snap_tmp](bool success, const string &err_msg) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
//生成截图失败,可能残留空文件
|
//生成截图失败,可能残留空文件
|
||||||
File::delete_file(new_snap_tmp.data());
|
File::delete_file(new_snap_tmp);
|
||||||
} else {
|
} else {
|
||||||
//临时文件改成正式文件
|
//临时文件改成正式文件
|
||||||
File::delete_file(new_snap.data());
|
File::delete_file(new_snap);
|
||||||
rename(new_snap_tmp.data(), new_snap.data());
|
rename(new_snap_tmp.data(), new_snap.data());
|
||||||
}
|
}
|
||||||
responseSnap(new_snap, allArgs.getParser().getHeader(), invoker, err_msg);
|
responseSnap(new_snap, allArgs.getParser().getHeader(), invoker, err_msg);
|
||||||
|
@ -263,7 +263,7 @@ int start_main(int argc,char *argv[]) {
|
|||||||
//加载配置文件,如果配置文件不存在就创建一个
|
//加载配置文件,如果配置文件不存在就创建一个
|
||||||
loadIniConfig(g_ini_file.data());
|
loadIniConfig(g_ini_file.data());
|
||||||
|
|
||||||
if (!File::is_dir(ssl_file.data())) {
|
if (!File::is_dir(ssl_file)) {
|
||||||
//不是文件夹,加载证书,证书包含公钥和私钥
|
//不是文件夹,加载证书,证书包含公钥和私钥
|
||||||
SSL_Initor::Instance().loadCertificate(ssl_file.data());
|
SSL_Initor::Instance().loadCertificate(ssl_file.data());
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ void HttpDownloader::startDownload(const string &url, const string &file_path, b
|
|||||||
if (_file_path.empty()) {
|
if (_file_path.empty()) {
|
||||||
_file_path = exeDir() + "HttpDownloader/" + MD5(url).hexdigest();
|
_file_path = exeDir() + "HttpDownloader/" + MD5(url).hexdigest();
|
||||||
}
|
}
|
||||||
_save_file = File::create_file(_file_path.data(), append ? "ab" : "wb");
|
_save_file = File::create_file(_file_path, append ? "ab" : "wb");
|
||||||
if (!_save_file) {
|
if (!_save_file) {
|
||||||
auto strErr = StrPrinter << "打开文件失败:" << file_path << endl;
|
auto strErr = StrPrinter << "打开文件失败:" << file_path << endl;
|
||||||
throw std::runtime_error(strErr);
|
throw std::runtime_error(strErr);
|
||||||
|
@ -192,7 +192,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
|||||||
last_dir_name = split(strPathPrefix, "/").back();
|
last_dir_name = split(strPathPrefix, "/").back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!File::is_dir(strPathPrefix.data())) {
|
if (!File::is_dir(strPathPrefix)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
@ -250,7 +250,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &pr :file_map) {
|
for (auto &pr :file_map) {
|
||||||
auto &strAbsolutePath = pr.second.second;
|
auto &strAbsolutePath = pr.second.second;
|
||||||
bool isDir = File::is_dir(strAbsolutePath.data());
|
bool isDir = File::is_dir(strAbsolutePath);
|
||||||
ss << "<li><span>" << i++ << "</span>\t";
|
ss << "<li><span>" << i++ << "</span>\t";
|
||||||
ss << "<a href=\"";
|
ss << "<a href=\"";
|
||||||
//路径链接地址
|
//路径链接地址
|
||||||
@ -271,7 +271,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//是文件
|
//是文件
|
||||||
auto fileSize = File::fileSize(strAbsolutePath.data());
|
auto fileSize = File::fileSize(strAbsolutePath);
|
||||||
if (fileSize < 1024) {
|
if (fileSize < 1024) {
|
||||||
ss << " (" << fileSize << "B)" << endl;
|
ss << " (" << fileSize << "B)" << endl;
|
||||||
} else if (fileSize < 1024 * 1024) {
|
} else if (fileSize < 1024 * 1024) {
|
||||||
@ -467,7 +467,7 @@ static string pathCat(const string &a, const string &b){
|
|||||||
*/
|
*/
|
||||||
static void accessFile(Session &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
static void accessFile(Session &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||||
bool is_hls = end_with(file_path, kHlsSuffix) || end_with(file_path, kHlsFMP4Suffix);
|
bool is_hls = end_with(file_path, kHlsSuffix) || end_with(file_path, kHlsFMP4Suffix);
|
||||||
if (!is_hls && !File::fileExist(file_path.data())) {
|
if (!is_hls && !File::fileExist(file_path)) {
|
||||||
//文件不存在且不是hls,那么直接返回404
|
//文件不存在且不是hls,那么直接返回404
|
||||||
sendNotFound(cb);
|
sendNotFound(cb);
|
||||||
return;
|
return;
|
||||||
@ -628,12 +628,12 @@ void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//访问的是文件夹
|
//访问的是文件夹
|
||||||
if (File::is_dir(file_path.data())) {
|
if (File::is_dir(file_path)) {
|
||||||
auto indexFile = searchIndexFile(file_path);
|
auto indexFile = searchIndexFile(file_path);
|
||||||
if (!indexFile.empty()) {
|
if (!indexFile.empty()) {
|
||||||
// 发现该文件夹下有index文件
|
// 发现该文件夹下有index文件
|
||||||
file_path = pathCat(file_path, indexFile);
|
file_path = pathCat(file_path, indexFile);
|
||||||
if (!File::is_dir(file_path.data())) {
|
if (!File::is_dir(file_path)) {
|
||||||
// 不是文件夹
|
// 不是文件夹
|
||||||
parser.setUrl(pathCat(parser.url(), indexFile));
|
parser.setUrl(pathCat(parser.url(), indexFile));
|
||||||
accessFile(sender, parser, media_info, file_path, cb);
|
accessFile(sender, parser, media_info, file_path, cb);
|
||||||
|
@ -85,10 +85,10 @@ void MP4Recorder::asyncClose() {
|
|||||||
TraceL << "Closed tmp mp4 file: " << full_path_tmp;
|
TraceL << "Closed tmp mp4 file: " << full_path_tmp;
|
||||||
if (!full_path_tmp.empty()) {
|
if (!full_path_tmp.empty()) {
|
||||||
// 获取文件大小
|
// 获取文件大小
|
||||||
info.file_size = File::fileSize(full_path_tmp.data());
|
info.file_size = File::fileSize(full_path_tmp);
|
||||||
if (info.file_size < 1024) {
|
if (info.file_size < 1024) {
|
||||||
// 录像文件太小,删除之
|
// 录像文件太小,删除之
|
||||||
File::delete_file(full_path_tmp.data());
|
File::delete_file(full_path_tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 临时文件名改成正式文件名,防止mp4未完成时被访问
|
// 临时文件名改成正式文件名,防止mp4未完成时被访问
|
||||||
|
@ -174,7 +174,7 @@ void FlvRecorder::startRecord(const EventPoller::Ptr &poller, const RtmpMediaSou
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
//新建文件
|
//新建文件
|
||||||
_file.reset(File::create_file(file_path.data(), "wb"), [fileBuf](FILE *fp) {
|
_file.reset(File::create_file(file_path, "wb"), [fileBuf](FILE *fp) {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -33,7 +33,7 @@ RtpProcess::RtpProcess(const string &stream_id) {
|
|||||||
|
|
||||||
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
|
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
|
||||||
{
|
{
|
||||||
FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info.stream + ".rtp", dump_dir).data(), "wb") : nullptr;
|
FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info.stream + ".rtp", dump_dir), "wb") : nullptr;
|
||||||
if (fp) {
|
if (fp) {
|
||||||
_save_file_rtp.reset(fp, [](FILE *fp) {
|
_save_file_rtp.reset(fp, [](FILE *fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -42,7 +42,7 @@ RtpProcess::RtpProcess(const string &stream_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info.stream + ".video", dump_dir).data(), "wb") : nullptr;
|
FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info.stream + ".video", dump_dir), "wb") : nullptr;
|
||||||
if (fp) {
|
if (fp) {
|
||||||
_save_file_video.reset(fp, [](FILE *fp) {
|
_save_file_video.reset(fp, [](FILE *fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -138,7 +138,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
auto parse_urls = [&]() {
|
auto parse_urls = [&]() {
|
||||||
// 获取输入源列表
|
// 获取输入源列表
|
||||||
auto inputs = ::split(toolkit::File::loadFile(in_urls.c_str()), "\n");
|
auto inputs = ::split(toolkit::File::loadFile(in_urls), "\n");
|
||||||
for(auto &url : inputs){
|
for(auto &url : inputs){
|
||||||
if(url.empty() || url.find("://") == std::string::npos) {
|
if(url.empty() || url.find("://") == std::string::npos) {
|
||||||
continue;
|
continue;
|
||||||
@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
|
|||||||
input_urls.emplace_back(input_url);
|
input_urls.emplace_back(input_url);
|
||||||
}
|
}
|
||||||
// 获取输出源列表
|
// 获取输出源列表
|
||||||
auto outputs = ::split(toolkit::File::loadFile(out_urls.c_str()), "\n");
|
auto outputs = ::split(toolkit::File::loadFile(out_urls), "\n");
|
||||||
for(auto &url : outputs){
|
for(auto &url : outputs){
|
||||||
if(url.empty() || url.find("://") == std::string::npos){
|
if(url.empty() || url.find("://") == std::string::npos){
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user