mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-03-06 22:20:52 +08:00
兼容某些不规范的rtsp流 (#4188)
This commit is contained in:
@@ -265,7 +265,7 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
|
||||
case Rtsp::RTP_TCP: {
|
||||
sendRtspRequest(
|
||||
"SETUP", control_url,
|
||||
{ "Transport", StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2 << "-" << track->_type * 2 + 1 << ";mode=play" });
|
||||
{ "Transport", StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track_idx * 2 << "-" << track_idx * 2 + 1 << ";mode=play" });
|
||||
} break;
|
||||
case Rtsp::RTP_MULTICAST: {
|
||||
sendRtspRequest("SETUP", control_url, { "Transport", "RTP/AVP;multicast;mode=play" });
|
||||
@@ -552,7 +552,9 @@ void RtspPlayer::onRtpPacket(const char *data, size_t len) {
|
||||
int trackIdx = -1;
|
||||
uint8_t interleaved = data[1];
|
||||
if (interleaved % 2 == 0) {
|
||||
trackIdx = getTrackIndexByInterleaved(interleaved);
|
||||
CHECK(len > RtpPacket::kRtpHeaderSize + RtpPacket::kRtpTcpHeaderSize);
|
||||
RtpHeader *header = (RtpHeader *)(data + RtpPacket::kRtpTcpHeaderSize);
|
||||
trackIdx = getTrackIndexByPT(header->pt);
|
||||
if (trackIdx == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -804,6 +806,19 @@ void RtspPlayer::onPlayResult_l(const SockException &ex, bool handshake_done) {
|
||||
}
|
||||
}
|
||||
|
||||
int RtspPlayer::getTrackIndexByPT(int pt) const {
|
||||
for (size_t i = 0; i < _sdp_track.size(); ++i) {
|
||||
if (_sdp_track[i]->_pt == pt) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (_sdp_track.size() == 1) {
|
||||
return 0;
|
||||
}
|
||||
WarnL << "no such track with pt:" << pt;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const {
|
||||
for (size_t i = 0; i < _sdp_track.size(); ++i) {
|
||||
if (_sdp_track[i]->_interleaved == interleaved) {
|
||||
|
||||
@@ -117,6 +117,7 @@ protected:
|
||||
private:
|
||||
void onPlayResult_l(const toolkit::SockException &ex , bool handshake_done);
|
||||
|
||||
int getTrackIndexByPT(int pt) const;
|
||||
int getTrackIndexByInterleaved(int interleaved) const;
|
||||
int getTrackIndexByTrackType(TrackType track_type) const;
|
||||
|
||||
|
||||
@@ -277,8 +277,8 @@ void RtspPusher::sendSetup(unsigned int track_idx) {
|
||||
switch (_rtp_type) {
|
||||
case Rtsp::RTP_TCP: {
|
||||
sendRtspRequest("SETUP", control_url, {"Transport",
|
||||
StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track->_type * 2
|
||||
<< "-" << track->_type * 2 + 1 << ";mode=record"});
|
||||
StrPrinter << "RTP/AVP/TCP;unicast;interleaved=" << track_idx * 2
|
||||
<< "-" << track_idx * 2 + 1 << ";mode=record"});
|
||||
}
|
||||
break;
|
||||
case Rtsp::RTP_UDP: {
|
||||
|
||||
@@ -167,7 +167,9 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
|
||||
void RtspSession::onRtpPacket(const char *data, size_t len) {
|
||||
uint8_t interleaved = data[1];
|
||||
if (interleaved % 2 == 0) {
|
||||
auto track_idx = getTrackIndexByInterleaved(interleaved);
|
||||
CHECK(len > RtpPacket::kRtpHeaderSize + RtpPacket::kRtpTcpHeaderSize);
|
||||
RtpHeader *header = (RtpHeader *)(data + RtpPacket::kRtpTcpHeaderSize);
|
||||
auto track_idx = getTrackIndexByPT(header->pt);
|
||||
handleOneRtp(track_idx, _sdp_track[track_idx]->_type, _sdp_track[track_idx]->_samplerate, (uint8_t *) data + RtpPacket::kRtpTcpHeaderSize, len - RtpPacket::kRtpTcpHeaderSize);
|
||||
} else {
|
||||
auto track_idx = getTrackIndexByInterleaved(interleaved - 1);
|
||||
@@ -1124,6 +1126,18 @@ bool RtspSession::sendRtspResponse(const string &res_code, const std::initialize
|
||||
return sendRtspResponse(res_code,header_map,sdp,protocol);
|
||||
}
|
||||
|
||||
int RtspSession::getTrackIndexByPT(int pt) const {
|
||||
for (size_t i = 0; i < _sdp_track.size(); ++i) {
|
||||
if (pt == _sdp_track[i]->_pt) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (_sdp_track.size() == 1) {
|
||||
return 0;
|
||||
}
|
||||
throw SockException(Err_shutdown, StrPrinter << "no such track with pt:" << pt);
|
||||
}
|
||||
|
||||
int RtspSession::getTrackIndexByTrackType(TrackType type) {
|
||||
for (size_t i = 0; i < _sdp_track.size(); ++i) {
|
||||
if (type == _sdp_track[i]->_type) {
|
||||
|
||||
@@ -153,6 +153,7 @@ private:
|
||||
void send_NotAcceptable();
|
||||
// 获取track下标 [AUTO-TRANSLATED:36d0b2c2]
|
||||
// Get the track index
|
||||
int getTrackIndexByPT(int pt) const;
|
||||
int getTrackIndexByTrackType(TrackType type);
|
||||
int getTrackIndexByControlUrl(const std::string &control_url);
|
||||
int getTrackIndexByInterleaved(int interleaved);
|
||||
|
||||
Reference in New Issue
Block a user