blob: 07a858146727dfc5b534122764c662d09d580e5d [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
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
nisseea3a7982017-05-15 02:42:11 -070017#include "webrtc/common_video/include/video_frame.h"
sprang3911c262016-04-15 01:24:14 -070018#include "webrtc/modules/include/module_common_types.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020019#include "webrtc/rtc_base/constructormagic.h"
20#include "webrtc/rtc_base/file.h"
21#include "webrtc/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
60#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_IVF_FILE_WRITER_H_