mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
单track rtsp推流加快媒体注册速度
This commit is contained in:
parent
61afc57ed1
commit
e807a08f2e
@ -226,31 +226,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
|||||||
throw SockException(Err_shutdown, StrPrinter << err << ":" << full_url);
|
throw SockException(Err_shutdown, StrPrinter << err << ":" << full_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
SdpParser sdpParser(parser.Content());
|
auto onRes = [this, parser, full_url](const string &err, bool enableHls, bool enableMP4){
|
||||||
_sessionid = makeRandStr(12);
|
|
||||||
_sdp_track = sdpParser.getAvailableTrack();
|
|
||||||
if (_sdp_track.empty()) {
|
|
||||||
//sdp无效
|
|
||||||
static constexpr auto err = "sdp中无有效track";
|
|
||||||
sendRtspResponse("403 Forbidden", {"Content-Type", "text/plain"}, err);
|
|
||||||
throw SockException(Err_shutdown,StrPrinter << err << ":" << full_url);
|
|
||||||
}
|
|
||||||
_rtcp_context.clear();
|
|
||||||
for (auto &track : _sdp_track) {
|
|
||||||
_rtcp_context.emplace_back(std::make_shared<RtcpContext>(track->_samplerate, true));
|
|
||||||
}
|
|
||||||
_push_src = std::make_shared<RtspMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
|
|
||||||
_push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
|
||||||
_push_src->setSdp(sdpParser.toString());
|
|
||||||
sendRtspResponse("200 OK",{"Content-Base", _content_base + "/"});
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtspSession::handleReq_RECORD(const Parser &parser){
|
|
||||||
if (_sdp_track.empty() || parser["Session"] != _sessionid) {
|
|
||||||
send_SessionNotFound();
|
|
||||||
throw SockException(Err_shutdown, _sdp_track.empty() ? "can not find any availabe track when record" : "session not found when record");
|
|
||||||
}
|
|
||||||
auto onRes = [this](const string &err, bool enableHls, bool enableMP4){
|
|
||||||
bool authSuccess = err.empty();
|
bool authSuccess = err.empty();
|
||||||
if (!authSuccess) {
|
if (!authSuccess) {
|
||||||
sendRtspResponse("401 Unauthorized", {"Content-Type", "text/plain"}, err);
|
sendRtspResponse("401 Unauthorized", {"Content-Type", "text/plain"}, err);
|
||||||
@ -258,25 +234,25 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置转协议
|
SdpParser sdpParser(parser.Content());
|
||||||
_push_src->setProtocolTranslation(enableHls, enableMP4);
|
_sessionid = makeRandStr(12);
|
||||||
|
_sdp_track = sdpParser.getAvailableTrack();
|
||||||
_StrPrinter rtp_info;
|
if (_sdp_track.empty()) {
|
||||||
for(auto &track : _sdp_track){
|
//sdp无效
|
||||||
if (track->_inited == false) {
|
static constexpr auto err = "sdp中无有效track";
|
||||||
//还有track没有setup
|
sendRtspResponse("403 Forbidden", {"Content-Type", "text/plain"}, err);
|
||||||
shutdown(SockException(Err_shutdown,"track not setuped"));
|
shutdown(SockException(Err_shutdown, StrPrinter << err << ":" << full_url));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rtp_info << "url=" << track->getControlUrl(_content_base) << ",";
|
_rtcp_context.clear();
|
||||||
}
|
for (auto &track : _sdp_track) {
|
||||||
|
_rtcp_context.emplace_back(std::make_shared<RtcpContext>(track->_samplerate, true));
|
||||||
rtp_info.pop_back();
|
|
||||||
sendRtspResponse("200 OK", {"RTP-Info",rtp_info});
|
|
||||||
if(_rtp_type == Rtsp::RTP_TCP){
|
|
||||||
//如果是rtsp推流服务器,并且是TCP推流,设置socket flags,,这样能提升接收性能
|
|
||||||
setSocketFlags();
|
|
||||||
}
|
}
|
||||||
|
_push_src = std::make_shared<RtspMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
|
||||||
|
_push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
||||||
|
_push_src->setProtocolTranslation(enableHls, enableMP4);
|
||||||
|
_push_src->setSdp(sdpParser.toString());
|
||||||
|
sendRtspResponse("200 OK", {"Content-Base", _content_base + "/"});
|
||||||
};
|
};
|
||||||
|
|
||||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||||
@ -304,6 +280,29 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtspSession::handleReq_RECORD(const Parser &parser){
|
||||||
|
if (_sdp_track.empty() || parser["Session"] != _sessionid) {
|
||||||
|
send_SessionNotFound();
|
||||||
|
throw SockException(Err_shutdown, _sdp_track.empty() ? "can not find any availabe track when record" : "session not found when record");
|
||||||
|
}
|
||||||
|
|
||||||
|
_StrPrinter rtp_info;
|
||||||
|
for (auto &track : _sdp_track) {
|
||||||
|
if (track->_inited == false) {
|
||||||
|
//还有track没有setup
|
||||||
|
shutdown(SockException(Err_shutdown, "track not setuped"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rtp_info << "url=" << track->getControlUrl(_content_base) << ",";
|
||||||
|
}
|
||||||
|
rtp_info.pop_back();
|
||||||
|
sendRtspResponse("200 OK", {"RTP-Info", rtp_info});
|
||||||
|
if (_rtp_type == Rtsp::RTP_TCP) {
|
||||||
|
//如果是rtsp推流服务器,并且是TCP推流,设置socket flags,,这样能提升接收性能
|
||||||
|
setSocketFlags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RtspSession::emitOnPlay(){
|
void RtspSession::emitOnPlay(){
|
||||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||||
//url鉴权回调
|
//url鉴权回调
|
||||||
|
Loading…
Reference in New Issue
Block a user