test_video_capturer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2013 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_TEST_VIDEO_CAPTURER_H_
  11. #define TEST_TEST_VIDEO_CAPTURER_H_
  12. #include <stddef.h>
  13. #include <memory>
  14. #include "api/video/video_frame.h"
  15. #include "api/video/video_source_interface.h"
  16. #include "media/base/video_adapter.h"
  17. #include "media/base/video_broadcaster.h"
  18. #include "rtc_base/synchronization/mutex.h"
  19. namespace webrtc {
  20. namespace test {
  21. class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
  22. public:
  23. class FramePreprocessor {
  24. public:
  25. virtual ~FramePreprocessor() = default;
  26. virtual VideoFrame Preprocess(const VideoFrame& frame) = 0;
  27. };
  28. ~TestVideoCapturer() override;
  29. void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
  30. const rtc::VideoSinkWants& wants) override;
  31. void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
  32. void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) {
  33. MutexLock lock(&lock_);
  34. preprocessor_ = std::move(preprocessor);
  35. }
  36. protected:
  37. void OnFrame(const VideoFrame& frame);
  38. rtc::VideoSinkWants GetSinkWants();
  39. private:
  40. void UpdateVideoAdapter();
  41. VideoFrame MaybePreprocess(const VideoFrame& frame);
  42. Mutex lock_;
  43. std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
  44. rtc::VideoBroadcaster broadcaster_;
  45. cricket::VideoAdapter video_adapter_;
  46. };
  47. } // namespace test
  48. } // namespace webrtc
  49. #endif // TEST_TEST_VIDEO_CAPTURER_H_