| OLD | NEW |
| 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 <deque> | 5 #include <deque> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/test/simple_test_tick_clock.h" | 11 #include "base/test/simple_test_tick_clock.h" |
| 12 #include "media/cast/cast_defines.h" | 12 #include "media/cast/cast_defines.h" |
| 13 #include "media/cast/cast_environment.h" | 13 #include "media/cast/cast_environment.h" |
| 14 #include "media/cast/logging/simple_event_subscriber.h" | 14 #include "media/cast/logging/simple_event_subscriber.h" |
| 15 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | 15 #include "media/cast/rtcp/test_rtcp_packet_builder.h" |
| 16 #include "media/cast/test/fake_single_thread_task_runner.h" | 16 #include "media/cast/test/fake_single_thread_task_runner.h" |
| 17 #include "media/cast/test/utility/default_config.h" |
| 17 #include "media/cast/transport/pacing/mock_paced_packet_sender.h" | 18 #include "media/cast/transport/pacing/mock_paced_packet_sender.h" |
| 18 #include "media/cast/video_receiver/video_receiver.h" | 19 #include "media/cast/video_receiver/video_receiver.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 | 21 |
| 21 using ::testing::_; | 22 using ::testing::_; |
| 22 | 23 |
| 23 namespace media { | 24 namespace media { |
| 24 namespace cast { | 25 namespace cast { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 std::deque<std::pair<uint32, base::TimeTicks> > expected_results_; | 59 std::deque<std::pair<uint32, base::TimeTicks> > expected_results_; |
| 59 int num_called_; | 60 int num_called_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(FakeVideoClient); | 62 DISALLOW_COPY_AND_ASSIGN(FakeVideoClient); |
| 62 }; | 63 }; |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 class VideoReceiverTest : public ::testing::Test { | 66 class VideoReceiverTest : public ::testing::Test { |
| 66 protected: | 67 protected: |
| 67 VideoReceiverTest() { | 68 VideoReceiverTest() { |
| 69 config_ = GetDefaultVideoReceiverConfig(); |
| 68 config_.rtp_max_delay_ms = kPlayoutDelayMillis; | 70 config_.rtp_max_delay_ms = kPlayoutDelayMillis; |
| 69 config_.use_external_decoder = false; | |
| 70 // Note: Frame rate must divide 1000 without remainder so the test code | 71 // Note: Frame rate must divide 1000 without remainder so the test code |
| 71 // doesn't have to account for rounding errors. | 72 // doesn't have to account for rounding errors. |
| 72 config_.max_frame_rate = 25; | 73 config_.max_frame_rate = 25; |
| 73 config_.codec = transport::kVp8; // Frame skipping not allowed. | 74 config_.codec.video = transport::kVp8; // Frame skipping not allowed. |
| 74 config_.feedback_ssrc = 1234; | |
| 75 config_.incoming_ssrc = 5678; | |
| 76 testing_clock_ = new base::SimpleTestTickClock(); | 75 testing_clock_ = new base::SimpleTestTickClock(); |
| 77 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); | 76 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); |
| 78 start_time_ = testing_clock_->NowTicks(); | 77 start_time_ = testing_clock_->NowTicks(); |
| 79 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); | 78 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); |
| 80 | 79 |
| 81 cast_environment_ = | 80 cast_environment_ = |
| 82 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(), | 81 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(), |
| 83 task_runner_, | 82 task_runner_, |
| 84 task_runner_, | 83 task_runner_, |
| 85 task_runner_); | 84 task_runner_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 114 uint32 ntp_seconds; | 113 uint32 ntp_seconds; |
| 115 uint32 ntp_fraction; | 114 uint32 ntp_fraction; |
| 116 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); | 115 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); |
| 117 TestRtcpPacketBuilder rtcp_packet; | 116 TestRtcpPacketBuilder rtcp_packet; |
| 118 rtcp_packet.AddSrWithNtp(config_.incoming_ssrc, | 117 rtcp_packet.AddSrWithNtp(config_.incoming_ssrc, |
| 119 ntp_seconds, ntp_fraction, | 118 ntp_seconds, ntp_fraction, |
| 120 static_cast<uint32>(rtp_timestamp)); | 119 static_cast<uint32>(rtp_timestamp)); |
| 121 receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass()); | 120 receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass()); |
| 122 } | 121 } |
| 123 | 122 |
| 124 VideoReceiverConfig config_; | 123 FrameReceiverConfig config_; |
| 125 std::vector<uint8> payload_; | 124 std::vector<uint8> payload_; |
| 126 RtpCastHeader rtp_header_; | 125 RtpCastHeader rtp_header_; |
| 127 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. | 126 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. |
| 128 base::TimeTicks start_time_; | 127 base::TimeTicks start_time_; |
| 129 transport::MockPacedPacketSender mock_transport_; | 128 transport::MockPacedPacketSender mock_transport_; |
| 130 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 129 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
| 131 scoped_refptr<CastEnvironment> cast_environment_; | 130 scoped_refptr<CastEnvironment> cast_environment_; |
| 132 FakeVideoClient fake_video_client_; | 131 FakeVideoClient fake_video_client_; |
| 133 | 132 |
| 134 // Important for the VideoReceiver to be declared last, since its dependencies | 133 // Important for the VideoReceiver to be declared last, since its dependencies |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 EXPECT_EQ(rtp_header_.frame_id, frame_events.begin()->frame_id); | 173 EXPECT_EQ(rtp_header_.frame_id, frame_events.begin()->frame_id); |
| 175 EXPECT_EQ(rtp_header_.rtp_timestamp, frame_events.begin()->rtp_timestamp); | 174 EXPECT_EQ(rtp_header_.rtp_timestamp, frame_events.begin()->rtp_timestamp); |
| 176 | 175 |
| 177 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber); | 176 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber); |
| 178 } | 177 } |
| 179 | 178 |
| 180 TEST_F(VideoReceiverTest, ReceivesFramesRefusingToSkipAny) { | 179 TEST_F(VideoReceiverTest, ReceivesFramesRefusingToSkipAny) { |
| 181 EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) | 180 EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) |
| 182 .WillRepeatedly(testing::Return(true)); | 181 .WillRepeatedly(testing::Return(true)); |
| 183 | 182 |
| 184 const uint32 rtp_advance_per_frame = kVideoFrequency / config_.max_frame_rate; | 183 const uint32 rtp_advance_per_frame = |
| 184 config_.frequency / config_.max_frame_rate; |
| 185 const base::TimeDelta time_advance_per_frame = | 185 const base::TimeDelta time_advance_per_frame = |
| 186 base::TimeDelta::FromSeconds(1) / config_.max_frame_rate; | 186 base::TimeDelta::FromSeconds(1) / config_.max_frame_rate; |
| 187 | 187 |
| 188 // Feed and process lip sync in receiver. | 188 // Feed and process lip sync in receiver. |
| 189 FeedLipSyncInfoIntoReceiver(); | 189 FeedLipSyncInfoIntoReceiver(); |
| 190 task_runner_->RunTasks(); | 190 task_runner_->RunTasks(); |
| 191 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); | 191 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); |
| 192 | 192 |
| 193 // Enqueue a request for a video frame. | 193 // Enqueue a request for a video frame. |
| 194 const FrameEncodedCallback frame_encoded_callback = | 194 const FrameEncodedCallback frame_encoded_callback = |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 // Move forward to the playout time of an unreceived Frame 5. Expect no | 258 // Move forward to the playout time of an unreceived Frame 5. Expect no |
| 259 // additional frames were emitted. | 259 // additional frames were emitted. |
| 260 testing_clock_->Advance(3 * time_advance_per_frame); | 260 testing_clock_->Advance(3 * time_advance_per_frame); |
| 261 task_runner_->RunTasks(); | 261 task_runner_->RunTasks(); |
| 262 EXPECT_EQ(3, fake_video_client_.number_times_called()); | 262 EXPECT_EQ(3, fake_video_client_.number_times_called()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace cast | 265 } // namespace cast |
| 266 } // namespace media | 266 } // namespace media |
| OLD | NEW |