ivf_file_writer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2016 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 MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_
  11. #define MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <memory>
  15. #include "api/video/encoded_image.h"
  16. #include "api/video/video_codec_type.h"
  17. #include "rtc_base/constructor_magic.h"
  18. #include "rtc_base/system/file_wrapper.h"
  19. #include "rtc_base/time_utils.h"
  20. namespace webrtc {
  21. class IvfFileWriter {
  22. public:
  23. // Takes ownership of the file, which will be closed either through
  24. // Close or ~IvfFileWriter. If writing a frame would take the file above the
  25. // |byte_limit| the file will be closed, the write (and all future writes)
  26. // will fail. A |byte_limit| of 0 is equivalent to no limit.
  27. static std::unique_ptr<IvfFileWriter> Wrap(FileWrapper file,
  28. size_t byte_limit);
  29. ~IvfFileWriter();
  30. bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type);
  31. bool Close();
  32. private:
  33. explicit IvfFileWriter(FileWrapper file, size_t byte_limit);
  34. bool WriteHeader();
  35. bool InitFromFirstFrame(const EncodedImage& encoded_image,
  36. VideoCodecType codec_type);
  37. bool WriteOneSpatialLayer(int64_t timestamp,
  38. const uint8_t* data,
  39. size_t size);
  40. VideoCodecType codec_type_;
  41. size_t bytes_written_;
  42. size_t byte_limit_;
  43. size_t num_frames_;
  44. uint16_t width_;
  45. uint16_t height_;
  46. int64_t last_timestamp_;
  47. bool using_capture_timestamps_;
  48. rtc::TimestampWrapAroundHandler wrap_handler_;
  49. FileWrapper file_;
  50. RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter);
  51. };
  52. } // namespace webrtc
  53. #endif // MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_