PageRenderTime 64ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/CSipSimple/jni/webrtc/sources/voice_engine/main/test/cmd_test/voe_cmd_test.cc

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