| 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
| 8 #include "base/time/tick_clock.h" | 8 #include "base/time/tick_clock.h" |
| 9 #include "media/cast/cast_environment.h" | 9 #include "media/cast/cast_environment.h" |
| 10 #include "media/cast/logging/logging_defines.h" | 10 #include "media/cast/logging/logging_defines.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 base::SimpleTestTickClock receiver_clock_; | 43 base::SimpleTestTickClock receiver_clock_; |
| 44 ReceiverTimeOffsetEstimatorImpl estimator_; | 44 ReceiverTimeOffsetEstimatorImpl estimator_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Suppose the true offset is 100ms. | 47 // Suppose the true offset is 100ms. |
| 48 // Event A occurred at sender time 20ms. | 48 // Event A occurred at sender time 20ms. |
| 49 // Event B occurred at receiver time 130ms. (sender time 30ms) | 49 // Event B occurred at receiver time 130ms. (sender time 30ms) |
| 50 // Event C occurred at sender time 60ms. | 50 // Event C occurred at sender time 60ms. |
| 51 // Then the bound after all 3 events have arrived is [130-60=70, 130-20=110]. | 51 // Then the bound after all 3 events have arrived is [130-60=70, 130-20=110]. |
| 52 TEST_F(ReceiverTimeOffsetEstimatorImplTest, EstimateOffset) { | 52 TEST_F(ReceiverTimeOffsetEstimatorImplTest, EstimateOffset) { |
| 53 int64 true_offset_ms = 100; | 53 int64_t true_offset_ms = 100; |
| 54 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); | 54 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); |
| 55 | 55 |
| 56 base::TimeDelta lower_bound; | 56 base::TimeDelta lower_bound; |
| 57 base::TimeDelta upper_bound; | 57 base::TimeDelta upper_bound; |
| 58 | 58 |
| 59 EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); | 59 EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); |
| 60 | 60 |
| 61 RtpTimestamp rtp_timestamp = 0; | 61 RtpTimestamp rtp_timestamp = 0; |
| 62 uint32 frame_id = 0; | 62 uint32_t frame_id = 0; |
| 63 | 63 |
| 64 AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); | 64 AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); |
| 65 | 65 |
| 66 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); | 66 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); |
| 67 encode_event->timestamp = sender_clock_->NowTicks(); | 67 encode_event->timestamp = sender_clock_->NowTicks(); |
| 68 encode_event->type = FRAME_ENCODED; | 68 encode_event->type = FRAME_ENCODED; |
| 69 encode_event->media_type = VIDEO_EVENT; | 69 encode_event->media_type = VIDEO_EVENT; |
| 70 encode_event->rtp_timestamp = rtp_timestamp; | 70 encode_event->rtp_timestamp = rtp_timestamp; |
| 71 encode_event->frame_id = frame_id; | 71 encode_event->frame_id = frame_id; |
| 72 encode_event->size = 1234; | 72 encode_event->size = 1234; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 scoped_ptr<FrameEvent> ack_event(new FrameEvent()); | 115 scoped_ptr<FrameEvent> ack_event(new FrameEvent()); |
| 116 ack_event->timestamp = sender_clock_->NowTicks(); | 116 ack_event->timestamp = sender_clock_->NowTicks(); |
| 117 ack_event->type = FRAME_ACK_RECEIVED; | 117 ack_event->type = FRAME_ACK_RECEIVED; |
| 118 ack_event->media_type = VIDEO_EVENT; | 118 ack_event->media_type = VIDEO_EVENT; |
| 119 ack_event->rtp_timestamp = rtp_timestamp; | 119 ack_event->rtp_timestamp = rtp_timestamp; |
| 120 ack_event->frame_id = frame_id; | 120 ack_event->frame_id = frame_id; |
| 121 cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); | 121 cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); |
| 122 | 122 |
| 123 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); | 123 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); |
| 124 | 124 |
| 125 int64 lower_bound_ms = lower_bound.InMilliseconds(); | 125 int64_t lower_bound_ms = lower_bound.InMilliseconds(); |
| 126 int64 upper_bound_ms = upper_bound.InMilliseconds(); | 126 int64_t upper_bound_ms = upper_bound.InMilliseconds(); |
| 127 EXPECT_EQ(70, lower_bound_ms); | 127 EXPECT_EQ(70, lower_bound_ms); |
| 128 EXPECT_EQ(110, upper_bound_ms); | 128 EXPECT_EQ(110, upper_bound_ms); |
| 129 EXPECT_GE(true_offset_ms, lower_bound_ms); | 129 EXPECT_GE(true_offset_ms, lower_bound_ms); |
| 130 EXPECT_LE(true_offset_ms, upper_bound_ms); | 130 EXPECT_LE(true_offset_ms, upper_bound_ms); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Same scenario as above, but event C arrives before event B. It doesn't mean | 133 // Same scenario as above, but event C arrives before event B. It doesn't mean |
| 134 // event C occurred before event B. | 134 // event C occurred before event B. |
| 135 TEST_F(ReceiverTimeOffsetEstimatorImplTest, EventCArrivesBeforeEventB) { | 135 TEST_F(ReceiverTimeOffsetEstimatorImplTest, EventCArrivesBeforeEventB) { |
| 136 int64 true_offset_ms = 100; | 136 int64_t true_offset_ms = 100; |
| 137 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); | 137 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); |
| 138 | 138 |
| 139 base::TimeDelta lower_bound; | 139 base::TimeDelta lower_bound; |
| 140 base::TimeDelta upper_bound; | 140 base::TimeDelta upper_bound; |
| 141 | 141 |
| 142 EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); | 142 EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); |
| 143 | 143 |
| 144 RtpTimestamp rtp_timestamp = 0; | 144 RtpTimestamp rtp_timestamp = 0; |
| 145 uint32 frame_id = 0; | 145 uint32_t frame_id = 0; |
| 146 | 146 |
| 147 AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); | 147 AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); |
| 148 | 148 |
| 149 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); | 149 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); |
| 150 encode_event->timestamp = sender_clock_->NowTicks(); | 150 encode_event->timestamp = sender_clock_->NowTicks(); |
| 151 encode_event->type = FRAME_ENCODED; | 151 encode_event->type = FRAME_ENCODED; |
| 152 encode_event->media_type = VIDEO_EVENT; | 152 encode_event->media_type = VIDEO_EVENT; |
| 153 encode_event->rtp_timestamp = rtp_timestamp; | 153 encode_event->rtp_timestamp = rtp_timestamp; |
| 154 encode_event->frame_id = frame_id; | 154 encode_event->frame_id = frame_id; |
| 155 encode_event->size = 1234; | 155 encode_event->size = 1234; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); | 201 scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); |
| 202 ack_sent_event->timestamp = event_b_time; | 202 ack_sent_event->timestamp = event_b_time; |
| 203 ack_sent_event->type = FRAME_ACK_SENT; | 203 ack_sent_event->type = FRAME_ACK_SENT; |
| 204 ack_sent_event->media_type = VIDEO_EVENT; | 204 ack_sent_event->media_type = VIDEO_EVENT; |
| 205 ack_sent_event->rtp_timestamp = rtp_timestamp; | 205 ack_sent_event->rtp_timestamp = rtp_timestamp; |
| 206 ack_sent_event->frame_id = frame_id; | 206 ack_sent_event->frame_id = frame_id; |
| 207 cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); | 207 cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); |
| 208 | 208 |
| 209 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); | 209 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); |
| 210 | 210 |
| 211 int64 lower_bound_ms = lower_bound.InMilliseconds(); | 211 int64_t lower_bound_ms = lower_bound.InMilliseconds(); |
| 212 int64 upper_bound_ms = upper_bound.InMilliseconds(); | 212 int64_t upper_bound_ms = upper_bound.InMilliseconds(); |
| 213 EXPECT_EQ(70, lower_bound_ms); | 213 EXPECT_EQ(70, lower_bound_ms); |
| 214 EXPECT_EQ(110, upper_bound_ms); | 214 EXPECT_EQ(110, upper_bound_ms); |
| 215 EXPECT_GE(true_offset_ms, lower_bound_ms); | 215 EXPECT_GE(true_offset_ms, lower_bound_ms); |
| 216 EXPECT_LE(true_offset_ms, upper_bound_ms); | 216 EXPECT_LE(true_offset_ms, upper_bound_ms); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(ReceiverTimeOffsetEstimatorImplTest, MultipleIterations) { | 219 TEST_F(ReceiverTimeOffsetEstimatorImplTest, MultipleIterations) { |
| 220 int64 true_offset_ms = 100; | 220 int64_t true_offset_ms = 100; |
| 221 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); | 221 receiver_clock_.Advance(base::TimeDelta::FromMilliseconds(true_offset_ms)); |
| 222 | 222 |
| 223 base::TimeDelta lower_bound; | 223 base::TimeDelta lower_bound; |
| 224 base::TimeDelta upper_bound; | 224 base::TimeDelta upper_bound; |
| 225 | 225 |
| 226 RtpTimestamp rtp_timestamp_a = 0; | 226 RtpTimestamp rtp_timestamp_a = 0; |
| 227 int frame_id_a = 0; | 227 int frame_id_a = 0; |
| 228 RtpTimestamp rtp_timestamp_b = 90; | 228 RtpTimestamp rtp_timestamp_b = 90; |
| 229 int frame_id_b = 1; | 229 int frame_id_b = 1; |
| 230 RtpTimestamp rtp_timestamp_c = 180; | 230 RtpTimestamp rtp_timestamp_c = 180; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 AdvanceClocks(base::TimeDelta::FromMilliseconds(30)); | 380 AdvanceClocks(base::TimeDelta::FromMilliseconds(30)); |
| 381 ack_event.reset(new FrameEvent()); | 381 ack_event.reset(new FrameEvent()); |
| 382 ack_event->timestamp = sender_clock_->NowTicks(); | 382 ack_event->timestamp = sender_clock_->NowTicks(); |
| 383 ack_event->type = FRAME_ACK_RECEIVED; | 383 ack_event->type = FRAME_ACK_RECEIVED; |
| 384 ack_event->media_type = VIDEO_EVENT; | 384 ack_event->media_type = VIDEO_EVENT; |
| 385 ack_event->rtp_timestamp = rtp_timestamp_c; | 385 ack_event->rtp_timestamp = rtp_timestamp_c; |
| 386 ack_event->frame_id = frame_id_c; | 386 ack_event->frame_id = frame_id_c; |
| 387 cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); | 387 cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); |
| 388 | 388 |
| 389 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); | 389 EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); |
| 390 int64 lower_bound_ms = lower_bound.InMilliseconds(); | 390 int64_t lower_bound_ms = lower_bound.InMilliseconds(); |
| 391 int64 upper_bound_ms = upper_bound.InMilliseconds(); | 391 int64_t upper_bound_ms = upper_bound.InMilliseconds(); |
| 392 EXPECT_GT(lower_bound_ms, 90); | 392 EXPECT_GT(lower_bound_ms, 90); |
| 393 EXPECT_LE(lower_bound_ms, true_offset_ms); | 393 EXPECT_LE(lower_bound_ms, true_offset_ms); |
| 394 EXPECT_LT(upper_bound_ms, 150); | 394 EXPECT_LT(upper_bound_ms, 150); |
| 395 EXPECT_GT(upper_bound_ms, true_offset_ms); | 395 EXPECT_GT(upper_bound_ms, true_offset_ms); |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace cast | 398 } // namespace cast |
| 399 } // namespace media | 399 } // namespace media |
| OLD | NEW |