From 9c42c5ed8c317fa8793cd2aa96369595c8d03f51 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 7 Jan 2020 14:37:18 +0800 Subject: [PATCH] =?UTF-8?q?windows=E8=A7=86=E9=A2=91FFmpeg=E6=8B=89?= =?UTF-8?q?=E6=B5=81=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/CMakeLists.txt | 7 +- server/FFmpegSource.cpp | 19 ++- server/Process.cpp | 208 ++++++++++++++++++++------------ server/Process.h | 11 +- server/System.cpp | 261 ++++------------------------------------ server/System.h | 56 +-------- server/WebApi.cpp | 9 -- 7 files changed, 178 insertions(+), 393 deletions(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 5bc42a8d..092a4221 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -3,12 +3,7 @@ file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h ) add_library(jsoncpp STATIC ${jsoncpp_src_list}) -if (CMAKE_SYSTEM_NAME MATCHES "Windows") - set(MediaServer_src_list ./WebApi.cpp ./WebHook.cpp main.cpp) -else() - file(GLOB MediaServer_src_list ./*.cpp ./*.h) -endif() - +file(GLOB MediaServer_src_list ./*.cpp ./*.h) #message(STATUS ${MediaServer_src_list}) add_executable(MediaServer ${MediaServer_src_list}) diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 3824f910..d8a821c6 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -32,13 +32,22 @@ namespace FFmpeg { #define FFmpeg_FIELD "ffmpeg." -const char kBin[] = FFmpeg_FIELD"bin"; -const char kCmd[] = FFmpeg_FIELD"cmd"; -const char kLog[] = FFmpeg_FIELD"log"; +const string kBin = FFmpeg_FIELD"bin"; +const string kCmd = FFmpeg_FIELD"cmd"; +const string kLog = FFmpeg_FIELD"log"; onceToken token([]() { - mINI::Instance()[kBin] = trim(System::execute("which ffmpeg")); - mINI::Instance()[kCmd] = "%s -re -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s"; +#ifdef _WIN32 + string ffmpeg_bin = System::execute("where ffmpeg"); + //windows下先关闭FFmpeg日志(目前不支持日志重定向) + mINI::Instance()[kCmd] = "%s -re -i \"%s\" -loglevel quiet -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; +#else + string ffmpeg_bin = System::execute("which ffmpeg"); + mINI::Instance()[kCmd] = "%s -re -i \"%s\" -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; +#endif + //默认ffmpeg命令路径为环境变量中路径 + mINI::Instance()[kBin] = ffmpeg_bin.empty() ? "ffmpeg" : ffmpeg_bin; + //ffmpeg日志保存路径 mINI::Instance()[kLog] = "./ffmpeg/ffmpeg.log"; }); } diff --git a/server/Process.cpp b/server/Process.cpp index e215dc81..d64ae72a 100644 --- a/server/Process.cpp +++ b/server/Process.cpp @@ -26,8 +26,15 @@ #include #include + +#ifndef _WIN32 #include #include +#else +//#include +#include +#endif + #include #include #include "Util/util.h" @@ -39,75 +46,95 @@ using namespace toolkit; void Process::run(const string &cmd, const string &log_file_tmp) { - kill(2000); - _pid = fork(); - if (_pid < 0) { - throw std::runtime_error(StrPrinter << "fork child process falied,err:" << get_uv_errmsg()); - } - if (_pid == 0) { - //子进程关闭core文件生成 - struct rlimit rlim = {0,0}; - setrlimit(RLIMIT_CORE, &rlim); + kill(2000); +#ifdef _WIN32 + STARTUPINFO si; + PROCESS_INFORMATION pi; + ZeroMemory(&si, sizeof(si)); //结构体初始化; + ZeroMemory(&pi, sizeof(pi)); - //在启动子进程时,暂时禁用SIGINT、SIGTERM信号 - // ignore the SIGINT and SIGTERM - signal(SIGINT, SIG_IGN); - signal(SIGTERM, SIG_IGN); + LPTSTR lpDir = const_cast(cmd .data()); - string log_file ; - if(log_file_tmp.empty()){ - log_file = "/dev/null"; - }else{ - log_file = StrPrinter << log_file_tmp << "." << getpid(); - } + if (CreateProcess(NULL, lpDir, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ + //下面两行关闭句柄,解除本进程和新进程的关系,不然有可能 不小心调用TerminateProcess函数关掉子进程 + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); - int log_fd = -1; - int flags = O_CREAT | O_WRONLY | O_APPEND; - mode_t mode = S_IRWXO | S_IRWXG | S_IRWXU;// S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; - File::createfile_path(log_file.data(), mode); - if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { - fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); - } else { - // dup to stdout and stderr. - if (dup2(log_fd, STDOUT_FILENO) < 0) { - fprintf(stderr, "dup2 stdout file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); - } - if (dup2(log_fd, STDERR_FILENO) < 0) { - fprintf(stderr, "dup2 stderr file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); - } - // close log fd - ::close(log_fd); - } - fprintf(stderr, "\r\n\r\n#### pid=%d,cmd=%s #####\r\n\r\n", getpid(), cmd.data()); + _pid = pi.dwProcessId; + InfoL << "start child proces " << _pid; + } else { + WarnL << "start child proces fail: " << GetLastError(); + } +#else + _pid = fork(); + if (_pid < 0) { + throw std::runtime_error(StrPrinter << "fork child process falied,err:" << get_uv_errmsg()); + } + if (_pid == 0) { + //子进程关闭core文件生成 + struct rlimit rlim = { 0,0 }; + setrlimit(RLIMIT_CORE, &rlim); - // close other fds - // TODO: do in right way. - for (int i = 3; i < 1024; i++) { - ::close(i); - } + //在启动子进程时,暂时禁用SIGINT、SIGTERM信号 + // ignore the SIGINT and SIGTERM + signal(SIGINT, SIG_IGN); + signal(SIGTERM, SIG_IGN); - auto params = split(cmd, " "); - // memory leak in child process, it's ok. - char **charpv_params = new char *[params.size() + 1]; - for (int i = 0; i < (int) params.size(); i++) { - std::string &p = params[i]; - charpv_params[i] = (char *) p.data(); - } - // EOF: NULL - charpv_params[params.size()] = NULL; + string log_file; + if (log_file_tmp.empty()) { + log_file = "/dev/null"; + } + else { + log_file = StrPrinter << log_file_tmp << "." << getpid(); + } - // TODO: execv or execvp - auto ret = execv(params[0].c_str(), charpv_params); - if (ret < 0) { - fprintf(stderr, "fork process failed, errno=%d(%s)\r\n", errno, strerror(errno)); - } - exit(ret); - } + int log_fd = -1; + int flags = O_CREAT | O_WRONLY | O_APPEND; + mode_t mode = S_IRWXO | S_IRWXG | S_IRWXU;// S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; + File::createfile_path(log_file.data(), mode); + if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { + fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); + } + else { + // dup to stdout and stderr. + if (dup2(log_fd, STDOUT_FILENO) < 0) { + fprintf(stderr, "dup2 stdout file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); + } + if (dup2(log_fd, STDERR_FILENO) < 0) { + fprintf(stderr, "dup2 stderr file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); + } + // close log fd + ::close(log_fd); + } + fprintf(stderr, "\r\n\r\n#### pid=%d,cmd=%s #####\r\n\r\n", getpid(), cmd.data()); - InfoL << "start child proces " << _pid; + // close other fds + // TODO: do in right way. + for (int i = 3; i < 1024; i++) { + ::close(i); + } + + auto params = split(cmd, " "); + // memory leak in child process, it's ok. + char **charpv_params = new char *[params.size() + 1]; + for (int i = 0; i < (int)params.size(); i++) { + std::string &p = params[i]; + charpv_params[i] = (char *)p.data(); + } + // EOF: NULL + charpv_params[params.size()] = NULL; + + // TODO: execv or execvp + auto ret = execv(params[0].c_str(), charpv_params); + if (ret < 0) { + fprintf(stderr, "fork process failed, errno=%d(%s)\r\n", errno, strerror(errno)); + } + exit(ret); + } + InfoL << "start child proces " << _pid; +#endif // _WIN32 } - /** * 获取进程是否存活状态 * @param pid 进程号 @@ -120,20 +147,30 @@ static bool s_wait(pid_t pid,int *exit_code_ptr,bool block) { return false; } int status = 0; - pid_t p = waitpid(pid, &status, block ? 0 : WNOHANG); - int exit_code = (status & 0xFF00) >> 8; - if(exit_code_ptr){ - *exit_code_ptr = (status & 0xFF00) >> 8; - } - if (p < 0) { - WarnL << "waitpid failed, pid=" << pid << ", err=" << get_uv_errmsg(); - return false; - } - if (p > 0) { - InfoL << "process terminated, pid=" << pid << ", exit code=" << exit_code; - return false; - } - //WarnL << "process is running, pid=" << _pid; +#ifdef _WIN32 + HANDLE hProcess = NULL; + hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid); //打开目标进程 + if (hProcess == NULL) { + return false; + } + + CloseHandle(hProcess); +#else + pid_t p = waitpid(pid, &status, block ? 0 : WNOHANG); + int exit_code = (status & 0xFF00) >> 8; + if (exit_code_ptr) { + *exit_code_ptr = (status & 0xFF00) >> 8; + } + if (p < 0) { + WarnL << "waitpid failed, pid=" << pid << ", err=" << get_uv_errmsg(); + return false; + } + if (p > 0) { + InfoL << "process terminated, pid=" << pid << ", exit code=" << exit_code; + return false; + } +#endif // _WIN32 + return true; } @@ -142,12 +179,25 @@ static void s_kill(pid_t pid,int max_delay,bool force){ //pid无效 return; } +#ifdef _WIN32 + HANDLE hProcess = NULL; + hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid); //打开目标进程 + if (hProcess == NULL) { + WarnL << "\nOpen Process fAiled: " << GetLastError(); + return; + } + DWORD ret = TerminateProcess(hProcess, 0); //结束目标进程 + if (ret == 0) { + WarnL << GetLastError; + } +#else + if (::kill(pid, force ? SIGKILL : SIGTERM) == -1) { + //进程可能已经退出了 + WarnL << "kill process " << pid << " failed:" << get_uv_errmsg(); + return; + } +#endif // _WIN32 - if (::kill(pid, force ? SIGKILL : SIGTERM) == -1) { - //进程可能已经退出了 - WarnL << "kill process " << pid << " failed:" << get_uv_errmsg(); - return; - } if(force){ //发送SIGKILL信号后,阻塞等待退出 diff --git a/server/Process.h b/server/Process.h index cce8470a..392ccbbf 100644 --- a/server/Process.h +++ b/server/Process.h @@ -23,10 +23,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef IPTV_PROCESS_H -#define IPTV_PROCESS_H +#ifndef ZLMEDIAKIT_PROCESS_H +#define ZLMEDIAKIT_PROCESS_H +#ifdef _WIN32 +typedef int pid_t; +#else #include +#endif // _WIN32 + #include #include using namespace std; @@ -45,4 +50,4 @@ private: }; -#endif //IPTV_PROCESS_H +#endif //ZLMEDIAKIT_PROCESS_H diff --git a/server/System.cpp b/server/System.cpp index dc9fdb15..df666120 100644 --- a/server/System.cpp +++ b/server/System.cpp @@ -24,239 +24,36 @@ * SOFTWARE. */ -#include "System.h" -#include -#include -#include +#if !defined(_WIN32) #include #include -#include #include -#ifndef ANDROID +#if !defined(ANDROID) #include -#endif -#include -#include -#include -#include "Util/mini.h" -#include "Util/util.h" -#include "Util/logger.h" -#include "Util/onceToken.h" -#include "Util/NoticeCenter.h" +#endif//!defined(ANDROID) +#endif//!defined(_WIN32) + #include "System.h" +#include +#include +#include +#include "Util/logger.h" +#include "Util/NoticeCenter.h" #include "Util/uv_errno.h" -#include "Util/CMD.h" -#include "Util/MD5.h" using namespace toolkit; const int MAX_STACK_FRAMES = 128; #define BroadcastOnCrashDumpArgs int &sig,const vector > &stack const char kBroadcastOnCrashDump[] = "kBroadcastOnCrashDump"; -//#if defined(__MACH__) || defined(__APPLE__) -//#define TEST_LINUX -//#endif - -vector splitWithEmptyLine(const string &s, const char *delim) { - vector ret; - int last = 0; - int index = s.find(delim, last); - while (index != string::npos) { - ret.push_back(s.substr(last, index - last)); - last = index + strlen(delim); - index = s.find(delim, last); - } - if (s.size() - last > 0) { - ret.push_back(s.substr(last)); - } - return ret; -} - -map splitTopStr(const string &cmd_str) { - map ret; - auto lines = splitWithEmptyLine(cmd_str, "\n"); - int i = 0; - for (auto &line : lines) { - if(i++ < 1 && line.empty()){ - continue; - } - if (line.empty()) { - break; - } - auto line_vec = split(line, ":"); - - if (line_vec.size() < 2) { - continue; - } - trim(line_vec[0], " \r\n\t"); - auto args_vec = split(line_vec[1], ","); - for (auto &arg : args_vec) { - auto arg_vec = split(trim(arg, " \r\n\t."), " "); - if (arg_vec.size() < 2) { - continue; - } - ret[line_vec[0]].emplace(arg_vec[1], arg_vec[0]); - } - } - return ret; -} - -bool System::getSystemUsage(SystemUsage &usage) { - try { -#if defined(__linux) || defined(__linux__) || defined(TEST_LINUX) - string cmd_str; -#if !defined(TEST_LINUX) - cmd_str = System::execute("top -b -n 1"); -#else - cmd_str = "top - 07:21:31 up 5:48, 2 users, load average: 0.03, 0.62, 0.54\n" - "Tasks: 80 total, 1 running, 78 sleeping, 0 stopped, 1 zombie\n" - "%Cpu(s): 0.8 us, 0.4 sy, 0.0 ni, 98.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\n" - "KiB Mem: 2058500 total, 249100 used, 1809400 free, 19816 buffers\n" - "KiB Swap: 1046524 total, 0 used, 1046524 free. 153012 cached Mem\n" - "\n"; +#ifdef _WIN32 +#define popen _popen +#define pclose _pclose #endif - if (cmd_str.empty()) { - WarnL << "System::execute(\"top -b -n 1\") return empty"; - return false; - } - auto topMap = splitTopStr(cmd_str); - - usage.task_total = topMap["Tasks"]["total"]; - usage.task_running = topMap["Tasks"]["running"]; - usage.task_sleeping = topMap["Tasks"]["sleeping"]; - usage.task_stopped = topMap["Tasks"]["stopped"]; - - usage.cpu_user = topMap["%Cpu(s)"]["us"]; - usage.cpu_sys = topMap["%Cpu(s)"]["sy"]; - usage.cpu_idle = topMap["%Cpu(s)"]["id"]; - - usage.mem_total = topMap["KiB Mem"]["total"]; - usage.mem_free = topMap["KiB Mem"]["free"]; - usage.mem_used = topMap["KiB Mem"]["used"]; - return true; - -#elif defined(__MACH__) || defined(__APPLE__) - /* - "Processes: 275 total, 2 running, 1 stuck, 272 sleeping, 1258 threads \n" - "2018/09/12 10:41:32\n" - "Load Avg: 2.06, 2.88, 2.86 \n" - "CPU usage: 14.54% user, 25.45% sys, 60.0% idle \n" - "SharedLibs: 117M resident, 37M data, 15M linkedit.\n" - "MemRegions: 46648 total, 3654M resident, 62M private, 714M shared.\n" - "PhysMem: 7809M used (1906M wired), 381M unused.\n" - "VM: 751G vsize, 614M framework vsize, 0(0) swapins, 0(0) swapouts.\n" - "Networks: packets: 502366/248M in, 408957/87M out.\n" - "Disks: 349435/6037M read, 78622/2577M written."; - */ - - string cmd_str = System::execute("top -l 1"); - if(cmd_str.empty()){ - WarnL << "System::execute(\"top -n 1\") return empty"; - return false; - } - auto topMap = splitTopStr(cmd_str); - usage.task_total = topMap["Processes"]["total"]; - usage.task_running = topMap["Processes"]["running"]; - usage.task_sleeping = topMap["Processes"]["sleeping"]; - usage.task_stopped = topMap["Processes"]["stuck"]; - - usage.cpu_user = topMap["CPU usage"]["user"]; - usage.cpu_sys = topMap["CPU usage"]["sys"]; - usage.cpu_idle = topMap["CPU usage"]["idle"]; - - usage.mem_free = topMap["PhysMem"]["unused"].as() * 1024 * 1024; - usage.mem_used = topMap["PhysMem"]["used"].as() * 1024 * 1024; - usage.mem_total = usage.mem_free + usage.mem_used; - return true; -#else - WarnL << "System not supported"; - return false; -#endif - } catch (std::exception &ex) { - WarnL << ex.what(); - return false; - } -} - -bool System::getNetworkUsage(vector &usage) { - try { -#if defined(__linux) || defined(__linux__) || defined(TEST_LINUX) - string cmd_str; -#if !defined(TEST_LINUX) - cmd_str = System::execute("cat /proc/net/dev"); -#else - cmd_str = - "Inter-| Receive | Transmit\n" - " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n" - " lo: 475978 7546 0 0 0 0 0 0 475978 7546 0 0 0 0 0 0\n" - "enp3s0: 151747818 315136 0 0 0 0 0 145 1590783447 1124616 0 0 0 0 0 0"; -#endif - if (cmd_str.empty()) { - return false; - } - auto lines = split(cmd_str, "\n"); - int i = 0; - vector column_name_vec; - vector category_prefix_vec; - for (auto &line : lines) { - switch (i++) { - case 0: { - category_prefix_vec = split(line, "|"); - } - break; - case 1: { - auto category_suffix_vec = split(line, "|"); - int j = 0; - for (auto &category_suffix : category_suffix_vec) { - auto column_suffix_vec = split(category_suffix, " "); - for (auto &column_suffix : column_suffix_vec) { - column_name_vec.emplace_back(trim(category_prefix_vec[j]) + "-" + trim(column_suffix)); - } - j++; - } - } - break; - default: { - mINI valMap; - auto vals = split(line, " "); - int j = 0; - for (auto &val : vals) { - valMap[column_name_vec[j++]] = trim(val, " \r\n\t:"); - } - usage.emplace_back(NetworkUsage()); - auto &ifrUsage = usage.back(); - ifrUsage.interface = valMap["Inter--face"]; - ifrUsage.recv_bytes = valMap["Receive-bytes"]; - ifrUsage.recv_packets = valMap["Receive-packets"]; - ifrUsage.snd_bytes = valMap["Transmit-bytes"]; - ifrUsage.snd_packets = valMap["Transmit-packets"]; - } - break; - } - } - return true; -#else - WarnL << "System not supported"; - return false; -#endif - } catch (std::exception &ex) { - WarnL << ex.what(); - return false; - } -} - - -bool System::getTcpUsage(System::TcpUsage &usage) { - usage.established = atoi(trim(System::execute("netstat -na|grep ESTABLISHED|wc -l")).data()); - usage.syn_recv = atoi(trim(System::execute("netstat -na|grep SYN_RECV|wc -l")).data()); - usage.time_wait = atoi(trim(System::execute("netstat -na|grep TIME_WAIT|wc -l")).data()); - usage.close_wait = atoi(trim(System::execute("netstat -na|grep CLOSE_WAIT|wc -l")).data()); - return true; -} string System::execute(const string &cmd) { -// DebugL << cmd; - FILE *fPipe = popen(cmd.data(), "r"); + FILE *fPipe = NULL; + fPipe = popen(cmd.data(), "r"); if(!fPipe){ return ""; } @@ -269,12 +66,12 @@ string System::execute(const string &cmd) { return ret; } +#if !defined(ANDROID) && !defined(_WIN32) static string addr2line(const string &address) { string cmd = StrPrinter << "addr2line -e " << exePath() << " " << address; return System::execute(cmd); } -#ifndef ANDROID static void sig_crash(int sig) { signal(sig, SIG_DFL); void *array[MAX_STACK_FRAMES]; @@ -294,14 +91,13 @@ static void sig_crash(int sig) { #endif//__linux } free(strings); - NoticeCenter::Instance().emitEvent(kBroadcastOnCrashDump,sig,stack); } - -#endif//#ifndef ANDROID +#endif // !defined(ANDROID) && !defined(_WIN32) void System::startDaemon() { +#ifndef _WIN32 static pid_t pid; do{ pid = fork(); @@ -336,21 +132,11 @@ void System::startDaemon() { DebugL << "waitpid被中断:" << get_uv_errmsg(); }while (true); }while (true); -} - - - -static string currentDateTime(){ - time_t ts = time(NULL); - std::tm tm_snapshot; - localtime_r(&ts, &tm_snapshot); - - char buffer[1024] = {0}; - std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm_snapshot); - return buffer; +#endif // _WIN32 } void System::systemSetup(){ +#if !defined(_WIN32) struct rlimit rlim,rlim_new; if (getrlimit(RLIMIT_CORE, &rlim)==0) { rlim_new.rlim_cur = rlim_new.rlim_max = RLIM_INFINITY; @@ -373,11 +159,9 @@ void System::systemSetup(){ #ifndef ANDROID signal(SIGSEGV, sig_crash); signal(SIGABRT, sig_crash); -#endif//#ifndef ANDROID - NoticeCenter::Instance().addListener(nullptr,kBroadcastOnCrashDump,[](BroadcastOnCrashDumpArgs){ stringstream ss; - ss << "## crash date:" << currentDateTime() << endl; + ss << "## crash date:" << getTimeStr("%Y-%m-%d %H:%M:%S") << endl; ss << "## exe: " << exeName() << endl; ss << "## signal: " << sig << endl; ss << "## stack: " << endl; @@ -391,8 +175,9 @@ void System::systemSetup(){ ofstream out(StrPrinter << exeDir() << "/crash." << getpid(), ios::out | ios::binary | ios::trunc); out << stack_info; out.flush(); - cerr << stack_info << endl; }); +#endif// ANDROID +#endif//!defined(_WIN32) } diff --git a/server/System.h b/server/System.h index c8857a73..565b99b3 100644 --- a/server/System.h +++ b/server/System.h @@ -24,67 +24,17 @@ * SOFTWARE. */ -#ifndef IPTV_BASH_H -#define IPTV_BASH_H +#ifndef ZLMEDIAKIT_SYSTEM_H +#define ZLMEDIAKIT_SYSTEM_H -#include #include -#include -#include -#include "Util/NoticeCenter.h" - using namespace std; -using namespace toolkit; class System { public: - typedef struct { - uint32_t task_total; - uint32_t task_running; - uint32_t task_sleeping; - uint32_t task_stopped; - - uint64_t mem_total; - uint64_t mem_free; - uint64_t mem_used; - - float cpu_user; - float cpu_sys; - float cpu_idle; - } SystemUsage; - - typedef struct { - uint64_t recv_bytes; - uint64_t recv_packets; - uint64_t snd_bytes; - uint64_t snd_packets; - string interface; - } NetworkUsage; - - typedef struct { - uint64_t available; - uint64_t used; - float used_per; - string mounted_on; - string filesystem; - bool mounted; - } DiskUsage; - - typedef struct { - uint32_t established; - uint32_t syn_recv; - uint32_t time_wait; - uint32_t close_wait; - } TcpUsage; - - static bool getSystemUsage(SystemUsage &usage); - static bool getNetworkUsage(vector &usage); - static bool getTcpUsage(TcpUsage &usage); static string execute(const string &cmd); static void startDaemon(); static void systemSetup(); - }; - -#endif //IPTV_BASH_H +#endif //ZLMEDIAKIT_SYSTEM_H diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 04dd3715..b2eb6713 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -47,10 +47,7 @@ #include "WebHook.h" #include "Thread/WorkThreadPool.h" #include "Rtp/RtpSelector.h" - -#if !defined(_WIN32) #include "FFmpegSource.h" -#endif//!defined(_WIN32) using namespace Json; using namespace toolkit; @@ -268,10 +265,8 @@ static inline string getProxyKey(const string &vhost,const string &app,const str return vhost + "/" + app + "/" + stream; } -#if !defined(_WIN32) static unordered_map s_ffmpegMap; static recursive_mutex s_ffmpegMapMtx; -#endif//#if !defined(_WIN32) /** * 安装api接口 @@ -646,7 +641,6 @@ void installWebApi() { val["data"]["flag"] = s_proxyMap.erase(allArgs["key"]) == 1; }); -#if !defined(_WIN32) static auto addFFmpegSource = [](const string &src_url, const string &dst_url, int timeout_ms, @@ -713,7 +707,6 @@ void installWebApi() { API_REGIST(api,delFFmepgSource,{ api_delFFmpegSource(API_ARGS_VALUE); }); -#endif //新增http api下载可执行程序文件接口 //测试url http://127.0.0.1/index/api/downloadBin @@ -932,10 +925,8 @@ void unInstallWebApi(){ s_proxyMap.clear(); } -#if !defined(_WIN32) { lock_guard lck(s_ffmpegMapMtx); s_ffmpegMap.clear(); } -#endif } \ No newline at end of file