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
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-12-22 07:53:51 -08:00
|
|
|
#include <list>
|
|
|
|
|
|
2018-06-21 10:17:24 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-11-14 10:32:15 +01:00
|
|
|
#include "modules/include/module_common_types_public.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2017-11-15 16:48:04 +00:00
|
|
|
#include "rtc_base/numerics/moving_median_filter.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/ntp_time.h"
|
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
|
|
|
};
|
|
|
|
|
|
2021-07-27 12:40:17 +02:00
|
|
|
// Estimated parameters from RTP and NTP timestamp pairs in `measurements_`.
|
2016-12-22 07:53:51 -08:00
|
|
|
struct Parameters {
|
2017-11-15 16:48:04 +00:00
|
|
|
Parameters() : frequency_khz(0.0), offset_ms(0.0) {}
|
|
|
|
|
|
2018-11-12 15:03:51 +01:00
|
|
|
Parameters(double frequency_khz, double offset_ms)
|
|
|
|
|
: frequency_khz(frequency_khz), offset_ms(offset_ms) {}
|
|
|
|
|
|
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.
|
2021-07-27 12:40:17 +02:00
|
|
|
// `new_rtcp_sr` is set to true if a new report is added.
|
2016-12-22 07:53:51 -08:00
|
|
|
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.
|
2018-11-12 15:03:51 +01:00
|
|
|
bool Estimate(int64_t rtp_timestamp, int64_t* ntp_timestamp_ms) const;
|
2016-12-22 07:53:51 -08:00
|
|
|
|
2017-11-15 16:48:04 +00:00
|
|
|
// Returns estimated rtp to ntp linear transform parameters.
|
2018-06-21 10:17:24 +02:00
|
|
|
const absl::optional<Parameters> params() const;
|
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_;
|
2018-11-12 15:03:51 +01:00
|
|
|
absl::optional<Parameters> params_;
|
2017-11-14 10:32:15 +01:00
|
|
|
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_
|