From d52fc4c31f07a15115f569b3f4060af409bef9c5 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 12 Jan 2022 15:21:33 +0800 Subject: [PATCH] =?UTF-8?q?Refine:=20=E4=BC=98=E5=8C=96rtsp=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtpReceiver.h | 9 +++++++-- src/Rtsp/RtspPlayer.cpp | 6 +++--- src/Rtsp/RtspPusher.cpp | 8 ++++---- src/Rtsp/RtspSession.cpp | 16 ++++++++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index 8b6f7fed..089f36fe 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -236,7 +236,8 @@ public: * @param len rtp数据指针长度 * @return 解析成功返回true */ - bool handleOneRtp(int index, TrackType type, int sample_rate, uint8_t *ptr, size_t len){ + bool handleOneRtp(int index, TrackType type, int sample_rate, uint8_t *ptr, size_t len) { + assert(index < kCount && index >= 0); return _track[index].inputRtp(type, sample_rate, ptr, len).operator bool(); } @@ -247,7 +248,8 @@ public: * @param rtp_stamp rtp时间戳 * @param ntp_stamp_ms ntp时间戳 */ - void setNtpStamp(int index, uint32_t rtp_stamp, uint64_t ntp_stamp_ms){ + void setNtpStamp(int index, uint32_t rtp_stamp, uint64_t ntp_stamp_ms) { + assert(index < kCount && index >= 0); _track[index].setNtpStamp(rtp_stamp, ntp_stamp_ms); } @@ -258,14 +260,17 @@ public: } size_t getJitterSize(int index) const { + assert(index < kCount && index >= 0); return _track[index].getJitterSize(); } size_t getCycleCount(int index) const { + assert(index < kCount && index >= 0); return _track[index].getCycleCount(); } uint32_t getSSRC(int index) const { + assert(index < kCount && index >= 0); return _track[index].getSSRC(); } diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 33dc548d..8e584de6 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -693,7 +693,7 @@ void RtspPlayer::onPlayResult_l(const SockException &ex , bool handshake_done) { } int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const { - for (unsigned int i = 0; i < _sdp_track.size(); i++) { + for (size_t i = 0; i < _sdp_track.size(); ++i) { if (_sdp_track[i]->_interleaved == interleaved) { return i; } @@ -705,7 +705,7 @@ int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const { } int RtspPlayer::getTrackIndexByTrackType(TrackType track_type) const { - for (unsigned int i = 0; i < _sdp_track.size(); i++) { + for (size_t i = 0; i < _sdp_track.size(); ++i) { if (_sdp_track[i]->_type == track_type) { return i; } @@ -713,7 +713,7 @@ int RtspPlayer::getTrackIndexByTrackType(TrackType track_type) const { if (_sdp_track.size() == 1) { return 0; } - throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << (int) track_type); + throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << getTrackString(track_type)); } } /* namespace mediakit */ diff --git a/src/Rtsp/RtspPusher.cpp b/src/Rtsp/RtspPusher.cpp index 8b7226bd..ab628210 100644 --- a/src/Rtsp/RtspPusher.cpp +++ b/src/Rtsp/RtspPusher.cpp @@ -419,7 +419,7 @@ void RtspPusher::sendRtpPacket(const RtspMediaSource::RingDataType &pkt) { } int RtspPusher::getTrackIndexByInterleaved(int interleaved) const { - for (int i = 0; i < (int)_track_vec.size(); ++i) { + for (size_t i = 0; i < _track_vec.size(); ++i) { if (_track_vec[i]->_interleaved == interleaved) { return i; } @@ -430,8 +430,8 @@ int RtspPusher::getTrackIndexByInterleaved(int interleaved) const { throw SockException(Err_shutdown, StrPrinter << "no such track with interleaved:" << interleaved); } -int RtspPusher::getTrackIndexByTrackType(TrackType type) const{ - for (int i = 0; i < (int)_track_vec.size(); ++i) { +int RtspPusher::getTrackIndexByTrackType(TrackType type) const { + for (size_t i = 0; i < _track_vec.size(); ++i) { if (type == _track_vec[i]->_type) { return i; } @@ -439,7 +439,7 @@ int RtspPusher::getTrackIndexByTrackType(TrackType type) const{ if (_track_vec.size() == 1) { return 0; } - throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << (int) type); + throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << getTrackString(type)); } void RtspPusher::sendRecord() { diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 536df225..f0a7a608 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -1098,36 +1098,36 @@ bool RtspSession::sendRtspResponse(const string &res_code, const std::initialize } int RtspSession::getTrackIndexByTrackType(TrackType type) { - for (unsigned int i = 0; i < _sdp_track.size(); i++) { + for (size_t i = 0; i < _sdp_track.size(); ++i) { if (type == _sdp_track[i]->_type) { return i; } } - if(_sdp_track.size() == 1){ + if (_sdp_track.size() == 1) { return 0; } - throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << (int) type); + throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << getTrackString(type)); } int RtspSession::getTrackIndexByControlUrl(const string &control_url) { - for (unsigned int i = 0; i < _sdp_track.size(); i++) { + for (size_t i = 0; i < _sdp_track.size(); ++i) { if (control_url == _sdp_track[i]->getControlUrl(_content_base)) { return i; } } - if(_sdp_track.size() == 1){ + if (_sdp_track.size() == 1) { return 0; } throw SockException(Err_shutdown, StrPrinter << "no such track with control url:" << control_url); } -int RtspSession::getTrackIndexByInterleaved(int interleaved){ - for (unsigned int i = 0; i < _sdp_track.size(); i++) { +int RtspSession::getTrackIndexByInterleaved(int interleaved) { + for (size_t i = 0; i < _sdp_track.size(); ++i) { if (_sdp_track[i]->_interleaved == interleaved) { return i; } } - if(_sdp_track.size() == 1){ + if (_sdp_track.size() == 1) { return 0; } throw SockException(Err_shutdown, StrPrinter << "no such track with interleaved:" << interleaved);