Refactor webrtc specific Event implementation to an EventFactory.

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3664 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org
2013-03-13 08:46:25 +00:00
parent b7edd06530
commit 2baf5f5fa0
26 changed files with 248 additions and 289 deletions

View File

@ -11,20 +11,19 @@
// Implementation of codec data base test
// testing is done via the VCM module, no specific CodecDataBase module functionality.
#include "codec_database_test.h"
#include "webrtc/modules/video_coding/main/test/codec_database_test.h"
#include <assert.h>
#include <stdio.h>
#include "../../../../engine_configurations.h"
#include "../source/event.h"
#include "test_callbacks.h"
#include "test_macros.h"
#include "test_util.h"
#include "testsupport/fileutils.h"
#include "testsupport/metrics/video_metrics.h"
#include "vp8.h" // for external codecs test
#include "webrtc/engine_configurations.h"
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_callbacks.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/metrics/video_metrics.h"
using namespace webrtc;

View File

@ -8,13 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "receiver_tests.h"
#include "video_coding.h"
#include "rtp_rtcp.h"
#include "trace.h"
#include "../source/event.h"
#include "rtp_player.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/rtp_player.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
@ -35,12 +34,7 @@ private:
int DecodeFromStorageTest(CmdArgs& args)
{
// Make sure this test isn't executed without simulated events.
#if !defined(EVENT_DEBUG)
return -1;
#endif
// BEGIN Settings
bool protectionEnabled = false;
VCMVideoProtection protectionMethod = kProtectionNack;
WebRtc_UWord32 rttMS = 100;
@ -65,9 +59,12 @@ int DecodeFromStorageTest(CmdArgs& args)
SimulatedClock clock(0);
NullEventFactory event_factory;
// TODO(hlundin): This test was not verified after changing to FakeTickTime.
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock);
VideoCodingModule* vcmPlayback = VideoCodingModule::Create(2, &clock);
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock,
&event_factory);
VideoCodingModule* vcmPlayback = VideoCodingModule::Create(2, &clock,
&event_factory);
FrameStorageCallback storageCallback(vcmPlayback);
RtpDataCallback dataCallback(vcm);
WebRtc_Word32 ret = vcm->InitializeReceiver();

View File

