frame_forwarder.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2019 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 TEST_FRAME_FORWARDER_H_
  11. #define TEST_FRAME_FORWARDER_H_
  12. #include "api/video/video_frame.h"
  13. #include "api/video/video_source_interface.h"
  14. #include "rtc_base/synchronization/mutex.h"
  15. namespace webrtc {
  16. namespace test {
  17. // FrameForwarder can be used as an implementation
  18. // of rtc::VideoSourceInterface<VideoFrame> where the caller controls when
  19. // a frame should be forwarded to its sink.
  20. // Currently this implementation only support one sink.
  21. class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> {
  22. public:
  23. FrameForwarder();
  24. ~FrameForwarder() override;
  25. // Forwards |video_frame| to the registered |sink_|.
  26. virtual void IncomingCapturedFrame(const VideoFrame& video_frame)
  27. RTC_LOCKS_EXCLUDED(mutex_);
  28. rtc::VideoSinkWants sink_wants() const RTC_LOCKS_EXCLUDED(mutex_);
  29. bool has_sinks() const RTC_LOCKS_EXCLUDED(mutex_);
  30. protected:
  31. rtc::VideoSinkWants sink_wants_locked() const
  32. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
  33. void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
  34. const rtc::VideoSinkWants& wants)
  35. RTC_LOCKS_EXCLUDED(mutex_) override;
  36. void AddOrUpdateSinkLocked(rtc::VideoSinkInterface<VideoFrame>* sink,
  37. const rtc::VideoSinkWants& wants)
  38. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
  39. void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink)
  40. RTC_LOCKS_EXCLUDED(mutex_) override;
  41. mutable Mutex mutex_;
  42. rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(mutex_);
  43. rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(mutex_);
  44. };
  45. } // namespace test
  46. } // namespace webrtc
  47. #endif // TEST_FRAME_FORWARDER_H_