mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
移植Windows
This commit is contained in:
parent
bede5500c8
commit
25286c4377
@ -125,11 +125,7 @@ endif ()
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
#主服务器
|
#主服务器
|
||||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
add_subdirectory(server)
|
||||||
add_subdirectory(server)
|
|
||||||
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|
||||||
add_subdirectory(server)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,8 +2,21 @@
|
|||||||
file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h )
|
file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h )
|
||||||
add_library(jsoncpp STATIC ${jsoncpp_src_list})
|
add_library(jsoncpp STATIC ${jsoncpp_src_list})
|
||||||
|
|
||||||
file(GLOB MediaServer_src_list ./*.cpp ./*.h)
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
message(STATUS ${MediaServer_src_list})
|
||||||
|
|
||||||
add_executable(MediaServer ${MediaServer_src_list})
|
add_executable(MediaServer ${MediaServer_src_list})
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set_target_properties(MediaServer PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST})
|
target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
|
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
|
||||||
@ -42,10 +42,13 @@
|
|||||||
#include "Http/HttpSession.h"
|
#include "Http/HttpSession.h"
|
||||||
#include "Network/TcpServer.h"
|
#include "Network/TcpServer.h"
|
||||||
#include "Player/PlayerProxy.h"
|
#include "Player/PlayerProxy.h"
|
||||||
#include "FFmpegSource.h"
|
|
||||||
#include "Util/MD5.h"
|
#include "Util/MD5.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
#include "FFmpegSource.h"
|
||||||
|
#endif//!defined(_WIN32)
|
||||||
|
|
||||||
using namespace Json;
|
using namespace Json;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -245,8 +248,10 @@ static inline string getProxyKey(const string &vhost,const string &app,const str
|
|||||||
return vhost + "/" + app + "/" + stream;
|
return vhost + "/" + app + "/" + stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
static unordered_map<string ,FFmpegSource::Ptr> s_ffmpegMap;
|
static unordered_map<string ,FFmpegSource::Ptr> s_ffmpegMap;
|
||||||
static recursive_mutex s_ffmpegMapMtx;
|
static recursive_mutex s_ffmpegMapMtx;
|
||||||
|
#endif//#if !defined(_WIN32)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安装api接口
|
* 安装api接口
|
||||||
@ -322,6 +327,7 @@ void installWebApi() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
//重启服务器,只有Daemon方式才能重启,否则是直接关闭!
|
//重启服务器,只有Daemon方式才能重启,否则是直接关闭!
|
||||||
//测试url http://127.0.0.1/index/api/restartServer
|
//测试url http://127.0.0.1/index/api/restartServer
|
||||||
API_REGIST(api,restartServer,{
|
API_REGIST(api,restartServer,{
|
||||||
@ -340,6 +346,7 @@ void installWebApi() {
|
|||||||
});
|
});
|
||||||
val["msg"] = "服务器将在一秒后自动重启";
|
val["msg"] = "服务器将在一秒后自动重启";
|
||||||
});
|
});
|
||||||
|
#endif//#if !defined(_WIN32)
|
||||||
|
|
||||||
|
|
||||||
//获取流列表,可选筛选参数
|
//获取流列表,可选筛选参数
|
||||||
@ -507,6 +514,7 @@ void installWebApi() {
|
|||||||
val["data"]["flag"] = s_proxyMap.erase(allArgs["key"]) == 1;
|
val["data"]["flag"] = s_proxyMap.erase(allArgs["key"]) == 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
static auto addFFmepgSource = [](const string &src_url,
|
static auto addFFmepgSource = [](const string &src_url,
|
||||||
const string &dst_url,
|
const string &dst_url,
|
||||||
int timeout_ms,
|
int timeout_ms,
|
||||||
@ -563,6 +571,7 @@ void installWebApi() {
|
|||||||
lock_guard<decltype(s_ffmpegMapMtx)> lck(s_ffmpegMapMtx);
|
lock_guard<decltype(s_ffmpegMapMtx)> lck(s_ffmpegMapMtx);
|
||||||
val["data"]["flag"] = s_ffmpegMap.erase(allArgs["key"]) == 1;
|
val["data"]["flag"] = s_ffmpegMap.erase(allArgs["key"]) == 1;
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////以下是注册的Hook API////////////
|
////////////以下是注册的Hook API////////////
|
||||||
API_REGIST(hook,on_publish,{
|
API_REGIST(hook,on_publish,{
|
||||||
@ -600,12 +609,12 @@ void installWebApi() {
|
|||||||
throw SuccessException();
|
throw SuccessException();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
API_REGIST_INVOKER(hook,on_stream_not_found,{
|
API_REGIST_INVOKER(hook,on_stream_not_found,{
|
||||||
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
|
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("vhost","app","stream");
|
CHECK_ARGS("vhost","app","stream");
|
||||||
|
|
||||||
#if 1
|
|
||||||
//通过FFmpeg按需拉流
|
//通过FFmpeg按需拉流
|
||||||
GET_CONFIG(int,rtmp_port,Rtmp::kPort);
|
GET_CONFIG(int,rtmp_port,Rtmp::kPort);
|
||||||
string dst_url = StrPrinter
|
string dst_url = StrPrinter
|
||||||
@ -627,9 +636,14 @@ void installWebApi() {
|
|||||||
}
|
}
|
||||||
invoker("200 OK", headerOut, val.toStyledString());
|
invoker("200 OK", headerOut, val.toStyledString());
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
API_REGIST_INVOKER(hook,on_stream_not_found,{
|
||||||
|
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
|
||||||
|
CHECK_SECRET();
|
||||||
|
CHECK_ARGS("vhost","app","stream");
|
||||||
//通过内置支持的rtsp/rtmp按需拉流
|
//通过内置支持的rtsp/rtmp按需拉流
|
||||||
addStreamProxy(allArgs["vhost"],
|
addStreamProxy(allArgs["vhost"],
|
||||||
allArgs["app"],
|
allArgs["app"],
|
||||||
@ -648,9 +662,8 @@ void installWebApi() {
|
|||||||
}
|
}
|
||||||
invoker("200 OK", headerOut, val.toStyledString());
|
invoker("200 OK", headerOut, val.toStyledString());
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
|
#endif // !defined(_WIN32)
|
||||||
|
|
||||||
API_REGIST(hook,on_record_mp4,{
|
API_REGIST(hook,on_record_mp4,{
|
||||||
//录制mp4分片完毕事件
|
//录制mp4分片完毕事件
|
||||||
@ -701,8 +714,10 @@ void unInstallWebApi(){
|
|||||||
s_proxyMap.clear();
|
s_proxyMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
{
|
{
|
||||||
lock_guard<recursive_mutex> lck(s_ffmpegMapMtx);
|
lock_guard<recursive_mutex> lck(s_ffmpegMapMtx);
|
||||||
s_ffmpegMap.clear();
|
s_ffmpegMap.clear();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
@ -27,7 +27,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "System.h"
|
|
||||||
#include "jsoncpp/json.h"
|
#include "jsoncpp/json.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
|
@ -43,9 +43,12 @@
|
|||||||
#include "RtmpMuxer/FlvMuxer.h"
|
#include "RtmpMuxer/FlvMuxer.h"
|
||||||
#include "Player/PlayerProxy.h"
|
#include "Player/PlayerProxy.h"
|
||||||
#include "Http/WebSocketSession.h"
|
#include "Http/WebSocketSession.h"
|
||||||
#include "System.h"
|
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
#include "System.h"
|
||||||
|
#endif//!defined(_WIN32)
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -105,6 +108,7 @@ public:
|
|||||||
CMD_main() {
|
CMD_main() {
|
||||||
_parser.reset(new OptionParser(nullptr));
|
_parser.reset(new OptionParser(nullptr));
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
(*_parser) << Option('d',/*该选项简称,如果是\x00则说明无简称*/
|
(*_parser) << Option('d',/*该选项简称,如果是\x00则说明无简称*/
|
||||||
"daemon",/*该选项全称,每个选项必须有全称;不得为null或空字符串*/
|
"daemon",/*该选项全称,每个选项必须有全称;不得为null或空字符串*/
|
||||||
Option::ArgNone,/*该选项后面必须跟值*/
|
Option::ArgNone,/*该选项后面必须跟值*/
|
||||||
@ -112,6 +116,7 @@ public:
|
|||||||
false,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/
|
false,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/
|
||||||
"是否以Daemon方式启动",/*该选项说明文字*/
|
"是否以Daemon方式启动",/*该选项说明文字*/
|
||||||
nullptr);
|
nullptr);
|
||||||
|
#endif//!defined(_WIN32)
|
||||||
|
|
||||||
(*_parser) << Option('l',/*该选项简称,如果是\x00则说明无简称*/
|
(*_parser) << Option('l',/*该选项简称,如果是\x00则说明无简称*/
|
||||||
"level",/*该选项全称,每个选项必须有全称;不得为null或空字符串*/
|
"level",/*该选项全称,每个选项必须有全称;不得为null或空字符串*/
|
||||||
@ -158,12 +163,14 @@ extern void unInstallWebApi();
|
|||||||
extern void installWebHook();
|
extern void installWebHook();
|
||||||
extern void unInstallWebHook();
|
extern void unInstallWebHook();
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
static void inline listen_shell_input(){
|
static void inline listen_shell_input(){
|
||||||
cout << "> 欢迎进入命令模式,你可以输入\"help\"命令获取帮助" << endl;
|
cout << "> 欢迎进入命令模式,你可以输入\"help\"命令获取帮助" << endl;
|
||||||
cout << "> " << std::flush;
|
cout << "> " << std::flush;
|
||||||
|
|
||||||
signal(SIGTTOU,SIG_IGN);
|
signal(SIGTTOU,SIG_IGN);
|
||||||
signal(SIGTTIN,SIG_IGN);
|
signal(SIGTTIN,SIG_IGN);
|
||||||
|
|
||||||
SockUtil::setNoBlocked(STDIN_FILENO);
|
SockUtil::setNoBlocked(STDIN_FILENO);
|
||||||
auto oninput = [](int event) {
|
auto oninput = [](int event) {
|
||||||
if (event & Event_Read) {
|
if (event & Event_Read) {
|
||||||
@ -193,6 +200,8 @@ static void inline listen_shell_input(){
|
|||||||
};
|
};
|
||||||
EventPollerPool::Instance().getFirstPoller()->addEvent(STDIN_FILENO, Event_Read | Event_Error | Event_LT,oninput);
|
EventPollerPool::Instance().getFirstPoller()->addEvent(STDIN_FILENO, Event_Read | Event_Error | Event_LT,oninput);
|
||||||
}
|
}
|
||||||
|
#endif//!defined(_WIN32)
|
||||||
|
|
||||||
int main(int argc,char *argv[]) {
|
int main(int argc,char *argv[]) {
|
||||||
{
|
{
|
||||||
CMD_main cmd_main;
|
CMD_main cmd_main;
|
||||||
@ -218,13 +227,14 @@ int main(int argc,char *argv[]) {
|
|||||||
Logger::Instance().add(std::make_shared<FileChannel>("FileChannel", exePath() + ".log", logLevel));
|
Logger::Instance().add(std::make_shared<FileChannel>("FileChannel", exePath() + ".log", logLevel));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
if (bDaemon) {
|
if (bDaemon) {
|
||||||
//启动守护进程
|
//启动守护进程
|
||||||
System::startDaemon();
|
System::startDaemon();
|
||||||
}
|
}
|
||||||
|
|
||||||
//开启崩溃捕获等
|
//开启崩溃捕获等
|
||||||
System::systemSetup();
|
System::systemSetup();
|
||||||
|
#endif//!defined(_WIN32)
|
||||||
|
|
||||||
//启动异步日志线程
|
//启动异步日志线程
|
||||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||||
@ -275,10 +285,12 @@ int main(int argc,char *argv[]) {
|
|||||||
installWebHook();
|
installWebHook();
|
||||||
InfoL << "已启动http hook 接口";
|
InfoL << "已启动http hook 接口";
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
if (!bDaemon) {
|
if (!bDaemon) {
|
||||||
//交互式shell输入
|
//交互式shell输入
|
||||||
listen_shell_input();
|
listen_shell_input();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//设置退出信号处理函数
|
//设置退出信号处理函数
|
||||||
static semaphore sem;
|
static semaphore sem;
|
||||||
@ -287,7 +299,10 @@ int main(int argc,char *argv[]) {
|
|||||||
signal(SIGINT, SIG_IGN);// 设置退出信号
|
signal(SIGINT, SIG_IGN);// 设置退出信号
|
||||||
sem.post();
|
sem.post();
|
||||||
});// 设置退出信号
|
});// 设置退出信号
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
signal(SIGHUP, [](int) { mediakit::loadIniConfig(ini_file.data()); });
|
signal(SIGHUP, [](int) { mediakit::loadIniConfig(ini_file.data()); });
|
||||||
|
#endif
|
||||||
sem.wait();
|
sem.wait();
|
||||||
}
|
}
|
||||||
unInstallWebApi();
|
unInstallWebApi();
|
||||||
|
Loading…
Reference in New Issue
Block a user