Refactore base, Capture, Codec and Custom Call parts of autotest. The CL doesn't contain any real functional changes, only style changes, cast changes and changing reference to pointer as input argument to functions.

Custome call still doesn't pass cpplint, but I'll take that in another CL to not change the structure in the style change CL.

BUG=
TEST=

Review URL: https://webrtc-codereview.appspot.com/523001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2193 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2012-05-08 10:38:36 +00:00
parent 113f851cc3
commit e553031580
4 changed files with 1983 additions and 2032 deletions

View File

@ -8,13 +8,12 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "vie_autotest.h" #include "modules/video_capture/main/interface/video_capture_factory.h"
#include "video_engine/test/auto_test/interface/vie_autotest.h"
#include "base_primitives.h" #include "video_engine/test/auto_test/interface/vie_autotest_defines.h"
#include "general_primitives.h" #include "video_engine/test/auto_test/primitives/base_primitives.h"
#include "tb_interfaces.h" #include "video_engine/test/auto_test/primitives/general_primitives.h"
#include "vie_autotest_defines.h" #include "video_engine/test/libvietest/include/tb_interfaces.h"
#include "video_capture_factory.h"
class BaseObserver : public webrtc::ViEBaseObserver { class BaseObserver : public webrtc::ViEBaseObserver {
public: public:
@ -107,11 +106,11 @@ void ViEAutoTest::ViEBaseExtendedTest() {
// *************************************************************** // ***************************************************************
// TODO(mflodman) Add test for base observer. Cpu load must be over 75%. // TODO(mflodman) Add test for base observer. Cpu load must be over 75%.
// BaseObserver base_observer; // BaseObserver base_observer;
// EXPECT_EQ(ptrViEBase->RegisterObserver(base_observer), 0); // EXPECT_EQ(vie_base->RegisterObserver(base_observer), 0);
// //
// AutoTestSleep(KAutoTestSleepTimeMs); // AutoTestSleep(KAutoTestSleepTimeMs);
// //
// EXPECT_EQ(ptrViEBase->DeregisterObserver(), 0); // EXPECT_EQ(vie_base->DeregisterObserver(), 0);
// EXPECT_GT(base_observer.cpu_load, 0); // EXPECT_GT(base_observer.cpu_load, 0);
} }
@ -120,114 +119,117 @@ void ViEAutoTest::ViEBaseAPITest() {
// Begin create/initialize WebRTC Video Engine for testing // Begin create/initialize WebRTC Video Engine for testing
// *************************************************************** // ***************************************************************
// Get the ViEBase API // Get the ViEBase API
webrtc::ViEBase* ptrViEBase = webrtc::ViEBase::GetInterface(NULL); webrtc::ViEBase* vie_base = webrtc::ViEBase::GetInterface(NULL);
EXPECT_EQ(NULL, ptrViEBase) << "Should return null for a bad ViE pointer"; EXPECT_EQ(NULL, vie_base) << "Should return null for a bad ViE pointer";
webrtc::VideoEngine* ptrViE = webrtc::VideoEngine::Create(); webrtc::VideoEngine* video_engine = webrtc::VideoEngine::Create();
EXPECT_TRUE(NULL != ptrViE); EXPECT_TRUE(NULL != video_engine);
std::string trace_file_path = std::string trace_file_path =
ViETest::GetResultOutputPath() + "ViEBaseAPI_trace.txt"; ViETest::GetResultOutputPath() + "ViEBaseAPI_trace.txt";
EXPECT_EQ(0, ptrViE->SetTraceFile(trace_file_path.c_str())); EXPECT_EQ(0, video_engine->SetTraceFile(trace_file_path.c_str()));
ptrViEBase = webrtc::ViEBase::GetInterface(ptrViE); vie_base = webrtc::ViEBase::GetInterface(video_engine);
EXPECT_TRUE(NULL != ptrViEBase); EXPECT_TRUE(NULL != vie_base);
webrtc::ViENetwork* ptrVieNetwork = webrtc::ViENetwork::GetInterface(ptrViE); webrtc::ViENetwork* vie_network =
EXPECT_TRUE(ptrVieNetwork != NULL); webrtc::ViENetwork::GetInterface(video_engine);
EXPECT_TRUE(vie_network != NULL);
// *************************************************************** // ***************************************************************
// Engine ready. Begin testing class // Engine ready. Begin testing class
// *************************************************************** // ***************************************************************
char version[1024] = ""; char version[1024] = "";
EXPECT_EQ(0, ptrViEBase->GetVersion(version)); EXPECT_EQ(0, vie_base->GetVersion(version));
EXPECT_EQ(0, ptrViEBase->LastError()); EXPECT_EQ(0, vie_base->LastError());
// Create without init // Create without init
int videoChannel = -1; int video_channel = -1;
EXPECT_NE(0, ptrViEBase->CreateChannel(videoChannel)) << EXPECT_NE(0, vie_base->CreateChannel(video_channel)) <<
"Should fail since Init has not been called yet"; "Should fail since Init has not been called yet";
EXPECT_EQ(0, ptrViEBase->Init()); EXPECT_EQ(0, vie_base->Init());
EXPECT_EQ(0, ptrViEBase->CreateChannel(videoChannel)); EXPECT_EQ(0, vie_base->CreateChannel(video_channel));
int videoChannel2 = -1; int video_channel2 = -1;
int videoChannel3 = -1; int video_channel3 = -1;
EXPECT_EQ(0, ptrViEBase->CreateChannel(videoChannel2)); EXPECT_EQ(0, vie_base->CreateChannel(video_channel2));
EXPECT_NE(videoChannel, videoChannel2) << EXPECT_NE(video_channel, video_channel2) <<
"Should allocate new number for independent channel"; "Should allocate new number for independent channel";
EXPECT_EQ(0, ptrViEBase->DeleteChannel(videoChannel2)); EXPECT_EQ(0, vie_base->DeleteChannel(video_channel2));
EXPECT_EQ(-1, ptrViEBase->CreateChannel(videoChannel2, videoChannel + 1)) EXPECT_EQ(-1, vie_base->CreateChannel(video_channel2, video_channel + 1))
<< "Should fail since neither channel exists (the second must)"; << "Should fail since neither channel exists (the second must)";
// Create a receive only channel and a send channel. Verify we can't send on // Create a receive only channel and a send channel. Verify we can't send on
// the receive only channel. // the receive only channel.
EXPECT_EQ(0, ptrViEBase->CreateReceiveChannel(videoChannel2, videoChannel)); EXPECT_EQ(0, vie_base->CreateReceiveChannel(video_channel2,
EXPECT_EQ(0, ptrViEBase->CreateChannel(videoChannel3, videoChannel)); video_channel));
EXPECT_EQ(0, vie_base->CreateChannel(video_channel3, video_channel));
const char* ipAddress = "127.0.0.1\0"; const char* ip_address = "127.0.0.1\0";
const int sendPort = 1234; const int send_port = 1234;
EXPECT_EQ(0, ptrVieNetwork->SetSendDestination(videoChannel, ipAddress, EXPECT_EQ(0, vie_network->SetSendDestination(video_channel, ip_address,
sendPort)); send_port));
EXPECT_EQ(0, ptrVieNetwork->SetSendDestination(videoChannel2,ipAddress, EXPECT_EQ(0, vie_network->SetSendDestination(video_channel2, ip_address,
sendPort + 2)); send_port + 2));
EXPECT_EQ(0, ptrVieNetwork->SetSendDestination(videoChannel3,ipAddress, EXPECT_EQ(0, vie_network->SetSendDestination(video_channel3, ip_address,
sendPort + 4)); send_port + 4));
EXPECT_EQ(0, ptrViEBase->StartSend(videoChannel)); EXPECT_EQ(0, vie_base->StartSend(video_channel));
EXPECT_EQ(-1, ptrViEBase->StartSend(videoChannel2)); EXPECT_EQ(-1, vie_base->StartSend(video_channel2));
EXPECT_EQ(0, ptrViEBase->StartSend(videoChannel3)); EXPECT_EQ(0, vie_base->StartSend(video_channel3));
EXPECT_EQ(0, ptrViEBase->StopSend(videoChannel)); EXPECT_EQ(0, vie_base->StopSend(video_channel));
EXPECT_EQ(0, ptrViEBase->StopSend(videoChannel3)); EXPECT_EQ(0, vie_base->StopSend(video_channel3));
// Test Voice Engine integration with Video Engine. // Test Voice Engine integration with Video Engine.
webrtc::VoiceEngine* ptrVoE = NULL; webrtc::VoiceEngine* voice_engine = NULL;
webrtc::VoEBase* ptrVoEBase = NULL; webrtc::VoEBase* voe_base = NULL;
int audioChannel = -1; int audio_channel = -1;
ptrVoE = webrtc::VoiceEngine::Create(); voice_engine = webrtc::VoiceEngine::Create();
EXPECT_TRUE(NULL != ptrVoE); EXPECT_TRUE(NULL != voice_engine);
ptrVoEBase = webrtc::VoEBase::GetInterface(ptrVoE); voe_base = webrtc::VoEBase::GetInterface(voice_engine);
EXPECT_TRUE(NULL != ptrVoEBase); EXPECT_TRUE(NULL != voe_base);
EXPECT_EQ(0, ptrVoEBase->Init()); EXPECT_EQ(0, voe_base->Init());
audioChannel = ptrVoEBase->CreateChannel(); audio_channel = voe_base->CreateChannel();
EXPECT_NE(-1, audioChannel); EXPECT_NE(-1, audio_channel);
// Connect before setting VoE. // Connect before setting VoE.
EXPECT_NE(0, ptrViEBase->ConnectAudioChannel(videoChannel, audioChannel)) << EXPECT_NE(0, vie_base->ConnectAudioChannel(video_channel, audio_channel))
"Should fail since Voice Engine is not set yet."; << "Should fail since Voice Engine is not set yet.";
// Then do it right. // Then do it right.
EXPECT_EQ(0, ptrViEBase->SetVoiceEngine(ptrVoE)); EXPECT_EQ(0, vie_base->SetVoiceEngine(voice_engine));
EXPECT_EQ(0, ptrViEBase->ConnectAudioChannel(videoChannel, audioChannel)); EXPECT_EQ(0, vie_base->ConnectAudioChannel(video_channel, audio_channel));
// *************************************************************** // ***************************************************************
// Testing finished. Tear down Video Engine // Testing finished. Tear down Video Engine
// *************************************************************** // ***************************************************************
EXPECT_NE(0, ptrViEBase->DisconnectAudioChannel(videoChannel + 5)) << EXPECT_NE(0, vie_base->DisconnectAudioChannel(video_channel + 5)) <<
"Should fail: disconnecting bogus channel"; "Should fail: disconnecting bogus channel";
EXPECT_EQ(0, ptrViEBase->DisconnectAudioChannel(videoChannel)); EXPECT_EQ(0, vie_base->DisconnectAudioChannel(video_channel));
// Clean up voice engine // Clean up voice engine
EXPECT_EQ(0, ptrVieNetwork->Release()); EXPECT_EQ(0, vie_network->Release());
EXPECT_EQ(0, ptrViEBase->SetVoiceEngine(NULL)); EXPECT_EQ(0, vie_base->SetVoiceEngine(NULL));
// VoiceEngine reference counting is per object, not per interface, so // VoiceEngine reference counting is per object, not per interface, so
// Release should return != 0. // Release should return != 0.
EXPECT_NE(0, ptrVoEBase->Release()); EXPECT_NE(0, voe_base->Release());
EXPECT_TRUE(webrtc::VoiceEngine::Delete(ptrVoE)); EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine));
webrtc::ViEBase* ptrViEBase2 = webrtc::ViEBase::GetInterface(ptrViE); webrtc::ViEBase* vie_base2 = webrtc::ViEBase::GetInterface(video_engine);
EXPECT_TRUE(NULL != ptrViEBase2); EXPECT_TRUE(NULL != vie_base2);
EXPECT_EQ(1, ptrViEBase->Release()) << "There should be one interface left."; EXPECT_EQ(1, vie_base->Release()) <<
"There should be one interface left.";
EXPECT_FALSE(webrtc::VideoEngine::Delete(ptrViE)) << EXPECT_FALSE(webrtc::VideoEngine::Delete(video_engine)) <<
"Should fail since there are interfaces left."; "Should fail since there are interfaces left.";
EXPECT_EQ(0, ptrViEBase->Release()); EXPECT_EQ(0, vie_base->Release());
EXPECT_TRUE(webrtc::VideoEngine::Delete(ptrViE)); EXPECT_TRUE(webrtc::VideoEngine::Delete(video_engine));
} }

