blob: e10ef1911b0efb656b23eed61daea8e9e239bbb6 [file] [log] [blame]
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +00001/*
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +00003 *
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_TEST_TESTSUPPORT_FRAME_WRITER_H_
12#define WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_
13
14#include <cstdio>
15#include <string>
16
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000017#include "webrtc/typedefs.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000018
19namespace webrtc {
20namespace test {
21
22// Handles writing of video files.
23class FrameWriter {
24 public:
25 virtual ~FrameWriter() {}
26
27 // Initializes the file handler, i.e. opens the input and output files etc.
28 // This must be called before reading or writing frames has started.
29 // Returns false if an error has occurred, in addition to printing to stderr.
30 virtual bool Init() = 0;
31
32 // Writes a frame of the configured frame length to the output file.
33 // Returns true if the write was successful, false otherwise.
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000034 virtual bool WriteFrame(uint8_t* frame_buffer) = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000035
36 // Closes the output file if open. Essentially makes this class impossible
37 // to use anymore. Will also be invoked by the destructor.
38 virtual void Close() = 0;
39
40 // Frame length in bytes of a single frame image.
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000041 virtual size_t FrameLength() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000042};
43
44class FrameWriterImpl : public FrameWriter {
45 public:
46 // Creates a file handler. The input file is assumed to exist and be readable
47 // and the output file must be writable.
48 // Parameters:
49 // output_filename The file to write. Will be overwritten if already
50 // existing.
51 // frame_length_in_bytes The size of each frame.
52 // For YUV: 3*width*height/2
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000053 FrameWriterImpl(std::string output_filename, size_t frame_length_in_bytes);
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000054 virtual ~FrameWriterImpl();
55 bool Init();
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000056 bool WriteFrame(uint8_t* frame_buffer);
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000057 void Close();
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000058 size_t FrameLength() { return frame_length_in_bytes_; }
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000059
60 private:
61 std::string output_filename_;
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000062 size_t frame_length_in_bytes_;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000063 FILE* output_file_;
64};
65
66} // namespace test
67} // namespace webrtc
68
69#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_