mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 11:17:09 +08:00
http-flv/ws-flv先触发on_play再触发on_stream_not_found
This commit is contained in:
parent
68d910e229
commit
20d3757986
@ -188,65 +188,65 @@ bool HttpSession::checkLiveFlvStream(const function<void()> &cb){
|
|||||||
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
|
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
|
||||||
|
|
||||||
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||||
MediaSource::findAsync(_mediaInfo,weakSelf.lock(),[weakSelf,bClose,this,cb](const MediaSource::Ptr &src){
|
|
||||||
|
//鉴权结果回调
|
||||||
|
auto onRes = [cb, weakSelf, bClose](const string &err){
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if(!strongSelf){
|
if (!strongSelf) {
|
||||||
|
//本对象已经销毁
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!err.empty()){
|
||||||
|
//播放鉴权失败
|
||||||
|
strongSelf->sendResponse("401 Unauthorized", bClose, nullptr, KeyValue(), std::make_shared<HttpStringBody>(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//异步查找rtmp流
|
||||||
|
MediaSource::findAsync(strongSelf->_mediaInfo, strongSelf, [weakSelf, bClose, cb](const MediaSource::Ptr &src) {
|
||||||
|
auto strongSelf = weakSelf.lock();
|
||||||
|
if (!strongSelf) {
|
||||||
//本对象已经销毁
|
//本对象已经销毁
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(src);
|
auto rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(src);
|
||||||
if(!rtmp_src){
|
if (!rtmp_src) {
|
||||||
//未找到该流
|
//未找到该流
|
||||||
sendNotFound(bClose);
|
strongSelf->sendNotFound(bClose);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//找到流了
|
|
||||||
auto onRes = [this,rtmp_src,cb](const string &err){
|
|
||||||
bool authSuccess = err.empty();
|
|
||||||
if(!authSuccess){
|
|
||||||
sendResponse("401 Unauthorized", true, nullptr, KeyValue(), std::make_shared<HttpStringBody>(err));
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!cb) {
|
if (!cb) {
|
||||||
//找到rtmp源,发送http头,负载后续发送
|
//找到rtmp源,发送http头,负载后续发送
|
||||||
sendResponse("200 OK", false, "video/x-flv",KeyValue(),nullptr,true);
|
strongSelf->sendResponse("200 OK", false, "video/x-flv", KeyValue(), nullptr, true);
|
||||||
}else{
|
} else {
|
||||||
|
//自定义发送http头
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
//http-flv直播牺牲延时提升发送性能
|
//http-flv直播牺牲延时提升发送性能
|
||||||
setSocketFlags();
|
strongSelf->setSocketFlags();
|
||||||
|
strongSelf->start(strongSelf->getPoller(), rtmp_src);
|
||||||
try{
|
strongSelf->_is_flv_stream = true;
|
||||||
start(getPoller(),rtmp_src);
|
});
|
||||||
_is_flv_stream = true;
|
|
||||||
}catch (std::exception &ex){
|
|
||||||
//该rtmp源不存在
|
|
||||||
shutdown(SockException(Err_shutdown,"rtmp mediasource released"));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
weak_ptr<HttpSession> weakSelf = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
Broadcast::AuthInvoker invoker = [weakSelf, onRes](const string &err) {
|
||||||
Broadcast::AuthInvoker invoker = [weakSelf,onRes](const string &err){
|
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if(!strongSelf){
|
if (!strongSelf) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
strongSelf->async([weakSelf,onRes,err](){
|
|
||||||
auto strongSelf = weakSelf.lock();
|
|
||||||
if(!strongSelf){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
strongSelf->async([onRes, err]() {
|
||||||
onRes(err);
|
onRes(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,_mediaInfo,invoker,static_cast<SockInfo &>(*this));
|
|
||||||
if(!flag){
|
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _mediaInfo, invoker, static_cast<SockInfo &>(*this));
|
||||||
|
if (!flag) {
|
||||||
//该事件无人监听,默认不鉴权
|
//该事件无人监听,默认不鉴权
|
||||||
onRes("");
|
onRes("");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user