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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |
| 12 | #define MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 16 | |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 17 | #include <memory> |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 18 | |
Niels Möller | 4dc66c5 | 2018-10-05 14:17:58 +0200 | [diff] [blame] | 19 | #include "api/video/encoded_image.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/constructor_magic.h" |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 21 | #include "rtc_base/system/file_wrapper.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "rtc_base/time_utils.h" |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class IvfFileWriter { |
| 27 | public: |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 28 | // Takes ownership of the file, which will be closed either through |
| 29 | // Close or ~IvfFileWriter. If writing a frame would take the file above the |
| 30 | // |byte_limit| the file will be closed, the write (and all future writes) |
| 31 | // will fail. A |byte_limit| of 0 is equivalent to no limit. |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 32 | static std::unique_ptr<IvfFileWriter> Wrap(FileWrapper file, |
| 33 | size_t byte_limit); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 34 | ~IvfFileWriter(); |
| 35 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 36 | bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 37 | bool Close(); |
| 38 | |
| 39 | private: |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 40 | explicit IvfFileWriter(FileWrapper file, size_t byte_limit); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 41 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 42 | bool WriteHeader(); |
| 43 | bool InitFromFirstFrame(const EncodedImage& encoded_image, |
| 44 | VideoCodecType codec_type); |
| 45 | |
| 46 | VideoCodecType codec_type_; |
| 47 | size_t bytes_written_; |
| 48 | size_t byte_limit_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 49 | size_t num_frames_; |
| 50 | uint16_t width_; |
| 51 | uint16_t height_; |
| 52 | int64_t last_timestamp_; |
| 53 | bool using_capture_timestamps_; |
| 54 | rtc::TimestampWrapAroundHandler wrap_handler_; |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 55 | FileWrapper file_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 56 | |
| 57 | RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter); |
| 58 | }; |
| 59 | |
| 60 | } // namespace webrtc |
| 61 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 62 | #endif // MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_ |