Moving frame_analyzer and rgba_to_i420_converter to src/tools.

It might be useful to have these under src/tools as this way they will automatically sync in Chrome.

BUG=

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2653 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
vspasova@webrtc.org 2012-08-22 08:12:00 +00:00
parent 2143c60315
commit f61dc9be41
13 changed files with 442 additions and 164 deletions

View File

@ -92,33 +92,5 @@
'testsupport/packet_reader_unittest.cc',
],
},
{
'target_name': 'rgba_to_i420_converter',
'type': 'executable',
'dependencies': [
'test_support',
'<(DEPTH)/third_party/google-gflags/google-gflags.gyp:google-gflags',
'<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
],
'sources': [
'testsupport/converter/converter.h',
'testsupport/converter/converter.cc',
'testsupport/converter/rgba_to_i420_converter.cc',
],
},
{
'target_name': 'frame_analyzer',
'type': 'executable',
'dependencies': [
'<(webrtc_root)/test/test.gyp:test_support',
'<(DEPTH)/third_party/google-gflags/google-gflags.gyp:google-gflags',
'<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
],
'sources': [
'testsupport/frame_analyzer/frame_analyzer.cc',
'testsupport/frame_analyzer/video_quality_analysis.h',
'testsupport/frame_analyzer/video_quality_analysis.cc',
],
},
],
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cstdio>
#include "google/gflags.h"
#include "test/testsupport/converter/converter.h"
DEFINE_int32(width, -1, "Width in pixels of the frames in the input file.");
DEFINE_int32(height, -1, "Height in pixels of the frames in the input file.");
DEFINE_string(frames_dir, ".", "The path to the directory where the frames "
"reside");
DEFINE_string(output_file, "./output.yuv", "The output file to which frames are"
" written");
DEFINE_bool(delete_frames, false, "Whether or not to delete the input frames "
"after the conversion.");
/*
* A command-line tool based on libyuv to convert a set of RGBA files to a YUV
* video.
* Usage:
* rgba_to_i420_converter --frames_dir=<directory_to_rgba_frames>
* --output_file=<output_yuv_file> --width=<width_of_input_frames>
* --height=<height_of_input_frames>
*/
int main(int argc, char** argv) {
std::string program_name = argv[0];
std::string usage = "Converts RGBA raw image files to I420 frames for YUV.\n"
"Run " + program_name + " --helpshort for usage.\n"
"Example usage:\n" + program_name +
" --frames_dir=. --output_file=output.yuv --width=320 --height=240\n" +
"IMPORTANT: If you pass the --delete_frames command line parameter, the " +
"tool will delete the input frames after conversion.";
google::SetUsageMessage(usage);
google::ParseCommandLineFlags(&argc, &argv, true);
fprintf(stdout, "You entered the following flags: frames_dir=%s, "
"output_file=%s, width=%d, height=%d, delete_frames=%d\n",
FLAGS_frames_dir.c_str(), FLAGS_output_file.c_str(),
FLAGS_width, FLAGS_height, FLAGS_delete_frames);
webrtc::test::Converter converter(FLAGS_width, FLAGS_height);
bool success = converter.ConvertRGBAToI420Video(FLAGS_frames_dir,
FLAGS_output_file,
FLAGS_delete_frames);
if (success) {
fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");
return 0;
} else {
fprintf(stdout, "Unsuccessful conversion of RGBA frames to YUV video!\n");
return -1;
}
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cassert>
#include <cstdio>
#include <sstream>
#include <string>
#include "google/gflags.h"
#include "testsupport/frame_analyzer/video_quality_analysis.h"
#define STATS_LINE_LENGTH 25
DEFINE_string(stats_file, "stats.txt", "The full name of the file "
"containing the stats after decoding of the received YUV video");
DEFINE_string(reference_file, "ref.yuv", "The reference YUV file to compare "
"against.");
DEFINE_string(test_file, "test.yuv", "The test YUV file to run the analysis "
"for.");
DEFINE_int32(width, 352, "The width of the refence and test files.");
DEFINE_int32(height, 288, "The height of the reference and test files.");
int main(int argc, char** argv) {
std::string program_name = argv[0];
std::string usage = "Compares the output video with the initially sent video."
"\nRun " + program_name + " --helpshort for usage.\n"
"Example usage:\n" + program_name + " --stats_file=stats.txt "
"--reference_file=ref.yuv --test_file=test.yuv --width=352 --height=288";
google::SetUsageMessage(usage);
google::ParseCommandLineFlags(&argc, &argv, true);
fprintf(stdout, "You have entered:\n");
fprintf(stdout, "stats_file=%s, reference_file=%s, test_file=%s, width=%d, "
"height=%d\n", FLAGS_stats_file.c_str(), FLAGS_reference_file.c_str(),
FLAGS_test_file.c_str(), FLAGS_width, FLAGS_height);
webrtc::test::ResultsContainer results;
webrtc::test::RunAnalysis(FLAGS_reference_file.c_str(),
FLAGS_test_file.c_str(), FLAGS_stats_file.c_str(),
FLAGS_width, FLAGS_height, &results);
webrtc::test::PrintAnalysisResults(&results);
webrtc::test::PrintMaxRepeatedAndSkippedFrames(FLAGS_stats_file.c_str());
}

View File

@ -10,11 +10,11 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include "test/testsupport/converter/converter.h"
#include "test/testsupport/frame_reader.h"
#include "tools/converter/converter.h"
#ifdef WIN32
#define SEPARATOR '\\'
@ -130,14 +130,21 @@ bool Converter::AddYUVPlaneToFile(uint8* yuv_plane, int yuv_plane_size,
bool Converter::ReadRGBAFrame(const char* input_file_name, int input_frame_size,
unsigned char* buffer) {
// Use FrameReader.
FrameReaderImpl frame_reader(input_file_name, input_frame_size);
if (!frame_reader.Init()) {
fprintf(stderr, "Couldn't initialize FrameReader for frame %s",
FILE* input_file = fopen(input_file_name, "rb");
if (input_file == NULL) {
fprintf(stderr, "Couldn't open input file for reading: %s\n",
input_file_name);
return false;
}
frame_reader.ReadFrame(buffer);
size_t nbr_read = fread(buffer, 1, input_frame_size, input_file);
fclose(input_file);
if (nbr_read != static_cast<size_t>(input_frame_size)) {
fprintf(stderr, "Error reading from input file: %s\n", input_file_name);
return false;
}
return true;
}

View File

@ -8,12 +8,13 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SRC_TEST_TESTSUPPORT_CONVERTER_CONVERTER_H_
#define WEBRTC_SRC_TEST_TESTSUPPORT_CONVERTER_CONVERTER_H_
#ifndef WEBRTC_TOOLS_CONVERTER_CONVERTER_H_
#define WEBRTC_TOOLS_CONVERTER_CONVERTER_H_
#include <string>
#include "third_party/libyuv/include/libyuv.h"
#include "libyuv/convert.h"
#include "libyuv/compare.h"
namespace webrtc {
namespace test {
@ -102,4 +103,4 @@ class Converter {
} // namespace test
} // namespace webrtc
#endif // WEBRTC_SRC_TEST_TESTSUPPORT_CONVERTER_CONVERTER_H_
#endif // WEBRTC_TOOLS_CONVERTER_CONVERTER_H_

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cstdio>
#include <cstdlib>
#include <map>
#include <string>
#include <vector>
#include "tools/converter/converter.h"
#include "tools/simple_command_line_parser.h"
/*
* A command-line tool based on libyuv to convert a set of RGBA files to a YUV
* video.
* Usage:
* rgba_to_i420_converter --frames_dir=<directory_to_rgba_frames>
* --output_file=<output_yuv_file> --width=<width_of_input_frames>
* --height=<height_of_input_frames>
*/
int main(int argc, char** argv) {
std::string program_name = argv[0];
std::string usage = "Converts RGBA raw image files to I420 frames for YUV.\n"
"Example usage:\n" + program_name +
" --frames_dir=. --output_file=output.yuv --width=320 --height=240\n"
"IMPORTANT: If you pass the --delete_frames command line parameter, the "
"tool will delete the input frames after conversion.\n"
"Command line flags:\n"
" - width(int): Width in pixels of the frames in the input file."
" Default: -1\n"
" - height(int): Height in pixels of the frames in the input file."
" Default: -1\n"
" - frames_dir(string): The path to the directory where the frames reside."
" Default: .\n"
" - output_file(string): The output file to which frames are written."
" Default: output.yuv\n"
" - delete_frames(bool): Whether or not to delete the input frames after"
" the conversion. Default: false.\n";
webrtc::test::CommandLineParser parser;
// Init the parser and set the usage message
parser.Init(argc, argv);
parser.SetUsageMessage(usage);
parser.SetFlag("width", "-1");
parser.SetFlag("height", "-1");
parser.SetFlag("frames_dir", ".");
parser.SetFlag("output_file", "output.yuv");
parser.SetFlag("delete_frames", "false");
parser.SetFlag("help", "false");
parser.ProcessFlags();
if (parser.GetFlag("help") == "true") {
parser.PrintUsageMessage();
}
parser.PrintEnteredFlags();
int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
if (width <= 0 || height <= 0) {
fprintf(stderr, "Error: width or height cannot be <= 0!\n");
return -1;
}
bool del_frames = (parser.GetFlag("delete_frames") == "true") ? true : false;
webrtc::test::Converter converter(width, height);
bool success = converter.ConvertRGBAToI420Video(parser.GetFlag("frames_dir"),
parser.GetFlag("output_file"),
del_frames);
if (success) {
fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");
return 0;
} else {
fprintf(stdout, "Unsuccessful conversion of RGBA frames to YUV video!\n");
return -1;
}
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <string>
#include <map>
#include <vector>
#include "tools/frame_analyzer/video_quality_analysis.h"
#include "tools/simple_command_line_parser.h"
#define STATS_LINE_LENGTH 25
int main(int argc, char** argv) {
std::string program_name = argv[0];
std::string usage = "Compares the output video with the initially sent video."
"\nExample usage:\n" + program_name + " --stats_file=stats.txt "
"--reference_file=ref.yuv --test_file=test.yuv --width=320 --height=240\n"
"Command line flags:\n"
" - width(int): The width of the refence and test files. Default: -1\n"
" - height(int): The height of the reference and test files. "
" Default: -1\n"
" - stats_file(string): The full name of the file containing the stats"
" after decoding of the received YUV video. Default: stats.txt\n"
" - reference_file(string): The reference YUV file to compare against."
" Default: ref.yuv\n"
" - test_file(string): The test YUV file to run the analysis for."
" Default: test_file.yuv\n";
webrtc::test::CommandLineParser parser;
// Init the parser and set the usage message
parser.Init(argc, argv);
parser.SetUsageMessage(usage);
parser.SetFlag("width", "-1");
parser.SetFlag("height", "-1");
parser.SetFlag("stats_file", "stats.txt");
parser.SetFlag("reference_file", "ref.yuv");
parser.SetFlag("test_file", "test.yuv");
parser.SetFlag("help", "false");
parser.ProcessFlags();
if (parser.GetFlag("help") == "true") {
parser.PrintUsageMessage();
}
parser.PrintEnteredFlags();
int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
if (width <= 0 || height <= 0) {
fprintf(stderr, "Error: width or height cannot be <= 0!\n");
return -1;
}
webrtc::test::ResultsContainer results;
webrtc::test::RunAnalysis(parser.GetFlag("reference_file").c_str(),
parser.GetFlag("test_file").c_str(),
parser.GetFlag("stats_file").c_str(), width, height,
&results);
webrtc::test::PrintAnalysisResults(&results);
webrtc::test::PrintMaxRepeatedAndSkippedFrames(
parser.GetFlag("stats_file").c_str());
}

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "test/testsupport/frame_analyzer/video_quality_analysis.h"
#include "tools/frame_analyzer/video_quality_analysis.h"
#include <cassert>
#include <cstdio>

View File

@ -8,13 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_TEST_TESTSUPPORT_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
#define WEBRTC_TEST_TESTSUPPORT_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
#ifndef WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
#define WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
#include <string>
#include <vector>
#include "third_party/libyuv/include/libyuv.h"
#include "libyuv/convert.h"
#include "libyuv/compare.h"
namespace webrtc {
namespace test {
@ -68,9 +69,6 @@ bool GetNextStatsLine(FILE* stats_file, char* line);
// Calculates the size of a I420 frame if given the width and height.
unsigned int GetI420FrameSize(unsigned int width, unsigned int height);
// Converts a string to an int.
int StringToInt(std::string number);
// Extract the sequence of the frame in the video. I.e. if line is
// frame_0023 0284, we will get 23.
int ExtractFrameSequenceNumber(std::string line);
@ -94,4 +92,4 @@ bool ExtractFrameFromI420(const char* i420_file_name, int width, int height,
} // namespace test
} // namespace webrtc
#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_
#endif // WEBRTC_TOOLS_FRAME_ANALYZER_VIDEO_QUALITY_ANALYSIS_H_

View File

@ -0,0 +1,130 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "tools/simple_command_line_parser.h"
#include <cstdio>
#include <cstdlib>
namespace webrtc {
namespace test {
void CommandLineParser::Init(int argc, char** argv) {
args_ = std::vector<std::string> (argv + 1, argv + argc);
}
bool CommandLineParser::IsStandaloneFlag(std::string flag) {
int equal_pos = flag.find("=");
if (equal_pos < 0) {
return true;
}
return false;
}
bool CommandLineParser::IsFlagWellFormed(std::string flag) {
int dash_pos = flag.find("--");
int equal_pos = flag.find("=");
if (dash_pos != 0) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Flag doesn't start with --\n");
return false;
}
int flag_length = flag.length() - 1;
// We use 3 here because we assume that the flags are in the format
// --flag_name=flag_value, thus -- are at positions 0 and 1 and we should have
// at least one symbor for the flag name.
if (equal_pos >= 0 && (equal_pos < 3 || equal_pos == flag_length)) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Wrong placement of =\n");
return false;
}
return true;
}
std::string CommandLineParser::GetCommandLineFlagName(std::string flag) {
int dash_pos = flag.find("--");
int equal_pos = flag.find("=");
if (equal_pos < 0) {
return flag.substr(dash_pos+2);
} else {
return flag.substr(dash_pos+2, equal_pos-2);
}
}
std::string CommandLineParser::GetCommandLineFlagValue(std::string flag) {
int equal_pos = flag.find("=");
return flag.substr(equal_pos+1);
}
void CommandLineParser::PrintEnteredFlags() {
std::map<std::string, std::string>::iterator flag_iter;
fprintf(stdout, "You have entered:\n");
for (flag_iter = flags_.begin(); flag_iter != flags_.end(); ++flag_iter) {
if (flag_iter->first != "help") {
fprintf(stdout, "%s=%s, ", flag_iter->first.c_str(),
flag_iter->second.c_str());
}
}
fprintf(stdout, "\n");
}
void CommandLineParser::ProcessFlags() {
std::map<std::string, std::string>::iterator flag_iter;
std::vector<std::string>::iterator iter;
for (iter = args_.begin(); iter != args_.end(); ++iter) {
if (!IsFlagWellFormed(*iter)) {
// Ignore badly formated flags.
continue;
}
std::string flag_name = GetCommandLineFlagName(*iter);
flag_iter = flags_.find(flag_name);
if (flag_iter == flags_.end()) {
// Ignore unknown flags.
fprintf(stdout, "Flag '%s' is not recognized\n", flag_name.c_str());
continue;
}
if (IsStandaloneFlag(*iter)) {
flags_[flag_name] = "true";
} else {
flags_[flag_name] = GetCommandLineFlagValue(*iter);
}
}
}
void CommandLineParser::SetUsageMessage(std::string usage_message) {
usage_message_ = usage_message;
}
void CommandLineParser::PrintUsageMessage() {
fprintf(stdout, "%s", usage_message_.c_str());
}
void CommandLineParser::SetFlag(std::string flag_name, std::string flag_value) {
flags_[flag_name] = flag_value;
}
std::string CommandLineParser::GetFlag(std::string flag_name) {
std::map<std::string, std::string>::iterator flag_iter;
flag_iter = flags_.find(flag_name);
// If no such file.
if (flag_iter == flags_.end()) {
return "";
}
return flag_iter->second;
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_TOOLS_SIMPLE_COMMAND_LINE_PARSER_H_
#define WEBRTC_TOOLS_SIMPLE_COMMAND_LINE_PARSER_H_
#include <string>
#include <map>
#include <vector>
// This is a very basic command line parsing class. We pass the command line
// arguments and their number and the class forms a vector out of these. Than we
// should set up the flags - we provide a name and a string value and map these.
namespace webrtc {
namespace test {
class CommandLineParser {
public:
CommandLineParser() {}
~CommandLineParser() {}
void Init(int argc, char** argv);
// Prints the entered flags and their values (without --help).
void PrintEnteredFlags();
// Processes the vector of command line arguments and puts the value of each
// flag in the corresponding map entry for this flag's name. We don't process
// flags which haven't been defined in the map.
void ProcessFlags();
// Sets the usage message to be shown if we pass --help.
void SetUsageMessage(std::string usage_message);
// prints the usage message.
void PrintUsageMessage();
// Set a flag into the map of flag names/values.
void SetFlag(std::string flag_name, std::string flag_value);
// Gets a flag when provided a flag name. Returns "" if the flag is unknown.
std::string GetFlag(std::string flag_name);
private:
// The vector of passed command line arguments.
std::vector<std::string> args_;
// The map of the flag names/values.
std::map<std::string, std::string> flags_;
// The usage message.
std::string usage_message_;
// Returns whether the passed flag is standalone or not. By standalone we
// understand e.g. --standalone (in contrast to --non_standalone=1).
bool IsStandaloneFlag(std::string flag);
// Checks weather the flag is in the format --flag_name=flag_value.
bool IsFlagWellFormed(std::string flag);
// Extracts the flag name from the flag.
std::string GetCommandLineFlagName(std::string flag);
// Extracts the falg value from the flag.
std::string GetCommandLineFlagValue(std::string flag);
};
} // namespace test
} // namespace webrtc
#endif // WEBRTC_TOOLS_SIMPLE_COMMAND_LINE_PARSER_H_

43
src/tools/tools.gyp Normal file
View File

@ -0,0 +1,43 @@
# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
{
'includes': [
'../build/common.gypi',
],
'targets': [
{
'target_name': 'frame_analyzer',
'type': 'executable',
'dependencies': [
'<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
],
'sources': [
'frame_analyzer/frame_analyzer.cc',
'frame_analyzer/video_quality_analysis.h',
'frame_analyzer/video_quality_analysis.cc',
'simple_command_line_parser.h',
'simple_command_line_parser.cc',
],
},
{
'target_name': 'rgba_to_i420_converter',
'type': 'executable',
'dependencies': [
'<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
],
'sources': [
'converter/converter.h',
'converter/converter.cc',
'converter/rgba_to_i420_converter.cc',
'simple_command_line_parser.h',
'simple_command_line_parser.cc',
],
},
],
}

View File

@ -31,6 +31,7 @@
'dependencies': [
'src/test/metrics.gyp:*',
'src/test/test.gyp:*',
'src/tools/tools.gyp:*',
'tools/e2e_quality/e2e_quality.gyp:*',
],
}],