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

Side by Side Diff: webrtc/test/call_test.cc

Issue 2794243002: Making FakeNetworkPipe demux audio and video packets. (Closed)
Patch Set: on other comments Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 10
11 #include "webrtc/test/call_test.h" 11 #include "webrtc/test/call_test.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 15 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/config.h" 17 #include "webrtc/config.h"
18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
19 #include "webrtc/test/testsupport/fileutils.h" 19 #include "webrtc/test/testsupport/fileutils.h"
20 #include "webrtc/voice_engine/include/voe_base.h" 20 #include "webrtc/voice_engine/include/voe_base.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 namespace test { 23 namespace test {
24 24
25 namespace { 25 namespace {
26 const int kVideoRotationRtpExtensionId = 4; 26 const int kVideoRotationRtpExtensionId = 4;
27 } 27 }
28 28
29 void CallTest::PayloadDemuxer::SetReceiver(PacketReceiver* receiver) {
30 receiver_ = receiver;
31 }
32
33 PacketReceiver::DeliveryStatus CallTest::PayloadDemuxer::DeliverPacket(
34 MediaType media_type,
35 const uint8_t* packet,
36 size_t length,
37 const PacketTime& packet_time) {
38 if (media_type == MediaType::ANY) {
39 // This simplistic demux logic will not make much sense for RTCP
40 // packets, but it seems that doesn't matter.
41 RTC_CHECK_GE(length, 2);
42 uint8_t pt = packet[1] & 0x7f;
43 if (pt == kFakeVideoSendPayloadType || pt == kFlexfecPayloadType) {
44 media_type = MediaType::VIDEO;
45 } else {
46 media_type = MediaType::AUDIO;
47 }
48 }
49 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
50 }
51
52 CallTest::CallTest() 29 CallTest::CallTest()
53 : clock_(Clock::GetRealTimeClock()), 30 : clock_(Clock::GetRealTimeClock()),
54 video_send_config_(nullptr), 31 video_send_config_(nullptr),
55 video_send_stream_(nullptr), 32 video_send_stream_(nullptr),
56 audio_send_config_(nullptr), 33 audio_send_config_(nullptr),
57 audio_send_stream_(nullptr), 34 audio_send_stream_(nullptr),
58 fake_encoder_(clock_), 35 fake_encoder_(clock_),
59 num_video_streams_(1), 36 num_video_streams_(1),
60 num_audio_streams_(0), 37 num_audio_streams_(0),
61 num_flexfec_streams_(0), 38 num_flexfec_streams_(0),
(...skipping 29 matching lines...) Expand all
91 audio_state_config.audio_mixer = AudioMixerImpl::Create(); 68 audio_state_config.audio_mixer = AudioMixerImpl::Create();
92 recv_config.audio_state = AudioState::Create(audio_state_config); 69 recv_config.audio_state = AudioState::Create(audio_state_config);
93 } 70 }
94 CreateReceiverCall(recv_config); 71 CreateReceiverCall(recv_config);
95 } 72 }
96 test->OnCallsCreated(sender_call_.get(), receiver_call_.get()); 73 test->OnCallsCreated(sender_call_.get(), receiver_call_.get());
97 receive_transport_.reset(test->CreateReceiveTransport()); 74 receive_transport_.reset(test->CreateReceiveTransport());
98 send_transport_.reset(test->CreateSendTransport(sender_call_.get())); 75 send_transport_.reset(test->CreateSendTransport(sender_call_.get()));
99 76
100 if (test->ShouldCreateReceivers()) { 77 if (test->ShouldCreateReceivers()) {
101 // For tests using only video or only audio, we rely on each test 78 send_transport_->SetReceiver(receiver_call_->Receiver());
102 // configuring the underlying FakeNetworkPipe with the right media 79 receive_transport_->SetReceiver(sender_call_->Receiver());
103 // type. But for tests sending both video and audio over the same
104 // FakeNetworkPipe, we need to "demux", i.e., setting the
105 // MediaType based on RTP payload type.
106 if (num_video_streams_ > 0 && num_audio_streams_ > 0) {
107 receive_demuxer_.SetReceiver(receiver_call_->Receiver());
108 send_transport_->SetReceiver(&receive_demuxer_);
109 send_demuxer_.SetReceiver(sender_call_->Receiver());
110 receive_transport_->SetReceiver(&send_demuxer_);
111 } else {
112 send_transport_->SetReceiver(receiver_call_->Receiver());
113 receive_transport_->SetReceiver(sender_call_->Receiver());
114 }
115 if (num_video_streams_ > 0) 80 if (num_video_streams_ > 0)
116 receiver_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); 81 receiver_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp);
117 if (num_audio_streams_ > 0) 82 if (num_audio_streams_ > 0)
118 receiver_call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp); 83 receiver_call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp);
119 } else { 84 } else {
120 // Sender-only call delivers to itself. 85 // Sender-only call delivers to itself.
121 send_transport_->SetReceiver(sender_call_->Receiver()); 86 send_transport_->SetReceiver(sender_call_->Receiver());
122 receive_transport_->SetReceiver(nullptr); 87 receive_transport_->SetReceiver(nullptr);
123 } 88 }
124 89
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 257
293 RTC_DCHECK_GE(1, num_audio_streams_); 258 RTC_DCHECK_GE(1, num_audio_streams_);
294 if (num_audio_streams_ == 1) { 259 if (num_audio_streams_ == 1) {
295 RTC_DCHECK_LE(0, voe_send_.channel_id); 260 RTC_DCHECK_LE(0, voe_send_.channel_id);
296 AudioReceiveStream::Config audio_config; 261 AudioReceiveStream::Config audio_config;
297 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc; 262 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
298 audio_config.rtcp_send_transport = rtcp_send_transport; 263 audio_config.rtcp_send_transport = rtcp_send_transport;
299 audio_config.voe_channel_id = voe_recv_.channel_id; 264 audio_config.voe_channel_id = voe_recv_.channel_id;
300 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc; 265 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
301 audio_config.decoder_factory = decoder_factory_; 266 audio_config.decoder_factory = decoder_factory_;
302 audio_config.decoder_map = {{120, {"opus", 48000, 2}}}; 267 audio_config.decoder_map = {{kAudioSendPayloadType, {"opus", 48000, 2}}};
303 audio_receive_configs_.push_back(audio_config); 268 audio_receive_configs_.push_back(audio_config);
304 } 269 }
305 270
306 // TODO(brandtr): Update this when we support multistream protection. 271 // TODO(brandtr): Update this when we support multistream protection.
307 RTC_DCHECK(num_flexfec_streams_ <= 1); 272 RTC_DCHECK(num_flexfec_streams_ <= 1);
308 if (num_flexfec_streams_ == 1) { 273 if (num_flexfec_streams_ == 1) {
309 FlexfecReceiveStream::Config config(rtcp_send_transport); 274 FlexfecReceiveStream::Config config(rtcp_send_transport);
310 config.payload_type = kFlexfecPayloadType; 275 config.payload_type = kFlexfecPayloadType;
311 config.remote_ssrc = kFlexfecSendSsrc; 276 config.remote_ssrc = kFlexfecSendSsrc;
312 config.protected_media_ssrcs = {kVideoSendSsrcs[0]}; 277 config.protected_media_ssrcs = {kVideoSendSsrcs[0]};
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 const uint32_t CallTest::kSendRtxSsrcs[kNumSsrcs] = {0xBADCAFD, 0xBADCAFE, 419 const uint32_t CallTest::kSendRtxSsrcs[kNumSsrcs] = {0xBADCAFD, 0xBADCAFE,
455 0xBADCAFF}; 420 0xBADCAFF};
456 const uint32_t CallTest::kVideoSendSsrcs[kNumSsrcs] = {0xC0FFED, 0xC0FFEE, 421 const uint32_t CallTest::kVideoSendSsrcs[kNumSsrcs] = {0xC0FFED, 0xC0FFEE,
457 0xC0FFEF}; 422 0xC0FFEF};
458 const uint32_t CallTest::kAudioSendSsrc = 0xDEADBEEF; 423 const uint32_t CallTest::kAudioSendSsrc = 0xDEADBEEF;
459 const uint32_t CallTest::kFlexfecSendSsrc = 0xBADBEEF; 424 const uint32_t CallTest::kFlexfecSendSsrc = 0xBADBEEF;
460 const uint32_t CallTest::kReceiverLocalVideoSsrc = 0x123456; 425 const uint32_t CallTest::kReceiverLocalVideoSsrc = 0x123456;
461 const uint32_t CallTest::kReceiverLocalAudioSsrc = 0x1234567; 426 const uint32_t CallTest::kReceiverLocalAudioSsrc = 0x1234567;
462 const int CallTest::kNackRtpHistoryMs = 1000; 427 const int CallTest::kNackRtpHistoryMs = 1000;
463 428
429 const std::map<uint8_t, MediaType> CallTest::payload_type_map_ = {
430 {CallTest::kVideoSendPayloadType, MediaType::VIDEO},
431 {CallTest::kFakeVideoSendPayloadType, MediaType::VIDEO},
432 {CallTest::kSendRtxPayloadType, MediaType::VIDEO},
433 {CallTest::kRedPayloadType, MediaType::VIDEO},
434 {CallTest::kRtxRedPayloadType, MediaType::VIDEO},
435 {CallTest::kUlpfecPayloadType, MediaType::VIDEO},
436 {CallTest::kFlexfecPayloadType, MediaType::VIDEO},
437 {CallTest::kAudioSendPayloadType, MediaType::AUDIO}};
438
464 BaseTest::BaseTest() {} 439 BaseTest::BaseTest() {}
465 440
466 BaseTest::BaseTest(unsigned int timeout_ms) : RtpRtcpObserver(timeout_ms) { 441 BaseTest::BaseTest(unsigned int timeout_ms) : RtpRtcpObserver(timeout_ms) {
467 } 442 }
468 443
469 BaseTest::~BaseTest() { 444 BaseTest::~BaseTest() {
470 } 445 }
471 446
472 std::unique_ptr<FakeAudioDevice::Capturer> BaseTest::CreateCapturer() { 447 std::unique_ptr<FakeAudioDevice::Capturer> BaseTest::CreateCapturer() {
473 return FakeAudioDevice::CreatePulsedNoiseCapturer(256, 48000); 448 return FakeAudioDevice::CreatePulsedNoiseCapturer(256, 48000);
(...skipping 11 matching lines...) Expand all
485 return Call::Config(&event_log_); 460 return Call::Config(&event_log_);
486 } 461 }
487 462
488 Call::Config BaseTest::GetReceiverCallConfig() { 463 Call::Config BaseTest::GetReceiverCallConfig() {
489 return Call::Config(&event_log_); 464 return Call::Config(&event_log_);
490 } 465 }
491 466
492 void BaseTest::OnCallsCreated(Call* sender_call, Call* receiver_call) { 467 void BaseTest::OnCallsCreated(Call* sender_call, Call* receiver_call) {
493 } 468 }
494 469
495 MediaType BaseTest::SelectMediaType() {
496 if (GetNumVideoStreams() > 0) {
497 if (GetNumAudioStreams() > 0) {
498 // Relies on PayloadDemuxer to set media type from payload type.
499 return MediaType::ANY;
500 } else {
501 return MediaType::VIDEO;
502 }
503 } else {
504 return MediaType::AUDIO;
505 }
506 }
507
508 test::PacketTransport* BaseTest::CreateSendTransport(Call* sender_call) { 470 test::PacketTransport* BaseTest::CreateSendTransport(Call* sender_call) {
509 return new PacketTransport(sender_call, this, test::PacketTransport::kSender, 471 return new PacketTransport(sender_call, this, test::PacketTransport::kSender,
510 SelectMediaType(), 472 CallTest::payload_type_map_,
stefan-webrtc 2017/04/10 07:45:26 Wouldn't it be cleaner to pass the payload_type_ma
minyue-webrtc 2017/04/10 07:58:46 I also thought about it. I think it would be an im
stefan-webrtc 2017/04/10 12:04:15 SG
511 FakeNetworkPipe::Config()); 473 FakeNetworkPipe::Config());
512 } 474 }
513 475
514 test::PacketTransport* BaseTest::CreateReceiveTransport() { 476 test::PacketTransport* BaseTest::CreateReceiveTransport() {
515 return new PacketTransport(nullptr, this, test::PacketTransport::kReceiver, 477 return new PacketTransport(nullptr, this, test::PacketTransport::kReceiver,
516 SelectMediaType(), 478 CallTest::payload_type_map_,
517 FakeNetworkPipe::Config()); 479 FakeNetworkPipe::Config());
518 } 480 }
519 481
520 size_t BaseTest::GetNumVideoStreams() const { 482 size_t BaseTest::GetNumVideoStreams() const {
521 return 1; 483 return 1;
522 } 484 }
523 485
524 size_t BaseTest::GetNumAudioStreams() const { 486 size_t BaseTest::GetNumAudioStreams() const {
525 return 0; 487 return 0;
526 } 488 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 536
575 EndToEndTest::EndToEndTest(unsigned int timeout_ms) : BaseTest(timeout_ms) { 537 EndToEndTest::EndToEndTest(unsigned int timeout_ms) : BaseTest(timeout_ms) {
576 } 538 }
577 539
578 bool EndToEndTest::ShouldCreateReceivers() const { 540 bool EndToEndTest::ShouldCreateReceivers() const {
579 return true; 541 return true;
580 } 542 }
581 543
582 } // namespace test 544 } // namespace test
583 } // namespace webrtc 545 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698