OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time/tick_clock.h" | 9 #include "base/time/tick_clock.h" |
10 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" | 10 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 namespace cast { | 13 namespace cast { |
14 | 14 |
15 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::BoundCalculator() | 15 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::BoundCalculator() |
16 : has_bound_(false) {} | 16 : has_bound_(false) {} |
17 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::~BoundCalculator() {} | 17 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::~BoundCalculator() {} |
18 | 18 |
19 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetSent( | 19 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetSent( |
20 uint32 rtp, | 20 uint32_t rtp, |
21 uint32 packet_id, | 21 uint32_t packet_id, |
22 bool audio, | 22 bool audio, |
23 base::TimeTicks t) { | 23 base::TimeTicks t) { |
24 uint64 key = (static_cast<uint64>(rtp) << 32) | (packet_id << 1) | | 24 uint64_t key = (static_cast<uint64_t>(rtp) << 32) | (packet_id << 1) | |
25 static_cast<uint64>(audio); | 25 static_cast<uint64_t>(audio); |
26 events_[key].first = t; | 26 events_[key].first = t; |
27 CheckUpdate(key); | 27 CheckUpdate(key); |
28 } | 28 } |
29 | 29 |
30 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetReceived( | 30 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetReceived( |
31 uint32 rtp, | 31 uint32_t rtp, |
32 uint16 packet_id, | 32 uint16_t packet_id, |
33 bool audio, | 33 bool audio, |
34 base::TimeTicks t) { | 34 base::TimeTicks t) { |
35 uint64 key = (static_cast<uint64>(rtp) << 32) | (packet_id << 1) | | 35 uint64_t key = (static_cast<uint64_t>(rtp) << 32) | (packet_id << 1) | |
36 static_cast<uint64>(audio); | 36 static_cast<uint64_t>(audio); |
37 events_[key].second = t; | 37 events_[key].second = t; |
38 CheckUpdate(key); | 38 CheckUpdate(key); |
39 } | 39 } |
40 | 40 |
41 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::UpdateBound( | 41 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::UpdateBound( |
42 base::TimeTicks sent, base::TimeTicks received) { | 42 base::TimeTicks sent, base::TimeTicks received) { |
43 base::TimeDelta delta = received - sent; | 43 base::TimeDelta delta = received - sent; |
44 if (has_bound_) { | 44 if (has_bound_) { |
45 if (delta < bound_) { | 45 if (delta < bound_) { |
46 bound_ = delta; | 46 bound_ = delta; |
47 } else { | 47 } else { |
48 bound_ += (delta - bound_) / kClockDriftSpeed; | 48 bound_ += (delta - bound_) / kClockDriftSpeed; |
49 } | 49 } |
50 } else { | 50 } else { |
51 bound_ = delta; | 51 bound_ = delta; |
52 } | 52 } |
53 has_bound_ = true; | 53 has_bound_ = true; |
54 } | 54 } |
55 | 55 |
56 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::CheckUpdate( | 56 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::CheckUpdate( |
57 uint64 key) { | 57 uint64_t key) { |
58 const TimeTickPair& ticks = events_[key]; | 58 const TimeTickPair& ticks = events_[key]; |
59 if (!ticks.first.is_null() && !ticks.second.is_null()) { | 59 if (!ticks.first.is_null() && !ticks.second.is_null()) { |
60 UpdateBound(ticks.first, ticks.second); | 60 UpdateBound(ticks.first, ticks.second); |
61 events_.erase(key); | 61 events_.erase(key); |
62 return; | 62 return; |
63 } | 63 } |
64 | 64 |
65 if (events_.size() > kMaxEventTimesMapSize) { | 65 if (events_.size() > kMaxEventTimesMapSize) { |
66 EventMap::iterator i = ModMapOldest(&events_); | 66 EventMap::iterator i = ModMapOldest(&events_); |
67 if (i != events_.end()) { | 67 if (i != events_.end()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 break; | 136 break; |
137 default: | 137 default: |
138 // Ignored | 138 // Ignored |
139 break; | 139 break; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 } // namespace cast | 144 } // namespace cast |
145 } // namespace media | 145 } // namespace media |
OLD | NEW |