/pjsip_android/apps/pjsip/project/third_party/webrtc/voice_engine/main/test/cmd_test/voe_cmd_test.cc

http://csipsimple.googlecode.com/ · C++ · 918 lines · 797 code · 94 blank · 27 comment · 201 complexity · c9803bd3b260bf64d048da9e86da6a36 MD5 · raw file

  1. /*
  2. * Copyright (c) 2011 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 AGC1 = false;
  192. bool VAD = false;
  193. bool NS = false;
  194. bool NS1 = 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 += "test/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 plfreqi:%i\n", i, cinst.pltype,
  284. cinst.plfreq);
  285. }
  286. else {
  287. printf("%i. %s pltype:%i plfreq:%i\n", i, cinst.plname,
  288. cinst.pltype, cinst.plfreq);
  289. }
  290. }
  291. #ifdef DEBUG
  292. codecinput=0;
  293. #else
  294. printf("Select send codec: ");
  295. ASSERT_EQ(1, scanf("%i", &codecinput));
  296. #endif
  297. codec->GetCodec(codecinput, cinst);
  298. printf("Set primary codec\n");
  299. res = codec->SetSendCodec(chan, cinst);
  300. VALIDATE;
  301. const int kMaxNumChannels = 8;
  302. int channel_index = 0;
  303. std::vector<int> channels(kMaxNumChannels);
  304. for (i = 0; i < kMaxNumChannels; ++i) {
  305. channels[i] = base1->CreateChannel();
  306. int port = rPort + (i + 1) * 2;
  307. res = base1->SetSendDestination(channels[i], port, ip);
  308. VALIDATE;
  309. res = base1->SetLocalReceiver(channels[i], port);
  310. VALIDATE;
  311. res = codec->SetSendCodec(channels[i], cinst);
  312. VALIDATE;
  313. }
  314. // Call loop
  315. bool newcall = true;
  316. while (newcall) {
  317. #ifdef WEBRTC_LINUX
  318. int rd(-1), pd(-1);
  319. res = hardware->GetNumOfRecordingDevices(rd);
  320. VALIDATE;
  321. res = hardware->GetNumOfPlayoutDevices(pd);
  322. VALIDATE;
  323. char dn[128] = { 0 };
  324. char guid[128] = { 0 };
  325. printf("\nPlayout devices (%d): \n", pd);
  326. for (j=0; j<pd; ++j) {
  327. res = hardware->GetPlayoutDeviceName(j, dn, guid);
  328. VALIDATE;
  329. printf(" %d: %s \n", j, dn);
  330. }
  331. printf("Recording devices (%d): \n", rd);
  332. for (j=0; j<rd; ++j) {
  333. res = hardware->GetRecordingDeviceName(j, dn, guid);
  334. VALIDATE;
  335. printf(" %d: %s \n", j, dn);
  336. }
  337. printf("Select playout device: ");
  338. ASSERT_EQ(1, scanf("%d", &pd));
  339. res = hardware->SetPlayoutDevice(pd);
  340. VALIDATE;
  341. printf("Select recording device: ");
  342. ASSERT_EQ(1, scanf("%d", &rd));
  343. printf("Setting sound devices \n");
  344. res = hardware->SetRecordingDevice(rd);
  345. VALIDATE;
  346. #endif // WEBRTC_LINUX
  347. res = codec->SetVADStatus(0, VAD);
  348. VALIDATE;
  349. res = apm->SetAgcStatus(AGC);
  350. VALIDATE;
  351. res = apm->SetEcStatus(AEC);
  352. VALIDATE;
  353. res = apm->SetNsStatus(NS);
  354. VALIDATE;
  355. #ifdef DEBUG
  356. i = 1;
  357. #else
  358. printf("\n1. Send, listen and playout \n");
  359. printf("2. Send only \n");
  360. printf("3. Listen and playout only \n");
  361. printf("Select transfer mode: ");
  362. ASSERT_EQ(1, scanf("%i", &i));
  363. #endif
  364. const bool send = !(3 == i);
  365. const bool receive = !(2 == i);
  366. if (receive) {
  367. #ifndef EXTERNAL_TRANSPORT
  368. printf("Start Listen \n");
  369. res = base1->StartReceive(chan);
  370. VALIDATE;
  371. #endif
  372. printf("Start Playout \n");
  373. res = base1->StartPlayout(chan);
  374. VALIDATE;
  375. }
  376. if (send) {
  377. printf("Start Send \n");
  378. res = base1->StartSend(chan);
  379. VALIDATE;
  380. }
  381. printf("Getting mic volume \n");
  382. unsigned int vol = 999;
  383. res = volume->GetMicVolume(vol);
  384. VALIDATE;
  385. if ((vol > 255) || (vol < 1)) {
  386. printf("\n****ERROR in GetMicVolume");
  387. }
  388. int forever = 1;
  389. while (forever) {
  390. printf("\nActions\n");
  391. printf("Codec Changes\n");
  392. for (i = 0; i < codec->NumOfCodecs(); i++) {
  393. res = codec->GetCodec(i, cinst);
  394. VALIDATE;
  395. if (strncmp(cinst.plname, "ISAC", 4) == 0 && cinst.plfreq
  396. == 32000) {
  397. printf("\t%i. ISAC-swb pltype:%i plfreq:%i\n", i,
  398. cinst.pltype, cinst.plfreq);
  399. }
  400. else {
  401. printf("\t%i. %s pltype:%i plfreq:%i\n", i, cinst.plname,
  402. cinst.pltype, cinst.plfreq);
  403. }
  404. }
  405. printf("Other\n");
  406. const int noCodecs = i - 1;
  407. printf("\t%i. Toggle VAD\n", i);
  408. i++;
  409. printf("\t%i. Toggle AGC\n", i);
  410. i++;
  411. printf("\t%i. Toggle NS\n", i);
  412. i++;
  413. printf("\t%i. Toggle EC\n", i);
  414. i++;
  415. printf("\t%i. Select AEC\n", i);
  416. i++;
  417. printf("\t%i. Select AECM\n", i);
  418. i++;
  419. printf("\t%i. Get speaker volume\n", i);
  420. i++;
  421. printf("\t%i. Set speaker volume\n", i);
  422. i++;
  423. printf("\t%i. Get microphone volume\n", i);
  424. i++;
  425. printf("\t%i. Set microphone volume\n", i);
  426. i++;
  427. printf("\t%i. Play local file (audio_long16.pcm) \n", i);
  428. i++;
  429. printf("\t%i. Change playout device \n", i);
  430. i++;
  431. printf("\t%i. Change recording device \n", i);
  432. i++;
  433. printf("\t%i. Toggle receive-side AGC \n", i);
  434. i++;
  435. printf("\t%i. Toggle receive-side NS \n", i);
  436. i++;
  437. printf("\t%i. AGC status \n", i);
  438. i++;
  439. printf("\t%i. Toggle microphone mute \n", i);
  440. i++;
  441. printf("\t%i. Toggle on hold status \n", i);
  442. i++;
  443. printf("\t%i. Get last error code \n", i);
  444. i++;
  445. printf("\t%i. Toggle typing detection (for Mac/Windows only) \n", i);
  446. i++;
  447. printf("\t%i. Record a PCM file \n", i);
  448. i++;
  449. printf("\t%i. Play a previously recorded PCM file locally \n", i);
  450. i++;
  451. printf("\t%i. Play a previously recorded PCM file as microphone \n", i);
  452. i++;
  453. printf("\t%i. Add an additional file-playing channel \n", i);
  454. i++;
  455. printf("\t%i. Remove a file-playing channel \n", i);
  456. i++;
  457. printf("Select action or %i to stop the call: ", i);
  458. ASSERT_EQ(1, scanf("%i", &codecinput));
  459. if (codecinput < codec->NumOfCodecs()) {
  460. res = codec->GetCodec(codecinput, cinst);
  461. VALIDATE;
  462. printf("Set primary codec\n");
  463. res = codec->SetSendCodec(chan, cinst);
  464. VALIDATE;
  465. }
  466. else if (codecinput == (noCodecs + 1)) {
  467. VAD = !VAD;
  468. res = codec->SetVADStatus(0, VAD);
  469. VALIDATE;
  470. if (VAD)
  471. printf("\n VAD is now on! \n");
  472. else
  473. printf("\n VAD is now off! \n");
  474. }
  475. else if (codecinput == (noCodecs + 2)) {
  476. AGC = !AGC;
  477. res = apm->SetAgcStatus(AGC);
  478. VALIDATE;
  479. if (AGC)
  480. printf("\n AGC is now on! \n");
  481. else
  482. printf("\n AGC is now off! \n");
  483. }
  484. else if (codecinput == (noCodecs + 3)) {
  485. NS = !NS;
  486. res = apm->SetNsStatus(NS);
  487. VALIDATE;
  488. if (NS)
  489. printf("\n NS is now on! \n");
  490. else
  491. printf("\n NS is now off! \n");
  492. }
  493. else if (codecinput == (noCodecs + 4)) {
  494. AEC = !AEC;
  495. res = apm->SetEcStatus(AEC, kEcUnchanged);
  496. VALIDATE;
  497. if (AEC)
  498. printf("\n Echo control is now on! \n");
  499. else
  500. printf("\n Echo control is now off! \n");
  501. }
  502. else if (codecinput == (noCodecs + 5)) {
  503. res = apm->SetEcStatus(AEC, kEcAec);
  504. VALIDATE;
  505. printf("\n AEC selected! \n");
  506. if (AEC)
  507. printf(" (Echo control is on)\n");
  508. else
  509. printf(" (Echo control is off)\n");
  510. }
  511. else if (codecinput == (noCodecs + 6)) {
  512. res = apm->SetEcStatus(AEC, kEcAecm);
  513. VALIDATE;
  514. printf("\n AECM selected! \n");
  515. if (AEC)
  516. printf(" (Echo control is on)\n");
  517. else
  518. printf(" (Echo control is off)\n");
  519. }
  520. else if (codecinput == (noCodecs + 7)) {
  521. unsigned vol(0);
  522. res = volume->GetSpeakerVolume(vol);
  523. VALIDATE;
  524. printf("\n Speaker Volume is %d \n", vol);
  525. }
  526. else if (codecinput == (noCodecs + 8)) {
  527. printf("Level: ");
  528. ASSERT_EQ(1, scanf("%i", &i));
  529. res = volume->SetSpeakerVolume(i);
  530. VALIDATE;
  531. }
  532. else if (codecinput == (noCodecs + 9)) {
  533. unsigned vol(0);
  534. res = volume->GetMicVolume(vol);
  535. VALIDATE;
  536. printf("\n Microphone Volume is %d \n", vol);
  537. }
  538. else if (codecinput == (noCodecs + 10)) {
  539. printf("Level: ");
  540. ASSERT_EQ(1, scanf("%i", &i));
  541. res = volume->SetMicVolume(i);
  542. VALIDATE;
  543. }
  544. else if (codecinput == (noCodecs + 11)) {
  545. res = file->StartPlayingFileLocally(0, audio_filename.c_str());
  546. VALIDATE;
  547. }
  548. else if (codecinput == (noCodecs + 12)) {
  549. // change the playout device with current call
  550. int num_pd(-1);
  551. res = hardware->GetNumOfPlayoutDevices(num_pd);
  552. VALIDATE;
  553. char dn[128] = { 0 };
  554. char guid[128] = { 0 };
  555. printf("\nPlayout devices (%d): \n", num_pd);
  556. for (j = 0; j < num_pd; ++j) {
  557. res = hardware->GetPlayoutDeviceName(j, dn, guid);
  558. VALIDATE;
  559. printf(" %d: %s \n", j, dn);
  560. }
  561. printf("Select playout device: ");
  562. ASSERT_EQ(1, scanf("%d", &num_pd));
  563. // Will use plughw for hardware devices
  564. res = hardware->SetPlayoutDevice(num_pd);
  565. VALIDATE;
  566. }
  567. else if (codecinput == (noCodecs + 13)) {
  568. // change the recording device with current call
  569. int num_rd(-1);
  570. res = hardware->GetNumOfRecordingDevices(num_rd);
  571. VALIDATE;
  572. char dn[128] = { 0 };
  573. char guid[128] = { 0 };
  574. printf("Recording devices (%d): \n", num_rd);
  575. for (j = 0; j < num_rd; ++j) {
  576. res = hardware->GetRecordingDeviceName(j, dn, guid);
  577. VALIDATE;
  578. printf(" %d: %s \n", j, dn);
  579. }
  580. printf("Select recording device: ");
  581. ASSERT_EQ(1, scanf("%d", &num_rd));
  582. printf("Setting sound devices \n");
  583. // Will use plughw for hardware devices
  584. res = hardware->SetRecordingDevice(num_rd);
  585. VALIDATE;
  586. }
  587. else if (codecinput == (noCodecs + 14)) {
  588. // Remote AGC
  589. AGC1 = !AGC1;
  590. res = apm->SetRxAgcStatus(chan, AGC1);
  591. VALIDATE;
  592. if (AGC1)
  593. printf("\n Receive-side AGC is now on! \n");
  594. else
  595. printf("\n Receive-side AGC is now off! \n");
  596. }
  597. else if (codecinput == (noCodecs + 15)) {
  598. // Remote NS
  599. NS1 = !NS1;
  600. res = apm->SetRxNsStatus(chan, NS);
  601. VALIDATE;
  602. if (NS1)
  603. printf("\n Receive-side NS is now on! \n");
  604. else
  605. printf("\n Receive-side NS is now off! \n");
  606. }
  607. else if (codecinput == (noCodecs + 16)) {
  608. AgcModes agcmode;
  609. bool enable;
  610. res = apm->GetAgcStatus(enable, agcmode);
  611. VALIDATE
  612. printf("\n AGC enable is %d, mode is %d \n", enable, agcmode);
  613. }
  614. else if (codecinput == (noCodecs + 17)) {
  615. // Toggle Mute on Microphone
  616. res = volume->GetInputMute(chan, muted);
  617. VALIDATE;
  618. muted = !muted;
  619. res = volume->SetInputMute(chan, muted);
  620. VALIDATE;
  621. if (muted)
  622. printf("\n Microphone is now on mute! \n");
  623. else
  624. printf("\n Microphone is no longer on mute! \n");
  625. }
  626. else if (codecinput == (noCodecs + 18)) {
  627. // 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");
  639. }
  640. else if (codecinput == (noCodecs + 19)) {
  641. // Get the last error code and print to screen
  642. int err_code = 0;
  643. err_code = base1->LastError();
  644. if (err_code != -1)
  645. printf("\n The last error code was %i.\n", err_code);
  646. }
  647. else if (codecinput == (noCodecs + 20)) {
  648. typing_detection= !typing_detection;
  649. res = apm->SetTypingDetectionStatus(typing_detection);
  650. VALIDATE;
  651. if (typing_detection)
  652. printf("\n Typing detection is now on!\n");
  653. else
  654. printf("\n Typing detection is now off!\n");
  655. }
  656. else if (codecinput == (noCodecs + 21)) {
  657. int stop_record = 1;
  658. int file_source = 1;
  659. printf("\n Select source of recorded file. ");
  660. printf("\n 1. Record from microphone to file ");
  661. printf("\n 2. Record from playout to file ");
  662. printf("\n Enter your selection: \n");
  663. ASSERT_EQ(1, scanf("%i", &file_source));
  664. if (file_source == 1) {
  665. printf("\n Start recording microphone as %s \n",
  666. mic_filename.c_str());
  667. res = file->StartRecordingMicrophone(mic_filename.c_str());
  668. VALIDATE;
  669. }
  670. else {
  671. printf("\n Start recording playout as %s \n", play_filename.c_str());
  672. res = file->StartRecordingPlayout(chan, play_filename.c_str());
  673. VALIDATE;
  674. }
  675. while (stop_record != 0) {
  676. printf("\n Type 0 to stop recording file \n");
  677. ASSERT_EQ(1, scanf("%i", &stop_record));
  678. }
  679. if (file_source == 1) {
  680. res = file->StopRecordingMicrophone();
  681. VALIDATE;
  682. }
  683. else {
  684. res = file->StopRecordingPlayout(chan);
  685. VALIDATE;
  686. }
  687. printf("\n File finished recording \n");
  688. }
  689. else if (codecinput == (noCodecs + 22)) {
  690. int file_type = 1;
  691. int stop_play = 1;
  692. printf("\n Select a file to play locally in a loop.");
  693. printf("\n 1. Play %s", mic_filename.c_str());
  694. printf("\n 2. Play %s", play_filename.c_str());
  695. printf("\n Enter your selection\n");
  696. ASSERT_EQ(1, scanf("%i", &file_type));
  697. if (file_type == 1) {
  698. printf("\n Start playing %s locally in a loop\n",
  699. mic_filename.c_str());
  700. res = file->StartPlayingFileLocally(chan, mic_filename.c_str(), true);
  701. VALIDATE;
  702. }
  703. else {
  704. printf("\n Start playing %s locally in a loop\n",
  705. play_filename.c_str());
  706. res = file->StartPlayingFileLocally(chan, play_filename.c_str(),
  707. true);
  708. VALIDATE;
  709. }
  710. while (stop_play != 0) {
  711. printf("\n Type 0 to stop playing file\n");
  712. ASSERT_EQ(1, scanf("%i", &stop_play));
  713. }
  714. res = file->StopPlayingFileLocally(chan);
  715. VALIDATE;
  716. }
  717. else if (codecinput == (noCodecs + 23)) {
  718. int file_type = 1;
  719. int stop_play = 1;
  720. printf("\n Select a file to play as microphone in a loop.");
  721. printf("\n 1. Play %s", mic_filename.c_str());
  722. printf("\n 2. Play %s", play_filename.c_str());
  723. printf("\n Enter your selection\n");
  724. ASSERT_EQ(1, scanf("%i", &file_type));
  725. if (file_type == 1) {
  726. printf("\n Start playing %s as mic in a loop\n",
  727. mic_filename.c_str());
  728. res = file->StartPlayingFileAsMicrophone(chan, mic_filename.c_str(),
  729. true);
  730. VALIDATE;
  731. }
  732. else {
  733. printf("\n Start playing %s as mic in a loop\n",
  734. play_filename.c_str());
  735. res = file->StartPlayingFileAsMicrophone(chan, play_filename.c_str(),
  736. true);
  737. VALIDATE;
  738. }
  739. while (stop_play != 0) {
  740. printf("\n Type 0 to stop playing file\n");
  741. ASSERT_EQ(1, scanf("%i", &stop_play));
  742. }
  743. res = file->StopPlayingFileAsMicrophone(chan);
  744. VALIDATE;
  745. }
  746. else if (codecinput == (noCodecs + 24)) {
  747. if (channel_index < kMaxNumChannels) {
  748. res = base1->StartReceive(channels[channel_index]);
  749. VALIDATE;
  750. res = base1->StartPlayout(channels[channel_index]);
  751. VALIDATE;
  752. res = base1->StartSend(channels[channel_index]);
  753. VALIDATE;
  754. res = file->StartPlayingFileAsMicrophone(channels[channel_index],
  755. audio_filename.c_str(),
  756. true,
  757. false);
  758. VALIDATE;
  759. channel_index++;
  760. printf("Using %d additional channels\n", channel_index);
  761. } else {
  762. printf("Max number of channels reached\n");
  763. }
  764. }
  765. else if (codecinput == (noCodecs + 25)) {
  766. if (channel_index > 0) {
  767. channel_index--;
  768. res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
  769. VALIDATE;
  770. res = base1->StopSend(channels[channel_index]);
  771. VALIDATE;
  772. res = base1->StopPlayout(channels[channel_index]);
  773. VALIDATE;
  774. res = base1->StopReceive(channels[channel_index]);
  775. VALIDATE;
  776. printf("Using %d additional channels\n", channel_index);
  777. } else {
  778. printf("All additional channels stopped\n");
  779. }
  780. }
  781. else
  782. break;
  783. }
  784. if (send) {
  785. printf("Stop Send \n");
  786. res = base1->StopSend(chan);
  787. VALIDATE;
  788. }
  789. if (receive) {
  790. printf("Stop Playout \n");
  791. res = base1->StopPlayout(chan);
  792. VALIDATE;
  793. #ifndef EXTERNAL_TRANSPORT
  794. printf("Stop Listen \n");
  795. res = base1->StopReceive(chan);
  796. VALIDATE;
  797. #endif
  798. }
  799. while (channel_index > 0) {
  800. --channel_index;
  801. res = file->StopPlayingFileAsMicrophone(channels[channel_index]);
  802. VALIDATE;
  803. res = base1->StopSend(channels[channel_index]);
  804. VALIDATE;
  805. res = base1->StopPlayout(channels[channel_index]);
  806. VALIDATE;
  807. res = base1->StopReceive(channels[channel_index]);
  808. VALIDATE;
  809. }
  810. printf("\n1. New call \n");
  811. printf("2. Quit \n");
  812. printf("Select action: ");
  813. ASSERT_EQ(1, scanf("%i", &i));
  814. newcall = (1 == i);
  815. // Call loop
  816. }
  817. printf("Delete channels \n");
  818. res = base1->DeleteChannel(chan);
  819. VALIDATE;
  820. for (i = 0; i < kMaxNumChannels; ++i) {
  821. channels[i] = base1->DeleteChannel(channels[i]);
  822. VALIDATE;
  823. }
  824. }