Commit 0d6509ce by custompal

统一部分变量名和代码样式风格

parent 04aa3ef4
......@@ -245,8 +245,8 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
};
Broadcast::AuthInvoker invoker = [weak_self, onRes](const string &err) {
if (auto strongSelf = weak_self.lock()) {
strongSelf->async([onRes, err]() { onRes(err); });
if (auto strong_self = weak_self.lock()) {
strong_self->async([onRes, err]() { onRes(err); });
}
};
......@@ -277,6 +277,7 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
fmp4_src->pause(false);
_fmp4_reader = fmp4_src->getRing()->attach(getPoller());
_fmp4_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
_fmp4_reader->setDetachCB([weak_self]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
......@@ -285,9 +286,6 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
}
strong_self->shutdown(SockException(Err_shutdown, "fmp4 ring buffer detached"));
});
_fmp4_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
_fmp4_reader->setReadCB([weak_self](const FMP4MediaSource::RingDataType &fmp4_list) {
auto strong_self = weak_self.lock();
if (!strong_self) {
......@@ -321,6 +319,7 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
ts_src->pause(false);
_ts_reader = ts_src->getRing()->attach(getPoller());
_ts_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
_ts_reader->setDetachCB([weak_self](){
auto strong_self = weak_self.lock();
if (!strong_self) {
......@@ -329,9 +328,6 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
}
strong_self->shutdown(SockException(Err_shutdown,"ts ring buffer detached"));
});
_ts_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
_ts_reader->setReadCB([weak_self](const TSMediaSource::RingDataType &ts_list) {
auto strong_self = weak_self.lock();
if (!strong_self) {
......@@ -418,19 +414,19 @@ void HttpSession::Handle_Req_GET_l(ssize_t &content_len, bool sendBody) {
}
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
HttpFileManager::onAccessPath(*this, _parser, [weakSelf, bClose](int code, const string &content_type,
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
HttpFileManager::onAccessPath(*this, _parser, [weak_self, bClose](int code, const string &content_type,
const StrCaseMap &responseHeader, const HttpBody::Ptr &body) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->async([weakSelf, bClose, code, content_type, responseHeader, body]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
strong_self->async([weak_self, bClose, code, content_type, responseHeader, body]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->sendResponse(code, bClose, content_type.data(), responseHeader, body);
strong_self->sendResponse(code, bClose, content_type.data(), responseHeader, body);
});
});
}
......@@ -651,19 +647,19 @@ void HttpSession::urlDecode(Parser &parser){
bool HttpSession::emitHttpEvent(bool doInvoke){
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
/////////////////////异步回复Invoker///////////////////////////////
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
HttpResponseInvoker invoker = [weakSelf,bClose](int code, const KeyValue &headerOut, const HttpBody::Ptr &body){
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(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) {
return;
}
strongSelf->async([weakSelf, bClose, code, headerOut, body]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
strong_self->async([weak_self, bClose, code, headerOut, body]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
//本对象已经销毁
return;
}
strongSelf->sendResponse(code, bClose, nullptr, headerOut, body);
strong_self->sendResponse(code, bClose, nullptr, headerOut, body);
});
};
///////////////////广播HTTP事件///////////////////////////
......
......@@ -28,12 +28,12 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
throw std::runtime_error("RtmpMediaSource 无效");
}
if (!poller->isCurrentThread()) {
weak_ptr<FlvMuxer> weakSelf = getSharedPtr();
weak_ptr<FlvMuxer> weak_self = getSharedPtr();
//延时两秒启动录制,目的是为了等待config帧收集完毕
poller->doDelayTask(2000, [weakSelf, poller, media, start_pts]() {
auto strongSelf = weakSelf.lock();
if (strongSelf) {
strongSelf->start(poller, media, start_pts);
poller->doDelayTask(2000, [weak_self, poller, media, start_pts]() {
auto strong_self = weak_self.lock();
if (strong_self) {
strong_self->start(poller, media, start_pts);
}
return 0;
});
......@@ -42,24 +42,22 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
onWriteFlvHeader(media);
std::weak_ptr<FlvMuxer> weakSelf = getSharedPtr();
std::weak_ptr<FlvMuxer> weak_self = getSharedPtr();
media->pause(false);
_ring_reader = media->getRing()->attach(poller);
_ring_reader->setDetachCB([weakSelf]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
_ring_reader->setGetInfoCB([weak_self]() { return weak_self.lock(); });
_ring_reader->setDetachCB([weak_self]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->onDetach();
strong_self->onDetach();
});
bool check = start_pts > 0;
_ring_reader->setGetInfoCB([weakSelf]() { return weakSelf.lock(); });
_ring_reader->setReadCB([weakSelf, start_pts, check](const RtmpMediaSource::RingDataType &pkt) mutable {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
_ring_reader->setReadCB([weak_self, start_pts, check](const RtmpMediaSource::RingDataType &pkt) mutable {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
......@@ -72,7 +70,7 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
}
check = false;
}
strongSelf->onWriteRtmp(rtmp, ++i == size);
strong_self->onWriteRtmp(rtmp, ++i == size);
});
});
}
......
......@@ -199,13 +199,13 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}
Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, pToken](const string &err, const ProtocolOption &option) {
auto strongSelf = weak_self.lock();
if (!strongSelf) {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->async([weak_self, on_res, err, pToken, option]() {
auto strongSelf = weak_self.lock();
if (!strongSelf) {
strong_self->async([weak_self, on_res, err, pToken, option]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
on_res(err, option);
......@@ -307,29 +307,29 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
src->pause(false);
_ring_reader = src->getRing()->attach(getPoller());
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
_ring_reader->setGetInfoCB([weakSelf]() { return weakSelf.lock(); });
_ring_reader->setReadCB([weakSelf](const RtmpMediaSource::RingDataType &pkt) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
weak_ptr<RtmpSession> weak_self = dynamic_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();
if (!strong_self) {
return;
}
size_t i = 0;
auto size = pkt->size();
strongSelf->setSendFlushFlag(false);
strong_self->setSendFlushFlag(false);
pkt->for_each([&](const RtmpPacket::Ptr &rtmp){
if(++i == size){
strongSelf->setSendFlushFlag(true);
strong_self->setSendFlushFlag(true);
}
strongSelf->onSendMedia(rtmp);
strong_self->onSendMedia(rtmp);
});
});
_ring_reader->setDetachCB([weakSelf]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
_ring_reader->setDetachCB([weak_self]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached"));
strong_self->shutdown(SockException(Err_shutdown,"rtmp ring buffer detached"));
});
src->pause(false);
_play_src = src;
......@@ -361,9 +361,9 @@ void RtmpSession::doPlay(AMFDecoder &dec){
std::shared_ptr<Ticker> ticker(new Ticker);
weak_ptr<RtmpSession> weak_self = dynamic_pointer_cast<RtmpSession>(shared_from_this());
std::shared_ptr<onceToken> token(new onceToken(nullptr, [ticker,weak_self](){
auto strongSelf = weak_self.lock();
if (strongSelf) {
DebugP(strongSelf.get()) << "play 回复时间:" << ticker->elapsedTime() << "ms";
auto strong_self = weak_self.lock();
if (strong_self) {
DebugP(strong_self.get()) << "play 回复时间:" << ticker->elapsedTime() << "ms";
}
}));
Broadcast::AuthInvoker invoker = [weak_self,token](const string &err){
......
......@@ -36,7 +36,7 @@ protected:
private:
std::string _stream_id;
RtpProcess::Ptr _process;
std::weak_ptr<RtpSelector > _parent;
std::weak_ptr<RtpSelector> _parent;
};
class RtpSelector : public std::enable_shared_from_this<RtpSelector>{
......
......@@ -226,6 +226,8 @@ void SrtTransportImp::doPlay() {
assert(ts_src);
ts_src->pause(false);
strong_self->_ts_reader = ts_src->getRing()->attach(strong_self->getPoller());
weak_ptr<Session> weak_session = strong_self->getSession();
strong_self->_ts_reader->setGetInfoCB([weak_session]() { return weak_session.lock(); });
strong_self->_ts_reader->setDetachCB([weak_self]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
......@@ -234,8 +236,6 @@ void SrtTransportImp::doPlay() {
}
strong_self->onShutdown(SockException(Err_shutdown));
});
weak_ptr<Session> weak_session = strong_self->getSession();
strong_self->_ts_reader->setGetInfoCB([weak_session]() { return weak_session.lock(); });
strong_self->_ts_reader->setReadCB([weak_self](const TSMediaSource::RingDataType &ts_list) {
auto strong_self = weak_self.lock();
if (!strong_self) {
......
......@@ -42,22 +42,22 @@ void WebRtcPlayer::onStartWebRTC() {
weak_ptr<Session> weak_session = getSession();
_reader->setGetInfoCB([weak_session]() { return weak_session.lock(); });
_reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt) {
auto strongSelf = weak_self.lock();
if (!strongSelf) {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
size_t i = 0;
pkt->for_each([&](const RtpPacket::Ptr &rtp) {
//TraceL<<"send track type:"<<rtp->type<<" ts:"<<rtp->getStamp()<<" ntp:"<<rtp->ntp_stamp<<" size:"<<rtp->getPayloadSize()<<" i:"<<i;
strongSelf->onSendRtp(rtp, ++i == pkt->size());
strong_self->onSendRtp(rtp, ++i == pkt->size());
});
});
_reader->setDetachCB([weak_self]() {
auto strongSelf = weak_self.lock();
if (!strongSelf) {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
strongSelf->onShutdown(SockException(Err_shutdown, "rtsp ring buffer detached"));
strong_self->onShutdown(SockException(Err_shutdown, "rtsp ring buffer detached"));
});
}
//使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论