| 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 #ifndef MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ | 5 #ifndef MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ |
| 6 #define MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ | 6 #define MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
| 10 #include "media/cast/logging/logging_defines.h" | 10 #include "media/cast/logging/logging_defines.h" |
| 11 #include "media/cast/logging/receiver_time_offset_estimator.h" | 11 #include "media/cast/logging/receiver_time_offset_estimator.h" |
| 12 | 12 |
| 13 namespace base { |
| 14 class TickClock; |
| 15 } |
| 16 |
| 13 namespace media { | 17 namespace media { |
| 14 namespace cast { | 18 namespace cast { |
| 15 | 19 |
| 16 // This implementation listens to three types of video events: | 20 // This implementation listens to three types of video events: |
| 17 // 1. FRAME_ENCODED (sender side) | 21 // 1. FRAME_ENCODED (sender side) |
| 18 // 2. FRAME_ACK_SENT (receiver side) | 22 // 2. FRAME_ACK_SENT (receiver side) |
| 19 // 3. FRAME_ACK_RECEIVED (sender side) | 23 // 3. FRAME_ACK_RECEIVED (sender side) |
| 20 // There is a causal relationship between these events in that these events | 24 // There is a causal relationship between these events in that these events |
| 21 // must happen in order. This class obtains the lower and upper bounds for | 25 // must happen in order. This class obtains the lower and upper bounds for |
| 22 // the offset by taking the difference of timestamps (2) - (1) and (2) - (3), | 26 // the offset by taking the difference of timestamps (2) - (1) and (2) - (3), |
| 23 // respectively. | 27 // respectively. |
| 24 // The bound will become better as the latency between the events decreases. | 28 // The bound will become better as the latency between the events decreases. |
| 25 class ReceiverTimeOffsetEstimatorImpl : public ReceiverTimeOffsetEstimator { | 29 class ReceiverTimeOffsetEstimatorImpl : public ReceiverTimeOffsetEstimator { |
| 26 public: | 30 public: |
| 27 ReceiverTimeOffsetEstimatorImpl(); | 31 ReceiverTimeOffsetEstimatorImpl(base::TickClock* clock); |
| 28 | 32 |
| 29 virtual ~ReceiverTimeOffsetEstimatorImpl(); | 33 virtual ~ReceiverTimeOffsetEstimatorImpl(); |
| 30 | 34 |
| 31 // RawEventSubscriber implementations. | 35 // RawEventSubscriber implementations. |
| 32 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; | 36 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; |
| 33 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; | 37 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; |
| 34 | 38 |
| 35 // ReceiverTimeOffsetEstimator implementation. | 39 // ReceiverTimeOffsetEstimator implementation. |
| 36 virtual bool GetReceiverOffsetBounds(base::TimeDelta* lower_bound, | 40 virtual bool GetReceiverOffsetBounds(base::TimeDelta* lower_bound, |
| 37 base::TimeDelta* upper_bound) OVERRIDE; | 41 base::TimeDelta* upper_bound) OVERRIDE; |
| 38 | 42 |
| 39 private: | 43 private: |
| 40 struct EventTimes { | 44 struct EventTimes { |
| 41 base::TimeTicks event_a_time; | 45 base::TimeTicks event_a_time; |
| 42 base::TimeTicks event_b_time; | 46 base::TimeTicks event_b_time; |
| 43 base::TimeTicks event_c_time; | 47 base::TimeTicks event_c_time; |
| 44 }; | 48 }; |
| 45 | 49 |
| 46 typedef std::map<RtpTimestamp, EventTimes> EventTimesMap; | 50 typedef std::map<RtpTimestamp, EventTimes> EventTimesMap; |
| 47 | 51 |
| 48 void UpdateOffsetBounds(const EventTimes& event); | 52 void UpdateOffsetBounds(const EventTimes& event); |
| 49 | 53 |
| 50 // Fixed size storage to store event times for recent frames. | 54 // Fixed size storage to store event times for recent frames. |
| 51 EventTimesMap event_times_map_; | 55 EventTimesMap event_times_map_; |
| 52 | 56 |
| 53 bool bounded_; | 57 bool bounded_; |
| 58 base::TickClock* clock_; // Not owned by this class. |
| 59 |
| 60 bool offset_bounds_valid_; |
| 54 base::TimeDelta offset_lower_bound_; | 61 base::TimeDelta offset_lower_bound_; |
| 55 base::TimeDelta offset_upper_bound_; | 62 base::TimeDelta offset_upper_bound_; |
| 63 base::TimeDelta prev_offset_lower_bound_; |
| 64 base::TimeDelta prev_offset_upper_bound_; |
| 65 base::TimeTicks last_reset_time_; |
| 56 | 66 |
| 57 base::ThreadChecker thread_checker_; | 67 base::ThreadChecker thread_checker_; |
| 58 DISALLOW_COPY_AND_ASSIGN(ReceiverTimeOffsetEstimatorImpl); | 68 DISALLOW_COPY_AND_ASSIGN(ReceiverTimeOffsetEstimatorImpl); |
| 59 }; | 69 }; |
| 60 | 70 |
| 61 } // namespace cast | 71 } // namespace cast |
| 62 } // namespace media | 72 } // namespace media |
| 63 | 73 |
| 64 #endif // MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ | 74 #endif // MEDIA_CAST_LOGGING_RECEIVER_TIME_OFFSET_ESTIMATOR_IMPL_H_ |
| OLD | NEW |