VideoFilter.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include "pc/video_track_source.h"
  3. template<class T>
  4. class VideoFilter : public webrtc::VideoTrackSource {
  5. public:
  6. static rtc::scoped_refptr<VideoFilter> Create(rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> videoSource, const std::map<std::string, std::string> &opts) {
  7. std::unique_ptr<T> source = absl::WrapUnique(new T(videoSource, opts));
  8. if (!source) {
  9. return nullptr;
  10. }
  11. return new rtc::RefCountedObject<VideoFilter>(std::move(source));
  12. }
  13. protected:
  14. explicit VideoFilter(std::unique_ptr<T> source)
  15. : webrtc::VideoTrackSource(/*remote=*/false), m_source(std::move(source)) {}
  16. SourceState state() const override {
  17. return kLive;
  18. }
  19. bool GetStats(Stats* stats) override {
  20. bool result = false;
  21. T* source = m_source.get();
  22. if (source) {
  23. // stats->input_height = source->height();
  24. // stats->input_width = source->width();
  25. result = true;
  26. }
  27. return result;
  28. }
  29. private:
  30. rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
  31. return m_source.get();
  32. }
  33. std::unique_ptr<T> m_source;
  34. };