blob: 10fc198cde53c4ad5ad982ac5b4dcfbbd6d44c0b [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#ifndef _WIN32
15#include <unistd.h>
16#endif
17
18#include <vector>
19
minyue@webrtc.org0de00492013-09-30 08:43:50 +000020#include "gflags/gflags.h"
pbos@webrtc.org471ae722013-05-21 13:52:32 +000021#include "testing/gtest/include/gtest/gtest.h"
minyue@webrtc.org0de00492013-09-30 08:43:50 +000022#include "webrtc/common.h"
23#include "webrtc/common_types.h"
pbos@webrtc.org471ae722013-05-21 13:52:32 +000024#include "webrtc/engine_configurations.h"
minyue@webrtc.org0de00492013-09-30 08:43:50 +000025#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +000026#include "webrtc/system_wrappers/interface/scoped_ptr.h"
27#include "webrtc/test/channel_transport/include/channel_transport.h"
28#include "webrtc/test/testsupport/fileutils.h"
pbos@webrtc.org471ae722013-05-21 13:52:32 +000029#include "webrtc/voice_engine/include/voe_audio_processing.h"
30#include "webrtc/voice_engine/include/voe_base.h"
31#include "webrtc/voice_engine/include/voe_codec.h"
32#include "webrtc/voice_engine/include/voe_dtmf.h"
33#include "webrtc/voice_engine/include/voe_encryption.h"
34#include "webrtc/voice_engine/include/voe_errors.h"
35#include "webrtc/voice_engine/include/voe_external_media.h"
36#include "webrtc/voice_engine/include/voe_file.h"
37#include "webrtc/voice_engine/include/voe_hardware.h"
38#include "webrtc/voice_engine/include/voe_neteq_stats.h"
39#include "webrtc/voice_engine/include/voe_network.h"
40#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
41#include "webrtc/voice_engine/include/voe_video_sync.h"
42#include "webrtc/voice_engine/include/voe_volume_control.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000043
minyue@webrtc.org0de00492013-09-30 08:43:50 +000044DEFINE_bool(use_acm_version_2, false,
45 "If true, we'll run the tests with Audio Coding Module version 2.");
46
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000047using namespace webrtc;
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +000048using namespace test;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000049
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +000050#define VALIDATE \
51 if (res != 0) { \
52 printf("*** Error at line %i \n", __LINE__); \
53 printf("*** Error code = %i \n", base1->LastError()); \
54 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000055
56VoiceEngine* m_voe = NULL;
57VoEBase* base1 = NULL;
58VoECodec* codec = NULL;
59VoEVolumeControl* volume = NULL;
60VoEDtmf* dtmf = NULL;
61VoERTP_RTCP* rtp_rtcp = NULL;
62VoEAudioProcessing* apm = NULL;
63VoENetwork* netw = NULL;
64VoEFile* file = NULL;
65VoEVideoSync* vsync = NULL;
66VoEEncryption* encr = NULL;
67VoEHardware* hardware = NULL;
68VoEExternalMedia* xmedia = NULL;
69VoENetEqStats* neteqst = NULL;
70
71void RunTest(std::string out_path);
72
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000073class MyObserver : public VoiceEngineObserver {
74 public:
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000075 virtual void CallbackOnError(int channel, int err_code);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000076};
77
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000078void MyObserver::CallbackOnError(int channel, int err_code) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000079 // Add printf for other error codes here
80 if (err_code == VE_TYPING_NOISE_WARNING) {
81 printf(" TYPING NOISE DETECTED \n");
82 } else if (err_code == VE_RECEIVE_PACKET_TIMEOUT) {
83 printf(" RECEIVE PACKET TIMEOUT \n");
84 } else if (err_code == VE_PACKET_RECEIPT_RESTARTED) {
85 printf(" PACKET RECEIPT RESTARTED \n");
86 } else if (err_code == VE_RUNTIME_PLAY_WARNING) {
87 printf(" RUNTIME PLAY WARNING \n");
88 } else if (err_code == VE_RUNTIME_REC_WARNING) {
89 printf(" RUNTIME RECORD WARNING \n");
90 } else if (err_code == VE_SATURATION_WARNING) {
91 printf(" SATURATION WARNING \n");
92 } else if (err_code == VE_RUNTIME_PLAY_ERROR) {
93 printf(" RUNTIME PLAY ERROR \n");
94 } else if (err_code == VE_RUNTIME_REC_ERROR) {
95 printf(" RUNTIME RECORD ERROR \n");
96 } else if (err_code == VE_REC_DEVICE_REMOVED) {
97 printf(" RECORD DEVICE REMOVED \n");
98 }
99}
100
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000101void SetStereoIfOpus(bool use_stereo, CodecInst* codec_params) {
102 if (strncmp(codec_params->plname, "opus", 4) == 0) {
103 if (use_stereo)
104 codec_params->channels = 2;
105 else
106 codec_params->channels = 1;
107 }
108}
109
110void PrintCodecs(bool opus_stereo) {
111 CodecInst codec_params;
112 for (int i = 0; i < codec->NumOfCodecs(); ++i) {
113 int res = codec->GetCodec(i, codec_params);
114 VALIDATE;
115 SetStereoIfOpus(opus_stereo, &codec_params);
116 printf("%2d. %3d %s/%d/%d \n", i, codec_params.pltype, codec_params.plname,
117 codec_params.plfreq, codec_params.channels);
118 }
119}
120
minyue@webrtc.org0de00492013-09-30 08:43:50 +0000121int main(int argc, char** argv) {
122 google::ParseCommandLineFlags(&argc, &argv, true);
123
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000124 int res = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000125
126 printf("Test started \n");
127
minyue@webrtc.org0de00492013-09-30 08:43:50 +0000128 // TODO(minyue): Remove when the old ACM is removed (latest 2014-04-01).
129 Config config;
130 config.Set<AudioCodingModuleFactory>(FLAGS_use_acm_version_2 ?
131 new NewAudioCodingModuleFactory() :
132 new AudioCodingModuleFactory());
133 m_voe = VoiceEngine::Create(config);
134
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000135 base1 = VoEBase::GetInterface(m_voe);
136 codec = VoECodec::GetInterface(m_voe);
137 apm = VoEAudioProcessing::GetInterface(m_voe);
138 volume = VoEVolumeControl::GetInterface(m_voe);
139 dtmf = VoEDtmf::GetInterface(m_voe);
140 rtp_rtcp = VoERTP_RTCP::GetInterface(m_voe);
141 netw = VoENetwork::GetInterface(m_voe);
142 file = VoEFile::GetInterface(m_voe);
143 vsync = VoEVideoSync::GetInterface(m_voe);
144 encr = VoEEncryption::GetInterface(m_voe);
145 hardware = VoEHardware::GetInterface(m_voe);
146 xmedia = VoEExternalMedia::GetInterface(m_voe);
147 neteqst = VoENetEqStats::GetInterface(m_voe);
148
149 MyObserver my_observer;
150
151 const std::string out_path = webrtc::test::OutputPath();
152 const std::string trace_filename = out_path + "webrtc_trace.txt";
153
154 printf("Set trace filenames (enable trace)\n");
155 VoiceEngine::SetTraceFilter(kTraceAll);
156 res = VoiceEngine::SetTraceFile(trace_filename.c_str());
157 VALIDATE;
158
159 res = VoiceEngine::SetTraceCallback(NULL);
160 VALIDATE;
161
162 printf("Init\n");
163 res = base1->Init();
164 if (res != 0) {
165 printf("\nError calling Init: %d\n", base1->LastError());
166 fflush(NULL);
167 exit(1);
168 }
169
170 res = base1->RegisterVoiceEngineObserver(my_observer);
171 VALIDATE;
172
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000173 printf("Version\n");
174 char tmp[1024];
175 res = base1->GetVersion(tmp);
176 VALIDATE;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000177 printf("%s\n", tmp);
178
179 RunTest(out_path);
180
181 printf("Terminate \n");
182
183 base1->DeRegisterVoiceEngineObserver();
184
185 res = base1->Terminate();
186 VALIDATE;
187
188 if (base1)
189 base1->Release();
190
191 if (codec)
192 codec->Release();
193
194 if (volume)
195 volume->Release();
196
197 if (dtmf)
198 dtmf->Release();
199
200 if (rtp_rtcp)
201 rtp_rtcp->Release();
202
203 if (apm)
204 apm->Release();
205
206 if (netw)
207 netw->Release();
208
209 if (file)
210 file->Release();
211
212 if (vsync)
213 vsync->Release();
214
215 if (encr)
216 encr->Release();
217
218 if (hardware)
219 hardware->Release();
220
221 if (xmedia)
222 xmedia->Release();
223
224 if (neteqst)
225 neteqst->Release();
226
227 VoiceEngine::Delete(m_voe);
228
229 return 0;
230}
231
232void RunTest(std::string out_path) {
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000233 int chan, res;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000234 CodecInst cinst;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000235 bool enable_aec = false;
236 bool enable_agc = false;
237 bool enable_rx_agc = false;
238 bool enable_cng = false;
239 bool enable_ns = false;
240 bool enable_rx_ns = false;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000241 bool typing_detection = false;
242 bool muted = false;
243 bool on_hold = false;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000244 bool opus_stereo = false;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000245
246#if defined(WEBRTC_ANDROID)
247 std::string resource_path = "/sdcard/";
248#else
249 std::string resource_path = webrtc::test::ProjectRootPath();
250 if (resource_path == webrtc::test::kCannotFindProjectRootDir) {
251 printf("*** Unable to get project root directory. "
252 "File playing may fail. ***\n");
253 // Fall back to the current directory.
254 resource_path = "./";
255 } else {
256 resource_path += "data/voice_engine/";
257 }
258#endif
259 const std::string audio_filename = resource_path + "audio_long16.pcm";
260
261 const std::string play_filename = out_path + "recorded_playout.pcm";
262 const std::string mic_filename = out_path + "recorded_mic.pcm";
263
264 chan = base1->CreateChannel();
265 if (chan < 0) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000266 printf("************ Error code = %i\n", base1->LastError());
267 fflush(NULL);
268 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000269
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000270 char ip[64];
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000271 printf("1. 127.0.0.1 \n");
272 printf("2. Specify IP \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000273 int ip_selection;
274 ASSERT_EQ(1, scanf("%i", &ip_selection));
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000275
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000276 if (ip_selection == 1) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000277 strcpy(ip, "127.0.0.1");
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000278 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000279 printf("Specify remote IP: ");
280 ASSERT_EQ(1, scanf("%s", ip));
281 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000282
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000283 int rPort;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000284 printf("Specify remote port (1=1234): ");
285 ASSERT_EQ(1, scanf("%i", &rPort));
286 if (1 == rPort)
287 rPort = 1234;
288 printf("Set Send port \n");
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000289
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000290 scoped_ptr<VoiceChannelTransport> voice_channel_transport(
291 new VoiceChannelTransport(netw, chan));
292
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000293 printf("Set Send IP \n");
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000294 res = voice_channel_transport->SetSendDestination(ip, rPort);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000295 VALIDATE;
296
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000297 int lPort;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000298 printf("Specify local port (1=1234): ");
299 ASSERT_EQ(1, scanf("%i", &lPort));
300 if (1 == lPort)
301 lPort = 1234;
302 printf("Set Rec Port \n");
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000303
304 res = voice_channel_transport->SetLocalReceiver(lPort);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000305 VALIDATE;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000306
307 printf("\n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000308 PrintCodecs(opus_stereo);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000309 printf("Select send codec: ");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000310 int codec_selection;
311 ASSERT_EQ(1, scanf("%i", &codec_selection));
312 codec->GetCodec(codec_selection, cinst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000313
314 printf("Set primary codec\n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000315 SetStereoIfOpus(opus_stereo, &cinst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000316 res = codec->SetSendCodec(chan, cinst);
317 VALIDATE;
318
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000319 const int kMaxNumChannels = 8;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000320 int channel_index = 0;
321 std::vector<int> channels(kMaxNumChannels);
pwestin@webrtc.orgc39749a2013-04-04 17:24:15 +0000322 std::vector<VoiceChannelTransport*> voice_channel_transports(kMaxNumChannels);
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000323
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000324 for (int i = 0; i < kMaxNumChannels; ++i) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000325 channels[i] = base1->CreateChannel();
326 int port = rPort + (i + 1) * 2;
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000327
pwestin@webrtc.orgc39749a2013-04-04 17:24:15 +0000328 voice_channel_transports[i] = new VoiceChannelTransport(netw, channels[i]);
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000329
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000330 res = voice_channel_transports[i]->SetSendDestination(ip, port);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000331 VALIDATE;
pwestin@webrtc.orgaa922de2013-03-22 16:12:57 +0000332 res = voice_channel_transports[i]->SetLocalReceiver(port);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000333 VALIDATE;
334 res = codec->SetSendCodec(channels[i], cinst);
335 VALIDATE;
336 }
337
338 // Call loop
339 bool newcall = true;
340 while (newcall) {
341
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000342#ifndef WEBRTC_ANDROID
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000343 int rd(-1), pd(-1);
344 res = hardware->GetNumOfRecordingDevices(rd);
345 VALIDATE;
346 res = hardware->GetNumOfPlayoutDevices(pd);
347 VALIDATE;
348
349 char dn[128] = { 0 };
350 char guid[128] = { 0 };
351 printf("\nPlayout devices (%d): \n", pd);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000352 for (int j = 0; j < pd; ++j) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000353 res = hardware->GetPlayoutDeviceName(j, dn, guid);
354 VALIDATE;
355 printf(" %d: %s \n", j, dn);
356 }
357
358 printf("Recording devices (%d): \n", rd);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000359 for (int j = 0; j < rd; ++j) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000360 res = hardware->GetRecordingDeviceName(j, dn, guid);
361 VALIDATE;
362 printf(" %d: %s \n", j, dn);
363 }
364
365 printf("Select playout device: ");
366 ASSERT_EQ(1, scanf("%d", &pd));
367 res = hardware->SetPlayoutDevice(pd);
368 VALIDATE;
369 printf("Select recording device: ");
370 ASSERT_EQ(1, scanf("%d", &rd));
371 printf("Setting sound devices \n");
372 res = hardware->SetRecordingDevice(rd);
373 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000374#endif // WEBRTC_ANDROID
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000375
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000376 res = codec->SetVADStatus(0, enable_cng);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000377 VALIDATE;
378
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000379 res = apm->SetAgcStatus(enable_agc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000380 VALIDATE;
381
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000382 res = apm->SetEcStatus(enable_aec);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000383 VALIDATE;
384
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000385 res = apm->SetNsStatus(enable_ns);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000386 VALIDATE;
387
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000388 printf("\n1. Send, listen and playout \n");
389 printf("2. Send only \n");
390 printf("3. Listen and playout only \n");
391 printf("Select transfer mode: ");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000392 int call_selection;
393 ASSERT_EQ(1, scanf("%i", &call_selection));
394 const bool send = !(call_selection == 3);
395 const bool receive = !(call_selection == 2);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000396
397 if (receive) {
398#ifndef EXTERNAL_TRANSPORT
399 printf("Start Listen \n");
400 res = base1->StartReceive(chan);
401 VALIDATE;
402#endif
403
404 printf("Start Playout \n");
405 res = base1->StartPlayout(chan);
406 VALIDATE;
407 }
408
409 if (send) {
410 printf("Start Send \n");
411 res = base1->StartSend(chan);
412 VALIDATE;
413 }
414
415#ifndef WEBRTC_ANDROID
416 printf("Getting mic volume \n");
417 unsigned int vol = 999;
418 res = volume->GetMicVolume(vol);
419 VALIDATE;
420 if ((vol > 255) || (vol < 1)) {
421 printf("\n****ERROR in GetMicVolume");
422 }
423#endif
424
425 int forever = 1;
426 while (forever) {
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000427 printf("\nSelect codec\n");
428 PrintCodecs(opus_stereo);
429 printf("\nOther actions\n");
430 const int num_codecs = codec->NumOfCodecs();
431 int option_index = num_codecs;
432 printf("%i. Toggle CNG\n", option_index++);
433 printf("%i. Toggle AGC\n", option_index++);
434 printf("%i. Toggle NS\n", option_index++);
435 printf("%i. Toggle EC\n", option_index++);
436 printf("%i. Select AEC\n", option_index++);
437 printf("%i. Select AECM\n", option_index++);
438 printf("%i. Get speaker volume\n", option_index++);
439 printf("%i. Set speaker volume\n", option_index++);
440 printf("%i. Get microphone volume\n", option_index++);
441 printf("%i. Set microphone volume\n", option_index++);
442 printf("%i. Play local file (audio_long16.pcm) \n", option_index++);
443 printf("%i. Change playout device \n", option_index++);
444 printf("%i. Change recording device \n", option_index++);
445 printf("%i. Toggle receive-side AGC \n", option_index++);
446 printf("%i. Toggle receive-side NS \n", option_index++);
447 printf("%i. AGC status \n", option_index++);
448 printf("%i. Toggle microphone mute \n", option_index++);
449 printf("%i. Toggle on hold status \n", option_index++);
450 printf("%i. Get last error code \n", option_index++);
451 printf("%i. Toggle typing detection (for Mac/Windows only) \n",
452 option_index++);
453 printf("%i. Record a PCM file \n", option_index++);
454 printf("%i. Play a previously recorded PCM file locally \n",
455 option_index++);
456 printf("%i. Play a previously recorded PCM file as microphone \n",
457 option_index++);
458 printf("%i. Add an additional file-playing channel \n", option_index++);
459 printf("%i. Remove a file-playing channel \n", option_index++);
460 printf("%i. Toggle Opus stereo (Opus must be selected again to apply "
461 "the setting) \n", option_index++);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000462
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000463 printf("Select action or %i to stop the call: ", option_index);
464 int option_selection;
465 ASSERT_EQ(1, scanf("%i", &option_selection));
466
467 option_index = num_codecs;
468 if (option_selection < option_index) {
469 res = codec->GetCodec(option_selection, cinst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000470 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000471 SetStereoIfOpus(opus_stereo, &cinst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000472 printf("Set primary codec\n");
473 res = codec->SetSendCodec(chan, cinst);
474 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000475 } else if (option_selection == option_index++) {
476 enable_cng = !enable_cng;
477 res = codec->SetVADStatus(0, enable_cng);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000478 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000479 if (enable_cng)
480 printf("\n CNG is now on! \n");
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000481 else
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000482 printf("\n CNG is now off! \n");
483 } else if (option_selection == option_index++) {
484 enable_agc = !enable_agc;
485 res = apm->SetAgcStatus(enable_agc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000486 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000487 if (enable_agc)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000488 printf("\n AGC is now on! \n");
489 else
490 printf("\n AGC is now off! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000491 } else if (option_selection == option_index++) {
492 enable_ns = !enable_ns;
493 res = apm->SetNsStatus(enable_ns);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000494 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000495 if (enable_ns)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000496 printf("\n NS is now on! \n");
497 else
498 printf("\n NS is now off! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000499 } else if (option_selection == option_index++) {
500 enable_aec = !enable_aec;
501 res = apm->SetEcStatus(enable_aec, kEcUnchanged);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000502 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000503 if (enable_aec)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000504 printf("\n Echo control is now on! \n");
505 else
506 printf("\n Echo control is now off! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000507 } else if (option_selection == option_index++) {
508 res = apm->SetEcStatus(enable_aec, kEcAec);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000509 VALIDATE;
510 printf("\n AEC selected! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000511 if (enable_aec)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000512 printf(" (Echo control is on)\n");
513 else
514 printf(" (Echo control is off)\n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000515 } else if (option_selection == option_index++) {
516 res = apm->SetEcStatus(enable_aec, kEcAecm);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000517 VALIDATE;
518 printf("\n AECM selected! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000519 if (enable_aec)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000520 printf(" (Echo control is on)\n");
521 else
522 printf(" (Echo control is off)\n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000523 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000524 unsigned vol(0);
525 res = volume->GetSpeakerVolume(vol);
526 VALIDATE;
527 printf("\n Speaker Volume is %d \n", vol);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000528 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000529 printf("Level: ");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000530 int level;
531 ASSERT_EQ(1, scanf("%i", &level));
532 res = volume->SetSpeakerVolume(level);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000533 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000534 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000535 unsigned vol(0);
536 res = volume->GetMicVolume(vol);
537 VALIDATE;
538 printf("\n Microphone Volume is %d \n", vol);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000539 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000540 printf("Level: ");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000541 int level;
542 ASSERT_EQ(1, scanf("%i", &level));
543 res = volume->SetMicVolume(level);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000544 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000545 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000546 res = file->StartPlayingFileLocally(0, audio_filename.c_str());
547 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000548 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000549 // change the playout device with current call
550 int num_pd(-1);
551 res = hardware->GetNumOfPlayoutDevices(num_pd);
552 VALIDATE;
553
554 char dn[128] = { 0 };
555 char guid[128] = { 0 };
556
557 printf("\nPlayout devices (%d): \n", num_pd);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000558 for (int i = 0; i < num_pd; ++i) {
559 res = hardware->GetPlayoutDeviceName(i, dn, guid);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000560 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000561 printf(" %d: %s \n", i, dn);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000562 }
563 printf("Select playout device: ");
564 ASSERT_EQ(1, scanf("%d", &num_pd));
565 // Will use plughw for hardware devices
566 res = hardware->SetPlayoutDevice(num_pd);
567 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000568 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000569 // change the recording device with current call
570 int num_rd(-1);
571
572 res = hardware->GetNumOfRecordingDevices(num_rd);
573 VALIDATE;
574
575 char dn[128] = { 0 };
576 char guid[128] = { 0 };
577
578 printf("Recording devices (%d): \n", num_rd);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000579 for (int i = 0; i < num_rd; ++i) {
580 res = hardware->GetRecordingDeviceName(i, dn, guid);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000581 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000582 printf(" %d: %s \n", i, dn);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000583 }
584
585 printf("Select recording device: ");
586 ASSERT_EQ(1, scanf("%d", &num_rd));
587 printf("Setting sound devices \n");
588 // Will use plughw for hardware devices
589 res = hardware->SetRecordingDevice(num_rd);
590 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000591 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000592 // Remote AGC
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000593 enable_rx_agc = !enable_rx_agc;
594 res = apm->SetRxAgcStatus(chan, enable_rx_agc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000595 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000596 if (enable_rx_agc)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000597 printf("\n Receive-side AGC is now on! \n");
598 else
599 printf("\n Receive-side AGC is now off! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000600 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000601 // Remote NS
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000602 enable_rx_ns = !enable_rx_ns;
603 res = apm->SetRxNsStatus(chan, enable_rx_ns);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000604 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000605 if (enable_rx_ns)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000606 printf("\n Receive-side NS is now on! \n");
607 else
608 printf("\n Receive-side NS is now off! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000609 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000610 AgcModes agcmode;
611 bool enable;
612 res = apm->GetAgcStatus(enable, agcmode);
613 VALIDATE
614 printf("\n AGC enable is %d, mode is %d \n", enable, agcmode);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000615 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000616 // Toggle Mute on Microphone
617 res = volume->GetInputMute(chan, muted);
618 VALIDATE;
619 muted = !muted;
620 res = volume->SetInputMute(chan, muted);
621 VALIDATE;
622 if (muted)
623 printf("\n Microphone is now on mute! \n");
624 else
625 printf("\n Microphone is no longer on mute! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000626 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000627 // Toggle the call on hold
628 OnHoldModes mode;
629 res = base1->GetOnHoldStatus(chan, on_hold, mode);
630 VALIDATE;
631 on_hold = !on_hold;
632 mode = kHoldSendAndPlay;
633 res = base1->SetOnHoldStatus(chan, on_hold, mode);
634 VALIDATE;
635 if (on_hold)
636 printf("\n Call now on hold! \n");
637 else
638 printf("\n Call now not on hold! \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000639 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000640 // Get the last error code and print to screen
641 int err_code = 0;
642 err_code = base1->LastError();
643 if (err_code != -1)
644 printf("\n The last error code was %i.\n", err_code);
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000645 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000646 typing_detection= !typing_detection;
647 res = apm->SetTypingDetectionStatus(typing_detection);
648 VALIDATE;
649 if (typing_detection)
650 printf("\n Typing detection is now on!\n");
651 else
652 printf("\n Typing detection is now off!\n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000653 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000654 int stop_record = 1;
655 int file_source = 1;
656 printf("\n Select source of recorded file. ");
657 printf("\n 1. Record from microphone to file ");
658 printf("\n 2. Record from playout to file ");
659 printf("\n Enter your selection: \n");
660 ASSERT_EQ(1, scanf("%i", &file_source));
661 if (file_source == 1) {
662 printf("\n Start recording microphone as %s \n",
663 mic_filename.c_str());
664 res = file->StartRecordingMicrophone(mic_filename.c_str());
665 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000666 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000667 printf("\n Start recording playout as %s \n", play_filename.c_str());
668 res = file->StartRecordingPlayout(chan, play_filename.c_str());
669 VALIDATE;
670 }
671 while (stop_record != 0) {
672 printf("\n Type 0 to stop recording file \n");
673 ASSERT_EQ(1, scanf("%i", &stop_record));
674 }
675 if (file_source == 1) {
676 res = file->StopRecordingMicrophone();
677 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000678 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000679 res = file->StopRecordingPlayout(chan);
680 VALIDATE;
681 }
682 printf("\n File finished recording \n");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000683 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000684 int file_type = 1;
685 int stop_play = 1;
686 printf("\n Select a file to play locally in a loop.");
687 printf("\n 1. Play %s", mic_filename.c_str());
688 printf("\n 2. Play %s", play_filename.c_str());
689 printf("\n Enter your selection\n");
690 ASSERT_EQ(1, scanf("%i", &file_type));
691 if (file_type == 1) {
692 printf("\n Start playing %s locally in a loop\n",
693 mic_filename.c_str());
694 res = file->StartPlayingFileLocally(chan, mic_filename.c_str(), true);
695 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000696 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000697 printf("\n Start playing %s locally in a loop\n",
698 play_filename.c_str());
699 res = file->StartPlayingFileLocally(chan, play_filename.c_str(),
700 true);
701 VALIDATE;
702 }
703 while (stop_play != 0) {
704 printf("\n Type 0 to stop playing file\n");
705 ASSERT_EQ(1, scanf("%i", &stop_play));
706 }
707 res = file->StopPlayingFileLocally(chan);
708 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000709 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000710 int file_type = 1;
711 int stop_play = 1;
712 printf("\n Select a file to play as microphone in a loop.");
713 printf("\n 1. Play %s", mic_filename.c_str());
714 printf("\n 2. Play %s", play_filename.c_str());
715 printf("\n Enter your selection\n");
716 ASSERT_EQ(1, scanf("%i", &file_type));
717 if (file_type == 1) {
718 printf("\n Start playing %s as mic in a loop\n",
719 mic_filename.c_str());
720 res = file->StartPlayingFileAsMicrophone(chan, mic_filename.c_str(),
721 true);
722 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000723 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000724 printf("\n Start playing %s as mic in a loop\n",
725 play_filename.c_str());
726 res = file->StartPlayingFileAsMicrophone(chan, play_filename.c_str(),
727 true);
728 VALIDATE;
729 }
730 while (stop_play != 0) {
731 printf("\n Type 0 to stop playing file\n");
732 ASSERT_EQ(1, scanf("%i", &stop_play));
733 }
734 res = file->StopPlayingFileAsMicrophone(chan);
735 VALIDATE;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000736 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000737 if (channel_index < kMaxNumChannels) {
738 res = base1->StartReceive(channels[channel_index]);
739 VALIDATE;
740 res = base1->StartPlayout(channels[channel_index]);
741 VALIDATE;
742 res = base1->StartSend(channels[channel_index]);
743 VALIDATE;
744 res = file->StartPlayingFileAsMicrophone(channels[channel_index],
745 audio_filename.c_str(),
746 true,
747 false);
748 VALIDATE;
749 channel_index++;
750 printf("Using %d additional channels\n", channel_index);
751 } else {
752 printf("Max number of channels reached\n");
753 }
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000754 } else if (option_selection == option_index++) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000755 if (channel_index > 0) {
756 channel_index--;
757 res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
758 VALIDATE;
759 res = base1->StopSend(channels[channel_index]);
760 VALIDATE;
761 res = base1->StopPlayout(channels[channel_index]);
762 VALIDATE;
763 res = base1->StopReceive(channels[channel_index]);
764 VALIDATE;
765 printf("Using %d additional channels\n", channel_index);
766 } else {
767 printf("All additional channels stopped\n");
768 }
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000769 } else if (option_selection == option_index++) {
770 opus_stereo = !opus_stereo;
771 if (opus_stereo)
772 printf("\n Opus stereo enabled (select Opus again to apply the "
773 "setting). \n");
774 else
775 printf("\n Opus mono enabled (select Opus again to apply the "
776 "setting). \n");
777 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000778 break;
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000779 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000780 }
781
782 if (send) {
783 printf("Stop Send \n");
784 res = base1->StopSend(chan);
785 VALIDATE;
786 }
787
788 if (receive) {
789 printf("Stop Playout \n");
790 res = base1->StopPlayout(chan);
791 VALIDATE;
792
793#ifndef EXTERNAL_TRANSPORT
794 printf("Stop Listen \n");
795 res = base1->StopReceive(chan);
796 VALIDATE;
797#endif
798 }
799
800 while (channel_index > 0) {
801 --channel_index;
802 res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
803 VALIDATE;
804 res = base1->StopSend(channels[channel_index]);
805 VALIDATE;
806 res = base1->StopPlayout(channels[channel_index]);
807 VALIDATE;
808 res = base1->StopReceive(channels[channel_index]);
809 VALIDATE;
810 }
811
812 printf("\n1. New call \n");
813 printf("2. Quit \n");
814 printf("Select action: ");
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000815 int end_option;
816 ASSERT_EQ(1, scanf("%i", &end_option));
817 newcall = (end_option == 1);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000818 // Call loop
819 }
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000820 for (int i = 0; i < kMaxNumChannels; ++i) {
pwestin@webrtc.orgc39749a2013-04-04 17:24:15 +0000821 delete voice_channel_transports[i];
822 voice_channel_transports[i] = NULL;
823 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000824
825 printf("Delete channels \n");
826 res = base1->DeleteChannel(chan);
827 VALIDATE;
828
andrew@webrtc.orgc0fc4872013-05-02 15:57:36 +0000829 for (int i = 0; i < kMaxNumChannels; ++i) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000830 channels[i] = base1->DeleteChannel(channels[i]);
831 VALIDATE;
832 }
833}