Splitted FileHandler into FrameReader and FrameWriter classes and moved them to testsupport in test.gyp.
Fixed unit tests so they don't use ASSERT_DEATH since that doesn't work with Valgrind. Fixed all Valgrind warnings except the one caused by CriticalSectionWrapper in system_wrappers. Reworked all includes and GYP include paths to use full directory paths. Removed util.h for logging, since it rendered warnings in Valgrind because of gflags. Replaced it with a verbose flag and a new function in video_quality_measurement.cc BUG= TEST=Passed test_support_unittests and video_codecs_test_framework_unittests on Linux, Mac and Windows. Review URL: http://webrtc-codereview.appspot.com/311001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1126 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
441b3fe2a1
commit
5b97b1216f
@ -7,20 +7,25 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_MOCKS_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_MOCKS_H_
|
||||
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_MOCK_VIDEO_CODEC_INTERFACE_H_
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_MOCK_VIDEO_CODEC_INTERFACE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "file_handler.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "packet_manipulator.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
// This file contains mocks that are used by the unit tests.
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class MockEncodedImageCallback : public EncodedImageCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Encoded,
|
||||
WebRtc_Word32(EncodedImage& encodedImage,
|
||||
const CodecSpecificInfo* codecSpecificInfo,
|
||||
const RTPFragmentationHeader* fragmentation));
|
||||
};
|
||||
|
||||
class MockVideoEncoder : public VideoEncoder {
|
||||
public:
|
||||
MOCK_CONST_METHOD2(Version,
|
||||
@ -48,6 +53,16 @@ class MockVideoEncoder : public VideoEncoder {
|
||||
WebRtc_Word32(WebRtc_UWord8* /*buffer*/, WebRtc_Word32));
|
||||
};
|
||||
|
||||
class MockDecodedImageCallback : public DecodedImageCallback {
|
||||
public:
|
||||
MOCK_METHOD1(Decoded,
|
||||
WebRtc_Word32(RawImage& decodedImage));
|
||||
MOCK_METHOD1(ReceivedDecodedReferenceFrame,
|
||||
WebRtc_Word32(const WebRtc_UWord64 pictureId));
|
||||
MOCK_METHOD1(ReceivedDecodedFrame,
|
||||
WebRtc_Word32(const WebRtc_UWord64 pictureId));
|
||||
};
|
||||
|
||||
class MockVideoDecoder : public VideoDecoder {
|
||||
public:
|
||||
MOCK_METHOD2(InitDecode,
|
||||
@ -68,25 +83,6 @@ class MockVideoDecoder : public VideoDecoder {
|
||||
MOCK_METHOD0(Copy, VideoDecoder*());
|
||||
};
|
||||
|
||||
namespace test {
|
||||
|
||||
class MockFileHandler : public FileHandler {
|
||||
public:
|
||||
MOCK_METHOD0(Init, bool());
|
||||
MOCK_METHOD1(ReadFrame, bool(WebRtc_UWord8* source_buffer));
|
||||
MOCK_METHOD1(WriteFrame, bool(WebRtc_UWord8* frame_buffer));
|
||||
MOCK_METHOD0(Close, void());
|
||||
MOCK_METHOD1(GetFileSize, WebRtc_UWord64(std::string filename));
|
||||
MOCK_METHOD0(GetFrameLength, int());
|
||||
MOCK_METHOD0(GetNumberOfFrames, int());
|
||||
};
|
||||
|
||||
class MockPacketManipulator : public PacketManipulator {
|
||||
public:
|
||||
MOCK_METHOD1(ManipulatePackets, int(webrtc::EncodedImage* encoded_image));
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_MOCKS_H_
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_MOCK_VIDEO_CODEC_INTERFACE_H_
|
@ -8,13 +8,13 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_CODEC_INTERFACE_H
|
||||
#define VIDEO_CODEC_INTERFACE_H
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
|
||||
|
||||
#include "common_types.h"
|
||||
#include "common_video/interface/video_image.h"
|
||||
#include "modules/video_coding/codecs/interface/video_error_codes.h"
|
||||
#include "typedefs.h"
|
||||
#include "video_image.h"
|
||||
#include "video_error_codes.h"
|
||||
|
||||
namespace webrtc
|
||||
{
|
||||
@ -260,4 +260,4 @@ public:
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // VIDEO_CODEC_INTERFACE_H
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
|
||||
|
@ -8,8 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_ERROR_CODES_H
|
||||
#define VIDEO_ERROR_CODES_H
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_ERROR_CODES_H
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_ERROR_CODES_H
|
||||
|
||||
// NOTE: in sync with video_coding_module_defines.h
|
||||
|
||||
@ -27,4 +27,4 @@
|
||||
#define WEBRTC_VIDEO_CODEC_UNINITIALIZED -7
|
||||
#define WEBRTC_VIDEO_CODEC_ERR_REQUEST_SLI -12
|
||||
|
||||
#endif // VIDEO_ERROR_CODES_H
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_ERROR_CODES_H
|
||||
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_FILE_HANDLER_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_FILE_HANDLER_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Handles reading and writing video files for the test framework's needs.
|
||||
class FileHandler {
|
||||
public:
|
||||
virtual ~FileHandler() {}
|
||||
|
||||
// Initializes the file handler, i.e. opens the input and output files etc.
|
||||
// This must be called before reading or writing frames has started.
|
||||
// Returns false if an error has occurred, in addition to printing to stderr.
|
||||
virtual bool Init() = 0;
|
||||
|
||||
// Reads a frame into the supplied buffer, which must contain enough space
|
||||
// for the frame size.
|
||||
// Returns true if there are more frames to read, false if we've already
|
||||
// read the last frame (in the previous call).
|
||||
virtual bool ReadFrame(WebRtc_UWord8* source_buffer) = 0;
|
||||
|
||||
// Writes a frame of the configured frame length to the output file.
|
||||
// Returns true if the write was successful, false otherwise.
|
||||
virtual bool WriteFrame(WebRtc_UWord8* frame_buffer) = 0;
|
||||
|
||||
// Closes the input and output files. Essentially makes this class impossible
|
||||
// to use anymore.
|
||||
virtual void Close() = 0;
|
||||
|
||||
// File size of the supplied file in bytes. Will return 0 if the file is
|
||||
// empty or if the file does not exist/is readable.
|
||||
virtual WebRtc_UWord64 GetFileSize(std::string filename) = 0;
|
||||
// Frame length in bytes of a single frame image.
|
||||
virtual int GetFrameLength() = 0;
|
||||
// Total number of frames in the input video source.
|
||||
virtual int GetNumberOfFrames() = 0;
|
||||
};
|
||||
|
||||
class FileHandlerImpl : public FileHandler {
|
||||
public:
|
||||
// Creates a file handler. The input file is assumed to exist and be readable
|
||||
// and the output file must be writable.
|
||||
FileHandlerImpl(std::string input_filename,
|
||||
std::string output_filename,
|
||||
int frame_length_in_bytes);
|
||||
virtual ~FileHandlerImpl();
|
||||
bool Init();
|
||||
bool ReadFrame(WebRtc_UWord8* source_buffer);
|
||||
bool WriteFrame(WebRtc_UWord8* frame_buffer);
|
||||
void Close();
|
||||
WebRtc_UWord64 GetFileSize(std::string filename);
|
||||
int GetFrameLength() { return frame_length_in_bytes_; }
|
||||
int GetNumberOfFrames() { return number_of_frames_; }
|
||||
|
||||
private:
|
||||
std::string input_filename_;
|
||||
std::string output_filename_;
|
||||
int frame_length_in_bytes_;
|
||||
int number_of_frames_;
|
||||
FILE* input_file_;
|
||||
FILE* output_file_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_FILE_HANDLER_H_
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "file_handler.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "unittest_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
const std::string kInputFilename = "temp_inputfile.tmp";
|
||||
const std::string kOutputFilename = "temp_outputfile.tmp";
|
||||
const std::string kInputFileContents = "baz";
|
||||
// Setting the kFrameLength value to a value much larger than the
|
||||
// file to test causes the ReadFrame test to fail on Windows.
|
||||
const int kFrameLength = 1000;
|
||||
|
||||
// Boilerplate code for proper unit tests for FileHandler.
|
||||
class FileHandlerTest: public testing::Test {
|
||||
protected:
|
||||
FileHandler* file_handler_;
|
||||
|
||||
FileHandlerTest() {
|
||||
// To avoid warnings when using ASSERT_DEATH
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
}
|
||||
|
||||
virtual ~FileHandlerTest() {
|
||||
}
|
||||
|
||||
void SetUp() {
|
||||
// Cleanup any existing files:
|
||||
std::remove(kInputFilename.c_str());
|
||||
std::remove(kOutputFilename.c_str());
|
||||
|
||||
// Create a dummy input file:
|
||||
FILE* dummy = fopen(kInputFilename.c_str(), "wb");
|
||||
fprintf(dummy, "%s", kInputFileContents.c_str());
|
||||
fclose(dummy);
|
||||
|
||||
file_handler_ = new FileHandlerImpl(kInputFilename, kOutputFilename,
|
||||
kFrameLength);
|
||||
ASSERT_TRUE(file_handler_->Init());
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
delete file_handler_;
|
||||
// Cleanup the temporary file:
|
||||
std::remove(kInputFilename.c_str());
|
||||
std::remove(kOutputFilename.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(FileHandlerTest, InitSuccess) {
|
||||
FileHandlerImpl file_handler(kInputFilename, kOutputFilename, kFrameLength);
|
||||
ASSERT_TRUE(file_handler.Init());
|
||||
ASSERT_EQ(kFrameLength, file_handler.GetFrameLength());
|
||||
ASSERT_EQ(0, file_handler.GetNumberOfFrames());
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, ReadFrame) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
bool result = file_handler_->ReadFrame(buffer);
|
||||
ASSERT_FALSE(result); // no more files to read
|
||||
ASSERT_EQ(kInputFileContents[0], buffer[0]);
|
||||
ASSERT_EQ(kInputFileContents[1], buffer[1]);
|
||||
ASSERT_EQ(kInputFileContents[2], buffer[2]);
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, ReadFrameUninitialized) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
FileHandlerImpl file_handler(kInputFilename, kOutputFilename, kFrameLength);
|
||||
ASSERT_FALSE(file_handler.ReadFrame(buffer));
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, ReadFrameNullArgument) {
|
||||
ASSERT_DEATH(file_handler_->ReadFrame(NULL), "");
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, WriteFrame) {
|
||||
WebRtc_UWord8 buffer[kFrameLength];
|
||||
memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer
|
||||
bool result = file_handler_->WriteFrame(buffer);
|
||||
ASSERT_TRUE(result); // success
|
||||
// Close the file and verify the size:
|
||||
file_handler_->Close();
|
||||
ASSERT_EQ(kFrameLength,
|
||||
static_cast<int>(file_handler_->GetFileSize(kOutputFilename)));
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, WriteFrameUninitialized) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
FileHandlerImpl file_handler(kInputFilename, kOutputFilename, kFrameLength);
|
||||
ASSERT_FALSE(file_handler.WriteFrame(buffer));
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, WriteFrameNullArgument) {
|
||||
ASSERT_DEATH(file_handler_->WriteFrame(NULL), "");
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, GetFileSizeExistingFile) {
|
||||
ASSERT_EQ(kInputFileContents.length(),
|
||||
file_handler_->GetFileSize(kInputFilename));
|
||||
}
|
||||
|
||||
TEST_F(FileHandlerTest, GetFileSizeNonExistingFile) {
|
||||
ASSERT_EQ(0u, file_handler_->GetFileSize("non-existing-file.tmp"));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_MOCK_MOCK_PACKET_MANIPULATOR_H_
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_MOCK_MOCK_PACKET_MANIPULATOR_H_
|
||||
|
||||
#include "modules/video_coding/codecs/test/packet_manipulator.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common_video/interface/video_image.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
class MockPacketManipulator : public PacketManipulator {
|
||||
public:
|
||||
MOCK_METHOD1(ManipulatePackets, int(webrtc::EncodedImage* encoded_image));
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_MOCK_MOCK_PACKET_MANIPULATOR_H_
|
@ -7,20 +7,22 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "packet_manipulator.h"
|
||||
|
||||
#include "modules/video_coding/codecs/test/packet_manipulator.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "util.h"
|
||||
#include <cstdio>
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
PacketManipulatorImpl::PacketManipulatorImpl(PacketReader* packet_reader,
|
||||
const NetworkingConfig& config)
|
||||
const NetworkingConfig& config,
|
||||
bool verbose)
|
||||
: packet_reader_(packet_reader),
|
||||
config_(config),
|
||||
active_burst_packets_(0) {
|
||||
active_burst_packets_(0),
|
||||
verbose_(verbose) {
|
||||
assert(packet_reader);
|
||||
}
|
||||
|
||||
@ -66,9 +68,11 @@ int PacketManipulatorImpl::ManipulatePackets(
|
||||
if (nbr_packets_dropped > 0) {
|
||||
// Must set completeFrame to false to inform the decoder about this:
|
||||
encoded_image->_completeFrame = false;
|
||||
log("Dropped %d packets for frame %d (frame length: %d)\n",
|
||||
nbr_packets_dropped, encoded_image->_timeStamp,
|
||||
encoded_image->_length);
|
||||
if (verbose_) {
|
||||
printf("Dropped %d packets for frame %d (frame length: %d)\n",
|
||||
nbr_packets_dropped, encoded_image->_timeStamp,
|
||||
encoded_image->_length);
|
||||
}
|
||||
}
|
||||
return nbr_packets_dropped;
|
||||
}
|
||||
|
@ -7,13 +7,14 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "packet_reader.h"
|
||||
#include "video_codec_interface.h"
|
||||
#include "modules/video_coding/codecs/interface/video_codec_interface.h"
|
||||
#include "testsupport/packet_reader.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -87,7 +88,7 @@ class PacketManipulator {
|
||||
class PacketManipulatorImpl : public PacketManipulator {
|
||||
public:
|
||||
PacketManipulatorImpl(PacketReader* packet_reader,
|
||||
const NetworkingConfig& config);
|
||||
const NetworkingConfig& config, bool verbose);
|
||||
virtual ~PacketManipulatorImpl();
|
||||
virtual int ManipulatePackets(webrtc::EncodedImage* encoded_image);
|
||||
protected:
|
||||
@ -98,9 +99,10 @@ class PacketManipulatorImpl : public PacketManipulator {
|
||||
const NetworkingConfig& config_;
|
||||
// Used to simulate a burst over several frames.
|
||||
int active_burst_packets_;
|
||||
bool verbose_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_MANIPULATOR_H_
|
||||
|
@ -8,13 +8,14 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/video_coding/codecs/test/packet_manipulator.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "packet_manipulator.h"
|
||||
#include "modules/video_coding/codecs/interface/video_codec_interface.h"
|
||||
#include "testsupport/unittest_utils.h"
|
||||
#include "typedefs.h"
|
||||
#include "unittest_utils.h"
|
||||
#include "video_codec_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -31,9 +32,6 @@ class PacketManipulatorTest: public PacketRelatedTest {
|
||||
NetworkingConfig no_drop_config_;
|
||||
|
||||
PacketManipulatorTest() {
|
||||
// To avoid warnings when using ASSERT_DEATH
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
|
||||
image_._buffer = packet_data_;
|
||||
image_._length = kPacketDataLength;
|
||||
image_._size = kPacketDataLength;
|
||||
@ -49,8 +47,7 @@ class PacketManipulatorTest: public PacketRelatedTest {
|
||||
no_drop_config_.packet_loss_mode = kUniform;
|
||||
}
|
||||
|
||||
virtual ~PacketManipulatorTest() {
|
||||
}
|
||||
virtual ~PacketManipulatorTest() {}
|
||||
|
||||
void SetUp() {
|
||||
PacketRelatedTest::SetUp();
|
||||
@ -78,7 +75,7 @@ class PredictivePacketManipulatorImpl : public PacketManipulatorImpl {
|
||||
public:
|
||||
PredictivePacketManipulatorImpl(PacketReader* packet_reader,
|
||||
const NetworkingConfig& config)
|
||||
: PacketManipulatorImpl(packet_reader, config) {
|
||||
: PacketManipulatorImpl(packet_reader, config, false) {
|
||||
}
|
||||
// Adds a result. You must add at least the same number of results as the
|
||||
// expected calls to the RandomUniform method. The results are added to a
|
||||
@ -102,20 +99,11 @@ class PredictivePacketManipulatorImpl : public PacketManipulatorImpl {
|
||||
};
|
||||
|
||||
TEST_F(PacketManipulatorTest, Constructor) {
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_);
|
||||
}
|
||||
|
||||
TEST_F(PacketManipulatorTest, ConstructorNullArgument) {
|
||||
ASSERT_DEATH(PacketManipulatorImpl manipulator(NULL, no_drop_config_), "");
|
||||
}
|
||||
|
||||
TEST_F(PacketManipulatorTest, NullImageArgument) {
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_);
|
||||
ASSERT_DEATH(manipulator.ManipulatePackets(NULL), "");
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
|
||||
}
|
||||
|
||||
TEST_F(PacketManipulatorTest, DropNone) {
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_);
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
|
||||
int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
|
||||
VerifyPacketLoss(0, nbr_packets_dropped, kPacketDataLength,
|
||||
packet_data_, image_);
|
||||
@ -124,7 +112,7 @@ TEST_F(PacketManipulatorTest, DropNone) {
|
||||
TEST_F(PacketManipulatorTest, UniformDropNoneSmallFrame) {
|
||||
int data_length = 400; // smaller than the packet size
|
||||
image_._length = data_length;
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_);
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
|
||||
int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
|
||||
|
||||
VerifyPacketLoss(0, nbr_packets_dropped, data_length,
|
||||
@ -132,7 +120,7 @@ TEST_F(PacketManipulatorTest, UniformDropNoneSmallFrame) {
|
||||
}
|
||||
|
||||
TEST_F(PacketManipulatorTest, UniformDropAll) {
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, drop_config_);
|
||||
PacketManipulatorImpl manipulator(&packet_reader_, drop_config_, false);
|
||||
int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
|
||||
VerifyPacketLoss(kPacketDataNumberOfPackets, nbr_packets_dropped,
|
||||
0, packet_data_, image_);
|
||||
|
@ -7,22 +7,19 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "stats.h"
|
||||
|
||||
#include "modules/video_coding/codecs/test/stats.h"
|
||||
|
||||
#include <algorithm> // min_element, max_element
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
Stats::Stats() {
|
||||
}
|
||||
Stats::Stats() {}
|
||||
|
||||
Stats::~Stats() {
|
||||
}
|
||||
Stats::~Stats() {}
|
||||
|
||||
bool LessForEncodeTime(const FrameStatistic& s1, const FrameStatistic& s2) {
|
||||
return s1.encode_time_in_us < s2.encode_time_in_us;
|
||||
@ -40,7 +37,6 @@ bool LessForBitRate(const FrameStatistic& s1, const FrameStatistic& s2) {
|
||||
return s1.bit_rate_in_kbps < s2.bit_rate_in_kbps;
|
||||
}
|
||||
|
||||
|
||||
FrameStatistic& Stats::NewFrame(int frame_number) {
|
||||
assert(frame_number >= 0);
|
||||
FrameStatistic stat;
|
||||
@ -50,9 +46,9 @@ FrameStatistic& Stats::NewFrame(int frame_number) {
|
||||
}
|
||||
|
||||
void Stats::PrintSummary() {
|
||||
log("Processing summary:\n");
|
||||
printf("Processing summary:\n");
|
||||
if (stats_.size() == 0) {
|
||||
log("No frame statistics have been logged yet.\n");
|
||||
printf("No frame statistics have been logged yet.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,22 +78,22 @@ void Stats::PrintSummary() {
|
||||
FrameStatisticsIterator frame;
|
||||
|
||||
// ENCODING
|
||||
log("Encoding time:\n");
|
||||
printf("Encoding time:\n");
|
||||
frame = min_element(stats_.begin(),
|
||||
stats_.end(), LessForEncodeTime);
|
||||
log(" Min : %7d us (frame %d)\n",
|
||||
printf(" Min : %7d us (frame %d)\n",
|
||||
frame->encode_time_in_us, frame->frame_number);
|
||||
|
||||
frame = max_element(stats_.begin(),
|
||||
stats_.end(), LessForEncodeTime);
|
||||
log(" Max : %7d us (frame %d)\n",
|
||||
printf(" Max : %7d us (frame %d)\n",
|
||||
frame->encode_time_in_us, frame->frame_number);
|
||||
|
||||
log(" Average : %7d us\n",
|
||||
printf(" Average : %7d us\n",
|
||||
total_encoding_time_in_us / stats_.size());
|
||||
|
||||
// DECODING
|
||||
log("Decoding time:\n");
|
||||
printf("Decoding time:\n");
|
||||
// only consider frames that were successfully decoded (packet loss may cause
|
||||
// failures)
|
||||
std::vector<FrameStatistic> decoded_frames;
|
||||
@ -108,67 +104,67 @@ void Stats::PrintSummary() {
|
||||
}
|
||||
}
|
||||
if (decoded_frames.size() == 0) {
|
||||
printf("No successfully decoded frames exist in this statistics.");
|
||||
printf("No successfully decoded frames exist in this statistics.\n");
|
||||
} else {
|
||||
frame = min_element(decoded_frames.begin(),
|
||||
decoded_frames.end(), LessForDecodeTime);
|
||||
log(" Min : %7d us (frame %d)\n",
|
||||
printf(" Min : %7d us (frame %d)\n",
|
||||
frame->decode_time_in_us, frame->frame_number);
|
||||
|
||||
frame = max_element(decoded_frames.begin(),
|
||||
decoded_frames.end(), LessForDecodeTime);
|
||||
log(" Max : %7d us (frame %d)\n",
|
||||
printf(" Max : %7d us (frame %d)\n",
|
||||
frame->decode_time_in_us, frame->frame_number);
|
||||
|
||||
log(" Average : %7d us\n",
|
||||
printf(" Average : %7d us\n",
|
||||
total_decoding_time_in_us / decoded_frames.size());
|
||||
log(" Failures: %d frames failed to decode.\n",
|
||||
printf(" Failures: %d frames failed to decode.\n",
|
||||
(stats_.size() - decoded_frames.size()));
|
||||
}
|
||||
|
||||
// SIZE
|
||||
log("Frame sizes:\n");
|
||||
printf("Frame sizes:\n");
|
||||
frame = min_element(stats_.begin(),
|
||||
stats_.end(), LessForEncodedSize);
|
||||
log(" Min : %7d bytes (frame %d)\n",
|
||||
printf(" Min : %7d bytes (frame %d)\n",
|
||||
frame->encoded_frame_length_in_bytes, frame->frame_number);
|
||||
|
||||
frame = max_element(stats_.begin(),
|
||||
stats_.end(), LessForEncodedSize);
|
||||
log(" Max : %7d bytes (frame %d)\n",
|
||||
printf(" Max : %7d bytes (frame %d)\n",
|
||||
frame->encoded_frame_length_in_bytes, frame->frame_number);
|
||||
|
||||
log(" Average : %7d bytes\n",
|
||||
printf(" Average : %7d bytes\n",
|
||||
total_encoded_frames_lengths / stats_.size());
|
||||
if (nbr_keyframes > 0) {
|
||||
log(" Average key frame size : %7d bytes (%d keyframes)\n",
|
||||
printf(" Average key frame size : %7d bytes (%d keyframes)\n",
|
||||
total_encoded_key_frames_lengths / nbr_keyframes,
|
||||
nbr_keyframes);
|
||||
}
|
||||
if (nbr_nonkeyframes > 0) {
|
||||
log(" Average non-key frame size: %7d bytes (%d frames)\n",
|
||||
total_encoded_nonkey_frames_lengths / nbr_nonkeyframes,
|
||||
nbr_nonkeyframes);
|
||||
printf(" Average non-key frame size: %7d bytes (%d frames)\n",
|
||||
total_encoded_nonkey_frames_lengths / nbr_nonkeyframes,
|
||||
nbr_nonkeyframes);
|
||||
}
|
||||
|
||||
// BIT RATE
|
||||
log("Bit rates:\n");
|
||||
printf("Bit rates:\n");
|
||||
frame = min_element(stats_.begin(),
|
||||
stats_.end(), LessForBitRate);
|
||||
log(" Min bit rate: %7d kbps (frame %d)\n",
|
||||
frame->bit_rate_in_kbps, frame->frame_number);
|
||||
printf(" Min bit rate: %7d kbps (frame %d)\n",
|
||||
frame->bit_rate_in_kbps, frame->frame_number);
|
||||
|
||||
frame = max_element(stats_.begin(),
|
||||
stats_.end(), LessForBitRate);
|
||||
log(" Max bit rate: %7d kbps (frame %d)\n",
|
||||
frame->bit_rate_in_kbps, frame->frame_number);
|
||||
printf(" Max bit rate: %7d kbps (frame %d)\n",
|
||||
frame->bit_rate_in_kbps, frame->frame_number);
|
||||
|
||||
log("\n");
|
||||
log("Total encoding time : %7d ms.\n",
|
||||
printf("\n");
|
||||
printf("Total encoding time : %7d ms.\n",
|
||||
total_encoding_time_in_us / 1000);
|
||||
log("Total decoding time : %7d ms.\n",
|
||||
printf("Total decoding time : %7d ms.\n",
|
||||
total_decoding_time_in_us / 1000);
|
||||
log("Total processing time: %7d ms.\n",
|
||||
printf("Total processing time: %7d ms.\n",
|
||||
(total_encoding_time_in_us + total_decoding_time_in_us) / 1000);
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,13 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "video_image.h"
|
||||
#include "common_video/interface/video_image.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -24,7 +25,8 @@ struct FrameStatistic {
|
||||
encode_return_code(0), decode_return_code(0),
|
||||
encode_time_in_us(0), decode_time_in_us(0),
|
||||
frame_number(0), packets_dropped(0), total_packets(0),
|
||||
bit_rate_in_kbps(0), encoded_frame_length_in_bytes(0) {
|
||||
bit_rate_in_kbps(0), encoded_frame_length_in_bytes(0),
|
||||
frame_type(kDeltaFrame) {
|
||||
};
|
||||
bool encoding_successful;
|
||||
bool decoding_successful;
|
||||
@ -71,4 +73,4 @@ class Stats {
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_STATS_H_
|
||||
|
@ -7,8 +7,10 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/video_coding/codecs/test/stats.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "stats.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "util.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include "google/gflags.h"
|
||||
|
||||
DEFINE_bool(verbose, true, "Verbose mode. Prints a lot of debugging info. "
|
||||
"Suitable for tracking progress but not for capturing output. "
|
||||
"Default: enabled");
|
||||
|
||||
int log(const char *format, ...) {
|
||||
int result = 0;
|
||||
if (FLAGS_verbose) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
result = vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_UTIL_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_UTIL_H_
|
||||
|
||||
// Custom log method that only prints if the verbose flag is given
|
||||
// Supports all the standard printf parameters and formatting (just forwarded)
|
||||
int log(const char *format, ...);
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_UTIL_H_
|
@ -15,36 +15,16 @@
|
||||
'target_name': 'video_codecs_test_framework',
|
||||
'type': '<(library)',
|
||||
'dependencies': [
|
||||
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
||||
'<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib',
|
||||
'<(webrtc_root)/../testing/gtest.gyp:gtest',
|
||||
'<(webrtc_root)/../third_party/google-gflags/google-gflags.gyp:google-gflags',
|
||||
'<(webrtc_root)/../test/test.gyp:test_support',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../interface',
|
||||
'<(webrtc_root)/common_video/interface',
|
||||
],
|
||||
'direct_dependent_settings': {
|
||||
'include_dirs': [
|
||||
'../interface',
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
# header files
|
||||
'file_handler.h',
|
||||
'mock/mock_packet_manipulator.h',
|
||||
'packet_manipulator.h',
|
||||
'packet_reader.h',
|
||||
'stats.h',
|
||||
'videoprocessor.h',
|
||||
'util.h',
|
||||
|
||||
# source files
|
||||
'file_handler.cc',
|
||||
'packet_manipulator.cc',
|
||||
'packet_reader.cc',
|
||||
'stats.h',
|
||||
'stats.cc',
|
||||
'videoprocessor.h',
|
||||
'videoprocessor.cc',
|
||||
'util.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -53,21 +33,11 @@
|
||||
'dependencies': [
|
||||
'video_codecs_test_framework',
|
||||
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
||||
'<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib',
|
||||
'<(webrtc_root)/../testing/gmock.gyp:gmock',
|
||||
'<(webrtc_root)/../test/test.gyp:test_support_main',
|
||||
],
|
||||
'include_dirs': [
|
||||
'<(webrtc_root)/common_video/interface',
|
||||
],
|
||||
'sources': [
|
||||
# header files
|
||||
'mocks.h',
|
||||
|
||||
# source files
|
||||
'file_handler_unittest.cc',
|
||||
'packet_manipulator_unittest.cc',
|
||||
'packet_reader_unittest.cc',
|
||||
'stats_unittest.cc',
|
||||
'videoprocessor_unittest.cc',
|
||||
],
|
||||
|
@ -7,27 +7,29 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "videoprocessor.h"
|
||||
|
||||
#include "modules/video_coding/codecs/test/videoprocessor.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
#include "cpu_info.h"
|
||||
#include "util.h"
|
||||
#include "system_wrappers/interface/cpu_info.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
||||
webrtc::VideoDecoder* decoder,
|
||||
FileHandler* file_handler,
|
||||
FrameReader* frame_reader,
|
||||
FrameWriter* frame_writer,
|
||||
PacketManipulator* packet_manipulator,
|
||||
const TestConfig& config,
|
||||
Stats* stats)
|
||||
: encoder_(encoder),
|
||||
decoder_(decoder),
|
||||
file_handler_(file_handler),
|
||||
frame_reader_(frame_reader),
|
||||
frame_writer_(frame_writer),
|
||||
packet_manipulator_(packet_manipulator),
|
||||
config_(config),
|
||||
stats_(stats),
|
||||
@ -39,7 +41,8 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
||||
initialized_(false) {
|
||||
assert(encoder);
|
||||
assert(decoder);
|
||||
assert(file_handler);
|
||||
assert(frame_reader);
|
||||
assert(frame_writer);
|
||||
assert(packet_manipulator);
|
||||
assert(stats);
|
||||
}
|
||||
@ -48,7 +51,7 @@ bool VideoProcessorImpl::Init() {
|
||||
// Calculate a factor used for bit rate calculations:
|
||||
bit_rate_factor_ = config_.codec_settings.maxFramerate * 0.001 * 8; // bits
|
||||
|
||||
int frame_length_in_bytes = file_handler_->GetFrameLength();
|
||||
int frame_length_in_bytes = frame_reader_->FrameLength();
|
||||
|
||||
// Initialize data structures used by the encoder/decoder APIs
|
||||
source_buffer_ = new WebRtc_UWord8[frame_length_in_bytes];
|
||||
@ -96,13 +99,16 @@ bool VideoProcessorImpl::Init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
log("Video Processor:\n");
|
||||
log(" #CPU cores used : %d\n", nbr_of_cores);
|
||||
log(" Total # of frames: %d\n", file_handler_->GetNumberOfFrames());
|
||||
log(" Codec settings:\n");
|
||||
log(" Start bitrate : %d kbps\n", config_.codec_settings.startBitrate);
|
||||
log(" Width : %d\n", config_.codec_settings.width);
|
||||
log(" Height : %d\n", config_.codec_settings.height);
|
||||
if (config_.verbose) {
|
||||
printf("Video Processor:\n");
|
||||
printf(" #CPU cores used : %d\n", nbr_of_cores);
|
||||
printf(" Total # of frames: %d\n", frame_reader_->NumberOfFrames());
|
||||
printf(" Codec settings:\n");
|
||||
printf(" Start bitrate : %d kbps\n",
|
||||
config_.codec_settings.startBitrate);
|
||||
printf(" Width : %d\n", config_.codec_settings.width);
|
||||
printf(" Height : %d\n", config_.codec_settings.height);
|
||||
}
|
||||
initialized_ = true;
|
||||
return true;
|
||||
}
|
||||
@ -122,7 +128,7 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
|
||||
fprintf(stderr, "Attempting to use uninitialized VideoProcessor!\n");
|
||||
return false;
|
||||
}
|
||||
if (file_handler_->ReadFrame(source_buffer_)) {
|
||||
if (frame_reader_->ReadFrame(source_buffer_)) {
|
||||
// point the source frame buffer to the newly read frame data:
|
||||
source_frame_._buffer = source_buffer_;
|
||||
|
||||
@ -200,7 +206,7 @@ void VideoProcessorImpl::FrameEncoded(EncodedImage* encoded_image) {
|
||||
if (decode_result != WEBRTC_VIDEO_CODEC_OK) {
|
||||
// Write the last successful frame the output file to avoid getting it out
|
||||
// of sync with the source file for SSIM and PSNR comparisons:
|
||||
file_handler_->WriteFrame(last_successful_frame_buffer_);
|
||||
frame_writer_->WriteFrame(last_successful_frame_buffer_);
|
||||
}
|
||||
// save status for losses so we can inform the decoder for the next frame:
|
||||
last_frame_missing_ = encoded_image->_length == 0;
|
||||
@ -217,7 +223,7 @@ void VideoProcessorImpl::FrameDecoded(const RawImage& image) {
|
||||
// Update our copy of the last successful frame:
|
||||
memcpy(last_successful_frame_buffer_, image._buffer, image._length);
|
||||
|
||||
bool write_success = file_handler_->WriteFrame(image._buffer);
|
||||
bool write_success = frame_writer_->WriteFrame(image._buffer);
|
||||
if (!write_success) {
|
||||
fprintf(stderr, "Failed to write frame %d to disk!", frame_number);
|
||||
}
|
||||
|
@ -7,16 +7,18 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
|
||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "file_handler.h"
|
||||
#include "packet_manipulator.h"
|
||||
#include "stats.h"
|
||||
#include "tick_util.h"
|
||||
#include "video_codec_interface.h"
|
||||
#include "modules/video_coding/codecs/interface/video_codec_interface.h"
|
||||
#include "modules/video_coding/codecs/test/packet_manipulator.h"
|
||||
#include "modules/video_coding/codecs/test/stats.h"
|
||||
#include "system_wrappers/interface/tick_util.h"
|
||||
#include "testsupport/frame_reader.h"
|
||||
#include "testsupport/frame_writer.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -39,7 +41,8 @@ struct TestConfig {
|
||||
: name(""), description(""), test_number(0),
|
||||
input_filename(""), output_filename(""), output_dir("out"),
|
||||
networking_config(), exclude_frame_types(kExcludeOnlyFirstKeyFrame),
|
||||
frame_length_in_bytes(-1), use_single_core(false), keyframe_interval(0) {
|
||||
frame_length_in_bytes(-1), use_single_core(false), keyframe_interval(0),
|
||||
verbose(true) {
|
||||
};
|
||||
|
||||
// Name of the test. This is purely metadata and does not affect
|
||||
@ -98,6 +101,9 @@ struct TestConfig {
|
||||
// The codec settings to use for the test (target bitrate, video size,
|
||||
// framerate and so on)
|
||||
webrtc::VideoCodec codec_settings;
|
||||
|
||||
// If printing of information to stdout shall be performed during processing.
|
||||
bool verbose;
|
||||
};
|
||||
|
||||
// Returns a string representation of the enum value.
|
||||
@ -139,7 +145,8 @@ class VideoProcessorImpl : public VideoProcessor {
|
||||
public:
|
||||
VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
||||
webrtc::VideoDecoder* decoder,
|
||||
FileHandler* file_handler,
|
||||
FrameReader* frame_reader,
|
||||
FrameWriter* frame_writer,
|
||||
PacketManipulator* packet_manipulator,
|
||||
const TestConfig& config,
|
||||
Stats* stats);
|
||||
@ -159,7 +166,8 @@ class VideoProcessorImpl : public VideoProcessor {
|
||||
|
||||
webrtc::VideoEncoder* encoder_;
|
||||
webrtc::VideoDecoder* decoder_;
|
||||
FileHandler* file_handler_;
|
||||
FrameReader* frame_reader_;
|
||||
FrameWriter* frame_writer_;
|
||||
PacketManipulator* packet_manipulator_;
|
||||
const TestConfig& config_;
|
||||
Stats* stats_;
|
||||
@ -217,4 +225,4 @@ class VideoProcessorImpl : public VideoProcessor {
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
|
||||
|
@ -7,14 +7,17 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "mocks.h"
|
||||
#include "packet_reader.h"
|
||||
#include "packet_manipulator.h"
|
||||
#include "modules/video_coding/codecs/test/mock/mock_packet_manipulator.h"
|
||||
#include "modules/video_coding/codecs/test/videoprocessor.h"
|
||||
#include "modules/video_coding/codecs/interface/mock/mock_video_codec_interface.h"
|
||||
#include "testsupport/mock/mock_frame_reader.h"
|
||||
#include "testsupport/mock/mock_frame_writer.h"
|
||||
#include "testsupport/packet_reader.h"
|
||||
#include "testsupport/unittest_utils.h"
|
||||
#include "typedefs.h"
|
||||
#include "unittest_utils.h"
|
||||
#include "videoprocessor.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
@ -29,24 +32,16 @@ class VideoProcessorTest: public testing::Test {
|
||||
protected:
|
||||
MockVideoEncoder encoder_mock_;
|
||||
MockVideoDecoder decoder_mock_;
|
||||
MockFileHandler file_handler_mock_;
|
||||
MockFrameReader frame_reader_mock_;
|
||||
MockFrameWriter frame_writer_mock_;
|
||||
MockPacketManipulator packet_manipulator_mock_;
|
||||
Stats stats_;
|
||||
TestConfig config_;
|
||||
|
||||
VideoProcessorTest() {
|
||||
// To avoid warnings when using ASSERT_DEATH
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
}
|
||||
|
||||
virtual ~VideoProcessorTest() {
|
||||
}
|
||||
|
||||
void SetUp() {
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
VideoProcessorTest() {}
|
||||
virtual ~VideoProcessorTest() {}
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
|
||||
void ExpectInit() {
|
||||
EXPECT_CALL(encoder_mock_, InitEncode(_, _, _))
|
||||
@ -57,62 +52,18 @@ class VideoProcessorTest: public testing::Test {
|
||||
.Times(1);
|
||||
EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_))
|
||||
.Times(AtLeast(1));
|
||||
EXPECT_CALL(file_handler_mock_, GetNumberOfFrames())
|
||||
EXPECT_CALL(frame_reader_mock_, NumberOfFrames())
|
||||
.WillOnce(Return(1));
|
||||
EXPECT_CALL(file_handler_mock_, GetFrameLength())
|
||||
EXPECT_CALL(frame_reader_mock_, FrameLength())
|
||||
.WillOnce(Return(150000));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(VideoProcessorTest, ConstructorNullEncoder) {
|
||||
ASSERT_DEATH(VideoProcessorImpl video_processor(NULL,
|
||||
&decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
&packet_manipulator_mock_,
|
||||
config_,
|
||||
&stats_), "");
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, ConstructorNullDecoder) {
|
||||
ASSERT_DEATH(VideoProcessorImpl video_processor(&encoder_mock_,
|
||||
NULL,
|
||||
&file_handler_mock_,
|
||||
&packet_manipulator_mock_,
|
||||
config_,
|
||||
&stats_), "");
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, ConstructorNullFileHandler) {
|
||||
ASSERT_DEATH(VideoProcessorImpl video_processor(&encoder_mock_,
|
||||
&decoder_mock_,
|
||||
NULL,
|
||||
&packet_manipulator_mock_,
|
||||
config_,
|
||||
&stats_), "");
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, ConstructorNullPacketManipulator) {
|
||||
ASSERT_DEATH(VideoProcessorImpl video_processor(&encoder_mock_,
|
||||
&decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
NULL,
|
||||
config_,
|
||||
&stats_), "");
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, ConstructorNullStats) {
|
||||
ASSERT_DEATH(VideoProcessorImpl video_processor(&encoder_mock_,
|
||||
&decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
&packet_manipulator_mock_,
|
||||
config_,
|
||||
NULL), "");
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, Init) {
|
||||
ExpectInit();
|
||||
VideoProcessorImpl video_processor(&encoder_mock_, &decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
&frame_reader_mock_,
|
||||
&frame_writer_mock_,
|
||||
&packet_manipulator_mock_, config_,
|
||||
&stats_);
|
||||
video_processor.Init();
|
||||
@ -122,28 +73,18 @@ TEST_F(VideoProcessorTest, ProcessFrame) {
|
||||
ExpectInit();
|
||||
EXPECT_CALL(encoder_mock_, Encode(_, _, _))
|
||||
.Times(1);
|
||||
EXPECT_CALL(file_handler_mock_, ReadFrame(_))
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(frame_reader_mock_, ReadFrame(_))
|
||||
.WillOnce(Return(true));
|
||||
// Since we don't return any callback from the mock, the decoder will not
|
||||
// be more than initialized...
|
||||
VideoProcessorImpl video_processor(&encoder_mock_, &decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
&frame_reader_mock_,
|
||||
&frame_writer_mock_,
|
||||
&packet_manipulator_mock_, config_,
|
||||
&stats_);
|
||||
video_processor.Init();
|
||||
video_processor.ProcessFrame(0);
|
||||
}
|
||||
|
||||
TEST_F(VideoProcessorTest, ProcessFrameInvalidArgument) {
|
||||
ExpectInit();
|
||||
VideoProcessorImpl video_processor(&encoder_mock_, &decoder_mock_,
|
||||
&file_handler_mock_,
|
||||
&packet_manipulator_mock_, config_,
|
||||
&stats_);
|
||||
video_processor.Init();
|
||||
ASSERT_DEATH(video_processor.ProcessFrame(-1), "");
|
||||
}
|
||||
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
@ -16,21 +16,10 @@
|
||||
'type': 'executable',
|
||||
'dependencies': [
|
||||
'video_codecs_test_framework',
|
||||
'<(webrtc_root)/../test/test.gyp:test_support',
|
||||
'webrtc_vp8',
|
||||
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
||||
'<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib',
|
||||
'<(webrtc_root)/../third_party/google-gflags/google-gflags.gyp:google-gflags',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../test',
|
||||
'../interface',
|
||||
'<(webrtc_root)/common_video/interface',
|
||||
],
|
||||
'sources': [
|
||||
# header files
|
||||
|
||||
# source files
|
||||
'video_quality_measurement.cc',
|
||||
],
|
||||
},
|
||||
|
@ -8,23 +8,26 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h> // To check for directory existence.
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <sys/stat.h> // To check for directory existence.
|
||||
|
||||
#ifndef S_ISDIR // Not defined in stat.h on Windows.
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
#include "google/gflags.h"
|
||||
#include "packet_manipulator.h"
|
||||
#include "packet_reader.h"
|
||||
#include "stats.h"
|
||||
#include "trace.h"
|
||||
#include "modules/video_coding/codecs/test/packet_manipulator.h"
|
||||
#include "modules/video_coding/codecs/test/stats.h"
|
||||
#include "modules/video_coding/codecs/test/videoprocessor.h"
|
||||
#include "modules/video_coding/codecs/vp8/main/interface/vp8.h"
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
#include "testsupport/frame_reader.h"
|
||||
#include "testsupport/frame_writer.h"
|
||||
#include "testsupport/metrics/video_metrics.h"
|
||||
#include "util.h"
|
||||
#include "videoprocessor.h"
|
||||
#include "vp8.h"
|
||||
#include "testsupport/packet_reader.h"
|
||||
|
||||
DEFINE_string(test_name, "Quality test", "The name of the test to run. ");
|
||||
DEFINE_string(test_description, "", "A more detailed description about what "
|
||||
@ -80,6 +83,22 @@ DEFINE_bool(python, false, "Python output. Enabling this will output all frame "
|
||||
"statistics as a Python script at the end of execution. "
|
||||
"Recommended to run combine with --noverbose to avoid mixing "
|
||||
"output.");
|
||||
DEFINE_bool(verbose, true, "Verbose mode. Prints a lot of debugging info. "
|
||||
"Suitable for tracking progress but not for capturing output. "
|
||||
"Disable with --noverbose flag.");
|
||||
|
||||
// Custom log method that only prints if the verbose flag is given
|
||||
// Supports all the standard printf parameters and formatting (just forwarded)
|
||||
int Log(const char *format, ...) {
|
||||
int result = 0;
|
||||
if (FLAGS_verbose) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
result = vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Validates the arguments given as command line flags.
|
||||
// Returns 0 if everything is OK, otherwise an exit code.
|
||||
@ -223,60 +242,61 @@ int HandleCommandLineFlags(webrtc::test::TestConfig* config) {
|
||||
}
|
||||
config->networking_config.packet_loss_burst_length =
|
||||
FLAGS_packet_loss_burst_length;
|
||||
config->verbose = FLAGS_verbose;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CalculateSsimVideoMetrics(webrtc::test::TestConfig* config,
|
||||
QualityMetricsResult* ssimResult) {
|
||||
log("Calculating SSIM...\n");
|
||||
Log("Calculating SSIM...\n");
|
||||
SsimFromFiles(config->input_filename.c_str(), config->output_filename.c_str(),
|
||||
config->codec_settings.width,
|
||||
config->codec_settings.height, ssimResult);
|
||||
log(" Average: %3.2f\n", ssimResult->average);
|
||||
log(" Min : %3.2f (frame %d)\n", ssimResult->min,
|
||||
Log(" Average: %3.2f\n", ssimResult->average);
|
||||
Log(" Min : %3.2f (frame %d)\n", ssimResult->min,
|
||||
ssimResult->min_frame_number);
|
||||
log(" Max : %3.2f (frame %d)\n", ssimResult->max,
|
||||
Log(" Max : %3.2f (frame %d)\n", ssimResult->max,
|
||||
ssimResult->max_frame_number);
|
||||
}
|
||||
|
||||
void CalculatePsnrVideoMetrics(webrtc::test::TestConfig* config,
|
||||
QualityMetricsResult* psnrResult) {
|
||||
log("Calculating PSNR...\n");
|
||||
Log("Calculating PSNR...\n");
|
||||
PsnrFromFiles(config->input_filename.c_str(), config->output_filename.c_str(),
|
||||
config->codec_settings.width,
|
||||
config->codec_settings.height, psnrResult);
|
||||
log(" Average: %3.2f\n", psnrResult->average);
|
||||
log(" Min : %3.2f (frame %d)\n", psnrResult->min,
|
||||
Log(" Average: %3.2f\n", psnrResult->average);
|
||||
Log(" Min : %3.2f (frame %d)\n", psnrResult->min,
|
||||
psnrResult->min_frame_number);
|
||||
log(" Max : %3.2f (frame %d)\n", psnrResult->max,
|
||||
Log(" Max : %3.2f (frame %d)\n", psnrResult->max,
|
||||
psnrResult->max_frame_number);
|
||||
}
|
||||
|
||||
void PrintConfigurationSummary(const webrtc::test::TestConfig& config) {
|
||||
log("Quality test with parameters:\n");
|
||||
log(" Test name : %s\n", config.name.c_str());
|
||||
log(" Description : %s\n", config.description.c_str());
|
||||
log(" Input filename : %s\n", config.input_filename.c_str());
|
||||
log(" Output directory : %s\n", config.output_dir.c_str());
|
||||
log(" Output filename : %s\n", config.output_filename.c_str());
|
||||
log(" Frame length : %d bytes\n", config.frame_length_in_bytes);
|
||||
log(" Packet size : %d bytes\n",
|
||||
Log("Quality test with parameters:\n");
|
||||
Log(" Test name : %s\n", config.name.c_str());
|
||||
Log(" Description : %s\n", config.description.c_str());
|
||||
Log(" Input filename : %s\n", config.input_filename.c_str());
|
||||
Log(" Output directory : %s\n", config.output_dir.c_str());
|
||||
Log(" Output filename : %s\n", config.output_filename.c_str());
|
||||
Log(" Frame length : %d bytes\n", config.frame_length_in_bytes);
|
||||
Log(" Packet size : %d bytes\n",
|
||||
config.networking_config.packet_size_in_bytes);
|
||||
log(" Max payload size : %d bytes\n",
|
||||
Log(" Max payload size : %d bytes\n",
|
||||
config.networking_config.max_payload_size_in_bytes);
|
||||
log(" Packet loss:\n");
|
||||
log(" Mode : %s\n",
|
||||
Log(" Packet loss:\n");
|
||||
Log(" Mode : %s\n",
|
||||
PacketLossModeToStr(config.networking_config.packet_loss_mode));
|
||||
log(" Probability : %2.1f\n",
|
||||
Log(" Probability : %2.1f\n",
|
||||
config.networking_config.packet_loss_probability);
|
||||
log(" Burst length : %d packets\n",
|
||||
Log(" Burst length : %d packets\n",
|
||||
config.networking_config.packet_loss_burst_length);
|
||||
}
|
||||
|
||||
void PrintCsvOutput(const webrtc::test::Stats& stats,
|
||||
const QualityMetricsResult& ssimResult,
|
||||
const QualityMetricsResult& psnrResult) {
|
||||
log("\nCSV output (recommended to run with --noverbose to skip the "
|
||||
Log("\nCSV output (recommended to run with --noverbose to skip the "
|
||||
"above output)\n");
|
||||
printf("frame_number encoding_successful decoding_successful "
|
||||
"encode_return_code decode_return_code "
|
||||
@ -312,7 +332,7 @@ void PrintPythonOutput(const webrtc::test::TestConfig& config,
|
||||
const webrtc::test::Stats& stats,
|
||||
const QualityMetricsResult& ssimResult,
|
||||
const QualityMetricsResult& psnrResult) {
|
||||
log("\nPython output (recommended to run with --noverbose to skip the "
|
||||
Log("\nPython output (recommended to run with --noverbose to skip the "
|
||||
"above output)\n");
|
||||
printf("test_configuration = ["
|
||||
"{'name': 'name', 'value': '%s'},\n"
|
||||
@ -425,16 +445,19 @@ int main(int argc, char* argv[]) {
|
||||
webrtc::VP8Encoder encoder;
|
||||
webrtc::VP8Decoder decoder;
|
||||
webrtc::test::Stats stats;
|
||||
webrtc::test::FileHandlerImpl file_handler(config.input_filename,
|
||||
config.output_filename,
|
||||
webrtc::test::FrameReaderImpl frame_reader(config.input_filename,
|
||||
config.frame_length_in_bytes);
|
||||
file_handler.Init();
|
||||
webrtc::test::FrameWriterImpl frame_writer(config.output_filename,
|
||||
config.frame_length_in_bytes);
|
||||
frame_reader.Init();
|
||||
frame_writer.Init();
|
||||
webrtc::test::PacketReader packet_reader;
|
||||
|
||||
webrtc::test::PacketManipulatorImpl packet_manipulator(
|
||||
&packet_reader, config.networking_config);
|
||||
&packet_reader, config.networking_config, config.verbose);
|
||||
webrtc::test::VideoProcessorImpl processor(&encoder, &decoder,
|
||||
&file_handler,
|
||||
&frame_reader,
|
||||
&frame_writer,
|
||||
&packet_manipulator,
|
||||
config, &stats);
|
||||
processor.Init();
|
||||
@ -442,13 +465,13 @@ int main(int argc, char* argv[]) {
|
||||
int frame_number = 0;
|
||||
while (processor.ProcessFrame(frame_number)) {
|
||||
if (frame_number % 80 == 0) {
|
||||
log("\n"); // make the output a bit nicer.
|
||||
Log("\n"); // make the output a bit nicer.
|
||||
}
|
||||
log(".");
|
||||
Log(".");
|
||||
frame_number++;
|
||||
}
|
||||
log("\n");
|
||||
log("Processed %d frames\n", frame_number);
|
||||
Log("\n");
|
||||
Log("Processed %d frames\n", frame_number);
|
||||
|
||||
// Release encoder and decoder to make sure they have finished processing:
|
||||
encoder.Release();
|
||||
@ -458,7 +481,8 @@ int main(int argc, char* argv[]) {
|
||||
assert(frame_number == static_cast<int>(stats.stats_.size()));
|
||||
|
||||
// Close the files before we start using them for SSIM/PSNR calculations.
|
||||
file_handler.Close();
|
||||
frame_reader.Close();
|
||||
frame_writer.Close();
|
||||
|
||||
stats.PrintSummary();
|
||||
|
||||
@ -473,8 +497,6 @@ int main(int argc, char* argv[]) {
|
||||
if (FLAGS_python) {
|
||||
PrintPythonOutput(config, stats, ssimResult, psnrResult);
|
||||
}
|
||||
log("Quality test finished!");
|
||||
Log("Quality test finished!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,9 @@
|
||||
{
|
||||
'target_name': 'test_support',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [
|
||||
'.',
|
||||
],
|
||||
'direct_dependent_settings': {
|
||||
'include_dirs': [
|
||||
'.', # Some includes are hierarchical
|
||||
@ -34,8 +37,16 @@
|
||||
'test_suite.h',
|
||||
'testsupport/fileutils.h',
|
||||
'testsupport/fileutils.cc',
|
||||
'testsupport/frame_reader.h',
|
||||
'testsupport/frame_reader.cc',
|
||||
'testsupport/frame_writer.h',
|
||||
'testsupport/frame_writer.cc',
|
||||
'testsupport/packet_reader.h',
|
||||
'testsupport/packet_reader.cc',
|
||||
'testsupport/metrics/video_metrics.h',
|
||||
'testsupport/metrics/video_metrics.cc',
|
||||
'testsupport/mock/mock_frame_reader.h',
|
||||
'testsupport/mock/mock_frame_writer.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -58,7 +69,11 @@
|
||||
'<(webrtc_root)/../testing/gtest.gyp:gtest',
|
||||
],
|
||||
'sources': [
|
||||
'testsupport/unittest_utils.h',
|
||||
'testsupport/fileutils_unittest.cc',
|
||||
'testsupport/frame_reader_unittest.cc',
|
||||
'testsupport/frame_writer_unittest.cc',
|
||||
'testsupport/packet_reader_unittest.cc',
|
||||
'testsupport/metrics/video_metrics_unittest.cc',
|
||||
],
|
||||
},
|
||||
|
@ -8,7 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "fileutils.h"
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
@ -85,8 +85,7 @@ std::string WorkingDir() {
|
||||
if (!GET_CURRENT_DIR(path_buffer, sizeof(path_buffer))) {
|
||||
fprintf(stderr, "Cannot get current directory!\n");
|
||||
return kFallbackPath;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return std::string(path_buffer);
|
||||
}
|
||||
}
|
||||
@ -131,7 +130,8 @@ std::string ResourcePath(std::string name, std::string extension) {
|
||||
std::string architecture = "32";
|
||||
#endif // WEBRTC_ARCH_64_BITS
|
||||
|
||||
std::string resources_path = ProjectRootPath() + kResourcesDirName + kPathDelimiter;
|
||||
std::string resources_path = ProjectRootPath() + kResourcesDirName +
|
||||
kPathDelimiter;
|
||||
std::string resource_file = resources_path + name + "_" + platform + "_" +
|
||||
architecture + "." + extension;
|
||||
if (FileExists(resource_file)) {
|
||||
@ -151,5 +151,17 @@ std::string ResourcePath(std::string name, std::string extension) {
|
||||
return resources_path + name + "." + extension;
|
||||
}
|
||||
|
||||
size_t GetFileSize(std::string filename) {
|
||||
FILE* f = fopen(filename.c_str(), "rb");
|
||||
size_t size = 0;
|
||||
if (f != NULL) {
|
||||
if (fseek(f, 0, SEEK_END) == 0) {
|
||||
size = ftell(f);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
@ -8,6 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
// File utilities for testing purposes.
|
||||
//
|
||||
// The ProjectRootPath() method is a convenient way of getting an absolute
|
||||
@ -59,8 +61,8 @@
|
||||
// /Users/user/webrtc/trunk/out/Debug
|
||||
// (or any other directory below the trunk for that matter).
|
||||
|
||||
#ifndef TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
#define TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -131,7 +133,11 @@ std::string WorkingDir();
|
||||
// false if a file with the same name already exists.
|
||||
bool CreateDirectory(std::string directory_name);
|
||||
|
||||
// File size of the supplied file in bytes. Will return 0 if the file is
|
||||
// empty or if the file does not exist/is readable.
|
||||
size_t GetFileSize(std::string filename);
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
|
||||
|
@ -8,12 +8,13 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
#ifdef WIN32
|
||||
static const char* kPathDelimiter = "\\";
|
||||
@ -63,7 +64,7 @@ class FileUtilsTest : public testing::Test {
|
||||
file_it != files_.end(); ++file_it) {
|
||||
FILE* file = fopen(file_it->c_str(), "wb");
|
||||
ASSERT_TRUE(file != NULL) << "Failed to write file: " << file_it->c_str();
|
||||
ASSERT_TRUE(fprintf(file, "%s", "Dummy data") > 0);
|
||||
ASSERT_GT(fprintf(file, "%s", "Dummy data"), 0);
|
||||
fclose(file);
|
||||
}
|
||||
// Create a dummy subdir that can be chdir'ed into for testing purposes.
|
||||
@ -85,9 +86,9 @@ class FileUtilsTest : public testing::Test {
|
||||
ASSERT_EQ(chdir(original_working_dir_.c_str()), 0);
|
||||
}
|
||||
protected:
|
||||
static FileList files_;
|
||||
static std::string empty_dummy_dir_;
|
||||
private:
|
||||
static FileList files_;
|
||||
static std::string original_working_dir_;
|
||||
};
|
||||
|
||||
@ -164,7 +165,7 @@ TEST_F(FileUtilsTest, WorkingDirReturnsValue) {
|
||||
// Hard to cover all platforms. Just test that it returns something without
|
||||
// crashing:
|
||||
std::string working_dir = webrtc::test::WorkingDir();
|
||||
ASSERT_TRUE(working_dir.length() > 0);
|
||||
ASSERT_GT(working_dir.length(), 0u);
|
||||
}
|
||||
|
||||
// Due to multiple platforms, it is hard to make a complete test for
|
||||
@ -173,10 +174,18 @@ TEST_F(FileUtilsTest, WorkingDirReturnsValue) {
|
||||
// function.
|
||||
TEST_F(FileUtilsTest, ResourcePathReturnsValue) {
|
||||
std::string resource = webrtc::test::ResourcePath(kTestName, kExtension);
|
||||
ASSERT_TRUE(resource.find(kTestName) > 0);
|
||||
ASSERT_TRUE(resource.find(kExtension) > 0);
|
||||
ASSERT_GT(resource.find(kTestName), 0u);
|
||||
ASSERT_GT(resource.find(kExtension), 0u);
|
||||
ASSERT_EQ(0, chdir(kPathDelimiter));
|
||||
ASSERT_EQ("./", webrtc::test::OutputPath());
|
||||
}
|
||||
|
||||
TEST_F(FileUtilsTest, GetFileSizeExistingFile) {
|
||||
ASSERT_GT(webrtc::test::GetFileSize(files_.front()), 0u);
|
||||
}
|
||||
|
||||
TEST_F(FileUtilsTest, GetFileSizeNonExistingFile) {
|
||||
ASSERT_EQ(0u, webrtc::test::GetFileSize("non-existing-file.tmp"));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -7,68 +7,57 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "file_handler.h"
|
||||
|
||||
#include "testsupport/frame_reader.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
FileHandlerImpl::FileHandlerImpl(std::string input_filename,
|
||||
std::string output_filename,
|
||||
FrameReaderImpl::FrameReaderImpl(std::string input_filename,
|
||||
int frame_length_in_bytes)
|
||||
: input_filename_(input_filename),
|
||||
output_filename_(output_filename),
|
||||
frame_length_in_bytes_(frame_length_in_bytes),
|
||||
input_file_(NULL),
|
||||
output_file_(NULL) {
|
||||
input_file_(NULL) {
|
||||
}
|
||||
|
||||
FileHandlerImpl::~FileHandlerImpl() {
|
||||
FrameReaderImpl::~FrameReaderImpl() {
|
||||
Close();
|
||||
}
|
||||
|
||||
bool FileHandlerImpl::Init() {
|
||||
bool FrameReaderImpl::Init() {
|
||||
if (frame_length_in_bytes_ <= 0) {
|
||||
fprintf(stderr, "Frame length must be >0, was %d\n",
|
||||
frame_length_in_bytes_);
|
||||
return false;
|
||||
}
|
||||
|
||||
input_file_ = fopen(input_filename_.c_str(), "rb");
|
||||
if (input_file_ == NULL) {
|
||||
fprintf(stderr, "Couldn't open input file for reading: %s\n",
|
||||
input_filename_.c_str());
|
||||
return false;
|
||||
}
|
||||
output_file_ = fopen(output_filename_.c_str(), "wb");
|
||||
if (output_file_ == NULL) {
|
||||
fprintf(stderr, "Couldn't open output file for writing: %s\n",
|
||||
output_filename_.c_str());
|
||||
return false;
|
||||
}
|
||||
// Calculate total number of frames:
|
||||
WebRtc_UWord64 source_file_size = GetFileSize(input_filename_);
|
||||
// Calculate total number of frames.
|
||||
size_t source_file_size = GetFileSize(input_filename_);
|
||||
if (source_file_size <= 0u) {
|
||||
fprintf(stderr, "Found empty file: %s\n", input_filename_.c_str());
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
number_of_frames_ = source_file_size / frame_length_in_bytes_;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileHandlerImpl::Close() {
|
||||
void FrameReaderImpl::Close() {
|
||||
if (input_file_ != NULL) {
|
||||
fclose(input_file_);
|
||||
input_file_ = NULL;
|
||||
}
|
||||
if (output_file_ != NULL) {
|
||||
fclose(output_file_);
|
||||
output_file_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool FileHandlerImpl::ReadFrame(WebRtc_UWord8* source_buffer) {
|
||||
bool FrameReaderImpl::ReadFrame(WebRtc_UWord8* source_buffer) {
|
||||
assert(source_buffer);
|
||||
if (input_file_ == NULL) {
|
||||
fprintf(stderr, "FileHandler is not initialized (input file is NULL)\n");
|
||||
@ -83,35 +72,7 @@ bool FileHandlerImpl::ReadFrame(WebRtc_UWord8* source_buffer) {
|
||||
return false;
|
||||
}
|
||||
if (feof(input_file_) != 0) {
|
||||
return false; // no more frames to process
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
WebRtc_UWord64 FileHandlerImpl::GetFileSize(std::string filename) {
|
||||
FILE* f = fopen(filename.c_str(), "rb");
|
||||
WebRtc_UWord64 size = 0;
|
||||
if (f != NULL) {
|
||||
if (fseek(f, 0, SEEK_END) == 0) {
|
||||
size = ftell(f);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
bool FileHandlerImpl::WriteFrame(WebRtc_UWord8* frame_buffer) {
|
||||
assert(frame_buffer);
|
||||
if (output_file_ == NULL) {
|
||||
fprintf(stderr, "FileHandler is not initialized (output file is NULL)\n");
|
||||
return false;
|
||||
}
|
||||
int bytes_written = fwrite(frame_buffer, 1, frame_length_in_bytes_,
|
||||
output_file_);
|
||||
if (bytes_written != frame_length_in_bytes_) {
|
||||
fprintf(stderr, "Failed to write %d bytes to file %s\n",
|
||||
frame_length_in_bytes_, output_filename_.c_str());
|
||||
return false;
|
||||
return false; // No more frames to process.
|
||||
}
|
||||
return true;
|
||||
}
|
73
test/testsupport/frame_reader.h
Normal file
73
test/testsupport/frame_reader.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Handles reading of frames from video files.
|
||||
class FrameReader {
|
||||
public:
|
||||
virtual ~FrameReader() {}
|
||||
|
||||
// Initializes the frame reader, i.e. opens the input file.
|
||||
// This must be called before reading of frames has started.
|
||||
// Returns false if an error has occurred, in addition to printing to stderr.
|
||||
virtual bool Init() = 0;
|
||||
|
||||
// Reads a frame into the supplied buffer, which must contain enough space
|
||||
// for the frame size.
|
||||
// Returns true if there are more frames to read, false if we've already
|
||||
// read the last frame (in the previous call).
|
||||
virtual bool ReadFrame(WebRtc_UWord8* source_buffer) = 0;
|
||||
|
||||
// Closes the input file if open. Essentially makes this class impossible
|
||||
// to use anymore. Will also be invoked by the destructor.
|
||||
virtual void Close() = 0;
|
||||
|
||||
// Frame length in bytes of a single frame image.
|
||||
virtual int FrameLength() = 0;
|
||||
// Total number of frames in the input video source.
|
||||
virtual int NumberOfFrames() = 0;
|
||||
};
|
||||
|
||||
class FrameReaderImpl : public FrameReader {
|
||||
public:
|
||||
// Creates a file handler. The input file is assumed to exist and be readable.
|
||||
// Parameters:
|
||||
// input_filename The file to read from.
|
||||
// frame_length_in_bytes The size of each frame.
|
||||
// For YUV this is 3 * width * height / 2
|
||||
FrameReaderImpl(std::string input_filename, int frame_length_in_bytes);
|
||||
virtual ~FrameReaderImpl();
|
||||
bool Init();
|
||||
bool ReadFrame(WebRtc_UWord8* source_buffer);
|
||||
void Close();
|
||||
int FrameLength() { return frame_length_in_bytes_; }
|
||||
int NumberOfFrames() { return number_of_frames_; }
|
||||
|
||||
private:
|
||||
std::string input_filename_;
|
||||
int frame_length_in_bytes_;
|
||||
int number_of_frames_;
|
||||
FILE* input_file_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_
|
72
test/testsupport/frame_reader_unittest.cc
Normal file
72
test/testsupport/frame_reader_unittest.cc
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testsupport/frame_reader.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
const std::string kInputFilename = "temp_inputfile.tmp";
|
||||
const std::string kInputFileContents = "baz";
|
||||
// Setting the kFrameLength value to a value much larger than the
|
||||
// file to test causes the ReadFrame test to fail on Windows.
|
||||
const int kFrameLength = 1000;
|
||||
|
||||
class FrameReaderTest: public testing::Test {
|
||||
protected:
|
||||
FrameReaderTest() {}
|
||||
virtual ~FrameReaderTest() {}
|
||||
void SetUp() {
|
||||
// Cleanup any previous dummy input file.
|
||||
std::remove(kInputFilename.c_str());
|
||||
|
||||
// Create a dummy input file.
|
||||
FILE* dummy = fopen(kInputFilename.c_str(), "wb");
|
||||
fprintf(dummy, "%s", kInputFileContents.c_str());
|
||||
fclose(dummy);
|
||||
|
||||
frame_reader_ = new FrameReaderImpl(kInputFilename, kFrameLength);
|
||||
ASSERT_TRUE(frame_reader_->Init());
|
||||
}
|
||||
void TearDown() {
|
||||
delete frame_reader_;
|
||||
// Cleanup the dummy input file.
|
||||
std::remove(kInputFilename.c_str());
|
||||
}
|
||||
FrameReader* frame_reader_;
|
||||
};
|
||||
|
||||
TEST_F(FrameReaderTest, InitSuccess) {
|
||||
FrameReaderImpl frame_reader(kInputFilename, kFrameLength);
|
||||
ASSERT_TRUE(frame_reader.Init());
|
||||
ASSERT_EQ(kFrameLength, frame_reader.FrameLength());
|
||||
ASSERT_EQ(0, frame_reader.NumberOfFrames());
|
||||
}
|
||||
|
||||
TEST_F(FrameReaderTest, ReadFrame) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
bool result = frame_reader_->ReadFrame(buffer);
|
||||
ASSERT_FALSE(result); // No more files to read.
|
||||
ASSERT_EQ(kInputFileContents[0], buffer[0]);
|
||||
ASSERT_EQ(kInputFileContents[1], buffer[1]);
|
||||
ASSERT_EQ(kInputFileContents[2], buffer[2]);
|
||||
}
|
||||
|
||||
TEST_F(FrameReaderTest, ReadFrameUninitialized) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
FrameReaderImpl file_reader(kInputFilename, kFrameLength);
|
||||
ASSERT_FALSE(file_reader.ReadFrame(buffer));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
68
test/testsupport/frame_writer.cc
Normal file
68
test/testsupport/frame_writer.cc
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testsupport/frame_writer.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
FrameWriterImpl::FrameWriterImpl(std::string output_filename,
|
||||
int frame_length_in_bytes)
|
||||
: output_filename_(output_filename),
|
||||
frame_length_in_bytes_(frame_length_in_bytes),
|
||||
output_file_(NULL) {
|
||||
}
|
||||
|
||||
FrameWriterImpl::~FrameWriterImpl() {
|
||||
Close();
|
||||
}
|
||||
|
||||
bool FrameWriterImpl::Init() {
|
||||
if (frame_length_in_bytes_ <= 0) {
|
||||
fprintf(stderr, "Frame length must be >0, was %d\n",
|
||||
frame_length_in_bytes_);
|
||||
return false;
|
||||
}
|
||||
output_file_ = fopen(output_filename_.c_str(), "wb");
|
||||
if (output_file_ == NULL) {
|
||||
fprintf(stderr, "Couldn't open output file for writing: %s\n",
|
||||
output_filename_.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FrameWriterImpl::Close() {
|
||||
if (output_file_ != NULL) {
|
||||
fclose(output_file_);
|
||||
output_file_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool FrameWriterImpl::WriteFrame(WebRtc_UWord8* frame_buffer) {
|
||||
assert(frame_buffer);
|
||||
if (output_file_ == NULL) {
|
||||
fprintf(stderr, "FileHandler is not initialized (output file is NULL)\n");
|
||||
return false;
|
||||
}
|
||||
int bytes_written = fwrite(frame_buffer, 1, frame_length_in_bytes_,
|
||||
output_file_);
|
||||
if (bytes_written != frame_length_in_bytes_) {
|
||||
fprintf(stderr, "Failed to write %d bytes to file %s\n",
|
||||
frame_length_in_bytes_, output_filename_.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
70
test/testsupport/frame_writer.h
Normal file
70
test/testsupport/frame_writer.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Handles writing of video files.
|
||||
class FrameWriter {
|
||||
public:
|
||||
virtual ~FrameWriter() {}
|
||||
|
||||
// Initializes the file handler, i.e. opens the input and output files etc.
|
||||
// This must be called before reading or writing frames has started.
|
||||
// Returns false if an error has occurred, in addition to printing to stderr.
|
||||
virtual bool Init() = 0;
|
||||
|
||||
// Writes a frame of the configured frame length to the output file.
|
||||
// Returns true if the write was successful, false otherwise.
|
||||
virtual bool WriteFrame(WebRtc_UWord8* frame_buffer) = 0;
|
||||
|
||||
// Closes the output file if open. Essentially makes this class impossible
|
||||
// to use anymore. Will also be invoked by the destructor.
|
||||
virtual void Close() = 0;
|
||||
|
||||
// Frame length in bytes of a single frame image.
|
||||
virtual int FrameLength() = 0;
|
||||
};
|
||||
|
||||
class FrameWriterImpl : public FrameWriter {
|
||||
public:
|
||||
// Creates a file handler. The input file is assumed to exist and be readable
|
||||
// and the output file must be writable.
|
||||
// Parameters:
|
||||
// output_filename The file to write. Will be overwritten if already
|
||||
// existing.
|
||||
// frame_length_in_bytes The size of each frame.
|
||||
// For YUV: 3*width*height/2
|
||||
FrameWriterImpl(std::string output_filename, int frame_length_in_bytes);
|
||||
virtual ~FrameWriterImpl();
|
||||
bool Init();
|
||||
bool WriteFrame(WebRtc_UWord8* frame_buffer);
|
||||
void Close();
|
||||
int FrameLength() { return frame_length_in_bytes_; }
|
||||
|
||||
private:
|
||||
std::string output_filename_;
|
||||
int frame_length_in_bytes_;
|
||||
int number_of_frames_;
|
||||
FILE* output_file_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_
|
64
test/testsupport/frame_writer_unittest.cc
Normal file
64
test/testsupport/frame_writer_unittest.cc
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testsupport/frame_writer.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "testsupport/fileutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
const std::string kOutputFilename = "temp_outputfile.tmp";
|
||||
const int kFrameLength = 1000;
|
||||
|
||||
class FrameWriterTest: public testing::Test {
|
||||
protected:
|
||||
FrameWriterTest() {}
|
||||
virtual ~FrameWriterTest() {}
|
||||
void SetUp() {
|
||||
// Cleanup any previous output file.
|
||||
std::remove(kOutputFilename.c_str());
|
||||
frame_writer_ = new FrameWriterImpl(kOutputFilename, kFrameLength);
|
||||
ASSERT_TRUE(frame_writer_->Init());
|
||||
}
|
||||
void TearDown() {
|
||||
delete frame_writer_;
|
||||
// Cleanup the temporary file.
|
||||
std::remove(kOutputFilename.c_str());
|
||||
}
|
||||
FrameWriter* frame_writer_;
|
||||
};
|
||||
|
||||
TEST_F(FrameWriterTest, InitSuccess) {
|
||||
FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
|
||||
ASSERT_TRUE(frame_writer.Init());
|
||||
ASSERT_EQ(kFrameLength, frame_writer.FrameLength());
|
||||
}
|
||||
|
||||
TEST_F(FrameWriterTest, WriteFrame) {
|
||||
WebRtc_UWord8 buffer[kFrameLength];
|
||||
memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer
|
||||
bool result = frame_writer_->WriteFrame(buffer);
|
||||
ASSERT_TRUE(result); // success
|
||||
// Close the file and verify the size.
|
||||
frame_writer_->Close();
|
||||
ASSERT_EQ(kFrameLength,
|
||||
static_cast<int>(GetFileSize(kOutputFilename)));
|
||||
}
|
||||
|
||||
TEST_F(FrameWriterTest, WriteFrameUninitialized) {
|
||||
WebRtc_UWord8 buffer[3];
|
||||
FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
|
||||
ASSERT_FALSE(frame_writer.WriteFrame(buffer));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
@ -8,7 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "video_metrics.h"
|
||||
#include "testsupport/metrics/video_metrics.h"
|
||||
|
||||
#include <algorithm> // min_element, max_element
|
||||
#include <cmath>
|
||||
@ -43,6 +43,7 @@ PsnrFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
{
|
||||
// cannot open test file
|
||||
fprintf(stderr, "Cannot open file %s\n", testFileName);
|
||||
fclose(refFp);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@ -97,12 +98,12 @@ PsnrFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
{
|
||||
result->average = CalcPsnr(mseSum / frames);
|
||||
}
|
||||
|
||||
int return_code = 0;
|
||||
if (result->frames.size() == 0)
|
||||
{
|
||||
fprintf(stderr, "Tried to measure SSIM from empty files (reference "
|
||||
"file: %s test file: %s\n", refFileName, testFileName);
|
||||
return -3;
|
||||
return_code = -3;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -119,11 +120,9 @@ PsnrFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
}
|
||||
delete [] ref;
|
||||
delete [] test;
|
||||
|
||||
fclose(refFp);
|
||||
fclose(testFp);
|
||||
|
||||
return 0;
|
||||
return return_code;
|
||||
}
|
||||
|
||||
static double
|
||||
@ -305,6 +304,7 @@ SsimFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
{
|
||||
// cannot open test file
|
||||
fprintf(stderr, "Cannot open file %s\n", testFileName);
|
||||
fclose(refFp);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@ -335,12 +335,12 @@ SsimFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
refBytes = (WebRtc_Word32) fread(ref, 1, frameBytes, refFp);
|
||||
testBytes = (WebRtc_Word32) fread(test, 1, frameBytes, testFp);
|
||||
}
|
||||
|
||||
int return_code = 0;
|
||||
if (result->frames.size() == 0)
|
||||
{
|
||||
fprintf(stderr, "Tried to measure SSIM from empty files (reference "
|
||||
"file: %s test file: %s\n", refFileName, testFileName);
|
||||
return -3;
|
||||
return_code = -3;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -361,9 +361,7 @@ SsimFromFiles(const WebRtc_Word8 *refFileName, const WebRtc_Word8 *testFileName,
|
||||
}
|
||||
delete [] ref;
|
||||
delete [] test;
|
||||
|
||||
fclose(refFp);
|
||||
fclose(testFp);
|
||||
|
||||
return 0;
|
||||
return return_code;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "video_metrics.h"
|
||||
#include "testsupport/metrics/video_metrics.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
33
test/testsupport/mock/mock_frame_reader.h
Normal file
33
test/testsupport/mock/mock_frame_reader.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_READER_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_READER_H_
|
||||
|
||||
#include "testsupport/frame_reader.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
class MockFrameReader : public FrameReader {
|
||||
public:
|
||||
MOCK_METHOD0(Init, bool());
|
||||
MOCK_METHOD1(ReadFrame, bool(WebRtc_UWord8* source_buffer));
|
||||
MOCK_METHOD0(Close, void());
|
||||
MOCK_METHOD0(FrameLength, int());
|
||||
MOCK_METHOD0(NumberOfFrames, int());
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_READER_H_
|
32
test/testsupport/mock/mock_frame_writer.h
Normal file
32
test/testsupport/mock/mock_frame_writer.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_WRITER_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_WRITER_H_
|
||||
|
||||
#include "testsupport/frame_writer.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
class MockFrameWriter : public FrameWriter {
|
||||
public:
|
||||
MOCK_METHOD0(Init, bool());
|
||||
MOCK_METHOD1(WriteFrame, bool(WebRtc_UWord8* frame_buffer));
|
||||
MOCK_METHOD0(Close, void());
|
||||
MOCK_METHOD0(FrameLength, int());
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_MOCK_MOCK_FRAME_WRITER_H_
|
@ -7,7 +7,8 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "packet_reader.h"
|
||||
|
||||
#include "testsupport/packet_reader.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
@ -16,11 +17,9 @@ namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
PacketReader::PacketReader()
|
||||
: initialized_(false) {
|
||||
}
|
||||
: initialized_(false) {}
|
||||
|
||||
PacketReader::~PacketReader() {
|
||||
}
|
||||
PacketReader::~PacketReader() {}
|
||||
|
||||
void PacketReader::InitializeReading(WebRtc_UWord8* data,
|
||||
int data_length_in_bytes,
|
@ -7,8 +7,9 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_READER_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_READER_H_
|
||||
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
@ -49,4 +50,4 @@ class PacketReader {
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_PACKET_READER_H_
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
|
@ -7,34 +7,25 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testsupport/packet_reader.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "packet_reader.h"
|
||||
#include "typedefs.h"
|
||||
#include "unittest_utils.h"
|
||||
#include "testsupport/unittest_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
class PacketReaderTest: public PacketRelatedTest {
|
||||
protected:
|
||||
PacketReader* reader_;
|
||||
|
||||
PacketReaderTest() {
|
||||
// To avoid warnings when using ASSERT_DEATH
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
}
|
||||
|
||||
virtual ~PacketReaderTest() {
|
||||
}
|
||||
|
||||
PacketReaderTest() {}
|
||||
virtual ~PacketReaderTest() {}
|
||||
void SetUp() {
|
||||
reader_ = new PacketReader();
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
delete reader_;
|
||||
}
|
||||
|
||||
void VerifyPacketData(int expected_length,
|
||||
int actual_length,
|
||||
WebRtc_UWord8* original_data_pointer,
|
||||
@ -44,6 +35,7 @@ class PacketReaderTest: public PacketRelatedTest {
|
||||
EXPECT_EQ(0, memcmp(original_data_pointer, new_data_pointer,
|
||||
actual_length));
|
||||
}
|
||||
PacketReader* reader_;
|
||||
};
|
||||
|
||||
// Test lack of initialization
|
||||
@ -53,26 +45,11 @@ TEST_F(PacketReaderTest, Uninitialized) {
|
||||
EXPECT_EQ(NULL, data_pointer);
|
||||
}
|
||||
|
||||
TEST_F(PacketReaderTest, InitializeNullDataArgument) {
|
||||
ASSERT_DEATH(reader_->InitializeReading(NULL, kPacketDataLength,
|
||||
kPacketSizeInBytes), "");
|
||||
}
|
||||
|
||||
TEST_F(PacketReaderTest, InitializeInvalidLengthArgument) {
|
||||
ASSERT_DEATH(reader_->InitializeReading(packet_data_, -1, kPacketSizeInBytes),
|
||||
"");
|
||||
}
|
||||
|
||||
TEST_F(PacketReaderTest, InitializeZeroLengthArgument) {
|
||||
reader_->InitializeReading(packet_data_, 0, kPacketSizeInBytes);
|
||||
ASSERT_EQ(0, reader_->NextPacket(&packet_data_pointer_));
|
||||
}
|
||||
|
||||
TEST_F(PacketReaderTest, InitializeInvalidPacketSizeArgument) {
|
||||
ASSERT_DEATH(reader_->InitializeReading(packet_data_, kPacketDataLength,
|
||||
0), "");
|
||||
}
|
||||
|
||||
// Test with something smaller than one packet
|
||||
TEST_F(PacketReaderTest, NormalSmallData) {
|
||||
const int kDataLengthInBytes = 1499;
|
@ -1,9 +1,15 @@
|
||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
// Author: kjellander@google.com (Henrik Kjellander)
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SRC_MODULES_VIDEO_CODING_CODECS_TEST_UNITTEST_UTILS_H_
|
||||
#define SRC_MODULES_VIDEO_CODING_CODECS_TEST_UNITTEST_UTILS_H_
|
||||
#ifndef WEBRTC_TEST_TESTSUPPORT_UNITTEST_UTILS_H_
|
||||
#define WEBRTC_TEST_TESTSUPPORT_UNITTEST_UTILS_H_
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -39,20 +45,15 @@ class PacketRelatedTest: public testing::Test {
|
||||
kPacketSizeInBytes);
|
||||
memcpy(packet_data_pointer_ + kPacketSizeInBytes * 2, packet3_, 1);
|
||||
}
|
||||
|
||||
virtual ~PacketRelatedTest() {
|
||||
}
|
||||
|
||||
virtual ~PacketRelatedTest() {}
|
||||
void SetUp() {
|
||||
// Initialize the random generator with 0 to get deterministic behavior
|
||||
srand(0);
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SRC_MODULES_VIDEO_CODING_CODECS_TEST_UNITTEST_UTILS_H_
|
||||
#endif // WEBRTC_TEST_TESTSUPPORT_UNITTEST_UTILS_H_
|
Loading…
x
Reference in New Issue
Block a user