新增支持Python混合编程模式 (#4579)

This commit is contained in:
夏楚
2026-02-10 13:28:42 +08:00
committed by GitHub
parent da9deb352c
commit 6d520ea6a3
25 changed files with 1553 additions and 55 deletions

View File

@@ -43,6 +43,10 @@
#include "ZLMVersion.h"
#endif
#if defined(ENABLE_PYTHON)
#include "pyinvoker.h"
#endif
#include "System.h"
using namespace std;
@@ -59,7 +63,7 @@ const string kSSLPort = HTTP_FIELD"sslport";
onceToken token1([](){
mINI::Instance()[kPort] = 80;
mINI::Instance()[kSSLPort] = 443;
},nullptr);
});
}//namespace Http
// //////////SHELL配置/////////// [AUTO-TRANSLATED:f023ec45]
@@ -69,7 +73,7 @@ namespace Shell {
const string kPort = SHELL_FIELD"port";
onceToken token1([](){
mINI::Instance()[kPort] = 9000;
},nullptr);
});
} //namespace Shell
// //////////RTSP服务器配置/////////// [AUTO-TRANSLATED:950e1981]
@@ -81,7 +85,7 @@ const string kSSLPort = RTSP_FIELD"sslport";
onceToken token1([](){
mINI::Instance()[kPort] = 554;
mINI::Instance()[kSSLPort] = 332;
},nullptr);
});
} //namespace Rtsp
@@ -94,7 +98,7 @@ const string kSSLPort = RTMP_FIELD"sslport";
onceToken token1([](){
mINI::Instance()[kPort] = 1935;
mINI::Instance()[kSSLPort] = 19350;
},nullptr);
});
} //namespace RTMP
// //////////Rtp代理相关配置/////////// [AUTO-TRANSLATED:7b285587]
@@ -104,9 +108,17 @@ namespace RtpProxy {
const string kPort = RTP_PROXY_FIELD"port";
onceToken token1([](){
mINI::Instance()[kPort] = 10000;
},nullptr);
});
} //namespace RtpProxy
namespace Python {
#define Python_FIELD "python."
const string kPlugin = Python_FIELD"plugin";
onceToken token1([](){
mINI::Instance()[kPlugin] = "";
});
} //namespace Python
} // namespace mediakit
@@ -261,6 +273,16 @@ int start_main(int argc,char *argv[]) {
}
#endif //! defined(_WIN32)
// 设置poller线程数和cpu亲和性,该函数必须在使用ZLToolKit网络相关对象之前调用才能生效 [AUTO-TRANSLATED:7f03a1e5]
// Set the number of poller threads and CPU affinity. This function must be called before using ZLToolKit network related objects to take effect.
// 如果需要调用getSnap和addFFmpegSource接口可以关闭cpu亲和性 [AUTO-TRANSLATED:7629f7bc]
// If you need to call the getSnap and addFFmpegSource interfaces, you can turn off CPU affinity
EventPollerPool::setPoolSize(threads);
WorkThreadPool::setPoolSize(threads);
EventPollerPool::enableCpuAffinity(affinity);
WorkThreadPool::enableCpuAffinity(affinity);
// 开启崩溃捕获等 [AUTO-TRANSLATED:9c7c759c]
// Enable crash capture, etc.
System::systemSetup();
@@ -317,15 +339,6 @@ int start_main(int argc,char *argv[]) {
uint16_t httpsPort = mINI::Instance()[Http::kSSLPort];
uint16_t rtpPort = mINI::Instance()[RtpProxy::kPort];
// 设置poller线程数和cpu亲和性,该函数必须在使用ZLToolKit网络相关对象之前调用才能生效 [AUTO-TRANSLATED:7f03a1e5]
// Set the number of poller threads and CPU affinity. This function must be called before using ZLToolKit network related objects to take effect.
// 如果需要调用getSnap和addFFmpegSource接口可以关闭cpu亲和性 [AUTO-TRANSLATED:7629f7bc]
// If you need to call the getSnap and addFFmpegSource interfaces, you can turn off CPU affinity
EventPollerPool::setPoolSize(threads);
WorkThreadPool::setPoolSize(threads);
EventPollerPool::enableCpuAffinity(affinity);
// 简单的telnet服务器可用于服务器调试但是不能使用23端口否则telnet上了莫名其妙的现象 [AUTO-TRANSLATED:f9324c6e]
// Simple telnet server, can be used for server debugging, but cannot use port 23, otherwise telnet will have inexplicable phenomena
// 测试方法:telnet 127.0.0.1 9000 [AUTO-TRANSLATED:de0ac883]
@@ -494,12 +507,25 @@ int start_main(int argc,char *argv[]) {
g_reload_certificates();
});
#endif
#if defined(ENABLE_PYTHON)
// 初始化python解释器
auto &ref = PythonInvoker::Instance();
auto py_plugin = mINI::Instance()[Python::kPlugin];
if (!py_plugin.empty()) {
ref.load(py_plugin);
}
#endif
sem.wait();
}
unInstallWebApi();
unInstallWebHook();
onProcessExited();
#if defined(ENABLE_PYTHON)
PythonInvoker::release();
#endif
// 休眠1秒再退出防止资源释放顺序错误 [AUTO-TRANSLATED:1b11a74f]
// sleep for 1 second before exiting, to prevent resource release order errors
InfoL << "程序退出中,请等待...";