diff --git a/api/include/common.h b/api/include/common.h index 041968c4..c54f7170 100755 --- a/api/include/common.h +++ b/api/include/common.h @@ -132,6 +132,13 @@ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl); */ API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port); +/** + * 创建shell服务器 + * @param port shell监听端口 + * @return 0:失败,非0:端口号 + */ +API_EXPORT uint16_t API_CALL mk_shell_server_start(uint16_t port); + /** * 打印日志 * @param level 日志级别,支持0~4 diff --git a/api/source/common.cpp b/api/source/common.cpp index 287559d3..34b701d1 100755 --- a/api/source/common.cpp +++ b/api/source/common.cpp @@ -35,6 +35,7 @@ #include "Rtsp/RtspSession.h" #include "Rtmp/RtmpSession.h" #include "Http/HttpSession.h" +#include "Shell/ShellSession.h" using namespace std; using namespace toolkit; using namespace mediakit; @@ -42,6 +43,7 @@ using namespace mediakit; static TcpServer::Ptr rtsp_server[2]; static TcpServer::Ptr rtmp_server[2]; static TcpServer::Ptr http_server[2]; +static TcpServer::Ptr shell_server; #ifdef ENABLE_RTPPROXY #include "Rtp/UdpRecver.h" @@ -190,6 +192,18 @@ API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port){ #endif } +API_EXPORT uint16_t API_CALL mk_shell_server_start(uint16_t port){ + try { + shell_server = std::make_shared(); + shell_server->start(port); + return shell_server->getPort(); + } catch (std::exception &ex) { + shell_server.reset(); + WarnL << ex.what(); + return 0; + } +} + API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) { assert(file && function && fmt); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line); diff --git a/api/tests/server.cpp b/api/tests/server.cpp index 38acf606..05d3564e 100644 --- a/api/tests/server.cpp +++ b/api/tests/server.cpp @@ -396,6 +396,7 @@ int main(int argc, char *argv[]) { mk_http_server_start(80, false); mk_rtsp_server_start(554, false); mk_rtmp_server_start(1935, false); + mk_shell_server_start(9000); mk_rtp_server_start(10000); mk_events events = {