mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-05 10:58:11 +08:00
使用static_pointer_cast优化性能
This commit is contained in:
@@ -41,7 +41,7 @@ void RtmpMediaSource::onWrite(RtmpPacket::Ptr pkt, bool /*= true*/)
|
||||
}
|
||||
|
||||
if (!_ring) {
|
||||
std::weak_ptr<RtmpMediaSource> weakSelf = std::dynamic_pointer_cast<RtmpMediaSource>(shared_from_this());
|
||||
std::weak_ptr<RtmpMediaSource> weakSelf = std::static_pointer_cast<RtmpMediaSource>(shared_from_this());
|
||||
auto lam = [weakSelf](int size) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
|
||||
@@ -75,7 +75,7 @@ void RtmpPlayer::play(const string &url) {
|
||||
setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
|
||||
weak_ptr<RtmpPlayer> weak_self = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
weak_ptr<RtmpPlayer> weak_self = static_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
float play_timeout_sec = (*this)[Client::kTimeoutMS].as<int>() / 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<uint64_t>();
|
||||
weak_ptr<RtmpPlayer> weak_self = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
weak_ptr<RtmpPlayer> weak_self = static_pointer_cast<RtmpPlayer>(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<RtmpPlayer> weak_self = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
weak_ptr<RtmpPlayer> weak_self = static_pointer_cast<RtmpPlayer>(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<RtmpPlayer> weak_self = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
weak_ptr<RtmpPlayer> weak_self = static_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
_beat_timer.reset(new Timer((*this)[Client::kBeatIntervalMS].as<int>() / 1000.0f, [weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
||||
@@ -79,7 +79,7 @@ void RtmpPusher::publish(const string &url) {
|
||||
uint16_t port = 1935;
|
||||
splitUrl(host_url, host_url, port);
|
||||
|
||||
weak_ptr<RtmpPusher> weakSelf = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
weak_ptr<RtmpPusher> weakSelf = static_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
float publishTimeOutSec = (*this)[Client::kTimeoutMS].as<int>() / 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<RtmpPusher> weak_self = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
weak_ptr<RtmpPusher> weak_self = static_pointer_cast<RtmpPusher>(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<RtmpPusher> weak_self = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
weak_ptr<RtmpPusher> weak_self = static_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
_rtmp_reader->setReadCB([weak_self](const RtmpMediaSource::RingDataType &pkt) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
|
||||
@@ -127,7 +127,7 @@ void RtmpSession::onCmd_createStream(AMFDecoder &dec) {
|
||||
|
||||
void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
std::shared_ptr<Ticker> ticker(new Ticker);
|
||||
weak_ptr<RtmpSession> weak_self = dynamic_pointer_cast<RtmpSession>(shared_from_this());
|
||||
weak_ptr<RtmpSession> weak_self = static_pointer_cast<RtmpSession>(shared_from_this());
|
||||
std::shared_ptr<onceToken> 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<MediaSourceEvent>(shared_from_this()));
|
||||
_push_src->setListener(static_pointer_cast<RtmpSession>(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<RtmpSession> weak_self = dynamic_pointer_cast<RtmpSession>(shared_from_this());
|
||||
weak_ptr<RtmpSession> weak_self = static_pointer_cast<RtmpSession>(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<void(bool
|
||||
}
|
||||
|
||||
//鉴权成功,查找媒体源并回复
|
||||
weak_ptr<RtmpSession> weak_self = dynamic_pointer_cast<RtmpSession>(shared_from_this());
|
||||
weak_ptr<RtmpSession> weak_self = static_pointer_cast<RtmpSession>(shared_from_this());
|
||||
MediaSource::findAsync(_media_info, weak_self.lock(), [weak_self,cb](const MediaSource::Ptr &src){
|
||||
auto rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(src);
|
||||
auto strong_self = weak_self.lock();
|
||||
@@ -362,7 +362,7 @@ void RtmpSession::doPlayResponse(const string &err,const std::function<void(bool
|
||||
|
||||
void RtmpSession::doPlay(AMFDecoder &dec){
|
||||
std::shared_ptr<Ticker> ticker(new Ticker);
|
||||
weak_ptr<RtmpSession> weak_self = dynamic_pointer_cast<RtmpSession>(shared_from_this());
|
||||
weak_ptr<RtmpSession> weak_self = static_pointer_cast<RtmpSession>(shared_from_this());
|
||||
std::shared_ptr<onceToken> token(new onceToken(nullptr, [ticker,weak_self](){
|
||||
auto strong_self = weak_self.lock();
|
||||
if (strong_self) {
|
||||
|
||||
Reference in New Issue
Block a user