@ -8,13 +8,15 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "generic_codec_test.h"
#include "webrtc/modules/video_coding/main/test/generic_codec_test.h"
#include <cmath>
#include <stdio.h>
#include "../source/event.h"
#include "rtp_rtcp.h"
#include "common_video/interface/i420_video_frame.h"
#include "test_macros.h"
#include "webrtc/common_video/interface/i420_video_frame.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/system_wrappers/interface/clock.h"
using namespace webrtc;
@ -23,12 +25,10 @@ enum { kMaxWaitEncTimeMs = 100 };
int GenericCodecTest::RunTest(CmdArgs& args)
{
#if !defined(EVENT_DEBUG)
printf("\n\nEnable debug events to run this test!\n\n");
return -1;
#endif
SimulatedClock clock(0);
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock);
NullEventFactory event_factory;
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock,
&event_factory);
GenericCodecTest* get = new GenericCodecTest(vcm, &clock);
Trace::CreateTrace();
Trace::SetTraceFile(

View File

@ -8,20 +8,20 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include <stdio.h>
#include "webrtc/modules/video_coding/main/test/jitter_estimate_test.h"
#include "common_types.h"
#include "../source/event.h"
#include "frame_buffer.h"
#include "inter_frame_delay.h"
#include "jitter_buffer.h"
#include "jitter_estimate_test.h"
#include "jitter_estimator.h"
#include "media_opt_util.h"
#include "packet.h"
#include "test_util.h"
#include "test_macros.h"
#include <math.h>
#include "webrtc/common_types.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/source/frame_buffer.h"
#include "webrtc/modules/video_coding/main/source/inter_frame_delay.h"
#include "webrtc/modules/video_coding/main/source/jitter_buffer.h"
#include "webrtc/modules/video_coding/main/source/jitter_estimator.h"
#include "webrtc/modules/video_coding/main/source/media_opt_util.h"
#include "webrtc/modules/video_coding/main/source/packet.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/system_wrappers/interface/clock.h"
// TODO(holmer): Get rid of this to conform with style guide.
@ -93,10 +93,6 @@ int CheckOutFrame(VCMEncodedFrame* frameOut, unsigned int size, bool startCode)
int JitterBufferTest(CmdArgs& args)
{
// Don't run these tests with debug event.
#if defined(EVENT_DEBUG)
return -1;
#endif
Clock* clock = Clock::GetRealTimeClock();
// Start test
@ -106,7 +102,8 @@ int JitterBufferTest(CmdArgs& args)
WebRtc_UWord8 data[1500];
VCMPacket packet(data, size, seqNum, timeStamp, true);
VCMJitterBuffer jb(clock, -1, -1, true);
NullEventFactory event_factory;
VCMJitterBuffer jb(clock, &event_factory, -1, -1, true);
seqNum = 1234;
timeStamp = 123*90;

View File

@ -11,19 +11,17 @@
// Implementation of Media Optimization Test
// testing is done via the VCM module, no specific Media opt functionality.
#include "media_opt_test.h"
#include "webrtc/modules/video_coding/main/test/media_opt_test.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <vector>
#include "../source/event.h"
#include "test_macros.h"
#include "test_util.h" // send side callback
#include "testsupport/metrics/video_metrics.h"
#include "video_coding.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/test/testsupport/metrics/video_metrics.h"
using namespace webrtc;
@ -32,8 +30,8 @@ int MediaOptTest::RunTest(int testNum, CmdArgs& args)
Trace::CreateTrace();
Trace::SetTraceFile((test::OutputPath() + "mediaOptTestTrace.txt").c_str());
Trace::SetLevelFilter(webrtc::kTraceAll);
VideoCodingModule* vcm = VideoCodingModule::Create(1);
Clock* clock = Clock::GetRealTimeClock();
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock);
MediaOptTest* mot = new MediaOptTest(vcm, clock);
if (testNum == 0)
{ // regular

View File

@ -16,15 +16,14 @@
#include <string.h>
#include "../source/event.h"
#include "media_opt_test.h"
#include "mt_test_common.h"
#include "receiver_tests.h" // shared RTP state and receive side threads
#include "rtp_rtcp.h"
#include "test_macros.h"
#include "test_util.h" // send side callback
#include "thread_wrapper.h"
#include "video_coding.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/media_opt_test.h"
#include "webrtc/modules/video_coding/main/test/mt_test_common.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
using namespace webrtc;
@ -143,12 +142,11 @@ int MTRxTxTest(CmdArgs& args)
printf("Cannot read file %s.\n", outname.c_str());
return -1;
}
Clock* clock = Clock::GetRealTimeClock();
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock);
VideoCodingModule* vcm = VideoCodingModule::Create(1);
RtpDataCallback dataCallback(vcm);
RTPSendCompleteCallback* outgoingTransport =
new RTPSendCompleteCallback(clock, "dump.rtp");
new RTPSendCompleteCallback(Clock::GetRealTimeClock(), "dump.rtp");
RtpRtcp::Configuration configuration;
configuration.id = 1;

View File

