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 14#include <cstdio> 15#include <string> 16 17#include "typedefs.h" 18 19namespace webrtc { 20namespace test { 21 22// Handles reading of frames from video files. 23class FrameReader { 24 public: 25 virtual ~FrameReader() {} 26 27 // Initializes the frame reader, i.e. opens the input file. 28 // This must be called before reading of frames has started. 29 // Returns false if an error has occurred, in addition to printing to stderr. 30 virtual bool Init() = 0; 31 32 // Reads a frame into the supplied buffer, which must contain enough space 33 // for the frame size. 34 // Returns true if there are more frames to read, false if we've already 35 // read the last frame (in the previous call). 36 virtual bool ReadFrame(WebRtc_UWord8* source_buffer) = 0; 37 38 // Closes the input file if open. Essentially makes this class impossible 39 // to use anymore. Will also be invoked by the destructor. 40 virtual void Close() = 0; 41 42 // Frame length in bytes of a single frame image. 43 virtual int FrameLength() = 0; 44 // Total number of frames in the input video source. 45 virtual int NumberOfFrames() = 0; 46}; 47 48class FrameReaderImpl : public FrameReader { 49 public: 50 // Creates a file handler. The input file is assumed to exist and be readable. 51 // Parameters: 52 // input_filename The file to read from. 53 // frame_length_in_bytes The size of each frame. 54 // For YUV this is 3 * width * height / 2 55 FrameReaderImpl(std::string input_filename, int frame_length_in_bytes); 56 virtual ~FrameReaderImpl(); 57 bool Init(); 58 bool ReadFrame(WebRtc_UWord8* source_buffer); 59 void Close(); 60 int FrameLength() { return frame_length_in_bytes_; } 61 int NumberOfFrames() { return number_of_frames_; } 62 63 private: 64 std::string input_filename_; 65 int frame_length_in_bytes_; 66 int number_of_frames_; 67 FILE* input_file_; 68}; 69 70} // namespace test 71} // namespace webrtc 72 73#endif // WEBRTC_TEST_TESTSUPPORT_FRAME_READER_H_ 74