OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 last_timing_log_ms_(-1) { | 26 last_timing_log_ms_(-1) { |
27 } | 27 } |
28 | 28 |
29 RemoteNtpTimeEstimator::~RemoteNtpTimeEstimator() {} | 29 RemoteNtpTimeEstimator::~RemoteNtpTimeEstimator() {} |
30 | 30 |
31 bool RemoteNtpTimeEstimator::UpdateRtcpTimestamp(int64_t rtt, | 31 bool RemoteNtpTimeEstimator::UpdateRtcpTimestamp(int64_t rtt, |
32 uint32_t ntp_secs, | 32 uint32_t ntp_secs, |
33 uint32_t ntp_frac, | 33 uint32_t ntp_frac, |
34 uint32_t rtcp_timestamp) { | 34 uint32_t rtcp_timestamp) { |
35 bool new_rtcp_sr = false; | 35 bool new_rtcp_sr = false; |
36 if (!UpdateRtcpList( | 36 if (!rtp_to_ntp_.UpdateMeasurements(ntp_secs, ntp_frac, rtcp_timestamp, |
37 ntp_secs, ntp_frac, rtcp_timestamp, &rtcp_list_, &new_rtcp_sr)) { | 37 &new_rtcp_sr)) { |
38 return false; | 38 return false; |
39 } | 39 } |
40 if (!new_rtcp_sr) { | 40 if (!new_rtcp_sr) { |
41 // No new RTCP SR since last time this function was called. | 41 // No new RTCP SR since last time this function was called. |
42 return true; | 42 return true; |
43 } | 43 } |
44 // Update extrapolator with the new arrival time. | 44 // Update extrapolator with the new arrival time. |
45 // The extrapolator assumes the TimeInMilliseconds time. | 45 // The extrapolator assumes the TimeInMilliseconds time. |
46 int64_t receiver_arrival_time_ms = clock_->TimeInMilliseconds(); | 46 int64_t receiver_arrival_time_ms = clock_->TimeInMilliseconds(); |
47 int64_t sender_send_time_ms = Clock::NtpToMs(ntp_secs, ntp_frac); | 47 int64_t sender_send_time_ms = Clock::NtpToMs(ntp_secs, ntp_frac); |
48 int64_t sender_arrival_time_90k = (sender_send_time_ms + rtt / 2) * 90; | 48 int64_t sender_arrival_time_90k = (sender_send_time_ms + rtt / 2) * 90; |
49 ts_extrapolator_->Update(receiver_arrival_time_ms, sender_arrival_time_90k); | 49 ts_extrapolator_->Update(receiver_arrival_time_ms, sender_arrival_time_90k); |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 int64_t RemoteNtpTimeEstimator::Estimate(uint32_t rtp_timestamp) { | 53 int64_t RemoteNtpTimeEstimator::Estimate(uint32_t rtp_timestamp) { |
54 int64_t sender_capture_ntp_ms = 0; | 54 int64_t sender_capture_ntp_ms = 0; |
55 if (!RtpToNtpMs(rtp_timestamp, rtcp_list_, &sender_capture_ntp_ms)) { | 55 if (!rtp_to_ntp_.Estimate(rtp_timestamp, &sender_capture_ntp_ms)) { |
56 return -1; | 56 return -1; |
57 } | 57 } |
58 uint32_t timestamp = sender_capture_ntp_ms * 90; | 58 uint32_t timestamp = sender_capture_ntp_ms * 90; |
59 int64_t receiver_capture_ms = | 59 int64_t receiver_capture_ms = |
60 ts_extrapolator_->ExtrapolateLocalTime(timestamp); | 60 ts_extrapolator_->ExtrapolateLocalTime(timestamp); |
61 int64_t ntp_offset = | 61 int64_t ntp_offset = |
62 clock_->CurrentNtpInMilliseconds() - clock_->TimeInMilliseconds(); | 62 clock_->CurrentNtpInMilliseconds() - clock_->TimeInMilliseconds(); |
63 int64_t receiver_capture_ntp_ms = receiver_capture_ms + ntp_offset; | 63 int64_t receiver_capture_ntp_ms = receiver_capture_ms + ntp_offset; |
64 int64_t now_ms = clock_->TimeInMilliseconds(); | 64 int64_t now_ms = clock_->TimeInMilliseconds(); |
65 if (now_ms - last_timing_log_ms_ > kTimingLogIntervalMs) { | 65 if (now_ms - last_timing_log_ms_ > kTimingLogIntervalMs) { |
66 LOG(LS_INFO) << "RTP timestamp: " << rtp_timestamp | 66 LOG(LS_INFO) << "RTP timestamp: " << rtp_timestamp |
67 << " in NTP clock: " << sender_capture_ntp_ms | 67 << " in NTP clock: " << sender_capture_ntp_ms |
68 << " estimated time in receiver clock: " << receiver_capture_ms | 68 << " estimated time in receiver clock: " << receiver_capture_ms |
69 << " converted to NTP clock: " << receiver_capture_ntp_ms; | 69 << " converted to NTP clock: " << receiver_capture_ntp_ms; |
70 last_timing_log_ms_ = now_ms; | 70 last_timing_log_ms_ = now_ms; |
71 } | 71 } |
72 return receiver_capture_ntp_ms; | 72 return receiver_capture_ntp_ms; |
73 } | 73 } |
74 | 74 |
75 } // namespace webrtc | 75 } // namespace webrtc |
OLD | NEW |