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 "media/cast/logging/receiver_time_offset_estimator_impl.h" | 9 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 namespace cast { | 12 namespace cast { |
13 | 13 |
14 // This should be large enough so that we can collect all 3 events before | 14 // This should be large enough so that we can collect all 3 events before |
15 // the entry gets removed from the map. | 15 // the entry gets removed from the map. |
16 const size_t kMaxEventTimesMapSize = 100; | 16 const size_t kMaxEventTimesMapSize = 100; |
17 | 17 |
18 ReceiverTimeOffsetEstimatorImpl::ReceiverTimeOffsetEstimatorImpl() | 18 ReceiverTimeOffsetEstimatorImpl::ReceiverTimeOffsetEstimatorImpl() |
19 : bounded_(false) {} | 19 : bounded_(false) {} |
20 | 20 |
21 ReceiverTimeOffsetEstimatorImpl::~ReceiverTimeOffsetEstimatorImpl() { | 21 ReceiverTimeOffsetEstimatorImpl::~ReceiverTimeOffsetEstimatorImpl() { |
22 DCHECK(thread_checker_.CalledOnValidThread()); | 22 DCHECK(thread_checker_.CalledOnValidThread()); |
23 } | 23 } |
24 | 24 |
25 void ReceiverTimeOffsetEstimatorImpl::OnReceiveFrameEvent( | 25 void ReceiverTimeOffsetEstimatorImpl::OnReceiveFrameEvent( |
26 const FrameEvent& frame_event) { | 26 const FrameEvent& frame_event) { |
27 DCHECK(thread_checker_.CalledOnValidThread()); | 27 DCHECK(thread_checker_.CalledOnValidThread()); |
| 28 |
| 29 if (frame_event.media_type != VIDEO_EVENT) |
| 30 return; |
| 31 |
28 CastLoggingEvent event = frame_event.type; | 32 CastLoggingEvent event = frame_event.type; |
29 if (event != kVideoFrameEncoded && event != kVideoAckSent && | 33 if (event != FRAME_ENCODED && event != FRAME_ACK_SENT && |
30 event != kVideoAckReceived) | 34 event != FRAME_ACK_RECEIVED) |
31 return; | 35 return; |
32 | 36 |
33 EventTimesMap::iterator it = event_times_map_.find(frame_event.rtp_timestamp); | 37 EventTimesMap::iterator it = event_times_map_.find(frame_event.rtp_timestamp); |
34 if (it == event_times_map_.end()) { | 38 if (it == event_times_map_.end()) { |
35 EventTimes event_times; | 39 EventTimes event_times; |
36 it = event_times_map_.insert(std::make_pair(frame_event.rtp_timestamp, | 40 it = event_times_map_.insert(std::make_pair(frame_event.rtp_timestamp, |
37 event_times)).first; | 41 event_times)).first; |
38 } | 42 } |
39 switch (event) { | 43 switch (event) { |
40 case kVideoFrameEncoded: | 44 case FRAME_ENCODED: |
41 // Encode is supposed to happen only once. If we see duplicate event, | 45 // Encode is supposed to happen only once. If we see duplicate event, |
42 // throw away the entry. | 46 // throw away the entry. |
43 if (it->second.event_a_time.is_null()) { | 47 if (it->second.event_a_time.is_null()) { |
44 it->second.event_a_time = frame_event.timestamp; | 48 it->second.event_a_time = frame_event.timestamp; |
45 } else { | 49 } else { |
46 event_times_map_.erase(it); | 50 event_times_map_.erase(it); |
47 return; | 51 return; |
48 } | 52 } |
49 break; | 53 break; |
50 case kVideoAckSent: | 54 case FRAME_ACK_SENT: |
51 if (it->second.event_b_time.is_null()) { | 55 if (it->second.event_b_time.is_null()) { |
52 it->second.event_b_time = frame_event.timestamp; | 56 it->second.event_b_time = frame_event.timestamp; |
53 } else if (it->second.event_b_time != frame_event.timestamp) { | 57 } else if (it->second.event_b_time != frame_event.timestamp) { |
54 // Duplicate ack sent events are normal due to RTCP redundancy, | 58 // Duplicate ack sent events are normal due to RTCP redundancy, |
55 // but they must have the same event timestamp. | 59 // but they must have the same event timestamp. |
56 event_times_map_.erase(it); | 60 event_times_map_.erase(it); |
57 return; | 61 return; |
58 } | 62 } |
59 break; | 63 break; |
60 case kVideoAckReceived: | 64 case FRAME_ACK_RECEIVED: |
61 // If there are duplicate ack received events, pick the one with the | 65 // If there are duplicate ack received events, pick the one with the |
62 // smallest event timestamp so we can get a better bound. | 66 // smallest event timestamp so we can get a better bound. |
63 if (it->second.event_c_time.is_null()) { | 67 if (it->second.event_c_time.is_null()) { |
64 it->second.event_c_time = frame_event.timestamp; | 68 it->second.event_c_time = frame_event.timestamp; |
65 } else { | 69 } else { |
66 it->second.event_c_time = | 70 it->second.event_c_time = |
67 std::min(frame_event.timestamp, it->second.event_c_time); | 71 std::min(frame_event.timestamp, it->second.event_c_time); |
68 } | 72 } |
69 break; | 73 break; |
70 default: | 74 default: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return; | 120 return; |
117 } | 121 } |
118 | 122 |
119 offset_lower_bound_ = lower_bound; | 123 offset_lower_bound_ = lower_bound; |
120 offset_upper_bound_ = upper_bound; | 124 offset_upper_bound_ = upper_bound; |
121 bounded_ = true; | 125 bounded_ = true; |
122 } | 126 } |
123 | 127 |
124 } // namespace cast | 128 } // namespace cast |
125 } // namespace media | 129 } // namespace media |
OLD | NEW |