Commit a19f6767 by xia-chu

兼容一些rtsp流 #735

parent 19f3b1bd
......@@ -86,6 +86,14 @@ string SdpTrack::getName() const{
}
}
string SdpTrack::getControlUrl(const string &base_url) const{
if (_control.find("://") != string::npos) {
//以rtsp://开头
return _control;
}
return base_url +"/" + _control;
}
string SdpTrack::toString() const {
_StrPrinter _printer;
switch (_type){
......@@ -246,8 +254,6 @@ void SdpParser::load(const string &sdp) {
it = track._attr.find("control");
if(it != track._attr.end()) {
track._control = it->second;
auto surffix = string("/") + track._control;
track._control_surffix = surffix.substr(1 + surffix.rfind('/'));
}
}
}
......
......@@ -213,6 +213,7 @@ public:
string toString() const;
string getName() const;
string getControlUrl(const string &base_url) const;
public:
int _pt;
......@@ -222,7 +223,6 @@ public:
string _codec;
string _fmtp;
string _control;
string _control_surffix;
public:
bool _inited = false;
......
......@@ -226,22 +226,19 @@ void RtspPlayer::createUdpSockIfNecessary(int track_idx){
void RtspPlayer::sendSetup(unsigned int track_idx) {
_on_response = std::bind(&RtspPlayer::handleResSETUP, this, placeholders::_1, track_idx);
auto &track = _sdp_track[track_idx];
auto baseUrl = _content_base + "/" + track->_control_surffix;
if (track->_control.find("://") != string::npos) {
baseUrl = track->_control;
}
auto control_url = track->getControlUrl(_content_base);
switch (_rtp_type) {
case Rtsp::RTP_TCP: {
sendRtspRequest("SETUP",baseUrl,{"Transport",StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2 << "-" << track->_type * 2 + 1});
sendRtspRequest("SETUP", control_url, {"Transport", StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2 << "-" << track->_type * 2 + 1});
}
break;
case Rtsp::RTP_MULTICAST: {
sendRtspRequest("SETUP",baseUrl,{"Transport","RTP/AVP;multicast"});
sendRtspRequest("SETUP", control_url, {"Transport", "RTP/AVP;multicast"});
}
break;
case Rtsp::RTP_UDP: {
createUdpSockIfNecessary(track_idx);
sendRtspRequest("SETUP", baseUrl, {"Transport",
sendRtspRequest("SETUP", control_url, {"Transport",
StrPrinter << "RTP/AVP;unicast;client_port="
<< _rtp_sock[track_idx]->get_local_port() << "-"
<< _rtcp_sock[track_idx]->get_local_port()});
......
......@@ -261,13 +261,10 @@ void RtspPusher::createUdpSockIfNecessary(int track_idx){
void RtspPusher::sendSetup(unsigned int track_idx) {
_on_res_func = std::bind(&RtspPusher::handleResSetup, this, placeholders::_1, track_idx);
auto &track = _track_vec[track_idx];
auto base_url = _content_base + "/" + track->_control_surffix;
if (track->_control.find("://") != string::npos) {
base_url = track->_control;
}
auto control_url = track->getControlUrl(_content_base);
switch (_rtp_type) {
case Rtsp::RTP_TCP: {
sendRtspRequest("SETUP", base_url, {"Transport",
sendRtspRequest("SETUP", control_url, {"Transport",
StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2
<< "-" << track->_type * 2 + 1});
}
......@@ -275,7 +272,7 @@ void RtspPusher::sendSetup(unsigned int track_idx) {
case Rtsp::RTP_UDP: {
createUdpSockIfNecessary(track_idx);
int port = _rtp_sock[track_idx]->get_local_port();
sendRtspRequest("SETUP", base_url,
sendRtspRequest("SETUP", control_url,
{"Transport", StrPrinter << "RTP/AVP;unicast;client_port=" << port << "-" << port + 1});
}
break;
......
......@@ -268,7 +268,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
shutdown(SockException(Err_shutdown,"track not setuped"));
return;
}
rtp_info << "url=" << _content_base << "/" << track->_control_surffix << ",";
rtp_info << "url=" << track->getControlUrl(_content_base) << ",";
}
rtp_info.pop_back();
......@@ -614,11 +614,7 @@ void RtspSession::send_SessionNotFound() {
void RtspSession::handleReq_Setup(const Parser &parser) {
//处理setup命令,该函数可能进入多次
auto controlSuffix = split(parser.FullUrl(),"/").back();
if(controlSuffix.front() == '/'){
controlSuffix = controlSuffix.substr(1);
}
int trackIdx = getTrackIndexByControlSuffix(controlSuffix);
int trackIdx = getTrackIndexByControlUrl(parser.Url());
SdpTrack::Ptr &trackRef = _sdp_track[trackIdx];
if (trackRef->_inited) {
//已经初始化过该Track
......@@ -796,7 +792,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
track->_seq = play_src->getSeqence(track->_type);
track->_time_stamp = play_src->getTimeStamp(track->_type);
rtp_info << "url=" << _content_base << "/" << track->_control_surffix << ";"
rtp_info << "url=" << track->getControlUrl(_content_base) << ";"
<< "seq=" << track->_seq << ";"
<< "rtptime=" << (int) (track->_time_stamp * (track->_samplerate / 1000)) << ",";
}
......@@ -1068,16 +1064,16 @@ int RtspSession::getTrackIndexByTrackType(TrackType type) {
throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << (int) type);
}
int RtspSession::getTrackIndexByControlSuffix(const string &controlSuffix) {
int RtspSession::getTrackIndexByControlUrl(const string &control_url) {
for (unsigned int i = 0; i < _sdp_track.size(); i++) {
if (controlSuffix == _sdp_track[i]->_control_surffix) {
if (control_url == _sdp_track[i]->getControlUrl(_content_base)) {
return i;
}
}
if(_sdp_track.size() == 1){
return 0;
}
throw SockException(Err_shutdown, StrPrinter << "no such track with suffix:" << controlSuffix);
throw SockException(Err_shutdown, StrPrinter << "no such track with control url:" << control_url);
}
int RtspSession::getTrackIndexByInterleaved(int interleaved){
......
......@@ -132,7 +132,7 @@ private:
void send_NotAcceptable();
//获取track下标
int getTrackIndexByTrackType(TrackType type);
int getTrackIndexByControlSuffix(const string &control_suffix);
int getTrackIndexByControlUrl(const string &control_url);
int getTrackIndexByInterleaved(int interleaved);
//一般用于接收udp打洞包,也用于rtsp推流
void onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, const struct sockaddr &addr);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论