完善ntp时间戳计算逻辑

This commit is contained in:
ziyue
2021-09-02 21:17:59 +08:00
parent 72c2df057a
commit 415bc95dda
8 changed files with 36 additions and 32 deletions

View File

@@ -101,10 +101,10 @@ RtpPacket::Ptr RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr,
return rtp;
}
void RtpTrack::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms) {
_disable_ntp = rtp_stamp == 0 && sample_rate == 0 && ntp_stamp_ms == 0;
if (sample_rate) {
_ntp_stamp.setNtpStamp(rtp_stamp, sample_rate, ntp_stamp_ms);
void RtpTrack::setNtpStamp(uint32_t rtp_stamp, uint64_t ntp_stamp_ms) {
_disable_ntp = rtp_stamp == 0 && ntp_stamp_ms == 0;
if (!_disable_ntp) {
_ntp_stamp.setNtpStamp(rtp_stamp, ntp_stamp_ms);
}
}

View File

@@ -176,7 +176,7 @@ public:
void clear();
uint32_t getSSRC() const;
RtpPacket::Ptr inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len);
void setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms);
void setNtpStamp(uint32_t rtp_stamp, uint64_t ntp_stamp_ms);
protected:
virtual void onRtpSorted(RtpPacket::Ptr rtp) {}
@@ -245,11 +245,10 @@ public:
* 如果rtp_stamp/sample_rate/ntp_stamp_ms都为0那么采用rtp时间戳为ntp时间戳
* @param index track下标索引
* @param rtp_stamp rtp时间戳
* @param sample_rate 时间戳采样率
* @param ntp_stamp_ms ntp时间戳
*/
void setNtpStamp(int index, uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms){
_track[index].setNtpStamp(rtp_stamp, sample_rate, ntp_stamp_ms);
void setNtpStamp(int index, uint32_t rtp_stamp, uint64_t ntp_stamp_ms){
_track[index].setNtpStamp(rtp_stamp, ntp_stamp_ms);
}
void clear() {

View File

@@ -496,7 +496,7 @@ void RtspPlayer::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, uint8_t *data
if ((RtcpType) rtcp->pt == RtcpType::RTCP_SR) {
auto sr = (RtcpSR *) (rtcp);
//设置rtp时间戳与ntp时间戳的对应关系
setNtpStamp(track_idx, sr->rtpts, track->_samplerate, sr->getNtpUnixStampMS());
setNtpStamp(track_idx, sr->rtpts, sr->getNtpUnixStampMS());
}
}
}

View File

@@ -189,7 +189,7 @@ void RtspSession::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *
if ((RtcpType) rtcp->pt == RtcpType::RTCP_SR) {
auto sr = (RtcpSR *) (rtcp);
//设置rtp时间戳与ntp时间戳的对应关系
setNtpStamp(track_idx, sr->rtpts, track->_samplerate, sr->getNtpUnixStampMS());
setNtpStamp(track_idx, sr->rtpts, sr->getNtpUnixStampMS());
}
}
}