sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | |
nisse | ea3a798 | 2017-05-15 02:42:11 -0700 | [diff] [blame] | 17 | #include "webrtc/common_video/include/video_frame.h" |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 18 | #include "webrtc/modules/include/module_common_types.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 19 | #include "webrtc/rtc_base/constructormagic.h" |
| 20 | #include "webrtc/rtc_base/file.h" |
| 21 | #include "webrtc/rtc_base/timeutils.h" |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | class IvfFileWriter { |
| 26 | public: |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 27 | // Takes ownership of the file, which will be closed either through |
| 28 | // Close or ~IvfFileWriter. If writing a frame would take the file above the |
| 29 | // |byte_limit| the file will be closed, the write (and all future writes) |
| 30 | // will fail. A |byte_limit| of 0 is equivalent to no limit. |
| 31 | static std::unique_ptr<IvfFileWriter> Wrap(rtc::File file, size_t byte_limit); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 32 | ~IvfFileWriter(); |
| 33 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 34 | bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 35 | bool Close(); |
| 36 | |
| 37 | private: |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 38 | explicit IvfFileWriter(rtc::File file, size_t byte_limit); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 39 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 40 | bool WriteHeader(); |
| 41 | bool InitFromFirstFrame(const EncodedImage& encoded_image, |
| 42 | VideoCodecType codec_type); |
| 43 | |
| 44 | VideoCodecType codec_type_; |
| 45 | size_t bytes_written_; |
| 46 | size_t byte_limit_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 47 | size_t num_frames_; |
| 48 | uint16_t width_; |
| 49 | uint16_t height_; |
| 50 | int64_t last_timestamp_; |
| 51 | bool using_capture_timestamps_; |
| 52 | rtc::TimestampWrapAroundHandler wrap_handler_; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 53 | rtc::File file_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 54 | |
| 55 | RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter); |
| 56 | }; |
| 57 | |
| 58 | } // namespace webrtc |
| 59 | |
| 60 | #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |