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