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/audio_receiver/audio_receiver.h" | 12 #include "media/cast/audio_receiver/audio_receiver.h" |
13 #include "media/cast/cast_defines.h" | 13 #include "media/cast/cast_defines.h" |
14 #include "media/cast/cast_environment.h" | 14 #include "media/cast/cast_environment.h" |
15 #include "media/cast/logging/simple_event_subscriber.h" | 15 #include "media/cast/logging/simple_event_subscriber.h" |
16 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | 16 #include "media/cast/rtcp/test_rtcp_packet_builder.h" |
17 #include "media/cast/test/fake_single_thread_task_runner.h" | 17 #include "media/cast/test/fake_single_thread_task_runner.h" |
| 18 #include "media/cast/test/utility/default_config.h" |
18 #include "media/cast/transport/pacing/mock_paced_packet_sender.h" | 19 #include "media/cast/transport/pacing/mock_paced_packet_sender.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 { |
27 | 28 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 60 |
60 DISALLOW_COPY_AND_ASSIGN(FakeAudioClient); | 61 DISALLOW_COPY_AND_ASSIGN(FakeAudioClient); |
61 }; | 62 }; |
62 | 63 |
63 } // namespace | 64 } // namespace |
64 | 65 |
65 class AudioReceiverTest : public ::testing::Test { | 66 class AudioReceiverTest : public ::testing::Test { |
66 protected: | 67 protected: |
67 AudioReceiverTest() { | 68 AudioReceiverTest() { |
68 // Configure the audio receiver to use PCM16. | 69 // Configure the audio receiver to use PCM16. |
69 audio_config_.rtp_payload_type = 127; | 70 audio_config_ = GetDefaultAudioReceiverConfig(); |
| 71 audio_config_.rtp_max_delay_ms = kPlayoutDelayMillis; |
70 audio_config_.frequency = 16000; | 72 audio_config_.frequency = 16000; |
71 audio_config_.channels = 1; | 73 audio_config_.channels = 1; |
72 audio_config_.codec = transport::kPcm16; | 74 audio_config_.codec.audio = transport::kPcm16; |
73 audio_config_.use_external_decoder = true; | |
74 audio_config_.feedback_ssrc = 1234; | |
75 audio_config_.incoming_ssrc = 5678; | |
76 audio_config_.rtp_max_delay_ms = kPlayoutDelayMillis; | |
77 testing_clock_ = new base::SimpleTestTickClock(); | 75 testing_clock_ = new base::SimpleTestTickClock(); |
78 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); | 76 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); |
79 start_time_ = testing_clock_->NowTicks(); | 77 start_time_ = testing_clock_->NowTicks(); |
80 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); | 78 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); |
81 | 79 |
82 cast_environment_ = new CastEnvironment( | 80 cast_environment_ = new CastEnvironment( |
83 scoped_ptr<base::TickClock>(testing_clock_).Pass(), | 81 scoped_ptr<base::TickClock>(testing_clock_).Pass(), |
84 task_runner_, | 82 task_runner_, |
85 task_runner_, | 83 task_runner_, |
86 task_runner_); | 84 task_runner_); |
(...skipping 27 matching lines...) Expand all Loading... |
114 uint32 ntp_seconds; | 112 uint32 ntp_seconds; |
115 uint32 ntp_fraction; | 113 uint32 ntp_fraction; |
116 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); | 114 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); |
117 TestRtcpPacketBuilder rtcp_packet; | 115 TestRtcpPacketBuilder rtcp_packet; |
118 rtcp_packet.AddSrWithNtp(audio_config_.incoming_ssrc, | 116 rtcp_packet.AddSrWithNtp(audio_config_.incoming_ssrc, |
119 ntp_seconds, ntp_fraction, | 117 ntp_seconds, ntp_fraction, |
120 static_cast<uint32>(rtp_timestamp)); | 118 static_cast<uint32>(rtp_timestamp)); |
121 receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass()); | 119 receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass()); |
122 } | 120 } |
123 | 121 |
124 AudioReceiverConfig audio_config_; | 122 FrameReceiverConfig audio_config_; |
125 std::vector<uint8> payload_; | 123 std::vector<uint8> payload_; |
126 RtpCastHeader rtp_header_; | 124 RtpCastHeader rtp_header_; |
127 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. | 125 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. |
128 base::TimeTicks start_time_; | 126 base::TimeTicks start_time_; |
129 transport::MockPacedPacketSender mock_transport_; | 127 transport::MockPacedPacketSender mock_transport_; |
130 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 128 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
131 scoped_refptr<CastEnvironment> cast_environment_; | 129 scoped_refptr<CastEnvironment> cast_environment_; |
132 FakeAudioClient fake_audio_client_; | 130 FakeAudioClient fake_audio_client_; |
133 | 131 |
134 // Important for the AudioReceiver to be declared last, since its dependencies | 132 // Important for the AudioReceiver to be declared last, since its dependencies |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_EQ(rtp_header_.frame_id, frame_events.begin()->frame_id); | 171 EXPECT_EQ(rtp_header_.frame_id, frame_events.begin()->frame_id); |
174 EXPECT_EQ(rtp_header_.rtp_timestamp, frame_events.begin()->rtp_timestamp); | 172 EXPECT_EQ(rtp_header_.rtp_timestamp, frame_events.begin()->rtp_timestamp); |
175 | 173 |
176 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber); | 174 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber); |
177 } | 175 } |
178 | 176 |
179 TEST_F(AudioReceiverTest, ReceivesFramesSkippingWhenAppropriate) { | 177 TEST_F(AudioReceiverTest, ReceivesFramesSkippingWhenAppropriate) { |
180 EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) | 178 EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)) |
181 .WillRepeatedly(testing::Return(true)); | 179 .WillRepeatedly(testing::Return(true)); |
182 | 180 |
183 const uint32 rtp_advance_per_frame = audio_config_.frequency / 100; | 181 const uint32 rtp_advance_per_frame = |
| 182 audio_config_.frequency / audio_config_.max_frame_rate; |
184 const base::TimeDelta time_advance_per_frame = | 183 const base::TimeDelta time_advance_per_frame = |
185 base::TimeDelta::FromMilliseconds(10); | 184 base::TimeDelta::FromSeconds(1) / audio_config_.max_frame_rate; |
186 | 185 |
187 FeedLipSyncInfoIntoReceiver(); | 186 FeedLipSyncInfoIntoReceiver(); |
188 task_runner_->RunTasks(); | 187 task_runner_->RunTasks(); |
189 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); | 188 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); |
190 | 189 |
191 // Enqueue a request for an audio frame. | 190 // Enqueue a request for an audio frame. |
192 const FrameEncodedCallback frame_encoded_callback = | 191 const FrameEncodedCallback frame_encoded_callback = |
193 base::Bind(&FakeAudioClient::DeliverEncodedAudioFrame, | 192 base::Bind(&FakeAudioClient::DeliverEncodedAudioFrame, |
194 base::Unretained(&fake_audio_client_)); | 193 base::Unretained(&fake_audio_client_)); |
195 receiver_->GetEncodedAudioFrame(frame_encoded_callback); | 194 receiver_->GetEncodedAudioFrame(frame_encoded_callback); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 252 |
254 // Move forward to the playout time of an unreceived Frame 5. Expect no | 253 // Move forward to the playout time of an unreceived Frame 5. Expect no |
255 // additional frames were emitted. | 254 // additional frames were emitted. |
256 testing_clock_->Advance(3 * time_advance_per_frame); | 255 testing_clock_->Advance(3 * time_advance_per_frame); |
257 task_runner_->RunTasks(); | 256 task_runner_->RunTasks(); |
258 EXPECT_EQ(3, fake_audio_client_.number_times_called()); | 257 EXPECT_EQ(3, fake_audio_client_.number_times_called()); |
259 } | 258 } |
260 | 259 |
261 } // namespace cast | 260 } // namespace cast |
262 } // namespace media | 261 } // namespace media |
OLD | NEW |