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 namespace { |
| 16 |
| 17 // Bitwise merging of values to produce an ordered key for entries in the |
| 18 // BoundCalculator::events_ map. |
| 19 uint64_t MakeEventKey(RtpTimeTicks rtp, uint16_t packet_id, bool audio) { |
| 20 return (static_cast<uint64_t>(rtp.lower_32_bits()) << 32) | |
| 21 (static_cast<uint64_t>(packet_id) << 1) | |
| 22 (audio ? UINT64_C(1) : UINT64_C(0)); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
15 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::BoundCalculator() | 27 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::BoundCalculator() |
16 : has_bound_(false) {} | 28 : has_bound_(false) {} |
17 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::~BoundCalculator() {} | 29 ReceiverTimeOffsetEstimatorImpl::BoundCalculator::~BoundCalculator() {} |
18 | 30 |
19 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetSent( | 31 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetSent( |
20 uint32_t rtp, | 32 RtpTimeTicks rtp, |
21 uint32_t packet_id, | 33 uint16_t packet_id, |
22 bool audio, | 34 bool audio, |
23 base::TimeTicks t) { | 35 base::TimeTicks t) { |
24 uint64_t key = (static_cast<uint64_t>(rtp) << 32) | (packet_id << 1) | | 36 const uint64_t key = MakeEventKey(rtp, packet_id, audio); |
25 static_cast<uint64_t>(audio); | |
26 events_[key].first = t; | 37 events_[key].first = t; |
27 CheckUpdate(key); | 38 CheckUpdate(key); |
28 } | 39 } |
29 | 40 |
30 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetReceived( | 41 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::SetReceived( |
31 uint32_t rtp, | 42 RtpTimeTicks rtp, |
32 uint16_t packet_id, | 43 uint16_t packet_id, |
33 bool audio, | 44 bool audio, |
34 base::TimeTicks t) { | 45 base::TimeTicks t) { |
35 uint64_t key = (static_cast<uint64_t>(rtp) << 32) | (packet_id << 1) | | 46 const uint64_t key = MakeEventKey(rtp, packet_id, audio); |
36 static_cast<uint64_t>(audio); | |
37 events_[key].second = t; | 47 events_[key].second = t; |
38 CheckUpdate(key); | 48 CheckUpdate(key); |
39 } | 49 } |
40 | 50 |
41 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::UpdateBound( | 51 void ReceiverTimeOffsetEstimatorImpl::BoundCalculator::UpdateBound( |
42 base::TimeTicks sent, base::TimeTicks received) { | 52 base::TimeTicks sent, base::TimeTicks received) { |
43 base::TimeDelta delta = received - sent; | 53 base::TimeDelta delta = received - sent; |
44 if (has_bound_) { | 54 if (has_bound_) { |
45 if (delta < bound_) { | 55 if (delta < bound_) { |
46 bound_ = delta; | 56 bound_ = delta; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 break; | 146 break; |
137 default: | 147 default: |
138 // Ignored | 148 // Ignored |
139 break; | 149 break; |
140 } | 150 } |
141 } | 151 } |
142 | 152 |
143 | 153 |
144 } // namespace cast | 154 } // namespace cast |
145 } // namespace media | 155 } // namespace media |
OLD | NEW |