diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index caa3013e..548ce6c3 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2016 xiongziliang <771730766@qq.com> diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index eb5421a1..a19d49b2 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2016 xiongziliang <771730766@qq.com> diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 875fc1a6..da6af7b9 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -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; diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 55bce5c6..83ed9408 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -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; diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index e9f07f7e..72c7171a 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -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; iget_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; diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index d949c997..ef36c592 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -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'; diff --git a/src/Shell/ShellCMD.cpp b/src/Shell/ShellCMD.cpp index 5980e71f..cd75b844 100644 --- a/src/Shell/ShellCMD.cpp +++ b/src/Shell/ShellCMD.cpp @@ -1,4 +1,4 @@ -// +// // Created by xzl on 2017/12/1. // diff --git a/tests/test_server.cpp b/tests/test_server.cpp index 2ca2d1cb..5df2b33e 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -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(); });