blob: 57ba3318441b5ed76ae1706fed637262be567937 [file] [log] [blame]
Sebastian Janssonb34556e2018-03-21 13:38:321/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#ifndef CALL_RECEIVE_TIME_CALCULATOR_H_
11#define CALL_RECEIVE_TIME_CALCULATOR_H_
12
Yves Gerey3e707812018-11-28 15:47:4913#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3314
Sebastian Janssonb34556e2018-03-21 13:38:3215#include <memory>
16
Jonas Orelande62c2f22022-03-29 09:04:4817#include "api/field_trials_view.h"
Yves Gerey3e707812018-11-28 15:47:4918#include "api/units/time_delta.h"
19#include "rtc_base/experiments/field_trial_parser.h"
Sebastian Janssonb34556e2018-03-21 13:38:3220
21namespace webrtc {
22
Christoffer Rodbro76ad1542018-10-12 09:15:0923struct ReceiveTimeCalculatorConfig {
Jonas Orelande62c2f22022-03-29 09:04:4824 explicit ReceiveTimeCalculatorConfig(const FieldTrialsView& field_trials);
Christoffer Rodbro76ad1542018-10-12 09:15:0925 ReceiveTimeCalculatorConfig(const ReceiveTimeCalculatorConfig&);
26 ReceiveTimeCalculatorConfig& operator=(const ReceiveTimeCalculatorConfig&) =
27 default;
28 ~ReceiveTimeCalculatorConfig();
29 FieldTrialParameter<TimeDelta> max_packet_time_repair;
30 FieldTrialParameter<TimeDelta> stall_threshold;
31 FieldTrialParameter<TimeDelta> tolerance;
32 FieldTrialParameter<TimeDelta> max_stall;
33};
34
Sebastian Janssonb34556e2018-03-21 13:38:3235// The receive time calculator serves the purpose of combining packet time
36// stamps with a safely incremental clock. This assumes that the packet time
37// stamps are based on lower layer timestamps that have more accurate time
38// increments since they are based on the exact receive time. They might
39// however, have large jumps due to clock resets in the system. To compensate
40// this they are combined with a safe clock source that is guaranteed to be
41// consistent, but it will not be able to measure the exact time when a packet
42// is received.
43class ReceiveTimeCalculator {
44 public:
Jonas Orelandc7f691a2022-03-09 14:12:0745 static std::unique_ptr<ReceiveTimeCalculator> CreateFromFieldTrial(
Jonas Orelande62c2f22022-03-29 09:04:4846 const FieldTrialsView& field_trials);
47 explicit ReceiveTimeCalculator(const FieldTrialsView& field_trials);
Christoffer Rodbro76ad1542018-10-12 09:15:0948 int64_t ReconcileReceiveTimes(int64_t packet_time_us_,
49 int64_t system_time_us_,
50 int64_t safe_time_us_);
Sebastian Janssonb34556e2018-03-21 13:38:3251
52 private:
Christoffer Rodbro76ad1542018-10-12 09:15:0953 int64_t last_corrected_time_us_ = -1;
54 int64_t last_packet_time_us_ = -1;
55 int64_t last_system_time_us_ = -1;
56 int64_t last_safe_time_us_ = -1;
57 int64_t total_system_time_passed_us_ = 0;
58 int64_t static_clock_offset_us_ = 0;
59 int64_t small_reset_during_stall_ = false;
60 ReceiveTimeCalculatorConfig config_;
Sebastian Janssonb34556e2018-03-21 13:38:3261};
62} // namespace webrtc
63#endif // CALL_RECEIVE_TIME_CALCULATOR_H_