初步添加rtsp转webrtc相关功能

This commit is contained in:
ziyue
2021-03-24 16:52:41 +08:00
parent 2f0bdf2724
commit 65e470e060
20 changed files with 4000 additions and 0 deletions

View File

@@ -35,6 +35,9 @@
#if defined(ENABLE_RTPPROXY)
#include "Rtp/RtpServer.h"
#endif
#ifdef ENABLE_WEBRTC
#include "../webrtc/webrtc_transport.h"
#endif
using namespace toolkit;
using namespace mediakit;
@@ -1049,6 +1052,27 @@ void installWebApi() {
#endif
});
#ifdef ENABLE_WEBRTC
static list<WebRtcTransportImp::Ptr> rtcs;
api_regist("/webrtc",[](API_ARGS_MAP_ASYNC){
CHECK_ARGS("app", "stream");
auto src = dynamic_pointer_cast<RtspMediaSource>(MediaSource::find(RTSP_SCHEMA, DEFAULT_VHOST, allArgs["app"], allArgs["stream"]));
if (!src) {
throw ApiRetException("流不存在", API::NotFound);
}
headerOut["Content-Type"] = "text/plain";
headerOut["Access-Control-Allow-Origin"] = "*";
auto poller = EventPollerPool::Instance().getFirstPoller();
auto rtc = std::make_shared<WebRtcTransportImp>(poller);
poller->async([invoker, rtc, headerOut, src]() {
rtc->attach(src);
auto sdp = rtc->GetLocalSdp();
invoker(200, headerOut, sdp);
rtcs.emplace_back(rtc);
});
});
#endif
////////////以下是注册的Hook API////////////
api_regist("/index/hook/on_publish",[](API_ARGS_MAP){
//开始推流事件