mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2025-02-11 13:19:42 +08:00
完善rtsp 信令心跳包相关逻辑
This commit is contained in:
parent
0e9d8df2d0
commit
0779a4bee6
@ -107,8 +107,7 @@ void RtspPlayer::onConnect(const SockException &err){
|
||||
onPlayResult_l(err,false);
|
||||
return;
|
||||
}
|
||||
|
||||
sendDescribe();
|
||||
sendOptions();
|
||||
}
|
||||
|
||||
void RtspPlayer::onRecv(const Buffer::Ptr& pBuf) {
|
||||
@ -162,7 +161,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
|
||||
string authInfo = parser["WWW-Authenticate"];
|
||||
//发送DESCRIBE命令后的回复
|
||||
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) {
|
||||
sendDescribe();
|
||||
sendOptions();
|
||||
return;
|
||||
}
|
||||
if(parser.Url() == "302" || parser.Url() == "301"){
|
||||
@ -358,9 +357,33 @@ void RtspPlayer::sendDescribe() {
|
||||
sendRtspRequest("DESCRIBE",_strUrl,{"Accept","application/sdp"});
|
||||
}
|
||||
|
||||
void RtspPlayer::sendGetParameter(){
|
||||
void RtspPlayer::sendOptions(){
|
||||
_onHandshake = [this](const Parser& parser){
|
||||
if (parser.Url() != "200") {
|
||||
throw std::runtime_error(StrPrinter << "OPTIONS:" << parser.Url() << " " << parser.Tail() << endl);
|
||||
}
|
||||
//获取服务器支持的命令
|
||||
_supported_cmd.clear();
|
||||
auto public_val = split(parser["Public"],",");
|
||||
for(auto &cmd : public_val){
|
||||
trim(cmd);
|
||||
_supported_cmd.emplace(cmd);
|
||||
}
|
||||
//发送Describe请求,获取sdp
|
||||
sendDescribe();
|
||||
};
|
||||
sendRtspRequest("OPTIONS",_strUrl);
|
||||
}
|
||||
|
||||
void RtspPlayer::sendKeepAlive(){
|
||||
_onHandshake = [this](const Parser& parser){};
|
||||
if(_supported_cmd.find("GET_PARAMETER") != _supported_cmd.end()){
|
||||
//支持GET_PARAMETER,用此命令保活
|
||||
sendRtspRequest("GET_PARAMETER",_strUrl);
|
||||
}else{
|
||||
//不支持GET_PARAMETER,用OPTIONS命令保活
|
||||
sendRtspRequest("OPTIONS",_strUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void RtspPlayer::sendPause(int type , uint32_t seekMS){
|
||||
@ -695,10 +718,10 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url,const StrC
|
||||
|
||||
void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pkt, const SdpTrack::Ptr &track) {
|
||||
_rtpTicker.resetTime();
|
||||
onRecvRTP(pkt,track);
|
||||
onRecvRTP(pkt, track);
|
||||
|
||||
int iTrackIndex = getTrackIndexByInterleaved(pkt->interleaved);
|
||||
if(iTrackIndex == -1){
|
||||
if (iTrackIndex == -1) {
|
||||
return;
|
||||
}
|
||||
RtcpCounter &counter = _aRtcpCnt[iTrackIndex];
|
||||
@ -708,14 +731,17 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pkt, const SdpTrack::Ptr &tra
|
||||
//send rtcp every 5 second
|
||||
counter.lastTimeStamp = counter.timeStamp;
|
||||
//直接保存网络字节序
|
||||
memcpy(&counter.timeStamp, pkt->data() + 8 , 4);
|
||||
if(counter.lastTimeStamp != 0){
|
||||
sendReceiverReport(_eType == Rtsp::RTP_TCP,iTrackIndex);
|
||||
memcpy(&counter.timeStamp, pkt->data() + 8, 4);
|
||||
if (counter.lastTimeStamp != 0) {
|
||||
sendReceiverReport(_eType == Rtsp::RTP_TCP, iTrackIndex);
|
||||
ticker.resetTime();
|
||||
}
|
||||
|
||||
//有些rtsp服务器需要rtcp保活,有些需要发送信令保活
|
||||
sendGetParameter();
|
||||
if (iTrackIndex == 0) {
|
||||
//只需要发送一次心跳信令包
|
||||
sendKeepAlive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,11 +95,11 @@ private:
|
||||
bool handleAuthenticationFailure(const string &wwwAuthenticateParamsStr);
|
||||
void handleResPAUSE(const Parser &parser, int type);
|
||||
|
||||
//发送SETUP命令
|
||||
void sendOptions();
|
||||
void sendSetup(unsigned int uiTrackIndex);
|
||||
void sendPause(int type , uint32_t ms);
|
||||
void sendDescribe();
|
||||
void sendGetParameter();
|
||||
void sendKeepAlive();
|
||||
void sendRtspRequest(const string &cmd, const string &url ,const StrCaseMap &header = StrCaseMap());
|
||||
void sendRtspRequest(const string &cmd, const string &url ,const std::initializer_list<string> &header);
|
||||
void sendReceiverReport(bool overTcp,int iTrackIndex);
|
||||
@ -141,6 +141,9 @@ private:
|
||||
bool _is_play_back;
|
||||
//是否为性能测试模式
|
||||
bool _benchmark_mode = false;
|
||||
|
||||
//服务器支持的命令
|
||||
set<string> _supported_cmd;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
Loading…
Reference in New Issue
Block a user