Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: media/cast/net/rtcp/rtcp_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/test/simple_test_tick_clock.h" 9 #include "base/test/simple_test_tick_clock.h"
10 #include "media/cast/net/cast_transport_config.h" 10 #include "media/cast/net/cast_transport_config.h"
11 #include "media/cast/net/pacing/paced_sender.h" 11 #include "media/cast/net/pacing/paced_sender.h"
12 #include "media/cast/net/rtcp/rtcp.h" 12 #include "media/cast/net/rtcp/rtcp.h"
13 #include "media/cast/net/rtcp/rtcp_utility.h" 13 #include "media/cast/net/rtcp/rtcp_utility.h"
14 #include "media/cast/test/skewed_tick_clock.h" 14 #include "media/cast/test/skewed_tick_clock.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 16
17 namespace media { 17 namespace media {
18 namespace cast { 18 namespace cast {
19 19
20 using testing::_; 20 using testing::_;
21 21
22 static const uint32 kSenderSsrc = 0x10203; 22 static const uint32_t kSenderSsrc = 0x10203;
23 static const uint32 kReceiverSsrc = 0x40506; 23 static const uint32_t kReceiverSsrc = 0x40506;
24 static const int kInitialReceiverClockOffsetSeconds = -5; 24 static const int kInitialReceiverClockOffsetSeconds = -5;
25 25
26 class FakeRtcpTransport : public PacedPacketSender { 26 class FakeRtcpTransport : public PacedPacketSender {
27 public: 27 public:
28 explicit FakeRtcpTransport(base::SimpleTestTickClock* clock) 28 explicit FakeRtcpTransport(base::SimpleTestTickClock* clock)
29 : clock_(clock), 29 : clock_(clock),
30 packet_delay_(base::TimeDelta::FromMilliseconds(42)), 30 packet_delay_(base::TimeDelta::FromMilliseconds(42)),
31 paused_(false) {} 31 paused_(false) {}
32 32
33 void set_rtcp_destination(Rtcp* rtcp) { rtcp_ = rtcp; } 33 void set_rtcp_destination(Rtcp* rtcp) { rtcp_ = rtcp; }
34 34
35 base::TimeDelta packet_delay() const { return packet_delay_; } 35 base::TimeDelta packet_delay() const { return packet_delay_; }
36 void set_packet_delay(base::TimeDelta delay) { packet_delay_ = delay; } 36 void set_packet_delay(base::TimeDelta delay) { packet_delay_ = delay; }
37 37
38 bool SendRtcpPacket(uint32 ssrc, PacketRef packet) final { 38 bool SendRtcpPacket(uint32_t ssrc, PacketRef packet) final {
39 clock_->Advance(packet_delay_); 39 clock_->Advance(packet_delay_);
40 if (paused_) { 40 if (paused_) {
41 packet_queue_.push_back(packet); 41 packet_queue_.push_back(packet);
42 } else { 42 } else {
43 rtcp_->IncomingRtcpPacket(&packet->data[0], packet->data.size()); 43 rtcp_->IncomingRtcpPacket(&packet->data[0], packet->data.size());
44 } 44 }
45 return true; 45 return true;
46 } 46 }
47 47
48 bool SendPackets(const SendPacketVector& packets) final { return false; } 48 bool SendPackets(const SendPacketVector& packets) final { return false; }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Rtcp rtcp_for_sender_; 136 Rtcp rtcp_for_sender_;
137 Rtcp rtcp_for_receiver_; 137 Rtcp rtcp_for_receiver_;
138 138
139 DISALLOW_COPY_AND_ASSIGN(RtcpTest); 139 DISALLOW_COPY_AND_ASSIGN(RtcpTest);
140 }; 140 };
141 141
142 TEST_F(RtcpTest, LipSyncGleanedFromSenderReport) { 142 TEST_F(RtcpTest, LipSyncGleanedFromSenderReport) {
143 // Initially, expect no lip-sync info receiver-side without having first 143 // Initially, expect no lip-sync info receiver-side without having first
144 // received a RTCP packet. 144 // received a RTCP packet.
145 base::TimeTicks reference_time; 145 base::TimeTicks reference_time;
146 uint32 rtp_timestamp; 146 uint32_t rtp_timestamp;
147 ASSERT_FALSE(rtcp_for_receiver_.GetLatestLipSyncTimes(&rtp_timestamp, 147 ASSERT_FALSE(rtcp_for_receiver_.GetLatestLipSyncTimes(&rtp_timestamp,
148 &reference_time)); 148 &reference_time));
149 149
150 // Send a Sender Report to the receiver. 150 // Send a Sender Report to the receiver.
151 const base::TimeTicks reference_time_sent = sender_clock_->NowTicks(); 151 const base::TimeTicks reference_time_sent = sender_clock_->NowTicks();
152 const uint32 rtp_timestamp_sent = 0xbee5; 152 const uint32_t rtp_timestamp_sent = 0xbee5;
153 rtcp_for_sender_.SendRtcpFromRtpSender( 153 rtcp_for_sender_.SendRtcpFromRtpSender(
154 reference_time_sent, rtp_timestamp_sent, 1, 1); 154 reference_time_sent, rtp_timestamp_sent, 1, 1);
155 155
156 // Now the receiver should have lip-sync info. Confirm that the lip-sync 156 // Now the receiver should have lip-sync info. Confirm that the lip-sync
157 // reference time is the same as that sent. 157 // reference time is the same as that sent.
158 EXPECT_TRUE(rtcp_for_receiver_.GetLatestLipSyncTimes(&rtp_timestamp, 158 EXPECT_TRUE(rtcp_for_receiver_.GetLatestLipSyncTimes(&rtp_timestamp,
159 &reference_time)); 159 &reference_time));
160 const base::TimeTicks rolled_back_time = 160 const base::TimeTicks rolled_back_time =
161 (reference_time - 161 (reference_time -
162 // Roll-back relative clock offset: 162 // Roll-back relative clock offset:
(...skipping 23 matching lines...) Expand all
186 base::TimeDelta expected_rtt_according_to_sender; 186 base::TimeDelta expected_rtt_according_to_sender;
187 base::TimeDelta expected_rtt_according_to_receiver; 187 base::TimeDelta expected_rtt_according_to_receiver;
188 for (int i = 0; i < iterations; ++i) { 188 for (int i = 0; i < iterations; ++i) {
189 const base::TimeDelta one_way_trip_time = 189 const base::TimeDelta one_way_trip_time =
190 base::TimeDelta::FromMilliseconds(1 << i); 190 base::TimeDelta::FromMilliseconds(1 << i);
191 sender_to_receiver_.set_packet_delay(one_way_trip_time); 191 sender_to_receiver_.set_packet_delay(one_way_trip_time);
192 receiver_to_sender_.set_packet_delay(one_way_trip_time); 192 receiver_to_sender_.set_packet_delay(one_way_trip_time);
193 193
194 // Sender --> Receiver 194 // Sender --> Receiver
195 base::TimeTicks reference_time_sent = sender_clock_->NowTicks(); 195 base::TimeTicks reference_time_sent = sender_clock_->NowTicks();
196 uint32 rtp_timestamp_sent = 0xbee5 + i; 196 uint32_t rtp_timestamp_sent = 0xbee5 + i;
197 rtcp_for_sender_.SendRtcpFromRtpSender( 197 rtcp_for_sender_.SendRtcpFromRtpSender(
198 reference_time_sent, rtp_timestamp_sent, 1, 1); 198 reference_time_sent, rtp_timestamp_sent, 1, 1);
199 EXPECT_EQ(expected_rtt_according_to_sender, 199 EXPECT_EQ(expected_rtt_according_to_sender,
200 rtcp_for_sender_.current_round_trip_time()); 200 rtcp_for_sender_.current_round_trip_time());
201 #ifdef SENDER_PROVIDES_REPORT_BLOCK 201 #ifdef SENDER_PROVIDES_REPORT_BLOCK
202 EXPECT_EQ(expected_rtt_according_to_receiver, 202 EXPECT_EQ(expected_rtt_according_to_receiver,
203 rtcp_for_receiver_.current_round_trip_time()); 203 rtcp_for_receiver_.current_round_trip_time());
204 #endif 204 #endif
205 205
206 // Receiver --> Sender 206 // Receiver --> Sender
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 &cast_message, base::TimeDelta(), NULL, NULL); 260 &cast_message, base::TimeDelta(), NULL, NULL);
261 261
262 cast_message.ack_frame_id = 1; 262 cast_message.ack_frame_id = 1;
263 rtcp_for_receiver_.SendRtcpFromRtpReceiver( 263 rtcp_for_receiver_.SendRtcpFromRtpReceiver(
264 rtcp_for_receiver_.ConvertToNTPAndSave(base::TimeTicks()), 264 rtcp_for_receiver_.ConvertToNTPAndSave(base::TimeTicks()),
265 &cast_message, base::TimeDelta(), NULL, NULL); 265 &cast_message, base::TimeDelta(), NULL, NULL);
266 } 266 }
267 267
268 // TODO(miu): Find a better home for this test. 268 // TODO(miu): Find a better home for this test.
269 TEST(MisplacedCastTest, NtpAndTime) { 269 TEST(MisplacedCastTest, NtpAndTime) {
270 const int64 kSecondsbetweenYear1900and2010 = INT64_C(40176 * 24 * 60 * 60); 270 const int64_t kSecondsbetweenYear1900and2010 = INT64_C(40176 * 24 * 60 * 60);
271 const int64 kSecondsbetweenYear1900and2030 = INT64_C(47481 * 24 * 60 * 60); 271 const int64_t kSecondsbetweenYear1900and2030 = INT64_C(47481 * 24 * 60 * 60);
272 272
273 uint32 ntp_seconds_1 = 0; 273 uint32_t ntp_seconds_1 = 0;
274 uint32 ntp_fraction_1 = 0; 274 uint32_t ntp_fraction_1 = 0;
275 base::TimeTicks input_time = base::TimeTicks::Now(); 275 base::TimeTicks input_time = base::TimeTicks::Now();
276 ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fraction_1); 276 ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fraction_1);
277 277
278 // Verify absolute value. 278 // Verify absolute value.
279 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010); 279 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010);
280 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030); 280 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030);
281 281
282 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fraction_1); 282 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fraction_1);
283 EXPECT_EQ(input_time, out_1); // Verify inverse. 283 EXPECT_EQ(input_time, out_1); // Verify inverse.
284 284
285 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000); 285 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000);
286 input_time += time_delta; 286 input_time += time_delta;
287 287
288 uint32 ntp_seconds_2 = 0; 288 uint32_t ntp_seconds_2 = 0;
289 uint32 ntp_fraction_2 = 0; 289 uint32_t ntp_fraction_2 = 0;
290 290
291 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fraction_2); 291 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fraction_2);
292 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fraction_2); 292 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fraction_2);
293 EXPECT_EQ(input_time, out_2); // Verify inverse. 293 EXPECT_EQ(input_time, out_2); // Verify inverse.
294 294
295 // Verify delta. 295 // Verify delta.
296 EXPECT_EQ((out_2 - out_1), time_delta); 296 EXPECT_EQ((out_2 - out_1), time_delta);
297 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), UINT32_C(1)); 297 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), UINT32_C(1));
298 EXPECT_NEAR(ntp_fraction_2, ntp_fraction_1, 1); 298 EXPECT_NEAR(ntp_fraction_2, ntp_fraction_1, 1);
299 299
300 time_delta = base::TimeDelta::FromMilliseconds(500); 300 time_delta = base::TimeDelta::FromMilliseconds(500);
301 input_time += time_delta; 301 input_time += time_delta;
302 302
303 uint32 ntp_seconds_3 = 0; 303 uint32_t ntp_seconds_3 = 0;
304 uint32 ntp_fraction_3 = 0; 304 uint32_t ntp_fraction_3 = 0;
305 305
306 ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fraction_3); 306 ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fraction_3);
307 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fraction_3); 307 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fraction_3);
308 EXPECT_EQ(input_time, out_3); // Verify inverse. 308 EXPECT_EQ(input_time, out_3); // Verify inverse.
309 309
310 // Verify delta. 310 // Verify delta.
311 EXPECT_EQ((out_3 - out_2), time_delta); 311 EXPECT_EQ((out_3 - out_2), time_delta);
312 EXPECT_NEAR((ntp_fraction_3 - ntp_fraction_2), 0xffffffff / 2, 1); 312 EXPECT_NEAR((ntp_fraction_3 - ntp_fraction_2), 0xffffffff / 2, 1);
313 } 313 }
314 314
315 } // namespace cast 315 } // namespace cast
316 } // namespace media 316 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698