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