kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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_TEST_TESTSUPPORT_FRAME_READER_H_ |
| 12 | #define WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ |
| 13 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 16 | #include <string> |
| 17 | |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 18 | #include "webrtc/base/scoped_ref_ptr.h" |
kjellander@webrtc.org | 9c4e662 | 2013-02-13 09:35:12 | [diff] [blame] | 19 | #include "webrtc/typedefs.h" |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 22 | class I420Buffer; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 23 | namespace test { |
| 24 | |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 25 | // Handles reading of I420 frames from video files. |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 26 | class FrameReader { |
| 27 | public: |
| 28 | virtual ~FrameReader() {} |
| 29 | |
| 30 | // Initializes the frame reader, i.e. opens the input file. |
| 31 | // This must be called before reading of frames has started. |
| 32 | // Returns false if an error has occurred, in addition to printing to stderr. |
| 33 | virtual bool Init() = 0; |
| 34 | |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 35 | // Reads a frame from the input file. On success, returns the frame. |
| 36 | // Returns nullptr if encountering end of file or a read error. |
| 37 | virtual rtc::scoped_refptr<I420Buffer> ReadFrame() = 0; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 38 | |
| 39 | // Closes the input file if open. Essentially makes this class impossible |
| 40 | // to use anymore. Will also be invoked by the destructor. |
| 41 | virtual void Close() = 0; |
| 42 | |
| 43 | // Frame length in bytes of a single frame image. |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 | [diff] [blame] | 44 | virtual size_t FrameLength() = 0; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 45 | // Total number of frames in the input video source. |
| 46 | virtual int NumberOfFrames() = 0; |
| 47 | }; |
| 48 | |
brandtr | 2a8135a | 2017-02-21 13:24:03 | [diff] [blame] | 49 | class FrameReaderImpl : public FrameReader { |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 50 | public: |
| 51 | // Creates a file handler. The input file is assumed to exist and be readable. |
| 52 | // Parameters: |
| 53 | // input_filename The file to read from. |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 54 | // width, height Size of each frame to read. |
brandtr | 2a8135a | 2017-02-21 13:24:03 | [diff] [blame] | 55 | FrameReaderImpl(std::string input_filename, int width, int height); |
| 56 | ~FrameReaderImpl() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 57 | bool Init() override; |
nisse | 115bd15 | 2016-09-30 11:14:07 | [diff] [blame] | 58 | rtc::scoped_refptr<I420Buffer> ReadFrame() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 59 | void Close() override; |
| 60 | size_t FrameLength() override; |
| 61 | int NumberOfFrames() override; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 62 | |
| 63 | private: |
brandtr | 2a8135a | 2017-02-21 13:24:03 | [diff] [blame] | 64 | std::string input_filename_; |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 | [diff] [blame] | 65 | size_t frame_length_in_bytes_; |
brandtr | 2a8135a | 2017-02-21 13:24:03 | [diff] [blame] | 66 | int width_; |
| 67 | int height_; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 68 | int number_of_frames_; |
| 69 | FILE* input_file_; |
| 70 | }; |
| 71 | |
| 72 | } // namespace test |
| 73 | } // namespace webrtc |
| 74 | |
| 75 | #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ |