Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 1 | /* |
| 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 Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stddef.h> |
Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 14 | #include <cstdio> |
| 15 | #include <iterator> |
| 16 | #include <string> |
Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 17 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include "api/video/video_frame_buffer.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/ref_count.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "rtc_base/scoped_ref_ptr.h" |
Magnus Jedvert | 10e829a | 2018-09-05 10:46:18 +0200 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace 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. |
| 27 | class 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 | |
| 66 | rtc::scoped_refptr<Video> OpenY4mFile(const std::string& file_name); |
| 67 | |
| 68 | rtc::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. |
| 74 | rtc::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_ |