添加bom、完善rtsp客户端兼容性

This commit is contained in:
xiongziliang 2018-03-20 11:28:13 +08:00
parent 906fb0613b
commit 88e5a199eb
8 changed files with 34 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/*
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>

View File

@ -1,4 +1,4 @@
/*
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>

View File

@ -71,7 +71,13 @@ int parserSDP(const string& sdp, RtspTrack Track[2]) {
if (IDStr == "") {
break;
}
TrackID = atoi(IDStr.c_str());
if(strcasecmp(IDStr.data(),"video") == 0){
TrackID = 0;
}else if(strcasecmp(IDStr.data(),"audio") == 0){
TrackID = 1;
}else{
TrackID = atoi(IDStr.c_str());
}
pos_end = sdp.find("m=", pos_head + 2);
if (pos_end == string::npos) {
pos_end = sdp.size();
@ -81,8 +87,8 @@ int parserSDP(const string& sdp, RtspTrack Track[2]) {
Track[track_cnt].trackStyle = track_str;
Track[track_cnt].inited = false;
Track[track_cnt].trackId = TrackID;
Track[track_cnt].PT = atoi(
FindField(mid.c_str(), "rtpmap:", " ").c_str());
Track[track_cnt].trackIdStr = IDStr;
Track[track_cnt].PT = atoi(FindField(mid.c_str(), "rtpmap:", " ").c_str());
if (mid.find("m=video") != string::npos) {
//视频通道
Track[track_cnt].type = TrackVideo;

View File

@ -44,7 +44,8 @@ class RtspTrack{
public:
uint8_t PT;
uint8_t trackId;
uint8_t interleaved;
string trackIdStr;
uint8_t interleaved;
TrackType type = (TrackType) -1;
string trackSdp;
string trackStyle;

View File

@ -225,14 +225,19 @@ inline void RtspPlayer::HandleResDESCRIBE(const Parser& parser) {
}
auto strSdp = parser.Content();
m_strContentBase = parser["Content-Base"];
if(m_strContentBase.empty()){
m_strContentBase = m_strUrl;
}
if (m_strContentBase[m_strContentBase.length() - 1] == '/') {
m_strContentBase.pop_back();
}
auto iLen = atoi(parser["Content-Length"].data());
if(iLen > 0){
strSdp.erase(iLen);
}
if (m_strContentBase[m_strContentBase.length() - 1] == '/') {
m_strContentBase.pop_back();
}
//解析sdp
m_uiTrackCnt = parserSDP(strSdp, m_aTrackInfo);
for (unsigned int i=0; i<m_uiTrackCnt; i++) {
@ -256,21 +261,21 @@ inline void RtspPlayer::sendSetup(unsigned int trackIndex) {
auto &track = m_aTrackInfo[trackIndex];
switch (m_eType) {
case RTP_TCP: {
iLen = sprintf(acRtspbuf, "SETUP %s/%s%d RTSP/1.0\r\n"
iLen = sprintf(acRtspbuf, "SETUP %s/%s%s RTSP/1.0\r\n"
"CSeq: %d\r\n"
"Transport: RTP/AVP/TCP;unicast;interleaved=%d-%d\r\n"
"Authorization: Basic %s\r\n\r\n", m_strContentBase.c_str(),
track.trackStyle.c_str(), track.trackId, m_uiCseq++,
track.trackStyle.c_str(), track.trackIdStr.data(), m_uiCseq++,
track.trackId * 2, track.trackId * 2 + 1,
m_strAuthorization.c_str());
}
break;
case RTP_MULTICAST: {
iLen = sprintf(acRtspbuf, "SETUP %s/%s%d RTSP/1.0\r\n"
iLen = sprintf(acRtspbuf, "SETUP %s/%s%s RTSP/1.0\r\n"
"CSeq: %d\r\n"
"Transport: RTP/AVP;multicast\r\n"
"Authorization: Basic %s\r\n\r\n", m_strContentBase.c_str(),
track.trackStyle.c_str(), track.trackId, m_uiCseq++,
track.trackStyle.c_str(), track.trackIdStr.data(), m_uiCseq++,
m_strAuthorization.c_str());
}
break;
@ -281,11 +286,11 @@ inline void RtspPlayer::sendSetup(unsigned int trackIndex) {
throw std::runtime_error("open udp sock err");
}
int port = m_apUdpSock[trackIndex]->get_local_port();
iLen = sprintf(acRtspbuf, "SETUP %s/%s%d RTSP/1.0\r\n"
iLen = sprintf(acRtspbuf, "SETUP %s/%s%s RTSP/1.0\r\n"
"CSeq: %d\r\n"
"Transport: RTP/AVP;unicast;client_port=%d-%d\r\n"
"Authorization: Basic %s\r\n\r\n", m_strContentBase.c_str(),
track.trackStyle.c_str(), track.trackId, m_uiCseq++, port,
track.trackStyle.c_str(), track.trackIdStr.data(), m_uiCseq++, port,
port + 1, m_strAuthorization.c_str());
}
break;

View File

@ -734,9 +734,9 @@ bool RtspSession::handleReq_Play() {
shutdown();
return;
}
iLen += sprintf(m_pcBuf + iLen, "url=%s/%s%d;seq=%d;rtptime=%u,",
iLen += sprintf(m_pcBuf + iLen, "url=%s/%s%s;seq=%d;rtptime=%u,",
m_strUrl.data(), track.trackStyle.data(),
track.trackId, track.seq,track.timeStamp);
track.trackIdStr.data(), track.seq,track.timeStamp);
}
iLen -= 1;
(m_pcBuf)[iLen] = '\0';

View File

@ -1,4 +1,4 @@
//
//
// Created by xzl on 2017/12/1.
//

View File

@ -135,6 +135,10 @@ static onceToken s_token([](){
}, nullptr);
#if !defined(SIGHUP)
#defined SIGHUP 1
#endif
int main(int argc,char *argv[]) {
//设置退出信号处理函数
signal(SIGINT, [](int) { EventPoller::Instance().shutdown(); });