mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
commit
2f9b3e187b
@ -162,11 +162,18 @@ API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建rtc服务器
|
* 创建rtc服务器
|
||||||
* @param port rtp监听端口
|
* @param port rtc监听端口
|
||||||
* @return 0:失败,非0:端口号
|
* @return 0:失败,非0:端口号
|
||||||
*/
|
*/
|
||||||
API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port);
|
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服务器
|
* 创建shell服务器
|
||||||
|
@ -40,6 +40,11 @@ static std::shared_ptr<RtpServer> rtpServer;
|
|||||||
static std::shared_ptr<UdpServer> rtcServer;
|
static std::shared_ptr<UdpServer> rtcServer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ENABLE_SRT)
|
||||||
|
#include "../srt/SrtSession.hpp"
|
||||||
|
static std::shared_ptr<UdpServer> srtServer;
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////////////////////environment init///////////////////////////
|
//////////////////////////environment init///////////////////////////
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
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(rtsp_server);
|
||||||
CLEAR_ARR(rtmp_server);
|
CLEAR_ARR(rtmp_server);
|
||||||
CLEAR_ARR(http_server);
|
CLEAR_ARR(http_server);
|
||||||
|
shell_server = nullptr;
|
||||||
#ifdef ENABLE_RTPPROXY
|
#ifdef ENABLE_RTPPROXY
|
||||||
rtpServer = nullptr;
|
rtpServer = nullptr;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_WEBRTC
|
||||||
|
rtcServer = nullptr;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_SRT
|
||||||
|
srtServer = nullptr;
|
||||||
#endif
|
#endif
|
||||||
stopAllTcpServer();
|
stopAllTcpServer();
|
||||||
}
|
}
|
||||||
@ -254,6 +266,36 @@ API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
API_EXPORT uint16_t API_CALL mk_srt_server_start(uint16_t port) {
|
||||||
|
#ifdef ENABLE_SRT
|
||||||
|
try {
|
||||||
|
srtServer = std::make_shared<UdpServer>();
|
||||||
|
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<SRT::SrtSession>(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){
|
API_EXPORT uint16_t API_CALL mk_shell_server_start(uint16_t port){
|
||||||
try {
|
try {
|
||||||
shell_server = std::make_shared<TcpServer>();
|
shell_server = std::make_shared<TcpServer>();
|
||||||
|
@ -416,6 +416,7 @@ int main(int argc, char *argv[]) {
|
|||||||
mk_shell_server_start(9000);
|
mk_shell_server_start(9000);
|
||||||
mk_rtp_server_start(10000);
|
mk_rtp_server_start(10000);
|
||||||
mk_rtc_server_start(8000);
|
mk_rtc_server_start(8000);
|
||||||
|
mk_srt_server_start(9000);
|
||||||
|
|
||||||
mk_events events = {
|
mk_events events = {
|
||||||
.on_mk_media_changed = on_mk_media_changed,
|
.on_mk_media_changed = on_mk_media_changed,
|
||||||
|
@ -336,12 +336,9 @@ int start_main(int argc,char *argv[]) {
|
|||||||
if (rtcPort) { rtcSrv->start<WebRtcSession>(rtcPort); }
|
if (rtcPort) { rtcSrv->start<WebRtcSession>(rtcPort); }
|
||||||
#endif//defined(ENABLE_WEBRTC)
|
#endif//defined(ENABLE_WEBRTC)
|
||||||
|
|
||||||
|
|
||||||
#if defined(ENABLE_SRT)
|
#if defined(ENABLE_SRT)
|
||||||
// srt udp服务器
|
// srt udp服务器
|
||||||
if(srtPort){
|
if(srtPort) { srtSrv->start<SRT::SrtSession>(srtPort); }
|
||||||
srtSrv->start<SRT::SrtSession>(srtPort);
|
|
||||||
}
|
|
||||||
#endif//defined(ENABLE_SRT)
|
#endif//defined(ENABLE_SRT)
|
||||||
|
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "Util/onceToken.h"
|
#include "Util/onceToken.h"
|
||||||
|
#include "Util/mini.h"
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -15,6 +17,13 @@ const std::string kPort = SRT_FIELD "port";
|
|||||||
const std::string kLatencyMul = SRT_FIELD "latencyMul";
|
const std::string kLatencyMul = SRT_FIELD "latencyMul";
|
||||||
const std::string kPktBufSize = SRT_FIELD "pktBufSize";
|
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<uint32_t> s_srt_socket_id_generate { 125 };
|
static std::atomic<uint32_t> s_srt_socket_id_generate { 125 };
|
||||||
//////////// SrtTransport //////////////////////////
|
//////////// SrtTransport //////////////////////////
|
||||||
SrtTransport::SrtTransport(const EventPoller::Ptr &poller)
|
SrtTransport::SrtTransport(const EventPoller::Ptr &poller)
|
||||||
|
@ -46,14 +46,14 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="methond">methond(play or push or echo):</label>
|
<label for="method">method(play or push or echo):</label>
|
||||||
<input type="radio" name="methond" value="echo" >echo
|
<input type="radio" name="method" value="echo" >echo
|
||||||
<input type="radio" name="methond" value="push" >push
|
<input type="radio" name="method" value="push" >push
|
||||||
<input type="radio" name="methond" value="play" checked = true>play
|
<input type="radio" name="method" value="play" checked = true>play
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="resilution">resolution:</label>
|
<label for="resolution">resolution:</label>
|
||||||
<select id="resilution">
|
<select id="resolution">
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@ -98,7 +98,7 @@
|
|||||||
url = "http://127.0.0.1"+"/index/api/webrtc?app=live&stream=test&type=play"
|
url = "http://127.0.0.1"+"/index/api/webrtc?app=live&stream=test&type=play"
|
||||||
}
|
}
|
||||||
document.getElementById('streamUrl').value = url
|
document.getElementById('streamUrl').value = url
|
||||||
document.getElementsByName("methond").forEach((el,idx)=>{
|
document.getElementsByName("method").forEach((el,idx)=>{
|
||||||
el.onclick=function(e){
|
el.onclick=function(e){
|
||||||
let url = new URL(document.getElementById('streamUrl').value);
|
let url = new URL(document.getElementById('streamUrl').value);
|
||||||
url.searchParams.set("type",el.value)
|
url.searchParams.set("type",el.value)
|
||||||
@ -118,14 +118,14 @@
|
|||||||
opt = document.createElement('option');
|
opt = document.createElement('option');
|
||||||
opt.text = r.label +"("+r.width+"x"+r.height+")";
|
opt.text = r.label +"("+r.width+"x"+r.height+")";
|
||||||
opt.value = r;
|
opt.value = r;
|
||||||
document.getElementById("resilution").add(opt,null)
|
document.getElementById("resolution").add(opt,null)
|
||||||
|
|
||||||
//console.log(opt.text.match(/\d+/g))
|
//console.log(opt.text.match(/\d+/g))
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
function start_play(){
|
function start_play(){
|
||||||
let elr = document.getElementById("resilution");
|
let elr = document.getElementById("resolution");
|
||||||
let res = elr.options[elr.selectedIndex].text.match(/\d+/g);
|
let res = elr.options[elr.selectedIndex].text.match(/\d+/g);
|
||||||
let h = parseInt(res.pop());
|
let h = parseInt(res.pop());
|
||||||
let w = parseInt(res.pop());
|
let w = parseInt(res.pop());
|
||||||
@ -204,7 +204,7 @@
|
|||||||
function start()
|
function start()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
let elr = document.getElementById("resilution");
|
let elr = document.getElementById("resolution");
|
||||||
let res = elr.options[elr.selectedIndex].text.match(/\d+/g);
|
let res = elr.options[elr.selectedIndex].text.match(/\d+/g);
|
||||||
let h = parseInt(res.pop());
|
let h = parseInt(res.pop());
|
||||||
let w = parseInt(res.pop());
|
let w = parseInt(res.pop());
|
||||||
|
Loading…
Reference in New Issue
Block a user