kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 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_TEST_TESTSUPPORT_FRAME_WRITER_H_ |
| 12 | #define WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_ |
| 13 | |
| 14 | #include <cstdio> |
| 15 | #include <string> |
| 16 | |
kjellander@webrtc.org | 9c4e662 | 2013-02-13 09:35:12 +0000 | [diff] [blame] | 17 | #include "webrtc/typedefs.h" |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | namespace test { |
| 21 | |
| 22 | // Handles writing of video files. |
| 23 | class 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.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame] | 34 | virtual bool WriteFrame(uint8_t* frame_buffer) = 0; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 35 | |
| 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.org | fa53d87 | 2013-02-04 10:07:17 +0000 | [diff] [blame] | 41 | virtual size_t FrameLength() = 0; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | class 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.org | 9c4e662 | 2013-02-13 09:35:12 +0000 | [diff] [blame] | 53 | FrameWriterImpl(std::string output_filename, size_t frame_length_in_bytes); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 54 | virtual ~FrameWriterImpl(); |
pbos@webrtc.org | e6c3966 | 2013-07-30 13:08:38 +0000 | [diff] [blame^] | 55 | virtual bool Init() OVERRIDE; |
| 56 | virtual bool WriteFrame(uint8_t* frame_buffer) OVERRIDE; |
| 57 | virtual void Close() OVERRIDE; |
| 58 | virtual size_t FrameLength() OVERRIDE; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | std::string output_filename_; |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 +0000 | [diff] [blame] | 62 | size_t frame_length_in_bytes_; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 63 | FILE* output_file_; |
| 64 | }; |
| 65 | |
| 66 | } // namespace test |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_WRITER_H_ |