video_file_reader.h 2.5 KB

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