@ -8,40 +8,36 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "normal_test.h"
#include "webrtc/modules/video_coding/main/test/normal_test.h"
#include <assert.h>
#include <iostream>
#include <sstream>
#include <time.h>
#include "../source/event.h"
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "common_types.h"
#include "test_callbacks.h"
#include "test_macros.h"
#include "test_util.h"
#include "trace.h"
#include "testsupport/metrics/video_metrics.h"
#include "webrtc/common_types.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_callbacks.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/test/testsupport/metrics/video_metrics.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
int NormalTest::RunTest(const CmdArgs& args)
{
#if defined(EVENT_DEBUG)
printf("SIMULATION TIME\n");
SimulatedClock sim_clock;
SimulatedClock sim_clock(0);
SimulatedClock* clock = &sim_clock;
#else
printf("REAL-TIME\n");
Clock* clock = Clock::GetRealTimeClock();
#endif
NullEventFactory event_factory;
Trace::CreateTrace();
Trace::SetTraceFile(
(test::OutputPath() + "VCMNormalTestTrace.txt").c_str());
Trace::SetLevelFilter(webrtc::kTraceAll);
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock);
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock,
&event_factory);
NormalTest VCMNTest(vcm, clock);
VCMNTest.Perform(args);
VideoCodingModule::Destroy(vcm);
@ -289,9 +285,6 @@ NormalTest::Perform(const CmdArgs& args)
_vcm->RegisterSendStatisticsCallback(&sendStats);
while (feof(_sourceFile) == 0) {
#if !defined(EVENT_DEBUG)
WebRtc_Word64 processStartTime = _clock->TimeInMilliseconds();
#endif
TEST(fread(tmpBuffer, 1, _lengthSourceFrame, _sourceFile) > 0 ||
feof(_sourceFile));
_frameCnt++;
@ -331,17 +324,7 @@ NormalTest::Perform(const CmdArgs& args)
WebRtc_UWord32 framePeriod =
static_cast<WebRtc_UWord32>(
1000.0f / static_cast<float>(_sendCodec.maxFramerate) + 0.5f);
#if defined(EVENT_DEBUG)
static_cast<SimulatedClock*>(_clock)->AdvanceTimeMilliseconds(framePeriod);
#else
WebRtc_Word64 timeSpent =
_clock->TimeInMilliseconds() - processStartTime;
if (timeSpent < framePeriod)
{
waitEvent->Wait(framePeriod - timeSpent);
}
#endif
}
double endTime = clock()/(double)CLOCKS_PER_SEC;
_testTotalTime = endTime - startTime;

View File

@ -8,29 +8,30 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "quality_modes_test.h"
#include "webrtc/modules/video_coding/main/test/quality_modes_test.h"
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "modules/video_coding/main/source/event.h"
#include "modules/video_coding/main/test/test_callbacks.h"
#include "modules/video_coding/main/test/test_macros.h"
#include "modules/video_coding/main/test/test_util.h"
#include "system_wrappers/interface/data_log.h"
#include "system_wrappers/interface/data_log.h"
#include "testsupport/metrics/video_metrics.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_callbacks.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/data_log.h"
#include "webrtc/system_wrappers/interface/data_log.h"
#include "webrtc/test/testsupport/metrics/video_metrics.h"
using namespace webrtc;
int qualityModeTest(const CmdArgs& args)
{
SimulatedClock clock(0);
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock);
NullEventFactory event_factory;
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock, &event_factory);
QualityModesTest QMTest(vcm, &clock);
QMTest.Perform(args);
VideoCodingModule::Destroy(vcm);

View File

