/webrtc/video_engine/test/auto_test/source/vie_autotest_custom_call.cc
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
- /*
- * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
- #include <climits>
- #include <cstdarg>
- #include <cstdio>
- #include <algorithm>
- #include "video_engine/test/auto_test/interface/vie_autotest.h"
- #include "video_engine/test/auto_test/interface/vie_autotest_defines.h"
- #include "video_engine/test/auto_test/primitives/choice_helpers.h"
- #include "video_engine/test/auto_test/primitives/input_helpers.h"
- #define VCM_RED_PAYLOAD_TYPE 96
- #define VCM_ULPFEC_PAYLOAD_TYPE 97
- #define DEFAULT_SEND_IP "127.0.0.1"
- #define DEFAULT_VIDEO_PORT "11111"
- #define DEFAULT_VIDEO_CODEC "VP8"
- #define DEFAULT_VIDEO_CODEC_WIDTH "640"
- #define DEFAULT_VIDEO_CODEC_HEIGHT "480"
- #define DEFAULT_VIDEO_CODEC_BITRATE "300"
- #define DEFAULT_VIDEO_CODEC_MIN_BITRATE "100"
- #define DEFAULT_VIDEO_CODEC_MAX_BITRATE "1000"
- #define DEFAULT_AUDIO_PORT "11113"
- #define DEFAULT_AUDIO_CODEC "ISAC"
- #define DEFAULT_INCOMING_FILE_NAME "IncomingFile.avi"
- #define DEFAULT_OUTGOING_FILE_NAME "OutgoingFile.avi"
- #define DEFAULT_VIDEO_CODEC_MAX_FRAMERATE "30"
- #define DEFAULT_VIDEO_PROTECTION_METHOD "None"
- #define DEFAULT_TEMPORAL_LAYER "0"
- enum StatisticsType {
- kSendStatistic,
- kReceivedStatistic
- };
- enum VideoProtectionMethod {
- kProtectionMethodNone = 1,
- kProtectionMethodFecOnly,
- kProtectionMethodNackOnly,
- kProtectionMethodHybridNackAndFec,
- };
- using webrtc::FromChoices;
- using webrtc::TypedInput;
- class ViEAutotestFileObserver : public webrtc::ViEFileObserver {
- public:
- ViEAutotestFileObserver() {}
- ~ViEAutotestFileObserver() {}
- void PlayFileEnded(const WebRtc_Word32 file_id) {
- ViETest::Log("PlayFile ended");
- }
- };
- class ViEAutotestEncoderObserver : public webrtc::ViEEncoderObserver {
- public:
- ViEAutotestEncoderObserver() {}
- ~ViEAutotestEncoderObserver() {}
- void OutgoingRate(const int video_channel,
- const unsigned int framerate,
- const unsigned int bitrate) {
- std::cout << "Send FR: " << framerate
- << " BR: " << bitrate << std::endl;
- }
- };
- class ViEAutotestDecoderObserver : public webrtc::ViEDecoderObserver {
- public:
- ViEAutotestDecoderObserver() {}
- ~ViEAutotestDecoderObserver() {}
- void IncomingRate(const int video_channel,
- const unsigned int framerate,
- const unsigned int bitrate) {
- std::cout << "Received FR: " << framerate
- << " BR: " << bitrate << std::endl;
- }
- void IncomingCodecChanged(const int video_channel,
- const webrtc::VideoCodec& codec) {}
- void RequestNewKeyFrame(const int video_channel) {
- std::cout << "Decoder requesting a new key frame." << std::endl;
- }
- };
- // The following are general helper functions.
- bool GetVideoDevice(webrtc::ViEBase* vie_base,
- webrtc::ViECapture* vie_capture,
- char* capture_device_name, char* capture_device_unique_id);
- std::string GetIPAddress();
- bool ValidateIP(std::string i_str);
- // The following are Print to stdout functions.
- void PrintCallInformation(const char* IP,
- const char* video_capture_device_name,
- const char* video_capture_unique_id,
- webrtc::VideoCodec video_codec,
- int video_tx_port,
- int video_rx_port,
- const char* audio_capture_device_name,
- const char* audio_playbackDeviceName,
- webrtc::CodecInst audio_codec,
- int audio_tx_port,
- int audio_rx_port,
- int protection_method);
- void PrintRTCCPStatistics(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
- int video_channel,
- StatisticsType stat_type);
- void PrintRTPStatistics(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
- int video_channel);
- void PrintBandwidthUsage(webrtc::ViERTP_RTCP* vie_rtp_rtcp,
- int video_channel);
- void PrintCodecStatistics(webrtc::ViECodec* vie_codec,
- int video_channel,
- StatisticsType stat_type);
- void PrintGetDiscardedPackets(webrtc::ViECodec* vie_codec,
- int video_channel);
- void PrintVideoStreamInformation(webrtc::ViECodec* vie_codec,
- int video_channel);
- void PrintVideoCodec(webrtc::VideoCodec video_codec);
- // The following are video functions.
- void GetVideoPorts(int* tx_port, int* rx_port);
- void SetVideoCodecType(webrtc::ViECodec* vie_codec,
- webrtc::VideoCodec* video_codec);
- void SetVideoCodecResolution(webrtc::VideoCodec* video_codec);
- void SetVideoCodecSize(webrtc::VideoCodec* video_codec);
- void SetVideoCodecBitrate(webrtc::VideoCodec* video_codec);
- void SetVideoCodecMinBitrate(webrtc::VideoCodec* video_codec);
- void SetVideoCodecMaxBitrate(webrtc::VideoCodec* video_codec);
- void SetVideoCodecMaxFramerate(webrtc::VideoCodec* video_codec);
- void SetVideoCodecTemporalLayer(webrtc::VideoCodec* video_codec);
- VideoProtectionMethod GetVideoProtection();
- bool SetVideoProtection(webrtc::ViECodec* vie_codec,
- webrtc::ViERTP_RTCP* vie_rtp_rtcp,
- int video_channel,
- VideoProtectionMethod protection_method);
- bool GetBitrateSignaling();
- // The following are audio helper functions.
- bool GetAudioDevices(webrtc::VoEBase* voe_base,
- webrtc::VoEHardware* voe_hardware,
- char* recording_device_name, int& recording_device_index,
- char* playback_device_name, int& playback_device_index);
- bool GetAudioDevices(webrtc::VoEBase* voe_base,
- webrtc::VoEHardware* voe_hardware,
- int& recording_device_index, int& playback_device_index);
- void GetAudioPorts(int* tx_port, int* rx_port);
- bool GetAudioCodec(webrtc::VoECodec* voe_codec,
- webrtc::CodecInst& audio_codec);
- int ViEAutoTest::ViECustomCall() {
- ViETest::Log(" ");
- ViETest::Log("========================================");
- ViETest::Log(" Enter values to use custom settings\n");
- int error = 0;
- int number_of_errors = 0;
- std::string str;
- // Create the VoE and get the VoE interfaces.
- webrtc::VoiceEngine* voe = webrtc::VoiceEngine::Create();
- number_of_errors += ViETest::TestError(voe != NULL, "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- webrtc::VoEBase* voe_base = webrtc::VoEBase::GetInterface(voe);
- number_of_errors += ViETest::TestError(voe_base != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- error = voe_base->Init();
- number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- webrtc::VoECodec* voe_codec = webrtc::VoECodec::GetInterface(voe);
- number_of_errors += ViETest::TestError(voe_codec != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::VoEHardware* voe_hardware =
- webrtc::VoEHardware::GetInterface(voe);
- number_of_errors += ViETest::TestError(voe_hardware != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::VoEAudioProcessing* voe_apm =
- webrtc::VoEAudioProcessing::GetInterface(voe);
- number_of_errors += ViETest::TestError(voe_apm != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- // Create the ViE and get the ViE Interfaces.
- webrtc::VideoEngine* vie = webrtc::VideoEngine::Create();
- number_of_errors += ViETest::TestError(vie != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::ViEBase* vie_base = webrtc::ViEBase::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_base != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- error = vie_base->Init();
- number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- webrtc::ViECapture* vie_capture =
- webrtc::ViECapture::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_capture != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::ViERender* vie_renderer = webrtc::ViERender::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_renderer != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::ViECodec* vie_codec = webrtc::ViECodec::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_codec != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::ViENetwork* vie_network = webrtc::ViENetwork::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_network != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- webrtc::ViEFile* vie_file = webrtc::ViEFile::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie_file != NULL,
- "ERROR: %s at line %d", __FUNCTION__,
- __LINE__);
- bool start_call = false;
- std::string ip_address;
- const unsigned int KMaxUniqueIdLength = 256;
- char unique_id[KMaxUniqueIdLength] = "";
- char device_name[KMaxUniqueIdLength] = "";
- int video_tx_port = 0;
- int video_rx_port = 0;
- int video_channel = -1;
- webrtc::VideoCodec video_send_codec;
- char audio_capture_device_name[KMaxUniqueIdLength] = "";
- char audio_playbackDeviceName[KMaxUniqueIdLength] = "";
- int audio_capture_device_index = -1;
- int audio_playback_device_index = -1;
- int audio_tx_port = 0;
- int audio_rx_port = 0;
- webrtc::CodecInst audio_codec;
- int audio_channel = -1;
- VideoProtectionMethod protection_method = kProtectionMethodNone;
- bool is_image_scale_enabled = false;
- bool remb = true;
- while (!start_call) {
- // Get the IP address to use from call.
- ip_address = GetIPAddress();
- // Get the video device to use for call.
- memset(device_name, 0, KMaxUniqueIdLength);
- memset(unique_id, 0, KMaxUniqueIdLength);
- if (!GetVideoDevice(vie_base, vie_capture, device_name, unique_id))
- return number_of_errors;
- // Get and set the video ports for the call.
- video_tx_port = 0;
- video_rx_port = 0;
- GetVideoPorts(&video_tx_port, &video_rx_port);
- // Get and set the video codec parameters for the call.
- memset(&video_send_codec, 0, sizeof(webrtc::VideoCodec));
- SetVideoCodecType(vie_codec, &video_send_codec);
- SetVideoCodecSize(&video_send_codec);
- SetVideoCodecBitrate(&video_send_codec);
- SetVideoCodecMinBitrate(&video_send_codec);
- SetVideoCodecMaxBitrate(&video_send_codec);
- SetVideoCodecMaxFramerate(&video_send_codec);
- SetVideoCodecTemporalLayer(&video_send_codec);
- remb = GetBitrateSignaling();
- // Get the video protection method for the call.
- protection_method = GetVideoProtection();
- // Get the audio device for the call.
- memset(audio_capture_device_name, 0, KMaxUniqueIdLength);
- memset(audio_playbackDeviceName, 0, KMaxUniqueIdLength);
- GetAudioDevices(voe_base, voe_hardware, audio_capture_device_name,
- audio_capture_device_index, audio_playbackDeviceName,
- audio_playback_device_index);
- // Get the audio port for the call.
- audio_tx_port = 0;
- audio_rx_port = 0;
- GetAudioPorts(&audio_tx_port, &audio_rx_port);
- // Get the audio codec for the call.
- memset(static_cast<void*>(&audio_codec), 0, sizeof(audio_codec));
- GetAudioCodec(voe_codec, audio_codec);
- // Now ready to start the call. Check user wants to continue.
- PrintCallInformation(ip_address.c_str(), device_name, unique_id,
- video_send_codec, video_tx_port, video_rx_port,
- audio_capture_device_name, audio_playbackDeviceName,
- audio_codec, audio_tx_port, audio_rx_port,
- protection_method);
- printf("\n");
- int selection =
- FromChoices("Ready to start:",
- "Start the call\n"
- "Reconfigure call settings\n")
- .WithDefault("Start the call").Choose();
- start_call = (selection == 1);
- }
- /// **************************************************************
- // Begin create/initialize WebRTC Video Engine for testing.
- /// **************************************************************
- if (start_call == true) {
- // Configure audio channel first.
- audio_channel = voe_base->CreateChannel();
- error = voe_base->SetSendDestination(audio_channel, audio_tx_port,
- ip_address.c_str());
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_base->SetLocalReceiver(audio_channel, audio_rx_port);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_hardware->SetRecordingDevice(audio_capture_device_index);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_hardware->SetPlayoutDevice(audio_playback_device_index);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_codec->SetSendCodec(audio_channel, audio_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_apm->SetAgcStatus(true, webrtc::kAgcDefault);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_apm->SetNsStatus(true, webrtc::kNsHighSuppression);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- // Now configure the video channel.
- error = vie->SetTraceFilter(webrtc::kTraceAll);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- std::string trace_file =
- ViETest::GetResultOutputPath() + "ViECustomCall_trace.txt";
- error = vie->SetTraceFile(trace_file.c_str());
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->SetVoiceEngine(voe);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->CreateChannel(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->ConnectAudioChannel(video_channel, audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- int capture_id = 0;
- error = vie_capture->AllocateCaptureDevice(unique_id,
- KMaxUniqueIdLength,
- capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->ConnectCaptureDevice(capture_id, video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->StartCapture(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- webrtc::ViERTP_RTCP* vie_rtp_rtcp =
- webrtc::ViERTP_RTCP::GetInterface(vie);
- number_of_errors += ViETest::TestError(vie != NULL,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_rtp_rtcp->SetRTCPStatus(video_channel,
- webrtc::kRtcpCompound_RFC4585);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_rtp_rtcp->SetKeyFrameRequestMethod(
- video_channel, webrtc::kViEKeyFrameRequestPliRtcp);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- if (remb) {
- error = vie_rtp_rtcp->SetRembStatus(video_channel, true, true);
- number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- } else {
- error = vie_rtp_rtcp->SetTMMBRStatus(video_channel, true);
- number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- }
- error = vie_renderer->AddRenderer(capture_id, _window1, 0, 0.0, 0.0, 1.0,
- 1.0);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->AddRenderer(video_channel, _window2, 1, 0.0, 0.0, 1.0,
- 1.0);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_network->SetSendDestination(video_channel, ip_address.c_str(),
- video_tx_port);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_network->SetLocalReceiver(video_channel, video_rx_port);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_codec->SetSendCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- // Set the Video Protection before start send and receive.
- SetVideoProtection(vie_codec, vie_rtp_rtcp,
- video_channel, protection_method);
- // Start Voice Playout and Receive.
- error = voe_base->StartReceive(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_base->StartPlayout(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_base->StartSend(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- // Now start the Video Send & Receive.
- error = vie_base->StartSend(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->StartReceive(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->StartRender(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->StartRender(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- ViEAutotestFileObserver file_observer;
- int file_id;
- ViEAutotestEncoderObserver* codec_encoder_observer = NULL;
- ViEAutotestDecoderObserver* codec_decoder_observer = NULL;
- // Engine ready, wait for input.
- // Call started.
- std::cout << std::endl;
- std::cout << "Custom call started" << std::endl;
- // Modify call or stop call.
- printf("\n");
- int selection = FromChoices(
- "And now?",
- "Stop the call\n"
- "Modify the call\n").Choose();
- int file_selection = 0;
- while (selection == 2) {
- // Keep on modifying the call until user stops the call.
- int modify_selection = FromChoices(
- "Modify the call:",
- "Stop call\n"
- "Change Video Send Codec\n"
- "Change Video Send Size by Common Resolutions\n"
- "Change Video Send Size by Width & Height\n"
- "Change Video Capture Device\n"
- "Record Incoming Call\n"
- "Record Outgoing Call\n"
- "Play File on Video Channel "
- "(Assumes you recorded incoming & outgoing call)\n"
- "Change Video Protection Method\n"
- "Toggle Encoder Observer\n"
- "Toggle Decoder Observer\n"
- "Print Call Information\n"
- "Print Call Statistics\n"
- "Toggle Image Scaling (Warning: high CPU usage when enabled)\n")
- .WithDefault("Stop call")
- .Choose();
- switch (modify_selection) {
- case 1:
- selection = 1;
- break;
- case 2:
- // Change video codec.
- SetVideoCodecType(vie_codec, &video_send_codec);
- SetVideoCodecSize(&video_send_codec);
- SetVideoCodecBitrate(&video_send_codec);
- SetVideoCodecMinBitrate(&video_send_codec);
- SetVideoCodecMaxBitrate(&video_send_codec);
- SetVideoCodecMaxFramerate(&video_send_codec);
- SetVideoCodecTemporalLayer(&video_send_codec);
- PrintCallInformation(ip_address.c_str(), device_name,
- unique_id, video_send_codec,
- video_tx_port, video_rx_port,
- audio_capture_device_name,
- audio_playbackDeviceName, audio_codec,
- audio_tx_port, audio_rx_port, protection_method);
- error = vie_codec->SetSendCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- break;
- case 3:
- // Change Video codec size by common resolution.
- SetVideoCodecResolution(&video_send_codec);
- PrintCallInformation(ip_address.c_str(), device_name,
- unique_id, video_send_codec,
- video_tx_port, video_rx_port,
- audio_capture_device_name,
- audio_playbackDeviceName, audio_codec,
- audio_tx_port, audio_rx_port, protection_method);
- error = vie_codec->SetSendCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- break;
- case 4:
- // Change video codec by size height and width.
- SetVideoCodecSize(&video_send_codec);
- PrintCallInformation(ip_address.c_str(), device_name,
- unique_id, video_send_codec,
- video_tx_port, video_rx_port,
- audio_capture_device_name,
- audio_playbackDeviceName, audio_codec,
- audio_tx_port, audio_rx_port, protection_method);
- error = vie_codec->SetSendCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_codec->SetReceiveCodec(video_channel, video_send_codec);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- break;
- case 5:
- error = vie_renderer->StopRender(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->RemoveRenderer(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->StopCapture(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->DisconnectCaptureDevice(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->ReleaseCaptureDevice(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- memset(device_name, 0, KMaxUniqueIdLength);
- memset(unique_id, 0, KMaxUniqueIdLength);
- if (!GetVideoDevice(vie_base, vie_capture, device_name, unique_id))
- return number_of_errors;
- capture_id = 0;
- error = vie_capture->AllocateCaptureDevice(unique_id,
- KMaxUniqueIdLength,
- capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->ConnectCaptureDevice(capture_id,
- video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->StartCapture(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->AddRenderer(capture_id, _window1, 0, 0.0, 0.0,
- 1.0, 1.0);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->StartRender(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- break;
- case 6:
- // Record the incoming call.
- std::cout << "Start Recording Incoming Video "
- << DEFAULT_INCOMING_FILE_NAME << std::endl;
- error = vie_file->StartRecordIncomingVideo(
- video_channel, DEFAULT_INCOMING_FILE_NAME,
- webrtc::NO_AUDIO, audio_codec, video_send_codec);
- std::cout << "Press enter to stop...";
- std::getline(std::cin, str);
- error = vie_file->StopRecordIncomingVideo(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- break;
- case 7:
- // Record the outgoing call.
- std::cout << "Start Recording Outgoing Video "
- << DEFAULT_OUTGOING_FILE_NAME << std::endl;
- error = vie_file->StartRecordOutgoingVideo(
- video_channel, DEFAULT_OUTGOING_FILE_NAME,
- webrtc::NO_AUDIO, audio_codec, video_send_codec);
- std::cout << "Press enter to stop...";
- std::getline(std::cin, str);
- error = vie_file->StopRecordOutgoingVideo(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- break;
- case 8:
- // Send the file on the video_channel.
- file_selection = FromChoices(
- "Choose a file name:",
- DEFAULT_INCOMING_FILE_NAME "\n"
- DEFAULT_OUTGOING_FILE_NAME "\n")
- .WithDefault(DEFAULT_INCOMING_FILE_NAME).Choose();
- // Disconnect the camera first.
- error = vie_capture->DisconnectCaptureDevice(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- if (file_selection == 2)
- error = vie_file->StartPlayFile(DEFAULT_OUTGOING_FILE_NAME,
- file_id, true);
- else
- error = vie_file->StartPlayFile(DEFAULT_INCOMING_FILE_NAME,
- file_id, true);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- ViETest::Log("Registering file observer");
- error = vie_file->RegisterObserver(file_id, file_observer);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- std::cout << std::endl;
- std::cout << "Start sending the file that is played in a loop "
- << std::endl;
- error = vie_file->SendFileOnChannel(file_id, video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- std::cout << "Press enter to stop...";
- std::getline(std::cin, str);
- ViETest::Log("Stopped sending video on channel");
- error = vie_file->StopSendFileOnChannel(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- ViETest::Log("Stop playing the file.");
- error = vie_file->StopPlayFile(file_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- error = vie_capture->ConnectCaptureDevice(capture_id,
- video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- error = vie_file->DeregisterObserver(file_id, file_observer);
- number_of_errors += ViETest::TestError(error == -1,
- "ERROR:%d %s at line %d",
- vie_base->LastError(),
- __FUNCTION__, __LINE__);
- break;
- case 9:
- // Change the Video Protection.
- protection_method = GetVideoProtection();
- SetVideoProtection(vie_codec, vie_rtp_rtcp,
- video_channel, protection_method);
- break;
- case 10:
- // Toggle Encoder Observer.
- if (!codec_encoder_observer) {
- std::cout << "Registering Encoder Observer" << std::endl;
- codec_encoder_observer = new ViEAutotestEncoderObserver();
- error = vie_codec->RegisterEncoderObserver(video_channel,
- *codec_encoder_observer);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- } else {
- std::cout << "Deregistering Encoder Observer" << std::endl;
- error = vie_codec->DeregisterEncoderObserver(video_channel);
- delete codec_encoder_observer;
- codec_encoder_observer = NULL;
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- }
- break;
- case 11:
- // Toggle Decoder Observer.
- if (!codec_decoder_observer) {
- std::cout << "Registering Decoder Observer" << std::endl;
- codec_decoder_observer = new ViEAutotestDecoderObserver();
- error = vie_codec->RegisterDecoderObserver(video_channel,
- *codec_decoder_observer);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- } else {
- std::cout << "Deregistering Decoder Observer" << std::endl;
- error = vie_codec->DeregisterDecoderObserver(video_channel);
- delete codec_decoder_observer;
- codec_decoder_observer = NULL;
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- }
- break;
- case 12:
- // Print Call information..
- PrintCallInformation(ip_address.c_str(), device_name,
- unique_id, video_send_codec,
- video_tx_port, video_rx_port,
- audio_capture_device_name,
- audio_playbackDeviceName,
- audio_codec, audio_tx_port,
- audio_rx_port, protection_method);
- PrintVideoStreamInformation(vie_codec,
- video_channel);
- break;
- case 13:
- // Print Call statistics.
- PrintRTCCPStatistics(vie_rtp_rtcp, video_channel,
- kSendStatistic);
- PrintRTCCPStatistics(vie_rtp_rtcp, video_channel,
- kReceivedStatistic);
- PrintRTPStatistics(vie_rtp_rtcp, video_channel);
- PrintBandwidthUsage(vie_rtp_rtcp, video_channel);
- PrintCodecStatistics(vie_codec, video_channel,
- kSendStatistic);
- PrintCodecStatistics(vie_codec, video_channel,
- kReceivedStatistic);
- PrintGetDiscardedPackets(vie_codec, video_channel);
- break;
- case 14:
- is_image_scale_enabled = !is_image_scale_enabled;
- vie_codec->SetImageScaleStatus(video_channel, is_image_scale_enabled);
- if (is_image_scale_enabled) {
- std::cout << "Image Scale is now enabled" << std::endl;
- } else {
- std::cout << "Image Scale is now disabled" << std::endl;
- }
- break;
- default:
- assert(false);
- break;
- }
- }
- // Testing finished. Tear down Voice and Video Engine.
- // Tear down the VoE first.
- error = voe_base->StopReceive(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_base->StopPlayout(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = voe_base->DeleteChannel(audio_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- // Now tear down the ViE engine.
- error = vie_base->DisconnectAudioChannel(video_channel);
- // If Encoder/Decoder Observer is running, delete them.
- if (codec_encoder_observer) {
- error = vie_codec->DeregisterEncoderObserver(video_channel);
- delete codec_encoder_observer;
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- }
- if (codec_decoder_observer) {
- error = vie_codec->DeregisterDecoderObserver(video_channel);
- delete codec_decoder_observer;
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- }
- error = vie_base->StopReceive(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->StopSend(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->StopRender(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->StopRender(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->RemoveRenderer(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_renderer->RemoveRenderer(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->StopCapture(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->DisconnectCaptureDevice(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_capture->ReleaseCaptureDevice(capture_id);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- error = vie_base->DeleteChannel(video_channel);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- int remaining_interfaces = 0;
- remaining_interfaces = vie_file->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_codec->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_capture->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_rtp_rtcp->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_renderer->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_network->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- remaining_interfaces = vie_base->Release();
- number_of_errors += ViETest::TestError(remaining_interfaces == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- bool deleted = webrtc::VideoEngine::Delete(vie);
- number_of_errors += ViETest::TestError(deleted == true,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- ViETest::Log(" ");
- ViETest::Log(" ViE Autotest Custom Call Started");
- ViETest::Log("========================================");
- ViETest::Log(" ");
- }
- return number_of_errors;
- }
- bool GetVideoDevice(webrtc::ViEBase* vie_base,
- webrtc::ViECapture* vie_capture,
- char* capture_device_name,
- char* capture_device_unique_id) {
- int error = 0;
- int number_of_errors = 0;
- const unsigned int KMaxDeviceNameLength = 128;
- const unsigned int KMaxUniqueIdLength = 256;
- char device_name[KMaxDeviceNameLength];
- char unique_id[KMaxUniqueIdLength];
- if (vie_capture->NumberOfCaptureDevices() == 0) {
- printf("You have no capture devices plugged into your system.\n");
- return false;
- }
- std::string capture_choices;
- std::string first_device;
- for (int i = 0; i < vie_capture->NumberOfCaptureDevices(); i++) {
- memset(device_name, 0, KMaxDeviceNameLength);
- memset(unique_id, 0, KMaxUniqueIdLength);
- error = vie_capture->GetCaptureDevice(i, device_name,
- KMaxDeviceNameLength,
- unique_id,
- KMaxUniqueIdLength);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- const int kCaptureLineLength =
- KMaxDeviceNameLength + KMaxUniqueIdLength + 8;
- char capture_line[kCaptureLineLength];
- sprintf(capture_line, "%s (%s)", device_name, unique_id);
- capture_choices += capture_line;
- capture_choices += "\n";
- if (first_device.empty())
- first_device = capture_line;
- }
- int choice = FromChoices("Available Video Capture Devices", capture_choices)
- .WithDefault(first_device)
- .Choose();
- error = vie_capture->GetCaptureDevice(
- choice - 1, device_name, KMaxDeviceNameLength, unique_id,
- KMaxUniqueIdLength);
- number_of_errors += ViETest::TestError(error == 0,
- "ERROR: %s at line %d",
- __FUNCTION__, __LINE__);
- strcpy(capture_device_unique_id, unique_id);
- strcpy(capture_device_name, device_name);
- return true;
- }
- bool GetAudioDevices(webrtc::VoEBase* voe_base,
- webrtc::VoEHardware* voe_hardware,
- char* recording_device_name,
- int& recording_device_index,
- char* playback_device_name,
- int& playback_device_index) {
- int error = 0;
- int number_of_errors = 0;
- const unsigned int KMaxDeviceNameLength = 128;
- const unsigned int KMaxUniqueIdLength = 128;
- char recording_device_uniqu…
Large files files are truncated, but you can click here to view the full file