ViE Custom Call added SetImageScaleStatus toggle option and other changes.

1. added SetImageScaleStatus for testing purposes
2. added getting the codec information from the incoming/outgoing stream of a videochannel to print call information
3. fixed problem with toggling the one of the observers
4. did more clean up of the code style (mostly spacing)
5. renamed the GetVideo* functions properly to SetVideo* to reflect what the function does

Currently only tested on mac.  Need to test on win7 & linux before final commit.
Review URL: http://webrtc-codereview.appspot.com/267017

git-svn-id: http://webrtc.googlecode.com/svn/trunk@969 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
amyfong@webrtc.org 2011-11-17 21:29:39 +00:00
parent cd7b57ef9e
commit 917fa6b923

View File

@ -25,7 +25,7 @@
#define DEFAULT_VIDEO_CODEC "vp8"
#define DEFAULT_VIDEO_CODEC_WIDTH 640
#define DEFAULT_VIDEO_CODEC_HEIGHT 480
#define DEFAULT_VIDEO_CODEC_BITRATE 100
#define DEFAULT_VIDEO_CODEC_BITRATE 300
#define DEFAULT_VIDEO_CODEC_MAX_BITRATE 1000
#define DEFAULT_AUDIO_PORT 11113
#define DEFAULT_AUDIO_CODEC "ISAC"
@ -79,7 +79,7 @@ class ViEAutotestDecoderObserver: public webrtc::ViEDecoderObserver {
}
};
// general settings functions
// The following are general helper functions.
bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
webrtc::ViECapture* ptrViECapture,
char* captureDeviceName, char* captureDeviceUniqueId);
@ -87,7 +87,7 @@ bool GetIPAddress(char* IP);
#ifndef WEBRTC_ANDROID
bool ValidateIP(std::string iStr);
#endif
// Print Call information and statistics
// The following are Print to stdout functions.
void PrintCallInformation(char* IP, char* videoCaptureDeviceName,
char* videoCaptureUniqueId,
webrtc::VideoCodec videoCodec, int videoTxPort,
@ -104,27 +104,29 @@ void PrintBandwidthUsage(webrtc::ViERTP_RTCP* ptrViERtpRtcp,
void PrintCodecStatistics(webrtc::ViECodec* ptrViECodec, int videoChannel,
StatisticsType statType);
void PrintGetDiscardedPackets(webrtc::ViECodec* ptrViECodec, int videoChannel);
void PrintVideoStreamInformation(webrtc::ViECodec* ptrViECodec,
int videoChannel);
// video settings functions
bool GetVideoPorts(int* txPort, int* rxPort);
bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
// The following are video set functions.
bool SetVideoPorts(int* txPort, int* rxPort);
bool SetVideoCodecType(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool GetVideoCodecResolution(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecResolution(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool GetVideoCodecSize(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecSize(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool GetVideoCodecBitrate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecBitrate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool GetVideoCodecMaxBitrate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecMaxBitrate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool GetVideoCodecMaxFramerate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecMaxFramerate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec);
bool SetVideoProtection(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec,
webrtc::ViERTP_RTCP* ptrViERtpRtcp,
int videoChannel);
// audio settings functions
// The following are audio helper functions.
bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
webrtc::VoEHardware* ptrVEHardware,
char* recordingDeviceName, int& recordingDeviceIndex,
@ -146,7 +148,7 @@ int ViEAutoTest::ViECustomCall()
int numberOfErrors = 0;
std::string str;
// VoE
// Create the VoE and get the VoE interfaces.
webrtc::VoiceEngine* ptrVE = webrtc::VoiceEngine::Create();
numberOfErrors += ViETest::TestError(ptrVE != NULL, "ERROR: %s at line %d",
__FUNCTION__, __LINE__);
@ -177,7 +179,7 @@ int ViEAutoTest::ViECustomCall()
"ERROR: %s at line %d", __FUNCTION__,
__LINE__);
// ViE
// Create the ViE and get the ViE Interfaces.
webrtc::VideoEngine* ptrViE = webrtc::VideoEngine::Create();
numberOfErrors += ViETest::TestError(ptrViE != NULL,
"ERROR: %s at line %d", __FUNCTION__,
@ -242,32 +244,32 @@ int ViEAutoTest::ViECustomCall()
// toggle between registered or deregistered
bool isEncoderObserverRegistered = false;
bool isDecoderObserverRegistered = false;
bool isImageScaleEnabled = false;
while(1)
{
// IP
while (!startCall) {
// Get the IP address to use from call.
memset(ipAddress, 0, kMaxIPLength);
GetIPAddress(ipAddress);
// video devices
// Get the video device to use for call.
memset(deviceName, 0, KMaxUniqueIdLength);
memset(uniqueId, 0, KMaxUniqueIdLength);
GetVideoDevice(ptrViEBase, ptrViECapture, deviceName, uniqueId);
// video ports
// Get and set the video ports for the call.
videoTxPort = 0;
videoRxPort = 0;
GetVideoPorts(&videoTxPort, &videoRxPort);
SetVideoPorts(&videoTxPort, &videoRxPort);
// video codecs
// Get and set the video codec paramters for the call.
memset((void*)&videoCodec, 0, sizeof(videoCodec));
GetVideoCodecType(ptrViECodec, videoCodec);
GetVideoCodecSize(ptrViECodec, videoCodec);
GetVideoCodecBitrate(ptrViECodec, videoCodec);
GetVideoCodecMaxBitrate(ptrViECodec, videoCodec);
GetVideoCodecMaxFramerate(ptrViECodec, videoCodec);
SetVideoCodecType(ptrViECodec, videoCodec);
SetVideoCodecSize(ptrViECodec, videoCodec);
SetVideoCodecBitrate(ptrViECodec, videoCodec);
SetVideoCodecMaxBitrate(ptrViECodec, videoCodec);
SetVideoCodecMaxFramerate(ptrViECodec, videoCodec);
// Choose video protection mode
// Choose video protection method for the call.
std::cout << "Available Video Protection Method" << std::endl;
std::cout << "0. None" << std::endl;
std::cout << "1. FEC" << std::endl;
@ -279,23 +281,23 @@ int ViEAutoTest::ViECustomCall()
std::getline(std::cin, method);
protectionMethod = atoi(method.c_str());
// audio devices
// Get the audio device for the call.
memset(audioCaptureDeviceName, 0, KMaxUniqueIdLength);
memset(audioPlaybackDeviceName, 0, KMaxUniqueIdLength);
GetAudioDevices(ptrVEBase, ptrVEHardware, audioCaptureDeviceName,
audioCaptureDeviceIndex, audioPlaybackDeviceName,
audioPlaybackDeviceIndex);
// audio port
// Get the audio port for the call.
audioTxPort = 0;
audioRxPort = 0;
GetAudioPorts(&audioTxPort, &audioRxPort);
// audio codec
// Get the audio codec for the call.
memset((void*)&audioCodec, 0, sizeof(audioCodec));
GetAudioCodec(ptrVECodec, audioCodec);
// start the call now
// Now ready to start the call. Check user wants to continue.
PrintCallInformation(ipAddress, deviceName, uniqueId, videoCodec,
videoTxPort, videoRxPort, audioCaptureDeviceName,
audioPlaybackDeviceName, audioCodec, audioTxPort,
@ -304,7 +306,6 @@ int ViEAutoTest::ViECustomCall()
std::cout << std::endl;
std::cout << "1. Start the call" << std::endl;
std::cout << "2. Reconfigure call settings" << std::endl;
std::cout << "3. Go back to main menu" << std::endl;
std::cout << "What do you want to do? Press enter for default "
<< "(Start the call): ";
@ -312,35 +313,28 @@ int ViEAutoTest::ViECustomCall()
int selection = 0;
selection = atoi(str.c_str());
if(selection == 0 || selection == 1)
{
switch (selection) {
case 0:
startCall = true;
break;
}
else if(selection == 2)
{
continue;
}
else if(selection == 3)
{
case 1:
startCall = true;
break;
case 2:
startCall = false;
break;
}
else
{
// invalid selection
std::cout << "ERROR: Code=" << error <<
" Invalid selection" << std::endl;
default:
// Invalid selection gets error mesage.
std::cout << "ERROR: Code=" << error
<< " Invalid selection" << std::endl;
continue;
}
}
//***************************************************************
// Begin create/initialize WebRTC Video Engine for testing
// Begin create/initialize WebRTC Video Engine for testing.
//***************************************************************
if(startCall == true)
{
// Configure Audio first
if (startCall == true) {
// Configure audio channel first.
audioChannel = ptrVEBase->CreateChannel();
error = ptrVEBase->SetSendDestination(audioChannel, audioTxPort,
ipAddress);
@ -377,7 +371,7 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
// Configure Video now
// Now configure the video channel.
error = ptrViE->SetTraceFilter(webrtc::kTraceAll);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
@ -441,8 +435,8 @@ int ViEAutoTest::ViECustomCall()
// Set all video protection to false initially
// shouldn't be nessecary as ViE protection modes are all off
// initially.
// TODO(amyfong): remove the set to false and use i
// SetVideoProtection instead
// TODO(amyfong): Remove the set to false and use
// SetVideoProtection instead.
error = ptrViERtpRtcp->SetHybridNACKFECStatus(videoChannel, false,
VCM_RED_PAYLOAD_TYPE,
VCM_ULPFEC_PAYLOAD_TYPE);
@ -459,14 +453,13 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
// Set video protection for FEC, NACK or Hybrid
// Set video protection for FEC, NACK or Hybrid.
// TODO(amyfong): Use SetVideoProtection instead, need to
// move the set protection method after the first SetReceiveCodec
// also should change and use videoSendCodec & videoReceiveCodec
// instead of just videoCodec. Helps check what exactly the call
// setup is onces the call is up and running
switch (protectionMethod)
{
// setup is onces the call is up and running.
switch (protectionMethod) {
case 0: // None
// No protection selected, all protection already at false
break;
@ -510,7 +503,6 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
error = ptrViENetwork->SetSendDestination(videoChannel, ipAddress,
videoTxPort);
numberOfErrors += ViETest::TestError(error == 0,
@ -532,15 +524,14 @@ int ViEAutoTest::ViECustomCall()
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
// Set receive codecs for FEC and hybrid NACK/FEC
// Set receive codecs for FEC and hybrid NACK/FEC.
// TODO(amyfong): Use SetVideoProtection instead, need to
// move the set protection method after the first SetReceiveCodec
// also should change and use videoSendCodec & videoReceiveCodec
// instead of just videoCodec. Helps check what exactly the call
// setup is onces the call is up and running
// setup is onces the call is up and running.
if (protectionMethod == 1 || protectionMethod == 3)
{
if (protectionMethod == 1 || protectionMethod == 3) {
// RED
error = ptrViECodec->GetCodec(ptrViECodec->NumberOfCodecs() - 2,
videoCodec);
@ -566,8 +557,8 @@ int ViEAutoTest::ViECustomCall()
__FUNCTION__, __LINE__);
}
// **** start the engines
// VE first
// **** Start the engines.
// Start VE first
error = ptrVEBase->StartReceive(audioChannel);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
@ -607,7 +598,7 @@ int ViEAutoTest::ViECustomCall()
int fileId;
// Codec Observers
// TODO (amyfong): Change the observers to pointers, use NULL checks
// to toggle between registered or deregistered
// to toggle between registered or deregistered.
ViEAutotestEncoderObserver codecEncoderObserver;
ViEAutotestDecoderObserver codecDecoderObserver;
@ -616,12 +607,12 @@ int ViEAutoTest::ViECustomCall()
// Engine ready. Wait for input
//***************************************************************
// Call started
// Call started.
std::cout << std::endl;
std::cout << "Custom call started" << std::endl;
std::cout << std::endl << std::endl;
// Modify call or stop call
// Modify call or stop call.
std::cout << "Custom call in progress, would you like do?" << std::endl;
std::cout << " 0. Stop the call" << std::endl;
@ -633,11 +624,10 @@ int ViEAutoTest::ViECustomCall()
int selection = 0;
selection = atoi(str.c_str());
// keep on modifying the call until user selects finish modify call
// 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 Codec" << std::endl;
@ -655,6 +645,9 @@ int ViEAutoTest::ViECustomCall()
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): ";
@ -672,11 +665,11 @@ int ViEAutoTest::ViECustomCall()
break;
case 1:
// Change video Codec
GetVideoCodecType(ptrViECodec, videoCodec);
GetVideoCodecSize(ptrViECodec, videoCodec);
GetVideoCodecBitrate(ptrViECodec, videoCodec);
GetVideoCodecMaxBitrate(ptrViECodec, videoCodec);
GetVideoCodecMaxFramerate(ptrViECodec, videoCodec);
SetVideoCodecType(ptrViECodec, videoCodec);
SetVideoCodecSize(ptrViECodec, videoCodec);
SetVideoCodecBitrate(ptrViECodec, videoCodec);
SetVideoCodecMaxBitrate(ptrViECodec, videoCodec);
SetVideoCodecMaxFramerate(ptrViECodec, videoCodec);
PrintCallInformation(ipAddress, deviceName,
uniqueId, videoCodec,
videoTxPort, videoRxPort,
@ -695,7 +688,7 @@ int ViEAutoTest::ViECustomCall()
break;
case 2:
// Change Video codec size by common resolution
GetVideoCodecResolution(ptrViECodec, videoCodec);
SetVideoCodecResolution(ptrViECodec, videoCodec);
PrintCallInformation(ipAddress, deviceName,
uniqueId, videoCodec,
videoTxPort, videoRxPort,
@ -715,7 +708,7 @@ int ViEAutoTest::ViECustomCall()
break;
case 3:
// Change Video codec by size height and width
GetVideoCodecSize(ptrViECodec, videoCodec);
SetVideoCodecSize(ptrViECodec, videoCodec);
PrintCallInformation(ipAddress, deviceName,
uniqueId, videoCodec,
videoTxPort, videoRxPort,
@ -763,8 +756,8 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
error = ptrViECapture->ConnectCaptureDevice(
captureId, videoChannel);
error = ptrViECapture->ConnectCaptureDevice(captureId,
videoChannel);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
@ -893,7 +886,6 @@ int ViEAutoTest::ViECustomCall()
audioPlaybackDeviceName,
audioCodec, audioTxPort,
audioRxPort);
modify_call = true;
break;
case 9:
@ -911,7 +903,6 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
isEncoderObserverRegistered = false;
}
isEncoderObserverRegistered = !isEncoderObserverRegistered;
modify_call = true;
@ -944,6 +935,8 @@ int ViEAutoTest::ViECustomCall()
audioPlaybackDeviceName,
audioCodec, audioTxPort,
audioRxPort);
PrintVideoStreamInformation(ptrViECodec,
videoChannel);
modify_call = true;
break;
case 12:
@ -961,6 +954,16 @@ int ViEAutoTest::ViECustomCall()
PrintGetDiscardedPackets(ptrViECodec, videoChannel);
modify_call = true;
break;
case 13:
isImageScaleEnabled = !isImageScaleEnabled;
ptrViECodec->SetImageScaleStatus(videoChannel, isImageScaleEnabled);
if (isImageScaleEnabled) {
std::cout << "Image Scale is now enabled" << std::endl;
} 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;
@ -976,9 +979,9 @@ int ViEAutoTest::ViECustomCall()
std::cout << "Press enter to stop...";
std::getline(std::cin, str);
//***************************************************************
// Testing finished. Tear down Video Engine
// Testing finished. Tear down Voice and Video Engine.
//***************************************************************
// audio engine first
// Tear down the VE first.
error = ptrVEBase->StopReceive(audioChannel);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
@ -993,7 +996,7 @@ int ViEAutoTest::ViECustomCall()
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
// now do video
// Now tear down the ViE engine.
error = ptrViEBase->DisconnectAudioChannel(videoChannel);
error = ptrViEBase->StopReceive(videoChannel);
@ -1108,8 +1111,7 @@ bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
char deviceName[KMaxDeviceNameLength];
char uniqueId[KMaxUniqueIdLength];
while(1)
{
while (1) {
memset(deviceName, 0, KMaxDeviceNameLength);
memset(uniqueId, 0, KMaxUniqueIdLength);
@ -1117,8 +1119,8 @@ bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
std::cout << "Available video capture devices:" << std::endl;
int captureIdx = 0;
for (captureIdx = 0;
captureIdx < ptrViECapture->NumberOfCaptureDevices(); captureIdx++)
{
captureIdx < ptrViECapture->NumberOfCaptureDevices();
captureIdx++) {
memset(deviceName, 0, KMaxDeviceNameLength);
memset(uniqueId, 0, KMaxUniqueIdLength);
@ -1133,7 +1135,7 @@ bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
<< "/" << uniqueId
<< std::endl;
}
// Get the devName of the default (or first) camera for display
// Get the devName of the default (or first) camera for display.
error = ptrViECapture->GetCaptureDevice(0, deviceName,
KMaxDeviceNameLength,
uniqueId,
@ -1147,9 +1149,8 @@ bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
std::getline(std::cin, str);
captureDeviceIndex = atoi(str.c_str());
if(captureDeviceIndex == 0)
{
// use default (or first) camera
if (captureDeviceIndex == 0) {
// Use the default (or first) camera.
error = ptrViECapture->GetCaptureDevice(0, deviceName,
KMaxDeviceNameLength,
uniqueId,
@ -1160,16 +1161,12 @@ bool GetVideoDevice(webrtc::ViEBase* ptrViEBase,
strcpy(captureDeviceUniqueId, uniqueId);
strcpy(captureDeviceName, deviceName);
return true;
}
else if(captureDeviceIndex < 0
} else if (captureDeviceIndex < 0
|| (captureDeviceIndex >
(int)ptrViECapture->NumberOfCaptureDevices()))
{
(int)ptrViECapture->NumberOfCaptureDevices())) {
// invalid selection
continue;
}
else
{
} else {
error = ptrViECapture->GetCaptureDevice(captureDeviceIndex - 1,
deviceName,
KMaxDeviceNameLength,
@ -1190,8 +1187,7 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
char* recordingDeviceName,
int& recordingDeviceIndex,
char* playbackDeviceName,
int& playbackDeviceIndex)
{
int& playbackDeviceIndex) {
int error = 0;
int numberOfErrors = 0;
std::string str;
@ -1206,16 +1202,14 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
__FUNCTION__, __LINE__);
while(1)
{
while (1) {
recordingDeviceIndex = -1;
std::cout << std::endl;
std::cout << "Available audio capture devices:" << std::endl;
int captureIdx = 0;
for (captureIdx = 0; captureIdx < numberOfRecordingDevices;
captureIdx++)
{
captureIdx++) {
memset(recordingDeviceName, 0, KMaxDeviceNameLength);
memset(recordingDeviceUniqueName, 0, KMaxDeviceNameLength);
error = ptrVEHardware->GetRecordingDeviceName(
@ -1232,9 +1226,8 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
std::getline(std::cin, str);
int captureDeviceIndex = atoi(str.c_str());
if(captureDeviceIndex == 0)
{
// use default (or first) camera
if (captureDeviceIndex == 0) {
// Use the default (or first) recording device.
recordingDeviceIndex = 0;
error = ptrVEHardware->GetRecordingDeviceName(
recordingDeviceIndex, recordingDeviceName,
@ -1243,15 +1236,11 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
break;
}
else if(captureDeviceIndex < 0
|| captureDeviceIndex > numberOfRecordingDevices)
{
} else if (captureDeviceIndex < 0
|| captureDeviceIndex > numberOfRecordingDevices) {
// invalid selection
continue;
}
else
{
} else {
recordingDeviceIndex = captureDeviceIndex - 1;
error = ptrVEHardware->GetRecordingDeviceName(
recordingDeviceIndex, recordingDeviceName,
@ -1268,16 +1257,14 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
__FUNCTION__, __LINE__);
while(1)
{
while (1) {
playbackDeviceIndex = -1;
std::cout << std::endl;
std::cout << "Available audio playout devices:" << std::endl;
int captureIdx = 0;
for (captureIdx = 0; captureIdx < numberOfPlaybackDevices;
captureIdx++)
{
captureIdx++) {
memset(playbackDeviceName, 0, KMaxDeviceNameLength);
memset(playbackDeviceUniqueName, 0, KMaxDeviceNameLength);
error = ptrVEHardware->GetPlayoutDeviceName(
@ -1295,9 +1282,8 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
std::getline(std::cin, str);
int captureDeviceIndex = atoi(str.c_str());
if(captureDeviceIndex == 0)
{
// use default (or first) camera
if (captureDeviceIndex == 0) {
// Use the default (or first) playout device.
playbackDeviceIndex = 0;
error = ptrVEHardware->GetPlayoutDeviceName(
playbackDeviceIndex, playbackDeviceName,
@ -1306,15 +1292,11 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
return true;
}
else if(captureDeviceIndex < 0
|| captureDeviceIndex > numberOfPlaybackDevices)
{
} else if (captureDeviceIndex < 0
|| captureDeviceIndex > numberOfPlaybackDevices) {
// invalid selection
continue;
}
else
{
} else {
playbackDeviceIndex = captureDeviceIndex - 1;
error = ptrVEHardware->GetPlayoutDeviceName(
playbackDeviceIndex, playbackDeviceName,
@ -1327,31 +1309,27 @@ bool GetAudioDevices(webrtc::VoEBase* ptrVEBase,
}
}
// general settings functions
// General helper functions.
bool GetIPAddress(char* iIP) {
char oIP[16] = DEFAULT_SEND_IP;
std::string str;
while(1)
{
while (1) {
std::cout << std::endl;
std::cout << "Enter destination IP. Press enter for default ("
<< oIP << "): ";
std::getline(std::cin, str);
if(str.compare("") == 0)
{
if (str.compare("") == 0) {
// use default value;
strcpy(iIP, oIP);
return true;
}
if(ValidateIP(str) == false)
{
if (ValidateIP(str) == false) {
std::cout << "Invalid entry. Try again." << std::endl;
continue;
}
// done. Copy std::string to c_string and return
strcpy(iIP, str.c_str());
return true;
@ -1361,15 +1339,15 @@ bool GetIPAddress(char* iIP) {
}
bool ValidateIP(std::string iStr) {
if(0 == iStr.compare(""))
{
if (0 == iStr.compare("")) {
return false;
}
return true;
}
// video settings functions
bool GetVideoPorts(int* txPort, int* rxPort) {
// Video settings functions.
bool SetVideoPorts(int* txPort, int* rxPort) {
std::string str;
int port = 0;
@ -1377,56 +1355,42 @@ bool GetVideoPorts(int* txPort, int* rxPort) {
*txPort = DEFAULT_VIDEO_PORT;
*rxPort = DEFAULT_VIDEO_PORT;
while(1)
{
while (1) {
std::cout << "Enter video send port. Press enter for default ("
<< *txPort << "): ";
std::getline(std::cin, str);
port = atoi(str.c_str());
if(port == 0)
{
if (port == 0) {
// default value
break;
}
else
{
} else {
// user selection
if(port <= 0 || port > 63556)
{
if (port <= 0 || port > 63556) {
// invalid selection
continue;
}
else
{
} else {
*txPort = port;
break; // move on to rxport
}
}
}
while(1)
{
while (1) {
std::cout << "Enter video receive port. Press enter for default ("
<< *rxPort << "): ";
std::getline(std::cin, str);
port = atoi(str.c_str());
if(port == 0)
{
if (port == 0) {
// default value
return true;
}
else
{
} else {
// user selection
if(port <= 0 || port > 63556)
{
if (port <= 0 || port > 63556) {
// invalid selection
continue;
}
else
{
} else {
*rxPort = port;
return true;
}
@ -1436,7 +1400,8 @@ bool GetVideoPorts(int* txPort, int* rxPort) {
return false;
}
// audio settings functions
// Audio settings functions.
bool GetAudioPorts(int* txPort, int* rxPort) {
int port = 0;
std::string str;
@ -1445,56 +1410,42 @@ bool GetAudioPorts(int* txPort, int* rxPort) {
*txPort = DEFAULT_AUDIO_PORT;
*rxPort = DEFAULT_AUDIO_PORT;
while(1)
{
while (1) {
std::cout << "Enter audio send port. Press enter for default ("
<< *txPort << "): ";
std::getline(std::cin, str);
port = atoi(str.c_str());
if(port == 0)
{
if (port == 0) {
// default value
break;
}
else
{
} else {
// user selection
if(port <= 0 || port > 63556)
{
if (port <= 0 || port > 63556) {
// invalid selection
continue;
}
else
{
} else {
*txPort = port;
break; // move on to rxport
}
}
}
while(1)
{
while (1) {
std::cout << "Enter audio receive port. Press enter for default ("
<< *rxPort << "): ";
std::getline(std::cin, str);
port = atoi(str.c_str());
if(port == 0)
{
if (port == 0) {
// default value
return true;
}
else
{
} else {
// user selection
if(port <= 0 || port > 63556)
{
if (port <= 0 || port > 63556) {
// invalid selection
continue;
}
else
{
} else {
*rxPort = port;
return true;
}
@ -1512,22 +1463,19 @@ bool GetAudioCodec(webrtc::VoECodec* ptrVeCodec,
std::string str;
memset(&audioCodec, 0, sizeof(webrtc::CodecInst));
while(1)
{
while (1) {
std::cout << std::endl;
std::cout << "Available audio codecs:" << std::endl;
int codecIdx = 0;
int defaultCodecIdx = 0;
for (codecIdx = 0; codecIdx < ptrVeCodec->NumOfCodecs(); codecIdx++)
{
for (codecIdx = 0; codecIdx < ptrVeCodec->NumOfCodecs(); codecIdx++) {
error = ptrVeCodec->GetCodec(codecIdx, audioCodec);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
// test for default codec index
if(strcmp(audioCodec.plname, DEFAULT_AUDIO_CODEC) == 0)
{
if (strcmp(audioCodec.plname, DEFAULT_AUDIO_CODEC) == 0) {
defaultCodecIdx = codecIdx;
}
std::cout << " " << codecIdx+1 << ". " << audioCodec.plname
@ -1539,25 +1487,21 @@ bool GetAudioCodec(webrtc::VoECodec* ptrVeCodec,
std::getline(std::cin, str);
codecSelection = atoi(str.c_str());
if(codecSelection == 0)
{
if (codecSelection == 0) {
// use default
error = ptrVeCodec->GetCodec(defaultCodecIdx, audioCodec);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
return true;
}
else
{
} else {
// user selection
codecSelection = atoi(str.c_str())-1;
error = ptrVeCodec->GetCodec(codecSelection, audioCodec);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
if(error != 0)
{
if (error != 0) {
std::cout << "ERROR: Code = " << error << " Invalid selection"
<< std::endl;
continue;
@ -1610,8 +1554,8 @@ void PrintCallInformation(char* IP, char* videoCaptureDeviceName,
std::cout << "************************************************"
<< std::endl;
}
// TODO(amyfong): Change the GetVideo* to SetVideo* where applicable
bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecType(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
int error = 0;
int numberOfErrors = 0;
@ -1620,7 +1564,7 @@ bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
memset(&videoCodec, 0, sizeof(webrtc::VideoCodec));
bool exitLoop=false;
while(!exitLoop) {
while (!exitLoop) {
std::cout << std::endl;
std::cout << "Available video codecs:" << std::endl;
int codecIdx = 0;
@ -1632,7 +1576,7 @@ bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
__FUNCTION__, __LINE__);
// test for default codec index
if(strcmp(videoCodec.plName, DEFAULT_VIDEO_CODEC) == 0) {
if (strcmp(videoCodec.plName, DEFAULT_VIDEO_CODEC) == 0) {
defaultCodecIdx = codecIdx;
}
std::cout << " " << codecIdx+1 << ". " << videoCodec.plName
@ -1643,22 +1587,21 @@ bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
<< DEFAULT_VIDEO_CODEC << "): ";
std::getline(std::cin, str);
codecSelection = atoi(str.c_str());
if(codecSelection == 0) {
if (codecSelection == 0) {
// use default
error = ptrViECodec->GetCodec(defaultCodecIdx, videoCodec);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
exitLoop=true;
}
else {
} else {
// user selection
codecSelection = atoi(str.c_str())-1;
error = ptrViECodec->GetCodec(codecSelection, videoCodec);
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__);
if(error != 0) {
if (error != 0) {
std::cout << "ERROR: Code=" << error << " Invalid selection"
<< std::endl;
continue;
@ -1673,7 +1616,7 @@ bool GetVideoCodecType(webrtc::ViECodec* ptrViECodec,
return true;
}
bool GetVideoCodecResolution(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecResolution(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
std::string str;
int sizeOption = 5;
@ -1738,14 +1681,13 @@ bool GetVideoCodecResolution(webrtc::ViECodec* ptrViECodec,
videoCodec.height = 768;
break;
}
}
else {
} else {
std::cout << "Can Only change codec size if it's VP8" << std::endl;
}
return true;
}
bool GetVideoCodecSize(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecSize(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
if (videoCodec.codecType == webrtc::kVideoCodecVP8) {
std::string str;
@ -1755,24 +1697,23 @@ bool GetVideoCodecSize(webrtc::ViECodec* ptrViECodec,
<< DEFAULT_VIDEO_CODEC_WIDTH << "): ";
std::getline(std::cin, str);
int sizeSelection = atoi(str.c_str());
if(sizeSelection!=0) {
if (sizeSelection!=0) {
videoCodec.width=sizeSelection;
}
std::cout << "Choose video height. Press enter for default ("
<< DEFAULT_VIDEO_CODEC_HEIGHT << "): ";
std::getline(std::cin, str);
sizeSelection = atoi(str.c_str());
if(sizeSelection!=0) {
if (sizeSelection!=0) {
videoCodec.height=sizeSelection;
}
}
else {
} else {
std::cout << "Can Only change codec size if it's VP8" << std::endl;
}
return true;
}
bool GetVideoCodecBitrate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecBitrate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
std::string str;
std::cout << std::endl;
@ -1787,7 +1728,7 @@ bool GetVideoCodecBitrate(webrtc::ViECodec* ptrViECodec,
return true;
}
bool GetVideoCodecMaxBitrate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecMaxBitrate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
std::string str;
std::cout << std::endl;
@ -1802,7 +1743,7 @@ bool GetVideoCodecMaxBitrate(webrtc::ViECodec* ptrViECodec,
return true;
}
bool GetVideoCodecMaxFramerate(webrtc::ViECodec* ptrViECodec,
bool SetVideoCodecMaxFramerate(webrtc::ViECodec* ptrViECodec,
webrtc::VideoCodec& videoCodec) {
std::string str;
std::cout << std::endl;
@ -2068,3 +2009,43 @@ void PrintGetDiscardedPackets(webrtc::ViECodec* ptrViECodec, int videoChannel) {
std::cout << "\tNumber of discarded packets: "
<< discardedPackets << std::endl;
}
void PrintVideoStreamInformation(webrtc::ViECodec* ptrViECodec,
int videoChannel) {
webrtc::VideoCodec outgoingCodec;
webrtc::VideoCodec incomingCodec;
memset((void*)&outgoingCodec, 0, sizeof(outgoingCodec));
memset((void*)&incomingCodec, 0, sizeof(incomingCodec));
ptrViECodec->GetSendCodec(videoChannel, outgoingCodec);
ptrViECodec->GetReceiveCodec(videoChannel, incomingCodec);
std::cout << "************************************************"
<< std::endl;
std::cout << "ChannelId: " << videoChannel << std::endl;
std::cout << "Outgoing Stream information:" <<std::endl;
std::cout << "\t\tplName: " << outgoingCodec.plName << std::endl;
std::cout << "\t\tplType: " << (int)outgoingCodec.plType << std::endl;
std::cout << "\t\twidth: " << outgoingCodec.width << std::endl;
std::cout << "\t\theight: " << outgoingCodec.height << std::endl;
std::cout << "\t\tstartBitrate: " << outgoingCodec.startBitrate
<< std::endl;
std::cout << "\t\tmaxBitrate: " << outgoingCodec.maxBitrate
<< std::endl;
std::cout << "\t\tmaxFramerate: " << (int)outgoingCodec.maxFramerate
<< std::endl;
std::cout << "Incoming Stream information:" <<std::endl;
std::cout << "\t\tplName: " << incomingCodec.plName << std::endl;
std::cout << "\t\tplType: " << (int)incomingCodec.plType << std::endl;
std::cout << "\t\twidth: " << incomingCodec.width << std::endl;
std::cout << "\t\theight: " << incomingCodec.height << std::endl;
std::cout << "\t\tstartBitrate: " << incomingCodec.startBitrate
<< std::endl;
std::cout << "\t\tmaxBitrate: " << incomingCodec.maxBitrate
<< std::endl;
std::cout << "\t\tmaxFramerate: " << (int)incomingCodec.maxFramerate
<< std::endl;
std::cout << "************************************************"
<< std::endl;
}