From c97678af0ac25d4568b3e9fe39897787150f7975 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 2 Jul 2021 14:50:48 +0800 Subject: [PATCH] =?UTF-8?q?webrtc=E6=92=AD=E6=94=BE=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=B5=81=E6=9C=AA=E6=89=BE=E5=88=B0=E4=BA=8B=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8C=89=E9=9C=80=E7=94=9F=E6=88=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index c8e2ea16..46ec56b1 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1189,25 +1189,34 @@ void installWebApi() { headerOut["Access-Control-Allow-Origin"] = "*"; if (type.empty() || !strcasecmp(type.data(), "play")) { - Broadcast::AuthInvoker authInvoker = [invoker, offer_sdp, val, info, headerOut](const string &err) mutable { - try { - auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA, info._vhost, info._app, info._streamid)); + auto session = static_cast(&sender); + auto session_ptr = session->shared_from_this(); + Broadcast::AuthInvoker authInvoker = [invoker, offer_sdp, val, info, headerOut, session_ptr](const string &err) mutable { + if (!err.empty()) { + val["code"] = API::Exception; + val["msg"] = err; + invoker(200, headerOut, val.toStyledString()); + return; + } + + //webrtc播放的是rtsp的源 + info._schema = RTSP_SCHEMA; + MediaSource::findAsync(info, session_ptr, [=](const MediaSource::Ptr &src_in) mutable { + auto src = dynamic_pointer_cast(src_in); if (!src) { - throw runtime_error("流不存在"); - } - if (!err.empty()) { - throw runtime_error(StrPrinter << "播放鉴权失败:" << err); + val["code"] = API::NotFound; + val["msg"] = "stream not found"; + invoker(200, headerOut, val.toStyledString()); + return; } + //还原成rtc,目的是为了hook时识别哪种播放协议 + info._schema = "rtc"; auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller()); rtc->attach(src, info, true); val["sdp"] = rtc->getAnswerSdp(offer_sdp); val["type"] = "answer"; invoker(200, headerOut, val.toStyledString()); - } catch (std::exception &ex) { - val["code"] = API::Exception; - val["msg"] = ex.what(); - invoker(200, headerOut, val.toStyledString()); - } + }); }; //广播通用播放url鉴权事件