namespace webrtc {
namespace { // Maximum number of RTCP SR reports to use to map between RTP and NTP.
constexpr size_t kNumRtcpReportsToUse = 20; // Don't allow NTP timestamps to jump more than 1 hour. Chosen arbitrary as big // enough to not affect normal use-cases. Yet it is smaller than RTP wrap-around // half-period (90khz RTP clock wrap-arounds every 13.25 hours). After half of // wrap-around period it is impossible to unwrap RTP timestamps correctly.
constexpr uint64_t kMaxAllowedRtcpNtpInterval = uint64_t{60 * 60} << 32;
} // namespace
void RtpToNtpEstimator::UpdateParameters() {
size_t n = measurements_.size();
if (n < 2) return;
// Run linear regression: // Given x[] and y[] writes out such k and b that line y=k*x+b approximates // given points in the best way (Least Squares Method). auto x = [](const RtcpMeasurement& m) { returnstatic_cast<double>(m.unwrapped_rtp_timestamp);
}; auto y = [](const RtcpMeasurement& m) { returnstatic_cast<double>(static_cast<uint64_t>(m.ntp_time));
};
for (const RtcpMeasurement& measurement : measurements_) { // Use || since two equal timestamps will result in zero frequency.
if (measurement.ntp_time == ntp ||
measurement.unwrapped_rtp_timestamp == unwrapped_rtp_timestamp) { return kSameMeasurement;
}
}
if (!new_measurement.ntp_time.Valid()) return kInvalidMeasurement;
uint64_t ntp_new = static_cast<uint64_t>(new_measurement.ntp_time); bool invalid_sample = false;
if (!measurements_.empty()) {
int64_t old_rtp_timestamp = measurements_.front().unwrapped_rtp_timestamp;
uint64_t old_ntp = static_cast<uint64_t>(measurements_.front().ntp_time);
if (ntp_new <= old_ntp || ntp_new > old_ntp + kMaxAllowedRtcpNtpInterval) {
invalid_sample = true;
} else if (unwrapped_rtp_timestamp <= old_rtp_timestamp) {
RTC_LOG(LS_WARNING)
<< "Newer RTCP SR report with older RTP timestamp, dropping";
invalid_sample = true;
} else if (unwrapped_rtp_timestamp - old_rtp_timestamp > (1 << 25)) { // Sanity check. No jumps too far into the future in rtp.
invalid_sample = true;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.