blob: 8f88a894fea860180dbed6f80f91e2c9c9db816f [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
14#include <cstdio>
15#include <string>
16
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000017#include "webrtc/typedefs.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000018
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).
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000036 virtual bool ReadFrame(uint8_t* source_buffer) = 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
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
kjellander@webrtc.org9c4e6622013-02-13 09:35:12 +000055 FrameReaderImpl(std::string input_filename, size_t frame_length_in_bytes);
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000056 virtual ~FrameReaderImpl();
pbos@webrtc.orge6c39662013-07-30 13:08:38 +000057 virtual bool Init() OVERRIDE;
58 virtual bool ReadFrame(uint8_t* source_buffer) OVERRIDE;
59 virtual void Close() OVERRIDE;
60 virtual size_t FrameLength() OVERRIDE;
61 virtual int NumberOfFrames() OVERRIDE;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000062
63 private:
64 std::string input_filename_;
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000065 size_t frame_length_in_bytes_;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000066 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_