blob: 21ebd9762f0daa3550d01a061f514168d1669e67 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
sprang3911c262016-04-15 01:24:14 -070016#include <memory>
sprang3911c262016-04-15 01:24:14 -070017
Niels Möller4dc66c52018-10-05 14:17:58 +020018#include "api/video/encoded_image.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/constructormagic.h"
21#include "rtc_base/file.h"
22#include "rtc_base/timeutils.h"
sprang3911c262016-04-15 01:24:14 -070023
24namespace webrtc {
25
26class IvfFileWriter {
27 public:
palmkviste75f2042016-09-28 06:19:48 -070028 // 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.
32 static std::unique_ptr<IvfFileWriter> Wrap(rtc::File file, size_t byte_limit);
sprang3911c262016-04-15 01:24:14 -070033 ~IvfFileWriter();
34
palmkviste75f2042016-09-28 06:19:48 -070035 bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type);
sprang3911c262016-04-15 01:24:14 -070036 bool Close();
37
38 private:
palmkviste75f2042016-09-28 06:19:48 -070039 explicit IvfFileWriter(rtc::File file, size_t byte_limit);
sprang3911c262016-04-15 01:24:14 -070040
palmkviste75f2042016-09-28 06:19:48 -070041 bool WriteHeader();
42 bool InitFromFirstFrame(const EncodedImage& encoded_image,
43 VideoCodecType codec_type);
44
45 VideoCodecType codec_type_;
46 size_t bytes_written_;
47 size_t byte_limit_;
sprang3911c262016-04-15 01:24:14 -070048 size_t num_frames_;
49 uint16_t width_;
50 uint16_t height_;
51 int64_t last_timestamp_;
52 bool using_capture_timestamps_;
53 rtc::TimestampWrapAroundHandler wrap_handler_;
palmkviste75f2042016-09-28 06:19:48 -070054 rtc::File file_;
sprang3911c262016-04-15 01:24:14 -070055
56 RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter);
57};
58
59} // namespace webrtc
60
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020061#endif // MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_