diff --git a/api/source/mk_tcp.cpp b/api/source/mk_tcp.cpp index e96ce4bf..d155cac8 100644 --- a/api/source/mk_tcp.cpp +++ b/api/source/mk_tcp.cpp @@ -155,7 +155,7 @@ API_EXPORT void API_CALL mk_tcp_session_send_buffer_safe(const mk_tcp_session ct API_EXPORT mk_tcp_session_ref API_CALL mk_tcp_session_ref_from(const mk_tcp_session ctx) { auto ref = ((SessionForC *) ctx)->shared_from_this(); - return (mk_tcp_session_ref)new std::shared_ptr(std::dynamic_pointer_cast(ref)); + return (mk_tcp_session_ref)new std::shared_ptr(std::static_pointer_cast(ref)); } API_EXPORT void mk_tcp_session_ref_release(const mk_tcp_session_ref ref) { diff --git a/api/source/mk_thread.cpp b/api/source/mk_thread.cpp index 56b5be2a..29775b43 100644 --- a/api/source/mk_thread.cpp +++ b/api/source/mk_thread.cpp @@ -143,7 +143,7 @@ public: } EventPoller::Ptr getPoller() { - return dynamic_pointer_cast(getExecutor()); + return static_pointer_cast(getExecutor()); } }; diff --git a/src/FMP4/FMP4MediaSource.h b/src/FMP4/FMP4MediaSource.h index e004dc5e..7986a08c 100644 --- a/src/FMP4/FMP4MediaSource.h +++ b/src/FMP4/FMP4MediaSource.h @@ -108,7 +108,7 @@ public: private: void createRing(){ - std::weak_ptr weak_self = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weak_self = std::static_pointer_cast(shared_from_this()); _ring = std::make_shared(_ring_size, [weak_self](int size) { auto strong_self = weak_self.lock(); if (!strong_self) { diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index e8ca1471..1de45cf8 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -80,7 +80,7 @@ void HlsPlayer::fetchSegment() { //播放器目前还存活,正在下载中 return; } - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); if (!_http_ts_player) { _http_ts_player = std::make_shared(getPoller()); _http_ts_player->setOnCreateSocket([weak_self](const EventPoller::Ptr &poller) { @@ -186,7 +186,7 @@ bool HlsPlayer::onParsed(bool is_m3u8_inner, int64_t sequence, const map weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); auto url = ts_map.rbegin()->second.url; getPoller()->async([weak_self, url]() { auto strong_self = weak_self.lock(); @@ -259,7 +259,7 @@ bool HlsPlayer::onRedirectUrl(const string &url, bool temporary) { } void HlsPlayer::playDelay() { - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _timer.reset(new Timer(delaySecond(), [weak_self]() { auto strong_self = weak_self.lock(); if (strong_self) { diff --git a/src/Http/HttpRequester.cpp b/src/Http/HttpRequester.cpp index ddc73631..3e403df2 100644 --- a/src/Http/HttpRequester.cpp +++ b/src/Http/HttpRequester.cpp @@ -27,7 +27,7 @@ void HttpRequester::onResponseBody(const char *buf, size_t size) { void HttpRequester::onResponseCompleted(const SockException &ex) { if (ex && _retry++ < _max_retry) { - std::weak_ptr weak_self = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weak_self = std::static_pointer_cast(shared_from_this()); getPoller()->doDelayTask(_retry_delay, [weak_self](){ if (auto self = weak_self.lock()) { InfoL << "resend request " << self->getUrl() << " with retry " << self->getRetry(); diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 7acd9fa7..8243cba0 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -202,7 +202,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi } bool close_flag = !strcasecmp(_parser["Connection"].data(), "close"); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); //鉴权结果回调 auto onRes = [cb, weak_self, close_flag](const string &err) { @@ -266,7 +266,7 @@ bool HttpSession::checkLiveStreamFMP4(const function &cb){ //直播牺牲延时提升发送性能 setSocketFlags(); onWrite(std::make_shared(fmp4_src->getInitSegment()), true); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); fmp4_src->pause(false); _fmp4_reader = fmp4_src->getRing()->attach(getPoller()); _fmp4_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); }); @@ -308,7 +308,7 @@ bool HttpSession::checkLiveStreamTS(const function &cb){ //直播牺牲延时提升发送性能 setSocketFlags(); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); ts_src->pause(false); _ts_reader = ts_src->getRing()->attach(getPoller()); _ts_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); }); @@ -406,7 +406,7 @@ void HttpSession::Handle_Req_GET_l(ssize_t &content_len, bool sendBody) { } bool bClose = !strcasecmp(_parser["Connection"].data(),"close"); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); HttpFileManager::onAccessPath(*this, _parser, [weak_self, bClose](int code, const string &content_type, const StrCaseMap &responseHeader, const HttpBody::Ptr &body) { auto strong_self = weak_self.lock(); @@ -434,12 +434,13 @@ class AsyncSenderData { public: friend class AsyncSender; using Ptr = std::shared_ptr; - AsyncSenderData(const Session::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) { - _session = dynamic_pointer_cast(session); + AsyncSenderData(HttpSession::Ptr session, const HttpBody::Ptr &body, bool close_when_complete) { + _session = std::move(session); _body = body; _close_when_complete = close_when_complete; } ~AsyncSenderData() = default; + private: std::weak_ptr _session; HttpBody::Ptr _body; @@ -612,7 +613,7 @@ void HttpSession::sendResponse(int code, } //发送http body - AsyncSenderData::Ptr data = std::make_shared(static_pointer_cast(shared_from_this()), body, bClose); + AsyncSenderData::Ptr data = std::make_shared(static_pointer_cast(shared_from_this()), body, bClose); getSock()->setOnFlush([data]() { return AsyncSender::onSocketFlushed(data); }); AsyncSender::onSocketFlushed(data); } @@ -639,7 +640,7 @@ void HttpSession::urlDecode(Parser &parser){ bool HttpSession::emitHttpEvent(bool doInvoke){ bool bClose = !strcasecmp(_parser["Connection"].data(),"close"); /////////////////////异步回复Invoker/////////////////////////////// - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); HttpResponseInvoker invoker = [weak_self,bClose](int code, const KeyValue &headerOut, const HttpBody::Ptr &body){ auto strong_self = weak_self.lock(); if(!strong_self) { diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 42eaad44..b06a7f9e 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -28,15 +28,16 @@ class HttpSession: public toolkit::Session, public HttpRequestSplitter, public WebSocketSplitter { public: - typedef StrCaseMap KeyValue; - typedef HttpResponseInvokerImp HttpResponseInvoker; + using Ptr = std::shared_ptr; + using KeyValue = StrCaseMap; + using HttpResponseInvoker = HttpResponseInvokerImp ; friend class AsyncSender; /** * @param errMsg 如果为空,则代表鉴权通过,否则为错误提示 * @param accessPath 运行或禁止访问的根目录 * @param cookieLifeSecond 鉴权cookie有效期 **/ - typedef std::function HttpAccessPathInvoker; + using HttpAccessPathInvoker = std::function; HttpSession(const toolkit::Socket::Ptr &pSock); ~HttpSession() override; diff --git a/src/Http/WebSocketClient.h b/src/Http/WebSocketClient.h index 379ae66d..5850b027 100644 --- a/src/Http/WebSocketClient.h +++ b/src/Http/WebSocketClient.h @@ -316,7 +316,7 @@ private: if (!ex) { // websocket握手成功 // 此处截取TcpClient派生类发送的数据并进行websocket协议打包 - std::weak_ptr weakSelf = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weakSelf = std::static_pointer_cast(shared_from_this()); if (auto strong_ref = _weak_delegate.lock()) { strong_ref->setOnBeforeSendCB([weakSelf](const toolkit::Buffer::Ptr &buf) { auto strong_self = weakSelf.lock(); diff --git a/src/Http/WebSocketSession.h b/src/Http/WebSocketSession.h index c8d8b432..96021c4d 100644 --- a/src/Http/WebSocketSession.h +++ b/src/Http/WebSocketSession.h @@ -139,7 +139,7 @@ protected: } //此处截取数据并进行websocket协议打包 - std::weak_ptr weakSelf = std::dynamic_pointer_cast(HttpSessionType::shared_from_this()); + std::weak_ptr weakSelf = std::static_pointer_cast(HttpSessionType::shared_from_this()); std::dynamic_pointer_cast(_session)->setOnBeforeSendCB([weakSelf](const toolkit::Buffer::Ptr &buf) { auto strongSelf = weakSelf.lock(); if (strongSelf) { diff --git a/src/Record/HlsMediaSource.cpp b/src/Record/HlsMediaSource.cpp index 406a6c6a..d6d4f4b4 100644 --- a/src/Record/HlsMediaSource.cpp +++ b/src/Record/HlsMediaSource.cpp @@ -68,7 +68,7 @@ HlsMediaSource::Ptr HlsCookieData::getMediaSource() const { void HlsMediaSource::setIndexFile(std::string index_file) { if (!_ring) { - std::weak_ptr weakSelf = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weakSelf = std::static_pointer_cast(shared_from_this()); auto lam = [weakSelf](int size) { auto strongSelf = weakSelf.lock(); if (!strongSelf) { diff --git a/src/Rtmp/RtmpMediaSourceImp.cpp b/src/Rtmp/RtmpMediaSourceImp.cpp index 8e49e534..7777a0fa 100644 --- a/src/Rtmp/RtmpMediaSourceImp.cpp +++ b/src/Rtmp/RtmpMediaSourceImp.cpp @@ -41,7 +41,7 @@ void RtmpMediaSource::onWrite(RtmpPacket::Ptr pkt, bool /*= true*/) } if (!_ring) { - std::weak_ptr weakSelf = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weakSelf = std::static_pointer_cast(shared_from_this()); auto lam = [weakSelf](int size) { auto strongSelf = weakSelf.lock(); if (!strongSelf) { diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 4e7d903d..ffaf0dfc 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -75,7 +75,7 @@ void RtmpPlayer::play(const string &url) { setNetAdapter((*this)[Client::kNetAdapter]); } - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); float play_timeout_sec = (*this)[Client::kTimeoutMS].as() / 1000.0f; _play_timer.reset(new Timer(play_timeout_sec, [weak_self]() { auto strong_self = weak_self.lock(); @@ -120,7 +120,7 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex, bool handshake_done) { //播放成功,恢复rtmp接收超时定时器 _rtmp_recv_ticker.resetTime(); auto timeout_ms = (*this)[Client::kMediaTimeoutMS].as(); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); auto lam = [weak_self, timeout_ms]() { auto strong_self = weak_self.lock(); if (!strong_self) { @@ -146,7 +146,7 @@ void RtmpPlayer::onConnect(const SockException &err) { onPlayResult_l(err, false); return; } - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); startClientSession([weak_self]() { if (auto strong_self = weak_self.lock()) { strong_self->send_connect(); @@ -258,7 +258,7 @@ void RtmpPlayer::send_pause(bool pause) { _beat_timer.reset(); if (pause) { - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _beat_timer.reset(new Timer((*this)[Client::kBeatIntervalMS].as() / 1000.0f, [weak_self]() { auto strong_self = weak_self.lock(); if (!strong_self) { diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index bf5ca332..31143dcf 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -79,7 +79,7 @@ void RtmpPusher::publish(const string &url) { uint16_t port = 1935; splitUrl(host_url, host_url, port); - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); float publishTimeOutSec = (*this)[Client::kTimeoutMS].as() / 1000.0f; _publish_timer.reset(new Timer(publishTimeOutSec, [weakSelf]() { auto strongSelf = weakSelf.lock(); @@ -107,7 +107,7 @@ void RtmpPusher::onConnect(const SockException &err){ onPublishResult_l(err, false); return; } - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); startClientSession([weak_self]() { auto strong_self = weak_self.lock(); if (!strong_self) { @@ -193,7 +193,7 @@ void RtmpPusher::send_metaData(){ src->pause(false); _rtmp_reader = src->getRing()->attach(getPoller()); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _rtmp_reader->setReadCB([weak_self](const RtmpMediaSource::RingDataType &pkt) { auto strong_self = weak_self.lock(); if (!strong_self) { diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index ae827551..3c3f552e 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -127,7 +127,7 @@ void RtmpSession::onCmd_createStream(AMFDecoder &dec) { void RtmpSession::onCmd_publish(AMFDecoder &dec) { std::shared_ptr ticker(new Ticker); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); std::shared_ptr token(new onceToken(nullptr, [ticker, weak_self]() { auto strong_self = weak_self.lock(); if (strong_self) { @@ -188,7 +188,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { _push_src->setProtocolOption(option); } - _push_src->setListener(dynamic_pointer_cast(shared_from_this())); + _push_src->setListener(static_pointer_cast(shared_from_this())); _continue_push_ms = option.continue_push_ms; sendStatus({"level", "status", "code", "NetStream.Publish.Start", @@ -310,7 +310,7 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr src->pause(false); _ring_reader = src->getRing()->attach(getPoller()); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _ring_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); }); _ring_reader->setReadCB([weak_self](const RtmpMediaSource::RingDataType &pkt) { auto strong_self = weak_self.lock(); @@ -349,7 +349,7 @@ void RtmpSession::doPlayResponse(const string &err,const std::function weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); MediaSource::findAsync(_media_info, weak_self.lock(), [weak_self,cb](const MediaSource::Ptr &src){ auto rtmp_src = dynamic_pointer_cast(src); auto strong_self = weak_self.lock(); @@ -362,7 +362,7 @@ void RtmpSession::doPlayResponse(const string &err,const std::function ticker(new Ticker); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); std::shared_ptr token(new onceToken(nullptr, [ticker,weak_self](){ auto strong_self = weak_self.lock(); if (strong_self) { diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index 26faadfb..38b6d4cd 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -122,7 +122,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) { return; } _process->setOnlyAudio(_only_audio); - _process->setDelegate(dynamic_pointer_cast(shared_from_this())); + _process->setDelegate(static_pointer_cast(shared_from_this())); } try { uint32_t rtp_ssrc = 0; diff --git a/src/Rtsp/RtspMediaSourceImp.cpp b/src/Rtsp/RtspMediaSourceImp.cpp index a262fad5..7354306f 100644 --- a/src/Rtsp/RtspMediaSourceImp.cpp +++ b/src/Rtsp/RtspMediaSourceImp.cpp @@ -55,7 +55,7 @@ void RtspMediaSource::onWrite(RtpPacket::Ptr rtp, bool keyPos) { track->_ssrc = rtp->getSSRC(); } if (!_ring) { - std::weak_ptr weakSelf = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weakSelf = std::static_pointer_cast(shared_from_this()); auto lam = [weakSelf](int size) { auto strongSelf = weakSelf.lock(); if (!strongSelf) { diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 6fae5e07..67d0b281 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -92,7 +92,7 @@ void RtspPlayer::play(const string &strUrl){ _rtp_type = (Rtsp::eRtpType)(int)(*this)[Client::kRtpType]; DebugL << url._url << " " << (url._user.size() ? url._user : "null") << " " << (url._passwd.size() ? url._passwd : "null") << " " << _rtp_type; - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); float playTimeOutSec = (*this)[Client::kTimeoutMS].as() / 1000.0f; _play_check_timer.reset(new Timer(playTimeOutSec, [weakSelf]() { auto strongSelf=weakSelf.lock(); @@ -348,7 +348,7 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) { } auto peer_ip = get_peer_ip(); - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); //设置rtp over udp接收回调处理函数 pRtpSockRef->setOnRead([peer_ip, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) { auto strongSelf = weakSelf.lock(); @@ -705,7 +705,7 @@ void RtspPlayer::onPlayResult_l(const SockException &ex , bool handshake_done) { //播放成功,恢复rtp接收超时定时器 _rtp_recv_ticker.resetTime(); auto timeoutMS = (*this)[Client::kMediaTimeoutMS].as(); - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); auto lam = [weakSelf, timeoutMS]() { auto strongSelf = weakSelf.lock(); if (!strongSelf) { diff --git a/src/Rtsp/RtspPusher.cpp b/src/Rtsp/RtspPusher.cpp index 575f551c..01727adc 100644 --- a/src/Rtsp/RtspPusher.cpp +++ b/src/Rtsp/RtspPusher.cpp @@ -80,7 +80,7 @@ void RtspPusher::publish(const string &url_str) { DebugL << url._url << " " << (url._user.size() ? url._user : "null") << " " << (url._passwd.size() ? url._passwd : "null") << " " << _rtp_type; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); float publish_timeout_sec = (*this)[Client::kTimeoutMS].as() / 1000.0f; _publish_timer.reset(new Timer(publish_timeout_sec, [weak_self]() { auto strong_self = weak_self.lock(); @@ -320,7 +320,7 @@ void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) { rtcp_sock->bindPeerAddr((struct sockaddr *)&(rtcpto)); auto peer_ip = get_peer_ip(); - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); if(rtcp_sock) { //设置rtcp over udp接收回调处理函数 rtcp_sock->setOnRead([peer_ip, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) { @@ -451,7 +451,7 @@ void RtspPusher::sendRecord() { src->pause(false); _rtsp_reader = src->getRing()->attach(getPoller()); - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _rtsp_reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt) { auto strong_self = weak_self.lock(); if (!strong_self) { diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index c02772ce..5388ad53 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -273,12 +273,12 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { _push_src->setSdp(parser.Content()); } - _push_src->setListener(dynamic_pointer_cast(shared_from_this())); + _push_src->setListener(static_pointer_cast(shared_from_this())); _continue_push_ms = option.continue_push_ms; sendRtspResponse("200 OK"); }; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); Broadcast::PublishAuthInvoker invoker = [weak_self, onRes](const string &err, const ProtocolOption &option) { auto strong_self = weak_self.lock(); if (!strong_self) { @@ -325,7 +325,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){ } void RtspSession::emitOnPlay(){ - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); //url鉴权回调 auto onRes = [weak_self](const string &err) { auto strong_self = weak_self.lock(); @@ -364,7 +364,7 @@ void RtspSession::emitOnPlay(){ void RtspSession::handleReq_Describe(const Parser &parser) { //该请求中的认证信息 auto authorization = parser["Authorization"]; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); //rtsp专属鉴权是否开启事件回调 onGetRealm invoker = [weak_self, authorization](const string &realm) { auto strong_self = weak_self.lock(); @@ -402,7 +402,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) { } void RtspSession::onAuthSuccess() { - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); MediaSource::findAsync(_media_info, weak_self.lock(), [weak_self](const MediaSource::Ptr &src){ auto strong_self = weak_self.lock(); if(!strong_self){ @@ -471,7 +471,7 @@ void RtspSession::onAuthBasic(const string &realm, const string &auth_base64) { } auto user = user_pwd_vec[0]; auto pwd = user_pwd_vec[1]; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); onAuth invoker = [pwd, realm, weak_self](bool encrypted, const string &good_pwd) { auto strong_self = weak_self.lock(); if (!strong_self) { @@ -564,7 +564,7 @@ void RtspSession::onAuthDigest(const string &realm,const string &auth_md5){ } }; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); onAuth invoker = [realInvoker,weak_self](bool encrypted,const string &good_pwd){ auto strong_self = weak_self.lock(); if(!strong_self){ @@ -722,7 +722,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) { send_NotAcceptable(); throw SockException(Err_shutdown, "can not get a available udp multicast socket"); } - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _multicaster->setDetachCB(this, [weak_self]() { auto strong_self = weak_self.lock(); if(!strong_self) { @@ -830,7 +830,7 @@ void RtspSession::handleReq_Play(const Parser &parser) { setSocketFlags(); if (!_play_reader && _rtp_type != Rtsp::RTP_MULTICAST) { - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); _play_reader = play_src->getRing()->attach(getPoller(), use_gop); _play_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); }); _play_reader->setDetachCB([weak_self]() { @@ -880,7 +880,7 @@ void RtspSession::handleReq_Get(const Parser &parser) { //注册http getter,以便http poster绑定 lock_guard lock(g_mtxGetter); - g_mapGetter[_http_x_sessioncookie] = dynamic_pointer_cast(shared_from_this()); + g_mapGetter[_http_x_sessioncookie] = static_pointer_cast(shared_from_this()); } void RtspSession::handleReq_Post(const Parser &parser) { @@ -973,7 +973,7 @@ void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, cons } void RtspSession::startListenPeerUdpData(int track_idx) { - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); auto peer_ip = get_peer_ip(); auto onUdpData = [weak_self,peer_ip](const Buffer::Ptr &buf, struct sockaddr *peer_addr, int interleaved){ auto strong_self = weak_self.lock(); diff --git a/src/Shell/ShellSession.cpp b/src/Shell/ShellSession.cpp index 81e18d7b..fe0c23fd 100644 --- a/src/Shell/ShellSession.cpp +++ b/src/Shell/ShellSession.cpp @@ -120,7 +120,7 @@ inline void ShellSession::pleaseInputPasswd() { _loginInterceptor=nullptr; }; - weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); + weak_ptr weakSelf = static_pointer_cast(shared_from_this()); Broadcast::AuthInvoker invoker = [weakSelf,onAuth](const string &errMessage){ auto strongSelf = weakSelf.lock(); if(!strongSelf){ diff --git a/src/TS/TSMediaSource.h b/src/TS/TSMediaSource.h index 1f4503a4..8a22ad90 100644 --- a/src/TS/TSMediaSource.h +++ b/src/TS/TSMediaSource.h @@ -92,7 +92,7 @@ public: private: void createRing(){ - std::weak_ptr weak_self = std::dynamic_pointer_cast(shared_from_this()); + std::weak_ptr weak_self = std::static_pointer_cast(shared_from_this()); _ring = std::make_shared(_ring_size, [weak_self](int size) { auto strong_self = weak_self.lock(); if (!strong_self) { diff --git a/webrtc/WebRtcSession.cpp b/webrtc/WebRtcSession.cpp index 28c60d58..ee3051c0 100644 --- a/webrtc/WebRtcSession.cpp +++ b/webrtc/WebRtcSession.cpp @@ -54,7 +54,7 @@ WebRtcSession::WebRtcSession(const Socket::Ptr &sock) : Session(sock) { WebRtcSession::~WebRtcSession() = default; void WebRtcSession::attachServer(const Server &server) { - _server = std::dynamic_pointer_cast(const_cast(server).shared_from_this()); + _server = std::static_pointer_cast(const_cast(server).shared_from_this()); } void WebRtcSession::onRecv_l(const char *data, size_t len) { diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 05935076..470ef733 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -860,7 +860,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) { void WebRtcTransportImp::createRtpChannel(const string &rid, uint32_t ssrc, MediaTrack &track) { // rid --> RtpReceiverImp auto &ref = track.rtp_channel[rid]; - weak_ptr weak_self = dynamic_pointer_cast(shared_from_this()); + weak_ptr weak_self = static_pointer_cast(shared_from_this()); ref = std::make_shared( getPoller(), [&track, this, rid](RtpPacket::Ptr rtp) mutable { onSortedRtp(track, rid, std::move(rtp)); }, [&track, weak_self, ssrc](const FCI_NACK &nack) mutable {