blob: 4775beddac85a51b69298c5b13552e74a5395de3 [file] [log] [blame]
sprang3911c262016-04-15 01:24:14 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_
12#define MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_
sprang3911c262016-04-15 01:24:14 -070013
14#include <memory>
15#include <string>
16
Niels Möller4dc66c52018-10-05 14:17:58 +020017#include "api/video/encoded_image.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/include/module_common_types.h"
19#include "rtc_base/constructormagic.h"
20#include "rtc_base/file.h"
21#include "rtc_base/timeutils.h"
sprang3911c262016-04-15 01:24:14 -070022
23namespace webrtc {
24
25class IvfFileWriter {
26 public:
palmkviste75f2042016-09-28 06:19:48 -070027 // 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);
sprang3911c262016-04-15 01:24:14 -070032 ~IvfFileWriter();
33
palmkviste75f2042016-09-28 06:19:48 -070034 bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type);
sprang3911c262016-04-15 01:24:14 -070035 bool Close();
36
37 private:
palmkviste75f2042016-09-28 06:19:48 -070038 explicit IvfFileWriter(rtc::File file, size_t byte_limit);
sprang3911c262016-04-15 01:24:14 -070039
palmkviste75f2042016-09-28 06:19:48 -070040 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_;
sprang3911c262016-04-15 01:24:14 -070047 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_;
palmkviste75f2042016-09-28 06:19:48 -070053 rtc::File file_;
sprang3911c262016-04-15 01:24:14 -070054
55 RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter);
56};
57
58} // namespace webrtc
59
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#endif // MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_