blob: 8a6b1c215259a0bede437dc9ab2eb94b688c4ae2 [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
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000014#include <stdio.h>
15
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000016#include <string>
17
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000018#include "webrtc/typedefs.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000019
20namespace webrtc {
21namespace test {
22
23// Handles writing of video files.
24class FrameWriter {
25 public:
26 virtual ~FrameWriter() {}
27
28 // Initializes the file handler, i.e. opens the input and output files etc.
29 // This must be called before reading or writing frames has started.
30 // Returns false if an error has occurred, in addition to printing to stderr.
31 virtual bool Init() = 0;
32
33 // Writes a frame of the configured frame length to the output file.
34 // Returns true if the write was successful, false otherwise.
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000035 virtual bool WriteFrame(uint8_t* frame_buffer) = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000036
37 // Closes the output file if open. Essentially makes this class impossible
38 // to use anymore. Will also be invoked by the destructor.
39 virtual void Close() = 0;
40
41 // Frame length in bytes of a single frame image.
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000042 virtual size_t FrameLength() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000043};
44
brandtr2a8135a2017-02-21 05:24:03 -080045class FrameWriterImpl : public FrameWriter {
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000046 public:
47 // Creates a file handler. The input file is assumed to exist and be readable
48 // and the output file must be writable.
49 // Parameters:
50 // output_filename The file to write. Will be overwritten if already
51 // existing.
brandtr2a8135a2017-02-21 05:24:03 -080052 // frame_length_in_bytes The size of each frame.
53 // For YUV: 3*width*height/2
54 FrameWriterImpl(std::string output_filename, size_t frame_length_in_bytes);
55 ~FrameWriterImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 bool Init() override;
57 bool WriteFrame(uint8_t* frame_buffer) override;
58 void Close() override;
59 size_t FrameLength() override;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000060
brandtr872104a2017-02-21 03:59:15 -080061 private:
brandtr2a8135a2017-02-21 05:24:03 -080062 std::string output_filename_;
63 size_t frame_length_in_bytes_;
64 FILE* output_file_;
brandtr872104a2017-02-21 03:59:15 -080065};
66
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000067} // namespace test
68} // namespace webrtc
69
70#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_