blob: d057a24ad814ced159392756645b6d6411e24fcd [file] [log] [blame]
perkj916c76e2016-03-11 22:54:27 +01001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "media/base/video_source_base.h"
perkj916c76e2016-03-11 22:54:27 +010012
Steve Anton2c9ebef2019-01-28 17:27:58 -080013#include "absl/algorithm/container.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
perkjd6c39542016-03-17 10:35:23 +010015
16namespace rtc {
17
Niels Möller3793bb42018-12-20 13:46:06 +010018VideoSourceBase::VideoSourceBase() = default;
Paulina Hensmana680a6a2018-04-05 11:42:24 +020019VideoSourceBase::~VideoSourceBase() = default;
perkjd6c39542016-03-17 10:35:23 +010020
21void VideoSourceBase::AddOrUpdateSink(
nisseacd935b2016-11-11 03:55:13 -080022 VideoSinkInterface<webrtc::VideoFrame>* sink,
perkjd6c39542016-03-17 10:35:23 +010023 const VideoSinkWants& wants) {
perkjd6c39542016-03-17 10:35:23 +010024 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
nisseacd935b2016-11-11 03:55:13 -080034void VideoSourceBase::RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) {
perkjd6c39542016-03-17 10:35:23 +010035 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
44VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
nisseacd935b2016-11-11 03:55:13 -080045 const VideoSinkInterface<webrtc::VideoFrame>* sink) {
Steve Anton2c9ebef2019-01-28 17:27:58 -080046 auto sink_pair_it = absl::c_find_if(
47 sinks_,
perkjd6c39542016-03-17 10:35:23 +010048 [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