blob: 0bd3a82afcfe0e33d2874a541483d07279a87201 [file] [log] [blame]
Sebastian Janssonb34556e2018-03-21 14:38:32 +01001/*
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 16:47:49 +010013#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Sebastian Janssonb34556e2018-03-21 14:38:32 +010015#include <memory>
16
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "api/units/time_delta.h"
18#include "rtc_base/experiments/field_trial_parser.h"
Sebastian Janssonb34556e2018-03-21 14:38:32 +010019
20namespace webrtc {
21
Christoffer Rodbro76ad1542018-10-12 11:15:09 +020022struct ReceiveTimeCalculatorConfig {
23 ReceiveTimeCalculatorConfig();
24 ReceiveTimeCalculatorConfig(const ReceiveTimeCalculatorConfig&);
25 ReceiveTimeCalculatorConfig& operator=(const ReceiveTimeCalculatorConfig&) =
26 default;
27 ~ReceiveTimeCalculatorConfig();
28 FieldTrialParameter<TimeDelta> max_packet_time_repair;
29 FieldTrialParameter<TimeDelta> stall_threshold;
30 FieldTrialParameter<TimeDelta> tolerance;
31 FieldTrialParameter<TimeDelta> max_stall;
32};
33
Sebastian Janssonb34556e2018-03-21 14:38:32 +010034// The receive time calculator serves the purpose of combining packet time
35// stamps with a safely incremental clock. This assumes that the packet time
36// stamps are based on lower layer timestamps that have more accurate time
37// increments since they are based on the exact receive time. They might
38// however, have large jumps due to clock resets in the system. To compensate
39// this they are combined with a safe clock source that is guaranteed to be
40// consistent, but it will not be able to measure the exact time when a packet
41// is received.
42class ReceiveTimeCalculator {
43 public:
44 static std::unique_ptr<ReceiveTimeCalculator> CreateFromFieldTrial();
Christoffer Rodbro76ad1542018-10-12 11:15:09 +020045 ReceiveTimeCalculator();
46 int64_t ReconcileReceiveTimes(int64_t packet_time_us_,
47 int64_t system_time_us_,
48 int64_t safe_time_us_);
Sebastian Janssonb34556e2018-03-21 14:38:32 +010049
50 private:
Christoffer Rodbro76ad1542018-10-12 11:15:09 +020051 int64_t last_corrected_time_us_ = -1;
52 int64_t last_packet_time_us_ = -1;
53 int64_t last_system_time_us_ = -1;
54 int64_t last_safe_time_us_ = -1;
55 int64_t total_system_time_passed_us_ = 0;
56 int64_t static_clock_offset_us_ = 0;
57 int64_t small_reset_during_stall_ = false;
58 ReceiveTimeCalculatorConfig config_;
Sebastian Janssonb34556e2018-03-21 14:38:32 +010059};
60} // namespace webrtc
61#endif // CALL_RECEIVE_TIME_CALCULATOR_H_