使用static_pointer_cast优化性能

This commit is contained in:
xia-chu
2023-04-28 22:04:38 +08:00
parent cdf97e7605
commit d2349f01bd
23 changed files with 59 additions and 57 deletions

View File

@@ -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<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
weak_ptr<RtspPlayer> weakSelf = static_pointer_cast<RtspPlayer>(shared_from_this());
float playTimeOutSec = (*this)[Client::kTimeoutMS].as<int>() / 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<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
weak_ptr<RtspPlayer> weakSelf = static_pointer_cast<RtspPlayer>(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<uint64_t>();
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
weak_ptr<RtspPlayer> weakSelf = static_pointer_cast<RtspPlayer>(shared_from_this());
auto lam = [weakSelf, timeoutMS]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {