Home | History | Annotate | Download | only in converter
      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 "third_party/libyuv/include/libyuv/compare.h"
     17 #include "third_party/libyuv/include/libyuv/convert.h"
     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.
     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.
     78   bool AddYUVToFile(uint8* y_plane, int y_plane_size,
     79                     uint8* u_plane, int u_plane_size,
     80                     uint8* v_plane, int v_plane_size,
     81                     FILE* output_file);
     82 
     83   // Adds the Y, U or V plane to the file.
     84   bool AddYUVPlaneToFile(uint8* yuv_plane, int yuv_plane_size, FILE* file);
     85 
     86   // Reads a RGBA frame from input_file_name with input_frame_size size in bytes
     87   // into the buffer.
     88   bool ReadRGBAFrame(const char* input_file_name, int input_frame_size,
     89                      unsigned char* buffer);
     90 
     91   // Finds the full path name of the file - concatenates the directory and file
     92   // names.
     93   std::string FindFullFileName(std::string dir_name, std::string file_name);
     94 
     95   // Checks if a file exists.
     96   bool FileExists(std::string file_name_to_check);
     97 
     98   // Returns the name of the file in the form frame_<number>, where <number> is
     99     // 4 zero padded (i.e. frame_0000, frame_0001, etc.).
    100   std::string FormFrameName(int width, int number);
    101 };
    102 
    103 }  // namespace test
    104 }  // namespace webrtc
    105 
    106 #endif  // WEBRTC_TOOLS_CONVERTER_CONVERTER_H_
    107