You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2016 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. #include "media/base/video_source_base.h"
  11. #include "absl/algorithm/container.h"
  12. #include "rtc_base/checks.h"
  13. namespace rtc {
  14. VideoSourceBase::VideoSourceBase() = default;
  15. VideoSourceBase::~VideoSourceBase() = default;
  16. void VideoSourceBase::AddOrUpdateSink(
  17. VideoSinkInterface<webrtc::VideoFrame>* sink,
  18. const VideoSinkWants& wants) {
  19. RTC_DCHECK(sink != nullptr);
  20. SinkPair* sink_pair = FindSinkPair(sink);
  21. if (!sink_pair) {
  22. sinks_.push_back(SinkPair(sink, wants));
  23. } else {
  24. sink_pair->wants = wants;
  25. }
  26. }
  27. void VideoSourceBase::RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) {
  28. RTC_DCHECK(sink != nullptr);
  29. RTC_DCHECK(FindSinkPair(sink));
  30. sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(),
  31. [sink](const SinkPair& sink_pair) {
  32. return sink_pair.sink == sink;
  33. }),
  34. sinks_.end());
  35. }
  36. VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
  37. const VideoSinkInterface<webrtc::VideoFrame>* sink) {
  38. auto sink_pair_it = absl::c_find_if(
  39. sinks_,
  40. [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
  41. if (sink_pair_it != sinks_.end()) {
  42. return &*sink_pair_it;
  43. }
  44. return nullptr;
  45. }
  46. } // namespace rtc