Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Unified Diff: webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc

Issue 2574133003: Make class of static functions in rtp_to_ntp.h: (Closed)
Patch Set: address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
diff --git a/webrtc/system_wrappers/source/rtp_to_ntp.cc b/webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
similarity index 55%
rename from webrtc/system_wrappers/source/rtp_to_ntp.cc
rename to webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
index cbd5020a1f0fadf6247c0b7d114765a9c2710503..339635e88dd9da1d47dfadd2d917a13438bd45e9 100644
--- a/webrtc/system_wrappers/source/rtp_to_ntp.cc
+++ b/webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "webrtc/system_wrappers/include/rtp_to_ntp.h"
+#include "webrtc/system_wrappers/include/rtp_to_ntp_estimator.h"
#include "webrtc/base/logging.h"
#include "webrtc/system_wrappers/include/clock.h"
@@ -19,16 +19,16 @@ namespace {
const size_t kNumRtcpReportsToUse = 2;
// Calculates the RTP timestamp frequency from two pairs of NTP/RTP timestamps.
-bool CalculateFrequency(int64_t rtcp_ntp_ms1,
+bool CalculateFrequency(int64_t ntp_ms1,
uint32_t rtp_timestamp1,
- int64_t rtcp_ntp_ms2,
+ int64_t ntp_ms2,
uint32_t rtp_timestamp2,
double* frequency_khz) {
- if (rtcp_ntp_ms1 <= rtcp_ntp_ms2) {
+ if (ntp_ms1 <= ntp_ms2)
return false;
- }
+
*frequency_khz = static_cast<double>(rtp_timestamp1 - rtp_timestamp2) /
- static_cast<double>(rtcp_ntp_ms1 - rtcp_ntp_ms2);
+ static_cast<double>(ntp_ms1 - ntp_ms2);
return true;
}
@@ -45,133 +45,126 @@ bool CompensateForWrapAround(uint32_t new_timestamp,
*compensated_timestamp = new_timestamp + (wraps << 32);
return true;
}
-} // namespace
-
-// Class holding RTP and NTP timestamp from a RTCP SR report.
-RtcpMeasurement::RtcpMeasurement() : ntp_time(0, 0), rtp_timestamp(0) {}
-RtcpMeasurement::RtcpMeasurement(uint32_t ntp_secs,
- uint32_t ntp_frac,
- uint32_t timestamp)
- : ntp_time(ntp_secs, ntp_frac), rtp_timestamp(timestamp) {}
-
-bool RtcpMeasurement::IsEqual(const RtcpMeasurement& other) const {
- // Use || since two equal timestamps will result in zero frequency and in
- // RtpToNtpMs, |rtp_timestamp_ms| is estimated by dividing by the frequency.
- return (ntp_time == other.ntp_time) || (rtp_timestamp == other.rtp_timestamp);
-}
-
-// Class holding list of RTP and NTP timestamp pairs.
-RtcpMeasurements::RtcpMeasurements() {}
-RtcpMeasurements::~RtcpMeasurements() {}
-
-bool RtcpMeasurements::Contains(const RtcpMeasurement& other) const {
- for (const auto& it : list) {
- if (it.IsEqual(other))
+bool Contains(const std::list<RtpToNtpEstimator::RtcpMeasurement>& measurements,
+ const RtpToNtpEstimator::RtcpMeasurement& other) {
+ for (const auto& measurement : measurements) {
+ if (measurement.IsEqual(other))
return true;
}
return false;
}
-bool RtcpMeasurements::IsValid(const RtcpMeasurement& other) const {
+bool IsValid(const std::list<RtpToNtpEstimator::RtcpMeasurement>& measurements,
+ const RtpToNtpEstimator::RtcpMeasurement& other) {
if (!other.ntp_time.Valid())
return false;
int64_t ntp_ms_new = other.ntp_time.ToMs();
- for (const auto& it : list) {
- if (ntp_ms_new <= it.ntp_time.ToMs()) {
+ for (const auto& measurement : measurements) {
+ if (ntp_ms_new <= measurement.ntp_time.ToMs()) {
// Old report.
return false;
}
int64_t timestamp_new = other.rtp_timestamp;
- if (!CompensateForWrapAround(timestamp_new, it.rtp_timestamp,
+ if (!CompensateForWrapAround(timestamp_new, measurement.rtp_timestamp,
&timestamp_new)) {
return false;
}
- if (timestamp_new <= it.rtp_timestamp) {
+ if (timestamp_new <= measurement.rtp_timestamp) {
LOG(LS_WARNING) << "Newer RTCP SR report with older RTP timestamp.";
return false;
}
}
return true;
}
+} // namespace
-void RtcpMeasurements::UpdateParameters() {
- if (list.size() != kNumRtcpReportsToUse)
+RtpToNtpEstimator::RtcpMeasurement::RtcpMeasurement(uint32_t ntp_secs,
+ uint32_t ntp_frac,
+ uint32_t timestamp)
+ : ntp_time(ntp_secs, ntp_frac), rtp_timestamp(timestamp) {}
+
+bool RtpToNtpEstimator::RtcpMeasurement::IsEqual(
+ const RtcpMeasurement& other) const {
+ // Use || since two equal timestamps will result in zero frequency and in
+ // RtpToNtpMs, |rtp_timestamp_ms| is estimated by dividing by the frequency.
+ return (ntp_time == other.ntp_time) || (rtp_timestamp == other.rtp_timestamp);
+}
+
+// Class for converting an RTP timestamp to the NTP domain.
+RtpToNtpEstimator::RtpToNtpEstimator() {}
+RtpToNtpEstimator::~RtpToNtpEstimator() {}
+
+void RtpToNtpEstimator::UpdateParameters() {
+ if (measurements_.size() != kNumRtcpReportsToUse)
return;
- int64_t timestamp_new = list.front().rtp_timestamp;
- int64_t timestamp_old = list.back().rtp_timestamp;
+ int64_t timestamp_new = measurements_.front().rtp_timestamp;
+ int64_t timestamp_old = measurements_.back().rtp_timestamp;
if (!CompensateForWrapAround(timestamp_new, timestamp_old, &timestamp_new))
return;
- int64_t ntp_ms_new = list.front().ntp_time.ToMs();
- int64_t ntp_ms_old = list.back().ntp_time.ToMs();
+ int64_t ntp_ms_new = measurements_.front().ntp_time.ToMs();
+ int64_t ntp_ms_old = measurements_.back().ntp_time.ToMs();
if (!CalculateFrequency(ntp_ms_new, timestamp_new, ntp_ms_old, timestamp_old,
- &params.frequency_khz)) {
+ &params_.frequency_khz)) {
return;
}
- params.offset_ms = timestamp_new - params.frequency_khz * ntp_ms_new;
- params.calculated = true;
+ params_.offset_ms = timestamp_new - params_.frequency_khz * ntp_ms_new;
+ params_.calculated = true;
}
-// Updates list holding NTP and RTP timestamp pairs.
-bool UpdateRtcpList(uint32_t ntp_secs,
- uint32_t ntp_frac,
- uint32_t rtp_timestamp,
- RtcpMeasurements* rtcp_measurements,
- bool* new_rtcp_sr) {
+bool RtpToNtpEstimator::UpdateMeasurements(uint32_t ntp_secs,
+ uint32_t ntp_frac,
+ uint32_t rtp_timestamp,
+ bool* new_rtcp_sr) {
*new_rtcp_sr = false;
RtcpMeasurement measurement(ntp_secs, ntp_frac, rtp_timestamp);
- if (rtcp_measurements->Contains(measurement)) {
+ if (Contains(measurements_, measurement)) {
// RTCP SR report already added.
return true;
}
-
- if (!rtcp_measurements->IsValid(measurement)) {
+ if (!IsValid(measurements_, measurement)) {
// Old report or invalid parameters.
return false;
}
// Insert new RTCP SR report.
- if (rtcp_measurements->list.size() == kNumRtcpReportsToUse)
- rtcp_measurements->list.pop_back();
+ if (measurements_.size() == kNumRtcpReportsToUse)
+ measurements_.pop_back();
- rtcp_measurements->list.push_front(measurement);
+ measurements_.push_front(measurement);
*new_rtcp_sr = true;
// List updated, calculate new parameters.
- rtcp_measurements->UpdateParameters();
+ UpdateParameters();
return true;
}
-// Converts |rtp_timestamp| to the NTP time base using the NTP and RTP timestamp
-// pairs in |rtcp|. The converted timestamp is returned in
-// |rtp_timestamp_in_ms|. This function compensates for wrap arounds in RTP
-// timestamps and returns false if it can't do the conversion due to reordering.
-bool RtpToNtpMs(int64_t rtp_timestamp,
- const RtcpMeasurements& rtcp,
- int64_t* rtp_timestamp_in_ms) {
- if (!rtcp.params.calculated || rtcp.list.empty())
+bool RtpToNtpEstimator::Estimate(int64_t rtp_timestamp,
+ int64_t* rtp_timestamp_ms) const {
+ if (!params_.calculated || measurements_.empty())
return false;
- uint32_t rtcp_timestamp_old = rtcp.list.back().rtp_timestamp;
+ uint32_t rtp_timestamp_old = measurements_.back().rtp_timestamp;
int64_t rtp_timestamp_unwrapped;
- if (!CompensateForWrapAround(rtp_timestamp, rtcp_timestamp_old,
+ if (!CompensateForWrapAround(rtp_timestamp, rtp_timestamp_old,
&rtp_timestamp_unwrapped)) {
return false;
}
- double rtp_timestamp_ms =
- (static_cast<double>(rtp_timestamp_unwrapped) - rtcp.params.offset_ms) /
- rtcp.params.frequency_khz +
+ double rtp_ms =
+ (static_cast<double>(rtp_timestamp_unwrapped) - params_.offset_ms) /
+ params_.frequency_khz +
0.5f;
- if (rtp_timestamp_ms < 0) {
+
+ if (rtp_ms < 0)
return false;
- }
- *rtp_timestamp_in_ms = rtp_timestamp_ms;
+
+ *rtp_timestamp_ms = rtp_ms;
return true;
}
« no previous file with comments | « webrtc/system_wrappers/source/rtp_to_ntp.cc ('k') | webrtc/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698