@ -8,19 +8,18 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "receiver_tests.h"
#include "video_coding.h"
#include "trace.h"
#include "../source/event.h"
#include "../source/internal_defines.h"
#include "timing.h"
#include "test_macros.h"
#include "test_util.h"
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/source/internal_defines.h"
#include "webrtc/modules/video_coding/main/source/timing.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
float vcmFloatMax(float a, float b)
@ -48,11 +47,6 @@ public:
int ReceiverTimingTests(CmdArgs& args)
{
// Make sure this test is never executed with simulated events.
#if defined(EVENT_DEBUG)
return -1;
#endif
// Set up trace
Trace::CreateTrace();
Trace::SetTraceFile((test::OutputPath() + "receiverTestTrace.txt").c_str());

View File

@ -18,7 +18,7 @@
#include <arpa/inet.h>
#endif
#include "gtest/gtest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/source/internal_defines.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"

View File

@ -19,8 +19,10 @@
#include <fstream>
#include <cstdlib>
#include "module_common_types.h"
#include "testsupport/fileutils.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/test/testsupport/fileutils.h"
enum { kMaxNackListSize = 250 };
enum { kMaxPacketAgeToNack = 450 };
@ -72,6 +74,31 @@ struct RtpPacket {
WebRtc_Word64 receiveTime;
};
class NullEvent : public webrtc::EventWrapper {
public:
virtual ~NullEvent() {}
virtual bool Set() { return true; }
virtual bool Reset() { return true; }
virtual webrtc::EventTypeWrapper Wait(unsigned long max_time) {
return webrtc::kEventTimeout;
}
virtual bool StartTimer(bool periodic, unsigned long time) { return true; }
virtual bool StopTimer() { return true; }
};
class NullEventFactory : public webrtc::EventFactory {
public:
virtual ~NullEventFactory() {}
virtual webrtc::EventWrapper* CreateEvent() {
return new NullEvent;
}
};
// Codec type conversion
webrtc::RTPVideoCodecTypes

View File

@ -8,24 +8,20 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "google/gflags.h"
#include "receiver_tests.h"
#include "normal_test.h"
#include "codec_database_test.h"
#include "generic_codec_test.h"
#include "../source/event.h"
#include "media_opt_test.h"
#include "quality_modes_test.h"
#include "test_util.h"
#include "webrtc/test/testsupport/fileutils.h"
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
//#include "vld.h"
#endif
#include "google/gflags.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/normal_test.h"
#include "webrtc/modules/video_coding/main/test/codec_database_test.h"
#include "webrtc/modules/video_coding/main/test/generic_codec_test.h"
#include "webrtc/modules/video_coding/main/test/media_opt_test.h"
#include "webrtc/modules/video_coding/main/test/quality_modes_test.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/test/testsupport/fileutils.h"
DEFINE_string(codec, "VP8", "Codec to use (VP8 or I420).");
DEFINE_int32(width, 352, "Width in pixels of the frames in the input file.");

View File

@ -8,21 +8,20 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "receiver_tests.h"
#include "video_coding.h"
#include "rtp_rtcp.h"
#include "trace.h"
#include "../source/event.h"
#include "../source/internal_defines.h"
#include "test_macros.h"
#include "rtp_player.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include <stdio.h>
#include <string.h>
#include <sstream>
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/source/internal_defines.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/modules/video_coding/main/test/rtp_player.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
WebRtc_Word32
@ -112,12 +111,7 @@ std::string FrameReceiveCallback::AppendWidthHeightAndCount(
int RtpPlay(CmdArgs& args)
{
// Make sure this test isn't executed without simulated events.
#if !defined(EVENT_DEBUG)
return -1;
#endif
// BEGIN Settings
bool protectionEnabled = true;
VCMVideoProtection protectionMethod = kProtectionNack;
WebRtc_UWord32 rttMS = 0;
@ -131,7 +125,9 @@ int RtpPlay(CmdArgs& args)
outFile = test::OutputPath() + "RtpPlay_decoded.yuv";
FrameReceiveCallback receiveCallback(outFile);
SimulatedClock clock(0);
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock);
NullEventFactory event_factory;
VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock,
&event_factory);
RtpDataCallback dataCallback(vcm);
RTPPlayer rtpStream(args.inputFile.c_str(), &dataCallback, &clock);

View File

@ -12,11 +12,11 @@
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/source/event.h"
#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
#include "webrtc/modules/video_coding/main/test/rtp_player.h"
#include "webrtc/modules/video_coding/main/test/test_macros.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
@ -61,13 +61,7 @@ bool DecodeThread(void* obj)
int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTestVideoType)
{
// Don't run these tests with debug events.
#if defined(EVENT_DEBUG)
return -1;
#endif
// BEGIN Settings
bool protectionEnabled = true;
VCMVideoProtection protection = kProtectionDualDecoder;
WebRtc_UWord8 rttMS = 50;
@ -83,8 +77,7 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe
(protection == kProtectionDualDecoder ||
protection == kProtectionNack ||
kProtectionNackFEC));
Clock* clock = Clock::GetRealTimeClock();
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock);
VideoCodingModule* vcm = VideoCodingModule::Create(1);
RtpDataCallback dataCallback(vcm);
std::string rtpFilename;
rtpFilename = args.inputFile;
@ -137,7 +130,8 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe
}
printf("Watch %s to verify that the output is reasonable\n", outFilename.c_str());
}
RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback, clock);
RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback,
Clock::GetRealTimeClock());
PayloadTypeList payloadTypes;
payloadTypes.push_front(new PayloadCodecTuple(VCM_VP8_PAYLOAD_TYPE, "VP8",
kVideoCodecVP8));