2016-12-22 07:53:51 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
|
|
|
|
|
#define SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
|
2016-12-22 07:53:51 -08:00
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
2017-11-14 10:32:15 +01:00
|
|
|
#include "api/optional.h"
|
|
|
|
|
#include "modules/include/module_common_types_public.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/ntp_time.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2016-12-22 07:53:51 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
// Class for converting an RTP timestamp to the NTP domain in milliseconds.
|
|
|
|
|
// The class needs to be trained with (at least 2) RTP/NTP timestamp pairs from
|
|
|
|
|
// RTCP sender reports before the convertion can be done.
|
|
|
|
|
class RtpToNtpEstimator {
|
|
|
|
|
public:
|
|
|
|
|
RtpToNtpEstimator();
|
|
|
|
|
~RtpToNtpEstimator();
|
|
|
|
|
|
|
|
|
|
// RTP and NTP timestamp pair from a RTCP SR report.
|
|
|
|
|
struct RtcpMeasurement {
|
2017-11-14 10:32:15 +01:00
|
|
|
RtcpMeasurement(uint32_t ntp_secs,
|
|
|
|
|
uint32_t ntp_frac,
|
|
|
|
|
int64_t unwrapped_timestamp);
|
2016-12-22 07:53:51 -08:00
|
|
|
bool IsEqual(const RtcpMeasurement& other) const;
|
|
|
|
|
|
|
|
|
|
NtpTime ntp_time;
|
2017-11-14 10:32:15 +01:00
|
|
|
int64_t unwrapped_rtp_timestamp;
|
2016-12-22 07:53:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Estimated parameters from RTP and NTP timestamp pairs in |measurements_|.
|
|
|
|
|
struct Parameters {
|
2017-11-14 10:32:15 +01:00
|
|
|
double frequency_khz;
|
|
|
|
|
double offset_ms;
|
2016-12-22 07:53:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Updates measurements with RTP/NTP timestamp pair from a RTCP sender report.
|
|
|
|
|
// |new_rtcp_sr| is set to true if a new report is added.
|
|
|
|
|
bool UpdateMeasurements(uint32_t ntp_secs,
|
|
|
|
|
uint32_t ntp_frac,
|
|
|
|
|
uint32_t rtp_timestamp,
|
|
|
|
|
bool* new_rtcp_sr);
|
|
|
|
|
|
|
|
|
|
// Converts an RTP timestamp to the NTP domain in milliseconds.
|
|
|
|
|
// Returns true on success, false otherwise.
|
|
|
|
|
bool Estimate(int64_t rtp_timestamp, int64_t* rtp_timestamp_ms) const;
|
|
|
|
|
|
2017-11-15 16:14:28 +00:00
|
|
|
const rtc::Optional<Parameters> params() const {
|
|
|
|
|
rtc::Optional<Parameters> res;
|
|
|
|
|
if (params_calculated_) {
|
|
|
|
|
res.emplace(params_);
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2016-12-22 07:53:51 -08:00
|
|
|
|
2017-06-30 06:28:13 -07:00
|
|
|
static const int kMaxInvalidSamples = 3;
|
|
|
|
|
|
2016-12-22 07:53:51 -08:00
|
|
|
private:
|
|
|
|
|
void UpdateParameters();
|
|
|
|
|
|
2017-06-30 06:28:13 -07:00
|
|
|
int consecutive_invalid_samples_;
|
2016-12-22 07:53:51 -08:00
|
|
|
std::list<RtcpMeasurement> measurements_;
|
|
|
|
|
Parameters params_;
|
2017-11-14 10:32:15 +01:00
|
|
|
bool params_calculated_;
|
|
|
|
|
mutable TimestampUnwrapper unwrapper_;
|
2016-12-22 07:53:51 -08:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
|