OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/call.h" | 19 #include "webrtc/call.h" |
20 #include "webrtc/call/transport_adapter.h" | 20 #include "webrtc/call/transport_adapter.h" |
| 21 #include "webrtc/common.h" |
| 22 #include "webrtc/config.h" |
21 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 23 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
25 #include "webrtc/system_wrappers/include/rtp_to_ntp.h" | 27 #include "webrtc/system_wrappers/include/rtp_to_ntp.h" |
26 #include "webrtc/test/call_test.h" | 28 #include "webrtc/test/call_test.h" |
27 #include "webrtc/test/direct_transport.h" | 29 #include "webrtc/test/direct_transport.h" |
28 #include "webrtc/test/encoder_settings.h" | 30 #include "webrtc/test/encoder_settings.h" |
29 #include "webrtc/test/fake_audio_device.h" | 31 #include "webrtc/test/fake_audio_device.h" |
30 #include "webrtc/test/fake_decoder.h" | 32 #include "webrtc/test/fake_decoder.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 Clock* const clock_; | 184 Clock* const clock_; |
183 const int voe_channel_; | 185 const int voe_channel_; |
184 VoEVideoSync* const voe_sync_; | 186 VoEVideoSync* const voe_sync_; |
185 SyncRtcpObserver* const audio_observer_; | 187 SyncRtcpObserver* const audio_observer_; |
186 const int64_t creation_time_ms_; | 188 const int64_t creation_time_ms_; |
187 int64_t first_time_in_sync_; | 189 int64_t first_time_in_sync_; |
188 }; | 190 }; |
189 | 191 |
190 void CallPerfTest::TestAudioVideoSync(bool fec, bool create_audio_first) { | 192 void CallPerfTest::TestAudioVideoSync(bool fec, bool create_audio_first) { |
191 const char* kSyncGroup = "av_sync"; | 193 const char* kSyncGroup = "av_sync"; |
| 194 const uint32_t kAudioSendSsrc = 1234; |
| 195 const uint32_t kAudioRecvSsrc = 5678; |
192 class AudioPacketReceiver : public PacketReceiver { | 196 class AudioPacketReceiver : public PacketReceiver { |
193 public: | 197 public: |
194 AudioPacketReceiver(int channel, VoENetwork* voe_network) | 198 AudioPacketReceiver(int channel, VoENetwork* voe_network) |
195 : channel_(channel), | 199 : channel_(channel), |
196 voe_network_(voe_network), | 200 voe_network_(voe_network), |
197 parser_(RtpHeaderParser::Create()) {} | 201 parser_(RtpHeaderParser::Create()) {} |
198 DeliveryStatus DeliverPacket(MediaType media_type, | 202 DeliveryStatus DeliverPacket(MediaType media_type, |
199 const uint8_t* packet, | 203 const uint8_t* packet, |
200 size_t length, | 204 size_t length, |
201 const PacketTime& packet_time) override { | 205 const PacketTime& packet_time) override { |
(...skipping 19 matching lines...) Expand all Loading... |
221 VoEBase* voe_base = VoEBase::GetInterface(voice_engine); | 225 VoEBase* voe_base = VoEBase::GetInterface(voice_engine); |
222 VoECodec* voe_codec = VoECodec::GetInterface(voice_engine); | 226 VoECodec* voe_codec = VoECodec::GetInterface(voice_engine); |
223 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine); | 227 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine); |
224 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine); | 228 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine); |
225 const std::string audio_filename = | 229 const std::string audio_filename = |
226 test::ResourcePath("voice_engine/audio_long16", "pcm"); | 230 test::ResourcePath("voice_engine/audio_long16", "pcm"); |
227 ASSERT_STRNE("", audio_filename.c_str()); | 231 ASSERT_STRNE("", audio_filename.c_str()); |
228 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(), | 232 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(), |
229 audio_filename); | 233 audio_filename); |
230 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, nullptr)); | 234 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, nullptr)); |
231 int channel = voe_base->CreateChannel(); | 235 Config voe_config; |
| 236 voe_config.Set<VoicePacing>(new VoicePacing(true)); |
| 237 int send_channel_id = voe_base->CreateChannel(voe_config); |
| 238 int recv_channel_id = voe_base->CreateChannel(); |
232 | 239 |
233 SyncRtcpObserver audio_observer; | 240 SyncRtcpObserver audio_observer; |
234 | 241 |
235 AudioState::Config audio_state_config; | 242 AudioState::Config send_audio_state_config; |
236 audio_state_config.voice_engine = voice_engine; | 243 send_audio_state_config.voice_engine = voice_engine; |
| 244 Call::Config sender_config; |
| 245 sender_config.audio_state = AudioState::Create(send_audio_state_config); |
237 Call::Config receiver_config; | 246 Call::Config receiver_config; |
238 receiver_config.audio_state = AudioState::Create(audio_state_config); | 247 receiver_config.audio_state = sender_config.audio_state; |
239 CreateCalls(Call::Config(), receiver_config); | 248 CreateCalls(sender_config, receiver_config); |
240 | 249 |
241 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000}; | 250 AudioPacketReceiver voe_send_packet_receiver(send_channel_id, voe_network); |
242 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, isac)); | 251 AudioPacketReceiver voe_recv_packet_receiver(recv_channel_id, voe_network); |
243 | |
244 AudioPacketReceiver voe_packet_receiver(channel, voe_network); | |
245 | 252 |
246 FakeNetworkPipe::Config net_config; | 253 FakeNetworkPipe::Config net_config; |
247 net_config.queue_delay_ms = 500; | 254 net_config.queue_delay_ms = 500; |
248 net_config.loss_percent = 5; | 255 net_config.loss_percent = 5; |
249 test::PacketTransport audio_send_transport( | 256 test::PacketTransport audio_send_transport( |
250 nullptr, &audio_observer, test::PacketTransport::kSender, net_config); | 257 nullptr, &audio_observer, test::PacketTransport::kSender, net_config); |
251 audio_send_transport.SetReceiver(&voe_packet_receiver); | 258 audio_send_transport.SetReceiver(&voe_recv_packet_receiver); |
252 test::PacketTransport audio_receive_transport( | 259 test::PacketTransport audio_receive_transport( |
253 nullptr, &audio_observer, test::PacketTransport::kReceiver, net_config); | 260 nullptr, &audio_observer, test::PacketTransport::kReceiver, net_config); |
254 audio_receive_transport.SetReceiver(&voe_packet_receiver); | 261 audio_receive_transport.SetReceiver(&voe_send_packet_receiver); |
255 | 262 |
256 internal::TransportAdapter transport_adapter(&audio_send_transport); | 263 internal::TransportAdapter send_transport_adapter(&audio_send_transport); |
257 transport_adapter.Enable(); | 264 send_transport_adapter.Enable(); |
258 EXPECT_EQ(0, | 265 EXPECT_EQ(0, voe_network->RegisterExternalTransport(send_channel_id, |
259 voe_network->RegisterExternalTransport(channel, transport_adapter)); | 266 send_transport_adapter)); |
260 | 267 |
261 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), channel, | 268 internal::TransportAdapter recv_transport_adapter(&audio_receive_transport); |
| 269 recv_transport_adapter.Enable(); |
| 270 EXPECT_EQ(0, voe_network->RegisterExternalTransport(recv_channel_id, |
| 271 recv_transport_adapter)); |
| 272 |
| 273 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), recv_channel_id, |
262 voe_sync, &audio_observer); | 274 voe_sync, &audio_observer); |
263 | 275 |
264 test::PacketTransport sync_send_transport(sender_call_.get(), &observer, | 276 test::PacketTransport sync_send_transport(sender_call_.get(), &observer, |
265 test::PacketTransport::kSender, | 277 test::PacketTransport::kSender, |
266 FakeNetworkPipe::Config()); | 278 FakeNetworkPipe::Config()); |
267 sync_send_transport.SetReceiver(receiver_call_->Receiver()); | 279 sync_send_transport.SetReceiver(receiver_call_->Receiver()); |
268 test::PacketTransport sync_receive_transport(receiver_call_.get(), &observer, | 280 test::PacketTransport sync_receive_transport(receiver_call_.get(), &observer, |
269 test::PacketTransport::kReceiver, | 281 test::PacketTransport::kReceiver, |
270 FakeNetworkPipe::Config()); | 282 FakeNetworkPipe::Config()); |
271 sync_receive_transport.SetReceiver(sender_call_->Receiver()); | 283 sync_receive_transport.SetReceiver(sender_call_->Receiver()); |
272 | 284 |
273 test::FakeDecoder fake_decoder; | 285 test::FakeDecoder fake_decoder; |
274 | 286 |
275 CreateSendConfig(1, &sync_send_transport); | 287 CreateSendConfig(1, &sync_send_transport); |
276 CreateMatchingReceiveConfigs(&sync_receive_transport); | 288 CreateMatchingReceiveConfigs(&sync_receive_transport); |
277 | 289 |
| 290 AudioSendStream::Config audio_send_config(&audio_send_transport); |
| 291 audio_send_config.voe_channel_id = send_channel_id; |
| 292 audio_send_config.rtp.ssrc = kAudioSendSsrc; |
| 293 AudioSendStream* audio_send_stream = |
| 294 sender_call_->CreateAudioSendStream(audio_send_config); |
| 295 |
| 296 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000}; |
| 297 EXPECT_EQ(0, voe_codec->SetSendCodec(send_channel_id, isac)); |
| 298 |
278 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; | 299 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
279 if (fec) { | 300 if (fec) { |
280 send_config_.rtp.fec.red_payload_type = kRedPayloadType; | 301 send_config_.rtp.fec.red_payload_type = kRedPayloadType; |
281 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; | 302 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
282 receive_configs_[0].rtp.fec.red_payload_type = kRedPayloadType; | 303 receive_configs_[0].rtp.fec.red_payload_type = kRedPayloadType; |
283 receive_configs_[0].rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; | 304 receive_configs_[0].rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
284 } | 305 } |
285 receive_configs_[0].rtp.nack.rtp_history_ms = 1000; | 306 receive_configs_[0].rtp.nack.rtp_history_ms = 1000; |
286 receive_configs_[0].renderer = &observer; | 307 receive_configs_[0].renderer = &observer; |
287 receive_configs_[0].sync_group = kSyncGroup; | 308 receive_configs_[0].sync_group = kSyncGroup; |
288 | 309 |
289 AudioReceiveStream::Config audio_config; | 310 AudioReceiveStream::Config audio_recv_config; |
290 audio_config.voe_channel_id = channel; | 311 audio_recv_config.rtp.remote_ssrc = kAudioSendSsrc; |
291 audio_config.sync_group = kSyncGroup; | 312 audio_recv_config.rtp.local_ssrc = kAudioRecvSsrc; |
| 313 audio_recv_config.voe_channel_id = recv_channel_id; |
| 314 audio_recv_config.sync_group = kSyncGroup; |
292 | 315 |
293 AudioReceiveStream* audio_receive_stream = nullptr; | 316 AudioReceiveStream* audio_receive_stream; |
294 | 317 |
295 if (create_audio_first) { | 318 if (create_audio_first) { |
296 audio_receive_stream = | 319 audio_receive_stream = |
297 receiver_call_->CreateAudioReceiveStream(audio_config); | 320 receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
298 CreateStreams(); | 321 CreateStreams(); |
299 } else { | 322 } else { |
300 CreateStreams(); | 323 CreateStreams(); |
301 audio_receive_stream = | 324 audio_receive_stream = |
302 receiver_call_->CreateAudioReceiveStream(audio_config); | 325 receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
303 } | 326 } |
304 | 327 |
305 CreateFrameGeneratorCapturer(); | 328 CreateFrameGeneratorCapturer(); |
306 | 329 |
307 Start(); | 330 Start(); |
308 | 331 |
309 fake_audio_device.Start(); | 332 fake_audio_device.Start(); |
310 EXPECT_EQ(0, voe_base->StartPlayout(channel)); | 333 EXPECT_EQ(0, voe_base->StartPlayout(recv_channel_id)); |
311 EXPECT_EQ(0, voe_base->StartReceive(channel)); | 334 EXPECT_EQ(0, voe_base->StartReceive(recv_channel_id)); |
312 EXPECT_EQ(0, voe_base->StartSend(channel)); | 335 EXPECT_EQ(0, voe_base->StartSend(send_channel_id)); |
313 | 336 |
314 EXPECT_EQ(kEventSignaled, observer.Wait()) | 337 EXPECT_EQ(kEventSignaled, observer.Wait()) |
315 << "Timed out while waiting for audio and video to be synchronized."; | 338 << "Timed out while waiting for audio and video to be synchronized."; |
316 | 339 |
317 EXPECT_EQ(0, voe_base->StopSend(channel)); | 340 EXPECT_EQ(0, voe_base->StopSend(send_channel_id)); |
318 EXPECT_EQ(0, voe_base->StopReceive(channel)); | 341 EXPECT_EQ(0, voe_base->StopReceive(recv_channel_id)); |
319 EXPECT_EQ(0, voe_base->StopPlayout(channel)); | 342 EXPECT_EQ(0, voe_base->StopPlayout(recv_channel_id)); |
320 fake_audio_device.Stop(); | 343 fake_audio_device.Stop(); |
321 | 344 |
322 Stop(); | 345 Stop(); |
323 sync_send_transport.StopSending(); | 346 sync_send_transport.StopSending(); |
324 sync_receive_transport.StopSending(); | 347 sync_receive_transport.StopSending(); |
325 audio_send_transport.StopSending(); | 348 audio_send_transport.StopSending(); |
326 audio_receive_transport.StopSending(); | 349 audio_receive_transport.StopSending(); |
327 | 350 |
328 voe_base->DeleteChannel(channel); | 351 DestroyStreams(); |
| 352 |
| 353 sender_call_->DestroyAudioSendStream(audio_send_stream); |
| 354 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); |
| 355 |
| 356 voe_base->DeleteChannel(send_channel_id); |
| 357 voe_base->DeleteChannel(recv_channel_id); |
329 voe_base->Release(); | 358 voe_base->Release(); |
330 voe_codec->Release(); | 359 voe_codec->Release(); |
331 voe_network->Release(); | 360 voe_network->Release(); |
332 voe_sync->Release(); | 361 voe_sync->Release(); |
333 | 362 |
334 DestroyStreams(); | |
335 | |
336 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); | |
337 | |
338 DestroyCalls(); | 363 DestroyCalls(); |
339 | 364 |
340 VoiceEngine::Delete(voice_engine); | 365 VoiceEngine::Delete(voice_engine); |
341 } | 366 } |
342 | 367 |
343 TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithAudioCreatedFirst) { | 368 TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithAudioCreatedFirst) { |
344 TestAudioVideoSync(false, true); | 369 TestAudioVideoSync(false, true); |
345 } | 370 } |
346 | 371 |
347 TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoCreatedFirst) { | 372 TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoCreatedFirst) { |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 int encoder_inits_; | 733 int encoder_inits_; |
709 uint32_t last_set_bitrate_; | 734 uint32_t last_set_bitrate_; |
710 VideoSendStream* send_stream_; | 735 VideoSendStream* send_stream_; |
711 VideoEncoderConfig encoder_config_; | 736 VideoEncoderConfig encoder_config_; |
712 } test; | 737 } test; |
713 | 738 |
714 RunBaseTest(&test, FakeNetworkPipe::Config()); | 739 RunBaseTest(&test, FakeNetworkPipe::Config()); |
715 } | 740 } |
716 | 741 |
717 } // namespace webrtc | 742 } // namespace webrtc |
OLD | NEW |