• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // Sets up a simple VoiceEngine loopback call with the default audio devices
12 // and runs forever. Some parameters can be configured through command-line
13 // flags.
14 
15 #include "gflags/gflags.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 
18 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/test/channel_transport/channel_transport.h"
20 #include "webrtc/voice_engine/include/voe_audio_processing.h"
21 #include "webrtc/voice_engine/include/voe_base.h"
22 #include "webrtc/voice_engine/include/voe_codec.h"
23 #include "webrtc/voice_engine/include/voe_hardware.h"
24 #include "webrtc/voice_engine/include/voe_network.h"
25 
26 DEFINE_string(render, "render", "render device name");
27 DEFINE_string(codec, "ISAC", "codec name");
28 DEFINE_int32(rate, 16000, "codec sample rate in Hz");
29 
30 namespace webrtc {
31 namespace test {
32 
RunHarness()33 void RunHarness() {
34   VoiceEngine* voe = VoiceEngine::Create();
35   ASSERT_TRUE(voe != NULL);
36   VoEAudioProcessing* audio = VoEAudioProcessing::GetInterface(voe);
37   ASSERT_TRUE(audio != NULL);
38   VoEBase* base = VoEBase::GetInterface(voe);
39   ASSERT_TRUE(base != NULL);
40   VoECodec* codec = VoECodec::GetInterface(voe);
41   ASSERT_TRUE(codec != NULL);
42   VoEHardware* hardware = VoEHardware::GetInterface(voe);
43   ASSERT_TRUE(hardware != NULL);
44   VoENetwork* network = VoENetwork::GetInterface(voe);
45   ASSERT_TRUE(network != NULL);
46 
47   ASSERT_EQ(0, base->Init());
48   int channel = base->CreateChannel();
49   ASSERT_NE(-1, channel);
50 
51   rtc::scoped_ptr<VoiceChannelTransport> voice_channel_transport(
52       new VoiceChannelTransport(network, channel));
53 
54   ASSERT_EQ(0, voice_channel_transport->SetSendDestination("127.0.0.1", 1234));
55   ASSERT_EQ(0, voice_channel_transport->SetLocalReceiver(1234));
56 
57   CodecInst codec_params = {0};
58   bool codec_found = false;
59   for (int i = 0; i < codec->NumOfCodecs(); i++) {
60     ASSERT_EQ(0, codec->GetCodec(i, codec_params));
61     if (FLAGS_codec.compare(codec_params.plname) == 0 &&
62         FLAGS_rate == codec_params.plfreq) {
63       codec_found = true;
64       break;
65     }
66   }
67   ASSERT_TRUE(codec_found);
68   ASSERT_EQ(0, codec->SetSendCodec(channel, codec_params));
69 
70   int num_devices = 0;
71   ASSERT_EQ(0, hardware->GetNumOfPlayoutDevices(num_devices));
72   char device_name[128] = {0};
73   char guid[128] = {0};
74   bool device_found = false;
75   int device_index;
76   for (device_index = 0; device_index < num_devices; device_index++) {
77     ASSERT_EQ(0, hardware->GetPlayoutDeviceName(device_index, device_name,
78                                                 guid));
79     if (FLAGS_render.compare(device_name) == 0) {
80       device_found = true;
81       break;
82     }
83   }
84   ASSERT_TRUE(device_found);
85   ASSERT_EQ(0, hardware->SetPlayoutDevice(device_index));
86 
87   // Disable all audio processing.
88   ASSERT_EQ(0, audio->SetAgcStatus(false));
89   ASSERT_EQ(0, audio->SetEcStatus(false));
90   ASSERT_EQ(0, audio->EnableHighPassFilter(false));
91   ASSERT_EQ(0, audio->SetNsStatus(false));
92 
93   ASSERT_EQ(0, base->StartReceive(channel));
94   ASSERT_EQ(0, base->StartPlayout(channel));
95   ASSERT_EQ(0, base->StartSend(channel));
96 
97   // Run forever...
98   while (1) {
99   }
100 }
101 
102 }  // namespace test
103 }  // namespace webrtc
104 
main(int argc,char ** argv)105 int main(int argc, char** argv) {
106   google::ParseCommandLineFlags(&argc, &argv, true);
107   webrtc::test::RunHarness();
108 }
109