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 13 #include <stddef.h> 14 15 #include <cstdio> 16 #include <iterator> 17 #include <string> 18 19 #include "api/scoped_refptr.h" 20 #include "api/video/video_frame_buffer.h" 21 #include "rtc_base/ref_count.h" 22 23 namespace webrtc { 24 namespace 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. 28 class 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 67 rtc::scoped_refptr<Video> OpenY4mFile(const std::string& file_name); 68 69 rtc::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. 75 rtc::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_ 83