blob: de8962e1266b5b7f05193aa2a469452296df7786 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef TEST_TESTSUPPORT_FRAME_READER_H_
12#define TEST_TESTSUPPORT_FRAME_READER_H_
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000013
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/scoped_ref_ptr.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000019
20namespace webrtc {
nisse115bd152016-09-30 04:14:07 -070021class I420Buffer;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000022namespace test {
23
nisse115bd152016-09-30 04:14:07 -070024// Handles reading of I420 frames from video files.
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000025class FrameReader {
26 public:
27 virtual ~FrameReader() {}
28
29 // Initializes the frame reader, i.e. opens the input file.
30 // This must be called before reading of frames has started.
31 // Returns false if an error has occurred, in addition to printing to stderr.
32 virtual bool Init() = 0;
33
nisse115bd152016-09-30 04:14:07 -070034 // Reads a frame from the input file. On success, returns the frame.
35 // Returns nullptr if encountering end of file or a read error.
36 virtual rtc::scoped_refptr<I420Buffer> ReadFrame() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000037
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.
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000043 virtual size_t FrameLength() = 0;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000044 // Total number of frames in the input video source.
45 virtual int NumberOfFrames() = 0;
46};
47
brandtrb78bc752017-02-22 01:26:59 -080048class YuvFrameReaderImpl : public FrameReader {
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000049 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.
nisse115bd152016-09-30 04:14:07 -070053 // width, height Size of each frame to read.
brandtrb78bc752017-02-22 01:26:59 -080054 YuvFrameReaderImpl(std::string input_filename, int width, int height);
55 ~YuvFrameReaderImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 bool Init() override;
nisse115bd152016-09-30 04:14:07 -070057 rtc::scoped_refptr<I420Buffer> ReadFrame() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000058 void Close() override;
59 size_t FrameLength() override;
60 int NumberOfFrames() override;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000061
62 private:
brandtrb78bc752017-02-22 01:26:59 -080063 const std::string input_filename_;
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000064 size_t frame_length_in_bytes_;
brandtrb78bc752017-02-22 01:26:59 -080065 const int width_;
66 const int height_;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000067 int number_of_frames_;
68 FILE* input_file_;
69};
70
71} // namespace test
72} // namespace webrtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // TEST_TESTSUPPORT_FRAME_READER_H_