blob: 13800cdc6fe08c91e12c5a5b42fdbbb121277e3b [file] [log] [blame]
kjellander@webrtc.org5b97b122011-12-08 07:42:181/*
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.org12dc1a32013-08-05 16:22:5314#include <stdio.h>
15
kjellander@webrtc.org5b97b122011-12-08 07:42:1816#include <string>
17
nisse115bd152016-09-30 11:14:0718#include "webrtc/base/scoped_ref_ptr.h"
kjellander@webrtc.org9c4e6622013-02-13 09:35:1219#include "webrtc/typedefs.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:1820
21namespace webrtc {
nisse115bd152016-09-30 11:14:0722class I420Buffer;
kjellander@webrtc.org5b97b122011-12-08 07:42:1823namespace test {
24
nisse115bd152016-09-30 11:14:0725// Handles reading of I420 frames from video files.
kjellander@webrtc.org5b97b122011-12-08 07:42:1826class 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
nisse115bd152016-09-30 11:14:0735 // 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.org5b97b122011-12-08 07:42:1838
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.orgfa53d872013-02-04 10:07:1744 virtual size_t FrameLength() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:1845 // Total number of frames in the input video source.
46 virtual int NumberOfFrames() = 0;
47};
48
brandtr2a8135a2017-02-21 13:24:0349class FrameReaderImpl : public FrameReader {
kjellander@webrtc.org5b97b122011-12-08 07:42:1850 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.
nisse115bd152016-09-30 11:14:0754 // width, height Size of each frame to read.
brandtr2a8135a2017-02-21 13:24:0355 FrameReaderImpl(std::string input_filename, int width, int height);
56 ~FrameReaderImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:3557 bool Init() override;
nisse115bd152016-09-30 11:14:0758 rtc::scoped_refptr<I420Buffer> ReadFrame() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:3559 void Close() override;
60 size_t FrameLength() override;
61 int NumberOfFrames() override;
kjellander@webrtc.org5b97b122011-12-08 07:42:1862
63 private:
brandtr2a8135a2017-02-21 13:24:0364 std::string input_filename_;
kjellander@webrtc.orgfa53d872013-02-04 10:07:1765 size_t frame_length_in_bytes_;
brandtr2a8135a2017-02-21 13:24:0366 int width_;
67 int height_;
kjellander@webrtc.org5b97b122011-12-08 07:42:1868 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_