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 | |
kjellander@webrtc.org | 9c4e662 | 2013-02-13 09:35:12 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
| 23 | // Handles reading of frames from video files. |
| 24 | class FrameReader { |
| 25 | public: |
| 26 | virtual ~FrameReader() {} |
| 27 | |
| 28 | // Initializes the frame reader, i.e. opens the input file. |
| 29 | // This must be called before reading of frames has started. |
| 30 | // Returns false if an error has occurred, in addition to printing to stderr. |
| 31 | virtual bool Init() = 0; |
| 32 | |
| 33 | // Reads a frame into the supplied buffer, which must contain enough space |
| 34 | // for the frame size. |
| 35 | // Returns true if there are more frames to read, false if we've already |
| 36 | // read the last frame (in the previous call). |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 | [diff] [blame] | 37 | virtual bool ReadFrame(uint8_t* source_buffer) = 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 | |
| 49 | class FrameReaderImpl : public FrameReader { |
| 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. |
| 54 | // frame_length_in_bytes The size of each frame. |
| 55 | // For YUV this is 3 * width * height / 2 |
kjellander@webrtc.org | 9c4e662 | 2013-02-13 09:35:12 | [diff] [blame] | 56 | FrameReaderImpl(std::string input_filename, size_t frame_length_in_bytes); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 57 | virtual ~FrameReaderImpl(); |
pbos@webrtc.org | e6c3966 | 2013-07-30 13:08:38 | [diff] [blame] | 58 | virtual bool Init() OVERRIDE; |
| 59 | virtual bool ReadFrame(uint8_t* source_buffer) OVERRIDE; |
| 60 | virtual void Close() OVERRIDE; |
| 61 | virtual size_t FrameLength() OVERRIDE; |
| 62 | virtual int NumberOfFrames() OVERRIDE; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | std::string input_filename_; |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 | [diff] [blame] | 66 | size_t frame_length_in_bytes_; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 | [diff] [blame] | 67 | int number_of_frames_; |
| 68 | FILE* input_file_; |
| 69 | }; |
| 70 | |
| 71 | } // namespace test |
| 72 | } // namespace webrtc |
| 73 | |
| 74 | #endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ |