converter.h 3.2 KB

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