18e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org/* 28e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 38e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * 48e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * Use of this source code is governed by a BSD-style license 58e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * that can be found in the LICENSE file in the root of the source 68e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * tree. An additional intellectual property rights grant can be found 78e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * in the file PATENTS. All contributing project authors may 88e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org * be found in the AUTHORS file in the root of the source tree. 98e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org */ 108e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 118e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org// Sets up a simple VoiceEngine loopback call with the default audio devices 128e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org// and runs forever. Some parameters can be configured through command-line 138e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org// flags. 148e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 158e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "gflags/gflags.h" 168e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "gtest/gtest.h" 178e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 188e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/system_wrappers/interface/scoped_ptr.h" 198e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/test/channel_transport/include/channel_transport.h" 208e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/voice_engine/include/voe_audio_processing.h" 218e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/voice_engine/include/voe_base.h" 228e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/voice_engine/include/voe_codec.h" 238e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/voice_engine/include/voe_hardware.h" 248e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org#include "webrtc/voice_engine/include/voe_network.h" 258e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 268e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgDEFINE_string(render, "render", "render device name"); 278e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgDEFINE_string(codec, "ISAC", "codec name"); 288e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgDEFINE_int32(rate, 16000, "codec sample rate in Hz"); 298e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 308e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgnamespace webrtc { 318e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgnamespace test { 328e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 338e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgvoid RunHarness() { 348e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoiceEngine* voe = VoiceEngine::Create(); 358e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(voe != NULL); 368e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoEAudioProcessing* audio = VoEAudioProcessing::GetInterface(voe); 378e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(audio != NULL); 388e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoEBase* base = VoEBase::GetInterface(voe); 398e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(base != NULL); 408e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoECodec* codec = VoECodec::GetInterface(voe); 418e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(codec != NULL); 428e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoEHardware* hardware = VoEHardware::GetInterface(voe); 438e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(hardware != NULL); 448e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org VoENetwork* network = VoENetwork::GetInterface(voe); 458e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(network != NULL); 468e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 478e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, base->Init()); 488e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org int channel = base->CreateChannel(); 498e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_NE(-1, channel); 508e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 518e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org scoped_ptr<VoiceChannelTransport> voice_channel_transport( 528e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org new VoiceChannelTransport(network, channel)); 538e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 548e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, voice_channel_transport->SetSendDestination("127.0.0.1", 1234)); 558e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, voice_channel_transport->SetLocalReceiver(1234)); 568e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 578e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org CodecInst codec_params = {0}; 588e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org bool codec_found = false; 598e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org for (int i = 0; i < codec->NumOfCodecs(); i++) { 608e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, codec->GetCodec(i, codec_params)); 618e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org if (FLAGS_codec.compare(codec_params.plname) == 0 && 628e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org FLAGS_rate == codec_params.plfreq) { 638e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org codec_found = true; 648e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org break; 658e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org } 668e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org } 678e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(codec_found); 688e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, codec->SetSendCodec(channel, codec_params)); 698e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 708e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org int num_devices = 0; 718e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, hardware->GetNumOfPlayoutDevices(num_devices)); 728e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org char device_name[128] = {0}; 738e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org char guid[128] = {0}; 748e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org bool device_found = false; 758e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org int device_index; 768e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org for (device_index = 0; device_index < num_devices; device_index++) { 778e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, hardware->GetPlayoutDeviceName(device_index, device_name, 788e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org guid)); 798e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org if (FLAGS_render.compare(device_name) == 0) { 808e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org device_found = true; 818e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org break; 828e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org } 838e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org } 848e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_TRUE(device_found); 858e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, hardware->SetPlayoutDevice(device_index)); 868e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 878e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org // Disable all audio processing. 888e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, audio->SetAgcStatus(false)); 898e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, audio->SetEcStatus(false)); 908e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, audio->EnableHighPassFilter(false)); 918e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, audio->SetNsStatus(false)); 928e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 938e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, base->StartReceive(channel)); 948e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, base->StartPlayout(channel)); 958e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org ASSERT_EQ(0, base->StartSend(channel)); 968e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 978e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org // Run forever... 988e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org while (1) { 998e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org } 1008e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org} 1018e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 1028e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org} // namespace test 1038e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org} // namespace webrtc 1048e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org 1058e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.orgint main(int argc, char** argv) { 1068e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org google::ParseCommandLineFlags(&argc, &argv, true); 1078e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org webrtc::test::RunHarness(); 1088e701084207e4bfccf28a0088d41310d6af06410kjellander@webrtc.org} 109