View File

@ -8,43 +8,39 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "vie_autotest.h" #include "common_types.h" // NOLINT
#include "engine_configurations.h" // NOLINT
#include "common_types.h"
#include "engine_configurations.h"
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "tb_interfaces.h" #include "modules/video_capture/main/interface/video_capture_factory.h"
#include "tb_video_channel.h" #include "system_wrappers/interface/tick_util.h"
#include "tick_util.h" #include "video_engine/include/vie_base.h"
#include "vie_autotest_defines.h" #include "video_engine/include/vie_capture.h"
#include "video_capture_factory.h" #include "video_engine/include/vie_codec.h"
#include "vie_base.h" #include "video_engine/include/vie_network.h"
#include "vie_capture.h" #include "video_engine/include/vie_render.h"
#include "vie_codec.h" #include "video_engine/include/vie_rtp_rtcp.h"
#include "vie_network.h" #include "video_engine/test/auto_test/interface/vie_autotest.h"
#include "vie_render.h" #include "video_engine/test/auto_test/interface/vie_autotest_defines.h"
#include "vie_rtp_rtcp.h" #include "video_engine/test/libvietest/include/tb_interfaces.h"
#include "voe_base.h" #include "video_engine/test/libvietest/include/tb_video_channel.h"
#include "voice_engine/main/interface/voe_base.h"
DEFINE_bool(capture_test_ensure_resolution_alignment_in_capture_device, true, DEFINE_bool(capture_test_ensure_resolution_alignment_in_capture_device, true,
"If true, we will give resolutions slightly below a reasonable " "If true, we will give resolutions slightly below a reasonable "
"value to test the camera's ability to choose a good resolution. " "value to test the camera's ability to choose a good resolution. "
"If false, we will provide reasonable resolutions instead."); "If false, we will provide reasonable resolutions instead.");
class CaptureObserver: public webrtc::ViECaptureObserver class CaptureObserver : public webrtc::ViECaptureObserver {
{
public: public:
CaptureObserver() : CaptureObserver()
_brightness(webrtc::Normal), : brightness_(webrtc::Normal),
_alarm(webrtc::AlarmCleared), alarm_(webrtc::AlarmCleared),
_frameRate(0) {} frame_rate_(0) {}
virtual void BrightnessAlarm(const int captureId, virtual void BrightnessAlarm(const int capture_id,
const webrtc::Brightness brightness) const webrtc::Brightness brightness) {
{ brightness_ = brightness;
_brightness = brightness; switch (brightness) {
switch (brightness)
{
case webrtc::Normal: case webrtc::Normal:
ViETest::Log(" BrightnessAlarm Normal"); ViETest::Log(" BrightnessAlarm Normal");
break; break;
@ -57,30 +53,25 @@ public:
} }
} }
virtual void CapturedFrameRate(const int captureId, virtual void CapturedFrameRate(const int capture_id,
const unsigned char frameRate) const unsigned char frame_rate) {
{ ViETest::Log(" CapturedFrameRate %u", frame_rate);
ViETest::Log(" CapturedFrameRate %u", frameRate); frame_rate_ = frame_rate;
_frameRate = frameRate;
} }
virtual void NoPictureAlarm(const int captureId, virtual void NoPictureAlarm(const int capture_id,
const webrtc::CaptureAlarm alarm) const webrtc::CaptureAlarm alarm) {
{ alarm_ = alarm;
_alarm = alarm; if (alarm == webrtc::AlarmRaised) {
if (alarm == webrtc::AlarmRaised)
{
ViETest::Log("NoPictureAlarm CARaised."); ViETest::Log("NoPictureAlarm CARaised.");
} } else {
else
{
ViETest::Log("NoPictureAlarm CACleared."); ViETest::Log("NoPictureAlarm CACleared.");
} }
} }
webrtc::Brightness _brightness; webrtc::Brightness brightness_;
webrtc::CaptureAlarm _alarm; webrtc::CaptureAlarm alarm_;
unsigned char _frameRate; unsigned char frame_rate_;
}; };
class CaptureEffectFilter : public webrtc::ViEEffectFilter { class CaptureEffectFilter : public webrtc::ViEEffectFilter {
@ -91,11 +82,11 @@ class CaptureEffectFilter: public webrtc::ViEEffectFilter {
expected_height_(expected_height) { expected_height_(expected_height) {
} }
// Implements ViEEffectFilter // Implements video_engineEffectFilter.
virtual int Transform(int size, unsigned char* frameBuffer, virtual int Transform(int size, unsigned char* frame_buffer,
unsigned int timeStamp90KHz, unsigned int width, unsigned int time_stamp90KHz, unsigned int width,
unsigned int height) { unsigned int height) {
EXPECT_TRUE(frameBuffer != NULL); EXPECT_TRUE(frame_buffer != NULL);
EXPECT_EQ(expected_width_, width); EXPECT_EQ(expected_width_, width);
EXPECT_EQ(expected_height_, height); EXPECT_EQ(expected_height_, height);
++number_of_captured_frames_; ++number_of_captured_frames_;
@ -109,66 +100,62 @@ class CaptureEffectFilter: public webrtc::ViEEffectFilter {
unsigned int expected_height_; unsigned int expected_height_;
}; };
void ViEAutoTest::ViECaptureStandardTest() void ViEAutoTest::ViECaptureStandardTest() {
{ /// **************************************************************
//***************************************************************
// Begin create/initialize WebRTC Video Engine for testing // Begin create/initialize WebRTC Video Engine for testing
//*************************************************************** /// **************************************************************
//*************************************************************** /// **************************************************************
// Engine ready. Begin testing class // Engine ready. Begin testing class
//*************************************************************** /// **************************************************************
TbInterfaces ViE("ViECaptureStandardTest"); TbInterfaces video_engine("video_engineCaptureStandardTest");
webrtc::VideoCaptureModule::DeviceInfo* devInfo = webrtc::VideoCaptureModule::DeviceInfo* dev_info =
webrtc::VideoCaptureFactory::CreateDeviceInfo(0); webrtc::VideoCaptureFactory::CreateDeviceInfo(0);
ASSERT_TRUE(devInfo != NULL); ASSERT_TRUE(dev_info != NULL);
int numberOfCaptureDevices = devInfo->NumberOfDevices(); int number_of_capture_devices = dev_info->NumberOfDevices();
ViETest::Log("Number of capture devices %d", numberOfCaptureDevices); ViETest::Log("Number of capture devices %d",
ASSERT_GT(numberOfCaptureDevices, 0) number_of_capture_devices);
ASSERT_GT(number_of_capture_devices, 0)
<< "This test requires a capture device (i.e. a webcam)"; << "This test requires a capture device (i.e. a webcam)";
int captureDeviceId[10]; int capture_device_id[10];
memset(captureDeviceId, 0, sizeof(captureDeviceId)); memset(capture_device_id, 0, sizeof(capture_device_id));
webrtc::VideoCaptureModule* vcpms[10]; webrtc::VideoCaptureModule* vcpms[10];
memset(vcpms, 0, sizeof(vcpms)); memset(vcpms, 0, sizeof(vcpms));
// Check capabilities // Check capabilities
for (int deviceIndex = 0; for (int device_index = 0; device_index < number_of_capture_devices;
deviceIndex < numberOfCaptureDevices; ++device_index) {
++deviceIndex) char device_name[128];
{ char device_unique_name[512];
char deviceName[128];
char deviceUniqueName[512];
EXPECT_EQ(0, devInfo->GetDeviceName(deviceIndex, EXPECT_EQ(0, dev_info->GetDeviceName(device_index,
deviceName, device_name,
sizeof(deviceName), sizeof(device_name),
deviceUniqueName, device_unique_name,
sizeof(deviceUniqueName))); sizeof(device_unique_name)));
ViETest::Log("Found capture device %s\nUnique name %s", deviceName, ViETest::Log("Found capture device %s\nUnique name %s",
deviceUniqueName); device_name, device_unique_name);
#if !defined(WEBRTC_MAC_INTEL) // these functions will return -1 #if !defined(WEBRTC_MAC_INTEL) // these functions will return -1
int numberOfCapabilities = int number_of_capabilities =
devInfo->NumberOfCapabilities(deviceUniqueName); dev_info->NumberOfCapabilities(device_unique_name);
EXPECT_GT(numberOfCapabilities, 0); EXPECT_GT(number_of_capabilities, 0);
for (int capIndex = 0; capIndex < numberOfCapabilities; ++capIndex) for (int cap_index = 0; cap_index < number_of_capabilities; ++cap_index) {
{
webrtc::VideoCaptureCapability capability; webrtc::VideoCaptureCapability capability;
EXPECT_EQ(0, devInfo->GetCapability(deviceUniqueName, capIndex, EXPECT_EQ(0, dev_info->GetCapability(device_unique_name, cap_index,
capability)); capability));
ViETest::Log("Capture capability %d (of %u)", capIndex + 1, ViETest::Log("Capture capability %d (of %u)", cap_index + 1,
numberOfCapabilities); number_of_capabilities);
ViETest::Log("witdh %d, height %d, frame rate %d", ViETest::Log("witdh %d, height %d, frame rate %d",
capability.width, capability.height, capability.maxFPS); capability.width, capability.height, capability.maxFPS);
ViETest::Log("expected delay %d, color type %d, encoding %d", ViETest::Log("expected delay %d, color type %d, encoding %d",
capability.expectedCaptureDelay, capability.rawType, capability.expectedCaptureDelay, capability.rawType,
capability.codecType); capability.codecType);
EXPECT_GT(capability.width, 0); EXPECT_GT(capability.width, 0);
EXPECT_GT(capability.height, 0); EXPECT_GT(capability.height, 0);
EXPECT_GT(capability.maxFPS, -1); // >= 0 EXPECT_GT(capability.maxFPS, -1); // >= 0
@ -180,40 +167,35 @@ void ViEAutoTest::ViECaptureStandardTest()
#if !defined(WEBRTC_MAC_INTEL) #if !defined(WEBRTC_MAC_INTEL)
// Check allocation. Try to allocate them all after each other. // Check allocation. Try to allocate them all after each other.
for (int deviceIndex = 0; for (int device_index = 0; device_index < number_of_capture_devices;
deviceIndex < numberOfCaptureDevices; ++device_index) {
++deviceIndex) char device_name[128];
{ char device_unique_name[512];
char deviceName[128]; EXPECT_EQ(0, dev_info->GetDeviceName(device_index,
char deviceUniqueName[512]; device_name,
sizeof(device_name),
EXPECT_EQ(0, devInfo->GetDeviceName(deviceIndex, device_unique_name,
deviceName, sizeof(device_unique_name)));
sizeof(deviceName),
deviceUniqueName,
sizeof(deviceUniqueName)));
webrtc::VideoCaptureModule* vcpm = webrtc::VideoCaptureModule* vcpm =
webrtc::VideoCaptureFactory::Create( webrtc::VideoCaptureFactory::Create(device_index, device_unique_name);
deviceIndex, deviceUniqueName);
EXPECT_TRUE(vcpm != NULL); EXPECT_TRUE(vcpm != NULL);
vcpm->AddRef(); vcpm->AddRef();
vcpms[deviceIndex] = vcpm; vcpms[device_index] = vcpm;
EXPECT_EQ(0, ViE.capture->AllocateCaptureDevice( EXPECT_EQ(0, video_engine.capture->AllocateCaptureDevice(
*vcpm, captureDeviceId[deviceIndex])); *vcpm, capture_device_id[device_index]));
webrtc::VideoCaptureCapability capability; webrtc::VideoCaptureCapability capability;
EXPECT_EQ(0, devInfo->GetCapability(deviceUniqueName, 0, capability)); EXPECT_EQ(0, dev_info->GetCapability(device_unique_name, 0, capability));
// Test that the camera select the closest capability to the selected // Test that the camera select the closest capability to the selected
// width and height. // width and height.
CaptureEffectFilter filter(capability.width, capability.height); CaptureEffectFilter filter(capability.width, capability.height);
EXPECT_EQ(0, ViE.image_process->RegisterCaptureEffectFilter( EXPECT_EQ(0, video_engine.image_process->RegisterCaptureEffectFilter(
captureDeviceId[deviceIndex], filter)); capture_device_id[device_index], filter));
ViETest::Log("Testing Device %s capability width %d height %d", ViETest::Log("Testing Device %s capability width %d height %d",
deviceUniqueName, capability.width, capability.height); device_unique_name, capability.width, capability.height);
if (FLAGS_capture_test_ensure_resolution_alignment_in_capture_device) { if (FLAGS_capture_test_ensure_resolution_alignment_in_capture_device) {
// This tests that the capture device properly aligns to a // This tests that the capture device properly aligns to a
@ -222,53 +204,51 @@ void ViEAutoTest::ViECaptureStandardTest()
capability.width = capability.width - 2; capability.width = capability.width - 2;
} }
webrtc::CaptureCapability vieCapability; webrtc::CaptureCapability vie_capability;
vieCapability.width = capability.width; vie_capability.width = capability.width;
vieCapability.height = capability.height; vie_capability.height = capability.height;
vieCapability.codecType = capability.codecType; vie_capability.codecType = capability.codecType;
vieCapability.maxFPS = capability.maxFPS; vie_capability.maxFPS = capability.maxFPS;
vieCapability.rawType = capability.rawType; vie_capability.rawType = capability.rawType;
EXPECT_EQ(0, ViE.capture->StartCapture(captureDeviceId[deviceIndex], EXPECT_EQ(0, video_engine.capture->StartCapture(
vieCapability)); capture_device_id[device_index], vie_capability));
webrtc::TickTime startTime = webrtc::TickTime::Now(); webrtc::TickTime start_time = webrtc::TickTime::Now();
while (filter.number_of_captured_frames_ < 10 while (filter.number_of_captured_frames_ < 10 &&
&& (webrtc::TickTime::Now() - startTime).Milliseconds() < 10000) (webrtc::TickTime::Now() - start_time).Milliseconds() < 10000) {
{
AutoTestSleep(100); AutoTestSleep(100);
} }
EXPECT_GT(filter.number_of_captured_frames_, 9) << EXPECT_GT(filter.number_of_captured_frames_, 9)
"Should capture at least some frames"; << "Should capture at least some frames";
EXPECT_EQ(0, ViE.image_process->DeregisterCaptureEffectFilter( EXPECT_EQ(0, video_engine.image_process->DeregisterCaptureEffectFilter(
captureDeviceId[deviceIndex])); capture_device_id[device_index]));
#ifdef WEBRTC_ANDROID // Can only allocate one camera at the time on Android. #ifdef WEBRTC_ANDROID // Can only allocate one camera at the time on Android.
EXPECT_EQ(0, ViE.capture->StopCapture(captureDeviceId[deviceIndex])); EXPECT_EQ(0, video_engine.capture->StopCapture(
EXPECT_EQ(0, ViE.capture->ReleaseCaptureDevice( capture_device_id[device_index]));
captureDeviceId[deviceIndex])); EXPECT_EQ(0, video_engine.capture->ReleaseCaptureDevice(
capture_device_id[device_index]));
#endif #endif
} }
//*************************************************************** /// **************************************************************
// Testing finished. Tear down Video Engine // Testing finished. Tear down Video Engine
//*************************************************************** /// **************************************************************
// Stop all started capture devices. // Stop all started capture devices.
for (int deviceIndex = 0; for (int device_index = 0; device_index < number_of_capture_devices;
deviceIndex < numberOfCaptureDevices; ++device_index) {
++deviceIndex) {
#if !defined(WEBRTC_ANDROID) #if !defined(WEBRTC_ANDROID)
// Don't stop on Android since we can only allocate one camera. // Don't stop on Android since we can only allocate one camera.
EXPECT_EQ(0, ViE.capture->StopCapture( EXPECT_EQ(0, video_engine.capture->StopCapture(
captureDeviceId[deviceIndex])); capture_device_id[device_index]));
EXPECT_EQ(0, ViE.capture->ReleaseCaptureDevice( EXPECT_EQ(0, video_engine.capture->ReleaseCaptureDevice(
captureDeviceId[deviceIndex])); capture_device_id[device_index]));
#endif // !WEBRTC_ANDROID #endif // !WEBRTC_ANDROID
vcpms[deviceIndex]->Release(); vcpms[device_index]->Release();
} }
#endif // !WEBRTC_MAC_INTEL #endif // !WEBRTC_MAC_INTEL
} }
@ -279,285 +259,278 @@ void ViEAutoTest::ViECaptureExtendedTest() {
ViECaptureExternalCaptureTest(); ViECaptureExternalCaptureTest();
} }
void ViEAutoTest::ViECaptureAPITest() void ViEAutoTest::ViECaptureAPITest() {
{ /// **************************************************************
//***************************************************************
// Begin create/initialize WebRTC Video Engine for testing // Begin create/initialize WebRTC Video Engine for testing
//*************************************************************** /// **************************************************************
//*************************************************************** /// **************************************************************
// Engine ready. Begin testing class // Engine ready. Begin testing class
//*************************************************************** /// **************************************************************
TbInterfaces ViE("ViECaptureAPITest"); TbInterfaces video_engine("video_engineCaptureAPITest");
ViE.capture->NumberOfCaptureDevices(); video_engine.capture->NumberOfCaptureDevices();
char deviceName[128]; char device_name[128];
char deviceUniqueName[512]; char device_unique_name[512];
int captureId = 0; int capture_id = 0;
webrtc::VideoCaptureModule::DeviceInfo* devInfo = webrtc::VideoCaptureModule::DeviceInfo* dev_info =
webrtc::VideoCaptureFactory::CreateDeviceInfo(0); webrtc::VideoCaptureFactory::CreateDeviceInfo(0);
ASSERT_TRUE(devInfo != NULL); ASSERT_TRUE(dev_info != NULL);
ASSERT_GT(devInfo->NumberOfDevices(), 0u) ASSERT_GT(dev_info->NumberOfDevices(), 0u)
<< "This test requires a capture device (i.e. a webcam)"; << "This test requires a capture device (i.e. a webcam)";
// Get the first capture device // Get the first capture device
EXPECT_EQ(0, devInfo->GetDeviceName(0, deviceName, EXPECT_EQ(0, dev_info->GetDeviceName(0, device_name,
sizeof(deviceName), sizeof(device_name),
deviceUniqueName, device_unique_name,
sizeof(deviceUniqueName))); sizeof(device_unique_name)));
webrtc::VideoCaptureModule* vcpm = webrtc::VideoCaptureModule* vcpm =
webrtc::VideoCaptureFactory::Create(0, deviceUniqueName); webrtc::VideoCaptureFactory::Create(0, device_unique_name);
vcpm->AddRef(); vcpm->AddRef();
EXPECT_TRUE(vcpm != NULL); EXPECT_TRUE(vcpm != NULL);
// Allocate capture device. // Allocate capture device.
EXPECT_EQ(0, ViE.capture->AllocateCaptureDevice(*vcpm, captureId)); EXPECT_EQ(0, video_engine.capture->AllocateCaptureDevice(*vcpm, capture_id));
// Start the capture device. // Start the capture device.
EXPECT_EQ(0, ViE.capture->StartCapture(captureId)); EXPECT_EQ(0, video_engine.capture->StartCapture(capture_id));
// Start again. Should fail. // Start again. Should fail.
EXPECT_NE(0, ViE.capture->StartCapture(captureId)); EXPECT_NE(0, video_engine.capture->StartCapture(capture_id));
EXPECT_EQ(kViECaptureDeviceAlreadyStarted, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceAlreadyStarted, video_engine.LastError());
// Start invalid capture device. // Start invalid capture device.
EXPECT_NE(0, ViE.capture->StartCapture(captureId + 1)); EXPECT_NE(0, video_engine.capture->StartCapture(capture_id + 1));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Stop invalid capture device. // Stop invalid capture device.
EXPECT_NE(0, ViE.capture->StopCapture(captureId + 1)); EXPECT_NE(0, video_engine.capture->StopCapture(capture_id + 1));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Stop the capture device. // Stop the capture device.
EXPECT_EQ(0, ViE.capture->StopCapture(captureId)); EXPECT_EQ(0, video_engine.capture->StopCapture(capture_id));
// Stop the capture device again. // Stop the capture device again.
EXPECT_NE(0, ViE.capture->StopCapture(captureId)); EXPECT_NE(0, video_engine.capture->StopCapture(capture_id));
EXPECT_EQ(kViECaptureDeviceNotStarted, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceNotStarted, video_engine.LastError());
// Connect to invalid channel. // Connect to invalid channel.
EXPECT_NE(0, ViE.capture->ConnectCaptureDevice(captureId, 0)); EXPECT_NE(0, video_engine.capture->ConnectCaptureDevice(capture_id, 0));
EXPECT_EQ(kViECaptureDeviceInvalidChannelId, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceInvalidChannelId,
video_engine.LastError());
TbVideoChannel channel(ViE); TbVideoChannel channel(video_engine);
// Connect invalid captureId. // Connect invalid capture_id.
EXPECT_NE(0, ViE.capture->ConnectCaptureDevice(captureId + 1, EXPECT_NE(0, video_engine.capture->ConnectCaptureDevice(capture_id + 1,
channel.videoChannel)); channel.videoChannel));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Connect the capture device to the channel. // Connect the capture device to the channel.
EXPECT_EQ(0, ViE.capture->ConnectCaptureDevice(captureId, EXPECT_EQ(0, video_engine.capture->ConnectCaptureDevice(capture_id,
channel.videoChannel)); channel.videoChannel));
// Connect the channel again. // Connect the channel again.
EXPECT_NE(0, ViE.capture->ConnectCaptureDevice(captureId, EXPECT_NE(0, video_engine.capture->ConnectCaptureDevice(capture_id,
channel.videoChannel)); channel.videoChannel));
EXPECT_EQ(kViECaptureDeviceAlreadyConnected, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceAlreadyConnected,
video_engine.LastError());
// Start the capture device. // Start the capture device.
EXPECT_EQ(0, ViE.capture->StartCapture(captureId)); EXPECT_EQ(0, video_engine.capture->StartCapture(capture_id));
// Release invalid capture device. // Release invalid capture device.
EXPECT_NE(0, ViE.capture->ReleaseCaptureDevice(captureId + 1)); EXPECT_NE(0, video_engine.capture->ReleaseCaptureDevice(capture_id + 1));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Release the capture device. // Release the capture device.
EXPECT_EQ(0, ViE.capture->ReleaseCaptureDevice(captureId)); EXPECT_EQ(0, video_engine.capture->ReleaseCaptureDevice(capture_id));
// Release the capture device again. // Release the capture device again.
EXPECT_NE(0, ViE.capture->ReleaseCaptureDevice(captureId)); EXPECT_NE(0, video_engine.capture->ReleaseCaptureDevice(capture_id));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Test GetOrientation. // Test GetOrientation.
webrtc::VideoCaptureRotation orientation; webrtc::VideoCaptureRotation orientation;
char dummy_name[5]; char dummy_name[5];
EXPECT_NE(0, devInfo->GetOrientation(dummy_name, orientation)); EXPECT_NE(0, dev_info->GetOrientation(dummy_name, orientation));
// Test SetRotation. // Test SetRotation.
EXPECT_NE(0, ViE.capture->SetRotateCapturedFrames( EXPECT_NE(0, video_engine.capture->SetRotateCapturedFrames(
captureId, webrtc::RotateCapturedFrame_90)); capture_id, webrtc::RotateCapturedFrame_90));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
// Allocate capture device. // Allocate capture device.
EXPECT_EQ(0, ViE.capture->AllocateCaptureDevice(*vcpm, captureId)); EXPECT_EQ(0, video_engine.capture->AllocateCaptureDevice(*vcpm, capture_id));
EXPECT_EQ(0, ViE.capture->SetRotateCapturedFrames( EXPECT_EQ(0, video_engine.capture->SetRotateCapturedFrames(
captureId, webrtc::RotateCapturedFrame_0)); capture_id, webrtc::RotateCapturedFrame_0));
EXPECT_EQ(0, ViE.capture->SetRotateCapturedFrames( EXPECT_EQ(0, video_engine.capture->SetRotateCapturedFrames(
captureId, webrtc::RotateCapturedFrame_90)); capture_id, webrtc::RotateCapturedFrame_90));
EXPECT_EQ(0, ViE.capture->SetRotateCapturedFrames( EXPECT_EQ(0, video_engine.capture->SetRotateCapturedFrames(
captureId, webrtc::RotateCapturedFrame_180)); capture_id, webrtc::RotateCapturedFrame_180));
EXPECT_EQ(0, ViE.capture->SetRotateCapturedFrames( EXPECT_EQ(0, video_engine.capture->SetRotateCapturedFrames(
captureId, webrtc::RotateCapturedFrame_270)); capture_id, webrtc::RotateCapturedFrame_270));
// Release the capture device // Release the capture device
EXPECT_EQ(0, ViE.capture->ReleaseCaptureDevice(captureId)); EXPECT_EQ(0, video_engine.capture->ReleaseCaptureDevice(capture_id));
//*************************************************************** /// **************************************************************
// Testing finished. Tear down Video Engine // Testing finished. Tear down Video Engine
//*************************************************************** /// **************************************************************
delete devInfo; delete dev_info;
vcpm->Release(); vcpm->Release();
} }
void ViEAutoTest::ViECaptureExternalCaptureTest() void ViEAutoTest::ViECaptureExternalCaptureTest() {
{ /// **************************************************************
//***************************************************************
// Begin create/initialize WebRTC Video Engine for testing // Begin create/initialize WebRTC Video Engine for testing
//*************************************************************** /// **************************************************************
TbInterfaces ViE("ViECaptureExternalCaptureTest"); TbInterfaces video_engine("video_engineCaptureExternalCaptureTest");
TbVideoChannel channel(ViE); TbVideoChannel channel(video_engine);
channel.StartReceive(); channel.StartReceive();
channel.StartSend(); channel.StartSend();
webrtc::VideoCaptureExternal* externalCapture; webrtc::VideoCaptureExternal* external_capture = NULL;
int captureId = 0; int capture_id = 0;
// Allocate the external capture device. // Allocate the external capture device.
webrtc::VideoCaptureModule* vcpm = webrtc::VideoCaptureFactory::Create( webrtc::VideoCaptureModule* vcpm =
0, externalCapture); webrtc::VideoCaptureFactory::Create(0, external_capture);
EXPECT_TRUE(vcpm != NULL); EXPECT_TRUE(vcpm != NULL);
EXPECT_TRUE(externalCapture != NULL); EXPECT_TRUE(external_capture != NULL);
vcpm->AddRef(); vcpm->AddRef();
EXPECT_EQ(0, ViE.capture->AllocateCaptureDevice(*vcpm, captureId)); EXPECT_EQ(0, video_engine.capture->AllocateCaptureDevice(*vcpm, capture_id));
// Connect the capture device to the channel. // Connect the capture device to the channel.
EXPECT_EQ(0, ViE.capture->ConnectCaptureDevice(captureId, EXPECT_EQ(0, video_engine.capture->ConnectCaptureDevice(capture_id,
channel.videoChannel)); channel.videoChannel));
// Render the local capture. // Render the local capture.
EXPECT_EQ(0, ViE.render->AddRenderer(captureId, _window1, 1, 0.0, 0.0, EXPECT_EQ(0, video_engine.render->AddRenderer(capture_id, _window1, 1, 0.0,
1.0, 1.0)); 0.0, 1.0, 1.0));
// Render the remote capture. // Render the remote capture.
EXPECT_EQ(0, ViE.render->AddRenderer(channel.videoChannel, _window2, 1, EXPECT_EQ(0, video_engine.render->AddRenderer(channel.videoChannel, _window2,
0.0, 0.0, 1.0, 1.0)); 1, 0.0, 0.0, 1.0, 1.0));
EXPECT_EQ(0, ViE.render->StartRender(captureId)); EXPECT_EQ(0, video_engine.render->StartRender(capture_id));
EXPECT_EQ(0, ViE.render->StartRender(channel.videoChannel)); EXPECT_EQ(0, video_engine.render->StartRender(channel.videoChannel));
// Register observer. // Register observer.
CaptureObserver observer; CaptureObserver observer;
EXPECT_EQ(0, ViE.capture->RegisterObserver(captureId, observer)); EXPECT_EQ(0, video_engine.capture->RegisterObserver(capture_id, observer));
// Enable brightness alarm. // Enable brightness alarm.
EXPECT_EQ(0, ViE.capture->EnableBrightnessAlarm(captureId, true)); EXPECT_EQ(0, video_engine.capture->EnableBrightnessAlarm(capture_id, true));
CaptureEffectFilter effectFilter(176, 144); CaptureEffectFilter effect_filter(176, 144);
EXPECT_EQ(0, ViE.image_process->RegisterCaptureEffectFilter(captureId, EXPECT_EQ(0, video_engine.image_process->RegisterCaptureEffectFilter(
effectFilter)); capture_id, effect_filter));
// Call started. // Call started.
ViETest::Log("You should see local preview from external capture\n" ViETest::Log("You should see local preview from external capture\n"
"in window 1 and the remote video in window 2.\n"); "in window 1 and the remote video in window 2.\n");
//*************************************************************** /// **************************************************************
// Engine ready. Begin testing class // Engine ready. Begin testing class
//*************************************************************** /// **************************************************************
const unsigned int videoFrameLength = (176 * 144 * 3) / 2; const unsigned int video_frame_length = (176 * 144 * 3) / 2;
unsigned char* videoFrame = new unsigned char[videoFrameLength]; unsigned char* video_frame = new unsigned char[video_frame_length];
memset(videoFrame, 128, 176 * 144); memset(video_frame, 128, 176 * 144);
int frameCount = 0; int frame_count = 0;
webrtc::VideoCaptureCapability capability; webrtc::VideoCaptureCapability capability;
capability.width = 176; capability.width = 176;
capability.height = 144; capability.height = 144;
capability.rawType = webrtc::kVideoI420; capability.rawType = webrtc::kVideoI420;
ViETest::Log("Testing external capturing and frame rate callbacks."); ViETest::Log("Testing external capturing and frame rate callbacks.");
// TODO: Change when using a real file! // TODO(mflodman) Change when using a real file!
// while (fread(videoFrame, videoFrameLength, 1, foreman) == 1) // while (fread(video_frame, video_frame_length, 1, foreman) == 1)
while (frameCount < 120) while (frame_count < 120) {
{ external_capture->IncomingFrame(
externalCapture->IncomingFrame( video_frame, video_frame_length, capability,
videoFrame, videoFrameLength, capability,
webrtc::TickTime::Now().MillisecondTimestamp()); webrtc::TickTime::Now().MillisecondTimestamp());
AutoTestSleep(33); AutoTestSleep(33);
if (effectFilter.number_of_captured_frames_ > 2) if (effect_filter.number_of_captured_frames_ > 2) {
{ EXPECT_EQ(webrtc::Normal, observer.brightness_) <<
EXPECT_EQ(webrtc::Normal, observer._brightness) <<
"Brightness or picture alarm should not have been called yet."; "Brightness or picture alarm should not have been called yet.";
EXPECT_EQ(webrtc::AlarmCleared, observer._alarm) << EXPECT_EQ(webrtc::AlarmCleared, observer.alarm_) <<
"Brightness or picture alarm should not have been called yet."; "Brightness or picture alarm should not have been called yet.";
} }
frameCount++; frame_count++;
} }
// Test brightness alarm // Test brightness alarm.
// Test bright image // Test bright image.
for (int i = 0; i < 176 * 144; ++i) for (int i = 0; i < 176 * 144; ++i) {
{ if (video_frame[i] <= 155)
if (videoFrame[i] <= 155) video_frame[i] = video_frame[i] + 100;
videoFrame[i] = videoFrame[i] + 100;
else else
videoFrame[i] = 255; video_frame[i] = 255;
} }
ViETest::Log("Testing Brighness alarm"); ViETest::Log("Testing Brighness alarm");
for (int frame = 0; frame < 30; ++frame) for (int frame = 0; frame < 30; ++frame) {
{ external_capture->IncomingFrame(
externalCapture->IncomingFrame( video_frame, video_frame_length, capability,
videoFrame, videoFrameLength, capability,
webrtc::TickTime::Now().MillisecondTimestamp()); webrtc::TickTime::Now().MillisecondTimestamp());
AutoTestSleep(33); AutoTestSleep(33);
} }
EXPECT_EQ(webrtc::Bright, observer._brightness) << EXPECT_EQ(webrtc::Bright, observer.brightness_) <<
"Should be bright at this point since we are using a bright image."; "Should be bright at this point since we are using a bright image.";
// Test Dark image // Test Dark image
for (int i = 0; i < 176 * 144; ++i) for (int i = 0; i < 176 * 144; ++i) {
{ video_frame[i] = video_frame[i] > 200 ? video_frame[i] - 200 : 0;
videoFrame[i] = videoFrame[i] > 200 ? videoFrame[i] - 200 : 0;
} }
for (int frame = 0; frame < 30; ++frame) for (int frame = 0; frame < 30; ++frame) {
{ external_capture->IncomingFrame(
externalCapture->IncomingFrame( video_frame, video_frame_length, capability,
videoFrame, videoFrameLength, capability,
webrtc::TickTime::Now().MillisecondTimestamp()); webrtc::TickTime::Now().MillisecondTimestamp());
AutoTestSleep(33); AutoTestSleep(33);
} }
EXPECT_EQ(webrtc::Dark, observer._brightness) << EXPECT_EQ(webrtc::Dark, observer.brightness_) <<
"Should be dark at this point since we are using a dark image."; "Should be dark at this point since we are using a dark image.";
EXPECT_GT(effectFilter.number_of_captured_frames_, 150) << EXPECT_GT(effect_filter.number_of_captured_frames_, 150) <<
"Frames should have been played."; "Frames should have been played.";
EXPECT_GE(observer._frameRate, 29) << EXPECT_GE(observer.frame_rate_, 29) <<
"Frame rate callback should be approximately correct."; "Frame rate callback should be approximately correct.";
EXPECT_LE(observer._frameRate, 30) << EXPECT_LE(observer.frame_rate_, 30) <<
"Frame rate callback should be approximately correct."; "Frame rate callback should be approximately correct.";
// Test no picture alarm // Test no picture alarm
ViETest::Log("Testing NoPictureAlarm."); ViETest::Log("Testing NoPictureAlarm.");
AutoTestSleep(1050); AutoTestSleep(1050);
EXPECT_EQ(webrtc::AlarmRaised, observer._alarm) << EXPECT_EQ(webrtc::AlarmRaised, observer.alarm_) <<
"No picture alarm should be raised."; "No picture alarm should be raised.";
for (int frame = 0; frame < 10; ++frame) for (int frame = 0; frame < 10; ++frame) {
{ external_capture->IncomingFrame(
externalCapture->IncomingFrame( video_frame, video_frame_length, capability,
videoFrame, videoFrameLength, capability,
webrtc::TickTime::Now().MillisecondTimestamp()); webrtc::TickTime::Now().MillisecondTimestamp());
AutoTestSleep(33); AutoTestSleep(33);
} }
EXPECT_EQ(webrtc::AlarmCleared, observer._alarm) << EXPECT_EQ(webrtc::AlarmCleared, observer.alarm_) <<
"Alarm should be cleared since ge just got some data."; "Alarm should be cleared since ge just got some data.";
delete videoFrame; delete video_frame;
// Release the capture device // Release the capture device
EXPECT_EQ(0, ViE.capture->ReleaseCaptureDevice(captureId)); EXPECT_EQ(0, video_engine.capture->ReleaseCaptureDevice(capture_id));
// Release the capture device again // Release the capture device again
EXPECT_NE(0, ViE.capture->ReleaseCaptureDevice(captureId)); EXPECT_NE(0, video_engine.capture->ReleaseCaptureDevice(capture_id));
EXPECT_EQ(kViECaptureDeviceDoesNotExist, ViE.LastError()); EXPECT_EQ(kViECaptureDeviceDoesNotExist, video_engine.LastError());
vcpm->Release(); vcpm->Release();
//*************************************************************** /// **************************************************************
// Testing finished. Tear down Video Engine // Testing finished. Tear down Video Engine
//*************************************************************** /// **************************************************************
} }

View File

@ -8,24 +8,24 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "vie_autotest_defines.h" #include "common_types.h" // NOLINT
#include "vie_autotest.h" #include "engine_configurations.h" // NOLINT
#include "engine_configurations.h" #include "video_engine/test/auto_test/interface/vie_autotest_defines.h"
#include "video_engine/test/auto_test/interface/vie_autotest.h"
#include "video_engine/test/libvietest/include/tb_capture_device.h"
#include "video_engine/test/libvietest/include/tb_I420_codec.h"
#include "video_engine/test/libvietest/include/tb_interfaces.h"
#include "video_engine/test/libvietest/include/tb_video_channel.h"
#include "video_engine/include/vie_base.h"
#include "video_engine/include/vie_capture.h"
#include "video_engine/include/vie_codec.h"
#include "video_engine/include/vie_network.h"
#include "video_engine/include/vie_render.h"
#include "video_engine/include/vie_rtp_rtcp.h"
#include "voice_engine/main/interface/voe_base.h"
#include "common_types.h" class TestCodecObserver
#include "tb_capture_device.h" : public webrtc::ViEEncoderObserver,
#include "tb_I420_codec.h"
#include "tb_interfaces.h"
#include "tb_video_channel.h"
#include "vie_base.h"
#include "vie_capture.h"
#include "vie_codec.h"
#include "vie_network.h"
#include "vie_render.h"
#include "vie_rtp_rtcp.h"
#include "voe_base.h"
class TestCodecObserver : public webrtc::ViEEncoderObserver,
public webrtc::ViEDecoderObserver { public webrtc::ViEDecoderObserver {
public: public:
int incoming_codec_called_; int incoming_codec_called_;
@ -33,8 +33,8 @@ public:
int outgoing_rate_called_; int outgoing_rate_called_;
unsigned char last_payload_type_; unsigned char last_payload_type_;
unsigned short last_width_; uint16_t last_width_;
unsigned short last_height_; uint16_t last_height_;
unsigned int last_outgoing_framerate_; unsigned int last_outgoing_framerate_;
unsigned int last_outgoing_bitrate_; unsigned int last_outgoing_bitrate_;
@ -43,44 +43,46 @@ public:
webrtc::VideoCodec incoming_codec_; webrtc::VideoCodec incoming_codec_;
TestCodecObserver() { TestCodecObserver()
incoming_codec_called_ = 0; : incoming_codec_called_(0),
incoming_rate_called_ = 0; incoming_rate_called_(0),
outgoing_rate_called_ = 0; outgoing_rate_called_(0),
last_payload_type_ = 0; last_payload_type_(0),
last_width_ = 0; last_width_(0),
last_height_ = 0; last_height_(0),
last_outgoing_framerate_ = 0; last_outgoing_framerate_(0),
last_outgoing_bitrate_ = 0; last_outgoing_bitrate_(0),
last_incoming_framerate_ = 0; last_incoming_framerate_(0),
last_incoming_bitrate_ = 0; last_incoming_bitrate_(0) {
memset(&incoming_codec_, 0, sizeof(incoming_codec_)); memset(&incoming_codec_, 0, sizeof(incoming_codec_));
} }
virtual void IncomingCodecChanged(const int videoChannel, virtual void IncomingCodecChanged(const int video_channel,
const webrtc::VideoCodec& videoCodec) { const webrtc::VideoCodec& video_codec) {
incoming_codec_called_++; incoming_codec_called_++;
last_payload_type_ = videoCodec.plType; last_payload_type_ = video_codec.plType;
last_width_ = videoCodec.width; last_width_ = video_codec.width;
last_height_ = videoCodec.height; last_height_ = video_codec.height;
memcpy(&incoming_codec_, &videoCodec, sizeof(videoCodec)); memcpy(&incoming_codec_, &video_codec, sizeof(video_codec));
} }
virtual void IncomingRate(const int videoChannel, virtual void IncomingRate(const int video_channel,
const unsigned int framerate, const unsigned int bitrate) { const unsigned int framerate,
const unsigned int bitrate) {
incoming_rate_called_++; incoming_rate_called_++;
last_incoming_framerate_ += framerate; last_incoming_framerate_ += framerate;
last_incoming_bitrate_ += bitrate; last_incoming_bitrate_ += bitrate;
} }
virtual void OutgoingRate(const int videoChannel, virtual void OutgoingRate(const int video_channel,
const unsigned int framerate, const unsigned int bitrate) { const unsigned int framerate,
const unsigned int bitrate) {
outgoing_rate_called_++; outgoing_rate_called_++;
last_outgoing_framerate_ += framerate; last_outgoing_framerate_ += framerate;
last_outgoing_bitrate_ += bitrate; last_outgoing_bitrate_ += bitrate;
} }
virtual void RequestNewKeyFrame(const int videoChannel) { virtual void RequestNewKeyFrame(const int video_channel) {
} }
}; };
@ -99,8 +101,11 @@ public:
virtual ~RenderFilter() { virtual ~RenderFilter() {
} }
virtual int Transform(int size, unsigned char* frameBuffer, virtual int Transform(int size,
unsigned int timeStamp90KHz, unsigned int width, unsigned int height) { unsigned char* frame_buffer,
unsigned int time_stamp90KHz,
unsigned int width,
unsigned int height) {
num_frames_++; num_frames_++;
last_render_width_ = width; last_render_width_ = width;
last_render_height_ = height; last_render_height_ = height;
@ -131,10 +136,10 @@ void ViEAutoTest::ViECodecStandardTest() {
EXPECT_EQ(0, rtp_rtcp->SetKeyFrameRequestMethod( EXPECT_EQ(0, rtp_rtcp->SetKeyFrameRequestMethod(
video_channel, webrtc::kViEKeyFrameRequestPliRtcp)); video_channel, webrtc::kViEKeyFrameRequestPliRtcp));
EXPECT_EQ(0, rtp_rtcp->SetTMMBRStatus(video_channel, true)); EXPECT_EQ(0, rtp_rtcp->SetTMMBRStatus(video_channel, true));
EXPECT_EQ(0, render->AddRenderer( EXPECT_EQ(0, render->AddRenderer(capture_id, _window1, 0, 0.0, 0.0, 1.0,
capture_id, _window1, 0, 0.0, 0.0, 1.0, 1.0)); 1.0));
EXPECT_EQ(0, render->AddRenderer( EXPECT_EQ(0, render->AddRenderer(video_channel, _window2, 1, 0.0, 0.0, 1.0,
video_channel, _window2, 1, 0.0, 0.0, 1.0, 1.0)); 1.0));
EXPECT_EQ(0, render->StartRender(capture_id)); EXPECT_EQ(0, render->StartRender(capture_id));
EXPECT_EQ(0, render->StartRender(video_channel)); EXPECT_EQ(0, render->StartRender(video_channel));
@ -142,7 +147,6 @@ void ViEAutoTest::ViECodecStandardTest() {
memset(&video_codec, 0, sizeof(webrtc::VideoCodec)); memset(&video_codec, 0, sizeof(webrtc::VideoCodec));
for (int idx = 0; idx < codec->NumberOfCodecs(); idx++) { for (int idx = 0; idx < codec->NumberOfCodecs(); idx++) {
EXPECT_EQ(0, codec->GetCodec(idx, video_codec)); EXPECT_EQ(0, codec->GetCodec(idx, video_codec));
if (video_codec.codecType != webrtc::kVideoCodecI420) { if (video_codec.codecType != webrtc::kVideoCodecI420) {
video_codec.width = 640; video_codec.width = 640;
video_codec.height = 480; video_codec.height = 480;
@ -163,22 +167,19 @@ void ViEAutoTest::ViECodecStandardTest() {
} }
const char* ip_address = "127.0.0.1"; const char* ip_address = "127.0.0.1";
const unsigned short rtp_port = 6000; const uint16_t rtp_port = 6000;
EXPECT_EQ(0, network->SetLocalReceiver(video_channel, rtp_port)); EXPECT_EQ(0, network->SetLocalReceiver(video_channel, rtp_port));
EXPECT_EQ(0, base->StartReceive(video_channel)); EXPECT_EQ(0, base->StartReceive(video_channel));
EXPECT_EQ(0, network->SetSendDestination( EXPECT_EQ(0, network->SetSendDestination(
video_channel, ip_address, rtp_port)); video_channel, ip_address, rtp_port));
EXPECT_EQ(0, base->StartSend(video_channel)); EXPECT_EQ(0, base->StartSend(video_channel));
//
// Make sure all codecs runs // Make sure all codecs runs
//
{ {
webrtc::ViEImageProcess* image_process = webrtc::ViEImageProcess* image_process =
webrtc::ViEImageProcess::GetInterface(video_engine); webrtc::ViEImageProcess::GetInterface(video_engine);
TestCodecObserver codec_observer; TestCodecObserver codec_observer;
EXPECT_EQ(0, codec->RegisterDecoderObserver( EXPECT_EQ(0, codec->RegisterDecoderObserver(video_channel, codec_observer));
video_channel, codec_observer));
ViETest::Log("Loop through all codecs for %d seconds", ViETest::Log("Loop through all codecs for %d seconds",
KAutoTestSleepTimeMs / 1000); KAutoTestSleepTimeMs / 1000);
@ -194,8 +195,8 @@ void ViEAutoTest::ViECodecStandardTest() {
ViETest::Log("\t %d. %s", i, video_codec.plName); ViETest::Log("\t %d. %s", i, video_codec.plName);
RenderFilter frame_counter; RenderFilter frame_counter;
EXPECT_EQ(0, image_process->RegisterRenderEffectFilter( EXPECT_EQ(0, image_process->RegisterRenderEffectFilter(video_channel,
video_channel, frame_counter)); frame_counter));
AutoTestSleep(KAutoTestSleepTimeMs); AutoTestSleep(KAutoTestSleepTimeMs);
// Verify we've received and decoded correct payload. // Verify we've received and decoded correct payload.
@ -211,8 +212,7 @@ void ViEAutoTest::ViECodecStandardTest() {
} else { } else {
#ifdef WEBRTC_ANDROID #ifdef WEBRTC_ANDROID
// To get the autotest to pass on some slow devices // To get the autotest to pass on some slow devices
EXPECT_GT( EXPECT_GT(frame_counter.num_frames_, max_number_of_possible_frames / 6);
frame_counter.num_frames_, max_number_of_possible_frames / 6);
#else #else
EXPECT_GT(frame_counter.num_frames_, max_number_of_possible_frames / 4); EXPECT_GT(frame_counter.num_frames_, max_number_of_possible_frames / 4);
#endif #endif
@ -226,15 +226,10 @@ void ViEAutoTest::ViECodecStandardTest() {
ViETest::Log("Done!"); ViETest::Log("Done!");
} }
//
// Test Callbacks // Test Callbacks
// TestCodecObserver codec_observer;
EXPECT_EQ(0, codec->RegisterEncoderObserver(video_channel, codec_observer));
TestCodecObserver codecObserver; EXPECT_EQ(0, codec->RegisterDecoderObserver(video_channel, codec_observer));
EXPECT_EQ(0, codec->RegisterEncoderObserver(
video_channel, codecObserver));
EXPECT_EQ(0, codec->RegisterDecoderObserver(
video_channel, codecObserver));
ViETest::Log("\nTesting codec callbacks..."); ViETest::Log("\nTesting codec callbacks...");
@ -251,9 +246,9 @@ void ViEAutoTest::ViECodecStandardTest() {
EXPECT_EQ(0, codec->DeregisterEncoderObserver(video_channel)); EXPECT_EQ(0, codec->DeregisterEncoderObserver(video_channel));
EXPECT_EQ(0, codec->DeregisterDecoderObserver(video_channel)); EXPECT_EQ(0, codec->DeregisterDecoderObserver(video_channel));
EXPECT_GT(codecObserver.incoming_codec_called_, 0); EXPECT_GT(codec_observer.incoming_codec_called_, 0);
EXPECT_GT(codecObserver.incoming_rate_called_, 0); EXPECT_GT(codec_observer.incoming_rate_called_, 0);
EXPECT_GT(codecObserver.outgoing_rate_called_, 0); EXPECT_GT(codec_observer.outgoing_rate_called_, 0);
EXPECT_EQ(0, base->StopReceive(video_channel)); EXPECT_EQ(0, base->StopReceive(video_channel));
EXPECT_EQ(0, render->StopRender(video_channel)); EXPECT_EQ(0, render->StopRender(video_channel));
@ -292,11 +287,11 @@ void ViEAutoTest::ViECodecExtendedTest() {
EXPECT_EQ(0, rtp_rtcp->SetKeyFrameRequestMethod( EXPECT_EQ(0, rtp_rtcp->SetKeyFrameRequestMethod(
video_channel, webrtc::kViEKeyFrameRequestPliRtcp)); video_channel, webrtc::kViEKeyFrameRequestPliRtcp));
EXPECT_EQ(0, rtp_rtcp->SetTMMBRStatus(video_channel, true)); EXPECT_EQ(0, rtp_rtcp->SetTMMBRStatus(video_channel, true));
EXPECT_EQ(0, render->AddRenderer( EXPECT_EQ(0, render->AddRenderer(capture_id, _window1, 0, 0.0, 0.0, 1.0,
capture_id, _window1, 0, 0.0, 0.0, 1.0, 1.0)); 1.0));
EXPECT_EQ(0, render->AddRenderer( EXPECT_EQ(0, render->AddRenderer(video_channel, _window2, 1, 0.0, 0.0, 1.0,
video_channel, _window2, 1, 0.0, 0.0, 1.0, 1.0)); 1.0));
EXPECT_EQ(0, render->StartRender(capture_id)); EXPECT_EQ(0, render->StartRender(capture_id));
EXPECT_EQ(0, render->StartRender(video_channel)); EXPECT_EQ(0, render->StartRender(video_channel));
@ -312,16 +307,14 @@ void ViEAutoTest::ViECodecExtendedTest() {
} }
const char* ip_address = "127.0.0.1"; const char* ip_address = "127.0.0.1";
const unsigned short rtp_port = 6000; const uint16_t rtp_port = 6000;
EXPECT_EQ(0, network->SetLocalReceiver(video_channel, rtp_port)); EXPECT_EQ(0, network->SetLocalReceiver(video_channel, rtp_port));
EXPECT_EQ(0, base->StartReceive(video_channel)); EXPECT_EQ(0, base->StartReceive(video_channel));
EXPECT_EQ(0, network->SetSendDestination( EXPECT_EQ(0, network->SetSendDestination(
video_channel, ip_address, rtp_port)); video_channel, ip_address, rtp_port));
EXPECT_EQ(0, base->StartSend(video_channel)); EXPECT_EQ(0, base->StartSend(video_channel));
//
// Codec specific tests // Codec specific tests
//
memset(&video_codec, 0, sizeof(webrtc::VideoCodec)); memset(&video_codec, 0, sizeof(webrtc::VideoCodec));
EXPECT_EQ(0, base->StopSend(video_channel)); EXPECT_EQ(0, base->StopSend(video_channel));
@ -337,16 +330,13 @@ void ViEAutoTest::ViECodecExtendedTest() {
EXPECT_EQ(0, base->DeleteChannel(video_channel)); EXPECT_EQ(0, base->DeleteChannel(video_channel));
} }
//
// Multiple send channels. // Multiple send channels.
//
{ {
// Create two channels, where the second channel is created from the // Create two channels, where the second channel is created from the
// first channel. Send different resolutions on the channels and verify // first channel. Send different resolutions on the channels and verify
// the received streams. // the received streams.
TbInterfaces video_engine("ViECodecExtendedTest2"); TbInterfaces video_engine("ViECodecExtendedTest2");
TbCaptureDevice tbCapture(video_engine); TbCaptureDevice tb_capture(video_engine);
// Create channel 1. // Create channel 1.
int video_channel_1 = -1; int video_channel_1 = -1;
@ -359,8 +349,8 @@ void ViEAutoTest::ViECodecExtendedTest() {
EXPECT_NE(video_channel_1, video_channel_2) EXPECT_NE(video_channel_1, video_channel_2)
<< "Channel 2 should be unique."; << "Channel 2 should be unique.";
unsigned short rtp_port_1 = 12000; uint16_t rtp_port_1 = 12000;
unsigned short rtp_port_2 = 13000; uint16_t rtp_port_2 = 13000;
EXPECT_EQ(0, video_engine.network->SetLocalReceiver( EXPECT_EQ(0, video_engine.network->SetLocalReceiver(
video_channel_1, rtp_port_1)); video_channel_1, rtp_port_1));
EXPECT_EQ(0, video_engine.network->SetSendDestination( EXPECT_EQ(0, video_engine.network->SetSendDestination(
@ -369,47 +359,46 @@ void ViEAutoTest::ViECodecExtendedTest() {
video_channel_2, rtp_port_2)); video_channel_2, rtp_port_2));
EXPECT_EQ(0, video_engine.network->SetSendDestination( EXPECT_EQ(0, video_engine.network->SetSendDestination(
video_channel_2, "127.0.0.1", rtp_port_2)); video_channel_2, "127.0.0.1", rtp_port_2));
tb_capture.ConnectTo(video_channel_1);
tbCapture.ConnectTo(video_channel_1); tb_capture.ConnectTo(video_channel_2);
tbCapture.ConnectTo(video_channel_2);
EXPECT_EQ(0, video_engine.rtp_rtcp->SetKeyFrameRequestMethod( EXPECT_EQ(0, video_engine.rtp_rtcp->SetKeyFrameRequestMethod(
video_channel_1, webrtc::kViEKeyFrameRequestPliRtcp)); video_channel_1, webrtc::kViEKeyFrameRequestPliRtcp));
EXPECT_EQ(0, video_engine.rtp_rtcp->SetKeyFrameRequestMethod( EXPECT_EQ(0, video_engine.rtp_rtcp->SetKeyFrameRequestMethod(
video_channel_2, webrtc::kViEKeyFrameRequestPliRtcp)); video_channel_2, webrtc::kViEKeyFrameRequestPliRtcp));
EXPECT_EQ(0, video_engine.render->AddRenderer( EXPECT_EQ(0, video_engine.render->AddRenderer(video_channel_1, _window1, 0,
video_channel_1, _window1, 0, 0.0, 0.0, 1.0, 1.0)); 0.0, 0.0, 1.0, 1.0));
EXPECT_EQ(0, video_engine.render->StartRender(video_channel_1)); EXPECT_EQ(0, video_engine.render->StartRender(video_channel_1));
EXPECT_EQ(0, video_engine.render->AddRenderer( EXPECT_EQ(0, video_engine.render->AddRenderer(video_channel_2, _window2, 0,
video_channel_2, _window2, 0, 0.0, 0.0, 1.0, 1.0)); 0.0, 0.0, 1.0, 1.0));
EXPECT_EQ(0, video_engine.render->StartRender(video_channel_2)); EXPECT_EQ(0, video_engine.render->StartRender(video_channel_2));
// Set Send codec // Set Send codec.
unsigned short codecWidth = 320; uint16_t codec_width = 320;
unsigned short codecHeight = 240; uint16_t codec_height = 240;
bool codecSet = false; bool codec_set = false;
webrtc::VideoCodec videoCodec; webrtc::VideoCodec video_codec;
webrtc::VideoCodec sendCodec1; webrtc::VideoCodec send_codec1;
webrtc::VideoCodec sendCodec2; webrtc::VideoCodec send_codec2;
for (int idx = 0; idx < video_engine.codec->NumberOfCodecs(); idx++) { for (int idx = 0; idx < video_engine.codec->NumberOfCodecs(); idx++) {
EXPECT_EQ(0, video_engine.codec->GetCodec(idx, videoCodec)); EXPECT_EQ(0, video_engine.codec->GetCodec(idx, video_codec));
EXPECT_EQ(0, video_engine.codec->SetReceiveCodec( EXPECT_EQ(0, video_engine.codec->SetReceiveCodec(video_channel_1,
video_channel_1, videoCodec)); video_codec));
if (videoCodec.codecType == webrtc::kVideoCodecVP8) { if (video_codec.codecType == webrtc::kVideoCodecVP8) {
memcpy(&sendCodec1, &videoCodec, sizeof(videoCodec)); memcpy(&send_codec1, &video_codec, sizeof(video_codec));
sendCodec1.width = codecWidth; send_codec1.width = codec_width;
sendCodec1.height = codecHeight; send_codec1.height = codec_height;
EXPECT_EQ(0, video_engine.codec->SetSendCodec( EXPECT_EQ(0, video_engine.codec->SetSendCodec(
video_channel_1, sendCodec1)); video_channel_1, send_codec1));
memcpy(&sendCodec2, &videoCodec, sizeof(videoCodec)); memcpy(&send_codec2, &video_codec, sizeof(video_codec));
sendCodec2.width = 2 * codecWidth; send_codec2.width = 2 * codec_width;
sendCodec2.height = 2 * codecHeight; send_codec2.height = 2 * codec_height;
EXPECT_EQ(0, video_engine.codec->SetSendCodec( EXPECT_EQ(0, video_engine.codec->SetSendCodec(
video_channel_2, sendCodec2)); video_channel_2, send_codec2));
codecSet = true; codec_set = true;
break; break;
} }
}EXPECT_TRUE(codecSet); }
EXPECT_TRUE(codec_set);
// We need to verify using render effect filter since we won't trigger // We need to verify using render effect filter since we won't trigger
// a decode reset in loopback (due to using the same SSRC). // a decode reset in loopback (due to using the same SSRC).
@ -436,10 +425,10 @@ void ViEAutoTest::ViECodecExtendedTest() {
video_channel_1)); video_channel_1));
EXPECT_EQ(0, video_engine.image_process->DeregisterRenderEffectFilter( EXPECT_EQ(0, video_engine.image_process->DeregisterRenderEffectFilter(
video_channel_2)); video_channel_2));
EXPECT_EQ(sendCodec1.width, filter1.last_render_width_); EXPECT_EQ(send_codec1.width, filter1.last_render_width_);
EXPECT_EQ(sendCodec1.height, filter1.last_render_height_); EXPECT_EQ(send_codec1.height, filter1.last_render_height_);
EXPECT_EQ(sendCodec2.width, filter2.last_render_width_); EXPECT_EQ(send_codec2.width, filter2.last_render_width_);
EXPECT_EQ(sendCodec2.height, filter2.last_render_height_); EXPECT_EQ(send_codec2.height, filter2.last_render_height_);
EXPECT_EQ(0, video_engine.base->DeleteChannel(video_channel_1)); EXPECT_EQ(0, video_engine.base->DeleteChannel(video_channel_1));
EXPECT_EQ(0, video_engine.base->DeleteChannel(video_channel_2)); EXPECT_EQ(0, video_engine.base->DeleteChannel(video_channel_2));
@ -467,7 +456,6 @@ void ViEAutoTest::ViECodecAPITest() {
for (int i = 0; i < number_of_codecs; i++) { for (int i = 0; i < number_of_codecs; i++) {
EXPECT_EQ(0, codec->GetCodec(i, video_codec)); EXPECT_EQ(0, codec->GetCodec(i, video_codec));
if (video_codec.codecType == webrtc::kVideoCodecVP8) { if (video_codec.codecType == webrtc::kVideoCodecVP8) {
EXPECT_EQ(0, codec->SetSendCodec(video_channel, video_codec)); EXPECT_EQ(0, codec->SetSendCodec(video_channel, video_codec));
break; break;
@ -496,38 +484,37 @@ void ViEAutoTest::ViECodecAPITest() {
} }
#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
#include "vie_external_codec.h" #include "video_engine/include/vie_external_codec.h"
#endif #endif
void ViEAutoTest::ViECodecExternalCodecTest() { void ViEAutoTest::ViECodecExternalCodecTest() {
ViETest::Log(" "); ViETest::Log(" ");
ViETest::Log("========================================"); ViETest::Log("========================================");
ViETest::Log(" ViEExternalCodec Test\n"); ViETest::Log(" ViEExternalCodec Test\n");
//*************************************************************** /// **************************************************************
// Begin create/initialize WebRTC Video Engine for testing // Begin create/initialize WebRTC Video Engine for testing
//*************************************************************** /// **************************************************************
//*************************************************************** /// **************************************************************
// Engine ready. Begin testing class // Engine ready. Begin testing class
//*************************************************************** /// **************************************************************
#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
int numberOfErrors=0; int number_of_errors = 0;
{ {
int error = 0; int error = 0;
TbInterfaces ViE("ViEExternalCodec"); TbInterfaces ViE("ViEExternalCodec");
TbCaptureDevice captureDevice(ViE); TbCaptureDevice capture_device(ViE);
TbVideoChannel channel(ViE, webrtc::kVideoCodecI420, TbVideoChannel channel(ViE, webrtc::kVideoCodecI420, 352, 288, 30,
352,288,30,(352*288*3*8*30)/(2*1000)); (352 * 288 * 3 * 8 * 30) / (2 * 1000));
capture_device.ConnectTo(channel.videoChannel);
captureDevice.ConnectTo(channel.videoChannel); error = ViE.render->AddRenderer(channel.videoChannel, _window1, 0, 0.0, 0.0,
1.0, 1.0);
error = ViE.render->AddRenderer(channel.videoChannel, _window1, 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
0.0, 0.0, 1.0, 1.0);
numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ViE.render->StartRender(channel.videoChannel); error = ViE.render->StartRender(channel.videoChannel);
numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d", number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
channel.StartReceive(); channel.StartReceive();
@ -536,223 +523,208 @@ void ViEAutoTest::ViECodecExternalCodecTest() {
ViETest::Log("Using internal I420 codec"); ViETest::Log("Using internal I420 codec");
AutoTestSleep(KAutoTestSleepTimeMs / 2); AutoTestSleep(KAutoTestSleepTimeMs / 2);
webrtc::ViEExternalCodec* ptrViEExtCodec = webrtc::ViEExternalCodec* vie_external_codec =
webrtc::ViEExternalCodec::GetInterface(ViE.video_engine); webrtc::ViEExternalCodec::GetInterface(ViE.video_engine);
numberOfErrors += ViETest::TestError(ptrViEExtCodec != NULL, number_of_errors += ViETest::TestError(vie_external_codec != NULL,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
webrtc::VideoCodec codec_struct;
webrtc::VideoCodec codecStruct;
error = ViE.codec->GetSendCodec(channel.videoChannel, codecStruct); error = ViE.codec->GetSendCodec(channel.videoChannel, codecStruct);
numberOfErrors += ViETest::TestError(ptrViEExtCodec != NULL, number_of_errors += ViETest::TestError(vie_external_codec != NULL,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Use external encoder instead // Use external encoder instead.
{ {
TbI420Encoder extEncoder; TbI420Encoder ext_encoder;
// Test to register on wrong channel // Test to register on wrong channel.
error = ptrViEExtCodec->RegisterExternalSendCodec( error = vie_external_codec->RegisterExternalSendCodec(
channel.videoChannel+5,codecStruct.plType,&extEncoder); channel.videoChannel + 5, codecStruct.plType, &ext_encoder);
numberOfErrors += ViETest::TestError(error == -1, number_of_errors += ViETest::TestError(error == -1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
ViE.LastError() == kViECodecInvalidArgument, ViE.LastError() == kViECodecInvalidArgument,
"ERROR: %s at line %d", __FUNCTION__, __LINE__); "ERROR: %s at line %d", __FUNCTION__, __LINE__);
error = ptrViEExtCodec->RegisterExternalSendCodec( error = vie_external_codec->RegisterExternalSendCodec(
channel.videoChannel,codecStruct.plType,&extEncoder); channel.videoChannel, codecStruct.plType, &ext_encoder);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Use new external encoder // Use new external encoder
error = ViE.codec->SetSendCodec(channel.videoChannel, codecStruct); error = ViE.codec->SetSendCodec(channel.videoChannel, codecStruct);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
TbI420Decoder extDecoder; TbI420Decoder ext_decoder;
error = ptrViEExtCodec->RegisterExternalReceiveCodec( error = vie_external_codec->RegisterExternalReceiveCodec(
channel.videoChannel,codecStruct.plType,&extDecoder); channel.videoChannel, codecStruct.plType, &ext_decoder);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ViE.codec->SetReceiveCodec(channel.videoChannel, error = ViE.codec->SetReceiveCodec(channel.videoChannel, codec_struct);
codecStruct); number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
numberOfErrors += ViETest::TestError(error == 0,
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
ViETest::Log("Using external I420 codec"); ViETest::Log("Using external I420 codec");
AutoTestSleep(KAutoTestSleepTimeMs); AutoTestSleep(KAutoTestSleepTimeMs);
// Test to deregister on wrong channel // Test to deregister on wrong channel
error = ptrViEExtCodec->DeRegisterExternalSendCodec( error = vie_external_codec->DeRegisterExternalSendCodec(
channel.videoChannel + 5, codecStruct.plType); channel.videoChannel + 5, codecStruct.plType);
numberOfErrors += ViETest::TestError(error == -1, number_of_errors += ViETest::TestError(error == -1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
ViE.LastError() == kViECodecInvalidArgument, ViE.LastError() == kViECodecInvalidArgument, "ERROR: %s at line %d",
"ERROR: %s at line %d", __FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Test to deregister wrong payload type. // Test to deregister wrong payload type.
error = ptrViEExtCodec->DeRegisterExternalSendCodec( error = vie_external_codec->DeRegisterExternalSendCodec(
channel.videoChannel, codecStruct.plType - 1); channel.videoChannel, codecStruct.plType - 1);
numberOfErrors += ViETest::TestError(error == -1, number_of_errors += ViETest::TestError(error == -1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Deregister external send codec // Deregister external send codec
error = ptrViEExtCodec->DeRegisterExternalSendCodec( error = vie_external_codec->DeRegisterExternalSendCodec(
channel.videoChannel, codecStruct.plType); channel.videoChannel, codecStruct.plType);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d", __FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ptrViEExtCodec->DeRegisterExternalReceiveCodec( error = vie_external_codec->DeRegisterExternalReceiveCodec(
channel.videoChannel, codecStruct.plType); channel.videoChannel, codecStruct.plType);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Verify that the encoder and decoder has been used // Verify that the encoder and decoder has been used
TbI420Encoder::FunctionCalls encodeCalls = TbI420Encoder::FunctionCalls encode_calls =
extEncoder.GetFunctionCalls(); ext_encoder.GetFunctionCalls();
numberOfErrors += ViETest::TestError(encodeCalls.InitEncode == 1, number_of_errors += ViETest::TestError(encode_calls.InitEncode == 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.Release == 1, number_of_errors += ViETest::TestError(encode_calls.Release == 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.Encode > 30, number_of_errors += ViETest::TestError(encode_calls.Encode > 30,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
encodeCalls.RegisterEncodeCompleteCallback ==1, encode_calls.RegisterEncodeCompleteCallback == 1,
"ERROR: %s at line %d", __FUNCTION__, __LINE__); "ERROR: %s at line %d", __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.SetRates > 1, number_of_errors += ViETest::TestError(encode_calls.SetRates > 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.SetPacketLoss > 1, number_of_errors += ViETest::TestError(encode_calls.SetPacketLoss > 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
TbI420Decoder::FunctionCalls decodeCalls = TbI420Decoder::FunctionCalls decode_calls =
extDecoder.GetFunctionCalls(); ext_decoder.GetFunctionCalls();
numberOfErrors += ViETest::TestError(decodeCalls.InitDecode == 1, number_of_errors += ViETest::TestError(decode_calls.InitDecode == 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(decodeCalls.Release == 1, number_of_errors += ViETest::TestError(decode_calls.Release == 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(decodeCalls.Decode > 30, number_of_errors += ViETest::TestError(decode_calls.Decode > 30,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
decodeCalls.RegisterDecodeCompleteCallback ==1, decode_calls.RegisterDecodeCompleteCallback == 1,
"ERROR: %s at line %d", __FUNCTION__, __LINE__); "ERROR: %s at line %d", __FUNCTION__, __LINE__);
ViETest::Log("Changing payload type Using external I420 codec"); ViETest::Log("Changing payload type Using external I420 codec");
codecStruct.plType=codecStruct.plType-1; codec_struct.plType = codecStruct.plType - 1;
error = ptrViEExtCodec->RegisterExternalReceiveCodec( error = vie_external_codec->RegisterExternalReceiveCodec(
channel.videoChannel, codecStruct.plType, &extDecoder); channel.videoChannel, codec_struct.plType, &ext_decoder);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ViE.codec->SetReceiveCodec(channel.videoChannel, error = ViE.codec->SetReceiveCodec(channel.videoChannel,
codecStruct); codec_struct);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ptrViEExtCodec->RegisterExternalSendCodec( error = vie_external_codec->RegisterExternalSendCodec(
channel.videoChannel, codecStruct.plType, &extEncoder); channel.videoChannel, codec_struct.plType, &ext_encoder);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Use new external encoder // Use new external encoder
error = ViE.codec->SetSendCodec(channel.videoChannel, error = ViE.codec->SetSendCodec(channel.videoChannel,
codecStruct); codec_struct);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
AutoTestSleep(KAutoTestSleepTimeMs / 2); AutoTestSleep(KAutoTestSleepTimeMs / 2);
//*************************************************************** /// **************************************************************
// Testing finished. Tear down Video Engine // Testing finished. Tear down Video Engine
//*************************************************************** /// **************************************************************
error = ptrViEExtCodec->DeRegisterExternalSendCodec( error = vie_external_codec->DeRegisterExternalSendCodec(
channel.videoChannel, codecStruct.plType); channel.videoChannel, codecStruct.plType);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = ptrViEExtCodec->DeRegisterExternalReceiveCodec( error = vie_external_codec->DeRegisterExternalReceiveCodec(
channel.videoChannel, codecStruct.plType); channel.videoChannel, codecStruct.plType);
numberOfErrors += ViETest::TestError(error == 0, number_of_errors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
"ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
// Verify that the encoder and decoder has been used // Verify that the encoder and decoder has been used
encodeCalls = extEncoder.GetFunctionCalls(); encode_calls = ext_encoder.GetFunctionCalls();
numberOfErrors += ViETest::TestError(encodeCalls.InitEncode == 2, number_of_errors += ViETest::TestError(encode_calls.InitEncode == 2,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.Release == 2, number_of_errors += ViETest::TestError(encode_calls.Release == 2,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.Encode > 30, number_of_errors += ViETest::TestError(encode_calls.Encode > 30,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
encodeCalls.RegisterEncodeCompleteCallback == 2, encode_calls.RegisterEncodeCompleteCallback == 2,
"ERROR: %s at line %d", __FUNCTION__, __LINE__); "ERROR: %s at line %d", __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.SetRates > 1, number_of_errors += ViETest::TestError(encode_calls.SetRates > 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(encodeCalls.SetPacketLoss > 1, number_of_errors += ViETest::TestError(encode_calls.SetPacketLoss > 1,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
decodeCalls = extDecoder.GetFunctionCalls(); decode_calls = ext_decoder.GetFunctionCalls();
numberOfErrors += ViETest::TestError(decodeCalls.InitDecode == 2, number_of_errors += ViETest::TestError(decode_calls.InitDecode == 2,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(decodeCalls.Release == 2, number_of_errors += ViETest::TestError(decode_calls.Release == 2,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError(decodeCalls.Decode > 30, number_of_errors += ViETest::TestError(decode_calls.Decode > 30,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
numberOfErrors += ViETest::TestError( number_of_errors += ViETest::TestError(
decodeCalls.RegisterDecodeCompleteCallback == 2, decode_calls.RegisterDecodeCompleteCallback == 2,
"ERROR: %s at line %d", __FUNCTION__, __LINE__); "ERROR: %s at line %d", __FUNCTION__, __LINE__);
int remainingInterfaces = ptrViEExtCodec->Release(); int remaining_interfaces = vie_external_codec->Release();
numberOfErrors += ViETest::TestError(remainingInterfaces == 0, number_of_errors += ViETest::TestError(remaining_interfaces == 0,
"ERROR: %s at line %d", "ERROR: %s at line %d",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} // tbI420Encoder and extDecoder goes out of scope } // tbI420Encoder and ext_decoder goes out of scope.
ViETest::Log("Using internal I420 codec"); ViETest::Log("Using internal I420 codec");
AutoTestSleep(KAutoTestSleepTimeMs / 2); AutoTestSleep(KAutoTestSleepTimeMs / 2);
} }
if (numberOfErrors > 0) if (number_of_errors > 0) {
{
// Test failed // Test failed
ViETest::Log(" "); ViETest::Log(" ");
ViETest::Log(" ERROR ViEExternalCodec Test FAILED!"); ViETest::Log(" ERROR ViEExternalCodec Test FAILED!");
ViETest::Log(" Number of errors: %d", numberOfErrors); ViETest::Log(" Number of errors: %d", number_of_errors);
ViETest::Log("========================================"); ViETest::Log("========================================");
ViETest::Log(" "); ViETest::Log(" ");
return; return;