diff --git a/src/video_engine/test/auto_test/primitives/choice_helpers.cc b/src/video_engine/test/auto_test/primitives/choice_helpers.cc new file mode 100644 index 0000000000..ef4277bf80 --- /dev/null +++ b/src/video_engine/test/auto_test/primitives/choice_helpers.cc @@ -0,0 +1,95 @@ +/* + * 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 "video_engine/test/auto_test/primitives/choice_helpers.h" + +#include +#include + +namespace webrtc { + +static const int kNoDefault = 0; + +ChoiceBuilder::ChoiceBuilder(const Choices& choices) + : choices_(choices), default_choice_(kNoDefault), input_source_(stdin) { +} + +int ChoiceBuilder::Choose() { + if (!title_.empty()) { + printf("\n%s\n", title_.c_str()); + } + + Choices::const_iterator iterator = choices_.begin(); + for (int number = 1; iterator != choices_.end(); ++iterator, ++number) + printf(" %d. %s\n", number, (*iterator).c_str()); + + if (default_choice_ != kNoDefault) + printf(" Hit enter for default (%s):\n", default_choice_text_.c_str()); + printf("# "); + char input[8]; + fgets(input, 8, input_source_); + int selection; + if (input[0] == '\n') + selection = default_choice_; + else + selection = atoi(input); + + if (selection < 1 || selection > static_cast(choices_.size())) { + printf("Please select one of the given options.\n"); + return Choose(); + } + + return selection; +} + +ChoiceBuilder& ChoiceBuilder::WithDefault(const std::string& default_choice) { + Choices::const_iterator iterator = std::find( + choices_.begin(), choices_.end(), default_choice); + assert(iterator != choices_.end() && "No such choice."); + + // Store the value as the choice number, e.g. its index + 1. + default_choice_ = (iterator - choices_.begin()) + 1; + default_choice_text_ = default_choice; + return *this; +} + +ChoiceBuilder& ChoiceBuilder::WithInputSource(FILE* input_source) { + input_source_ = input_source; + return *this; +} + +ChoiceBuilder& ChoiceBuilder::WithTitle(const std::string& title) { + title_ = title; + return *this; +} + +Choices SplitChoices(const std::string& raw_choices) { + Choices result; + size_t current_pos = 0; + size_t next_newline = 0; + while ((next_newline = raw_choices.find('\n', current_pos)) != + std::string::npos) { + std::string choice = raw_choices.substr( + current_pos, next_newline - current_pos); + result.push_back(choice); + current_pos = next_newline + 1; + } + std::string last_choice = raw_choices.substr(current_pos); + if (!last_choice.empty()) + result.push_back(last_choice); + + return result; +} + +ChoiceBuilder FromChoices(const std::string& raw_choices) { + return ChoiceBuilder(SplitChoices(raw_choices)); +} + +} // namespace webrtc diff --git a/src/video_engine/test/auto_test/primitives/choice_helpers.h b/src/video_engine/test/auto_test/primitives/choice_helpers.h new file mode 100644 index 0000000000..25c26e1a12 --- /dev/null +++ b/src/video_engine/test/auto_test/primitives/choice_helpers.h @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#ifndef WEBRTC_VIDEO_ENGINE_TEST_AUTO_TEST_PRIMITIVES_CHOICE_HELPERS_H_ +#define WEBRTC_VIDEO_ENGINE_TEST_AUTO_TEST_PRIMITIVES_CHOICE_HELPERS_H_ + +#include +#include + +namespace webrtc { + +typedef std::vector Choices; + +/** + * Used to ask the user to make a choice. This class will allow you to + * configure how to ask the question, and then ask it. For instance, + * + * int choice = FromChoices("Choice 1\n" + * "Choice 2\n").WithDefault("Choice 1").Choose(); + * + * will print a menu presenting the two choices and ask for input. The user, + * can input 1, 2 or just hit enter since we specified a default in this case. + * The Choose call will block until the user gives valid input one way or the + * other. The choice variable is guaranteed to contain either 1 or 2 after + * this particular call. + * + * The class uses stdout and stdin by default, but stdin can be replaced using + * WithInputSource for unit tests. + */ +class ChoiceBuilder { + public: + explicit ChoiceBuilder(const Choices& choices); + + // Specifies the choice as the default. The choice must be one of the choices + // passed in the constructor. If this method is not called, the user has to + // choose an option explicitly. + ChoiceBuilder& WithDefault(const std::string& default_choice); + + // Replaces the input source where we ask for input. Default is stdin. + ChoiceBuilder& WithInputSource(FILE* input_source); + + // Prints a title above the choice list when the choice is made. + ChoiceBuilder& WithTitle(const std::string& title); + + // Prints the choice list and requests input from the input source. Returns + // the choice number (choices start at 1). + int Choose(); + + private: + Choices choices_; + int default_choice_; + std::string default_choice_text_; + std::string title_; + FILE* input_source_; +}; + +// Convenience function that creates a choice builder given a string where +// choices are separated by \n. +ChoiceBuilder FromChoices(const std::string& raw_choices); + +// Creates choices from a string where choices are separated by \n. +Choices SplitChoices(const std::string& raw_choices); + +} // namespace webrtc + +#endif // CHOICE_HELPERS_H_ diff --git a/src/video_engine/test/auto_test/primitives/choice_helpers_unittest.cc b/src/video_engine/test/auto_test/primitives/choice_helpers_unittest.cc new file mode 100644 index 0000000000..3c4d45c798 --- /dev/null +++ b/src/video_engine/test/auto_test/primitives/choice_helpers_unittest.cc @@ -0,0 +1,105 @@ +/* + * 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 + +#include "gtest/gtest.h" +#include "video_engine/test/auto_test/primitives/choice_helpers.h" + +namespace { + +FILE* FakeStdin(const std::string& input) { + FILE* fake_stdin = tmpfile(); + + EXPECT_EQ(input.size(), + fwrite(input.c_str(), sizeof(char), input.size(), fake_stdin)); + rewind(fake_stdin); + + return fake_stdin; +} + +} // namespace + + +namespace webrtc { + +class ChoiceHelpersTest : public testing::Test { +}; + +TEST_F(ChoiceHelpersTest, SplitReturnsEmptyChoicesForEmptyInput) { + EXPECT_TRUE(SplitChoices("").empty()); +} + +TEST_F(ChoiceHelpersTest, SplitHandlesSingleChoice) { + Choices choices = SplitChoices("Single Choice"); + EXPECT_EQ(1u, choices.size()); + EXPECT_EQ("Single Choice", choices[0]); +} + +TEST_F(ChoiceHelpersTest, SplitHandlesSingleChoiceWithEndingNewline) { + Choices choices = SplitChoices("Single Choice\n"); + EXPECT_EQ(1u, choices.size()); + EXPECT_EQ("Single Choice", choices[0]); +} + +TEST_F(ChoiceHelpersTest, SplitHandlesMultipleChoices) { + Choices choices = SplitChoices( + "Choice 1\n" + "Choice 2\n" + "Choice 3"); + EXPECT_EQ(3u, choices.size()); + EXPECT_EQ("Choice 1", choices[0]); + EXPECT_EQ("Choice 2", choices[1]); + EXPECT_EQ("Choice 3", choices[2]); +} + +TEST_F(ChoiceHelpersTest, SplitHandlesMultipleChoicesWithEndingNewline) { + Choices choices = SplitChoices( + "Choice 1\n" + "Choice 2\n" + "Choice 3\n"); + EXPECT_EQ(3u, choices.size()); + EXPECT_EQ("Choice 1", choices[0]); + EXPECT_EQ("Choice 2", choices[1]); + EXPECT_EQ("Choice 3", choices[2]); +} + +TEST_F(ChoiceHelpersTest, CanSelectUsingChoiceBuilder) { + FILE* fake_stdin = FakeStdin("1\n2\n"); + EXPECT_EQ(1, FromChoices("Choice 1\n" + "Choice 2").WithInputSource(fake_stdin).Choose()); + EXPECT_EQ(2, FromChoices("Choice 1\n" + "Choice 2").WithInputSource(fake_stdin).Choose()); + fclose(fake_stdin); +} + +TEST_F(ChoiceHelpersTest, RetriesIfGivenInvalidChoice) { + FILE* fake_stdin = FakeStdin("3\n0\n99\n23409234809\na\nwhatever\n1\n"); + EXPECT_EQ(1, FromChoices("Choice 1\n" + "Choice 2").WithInputSource(fake_stdin).Choose()); + fclose(fake_stdin); +} + +TEST_F(ChoiceHelpersTest, RetriesOnEnterIfNoDefaultSet) { + FILE* fake_stdin = FakeStdin("\n2\n"); + EXPECT_EQ(2, FromChoices("Choice 1\n" + "Choice 2").WithInputSource(fake_stdin).Choose()); + fclose(fake_stdin); +} + +TEST_F(ChoiceHelpersTest, PicksDefaultOnEnterIfDefaultSet) { + FILE* fake_stdin = FakeStdin("\n"); + EXPECT_EQ(2, FromChoices("Choice 1\n" + "Choice 2").WithInputSource(fake_stdin) + .WithDefault("Choice 2").Choose()); + fclose(fake_stdin); +} + +} // namespace webrtc diff --git a/src/video_engine/test/auto_test/source/vie_autotest_custom_call.cc b/src/video_engine/test/auto_test/source/vie_autotest_custom_call.cc index a0e991e72d..a36104fd2c 100644 --- a/src/video_engine/test/auto_test/source/vie_autotest_custom_call.cc +++ b/src/video_engine/test/auto_test/source/vie_autotest_custom_call.cc @@ -8,14 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #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" #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 "VP8" #define DEFAULT_VIDEO_CODEC_WIDTH 640 #define DEFAULT_VIDEO_CODEC_HEIGHT 480 #define DEFAULT_VIDEO_CODEC_BITRATE 300 @@ -26,7 +29,7 @@ #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 0 +#define DEFAULT_VIDEO_PROTECTION_METHOD "None" #define DEFAULT_TEMPORAL_LAYER 0 enum StatisticsType { @@ -34,6 +37,15 @@ enum StatisticsType { kReceivedStatistic }; +enum VideoProtectionMethod { + kProtectionMethodNone = 1, + kProtectionMethodFecOnly, + kProtectionMethodNackOnly, + kProtectionMethodHybridNackAndFec, +}; + +using webrtc::FromChoices; + class ViEAutotestFileObserver : public webrtc::ViEFileObserver { public: ViEAutotestFileObserver() {} @@ -130,17 +142,18 @@ bool SetVideoCodecMaxBitrate(webrtc::ViECodec* vie_codec, bool SetVideoCodecMaxFramerate(webrtc::ViECodec* vie_codec, webrtc::VideoCodec* video_codec); bool SetVideoCodecTemporalLayer(webrtc::VideoCodec* video_codec); -int GetVideoProtection(); +VideoProtectionMethod GetVideoProtection(); bool SetVideoProtection(webrtc::ViECodec* vie_codec, webrtc::ViERTP_RTCP* vie_rtp_rtcp, - int video_channel, int protection_method); + 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* playbackDeviceName, int& playback_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); @@ -247,8 +260,8 @@ int ViEAutoTest::ViECustomCall() { int audio_rx_port = 0; webrtc::CodecInst audio_codec; int audio_channel = -1; + VideoProtectionMethod protection_method = kProtectionMethodNone; bool is_image_scale_enabled = false; - int protection_method = DEFAULT_VIDEO_PROTECTION_METHOD; bool remb = true; while (!start_call) { @@ -259,7 +272,8 @@ int ViEAutoTest::ViECustomCall() { // Get the video device to use for call. memset(device_name, 0, KMaxUniqueIdLength); memset(unique_id, 0, KMaxUniqueIdLength); - GetVideoDevice(vie_base, vie_capture, device_name, unique_id); + 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; @@ -303,32 +317,12 @@ int ViEAutoTest::ViECustomCall() { audio_codec, audio_tx_port, audio_rx_port, protection_method); - std::cout << std::endl; - std::cout << "1. Start the call" << std::endl; - std::cout << "2. Reconfigure call settings" << std::endl; - std::cout << "What do you want to do? Press enter for default " - << "(Start the call): "; - - std::getline(std::cin, str); - int selection = 0; - selection = atoi(str.c_str()); - - switch (selection) { - case 0: - start_call = true; - break; - case 1: - start_call = true; - break; - case 2: - start_call = false; - break; - default: - // Invalid selection gets error mesage. - std::cout << "ERROR: Code=" << error - << " Invalid selection" << std::endl; - continue; - } + printf("\n"); + int selection = + FromChoices("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. @@ -527,60 +521,42 @@ int ViEAutoTest::ViECustomCall() { // Call started. std::cout << std::endl; std::cout << "Custom call started" << std::endl; - std::cout << std::endl << std::endl; // Modify call or stop call. + printf("\n"); + int selection = FromChoices( + "Stop the call\n" + "Modify the call\n").WithDefault("Stop the call").Choose(); - std::cout << "Custom call in progress, would you like do?" << std::endl; - std::cout << " 0. Stop the call" << std::endl; - std::cout << " 1. Modify the call" << std::endl; - std::cout << "What do you want to do? " - << "Press enter for default (Stop the call): "; + int file_selection = 0; - std::getline(std::cin, str); - int selection = 0; - selection = atoi(str.c_str()); - - // Keep on modifying the call until user selects finish modify call. - bool modify_call = false; - - while (selection == 1) { - std::cout << "Modify Custom Call" << std::endl; - std::cout << " 0. Finished modifying custom call" << std::endl; - std::cout << " 1. Change Video Send Codec" << std::endl; - std::cout << " 2. Change Video Send Size by Common Resolutions" - << std::endl; - std::cout << " 3. Change Video Send Size by Width & Height" << std::endl; - std::cout << " 4. Change Video Capture Device" << std::endl; - std::cout << " 5. Record Incoming Call" << std::endl; - std::cout << " 6. Record Outgoing Call" << std::endl; - std::cout << " 7. Play File on Video Channel" - << "(Assumes you recorded incoming & outgoing call)" - << std::endl; - std::cout << " 8. Change Video Protection Method" << std::endl; - std::cout << " 9. Toggle Encoder Observer" << std::endl; - std::cout << " 10. Toggle Decoder Observer" << std::endl; - std::cout << " 11. Print Call Information" << std::endl; - std::cout << " 12. Print Call Statistics" << std::endl; - std::cout << " 13. Toggle Image Scaling " - << "(Warning high CPU usage when enabled)" - << std::endl; - std::cout << "What do you want to do? "; - std::cout << "Press enter for default " - << "(Finished modifying custom call): "; - - std::getline(std::cin, str); - int modify_selection = 0; - int file_selection = 0; - - modify_selection = atoi(str.c_str()); + while (selection == 2) { + // Keep on modifying the call until user stops the call. + int modify_selection = FromChoices( + "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") + .WithTitle("Modify the call:") + .Choose(); switch (modify_selection) { - case 0: - std::cout << "Finished modifying custom call." << std::endl; - modify_call = false; - break; case 1: + selection = 1; + break; + case 2: // Change video codec. SetVideoCodecType(vie_codec, &video_send_codec); SetVideoCodecSize(vie_codec, &video_send_codec); @@ -603,9 +579,8 @@ int ViEAutoTest::ViECustomCall() { number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - modify_call = true; break; - case 2: + case 3: // Change Video codec size by common resolution. SetVideoCodecResolution(vie_codec, &video_send_codec); PrintCallInformation(ip_address, device_name, @@ -622,9 +597,8 @@ int ViEAutoTest::ViECustomCall() { number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - modify_call = true; break; - case 3: + case 4: // Change video codec by size height and width. SetVideoCodecSize(vie_codec, &video_send_codec); PrintCallInformation(ip_address, device_name, @@ -641,9 +615,8 @@ int ViEAutoTest::ViECustomCall() { number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - modify_call = true; break; - case 4: + case 5: error = vie_renderer->StopRender(capture_id); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", @@ -666,7 +639,8 @@ int ViEAutoTest::ViECustomCall() { __FUNCTION__, __LINE__); memset(device_name, 0, KMaxUniqueIdLength); memset(unique_id, 0, KMaxUniqueIdLength); - GetVideoDevice(vie_base, vie_capture, device_name, unique_id); + if (!GetVideoDevice(vie_base, vie_capture, device_name, unique_id)) + return number_of_errors; capture_id = 0; error = vie_capture->AllocateCaptureDevice(unique_id, KMaxUniqueIdLength, @@ -692,9 +666,8 @@ int ViEAutoTest::ViECustomCall() { number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - modify_call = true; break; - case 5: + case 6: // Record the incoming call. std::cout << "Start Recording Incoming Video " << DEFAULT_INCOMING_FILE_NAME << std::endl; @@ -708,9 +681,8 @@ int ViEAutoTest::ViECustomCall() { "ERROR:%d %s at line %d", vie_base->LastError(), __FUNCTION__, __LINE__); - modify_call = true; break; - case 6: + case 7: // Record the outgoing call. std::cout << "Start Recording Outgoing Video " << DEFAULT_OUTGOING_FILE_NAME << std::endl; @@ -724,25 +696,21 @@ int ViEAutoTest::ViECustomCall() { "ERROR:%d %s at line %d", vie_base->LastError(), __FUNCTION__, __LINE__); - modify_call = true; break; - case 7: + case 8: // Send the file on the video_channel. - file_selection = 0; - std::cout << "Available files to play" << std::endl; - std::cout << " 0. " << DEFAULT_INCOMING_FILE_NAME << std::endl; - std::cout << " 1. " << DEFAULT_OUTGOING_FILE_NAME << std::endl; - std::cout << "Press enter for default (" - << DEFAULT_INCOMING_FILE_NAME << "): "; - std::getline(std::cin, str); - file_selection = atoi(str.c_str()); + file_selection = FromChoices( + 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 == 1) + if (file_selection == 2) error = vie_file->StartPlayFile(DEFAULT_OUTGOING_FILE_NAME, file_id, true); else @@ -791,16 +759,14 @@ int ViEAutoTest::ViECustomCall() { "ERROR:%d %s at line %d", vie_base->LastError(), __FUNCTION__, __LINE__); - modify_call = true; break; - case 8: + case 9: // Change the Video Protection. protection_method = GetVideoProtection(); SetVideoProtection(vie_codec, vie_rtp_rtcp, video_channel, protection_method); - modify_call = true; break; - case 9: + case 10: // Toggle Encoder Observer. if (!codec_encoder_observer) { std::cout << "Registering Encoder Observer" << std::endl; @@ -819,9 +785,8 @@ int ViEAutoTest::ViECustomCall() { "ERROR: %s at line %d", __FUNCTION__, __LINE__); } - modify_call = true; break; - case 10: + case 11: // Toggle Decoder Observer. if (!codec_decoder_observer) { std::cout << "Registering Decoder Observer" << std::endl; @@ -840,9 +805,8 @@ int ViEAutoTest::ViECustomCall() { "ERROR: %s at line %d", __FUNCTION__, __LINE__); } - modify_call = true; break; - case 11: + case 12: // Print Call information.. PrintCallInformation(ip_address, device_name, unique_id, video_send_codec, @@ -853,9 +817,8 @@ int ViEAutoTest::ViECustomCall() { audio_rx_port, protection_method); PrintVideoStreamInformation(vie_codec, video_channel); - modify_call = true; break; - case 12: + case 13: // Print Call statistics. PrintRTCCPStatistics(vie_rtp_rtcp, video_channel, kSendStatistic); @@ -868,9 +831,8 @@ int ViEAutoTest::ViECustomCall() { PrintCodecStatistics(vie_codec, video_channel, kReceivedStatistic); PrintGetDiscardedPackets(vie_codec, video_channel); - modify_call = true; break; - case 13: + case 14: is_image_scale_enabled = !is_image_scale_enabled; vie_codec->SetImageScaleStatus(video_channel, is_image_scale_enabled); if (is_image_scale_enabled) { @@ -878,23 +840,13 @@ int ViEAutoTest::ViECustomCall() { } else { std::cout << "Image Scale is now disabled" << std::endl; } - modify_call = true; break; default: - // Invalid selection, shows options menu again. - std::cout << "Invalid selection. Select Again." << std::endl; + assert(false); break; } - // Modify_call is false if user does not select one of the modify options. - if (modify_call == false) { - selection = 0; - } } - // Stop the Call - std::cout << "Press enter to stop..."; - std::getline(std::cin, str); - // Testing finished. Tear down Voice and Video Engine. // Tear down the VoE first. error = voe_base->StopReceive(audio_channel); @@ -1034,211 +986,139 @@ bool GetVideoDevice(webrtc::ViEBase* vie_base, char* capture_device_unique_id) { int error = 0; int number_of_errors = 0; - int capture_device_index = 0; - std::string str; const unsigned int KMaxDeviceNameLength = 128; const unsigned int KMaxUniqueIdLength = 256; char device_name[KMaxDeviceNameLength]; char unique_id[KMaxUniqueIdLength]; - while (1) { + 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); - std::cout << std::endl; - std::cout << "Available video capture devices:" << std::endl; - int capture_idx = 0; - for (capture_idx = 0; - capture_idx < vie_capture->NumberOfCaptureDevices(); - capture_idx++) { - memset(device_name, 0, KMaxDeviceNameLength); - memset(unique_id, 0, KMaxUniqueIdLength); - - error = vie_capture->GetCaptureDevice(capture_idx, device_name, - KMaxDeviceNameLength, - unique_id, - KMaxUniqueIdLength); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - std::cout << " " << capture_idx + 1 << ". " << device_name - << "/" << unique_id - << std::endl; - } - // Get the dev_name of the default (or first) camera for display. - error = vie_capture->GetCaptureDevice(0, device_name, - KMaxDeviceNameLength, - unique_id, - 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__); - - std::cout << "Choose a video capture device. Press enter for default (" - << device_name << "/" << unique_id << "): "; - std::getline(std::cin, str); - capture_device_index = atoi(str.c_str()); - - if (capture_device_index == 0) { - // Use the default (or first) camera. - error = vie_capture->GetCaptureDevice(0, 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; - } else if ( - capture_device_index < 0 || - (capture_device_index > - static_cast(vie_capture->NumberOfCaptureDevices()))) { - // invalid selection - continue; - } else { - error = vie_capture->GetCaptureDevice(capture_device_index - 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; - } + "ERROR: %s at line %d", + __FUNCTION__, __LINE__); + const int kCaptureLineLength = + KMaxDeviceNameLength + KMaxUniqueIdLength + 8; + char capture_line[kCaptureLineLength]; + snprintf(capture_line, kCaptureLineLength, "%s (%s)", + device_name, unique_id); + capture_choices += capture_line; + capture_choices += "\n"; + if (first_device.empty()) + first_device = capture_line; } + + int choice = FromChoices(capture_choices) + .WithDefault(first_device) + .WithTitle("Available Video Capture Devices") + .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* playbackDeviceName, + char* playback_device_name, int& playback_device_index) { int error = 0; int number_of_errors = 0; - std::string str; const unsigned int KMaxDeviceNameLength = 128; const unsigned int KMaxUniqueIdLength = 128; char recording_device_unique_name[KMaxDeviceNameLength]; - char playbackDeviceUniqueName[KMaxUniqueIdLength]; + char playback_device_unique_name[KMaxUniqueIdLength]; int number_of_recording_devices = -1; error = voe_hardware->GetNumOfRecordingDevices(number_of_recording_devices); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - while (1) { - recording_device_index = -1; - std::cout << std::endl; - std::cout << "Available audio capture devices:" << std::endl; - int capture_idx = 0; + recording_device_index = -1; + playback_device_index = -1; - for (capture_idx = 0; capture_idx < number_of_recording_devices; - capture_idx++) { - memset(recording_device_name, 0, KMaxDeviceNameLength); - memset(recording_device_unique_name, 0, KMaxDeviceNameLength); - error = voe_hardware->GetRecordingDeviceName( - capture_idx, recording_device_name, recording_device_unique_name); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - std::cout << " " << capture_idx + 1 << ". " << recording_device_name - << std::endl; - } + std::string device_choices; + std::string default_recording_line; + for (int i = 0; i < number_of_recording_devices; ++i) { + error = voe_hardware->GetRecordingDeviceName( + i, recording_device_name, recording_device_unique_name); + number_of_errors += ViETest::TestError(error == 0, + "ERROR: %s at line %d", + __FUNCTION__, __LINE__); - std::cout << "Choose an audio capture device. Press enter for default(" - << recording_device_name << "): "; - std::getline(std::cin, str); - int capture_device_index = atoi(str.c_str()); - - if (capture_device_index == 0) { - // Use the default (or first) recording device. - recording_device_index = 0; - error = voe_hardware->GetRecordingDeviceName( - recording_device_index, recording_device_name, - recording_device_unique_name); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - break; - } else if (capture_device_index < 0 || - capture_device_index > number_of_recording_devices) { - // Invalid selection. - continue; - } else { - recording_device_index = capture_device_index - 1; - error = voe_hardware->GetRecordingDeviceName( - recording_device_index, recording_device_name, - recording_device_unique_name); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - break; - } + device_choices += recording_device_name; + device_choices += "\n"; + if (default_recording_line.empty()) + default_recording_line = recording_device_name; } - int number_of_playbackDevices = -1; - error = voe_hardware->GetNumOfPlayoutDevices(number_of_playbackDevices); + int choice = FromChoices(device_choices) + .WithDefault(default_recording_line) + .WithTitle("Available audio capture devices:") + .Choose(); + + recording_device_index = choice - 1; + error = voe_hardware->GetRecordingDeviceName( + recording_device_index, recording_device_name, + recording_device_unique_name); + number_of_errors += ViETest::TestError( + error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); + + int number_of_playback_devices = -1; + error = voe_hardware->GetNumOfPlayoutDevices(number_of_playback_devices); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - while (1) { - playback_device_index = -1; - std::cout << std::endl; - std::cout << "Available audio playout devices:" << std::endl; - int capture_idx = 0; - for (capture_idx = 0; capture_idx < number_of_playbackDevices; - capture_idx++) { - memset(playbackDeviceName, 0, KMaxDeviceNameLength); - memset(playbackDeviceUniqueName, 0, KMaxDeviceNameLength); - error = voe_hardware->GetPlayoutDeviceName(capture_idx, - playbackDeviceName, - playbackDeviceUniqueName); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - std::cout << " " << capture_idx + 1 << ". " << playbackDeviceName - << std::endl; - } - - std::cout << "Choose an audio playback device. Press enter for default (" - << playbackDeviceName << "): "; - std::getline(std::cin, str); - int capture_device_index = atoi(str.c_str()); - - if (capture_device_index == 0) { - // Use the default (or first) playout device. - playback_device_index = 0; - error = voe_hardware->GetPlayoutDeviceName( - playback_device_index, playbackDeviceName, - playbackDeviceUniqueName); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - return true; - } else if (capture_device_index < 0 - || capture_device_index > number_of_playbackDevices) { - // Invalid selection. - continue; - } else { - playback_device_index = capture_device_index - 1; - error = voe_hardware->GetPlayoutDeviceName(playback_device_index, - playbackDeviceName, - playbackDeviceUniqueName); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - return true; - } + std::string playback_choices; + std::string default_playback_line; + for (int i = 0; i < number_of_playback_devices; i++) { + error = voe_hardware->GetPlayoutDeviceName(i, + playback_device_name, + playback_device_unique_name); + number_of_errors += ViETest::TestError( + error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); + playback_choices += playback_device_name; + playback_choices += "\n"; + if (default_playback_line.empty()) + default_playback_line = playback_device_name; } + + choice = FromChoices(playback_choices) + .WithDefault(default_playback_line) + .WithTitle("Available audio playout devices:") + .Choose(); + + playback_device_index = choice - 1; + error = voe_hardware->GetPlayoutDeviceName(playback_device_index, + playback_device_name, + playback_device_unique_name); + number_of_errors += ViETest::TestError(error == 0, + "ERROR: %s at line %d", + __FUNCTION__, __LINE__); + return true; } // General helper functions. @@ -1390,62 +1270,39 @@ bool GetAudioPorts(int* tx_port, int* rx_port) { bool GetAudioCodec(webrtc::VoECodec* voe_codec, webrtc::CodecInst& audio_codec) { int error = 0; - int number_of_errors = 0; - int codec_selection = 0; - std::string str; memset(&audio_codec, 0, sizeof(webrtc::CodecInst)); - while (1) { - std::cout << std::endl; - std::cout << "Available audio codecs:" << std::endl; - int codec_idx = 0; - int default_codec_idx = 0; - for (codec_idx = 0; codec_idx < voe_codec->NumOfCodecs(); codec_idx++) { - error = voe_codec->GetCodec(codec_idx, audio_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); + std::string default_codec_line; + std::string codec_choices; + for (int codec_idx = 0; codec_idx < voe_codec->NumOfCodecs(); codec_idx++) { + error = voe_codec->GetCodec(codec_idx, audio_codec); + ViETest::TestError(error == 0, + "ERROR: %s at line %d", + __FUNCTION__, __LINE__); - // Test for default codec index. - if (strcmp(audio_codec.plname, DEFAULT_AUDIO_CODEC) == 0) { - default_codec_idx = codec_idx; - } - std::cout << " " << codec_idx + 1 << ". " << audio_codec.plname - << " type:" << audio_codec.pltype - << " freq:" << audio_codec.plfreq - << " chan:" << audio_codec.channels - << std::endl; - } - std::cout << std::endl; - std::cout << "Choose audio codec. Press enter for default (" - << DEFAULT_AUDIO_CODEC << "): "; - std::getline(std::cin, str); - codec_selection = atoi(str.c_str()); + char codec_line[128]; + snprintf(codec_line, 128, "%s type: %d freq: %d chan: %d", + audio_codec.plname, audio_codec.pltype, audio_codec.plfreq, + audio_codec.channels); + codec_choices += codec_line; + codec_choices += "\n"; - if (codec_selection == 0) { - // Use default. - error = voe_codec->GetCodec(default_codec_idx, audio_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - return true; - } else { - // User selection. - codec_selection = atoi(str.c_str()) - 1; - error = voe_codec->GetCodec(codec_selection, audio_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - if (error != 0) { - std::cout << "ERROR: Code = " << error << " Invalid selection" - << std::endl; - continue; - } - return true; + if (strcmp(audio_codec.plname, DEFAULT_AUDIO_CODEC) == 0) { + default_codec_line = codec_line; } } - assert(false); - return false; + assert(!default_codec_line.empty() && "Default codec doesn't exist."); + + int codec_selection = FromChoices(codec_choices) + .WithDefault(default_codec_line) + .WithTitle("Available Audio Codecs:") + .Choose(); + + error = voe_codec->GetCodec(codec_selection - 1, audio_codec); + ViETest::TestError(error == 0, + "ERROR: %s at line %d", + __FUNCTION__, __LINE__); + return true; } void PrintCallInformation(char* IP, char* video_capture_device_name, @@ -1470,8 +1327,8 @@ void PrintCallInformation(char* IP, char* video_capture_device_name, PrintVideoCodec(video_codec); std::cout << "\t Video Tx Port: " << video_tx_port << std::endl; std::cout << "\t Video Rx Port: " << video_rx_port << std::endl; - std::cout << "\t Video Protection Method: " << protection_method - << std::endl; + std::cout << "\t Video Protection Method (NOTE: Starts at 1 now): " + << protection_method << std::endl; std::cout << "\tAudio Capture Device: " << audio_capture_device_name << std::endl; std::cout << "\tAudio Playback Device: " << audio_playbackDeviceName @@ -1490,56 +1347,30 @@ bool SetVideoCodecType(webrtc::ViECodec* vie_codec, webrtc::VideoCodec* video_codec) { int error = 0; int number_of_errors = 0; - int codec_selection = 0; - std::string str; memset(video_codec, 0, sizeof(webrtc::VideoCodec)); - bool exit_loop = false; - while (!exit_loop) { - std::cout << std::endl; - std::cout << "Available video codecs:" << std::endl; - int codec_idx = 0; - int default_codec_idx = 0; - // Print out all the codecs available to set Codec to. - for (codec_idx = 0; codec_idx < vie_codec->NumberOfCodecs(); codec_idx++) { - error = vie_codec->GetCodec(codec_idx, *video_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - // Test for default codec index. - if (strcmp(video_codec->plName, DEFAULT_VIDEO_CODEC) == 0) { - default_codec_idx = codec_idx; - } - std::cout << " " << codec_idx + 1 << ". " << video_codec->plName - << std::endl; - } - std::cout << std::endl; - std::cout << "Choose video codec. Press enter for default (" - << DEFAULT_VIDEO_CODEC << "): "; - std::getline(std::cin, str); - codec_selection = atoi(str.c_str()); - if (codec_selection == 0) { - // Use default. - error = vie_codec->GetCodec(default_codec_idx, *video_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - exit_loop = true; - } else { - // User selection. - codec_selection = atoi(str.c_str()) - 1; - error = vie_codec->GetCodec(codec_selection, *video_codec); - number_of_errors += ViETest::TestError(error == 0, - "ERROR: %s at line %d", - __FUNCTION__, __LINE__); - if (error != 0) { - std::cout << "ERROR: Code=" << error << " Invalid selection" - << std::endl; - continue; - } - exit_loop = true; - } + std::string codec_choices; + std::string default_codec_line; + for (int i = 0; i < vie_codec->NumberOfCodecs(); i++) { + error = vie_codec->GetCodec(i, *video_codec); + number_of_errors += ViETest::TestError( + error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); + + codec_choices += video_codec->plName; + codec_choices += "\n"; + if (strcmp(video_codec->plName, DEFAULT_VIDEO_CODEC) == 0) + default_codec_line = video_codec->plName; } + assert(!default_codec_line.empty() && "Default does not exist."); + + int choice = FromChoices(codec_choices) + .WithDefault(default_codec_line) + .WithTitle("Available Video Codecs") + .Choose(); + error = vie_codec->GetCodec(choice - 1, *video_codec); + number_of_errors += ViETest::TestError( + error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); + if (video_codec->codecType == webrtc::kVideoCodecI420) { video_codec->width = 176; video_codec->height = 144; @@ -1549,97 +1380,93 @@ bool SetVideoCodecType(webrtc::ViECodec* vie_codec, bool SetVideoCodecResolution(webrtc::ViECodec* vie_codec, webrtc::VideoCodec* video_codec) { - std::string str; - int size_option = 5; + if (video_codec->codecType != webrtc::kVideoCodecVP8) { + printf("Can only change codec size if it's VP8\n"); + return false; + } - if (video_codec->codecType == webrtc::kVideoCodecVP8) { - std::cout << std::endl; - std::cout << "Available Common Resolutions : " << std::endl; - std::cout << " 1. SQCIF (128X96) " << std::endl; - std::cout << " 2. QQVGA (160X120) " << std::endl; - std::cout << " 3. QCIF (176X144) " << std::endl; - std::cout << " 4. CIF (352X288) " << std::endl; - std::cout << " 5. VGA (640X480) " << std::endl; - std::cout << " 6. WVGA (800x480) " << std::endl; - std::cout << " 7. 4CIF (704X576) " << std::endl; - std::cout << " 8. SVGA (800X600) " << std::endl; - std::cout << " 9. HD (1280X720) " << std::endl; - std::cout << " 10. XGA (1024x768) " << std::endl; - std::cout << "Enter frame size option: " << std::endl; + int choice = FromChoices( + "SQCIF (128X96)\n" + "QQVGA (160X120)\n" + "QCIF (176X144)\n" + "CIF (352X288)\n" + "VGA (640X480)\n" + "WVGA (800x480)\n" + "4CIF (704X576)\n" + "SVGA (800X600)\n" + "HD (1280X720)\n" + "XGA (1024x768)\n") + .WithTitle("Available Common Resolutions:") + .Choose(); - std::getline(std::cin, str); - size_option = atoi(str.c_str()); - - switch (size_option) { - case 1: - video_codec->width = 128; - video_codec->height = 96; - break; - case 2: - video_codec->width = 160; - video_codec->height = 120; - break; - case 3: - video_codec->width = 176; - video_codec->height = 144; - break; - case 4: - video_codec->width = 352; - video_codec->height = 288; - break; - case 5: - video_codec->width = 640; - video_codec->height = 480; - break; - case 6: - video_codec->width = 800; - video_codec->height = 480; - break; - case 7: - video_codec->width = 704; - video_codec->height = 576; - break; - case 8: - video_codec->width = 800; - video_codec->height = 600; - break; - case 9: - video_codec->width = 1280; - video_codec->height = 720; - break; - case 10: - video_codec->width = 1024; - video_codec->height = 768; - break; - } - } else { - std::cout << "Can Only change codec size if it's VP8" << std::endl; + switch (choice) { + case 1: + video_codec->width = 128; + video_codec->height = 96; + break; + case 2: + video_codec->width = 160; + video_codec->height = 120; + break; + case 3: + video_codec->width = 176; + video_codec->height = 144; + break; + case 4: + video_codec->width = 352; + video_codec->height = 288; + break; + case 5: + video_codec->width = 640; + video_codec->height = 480; + break; + case 6: + video_codec->width = 800; + video_codec->height = 480; + break; + case 7: + video_codec->width = 704; + video_codec->height = 576; + break; + case 8: + video_codec->width = 800; + video_codec->height = 600; + break; + case 9: + video_codec->width = 1280; + video_codec->height = 720; + break; + case 10: + video_codec->width = 1024; + video_codec->height = 768; + break; } return true; } bool SetVideoCodecSize(webrtc::ViECodec* vie_codec, webrtc::VideoCodec* video_codec) { - if (video_codec->codecType == webrtc::kVideoCodecVP8) { - std::string str; - video_codec->width = DEFAULT_VIDEO_CODEC_WIDTH; - video_codec->height = DEFAULT_VIDEO_CODEC_HEIGHT; - std::cout << "Choose video width. Press enter for default (" - << DEFAULT_VIDEO_CODEC_WIDTH << "): "; - std::getline(std::cin, str); - int size_selection = atoi(str.c_str()); - if (size_selection != 0) { - video_codec->width = size_selection; - } - std::cout << "Choose video height. Press enter for default (" - << DEFAULT_VIDEO_CODEC_HEIGHT << "): "; - std::getline(std::cin, str); - size_selection = atoi(str.c_str()); - if (size_selection != 0) { - video_codec->height = size_selection; - } - } else { - std::cout << "Can Only change codec size if it's VP8" << std::endl; + if (video_codec->codecType != webrtc::kVideoCodecVP8) { + printf("Can only change codec size if it's VP8\n"); + return false; + } + + std::string str; + video_codec->width = DEFAULT_VIDEO_CODEC_WIDTH; + video_codec->height = DEFAULT_VIDEO_CODEC_HEIGHT; + std::cout << "Choose video width. Press enter for default (" + << DEFAULT_VIDEO_CODEC_WIDTH << "): "; + std::getline(std::cin, str); + int size_selection = atoi(str.c_str()); + if (size_selection != 0) { + video_codec->width = size_selection; + } + std::cout << "Choose video height. Press enter for default (" + << DEFAULT_VIDEO_CODEC_HEIGHT << "): "; + std::getline(std::cin, str); + size_selection = atoi(str.c_str()); + if (size_selection != 0) { + video_codec->height = size_selection; } return true; } @@ -1724,33 +1551,26 @@ bool SetVideoCodecTemporalLayer(webrtc::VideoCodec* video_codec) { } // GetVideoProtection only prints the prompt to get a number -// that SetVideoProtection method uses -// 0 = None -// 1 = FEC -// 2 = NACK -// 3 = NACK + FEC (aka Hybrid) -// Default = DEFAULT_VIDEO_PROTECTION METHOD -int GetVideoProtection() { - int protection_method = DEFAULT_VIDEO_PROTECTION_METHOD; +// that SetVideoProtection method uses. +VideoProtectionMethod GetVideoProtection() { + int choice = FromChoices( + "None\n" + "FEC\n" + "NACK\n" + "NACK+FEC\n") + .WithDefault(DEFAULT_VIDEO_PROTECTION_METHOD) + .WithTitle("Available Video Protection Methods:") + .Choose(); - std::cout << "Available Video Protection Method." << std::endl; - std::cout << " 0. None" << std::endl; - std::cout << " 1. FEC" << std::endl; - std::cout << " 2. NACK" << std::endl; - std::cout << " 3. NACK+FEC" << std::endl; - std::cout << "Enter Video Protection Method. " - << "Press enter for default (" << protection_method << "):" - << std::endl; - std::string method; - std::getline(std::cin, method); - protection_method = atoi(method.c_str()); - - return protection_method; + assert(choice >= kProtectionMethodNone && + choice <= kProtectionMethodHybridNackAndFec); + return static_cast(choice); } bool SetVideoProtection(webrtc::ViECodec* vie_codec, webrtc::ViERTP_RTCP* vie_rtp_rtcp, - int video_channel, int protection_method) { + int video_channel, + VideoProtectionMethod protection_method) { int error = 0; int number_of_errors = 0; webrtc::VideoCodec video_codec; @@ -1759,8 +1579,8 @@ bool SetVideoProtection(webrtc::ViECodec* vie_codec, // Set all video protection to false initially error = vie_rtp_rtcp->SetHybridNACKFECStatus(video_channel, false, - VCM_RED_PAYLOAD_TYPE, - VCM_ULPFEC_PAYLOAD_TYPE); + VCM_RED_PAYLOAD_TYPE, + VCM_ULPFEC_PAYLOAD_TYPE); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -1776,14 +1596,12 @@ bool SetVideoProtection(webrtc::ViECodec* vie_codec, __FUNCTION__, __LINE__); // Set video protection for FEC, NACK or Hybrid. switch (protection_method) { - case 0: // None. + case kProtectionMethodNone: // No protection selected, all protection already at false. - std::cout << "Call using None protection Method" - << std::endl; + std::cout << "Call using None protection Method" << std::endl; break; - case 1: // FEC only. - std::cout << "Call using FEC protection Method" - << std::endl; + case kProtectionMethodFecOnly: + std::cout << "Call using FEC protection Method" << std::endl; error = vie_rtp_rtcp->SetFECStatus(video_channel, true, VCM_RED_PAYLOAD_TYPE, VCM_ULPFEC_PAYLOAD_TYPE); @@ -1791,15 +1609,14 @@ bool SetVideoProtection(webrtc::ViECodec* vie_codec, "ERROR: %s at line %d", __FUNCTION__, __LINE__); break; - case 2: // NACK only. - std::cout << "Call using NACK protection Method" - << std::endl; + case kProtectionMethodNackOnly: + std::cout << "Call using NACK protection Method" << std::endl; error = vie_rtp_rtcp->SetNACKStatus(video_channel, true); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); break; - case 3: // Hybrid NACK and FEC. + case kProtectionMethodHybridNackAndFec: std::cout << "Call using Hybrid NACK and FEC protection Method" << std::endl; error = vie_rtp_rtcp->SetHybridNACKFECStatus(video_channel, true, @@ -1812,7 +1629,8 @@ bool SetVideoProtection(webrtc::ViECodec* vie_codec, } // Set receive codecs for FEC and hybrid NACK/FEC. - if (protection_method == 1 || protection_method == 3) { + if (protection_method == kProtectionMethodFecOnly || + protection_method == kProtectionMethodHybridNackAndFec) { // RED. error = vie_codec->GetCodec(vie_codec->NumberOfCodecs() - 2, video_codec); @@ -1844,19 +1662,15 @@ bool SetVideoProtection(webrtc::ViECodec* vie_codec, return true; } +// Returns true if REMB, false if TMMBR. bool GetBitrateSignaling() { - std::cout << std::endl; - std::cout << "Available bitrate signaling methods." << std::endl; - std::cout << " 0. REMB" << std::endl; - std::cout << " 1. TMMBR" << std::endl; - std::cout << "Enter bitrate signaling methods. " - << "Press enter for default (REMB): " << std::endl; - std::string method; - std::getline(std::cin, method); - if (atoi(method.c_str()) == 1) { - return false; - } - return true; + int choice = FromChoices( + "REMB\n" + "TMMBR\n") + .WithDefault("REMB") + .WithTitle("Available Bitrate Signaling Methods:") + .Choose(); + return choice == 1; } void PrintRTCCPStatistics(webrtc::ViERTP_RTCP* vie_rtp_rtcp, diff --git a/src/video_engine/test/auto_test/vie_auto_test.gypi b/src/video_engine/test/auto_test/vie_auto_test.gypi index 9caef6be2d..bc5a15ce94 100644 --- a/src/video_engine/test/auto_test/vie_auto_test.gypi +++ b/src/video_engine/test/auto_test/vie_auto_test.gypi @@ -57,6 +57,9 @@ # Test primitives 'primitives/base_primitives.cc', 'primitives/base_primitives.h', + 'primitives/choice_helpers.cc', + 'primitives/choice_helpers.h', + 'primitives/choice_helpers_unittest.cc', 'primitives/codec_primitives.cc', 'primitives/codec_primitives.h', 'primitives/framedrop_primitives.h',