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