1 /*
2  *  Copyright (c) 2014 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 
11 #ifndef WEBRTC_MODULES_RTP_RTCP_INCLUDE_REMOTE_NTP_TIME_ESTIMATOR_H_
12 #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_REMOTE_NTP_TIME_ESTIMATOR_H_
13 
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/system_wrappers/include/rtp_to_ntp.h"
16 
17 namespace webrtc {
18 
19 class Clock;
20 class TimestampExtrapolator;
21 
22 // RemoteNtpTimeEstimator can be used to estimate a given RTP timestamp's NTP
23 // time in local timebase.
24 // Note that it needs to be trained with at least 2 RTCP SR (by calling
25 // |UpdateRtcpTimestamp|) before it can be used.
26 class RemoteNtpTimeEstimator {
27  public:
28   explicit RemoteNtpTimeEstimator(Clock* clock);
29 
30   ~RemoteNtpTimeEstimator();
31 
32   // Updates the estimator with round trip time |rtt|, NTP seconds |ntp_secs|,
33   // NTP fraction |ntp_frac| and RTP timestamp |rtcp_timestamp|.
34   bool UpdateRtcpTimestamp(int64_t rtt, uint32_t ntp_secs, uint32_t ntp_frac,
35                            uint32_t rtp_timestamp);
36 
37   // Estimates the NTP timestamp in local timebase from |rtp_timestamp|.
38   // Returns the NTP timestamp in ms when success. -1 if failed.
39   int64_t Estimate(uint32_t rtp_timestamp);
40 
41  private:
42   Clock* clock_;
43   rtc::scoped_ptr<TimestampExtrapolator> ts_extrapolator_;
44   RtcpList rtcp_list_;
45   int64_t last_timing_log_ms_;
46   RTC_DISALLOW_COPY_AND_ASSIGN(RemoteNtpTimeEstimator);
47 };
48 
49 }  // namespace webrtc
50 
51 #endif  // WEBRTC_MODULES_RTP_RTCP_INCLUDE_REMOTE_NTP_TIME_ESTIMATOR_H_
52