PageRenderTime 63ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc

https://bitbucket.org/bohlooli/webrtc
C++ | 1729 lines | 1476 code | 182 blank | 71 comment | 184 complexity | 6cf6978a8687dc3d1c1498530e41cd78 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  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 <climits>
  11. #include <cstdarg>
  12. #include <cstdio>
  13. #include <algorithm>
  14. #include "video_engine/test/auto_test/interface/vie_autotest.h"
  15. #include "video_engine/test/auto_test/interface/vie_autotest_defines.h"
  16. #include "video_engine/test/auto_test/primitives/choice_helpers.h"
  17. #include "video_engine/test/auto_test/primitives/input_helpers.h"
  18. #define VCM_RED_PAYLOAD_TYPE 96
  19. #define VCM_ULPFEC_PAYLOAD_TYPE 97
  20. #define DEFAULT_SEND_IP "127.0.0.1"
  21. #define DEFAULT_VIDEO_PORT "11111"
  22. #define DEFAULT_VIDEO_CODEC "VP8"
  23. #define DEFAULT_VIDEO_CODEC_WIDTH "640"
  24. #define DEFAULT_VIDEO_CODEC_HEIGHT "480"
  25. #define DEFAULT_VIDEO_CODEC_BITRATE "300"
  26. #define DEFAULT_VIDEO_CODEC_MIN_BITRATE "100"
  27. #define DEFAULT_VIDEO_CODEC_MAX_BITRATE "1000"
  28. #define DEFAULT_AUDIO_PORT "11113"
  29. #define DEFAULT_AUDIO_CODEC "ISAC"
  30. #define DEFAULT_INCOMING_FILE_NAME "IncomingFile.avi"
  31. #define DEFAULT_OUTGOING_FILE_NAME "OutgoingFile.avi"
  32. #define DEFAULT_VIDEO_CODEC_MAX_FRAMERATE "30"
  33. #define DEFAULT_VIDEO_PROTECTION_METHOD "None"
  34. #define DEFAULT_TEMPORAL_LAYER "0"
  35. enum StatisticsType {
  36. kSendStatistic,
  37. kReceivedStatistic
  38. };
  39. enum VideoProtectionMethod {
  40. kProtectionMethodNone = 1,
  41. kProtectionMethodFecOnly,
  42. kProtectionMethodNackOnly,
  43. kProtectionMethodHybridNackAndFec,
  44. };
  45. using webrtc::FromChoices;
  46. using webrtc::TypedInput;
  47. class ViEAutotestFileObserver : public webrtc::ViEFileObserver {
  48. public:
  49. ViEAutotestFileObserver() {}
  50. ~ViEAutotestFileObserver() {}
  51. void PlayFileEnded(const WebRtc_Word32 file_id) {
  52. ViETest::Log("PlayFile ended");
  53. }
  54. };
  55. class ViEAutotestEncoderObserver : public webrtc::ViEEncoderObserver {
  56. public:
  57. ViEAutotestEncoderObserver() {}
  58. ~ViEAutotestEncoderObserver() {}
  59. void OutgoingRate(const int video_channel,
  60. const unsigned int framerate,
  61. const unsigned int bitrate) {
  62. std::cout << "Send FR: " << framerate
  63. << " BR: " << bitrate << std::endl;
  64. }
  65. };
  66. class ViEAutotestDecoderObserver : public webrtc::ViEDecoderObserver {
  67. public:
  68. ViEAutotestDecoderObserver() {}
  69. ~ViEAutotestDecoderObserver() {}
  70. void IncomingRate(const int video_channel,
  71. const unsigned int framerate,
  72. const unsigned int bitrate) {
  73. std::cout << "Received FR: " << framerate
  74. << " BR: " << bitrate << std::endl;
  75. }
  76. void IncomingCodecChanged(const int video_channel,
  77. const webrtc::VideoCodec& codec) {}
  78. void RequestNewKeyFrame(const int video_channel) {
  79. std::cout << "Decoder requesting a new key frame." << std::endl;
  80. }
  81. };
  82. // The following are general helper functions.
  83. bool GetVideoDevice(webrtc::ViEBase* vie_base,
  84. webrtc::ViECapture* vie_capture,
  85. char* capture_device_name, char* capture_device_unique_id);
  86. std::string GetIPAddress();
  87. bool ValidateIP(std::string i_str);
  88. // The following are Print to stdout functions.
  89. void PrintCallInformation(const char* IP,
  90. const char* video_capture_device_name,
  91. const char* video_capture_unique_id,
  92. webrtc::VideoCodec video_codec,
  93. int video_tx_port,
  94. int video_rx_port,
  95. const char* audio_capture_device_name,
  96. const char* audio_playbackDeviceName,
  97. webrtc::CodecInst audio_codec,
  98. int audio_tx_port,
  99. int audio_rx_port,
  100. int protection_method);
  101. void PrintRTCCPStatistics(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
  102. int video_channel,
  103. StatisticsType stat_type);
  104. void PrintRTPStatistics(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
  105. int video_channel);
  106. void PrintBandwidthUsage(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
  107. int video_channel);
  108. void PrintCodecStatistics(webrtc::ViECodec* vie_codec,
  109. int video_channel,
  110. StatisticsType stat_type);
  111. void PrintGetDiscardedPackets(webrtc::ViECodec* vie_codec,
  112. int video_channel);
  113. void PrintVideoStreamInformation(webrtc::ViECodec* vie_codec,
  114. int video_channel);
  115. void PrintVideoCodec(webrtc::VideoCodec video_codec);
  116. // The following are video functions.
  117. void GetVideoPorts(int* tx_port, int* rx_port);
  118. void SetVideoCodecType(webrtc::ViECodec* vie_codec,
  119. webrtc::VideoCodec* video_codec);
  120. void SetVideoCodecResolution(webrtc::VideoCodec* video_codec);
  121. void SetVideoCodecSize(webrtc::VideoCodec* video_codec);
  122. void SetVideoCodecBitrate(webrtc::VideoCodec* video_codec);
  123. void SetVideoCodecMinBitrate(webrtc::VideoCodec* video_codec);
  124. void SetVideoCodecMaxBitrate(webrtc::VideoCodec* video_codec);
  125. void SetVideoCodecMaxFramerate(webrtc::VideoCodec* video_codec);
  126. void SetVideoCodecTemporalLayer(webrtc::VideoCodec* video_codec);
  127. VideoProtectionMethod GetVideoProtection();
  128. bool SetVideoProtection(webrtc::ViECodec* vie_codec,
  129. webrtc::ViERTP_RTCP* vie_rtp_rtcp,
  130. int video_channel,
  131. VideoProtectionMethod protection_method);
  132. bool GetBitrateSignaling();
  133. // The following are audio helper functions.
  134. bool GetAudioDevices(webrtc::VoEBase* voe_base,
  135. webrtc::VoEHardware* voe_hardware,
  136. char* recording_device_name, int& recording_device_index,
  137. char* playback_device_name, int& playback_device_index);
  138. bool GetAudioDevices(webrtc::VoEBase* voe_base,
  139. webrtc::VoEHardware* voe_hardware,
  140. int& recording_device_index, int& playback_device_index);
  141. void GetAudioPorts(int* tx_port, int* rx_port);
  142. bool GetAudioCodec(webrtc::VoECodec* voe_codec,
  143. webrtc::CodecInst& audio_codec);
  144. int ViEAutoTest::ViECustomCall() {
  145. ViETest::Log(" ");
  146. ViETest::Log("========================================");
  147. ViETest::Log(" Enter values to use custom settings\n");
  148. int error = 0;
  149. int number_of_errors = 0;
  150. std::string str;
  151. // Create the VoE and get the VoE interfaces.
  152. webrtc::VoiceEngine* voe = webrtc::VoiceEngine::Create();
  153. number_of_errors += ViETest::TestError(voe != NULL, "ERROR: %s at line %d",
  154. __FUNCTION__, __LINE__);
  155. webrtc::VoEBase* voe_base = webrtc::VoEBase::GetInterface(voe);
  156. number_of_errors += ViETest::TestError(voe_base != NULL,
  157. "ERROR: %s at line %d", __FUNCTION__,
  158. __LINE__);
  159. error = voe_base->Init();
  160. number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
  161. __FUNCTION__, __LINE__);
  162. webrtc::VoECodec* voe_codec = webrtc::VoECodec::GetInterface(voe);
  163. number_of_errors += ViETest::TestError(voe_codec != NULL,
  164. "ERROR: %s at line %d", __FUNCTION__,
  165. __LINE__);
  166. webrtc::VoEHardware* voe_hardware =
  167. webrtc::VoEHardware::GetInterface(voe);
  168. number_of_errors += ViETest::TestError(voe_hardware != NULL,
  169. "ERROR: %s at line %d", __FUNCTION__,
  170. __LINE__);
  171. webrtc::VoEAudioProcessing* voe_apm =
  172. webrtc::VoEAudioProcessing::GetInterface(voe);
  173. number_of_errors += ViETest::TestError(voe_apm != NULL,
  174. "ERROR: %s at line %d", __FUNCTION__,
  175. __LINE__);
  176. // Create the ViE and get the ViE Interfaces.
  177. webrtc::VideoEngine* vie = webrtc::VideoEngine::Create();
  178. number_of_errors += ViETest::TestError(vie != NULL,
  179. "ERROR: %s at line %d", __FUNCTION__,
  180. __LINE__);
  181. webrtc::ViEBase* vie_base = webrtc::ViEBase::GetInterface(vie);
  182. number_of_errors += ViETest::TestError(vie_base != NULL,
  183. "ERROR: %s at line %d", __FUNCTION__,
  184. __LINE__);
  185. error = vie_base->Init();
  186. number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
  187. __FUNCTION__, __LINE__);
  188. webrtc::ViECapture* vie_capture =
  189. webrtc::ViECapture::GetInterface(vie);
  190. number_of_errors += ViETest::TestError(vie_capture != NULL,
  191. "ERROR: %s at line %d", __FUNCTION__,
  192. __LINE__);
  193. webrtc::ViERender* vie_renderer = webrtc::ViERender::GetInterface(vie);
  194. number_of_errors += ViETest::TestError(vie_renderer != NULL,
  195. "ERROR: %s at line %d", __FUNCTION__,
  196. __LINE__);
  197. webrtc::ViECodec* vie_codec = webrtc::ViECodec::GetInterface(vie);
  198. number_of_errors += ViETest::TestError(vie_codec != NULL,
  199. "ERROR: %s at line %d", __FUNCTION__,
  200. __LINE__);
  201. webrtc::ViENetwork* vie_network = webrtc::ViENetwork::GetInterface(vie);
  202. number_of_errors += ViETest::TestError(vie_network != NULL,
  203. "ERROR: %s at line %d", __FUNCTION__,
  204. __LINE__);
  205. webrtc::ViEFile* vie_file = webrtc::ViEFile::GetInterface(vie);
  206. number_of_errors += ViETest::TestError(vie_file != NULL,
  207. "ERROR: %s at line %d", __FUNCTION__,
  208. __LINE__);
  209. bool start_call = false;
  210. std::string ip_address;
  211. const unsigned int KMaxUniqueIdLength = 256;
  212. char unique_id[KMaxUniqueIdLength] = "";
  213. char device_name[KMaxUniqueIdLength] = "";
  214. int video_tx_port = 0;
  215. int video_rx_port = 0;
  216. int video_channel = -1;
  217. webrtc::VideoCodec video_send_codec;
  218. char audio_capture_device_name[KMaxUniqueIdLength] = "";
  219. char audio_playbackDeviceName[KMaxUniqueIdLength] = "";
  220. int audio_capture_device_index = -1;
  221. int audio_playback_device_index = -1;
  222. int audio_tx_port = 0;
  223. int audio_rx_port = 0;
  224. webrtc::CodecInst audio_codec;
  225. int audio_channel = -1;
  226. VideoProtectionMethod protection_method = kProtectionMethodNone;
  227. bool is_image_scale_enabled = false;
  228. bool remb = true;
  229. while (!start_call) {
  230. // Get the IP address to use from call.
  231. ip_address = GetIPAddress();
  232. // Get the video device to use for call.
  233. memset(device_name, 0, KMaxUniqueIdLength);
  234. memset(unique_id, 0, KMaxUniqueIdLength);
  235. if (!GetVideoDevice(vie_base, vie_capture, device_name, unique_id))
  236. return number_of_errors;
  237. // Get and set the video ports for the call.
  238. video_tx_port = 0;
  239. video_rx_port = 0;
  240. GetVideoPorts(&video_tx_port, &video_rx_port);
  241. // Get and set the video codec parameters for the call.
  242. memset(&video_send_codec, 0, sizeof(webrtc::VideoCodec));
  243. SetVideoCodecType(vie_codec, &video_send_codec);
  244. SetVideoCodecSize(&video_send_codec);
  245. SetVideoCodecBitrate(&video_send_codec);
  246. SetVideoCodecMinBitrate(&video_send_codec);
  247. SetVideoCodecMaxBitrate(&video_send_codec);
  248. SetVideoCodecMaxFramerate(&video_send_codec);
  249. SetVideoCodecTemporalLayer(&video_send_codec);
  250. remb = GetBitrateSignaling();
  251. // Get the video protection method for the call.
  252. protection_method = GetVideoProtection();
  253. // Get the audio device for the call.
  254. memset(audio_capture_device_name, 0, KMaxUniqueIdLength);
  255. memset(audio_playbackDeviceName, 0, KMaxUniqueIdLength);
  256. GetAudioDevices(voe_base, voe_hardware, audio_capture_device_name,
  257. audio_capture_device_index, audio_playbackDeviceName,
  258. audio_playback_device_index);
  259. // Get the audio port for the call.
  260. audio_tx_port = 0;
  261. audio_rx_port = 0;
  262. GetAudioPorts(&audio_tx_port, &audio_rx_port);
  263. // Get the audio codec for the call.
  264. memset(static_cast<void*>(&audio_codec), 0, sizeof(audio_codec));
  265. GetAudioCodec(voe_codec, audio_codec);
  266. // Now ready to start the call. Check user wants to continue.
  267. PrintCallInformation(ip_address.c_str(), device_name, unique_id,
  268. video_send_codec, video_tx_port, video_rx_port,
  269. audio_capture_device_name, audio_playbackDeviceName,
  270. audio_codec, audio_tx_port, audio_rx_port,
  271. protection_method);
  272. printf("\n");
  273. int selection =
  274. FromChoices("Ready to start:",
  275. "Start the call\n"
  276. "Reconfigure call settings\n")
  277. .WithDefault("Start the call").Choose();
  278. start_call = (selection == 1);
  279. }
  280. /// **************************************************************
  281. // Begin create/initialize WebRTC Video Engine for testing.
  282. /// **************************************************************
  283. if (start_call == true) {
  284. // Configure audio channel first.
  285. audio_channel = voe_base->CreateChannel();
  286. error = voe_base->SetSendDestination(audio_channel, audio_tx_port,
  287. ip_address.c_str());
  288. number_of_errors += ViETest::TestError(error == 0,
  289. "ERROR: %s at line %d",
  290. __FUNCTION__, __LINE__);
  291. error = voe_base->SetLocalReceiver(audio_channel, audio_rx_port);
  292. number_of_errors += ViETest::TestError(error == 0,
  293. "ERROR: %s at line %d",
  294. __FUNCTION__, __LINE__);
  295. error = voe_hardware->SetRecordingDevice(audio_capture_device_index);
  296. number_of_errors += ViETest::TestError(error == 0,
  297. "ERROR: %s at line %d",
  298. __FUNCTION__, __LINE__);
  299. error = voe_hardware->SetPlayoutDevice(audio_playback_device_index);
  300. number_of_errors += ViETest::TestError(error == 0,
  301. "ERROR: %s at line %d",
  302. __FUNCTION__, __LINE__);
  303. error = voe_codec->SetSendCodec(audio_channel, audio_codec);
  304. number_of_errors += ViETest::TestError(error == 0,
  305. "ERROR: %s at line %d",
  306. __FUNCTION__, __LINE__);
  307. error = voe_apm->SetAgcStatus(true, webrtc::kAgcDefault);
  308. number_of_errors += ViETest::TestError(error == 0,
  309. "ERROR: %s at line %d",
  310. __FUNCTION__, __LINE__);
  311. error = voe_apm->SetNsStatus(true, webrtc::kNsHighSuppression);
  312. number_of_errors += ViETest::TestError(error == 0,
  313. "ERROR: %s at line %d",
  314. __FUNCTION__, __LINE__);
  315. // Now configure the video channel.
  316. error = vie->SetTraceFilter(webrtc::kTraceAll);
  317. number_of_errors += ViETest::TestError(error == 0,
  318. "ERROR: %s at line %d",
  319. __FUNCTION__, __LINE__);
  320. std::string trace_file =
  321. ViETest::GetResultOutputPath() + "ViECustomCall_trace.txt";
  322. error = vie->SetTraceFile(trace_file.c_str());
  323. number_of_errors += ViETest::TestError(error == 0,
  324. "ERROR: %s at line %d",
  325. __FUNCTION__, __LINE__);
  326. error = vie_base->SetVoiceEngine(voe);
  327. number_of_errors += ViETest::TestError(error == 0,
  328. "ERROR: %s at line %d",
  329. __FUNCTION__, __LINE__);
  330. error = vie_base->CreateChannel(video_channel);
  331. number_of_errors += ViETest::TestError(error == 0,
  332. "ERROR: %s at line %d",
  333. __FUNCTION__, __LINE__);
  334. error = vie_base->ConnectAudioChannel(video_channel, audio_channel);
  335. number_of_errors += ViETest::TestError(error == 0,
  336. "ERROR: %s at line %d",
  337. __FUNCTION__, __LINE__);
  338. int capture_id = 0;
  339. error = vie_capture->AllocateCaptureDevice(unique_id,
  340. KMaxUniqueIdLength,
  341. capture_id);
  342. number_of_errors += ViETest::TestError(error == 0,
  343. "ERROR: %s at line %d",
  344. __FUNCTION__, __LINE__);
  345. error = vie_capture->ConnectCaptureDevice(capture_id, video_channel);
  346. number_of_errors += ViETest::TestError(error == 0,
  347. "ERROR: %s at line %d",
  348. __FUNCTION__, __LINE__);
  349. error = vie_capture->StartCapture(capture_id);
  350. number_of_errors += ViETest::TestError(error == 0,
  351. "ERROR: %s at line %d",
  352. __FUNCTION__, __LINE__);
  353. webrtc::ViERTP_RTCP* vie_rtp_rtcp =
  354. webrtc::ViERTP_RTCP::GetInterface(vie);
  355. number_of_errors += ViETest::TestError(vie != NULL,
  356. "ERROR: %s at line %d",
  357. __FUNCTION__, __LINE__);
  358. error = vie_rtp_rtcp->SetRTCPStatus(video_channel,
  359. webrtc::kRtcpCompound_RFC4585);
  360. number_of_errors += ViETest::TestError(error == 0,
  361. "ERROR: %s at line %d",
  362. __FUNCTION__, __LINE__);
  363. error = vie_rtp_rtcp->SetKeyFrameRequestMethod(
  364. video_channel, webrtc::kViEKeyFrameRequestPliRtcp);
  365. number_of_errors += ViETest::TestError(error == 0,
  366. "ERROR: %s at line %d",
  367. __FUNCTION__, __LINE__);
  368. if (remb) {
  369. error = vie_rtp_rtcp->SetRembStatus(video_channel, true, true);
  370. number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
  371. __FUNCTION__, __LINE__);
  372. } else {
  373. error = vie_rtp_rtcp->SetTMMBRStatus(video_channel, true);
  374. number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
  375. __FUNCTION__, __LINE__);
  376. }
  377. error = vie_renderer->AddRenderer(capture_id, _window1, 0, 0.0, 0.0, 1.0,
  378. 1.0);
  379. number_of_errors += ViETest::TestError(error == 0,
  380. "ERROR: %s at line %d",
  381. __FUNCTION__, __LINE__);
  382. error = vie_renderer->AddRenderer(video_channel, _window2, 1, 0.0, 0.0, 1.0,
  383. 1.0);
  384. number_of_errors += ViETest::TestError(error == 0,
  385. "ERROR: %s at line %d",
  386. __FUNCTION__, __LINE__);
  387. error = vie_network->SetSendDestination(video_channel, ip_address.c_str(),
  388. video_tx_port);
  389. number_of_errors += ViETest::TestError(error == 0,
  390. "ERROR: %s at line %d",
  391. __FUNCTION__, __LINE__);
  392. error = vie_network->SetLocalReceiver(video_channel, video_rx_port);
  393. number_of_errors += ViETest::TestError(error == 0,
  394. "ERROR: %s at line %d",
  395. __FUNCTION__, __LINE__);
  396. error = vie_codec->SetSendCodec(video_channel, video_send_codec);
  397. number_of_errors += ViETest::TestError(error == 0,
  398. "ERROR: %s at line %d",
  399. __FUNCTION__, __LINE__);
  400. error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
  401. number_of_errors += ViETest::TestError(error == 0,
  402. "ERROR: %s at line %d",
  403. __FUNCTION__, __LINE__);
  404. // Set the Video Protection before start send and receive.
  405. SetVideoProtection(vie_codec, vie_rtp_rtcp,
  406. video_channel, protection_method);
  407. // Start Voice Playout and Receive.
  408. error = voe_base->StartReceive(audio_channel);
  409. number_of_errors += ViETest::TestError(error == 0,
  410. "ERROR: %s at line %d",
  411. __FUNCTION__, __LINE__);
  412. error = voe_base->StartPlayout(audio_channel);
  413. number_of_errors += ViETest::TestError(error == 0,
  414. "ERROR: %s at line %d",
  415. __FUNCTION__, __LINE__);
  416. error = voe_base->StartSend(audio_channel);
  417. number_of_errors += ViETest::TestError(error == 0,
  418. "ERROR: %s at line %d",
  419. __FUNCTION__, __LINE__);
  420. // Now start the Video Send & Receive.
  421. error = vie_base->StartSend(video_channel);
  422. number_of_errors += ViETest::TestError(error == 0,
  423. "ERROR: %s at line %d",
  424. __FUNCTION__, __LINE__);
  425. error = vie_base->StartReceive(video_channel);
  426. number_of_errors += ViETest::TestError(error == 0,
  427. "ERROR: %s at line %d",
  428. __FUNCTION__, __LINE__);
  429. error = vie_renderer->StartRender(capture_id);
  430. number_of_errors += ViETest::TestError(error == 0,
  431. "ERROR: %s at line %d",
  432. __FUNCTION__, __LINE__);
  433. error = vie_renderer->StartRender(video_channel);
  434. number_of_errors += ViETest::TestError(error == 0,
  435. "ERROR: %s at line %d",
  436. __FUNCTION__, __LINE__);
  437. ViEAutotestFileObserver file_observer;
  438. int file_id;
  439. ViEAutotestEncoderObserver* codec_encoder_observer = NULL;
  440. ViEAutotestDecoderObserver* codec_decoder_observer = NULL;
  441. // Engine ready, wait for input.
  442. // Call started.
  443. std::cout << std::endl;
  444. std::cout << "Custom call started" << std::endl;
  445. // Modify call or stop call.
  446. printf("\n");
  447. int selection = FromChoices(
  448. "And now?",
  449. "Stop the call\n"
  450. "Modify the call\n").Choose();
  451. int file_selection = 0;
  452. while (selection == 2) {
  453. // Keep on modifying the call until user stops the call.
  454. int modify_selection = FromChoices(
  455. "Modify the call:",
  456. "Stop call\n"
  457. "Change Video Send Codec\n"
  458. "Change Video Send Size by Common Resolutions\n"
  459. "Change Video Send Size by Width & Height\n"
  460. "Change Video Capture Device\n"
  461. "Record Incoming Call\n"
  462. "Record Outgoing Call\n"
  463. "Play File on Video Channel "
  464. "(Assumes you recorded incoming & outgoing call)\n"
  465. "Change Video Protection Method\n"
  466. "Toggle Encoder Observer\n"
  467. "Toggle Decoder Observer\n"
  468. "Print Call Information\n"
  469. "Print Call Statistics\n"
  470. "Toggle Image Scaling (Warning: high CPU usage when enabled)\n")
  471. .WithDefault("Stop call")
  472. .Choose();
  473. switch (modify_selection) {
  474. case 1:
  475. selection = 1;
  476. break;
  477. case 2:
  478. // Change video codec.
  479. SetVideoCodecType(vie_codec, &video_send_codec);
  480. SetVideoCodecSize(&video_send_codec);
  481. SetVideoCodecBitrate(&video_send_codec);
  482. SetVideoCodecMinBitrate(&video_send_codec);
  483. SetVideoCodecMaxBitrate(&video_send_codec);
  484. SetVideoCodecMaxFramerate(&video_send_codec);
  485. SetVideoCodecTemporalLayer(&video_send_codec);
  486. PrintCallInformation(ip_address.c_str(), device_name,
  487. unique_id, video_send_codec,
  488. video_tx_port, video_rx_port,
  489. audio_capture_device_name,
  490. audio_playbackDeviceName, audio_codec,
  491. audio_tx_port, audio_rx_port, protection_method);
  492. error = vie_codec->SetSendCodec(video_channel, video_send_codec);
  493. number_of_errors += ViETest::TestError(error == 0,
  494. "ERROR: %s at line %d",
  495. __FUNCTION__, __LINE__);
  496. error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
  497. number_of_errors += ViETest::TestError(error == 0,
  498. "ERROR: %s at line %d",
  499. __FUNCTION__, __LINE__);
  500. break;
  501. case 3:
  502. // Change Video codec size by common resolution.
  503. SetVideoCodecResolution(&video_send_codec);
  504. PrintCallInformation(ip_address.c_str(), device_name,
  505. unique_id, video_send_codec,
  506. video_tx_port, video_rx_port,
  507. audio_capture_device_name,
  508. audio_playbackDeviceName, audio_codec,
  509. audio_tx_port, audio_rx_port, protection_method);
  510. error = vie_codec->SetSendCodec(video_channel, video_send_codec);
  511. number_of_errors += ViETest::TestError(error == 0,
  512. "ERROR: %s at line %d",
  513. __FUNCTION__, __LINE__);
  514. error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
  515. number_of_errors += ViETest::TestError(error == 0,
  516. "ERROR: %s at line %d",
  517. __FUNCTION__, __LINE__);
  518. break;
  519. case 4:
  520. // Change video codec by size height and width.
  521. SetVideoCodecSize(&video_send_codec);
  522. PrintCallInformation(ip_address.c_str(), device_name,
  523. unique_id, video_send_codec,
  524. video_tx_port, video_rx_port,
  525. audio_capture_device_name,
  526. audio_playbackDeviceName, audio_codec,
  527. audio_tx_port, audio_rx_port, protection_method);
  528. error = vie_codec->SetSendCodec(video_channel, video_send_codec);
  529. number_of_errors += ViETest::TestError(error == 0,
  530. "ERROR: %s at line %d",
  531. __FUNCTION__, __LINE__);
  532. error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
  533. number_of_errors += ViETest::TestError(error == 0,
  534. "ERROR: %s at line %d",
  535. __FUNCTION__, __LINE__);
  536. break;
  537. case 5:
  538. error = vie_renderer->StopRender(capture_id);
  539. number_of_errors += ViETest::TestError(error == 0,
  540. "ERROR: %s at line %d",
  541. __FUNCTION__, __LINE__);
  542. error = vie_renderer->RemoveRenderer(capture_id);
  543. number_of_errors += ViETest::TestError(error == 0,
  544. "ERROR: %s at line %d",
  545. __FUNCTION__, __LINE__);
  546. error = vie_capture->StopCapture(capture_id);
  547. number_of_errors += ViETest::TestError(error == 0,
  548. "ERROR: %s at line %d",
  549. __FUNCTION__, __LINE__);
  550. error = vie_capture->DisconnectCaptureDevice(video_channel);
  551. number_of_errors += ViETest::TestError(error == 0,
  552. "ERROR: %s at line %d",
  553. __FUNCTION__, __LINE__);
  554. error = vie_capture->ReleaseCaptureDevice(capture_id);
  555. number_of_errors += ViETest::TestError(error == 0,
  556. "ERROR: %s at line %d",
  557. __FUNCTION__, __LINE__);
  558. memset(device_name, 0, KMaxUniqueIdLength);
  559. memset(unique_id, 0, KMaxUniqueIdLength);
  560. if (!GetVideoDevice(vie_base, vie_capture, device_name, unique_id))
  561. return number_of_errors;
  562. capture_id = 0;
  563. error = vie_capture->AllocateCaptureDevice(unique_id,
  564. KMaxUniqueIdLength,
  565. capture_id);
  566. number_of_errors += ViETest::TestError(error == 0,
  567. "ERROR: %s at line %d",
  568. __FUNCTION__, __LINE__);
  569. error = vie_capture->ConnectCaptureDevice(capture_id,
  570. video_channel);
  571. number_of_errors += ViETest::TestError(error == 0,
  572. "ERROR: %s at line %d",
  573. __FUNCTION__, __LINE__);
  574. error = vie_capture->StartCapture(capture_id);
  575. number_of_errors += ViETest::TestError(error == 0,
  576. "ERROR: %s at line %d",
  577. __FUNCTION__, __LINE__);
  578. error = vie_renderer->AddRenderer(capture_id, _window1, 0, 0.0, 0.0,
  579. 1.0, 1.0);
  580. number_of_errors += ViETest::TestError(error == 0,
  581. "ERROR: %s at line %d",
  582. __FUNCTION__, __LINE__);
  583. error = vie_renderer->StartRender(capture_id);
  584. number_of_errors += ViETest::TestError(error == 0,
  585. "ERROR: %s at line %d",
  586. __FUNCTION__, __LINE__);
  587. break;
  588. case 6:
  589. // Record the incoming call.
  590. std::cout << "Start Recording Incoming Video "
  591. << DEFAULT_INCOMING_FILE_NAME << std::endl;
  592. error = vie_file->StartRecordIncomingVideo(
  593. video_channel, DEFAULT_INCOMING_FILE_NAME,
  594. webrtc::NO_AUDIO, audio_codec, video_send_codec);
  595. std::cout << "Press enter to stop...";
  596. std::getline(std::cin, str);
  597. error = vie_file->StopRecordIncomingVideo(video_channel);
  598. number_of_errors += ViETest::TestError(error == 0,
  599. "ERROR:%d %s at line %d",
  600. vie_base->LastError(),
  601. __FUNCTION__, __LINE__);
  602. break;
  603. case 7:
  604. // Record the outgoing call.
  605. std::cout << "Start Recording Outgoing Video "
  606. << DEFAULT_OUTGOING_FILE_NAME << std::endl;
  607. error = vie_file->StartRecordOutgoingVideo(
  608. video_channel, DEFAULT_OUTGOING_FILE_NAME,
  609. webrtc::NO_AUDIO, audio_codec, video_send_codec);
  610. std::cout << "Press enter to stop...";
  611. std::getline(std::cin, str);
  612. error = vie_file->StopRecordOutgoingVideo(video_channel);
  613. number_of_errors += ViETest::TestError(error == 0,
  614. "ERROR:%d %s at line %d",
  615. vie_base->LastError(),
  616. __FUNCTION__, __LINE__);
  617. break;
  618. case 8:
  619. // Send the file on the video_channel.
  620. file_selection = FromChoices(
  621. "Choose a file name:",
  622. DEFAULT_INCOMING_FILE_NAME "\n"
  623. DEFAULT_OUTGOING_FILE_NAME "\n")
  624. .WithDefault(DEFAULT_INCOMING_FILE_NAME).Choose();
  625. // Disconnect the camera first.
  626. error = vie_capture->DisconnectCaptureDevice(video_channel);
  627. number_of_errors += ViETest::TestError(error == 0,
  628. "ERROR:%d %s at line %d",
  629. vie_base->LastError(),
  630. __FUNCTION__, __LINE__);
  631. if (file_selection == 2)
  632. error = vie_file->StartPlayFile(DEFAULT_OUTGOING_FILE_NAME,
  633. file_id, true);
  634. else
  635. error = vie_file->StartPlayFile(DEFAULT_INCOMING_FILE_NAME,
  636. file_id, true);
  637. number_of_errors += ViETest::TestError(error == 0,
  638. "ERROR:%d %s at line %d",
  639. vie_base->LastError(),
  640. __FUNCTION__, __LINE__);
  641. ViETest::Log("Registering file observer");
  642. error = vie_file->RegisterObserver(file_id, file_observer);
  643. number_of_errors += ViETest::TestError(error == 0,
  644. "ERROR:%d %s at line %d",
  645. vie_base->LastError(),
  646. __FUNCTION__, __LINE__);
  647. std::cout << std::endl;
  648. std::cout << "Start sending the file that is played in a loop "
  649. << std::endl;
  650. error = vie_file->SendFileOnChannel(file_id, video_channel);
  651. number_of_errors += ViETest::TestError(error == 0,
  652. "ERROR:%d %s at line %d",
  653. vie_base->LastError(),
  654. __FUNCTION__, __LINE__);
  655. std::cout << "Press enter to stop...";
  656. std::getline(std::cin, str);
  657. ViETest::Log("Stopped sending video on channel");
  658. error = vie_file->StopSendFileOnChannel(video_channel);
  659. number_of_errors += ViETest::TestError(error == 0,
  660. "ERROR:%d %s at line %d",
  661. vie_base->LastError(),
  662. __FUNCTION__, __LINE__);
  663. ViETest::Log("Stop playing the file.");
  664. error = vie_file->StopPlayFile(file_id);
  665. number_of_errors += ViETest::TestError(error == 0,
  666. "ERROR:%d %s at line %d",
  667. vie_base->LastError(),
  668. __FUNCTION__, __LINE__);
  669. error = vie_capture->ConnectCaptureDevice(capture_id,
  670. video_channel);
  671. number_of_errors += ViETest::TestError(error == 0,
  672. "ERROR:%d %s at line %d",
  673. vie_base->LastError(),
  674. __FUNCTION__, __LINE__);
  675. error = vie_file->DeregisterObserver(file_id, file_observer);
  676. number_of_errors += ViETest::TestError(error == -1,
  677. "ERROR:%d %s at line %d",
  678. vie_base->LastError(),
  679. __FUNCTION__, __LINE__);
  680. break;
  681. case 9:
  682. // Change the Video Protection.
  683. protection_method = GetVideoProtection();
  684. SetVideoProtection(vie_codec, vie_rtp_rtcp,
  685. video_channel, protection_method);
  686. break;
  687. case 10:
  688. // Toggle Encoder Observer.
  689. if (!codec_encoder_observer) {
  690. std::cout << "Registering Encoder Observer" << std::endl;
  691. codec_encoder_observer = new ViEAutotestEncoderObserver();
  692. error = vie_codec->RegisterEncoderObserver(video_channel,
  693. *codec_encoder_observer);
  694. number_of_errors += ViETest::TestError(error == 0,
  695. "ERROR: %s at line %d",
  696. __FUNCTION__, __LINE__);
  697. } else {
  698. std::cout << "Deregistering Encoder Observer" << std::endl;
  699. error = vie_codec->DeregisterEncoderObserver(video_channel);
  700. delete codec_encoder_observer;
  701. codec_encoder_observer = NULL;
  702. number_of_errors += ViETest::TestError(error == 0,
  703. "ERROR: %s at line %d",
  704. __FUNCTION__, __LINE__);
  705. }
  706. break;
  707. case 11:
  708. // Toggle Decoder Observer.
  709. if (!codec_decoder_observer) {
  710. std::cout << "Registering Decoder Observer" << std::endl;
  711. codec_decoder_observer = new ViEAutotestDecoderObserver();
  712. error = vie_codec->RegisterDecoderObserver(video_channel,
  713. *codec_decoder_observer);
  714. number_of_errors += ViETest::TestError(error == 0,
  715. "ERROR: %s at line %d",
  716. __FUNCTION__, __LINE__);
  717. } else {
  718. std::cout << "Deregistering Decoder Observer" << std::endl;
  719. error = vie_codec->DeregisterDecoderObserver(video_channel);
  720. delete codec_decoder_observer;
  721. codec_decoder_observer = NULL;
  722. number_of_errors += ViETest::TestError(error == 0,
  723. "ERROR: %s at line %d",
  724. __FUNCTION__, __LINE__);
  725. }
  726. break;
  727. case 12:
  728. // Print Call information..
  729. PrintCallInformation(ip_address.c_str(), device_name,
  730. unique_id, video_send_codec,
  731. video_tx_port, video_rx_port,
  732. audio_capture_device_name,
  733. audio_playbackDeviceName,
  734. audio_codec, audio_tx_port,
  735. audio_rx_port, protection_method);
  736. PrintVideoStreamInformation(vie_codec,
  737. video_channel);
  738. break;
  739. case 13:
  740. // Print Call statistics.
  741. PrintRTCCPStatistics(vie_rtp_rtcp, video_channel,
  742. kSendStatistic);
  743. PrintRTCCPStatistics(vie_rtp_rtcp, video_channel,
  744. kReceivedStatistic);
  745. PrintRTPStatistics(vie_rtp_rtcp, video_channel);
  746. PrintBandwidthUsage(vie_rtp_rtcp, video_channel);
  747. PrintCodecStatistics(vie_codec, video_channel,
  748. kSendStatistic);
  749. PrintCodecStatistics(vie_codec, video_channel,
  750. kReceivedStatistic);
  751. PrintGetDiscardedPackets(vie_codec, video_channel);
  752. break;
  753. case 14:
  754. is_image_scale_enabled = !is_image_scale_enabled;
  755. vie_codec->SetImageScaleStatus(video_channel, is_image_scale_enabled);
  756. if (is_image_scale_enabled) {
  757. std::cout << "Image Scale is now enabled" << std::endl;
  758. } else {
  759. std::cout << "Image Scale is now disabled" << std::endl;
  760. }
  761. break;
  762. default:
  763. assert(false);
  764. break;
  765. }
  766. }
  767. // Testing finished. Tear down Voice and Video Engine.
  768. // Tear down the VoE first.
  769. error = voe_base->StopReceive(audio_channel);
  770. number_of_errors += ViETest::TestError(error == 0,
  771. "ERROR: %s at line %d",
  772. __FUNCTION__, __LINE__);
  773. error = voe_base->StopPlayout(audio_channel);
  774. number_of_errors += ViETest::TestError(error == 0,
  775. "ERROR: %s at line %d",
  776. __FUNCTION__, __LINE__);
  777. error = voe_base->DeleteChannel(audio_channel);
  778. number_of_errors += ViETest::TestError(error == 0,
  779. "ERROR: %s at line %d",
  780. __FUNCTION__, __LINE__);
  781. // Now tear down the ViE engine.
  782. error = vie_base->DisconnectAudioChannel(video_channel);
  783. // If Encoder/Decoder Observer is running, delete them.
  784. if (codec_encoder_observer) {
  785. error = vie_codec->DeregisterEncoderObserver(video_channel);
  786. delete codec_encoder_observer;
  787. number_of_errors += ViETest::TestError(error == 0,
  788. "ERROR: %s at line %d",
  789. __FUNCTION__, __LINE__);
  790. }
  791. if (codec_decoder_observer) {
  792. error = vie_codec->DeregisterDecoderObserver(video_channel);
  793. delete codec_decoder_observer;
  794. number_of_errors += ViETest::TestError(error == 0,
  795. "ERROR: %s at line %d",
  796. __FUNCTION__, __LINE__);
  797. }
  798. error = vie_base->StopReceive(video_channel);
  799. number_of_errors += ViETest::TestError(error == 0,
  800. "ERROR: %s at line %d",
  801. __FUNCTION__, __LINE__);
  802. error = vie_base->StopSend(video_channel);
  803. number_of_errors += ViETest::TestError(error == 0,
  804. "ERROR: %s at line %d",
  805. __FUNCTION__, __LINE__);
  806. error = vie_renderer->StopRender(capture_id);
  807. number_of_errors += ViETest::TestError(error == 0,
  808. "ERROR: %s at line %d",
  809. __FUNCTION__, __LINE__);
  810. error = vie_renderer->StopRender(video_channel);
  811. number_of_errors += ViETest::TestError(error == 0,
  812. "ERROR: %s at line %d",
  813. __FUNCTION__, __LINE__);
  814. error = vie_renderer->RemoveRenderer(capture_id);
  815. number_of_errors += ViETest::TestError(error == 0,
  816. "ERROR: %s at line %d",
  817. __FUNCTION__, __LINE__);
  818. error = vie_renderer->RemoveRenderer(video_channel);
  819. number_of_errors += ViETest::TestError(error == 0,
  820. "ERROR: %s at line %d",
  821. __FUNCTION__, __LINE__);
  822. error = vie_capture->StopCapture(capture_id);
  823. number_of_errors += ViETest::TestError(error == 0,
  824. "ERROR: %s at line %d",
  825. __FUNCTION__, __LINE__);
  826. error = vie_capture->DisconnectCaptureDevice(video_channel);
  827. number_of_errors += ViETest::TestError(error == 0,
  828. "ERROR: %s at line %d",
  829. __FUNCTION__, __LINE__);
  830. error = vie_capture->ReleaseCaptureDevice(capture_id);
  831. number_of_errors += ViETest::TestError(error == 0,
  832. "ERROR: %s at line %d",
  833. __FUNCTION__, __LINE__);
  834. error = vie_base->DeleteChannel(video_channel);
  835. number_of_errors += ViETest::TestError(error == 0,
  836. "ERROR: %s at line %d",
  837. __FUNCTION__, __LINE__);
  838. int remaining_interfaces = 0;
  839. remaining_interfaces = vie_file->Release();
  840. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  841. "ERROR: %s at line %d",
  842. __FUNCTION__, __LINE__);
  843. remaining_interfaces = vie_codec->Release();
  844. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  845. "ERROR: %s at line %d",
  846. __FUNCTION__, __LINE__);
  847. remaining_interfaces = vie_capture->Release();
  848. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  849. "ERROR: %s at line %d",
  850. __FUNCTION__, __LINE__);
  851. remaining_interfaces = vie_rtp_rtcp->Release();
  852. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  853. "ERROR: %s at line %d",
  854. __FUNCTION__, __LINE__);
  855. remaining_interfaces = vie_renderer->Release();
  856. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  857. "ERROR: %s at line %d",
  858. __FUNCTION__, __LINE__);
  859. remaining_interfaces = vie_network->Release();
  860. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  861. "ERROR: %s at line %d",
  862. __FUNCTION__, __LINE__);
  863. remaining_interfaces = vie_base->Release();
  864. number_of_errors += ViETest::TestError(remaining_interfaces == 0,
  865. "ERROR: %s at line %d",
  866. __FUNCTION__, __LINE__);
  867. bool deleted = webrtc::VideoEngine::Delete(vie);
  868. number_of_errors += ViETest::TestError(deleted == true,
  869. "ERROR: %s at line %d",
  870. __FUNCTION__, __LINE__);
  871. ViETest::Log(" ");
  872. ViETest::Log(" ViE Autotest Custom Call Started");
  873. ViETest::Log("========================================");
  874. ViETest::Log(" ");
  875. }
  876. return number_of_errors;
  877. }
  878. bool GetVideoDevice(webrtc::ViEBase* vie_base,
  879. webrtc::ViECapture* vie_capture,
  880. char* capture_device_name,
  881. char* capture_device_unique_id) {
  882. int error = 0;
  883. int number_of_errors = 0;
  884. const unsigned int KMaxDeviceNameLength = 128;
  885. const unsigned int KMaxUniqueIdLength = 256;
  886. char device_name[KMaxDeviceNameLength];
  887. char unique_id[KMaxUniqueIdLength];
  888. if (vie_capture->NumberOfCaptureDevices() == 0) {
  889. printf("You have no capture devices plugged into your system.\n");
  890. return false;
  891. }
  892. std::string capture_choices;
  893. std::string first_device;
  894. for (int i = 0; i < vie_capture->NumberOfCaptureDevices(); i++) {
  895. memset(device_name, 0, KMaxDeviceNameLength);
  896. memset(unique_id, 0, KMaxUniqueIdLength);
  897. error = vie_capture->GetCaptureDevice(i, device_name,
  898. KMaxDeviceNameLength,
  899. unique_id,
  900. KMaxUniqueIdLength);
  901. number_of_errors += ViETest::TestError(error == 0,
  902. "ERROR: %s at line %d",
  903. __FUNCTION__, __LINE__);
  904. const int kCaptureLineLength =
  905. KMaxDeviceNameLength + KMaxUniqueIdLength + 8;
  906. char capture_line[kCaptureLineLength];
  907. sprintf(capture_line, "%s (%s)", device_name, unique_id);
  908. capture_choices += capture_line;
  909. capture_choices += "\n";
  910. if (first_device.empty())
  911. first_device = capture_line;
  912. }
  913. int choice = FromChoices("Available Video Capture Devices", capture_choices)
  914. .WithDefault(first_device)
  915. .Choose();
  916. error = vie_capture->GetCaptureDevice(
  917. choice - 1, device_name, KMaxDeviceNameLength, unique_id,
  918. KMaxUniqueIdLength);
  919. number_of_errors += ViETest::TestError(error == 0,
  920. "ERROR: %s at line %d",
  921. __FUNCTION__, __LINE__);
  922. strcpy(capture_device_unique_id, unique_id);
  923. strcpy(capture_device_name, device_name);
  924. return true;
  925. }
  926. bool GetAudioDevices(webrtc::VoEBase* voe_base,
  927. webrtc::VoEHardware* voe_hardware,
  928. char* recording_device_name,
  929. int& recording_device_index,
  930. char* playback_device_name,
  931. int& playback_device_index) {
  932. int error = 0;
  933. int number_of_errors = 0;
  934. const unsigned int KMaxDeviceNameLength = 128;
  935. const unsigned int KMaxUniqueIdLength = 128;
  936. char recording_device_uniqu

Large files files are truncated, but you can click here to view the full file