Reformat the WebRTC code base
Running clang-format with chromium's style guide. The goal is n-fold: * providing consistency and readability (that's what code guidelines are for) * preventing noise with presubmit checks and git cl format * building on the previous point: making it easier to automatically fix format issues * you name it Please consider using git-hyper-blame to ignore this commit. Bug: webrtc:9340 Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87 Reviewed-on: https://webrtc-review.googlesource.com/81185 Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23660}
This commit is contained in:
@ -27,10 +27,7 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
Converter::Converter(int width, int height)
|
||||
: width_(width),
|
||||
height_(height) {
|
||||
}
|
||||
Converter::Converter(int width, int height) : width_(width), height_(height) {}
|
||||
|
||||
bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
||||
std::string output_file_name,
|
||||
@ -53,7 +50,7 @@ bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
||||
int v_plane_size = VPlaneSize();
|
||||
uint8_t* dst_v = new uint8_t[v_plane_size];
|
||||
|
||||
int counter = 0; // Counter to form frame names.
|
||||
int counter = 0; // Counter to form frame names.
|
||||
bool success = false; // Is conversion successful.
|
||||
|
||||
while (true) {
|
||||
@ -79,16 +76,13 @@ bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
||||
}
|
||||
|
||||
// Convert to I420 frame.
|
||||
libyuv::ABGRToI420(rgba_buffer, SrcStrideFrame(),
|
||||
dst_y, DstStrideY(),
|
||||
dst_u, DstStrideU(),
|
||||
dst_v, DstStrideV(),
|
||||
width_, height_);
|
||||
libyuv::ABGRToI420(rgba_buffer, SrcStrideFrame(), dst_y, DstStrideY(),
|
||||
dst_u, DstStrideU(), dst_v, DstStrideV(), width_,
|
||||
height_);
|
||||
|
||||
// Add the I420 frame to the YUV video file.
|
||||
success = AddYUVToFile(dst_y, y_plane_size, dst_u, u_plane_size,
|
||||
dst_v, v_plane_size, output_file);
|
||||
|
||||
success = AddYUVToFile(dst_y, y_plane_size, dst_u, u_plane_size, dst_v,
|
||||
v_plane_size, output_file);
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "LibYUV error during RGBA to I420 frame conversion\n");
|
||||
@ -125,14 +119,17 @@ bool Converter::AddYUVPlaneToFile(uint8_t* yuv_plane,
|
||||
size_t bytes_written = fwrite(yuv_plane, 1, yuv_plane_size, file);
|
||||
|
||||
if (bytes_written != static_cast<size_t>(yuv_plane_size)) {
|
||||
fprintf(stderr, "Number of bytes written (%d) doesn't match size of y plane"
|
||||
" (%d)\n", static_cast<int>(bytes_written), yuv_plane_size);
|
||||
fprintf(stderr,
|
||||
"Number of bytes written (%d) doesn't match size of y plane"
|
||||
" (%d)\n",
|
||||
static_cast<int>(bytes_written), yuv_plane_size);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Converter::ReadRGBAFrame(const char* input_file_name, int input_frame_size,
|
||||
bool Converter::ReadRGBAFrame(const char* input_file_name,
|
||||
int input_frame_size,
|
||||
unsigned char* buffer) {
|
||||
FILE* input_file = fopen(input_file_name, "rb");
|
||||
if (input_file == NULL) {
|
||||
@ -157,7 +154,7 @@ std::string Converter::FindFullFileName(std::string dir_name,
|
||||
return dir_name + SEPARATOR + file_name;
|
||||
}
|
||||
|
||||
bool Converter:: FileExists(std::string file_name_to_check) {
|
||||
bool Converter::FileExists(std::string file_name_to_check) {
|
||||
struct STAT file_info;
|
||||
int result = STAT(file_name_to_check.c_str(), &file_info);
|
||||
return (result == 0);
|
||||
|
@ -27,51 +27,36 @@ class Converter {
|
||||
// Converts RGBA to YUV video. If the delete_frames argument is true, the
|
||||
// method will delete the input frames after conversion.
|
||||
bool ConvertRGBAToI420Video(std::string frames_dir,
|
||||
std::string output_file_name, bool delete_frames);
|
||||
std::string output_file_name,
|
||||
bool delete_frames);
|
||||
|
||||
private:
|
||||
int width_; // Width of the video (respectively of the RGBA frames).
|
||||
int width_; // Width of the video (respectively of the RGBA frames).
|
||||
int height_; // Height of the video (respectively of the RGBA frames).
|
||||
|
||||
// Returns the size of the Y plane in bytes.
|
||||
int YPlaneSize() const {
|
||||
return width_*height_;
|
||||
}
|
||||
int YPlaneSize() const { return width_ * height_; }
|
||||
|
||||
// Returns the size of the U plane in bytes.
|
||||
int UPlaneSize() const {
|
||||
return ((width_+1)/2)*((height_)/2);
|
||||
}
|
||||
int UPlaneSize() const { return ((width_ + 1) / 2) * ((height_) / 2); }
|
||||
|
||||
// Returns the size of the V plane in bytes.
|
||||
int VPlaneSize() const {
|
||||
return ((width_+1)/2)*((height_)/2);
|
||||
}
|
||||
int VPlaneSize() const { return ((width_ + 1) / 2) * ((height_) / 2); }
|
||||
|
||||
// Returns the number of bytes per row in the RGBA frame.
|
||||
int SrcStrideFrame() const {
|
||||
return width_*4;
|
||||
}
|
||||
int SrcStrideFrame() const { return width_ * 4; }
|
||||
|
||||
// Returns the number of bytes in the Y plane.
|
||||
int DstStrideY() const {
|
||||
return width_;
|
||||
}
|
||||
int DstStrideY() const { return width_; }
|
||||
|
||||
// Returns the number of bytes in the U plane.
|
||||
int DstStrideU() const {
|
||||
return (width_+1)/2;
|
||||
}
|
||||
int DstStrideU() const { return (width_ + 1) / 2; }
|
||||
|
||||
// Returns the number of bytes in the V plane.
|
||||
int DstStrideV() const {
|
||||
return (width_+1)/2;
|
||||
}
|
||||
int DstStrideV() const { return (width_ + 1) / 2; }
|
||||
|
||||
// Returns the size in bytes of the input RGBA frames.
|
||||
int InputFrameSize() const {
|
||||
return width_*height_*4;
|
||||
}
|
||||
int InputFrameSize() const { return width_ * height_ * 4; }
|
||||
|
||||
// Writes the Y, U and V (in this order) planes to the file, thus adding a
|
||||
// raw YUV frame to the file.
|
||||
@ -88,7 +73,8 @@ class Converter {
|
||||
|
||||
// Reads a RGBA frame from input_file_name with input_frame_size size in bytes
|
||||
// into the buffer.
|
||||
bool ReadRGBAFrame(const char* input_file_name, int input_frame_size,
|
||||
bool ReadRGBAFrame(const char* input_file_name,
|
||||
int input_frame_size,
|
||||
unsigned char* buffer);
|
||||
|
||||
// Finds the full path name of the file - concatenates the directory and file
|
||||
@ -99,7 +85,7 @@ class Converter {
|
||||
bool FileExists(std::string file_name_to_check);
|
||||
|
||||
// Returns the name of the file in the form frame_<number>, where <number> is
|
||||
// 4 zero padded (i.e. frame_0000, frame_0001, etc.).
|
||||
// 4 zero padded (i.e. frame_0000, frame_0001, etc.).
|
||||
std::string FormFrameName(int width, int number);
|
||||
};
|
||||
|
||||
|
@ -28,22 +28,25 @@
|
||||
*/
|
||||
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";
|
||||
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;
|
||||
|
||||
@ -76,9 +79,8 @@ int main(int argc, char* argv[]) {
|
||||
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);
|
||||
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");
|
||||
|
Reference in New Issue
Block a user