blob: 7e37fca362d9eb05045b6e0fae4fdf7913c477fb [file] [log] [blame]
Magnus Jedvert10e829a2018-09-05 10:46:18 +02001/*
2 * Copyright (c) 2018 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#ifndef RTC_TOOLS_VIDEO_FILE_READER_H_
11#define RTC_TOOLS_VIDEO_FILE_READER_H_
12
13#include <cstdio>
14#include <iterator>
15#include <string>
16#include <vector>
17
18#include "api/video/video_frame.h"
19#include "rtc_base/refcount.h"
20
21namespace webrtc {
22namespace test {
23
24// Iterable class representing a sequence of I420 buffers. This class is not
25// thread safe because it is expected to be backed by a file.
26class Video : public rtc::RefCountInterface {
27 public:
28 class Iterator {
29 public:
30 typedef int value_type;
31 typedef std::ptrdiff_t difference_type;
32 typedef int* pointer;
33 typedef int& reference;
34 typedef std::input_iterator_tag iterator_category;
35
36 Iterator(const rtc::scoped_refptr<const Video>& video, size_t index);
37 Iterator(const Iterator& other);
38 Iterator(Iterator&& other);
39 Iterator& operator=(Iterator&&);
40 Iterator& operator=(const Iterator&);
41 ~Iterator();
42
43 rtc::scoped_refptr<I420BufferInterface> operator*() const;
44 bool operator==(const Iterator& other) const;
45 bool operator!=(const Iterator& other) const;
46
47 Iterator operator++(int);
48 Iterator& operator++();
49
50 private:
51 rtc::scoped_refptr<const Video> video_;
52 size_t index_;
53 };
54
55 Iterator begin() const;
56 Iterator end() const;
57
58 virtual int width() const = 0;
59 virtual int height() const = 0;
60 virtual size_t number_of_frames() const = 0;
61 virtual rtc::scoped_refptr<I420BufferInterface> GetFrame(
62 size_t index) const = 0;
63};
64
65rtc::scoped_refptr<Video> OpenY4mFile(const std::string& file_name);
66
67rtc::scoped_refptr<Video> OpenYuvFile(const std::string& file_name,
68 int width,
69 int height);
70
71// This is a helper function for the two functions above. It reads the file
72// extension to determine whether it is a .yuv or a .y4m file.
73rtc::scoped_refptr<Video> OpenYuvOrY4mFile(const std::string& file_name,
74 int width,
75 int height);
76
77} // namespace test
78} // namespace webrtc
79
80#endif // RTC_TOOLS_VIDEO_FILE_READER_H_