• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RTC_TOOLS_CONVERTER_CONVERTER_H_
12 #define RTC_TOOLS_CONVERTER_CONVERTER_H_
13 
14 #include <stdio.h>
15 
16 #include <string>
17 
18 namespace webrtc {
19 namespace test {
20 
21 // Handles a conversion between a set of RGBA frames to a YUV (I420) video.
22 class Converter {
23  public:
24   Converter(int width, int height);
25 
26   // Converts RGBA to YUV video. If the delete_frames argument is true, the
27   // method will delete the input frames after conversion.
28   bool ConvertRGBAToI420Video(std::string frames_dir,
29                               std::string output_file_name,
30                               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 { return width_ * height_; }
38 
39   // Returns the size of the U plane in bytes.
UPlaneSize()40   int UPlaneSize() const { return ((width_ + 1) / 2) * ((height_) / 2); }
41 
42   // Returns the size of the V plane in bytes.
VPlaneSize()43   int VPlaneSize() const { return ((width_ + 1) / 2) * ((height_) / 2); }
44 
45   // Returns the number of bytes per row in the RGBA frame.
SrcStrideFrame()46   int SrcStrideFrame() const { return width_ * 4; }
47 
48   // Returns the number of bytes in the Y plane.
DstStrideY()49   int DstStrideY() const { return width_; }
50 
51   // Returns the number of bytes in the U plane.
DstStrideU()52   int DstStrideU() const { return (width_ + 1) / 2; }
53 
54   // Returns the number of bytes in the V plane.
DstStrideV()55   int DstStrideV() const { return (width_ + 1) / 2; }
56 
57   // Returns the size in bytes of the input RGBA frames.
InputFrameSize()58   int InputFrameSize() const { return width_ * height_ * 4; }
59 
60   // Writes the Y, U and V (in this order) planes to the file, thus adding a
61   // raw YUV frame to the file.
62   bool AddYUVToFile(uint8_t* y_plane,
63                     int y_plane_size,
64                     uint8_t* u_plane,
65                     int u_plane_size,
66                     uint8_t* v_plane,
67                     int v_plane_size,
68                     FILE* output_file);
69 
70   // Adds the Y, U or V plane to the file.
71   bool AddYUVPlaneToFile(uint8_t* yuv_plane, int yuv_plane_size, FILE* file);
72 
73   // Reads a RGBA frame from input_file_name with input_frame_size size in bytes
74   // into the buffer.
75   bool ReadRGBAFrame(const char* input_file_name,
76                      int input_frame_size,
77                      unsigned char* buffer);
78 
79   // Finds the full path name of the file - concatenates the directory and file
80   // names.
81   std::string FindFullFileName(std::string dir_name, std::string file_name);
82 
83   // Checks if a file exists.
84   bool FileExists(std::string file_name_to_check);
85 
86   // Returns the name of the file in the form frame_<number>, where <number> is
87   // 4 zero padded (i.e. frame_0000, frame_0001, etc.).
88   std::string FormFrameName(int width, int number);
89 };
90 
91 }  // namespace test
92 }  // namespace webrtc
93 
94 #endif  // RTC_TOOLS_CONVERTER_CONVERTER_H_
95