From b782832a74e73f5929ec36d4cd4658263f53eb54 Mon Sep 17 00:00:00 2001 From: Dw9 Date: Thu, 22 Sep 2022 21:16:56 +0800 Subject: [PATCH 1/2] fix typo --- www/webrtc/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/www/webrtc/index.html b/www/webrtc/index.html index a2ec0d4f..d4eb1776 100644 --- a/www/webrtc/index.html +++ b/www/webrtc/index.html @@ -46,14 +46,14 @@

- - echo - push - play + + echo + push + play

- -

@@ -98,7 +98,7 @@ url = "http://127.0.0.1"+"/index/api/webrtc?app=live&stream=test&type=play" } document.getElementById('streamUrl').value = url - document.getElementsByName("methond").forEach((el,idx)=>{ + document.getElementsByName("method").forEach((el,idx)=>{ el.onclick=function(e){ let url = new URL(document.getElementById('streamUrl').value); url.searchParams.set("type",el.value) @@ -118,14 +118,14 @@ opt = document.createElement('option'); opt.text = r.label +"("+r.width+"x"+r.height+")"; opt.value = r; - document.getElementById("resilution").add(opt,null) + document.getElementById("resolution").add(opt,null) //console.log(opt.text.match(/\d+/g)) }) function start_play(){ - let elr = document.getElementById("resilution"); + let elr = document.getElementById("resolution"); let res = elr.options[elr.selectedIndex].text.match(/\d+/g); let h = parseInt(res.pop()); let w = parseInt(res.pop()); @@ -204,7 +204,7 @@ function start() { stop(); - let elr = document.getElementById("resilution"); + let elr = document.getElementById("resolution"); let res = elr.options[elr.selectedIndex].text.match(/\d+/g); let h = parseInt(res.pop()); let w = parseInt(res.pop()); From 43bf7c7918812ddcc11ea56a3f88fd44f8704de3 Mon Sep 17 00:00:00 2001 From: Dw9 Date: Thu, 22 Sep 2022 21:18:34 +0800 Subject: [PATCH 2/2] c api support srt server --- api/include/mk_common.h | 9 ++++++++- api/source/mk_common.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ api/tests/server.c | 1 + server/main.cpp | 5 +---- srt/SrtTransport.cpp | 9 +++++++++ 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/api/include/mk_common.h b/api/include/mk_common.h index 7105f0d3..74a2d82a 100755 --- a/api/include/mk_common.h +++ b/api/include/mk_common.h @@ -162,11 +162,18 @@ API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port); /** * 创建rtc服务器 - * @param port rtp监听端口 + * @param port rtc监听端口 * @return 0:失败,非0:端口号 */ API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port); +/** + * 创建srt服务器 + * @param port srt监听端口 + * @return 0:失败,非0:端口号 + */ +API_EXPORT uint16_t API_CALL mk_srt_server_start(uint16_t port); + /** * 创建shell服务器 diff --git a/api/source/mk_common.cpp b/api/source/mk_common.cpp index 09a0d4fa..9e98db1d 100644 --- a/api/source/mk_common.cpp +++ b/api/source/mk_common.cpp @@ -40,6 +40,11 @@ static std::shared_ptr rtpServer; static std::shared_ptr rtcServer; #endif +#if defined(ENABLE_SRT) +#include "../srt/SrtSession.hpp" +static std::shared_ptr srtServer; +#endif + //////////////////////////environment init/////////////////////////// API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) { @@ -62,8 +67,15 @@ API_EXPORT void API_CALL mk_stop_all_server(){ CLEAR_ARR(rtsp_server); CLEAR_ARR(rtmp_server); CLEAR_ARR(http_server); + shell_server = nullptr; #ifdef ENABLE_RTPPROXY rtpServer = nullptr; +#endif +#ifdef ENABLE_WEBRTC + rtcServer = nullptr; +#endif +#ifdef ENABLE_SRT + srtServer = nullptr; #endif stopAllTcpServer(); } @@ -254,6 +266,36 @@ API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port) { #endif } +API_EXPORT uint16_t API_CALL mk_srt_server_start(uint16_t port) { +#ifdef ENABLE_SRT + try { + srtServer = std::make_shared(); + srtServer->setOnCreateSocket([](const EventPoller::Ptr &poller, const Buffer::Ptr &buf, struct sockaddr *, int) { + if (!buf) { + return Socket::createSocket(poller, false); + } + auto new_poller = SRT::SrtSession::queryPoller(buf); + if (!new_poller) { + //握手第一阶段 + return Socket::createSocket(poller, false); + } + return Socket::createSocket(new_poller, false); + }); + srtServer->start(port); + return srtServer->getPort(); + + } catch (std::exception &ex) { + srtServer.reset(); + WarnL << ex.what(); + return 0; + } +#else + WarnL << "未启用该功能!"; + return 0; +#endif +} + + API_EXPORT uint16_t API_CALL mk_shell_server_start(uint16_t port){ try { shell_server = std::make_shared(); diff --git a/api/tests/server.c b/api/tests/server.c index 9b1d713c..eb3efc83 100644 --- a/api/tests/server.c +++ b/api/tests/server.c @@ -416,6 +416,7 @@ int main(int argc, char *argv[]) { mk_shell_server_start(9000); mk_rtp_server_start(10000); mk_rtc_server_start(8000); + mk_srt_server_start(9000); mk_events events = { .on_mk_media_changed = on_mk_media_changed, diff --git a/server/main.cpp b/server/main.cpp index e1b0e8f6..a83e4f13 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -336,12 +336,9 @@ int start_main(int argc,char *argv[]) { if (rtcPort) { rtcSrv->start(rtcPort); } #endif//defined(ENABLE_WEBRTC) - #if defined(ENABLE_SRT) // srt udp服务器 - if(srtPort){ - srtSrv->start(srtPort); - } + if(srtPort) { srtSrv->start(srtPort); } #endif//defined(ENABLE_SRT) } catch (std::exception &ex) { diff --git a/srt/SrtTransport.cpp b/srt/SrtTransport.cpp index 89a83cb2..c88b2ca4 100644 --- a/srt/SrtTransport.cpp +++ b/srt/SrtTransport.cpp @@ -1,4 +1,6 @@ #include "Util/onceToken.h" +#include "Util/mini.h" + #include #include @@ -15,6 +17,13 @@ const std::string kPort = SRT_FIELD "port"; const std::string kLatencyMul = SRT_FIELD "latencyMul"; const std::string kPktBufSize = SRT_FIELD "pktBufSize"; +static onceToken token([]() { + mINI::Instance()[kTimeOutSec] = 5; + mINI::Instance()[kPort] = 9000; + mINI::Instance()[kLatencyMul] = 4; + mINI::Instance()[kPktBufSize] = 8192; +}); + static std::atomic s_srt_socket_id_generate { 125 }; //////////// SrtTransport ////////////////////////// SrtTransport::SrtTransport(const EventPoller::Ptr &poller)