blob: a8fe73f75d6bfa955b16f14ebd9fb79598a921b0 [file] [log] [blame]
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +00001/*
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:53 +000014#include <stdio.h>
15
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000016#include <string>
17
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/scoped_ref_ptr.h"
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000019#include "webrtc/typedefs.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000020
21namespace webrtc {
nisse115bd152016-09-30 04:14:07 -070022class I420Buffer;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000023namespace test {
24
nisse115bd152016-09-30 04:14:07 -070025// Handles reading of I420 frames from video files.
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000026class 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 04:14:07 -070035 // 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:18 +000038
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:17 +000044 virtual size_t FrameLength() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000045 // Total number of frames in the input video source.
46 virtual int NumberOfFrames() = 0;
47};
48
brandtrb78bc752017-02-22 01:26:59 -080049class YuvFrameReaderImpl : public FrameReader {
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000050 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 04:14:07 -070054 // width, height Size of each frame to read.
brandtrb78bc752017-02-22 01:26:59 -080055 YuvFrameReaderImpl(std::string input_filename, int width, int height);
56 ~YuvFrameReaderImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 bool Init() override;
nisse115bd152016-09-30 04:14:07 -070058 rtc::scoped_refptr<I420Buffer> ReadFrame() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 void Close() override;
60 size_t FrameLength() override;
61 int NumberOfFrames() override;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000062
63 private:
brandtrb78bc752017-02-22 01:26:59 -080064 const std::string input_filename_;
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000065 size_t frame_length_in_bytes_;
brandtrb78bc752017-02-22 01:26:59 -080066 const int width_;
67 const int height_;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000068 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_