PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc

https://bitbucket.org/bohlooli/webrtc
C++ | 926 lines | 805 code | 94 blank | 27 comment | 207 complexity | 49443dcb26fc75f726b22ac2eb329fa2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, BSD-3-Clause
  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. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #ifndef _WIN32
  14. #include <unistd.h>
  15. #endif
  16. #include <vector>
  17. #include "gtest/gtest.h"
  18. #include "test/testsupport/fileutils.h"
  19. #include "voe_errors.h"
  20. #include "voe_base.h"
  21. #include "voe_codec.h"
  22. #include "voe_volume_control.h"
  23. #include "voe_dtmf.h"
  24. #include "voe_rtp_rtcp.h"
  25. #include "voe_audio_processing.h"
  26. #include "voe_file.h"
  27. #include "voe_video_sync.h"
  28. #include "voe_encryption.h"
  29. #include "voe_hardware.h"
  30. #include "voe_external_media.h"
  31. #include "voe_network.h"
  32. #include "voe_neteq_stats.h"
  33. #include "engine_configurations.h"
  34. // Enable this this flag to run this test with hard coded
  35. // IP/Port/codec and start test automatically with key input
  36. // it could be useful in repeat tests.
  37. //#define DEBUG
  38. // #define EXTERNAL_TRANSPORT
  39. using namespace webrtc;
  40. #define VALIDATE \
  41. if (res != 0) \
  42. { \
  43. printf("*** Error at position %i / line %i \n", cnt, __LINE__); \
  44. printf("*** Error code = %i \n", base1->LastError()); \
  45. } \
  46. cnt++;
  47. VoiceEngine* m_voe = NULL;
  48. VoEBase* base1 = NULL;
  49. VoECodec* codec = NULL;
  50. VoEVolumeControl* volume = NULL;
  51. VoEDtmf* dtmf = NULL;
  52. VoERTP_RTCP* rtp_rtcp = NULL;
  53. VoEAudioProcessing* apm = NULL;
  54. VoENetwork* netw = NULL;
  55. VoEFile* file = NULL;
  56. VoEVideoSync* vsync = NULL;
  57. VoEEncryption* encr = NULL;
  58. VoEHardware* hardware = NULL;
  59. VoEExternalMedia* xmedia = NULL;
  60. VoENetEqStats* neteqst = NULL;
  61. void RunTest(std::string out_path);
  62. #ifdef EXTERNAL_TRANSPORT
  63. class my_transportation : public Transport
  64. {
  65. int SendPacket(int channel,const void *data,int len);
  66. int SendRTCPPacket(int channel, const void *data, int len);
  67. };
  68. int my_transportation::SendPacket(int channel,const void *data,int len)
  69. {
  70. netw->ReceivedRTPPacket(channel, data, len);
  71. return 0;
  72. }
  73. int my_transportation::SendRTCPPacket(int channel, const void *data, int len)
  74. {
  75. netw->ReceivedRTCPPacket(channel, data, len);
  76. return 0;
  77. }
  78. my_transportation my_transport;
  79. #endif
  80. class MyObserver : public VoiceEngineObserver {
  81. public:
  82. virtual void CallbackOnError(const int channel, const int err_code);
  83. };
  84. void MyObserver::CallbackOnError(const int channel, const int err_code) {
  85. // Add printf for other error codes here
  86. if (err_code == VE_TYPING_NOISE_WARNING) {
  87. printf(" TYPING NOISE DETECTED \n");
  88. } else if (err_code == VE_RECEIVE_PACKET_TIMEOUT) {
  89. printf(" RECEIVE PACKET TIMEOUT \n");
  90. } else if (err_code == VE_PACKET_RECEIPT_RESTARTED) {
  91. printf(" PACKET RECEIPT RESTARTED \n");
  92. } else if (err_code == VE_RUNTIME_PLAY_WARNING) {
  93. printf(" RUNTIME PLAY WARNING \n");
  94. } else if (err_code == VE_RUNTIME_REC_WARNING) {
  95. printf(" RUNTIME RECORD WARNING \n");
  96. } else if (err_code == VE_SATURATION_WARNING) {
  97. printf(" SATURATION WARNING \n");
  98. } else if (err_code == VE_RUNTIME_PLAY_ERROR) {
  99. printf(" RUNTIME PLAY ERROR \n");
  100. } else if (err_code == VE_RUNTIME_REC_ERROR) {
  101. printf(" RUNTIME RECORD ERROR \n");
  102. } else if (err_code == VE_REC_DEVICE_REMOVED) {
  103. printf(" RECORD DEVICE REMOVED \n");
  104. }
  105. }
  106. int main() {
  107. int res = 0;
  108. int cnt = 0;
  109. printf("Test started \n");
  110. m_voe = VoiceEngine::Create();
  111. base1 = VoEBase::GetInterface(m_voe);
  112. codec = VoECodec::GetInterface(m_voe);
  113. apm = VoEAudioProcessing::GetInterface(m_voe);
  114. volume = VoEVolumeControl::GetInterface(m_voe);
  115. dtmf = VoEDtmf::GetInterface(m_voe);
  116. rtp_rtcp = VoERTP_RTCP::GetInterface(m_voe);
  117. netw = VoENetwork::GetInterface(m_voe);
  118. file = VoEFile::GetInterface(m_voe);
  119. vsync = VoEVideoSync::GetInterface(m_voe);
  120. encr = VoEEncryption::GetInterface(m_voe);
  121. hardware = VoEHardware::GetInterface(m_voe);
  122. xmedia = VoEExternalMedia::GetInterface(m_voe);
  123. neteqst = VoENetEqStats::GetInterface(m_voe);
  124. MyObserver my_observer;
  125. const std::string out_path = webrtc::test::OutputPath();
  126. const std::string trace_filename = out_path + "webrtc_trace.txt";
  127. printf("Set trace filenames (enable trace)\n");
  128. VoiceEngine::SetTraceFilter(kTraceAll);
  129. res = VoiceEngine::SetTraceFile(trace_filename.c_str());
  130. VALIDATE;
  131. res = VoiceEngine::SetTraceCallback(NULL);
  132. VALIDATE;
  133. printf("Init\n");
  134. res = base1->Init();
  135. if (res != 0) {
  136. printf("\nError calling Init: %d\n", base1->LastError());
  137. fflush(NULL);
  138. exit(1);
  139. }
  140. res = base1->RegisterVoiceEngineObserver(my_observer);
  141. VALIDATE;
  142. cnt++;
  143. printf("Version\n");
  144. char tmp[1024];
  145. res = base1->GetVersion(tmp);
  146. VALIDATE;
  147. cnt++;
  148. printf("%s\n", tmp);
  149. RunTest(out_path);
  150. printf("Terminate \n");
  151. base1->DeRegisterVoiceEngineObserver();
  152. res = base1->Terminate();
  153. VALIDATE;
  154. if (base1)
  155. base1->Release();
  156. if (codec)
  157. codec->Release();
  158. if (volume)
  159. volume->Release();
  160. if (dtmf)
  161. dtmf->Release();
  162. if (rtp_rtcp)
  163. rtp_rtcp->Release();
  164. if (apm)
  165. apm->Release();
  166. if (netw)
  167. netw->Release();
  168. if (file)
  169. file->Release();
  170. if (vsync)
  171. vsync->Release();
  172. if (encr)
  173. encr->Release();
  174. if (hardware)
  175. hardware->Release();
  176. if (xmedia)
  177. xmedia->Release();
  178. if (neteqst)
  179. neteqst->Release();
  180. VoiceEngine::Delete(m_voe);
  181. return 0;
  182. }
  183. void RunTest(std::string out_path) {
  184. int chan, cnt, res;
  185. CodecInst cinst;
  186. cnt = 0;
  187. int i;
  188. int codecinput;
  189. bool AEC = false;
  190. bool AGC = true;
  191. bool rx_agc = false;
  192. bool VAD = false;
  193. bool NS = false;
  194. bool rx_ns = false;
  195. bool typing_detection = false;
  196. bool muted = false;
  197. bool on_hold = false;
  198. #if defined(WEBRTC_ANDROID)
  199. std::string resource_path = "/sdcard/";
  200. #else
  201. std::string resource_path = webrtc::test::ProjectRootPath();
  202. if (resource_path == webrtc::test::kCannotFindProjectRootDir) {
  203. printf("*** Unable to get project root directory. "
  204. "File playing may fail. ***\n");
  205. // Fall back to the current directory.
  206. resource_path = "./";
  207. } else {
  208. resource_path += "data/voice_engine/";
  209. }
  210. #endif
  211. const std::string audio_filename = resource_path + "audio_long16.pcm";
  212. const std::string play_filename = out_path + "recorded_playout.pcm";
  213. const std::string mic_filename = out_path + "recorded_mic.pcm";
  214. chan = base1->CreateChannel();
  215. if (chan < 0) {
  216. printf("Error at position %i\n", cnt);
  217. printf("************ Error code = %i\n", base1->LastError());
  218. fflush(NULL);
  219. }
  220. cnt++;
  221. int j = 0;
  222. #ifdef EXTERNAL_TRANSPORT
  223. my_transportation ch0transport;
  224. printf("Enabling external transport \n");
  225. netw->RegisterExternalTransport(0, ch0transport);
  226. #else
  227. char ip[64];
  228. #ifdef DEBUG
  229. strcpy(ip, "127.0.0.1");
  230. #else
  231. char localip[64];
  232. netw->GetLocalIP(localip);
  233. printf("local IP:%s\n", localip);
  234. printf("1. 127.0.0.1 \n");
  235. printf("2. Specify IP \n");
  236. ASSERT_EQ(1, scanf("%i", &i));
  237. if (1 == i)
  238. strcpy(ip, "127.0.0.1");
  239. else {
  240. printf("Specify remote IP: ");
  241. ASSERT_EQ(1, scanf("%s", ip));
  242. }
  243. #endif
  244. int colons(0);
  245. while (ip[j] != '\0' && j < 64 && !(colons = (ip[j++] == ':')))
  246. ;
  247. if (colons) {
  248. printf("Enabling IPv6\n");
  249. res = netw->EnableIPv6(0);
  250. VALIDATE;
  251. }
  252. int rPort;
  253. #ifdef DEBUG
  254. rPort=8500;
  255. #else
  256. printf("Specify remote port (1=1234): ");
  257. ASSERT_EQ(1, scanf("%i", &rPort));
  258. if (1 == rPort)
  259. rPort = 1234;
  260. printf("Set Send port \n");
  261. #endif
  262. printf("Set Send IP \n");
  263. res = base1->SetSendDestination(chan, rPort, ip);
  264. VALIDATE;
  265. int lPort;
  266. #ifdef DEBUG
  267. lPort=8500;
  268. #else
  269. printf("Specify local port (1=1234): ");
  270. ASSERT_EQ(1, scanf("%i", &lPort));
  271. if (1 == lPort)
  272. lPort = 1234;
  273. printf("Set Rec Port \n");
  274. #endif
  275. res = base1->SetLocalReceiver(chan, lPort);
  276. VALIDATE;
  277. #endif
  278. printf("\n");
  279. for (i = 0; i < codec->NumOfCodecs(); i++) {
  280. res = codec->GetCodec(i, cinst);
  281. VALIDATE;
  282. if (strncmp(cinst.plname, "ISAC", 4) == 0 && cinst.plfreq == 32000) {
  283. printf("%i. ISAC-swb pltype:%i plfreq:%i channels:%i\n", i, cinst.pltype,
  284. cinst.plfreq, cinst.channels);
  285. } else if (strncmp(cinst.plname, "ISAC", 4) == 0 && cinst.plfreq == 48000) {
  286. printf("%i. ISAC-fb pltype:%i plfreq:%i channels:%i\n", i, cinst.pltype,
  287. cinst.plfreq, cinst.channels);
  288. } else {
  289. printf("%i. %s pltype:%i plfreq:%i channels:%i\n", i, cinst.plname,
  290. cinst.pltype, cinst.plfreq, cinst.channels);
  291. }
  292. }
  293. #ifdef DEBUG
  294. codecinput=0;
  295. #else
  296. printf("Select send codec: ");
  297. ASSERT_EQ(1, scanf("%i", &codecinput));
  298. #endif
  299. codec->GetCodec(codecinput, cinst);
  300. printf("Set primary codec\n");
  301. res = codec->SetSendCodec(chan, cinst);
  302. VALIDATE;
  303. #ifndef WEBRTC_ANDROID
  304. const int kMaxNumChannels = 8;
  305. #else
  306. const int kMaxNumChannels = 1;
  307. #endif
  308. int channel_index = 0;
  309. std::vector<int> channels(kMaxNumChannels);
  310. for (i = 0; i < kMaxNumChannels; ++i) {
  311. channels[i] = base1->CreateChannel();
  312. int port = rPort + (i + 1) * 2;
  313. res = base1->SetSendDestination(channels[i], port, ip);
  314. VALIDATE;
  315. res = base1->SetLocalReceiver(channels[i], port);
  316. VALIDATE;
  317. res = codec->SetSendCodec(channels[i], cinst);
  318. VALIDATE;
  319. }
  320. // Call loop
  321. bool newcall = true;
  322. while (newcall) {
  323. #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
  324. int rd(-1), pd(-1);
  325. res = hardware->GetNumOfRecordingDevices(rd);
  326. VALIDATE;
  327. res = hardware->GetNumOfPlayoutDevices(pd);
  328. VALIDATE;
  329. char dn[128] = { 0 };
  330. char guid[128] = { 0 };
  331. printf("\nPlayout devices (%d): \n", pd);
  332. for (j=0; j<pd; ++j) {
  333. res = hardware->GetPlayoutDeviceName(j, dn, guid);
  334. VALIDATE;
  335. printf(" %d: %s \n", j, dn);
  336. }
  337. printf("Recording devices (%d): \n", rd);
  338. for (j=0; j<rd; ++j) {
  339. res = hardware->GetRecordingDeviceName(j, dn, guid);
  340. VALIDATE;
  341. printf(" %d: %s \n", j, dn);
  342. }
  343. printf("Select playout device: ");
  344. ASSERT_EQ(1, scanf("%d", &pd));
  345. res = hardware->SetPlayoutDevice(pd);
  346. VALIDATE;
  347. printf("Select recording device: ");
  348. ASSERT_EQ(1, scanf("%d", &rd));
  349. printf("Setting sound devices \n");
  350. res = hardware->SetRecordingDevice(rd);
  351. VALIDATE;
  352. #endif // WEBRTC_LINUX
  353. res = codec->SetVADStatus(0, VAD);
  354. VALIDATE;
  355. res = apm->SetAgcStatus(AGC);
  356. VALIDATE;
  357. res = apm->SetEcStatus(AEC);
  358. VALIDATE;
  359. res = apm->SetNsStatus(NS);
  360. VALIDATE;
  361. #ifdef DEBUG
  362. i = 1;
  363. #else
  364. printf("\n1. Send, listen and playout \n");
  365. printf("2. Send only \n");
  366. printf("3. Listen and playout only \n");
  367. printf("Select transfer mode: ");
  368. ASSERT_EQ(1, scanf("%i", &i));
  369. #endif
  370. const bool send = !(3 == i);
  371. const bool receive = !(2 == i);
  372. if (receive) {
  373. #ifndef EXTERNAL_TRANSPORT
  374. printf("Start Listen \n");
  375. res = base1->StartReceive(chan);
  376. VALIDATE;
  377. #endif
  378. printf("Start Playout \n");
  379. res = base1->StartPlayout(chan);
  380. VALIDATE;
  381. }
  382. if (send) {
  383. printf("Start Send \n");
  384. res = base1->StartSend(chan);
  385. VALIDATE;
  386. }
  387. #ifndef WEBRTC_ANDROID
  388. printf("Getting mic volume \n");
  389. unsigned int vol = 999;
  390. res = volume->GetMicVolume(vol);
  391. VALIDATE;
  392. if ((vol > 255) || (vol < 1)) {
  393. printf("\n****ERROR in GetMicVolume");
  394. }
  395. #endif
  396. int forever = 1;
  397. while (forever) {
  398. printf("\nActions\n");
  399. printf("Codec Changes\n");
  400. for (i = 0; i < codec->NumOfCodecs(); i++) {
  401. res = codec->GetCodec(i, cinst);
  402. VALIDATE;
  403. if (strncmp(cinst.plname, "ISAC", 4) == 0 && cinst.plfreq
  404. == 32000) {
  405. printf("\t%i. ISAC-swb pltype:%i plfreq:%i channels:%i\n", i,
  406. cinst.pltype, cinst.plfreq, cinst.channels);
  407. }
  408. else {
  409. printf("\t%i. %s pltype:%i plfreq:%i channels:%i\n", i, cinst.plname,
  410. cinst.pltype, cinst.plfreq, cinst.channels);
  411. }
  412. }
  413. printf("Other\n");
  414. const int noCodecs = i - 1;
  415. printf("\t%i. Toggle VAD\n", i);
  416. i++;
  417. printf("\t%i. Toggle AGC\n", i);
  418. i++;
  419. printf("\t%i. Toggle NS\n", i);
  420. i++;
  421. printf("\t%i. Toggle EC\n", i);
  422. i++;
  423. printf("\t%i. Select AEC\n", i);
  424. i++;
  425. printf("\t%i. Select AECM\n", i);
  426. i++;
  427. printf("\t%i. Get speaker volume\n", i);
  428. i++;
  429. printf("\t%i. Set speaker volume\n", i);
  430. i++;
  431. printf("\t%i. Get microphone volume\n", i);
  432. i++;
  433. printf("\t%i. Set microphone volume\n", i);
  434. i++;
  435. printf("\t%i. Play local file (audio_long16.pcm) \n", i);
  436. i++;
  437. printf("\t%i. Change playout device \n", i);
  438. i++;
  439. printf("\t%i. Change recording device \n", i);
  440. i++;
  441. printf("\t%i. Toggle receive-side AGC \n", i);
  442. i++;
  443. printf("\t%i. Toggle receive-side NS \n", i);
  444. i++;
  445. printf("\t%i. AGC status \n", i);
  446. i++;
  447. printf("\t%i. Toggle microphone mute \n", i);
  448. i++;
  449. printf("\t%i. Toggle on hold status \n", i);
  450. i++;
  451. printf("\t%i. Get last error code \n", i);
  452. i++;
  453. printf("\t%i. Toggle typing detection (for Mac/Windows only) \n", i);
  454. i++;
  455. printf("\t%i. Record a PCM file \n", i);
  456. i++;
  457. printf("\t%i. Play a previously recorded PCM file locally \n", i);
  458. i++;
  459. printf("\t%i. Play a previously recorded PCM file as microphone \n", i);
  460. i++;
  461. printf("\t%i. Add an additional file-playing channel \n", i);
  462. i++;
  463. printf("\t%i. Remove a file-playing channel \n", i);
  464. i++;
  465. printf("Select action or %i to stop the call: ", i);
  466. ASSERT_EQ(1, scanf("%i", &codecinput));
  467. if (codecinput < codec->NumOfCodecs()) {
  468. res = codec->GetCodec(codecinput, cinst);
  469. VALIDATE;
  470. printf("Set primary codec\n");
  471. res = codec->SetSendCodec(chan, cinst);
  472. VALIDATE;
  473. }
  474. else if (codecinput == (noCodecs + 1)) {
  475. VAD = !VAD;
  476. res = codec->SetVADStatus(0, VAD);
  477. VALIDATE;
  478. if (VAD)
  479. printf("\n VAD is now on! \n");
  480. else
  481. printf("\n VAD is now off! \n");
  482. }
  483. else if (codecinput == (noCodecs + 2)) {
  484. AGC = !AGC;
  485. res = apm->SetAgcStatus(AGC);
  486. VALIDATE;
  487. if (AGC)
  488. printf("\n AGC is now on! \n");
  489. else
  490. printf("\n AGC is now off! \n");
  491. }
  492. else if (codecinput == (noCodecs + 3)) {
  493. NS = !NS;
  494. res = apm->SetNsStatus(NS);
  495. VALIDATE;
  496. if (NS)
  497. printf("\n NS is now on! \n");
  498. else
  499. printf("\n NS is now off! \n");
  500. }
  501. else if (codecinput == (noCodecs + 4)) {
  502. AEC = !AEC;
  503. res = apm->SetEcStatus(AEC, kEcUnchanged);
  504. VALIDATE;
  505. if (AEC)
  506. printf("\n Echo control is now on! \n");
  507. else
  508. printf("\n Echo control is now off! \n");
  509. }
  510. else if (codecinput == (noCodecs + 5)) {
  511. res = apm->SetEcStatus(AEC, kEcAec);
  512. VALIDATE;
  513. printf("\n AEC selected! \n");
  514. if (AEC)
  515. printf(" (Echo control is on)\n");
  516. else
  517. printf(" (Echo control is off)\n");
  518. }
  519. else if (codecinput == (noCodecs + 6)) {
  520. res = apm->SetEcStatus(AEC, kEcAecm);
  521. VALIDATE;
  522. printf("\n AECM selected! \n");
  523. if (AEC)
  524. printf(" (Echo control is on)\n");
  525. else
  526. printf(" (Echo control is off)\n");
  527. }
  528. else if (codecinput == (noCodecs + 7)) {
  529. unsigned vol(0);
  530. res = volume->GetSpeakerVolume(vol);
  531. VALIDATE;
  532. printf("\n Speaker Volume is %d \n", vol);
  533. }
  534. else if (codecinput == (noCodecs + 8)) {
  535. printf("Level: ");
  536. ASSERT_EQ(1, scanf("%i", &i));
  537. res = volume->SetSpeakerVolume(i);
  538. VALIDATE;
  539. }
  540. else if (codecinput == (noCodecs + 9)) {
  541. unsigned vol(0);
  542. res = volume->GetMicVolume(vol);
  543. VALIDATE;
  544. printf("\n Microphone Volume is %d \n", vol);
  545. }
  546. else if (codecinput == (noCodecs + 10)) {
  547. printf("Level: ");
  548. ASSERT_EQ(1, scanf("%i", &i));
  549. res = volume->SetMicVolume(i);
  550. VALIDATE;
  551. }
  552. else if (codecinput == (noCodecs + 11)) {
  553. res = file->StartPlayingFileLocally(0, audio_filename.c_str());
  554. VALIDATE;
  555. }
  556. else if (codecinput == (noCodecs + 12)) {
  557. // change the playout device with current call
  558. int num_pd(-1);
  559. res = hardware->GetNumOfPlayoutDevices(num_pd);
  560. VALIDATE;
  561. char dn[128] = { 0 };
  562. char guid[128] = { 0 };
  563. printf("\nPlayout devices (%d): \n", num_pd);
  564. for (j = 0; j < num_pd; ++j) {
  565. res = hardware->GetPlayoutDeviceName(j, dn, guid);
  566. VALIDATE;
  567. printf(" %d: %s \n", j, dn);
  568. }
  569. printf("Select playout device: ");
  570. ASSERT_EQ(1, scanf("%d", &num_pd));
  571. // Will use plughw for hardware devices
  572. res = hardware->SetPlayoutDevice(num_pd);
  573. VALIDATE;
  574. }
  575. else if (codecinput == (noCodecs + 13)) {
  576. // change the recording device with current call
  577. int num_rd(-1);
  578. res = hardware->GetNumOfRecordingDevices(num_rd);
  579. VALIDATE;
  580. char dn[128] = { 0 };
  581. char guid[128] = { 0 };
  582. printf("Recording devices (%d): \n", num_rd);
  583. for (j = 0; j < num_rd; ++j) {
  584. res = hardware->GetRecordingDeviceName(j, dn, guid);
  585. VALIDATE;
  586. printf(" %d: %s \n", j, dn);
  587. }
  588. printf("Select recording device: ");
  589. ASSERT_EQ(1, scanf("%d", &num_rd));
  590. printf("Setting sound devices \n");
  591. // Will use plughw for hardware devices
  592. res = hardware->SetRecordingDevice(num_rd);
  593. VALIDATE;
  594. }
  595. else if (codecinput == (noCodecs + 14)) {
  596. // Remote AGC
  597. rx_agc = !rx_agc;
  598. res = apm->SetRxAgcStatus(chan, rx_agc);
  599. VALIDATE;
  600. if (rx_agc)
  601. printf("\n Receive-side AGC is now on! \n");
  602. else
  603. printf("\n Receive-side AGC is now off! \n");
  604. }
  605. else if (codecinput == (noCodecs + 15)) {
  606. // Remote NS
  607. rx_ns = !rx_ns;
  608. res = apm->SetRxNsStatus(chan, rx_ns);
  609. VALIDATE;
  610. if (rx_ns)
  611. printf("\n Receive-side NS is now on! \n");
  612. else
  613. printf("\n Receive-side NS is now off! \n");
  614. }
  615. else if (codecinput == (noCodecs + 16)) {
  616. AgcModes agcmode;
  617. bool enable;
  618. res = apm->GetAgcStatus(enable, agcmode);
  619. VALIDATE
  620. printf("\n AGC enable is %d, mode is %d \n", enable, agcmode);
  621. }
  622. else if (codecinput == (noCodecs + 17)) {
  623. // Toggle Mute on Microphone
  624. res = volume->GetInputMute(chan, muted);
  625. VALIDATE;
  626. muted = !muted;
  627. res = volume->SetInputMute(chan, muted);
  628. VALIDATE;
  629. if (muted)
  630. printf("\n Microphone is now on mute! \n");
  631. else
  632. printf("\n Microphone is no longer on mute! \n");
  633. }
  634. else if (codecinput == (noCodecs + 18)) {
  635. // Toggle the call on hold
  636. OnHoldModes mode;
  637. res = base1->GetOnHoldStatus(chan, on_hold, mode);
  638. VALIDATE;
  639. on_hold = !on_hold;
  640. mode = kHoldSendAndPlay;
  641. res = base1->SetOnHoldStatus(chan, on_hold, mode);
  642. VALIDATE;
  643. if (on_hold)
  644. printf("\n Call now on hold! \n");
  645. else
  646. printf("\n Call now not on hold! \n");
  647. }
  648. else if (codecinput == (noCodecs + 19)) {
  649. // Get the last error code and print to screen
  650. int err_code = 0;
  651. err_code = base1->LastError();
  652. if (err_code != -1)
  653. printf("\n The last error code was %i.\n", err_code);
  654. }
  655. else if (codecinput == (noCodecs + 20)) {
  656. typing_detection= !typing_detection;
  657. res = apm->SetTypingDetectionStatus(typing_detection);
  658. VALIDATE;
  659. if (typing_detection)
  660. printf("\n Typing detection is now on!\n");
  661. else
  662. printf("\n Typing detection is now off!\n");
  663. }
  664. else if (codecinput == (noCodecs + 21)) {
  665. int stop_record = 1;
  666. int file_source = 1;
  667. printf("\n Select source of recorded file. ");
  668. printf("\n 1. Record from microphone to file ");
  669. printf("\n 2. Record from playout to file ");
  670. printf("\n Enter your selection: \n");
  671. ASSERT_EQ(1, scanf("%i", &file_source));
  672. if (file_source == 1) {
  673. printf("\n Start recording microphone as %s \n",
  674. mic_filename.c_str());
  675. res = file->StartRecordingMicrophone(mic_filename.c_str());
  676. VALIDATE;
  677. }
  678. else {
  679. printf("\n Start recording playout as %s \n", play_filename.c_str());
  680. res = file->StartRecordingPlayout(chan, play_filename.c_str());
  681. VALIDATE;
  682. }
  683. while (stop_record != 0) {
  684. printf("\n Type 0 to stop recording file \n");
  685. ASSERT_EQ(1, scanf("%i", &stop_record));
  686. }
  687. if (file_source == 1) {
  688. res = file->StopRecordingMicrophone();
  689. VALIDATE;
  690. }
  691. else {
  692. res = file->StopRecordingPlayout(chan);
  693. VALIDATE;
  694. }
  695. printf("\n File finished recording \n");
  696. }
  697. else if (codecinput == (noCodecs + 22)) {
  698. int file_type = 1;
  699. int stop_play = 1;
  700. printf("\n Select a file to play locally in a loop.");
  701. printf("\n 1. Play %s", mic_filename.c_str());
  702. printf("\n 2. Play %s", play_filename.c_str());
  703. printf("\n Enter your selection\n");
  704. ASSERT_EQ(1, scanf("%i", &file_type));
  705. if (file_type == 1) {
  706. printf("\n Start playing %s locally in a loop\n",
  707. mic_filename.c_str());
  708. res = file->StartPlayingFileLocally(chan, mic_filename.c_str(), true);
  709. VALIDATE;
  710. }
  711. else {
  712. printf("\n Start playing %s locally in a loop\n",
  713. play_filename.c_str());
  714. res = file->StartPlayingFileLocally(chan, play_filename.c_str(),
  715. true);
  716. VALIDATE;
  717. }
  718. while (stop_play != 0) {
  719. printf("\n Type 0 to stop playing file\n");
  720. ASSERT_EQ(1, scanf("%i", &stop_play));
  721. }
  722. res = file->StopPlayingFileLocally(chan);
  723. VALIDATE;
  724. }
  725. else if (codecinput == (noCodecs + 23)) {
  726. int file_type = 1;
  727. int stop_play = 1;
  728. printf("\n Select a file to play as microphone in a loop.");
  729. printf("\n 1. Play %s", mic_filename.c_str());
  730. printf("\n 2. Play %s", play_filename.c_str());
  731. printf("\n Enter your selection\n");
  732. ASSERT_EQ(1, scanf("%i", &file_type));
  733. if (file_type == 1) {
  734. printf("\n Start playing %s as mic in a loop\n",
  735. mic_filename.c_str());
  736. res = file->StartPlayingFileAsMicrophone(chan, mic_filename.c_str(),
  737. true);
  738. VALIDATE;
  739. }
  740. else {
  741. printf("\n Start playing %s as mic in a loop\n",
  742. play_filename.c_str());
  743. res = file->StartPlayingFileAsMicrophone(chan, play_filename.c_str(),
  744. true);
  745. VALIDATE;
  746. }
  747. while (stop_play != 0) {
  748. printf("\n Type 0 to stop playing file\n");
  749. ASSERT_EQ(1, scanf("%i", &stop_play));
  750. }
  751. res = file->StopPlayingFileAsMicrophone(chan);
  752. VALIDATE;
  753. }
  754. else if (codecinput == (noCodecs + 24)) {
  755. if (channel_index < kMaxNumChannels) {
  756. res = base1->StartReceive(channels[channel_index]);
  757. VALIDATE;
  758. res = base1->StartPlayout(channels[channel_index]);
  759. VALIDATE;
  760. res = base1->StartSend(channels[channel_index]);
  761. VALIDATE;
  762. res = file->StartPlayingFileAsMicrophone(channels[channel_index],
  763. audio_filename.c_str(),
  764. true,
  765. false);
  766. VALIDATE;
  767. channel_index++;
  768. printf("Using %d additional channels\n", channel_index);
  769. } else {
  770. printf("Max number of channels reached\n");
  771. }
  772. }
  773. else if (codecinput == (noCodecs + 25)) {
  774. if (channel_index > 0) {
  775. channel_index--;
  776. res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
  777. VALIDATE;
  778. res = base1->StopSend(channels[channel_index]);
  779. VALIDATE;
  780. res = base1->StopPlayout(channels[channel_index]);
  781. VALIDATE;
  782. res = base1->StopReceive(channels[channel_index]);
  783. VALIDATE;
  784. printf("Using %d additional channels\n", channel_index);
  785. } else {
  786. printf("All additional channels stopped\n");
  787. }
  788. }
  789. else
  790. break;
  791. }
  792. if (send) {
  793. printf("Stop Send \n");
  794. res = base1->StopSend(chan);
  795. VALIDATE;
  796. }
  797. if (receive) {
  798. printf("Stop Playout \n");
  799. res = base1->StopPlayout(chan);
  800. VALIDATE;
  801. #ifndef EXTERNAL_TRANSPORT
  802. printf("Stop Listen \n");
  803. res = base1->StopReceive(chan);
  804. VALIDATE;
  805. #endif
  806. }
  807. while (channel_index > 0) {
  808. --channel_index;
  809. res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
  810. VALIDATE;
  811. res = base1->StopSend(channels[channel_index]);
  812. VALIDATE;
  813. res = base1->StopPlayout(channels[channel_index]);
  814. VALIDATE;
  815. res = base1->StopReceive(channels[channel_index]);
  816. VALIDATE;
  817. }
  818. printf("\n1. New call \n");
  819. printf("2. Quit \n");
  820. printf("Select action: ");
  821. ASSERT_EQ(1, scanf("%i", &i));
  822. newcall = (1 == i);
  823. // Call loop
  824. }
  825. printf("Delete channels \n");
  826. res = base1->DeleteChannel(chan);
  827. VALIDATE;
  828. for (i = 0; i < kMaxNumChannels; ++i) {
  829. channels[i] = base1->DeleteChannel(channels[i]);
  830. VALIDATE;
  831. }
  832. }