blob: 2c19923283d57cb47323a334011e49ed39ed7352 [file] [log] [blame]
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +00001/*
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
kjellanderd2b63cf2017-06-30 03:04:59 -070011#ifndef WEBRTC_RTC_TOOLS_CONVERTER_CONVERTER_H_
12#define WEBRTC_RTC_TOOLS_CONVERTER_CONVERTER_H_
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000013
14#include <string>
15
kjellander@webrtc.orgd7e34e12015-01-26 19:17:26 +000016#include "libyuv/compare.h" // NOLINT
17#include "libyuv/convert.h" // NOLINT
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000018
19namespace webrtc {
20namespace test {
21
22// Handles a conversion between a set of RGBA frames to a YUV (I420) video.
23class Converter {
24 public:
25 Converter(int width, int height);
26
vspasova@webrtc.org8e221ee2012-08-15 07:42:00 +000027 // Converts RGBA to YUV video. If the delete_frames argument is true, the
28 // method will delete the input frames after conversion.
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000029 bool ConvertRGBAToI420Video(std::string frames_dir,
vspasova@webrtc.org8e221ee2012-08-15 07:42:00 +000030 std::string output_file_name, bool delete_frames);
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000031
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.
37 int YPlaneSize() const {
38 return width_*height_;
39 }
40
41 // Returns the size of the U plane in bytes.
42 int UPlaneSize() const {
43 return ((width_+1)/2)*((height_)/2);
44 }
45
46 // Returns the size of the V plane in bytes.
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.
52 int SrcStrideFrame() const {
53 return width_*4;
54 }
55
56 // Returns the number of bytes in the Y plane.
57 int DstStrideY() const {
58 return width_;
59 }
60
61 // Returns the number of bytes in the U plane.
62 int DstStrideU() const {
63 return (width_+1)/2;
64 }
65
66 // Returns the number of bytes in the V plane.
67 int DstStrideV() const {
68 return (width_+1)/2;
69 }
70
71 // Returns the size in bytes of the input RGBA frames.
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.
Peter Boström0c4e06b2015-10-07 12:23:21 +020078 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,
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000084 FILE* output_file);
85
86 // Adds the Y, U or V plane to the file.
Peter Boström0c4e06b2015-10-07 12:23:21 +020087 bool AddYUVPlaneToFile(uint8_t* yuv_plane, int yuv_plane_size, FILE* file);
vspasova@webrtc.orgb358bd82012-07-02 07:43:30 +000088
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
kjellanderd2b63cf2017-06-30 03:04:59 -0700109#endif // WEBRTC_RTC_TOOLS_CONVERTER_CONVERTER_H_