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

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

Issue 280993002: [Cast] Repair receiver playout time calculations and frame skip logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « media/cast/rtcp/rtcp.cc ('k') | media/cast/test/end2end_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 6
7 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
8 #include "media/cast/cast_defines.h" 8 #include "media/cast/cast_defines.h"
9 #include "media/cast/cast_environment.h" 9 #include "media/cast/cast_environment.h"
10 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" 10 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 transport_sender, 135 transport_sender,
136 paced_packet_sender, 136 paced_packet_sender,
137 rtp_receiver_statistics, 137 rtp_receiver_statistics,
138 rtcp_mode, 138 rtcp_mode,
139 rtcp_interval, 139 rtcp_interval,
140 local_ssrc, 140 local_ssrc,
141 remote_ssrc, 141 remote_ssrc,
142 c_name, 142 c_name,
143 true) {} 143 true) {}
144 144
145 using Rtcp::CheckForWrapAround; 145 using Rtcp::OnReceivedNtp;
146 using Rtcp::OnReceivedLipSyncInfo; 146 using Rtcp::OnReceivedLipSyncInfo;
147 }; 147 };
148 148
149 class RtcpTest : public ::testing::Test { 149 class RtcpTest : public ::testing::Test {
150 protected: 150 protected:
151 RtcpTest() 151 RtcpTest()
152 : testing_clock_(new base::SimpleTestTickClock()), 152 : testing_clock_(new base::SimpleTestTickClock()),
153 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)), 153 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
154 cast_environment_(new CastEnvironment( 154 cast_environment_(new CastEnvironment(
155 scoped_ptr<base::TickClock>(testing_clock_).Pass(), 155 scoped_ptr<base::TickClock>(testing_clock_).Pass(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 scoped_refptr<CastEnvironment> cast_environment_; 197 scoped_refptr<CastEnvironment> cast_environment_;
198 RtcpTestPacketSender sender_to_receiver_; 198 RtcpTestPacketSender sender_to_receiver_;
199 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_; 199 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_;
200 LocalRtcpTransport receiver_to_sender_; 200 LocalRtcpTransport receiver_to_sender_;
201 MockRtcpSenderFeedback mock_sender_feedback_; 201 MockRtcpSenderFeedback mock_sender_feedback_;
202 202
203 DISALLOW_COPY_AND_ASSIGN(RtcpTest); 203 DISALLOW_COPY_AND_ASSIGN(RtcpTest);
204 }; 204 };
205 205
206 TEST_F(RtcpTest, TimeToSend) { 206 TEST_F(RtcpTest, TimeToSend) {
207 base::TimeTicks start_time = testing_clock_->NowTicks(); 207 const base::TimeTicks start_time = testing_clock_->NowTicks();
208 Rtcp rtcp(cast_environment_, 208 Rtcp rtcp(cast_environment_,
209 &mock_sender_feedback_, 209 &mock_sender_feedback_,
210 transport_sender_.get(), 210 transport_sender_.get(),
211 &receiver_to_sender_, 211 &receiver_to_sender_,
212 NULL, 212 NULL,
213 kRtcpCompound, 213 kRtcpCompound,
214 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), 214 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
215 kSenderSsrc, 215 kSenderSsrc,
216 kReceiverSsrc, 216 kReceiverSsrc,
217 kCName, 217 kCName,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 491
492 EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)); 492 EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt));
493 EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 2); 493 EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 2);
494 } 494 }
495 495
496 TEST_F(RtcpTest, NtpAndTime) { 496 TEST_F(RtcpTest, NtpAndTime) {
497 const int64 kSecondsbetweenYear1900and2010 = INT64_C(40176 * 24 * 60 * 60); 497 const int64 kSecondsbetweenYear1900and2010 = INT64_C(40176 * 24 * 60 * 60);
498 const int64 kSecondsbetweenYear1900and2030 = INT64_C(47481 * 24 * 60 * 60); 498 const int64 kSecondsbetweenYear1900and2030 = INT64_C(47481 * 24 * 60 * 60);
499 499
500 uint32 ntp_seconds_1 = 0; 500 uint32 ntp_seconds_1 = 0;
501 uint32 ntp_fractions_1 = 0; 501 uint32 ntp_fraction_1 = 0;
502 base::TimeTicks input_time = base::TimeTicks::Now(); 502 base::TimeTicks input_time = base::TimeTicks::Now();
503 ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fractions_1); 503 ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fraction_1);
504 504
505 // Verify absolute value. 505 // Verify absolute value.
506 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010); 506 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010);
507 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030); 507 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030);
508 508
509 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1); 509 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fraction_1);
510 EXPECT_EQ(input_time, out_1); // Verify inverse. 510 EXPECT_EQ(input_time, out_1); // Verify inverse.
511 511
512 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000); 512 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000);
513 input_time += time_delta; 513 input_time += time_delta;
514 514
515 uint32 ntp_seconds_2 = 0; 515 uint32 ntp_seconds_2 = 0;
516 uint32 ntp_fractions_2 = 0; 516 uint32 ntp_fraction_2 = 0;
517 517
518 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2); 518 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fraction_2);
519 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2); 519 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fraction_2);
520 EXPECT_EQ(input_time, out_2); // Verify inverse. 520 EXPECT_EQ(input_time, out_2); // Verify inverse.
521 521
522 // Verify delta. 522 // Verify delta.
523 EXPECT_EQ((out_2 - out_1), time_delta); 523 EXPECT_EQ((out_2 - out_1), time_delta);
524 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), UINT32_C(1)); 524 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), UINT32_C(1));
525 EXPECT_NEAR(ntp_fractions_2, ntp_fractions_1, 1); 525 EXPECT_NEAR(ntp_fraction_2, ntp_fraction_1, 1);
526 526
527 time_delta = base::TimeDelta::FromMilliseconds(500); 527 time_delta = base::TimeDelta::FromMilliseconds(500);
528 input_time += time_delta; 528 input_time += time_delta;
529 529
530 uint32 ntp_seconds_3 = 0; 530 uint32 ntp_seconds_3 = 0;
531 uint32 ntp_fractions_3 = 0; 531 uint32 ntp_fraction_3 = 0;
532 532
533 ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fractions_3); 533 ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fraction_3);
534 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fractions_3); 534 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fraction_3);
535 EXPECT_EQ(input_time, out_3); // Verify inverse. 535 EXPECT_EQ(input_time, out_3); // Verify inverse.
536 536
537 // Verify delta. 537 // Verify delta.
538 EXPECT_EQ((out_3 - out_2), time_delta); 538 EXPECT_EQ((out_3 - out_2), time_delta);
539 EXPECT_NEAR((ntp_fractions_3 - ntp_fractions_2), 0xffffffff / 2, 1); 539 EXPECT_NEAR((ntp_fraction_3 - ntp_fraction_2), 0xffffffff / 2, 1);
540 }
541
542 TEST_F(RtcpTest, WrapAround) {
543 RtcpPeer rtcp_peer(cast_environment_,
544 &mock_sender_feedback_,
545 transport_sender_.get(),
546 NULL,
547 NULL,
548 kRtcpReducedSize,
549 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
550 kReceiverSsrc,
551 kSenderSsrc,
552 kCName);
553 uint32 new_timestamp = 0;
554 uint32 old_timestamp = 0;
555 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
556 new_timestamp = 1234567890;
557 old_timestamp = 1234567000;
558 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
559 new_timestamp = 1234567000;
560 old_timestamp = 1234567890;
561 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
562 new_timestamp = 123;
563 old_timestamp = 4234567890u;
564 EXPECT_EQ(1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
565 new_timestamp = 4234567890u;
566 old_timestamp = 123;
567 EXPECT_EQ(-1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
568 }
569
570 TEST_F(RtcpTest, RtpTimestampInSenderTime) {
571 RtcpPeer rtcp_peer(cast_environment_,
572 &mock_sender_feedback_,
573 transport_sender_.get(),
574 &receiver_to_sender_,
575 NULL,
576 kRtcpReducedSize,
577 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
578 kReceiverSsrc,
579 kSenderSsrc,
580 kCName);
581 int frequency = 32000;
582 uint32 rtp_timestamp = 64000;
583 base::TimeTicks rtp_timestamp_in_ticks;
584
585 // Test fail before we get a OnReceivedLipSyncInfo.
586 EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(
587 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
588
589 uint32 ntp_seconds = 0;
590 uint32 ntp_fractions = 0;
591 uint64 input_time_us = 12345678901000LL;
592 base::TimeTicks input_time;
593 input_time += base::TimeDelta::FromMicroseconds(input_time_us);
594
595 // Test exact match.
596 ConvertTimeTicksToNtp(input_time, &ntp_seconds, &ntp_fractions);
597 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
598 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(
599 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
600 EXPECT_EQ(input_time, rtp_timestamp_in_ticks);
601
602 // Test older rtp_timestamp.
603 rtp_timestamp = 32000;
604 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(
605 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
606 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000),
607 rtp_timestamp_in_ticks);
608
609 // Test older rtp_timestamp with wrap.
610 rtp_timestamp = 4294903296u;
611 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(
612 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
613 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(4000),
614 rtp_timestamp_in_ticks);
615
616 // Test newer rtp_timestamp.
617 rtp_timestamp = 128000;
618 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(
619 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
620 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(2000),
621 rtp_timestamp_in_ticks);
622
623 // Test newer rtp_timestamp with wrap.
624 rtp_timestamp = 4294903296u;
625 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
626 rtp_timestamp = 64000;
627 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(
628 frequency, rtp_timestamp, &rtp_timestamp_in_ticks));
629 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000),
630 rtp_timestamp_in_ticks);
631 } 540 }
632 541
633 } // namespace cast 542 } // namespace cast
634 } // namespace media 543 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/rtcp/rtcp.cc ('k') | media/cast/test/end2end_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698