1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_TOOLS_CONVERTER_CONVERTER_H_ 12 #define WEBRTC_TOOLS_CONVERTER_CONVERTER_H_ 13 14 #include <string> 15 16 #include "libyuv/compare.h" // NOLINT 17 #include "libyuv/convert.h" // NOLINT 18 19 namespace webrtc { 20 namespace test { 21 22 // Handles a conversion between a set of RGBA frames to a YUV (I420) video. 23 class Converter { 24 public: 25 Converter(int width, int height); 26 27 // Converts RGBA to YUV video. If the delete_frames argument is true, the 28 // method will delete the input frames after conversion. 29 bool ConvertRGBAToI420Video(std::string frames_dir, 30 std::string output_file_name, bool delete_frames); 31 32 private: 33 int width_; // Width of the video (respectively of the RGBA frames). 34 int height_; // Height of the video (respectively of the RGBA frames). 35 36 // Returns the size of the Y plane in bytes. YPlaneSize()37 int YPlaneSize() const { 38 return width_*height_; 39 } 40 41 // Returns the size of the U plane in bytes. UPlaneSize()42 int UPlaneSize() const { 43 return ((width_+1)/2)*((height_)/2); 44 } 45 46 // Returns the size of the V plane in bytes. VPlaneSize()47 int VPlaneSize() const { 48 return ((width_+1)/2)*((height_)/2); 49 } 50 51 // Returns the number of bytes per row in the RGBA frame. SrcStrideFrame()52 int SrcStrideFrame() const { 53 return width_*4; 54 } 55 56 // Returns the number of bytes in the Y plane. DstStrideY()57 int DstStrideY() const { 58 return width_; 59 } 60 61 // Returns the number of bytes in the U plane. DstStrideU()62 int DstStrideU() const { 63 return (width_+1)/2; 64 } 65 66 // Returns the number of bytes in the V plane. DstStrideV()67 int DstStrideV() const { 68 return (width_+1)/2; 69 } 70 71 // Returns the size in bytes of the input RGBA frames. InputFrameSize()72 int InputFrameSize() const { 73 return width_*height_*4; 74 } 75 76 // Writes the Y, U and V (in this order) planes to the file, thus adding a 77 // raw YUV frame to the file. 78 bool AddYUVToFile(uint8_t* y_plane, 79 int y_plane_size, 80 uint8_t* u_plane, 81 int u_plane_size, 82 uint8_t* v_plane, 83 int v_plane_size, 84 FILE* output_file); 85 86 // Adds the Y, U or V plane to the file. 87 bool AddYUVPlaneToFile(uint8_t* yuv_plane, int yuv_plane_size, FILE* file); 88 89 // Reads a RGBA frame from input_file_name with input_frame_size size in bytes 90 // into the buffer. 91 bool ReadRGBAFrame(const char* input_file_name, int input_frame_size, 92 unsigned char* buffer); 93 94 // Finds the full path name of the file - concatenates the directory and file 95 // names. 96 std::string FindFullFileName(std::string dir_name, std::string file_name); 97 98 // Checks if a file exists. 99 bool FileExists(std::string file_name_to_check); 100 101 // Returns the name of the file in the form frame_<number>, where <number> is 102 // 4 zero padded (i.e. frame_0000, frame_0001, etc.). 103 std::string FormFrameName(int width, int number); 104 }; 105 106 } // namespace test 107 } // namespace webrtc 108 109 #endif // WEBRTC_TOOLS_CONVERTER_CONVERTER_H_ 110