blob: 71b4276eafe1cc23ba7db51e77f501c7af9cd4fb [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
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <algorithm>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
perkjd6c39542016-03-17 10:35:23 +010016
17namespace rtc {
18
Niels Möller3793bb42018-12-20 13:46:06 +010019VideoSourceBase::VideoSourceBase() = default;
Paulina Hensmana680a6a2018-04-05 11:42:24 +020020VideoSourceBase::~VideoSourceBase() = default;
perkjd6c39542016-03-17 10:35:23 +010021
22void VideoSourceBase::AddOrUpdateSink(
nisseacd935b2016-11-11 03:55:13 -080023 VideoSinkInterface<webrtc::VideoFrame>* sink,
perkjd6c39542016-03-17 10:35:23 +010024 const VideoSinkWants& wants) {
perkjd6c39542016-03-17 10:35:23 +010025 RTC_DCHECK(sink != nullptr);
26
27 SinkPair* sink_pair = FindSinkPair(sink);
28 if (!sink_pair) {
29 sinks_.push_back(SinkPair(sink, wants));
30 } else {
31 sink_pair->wants = wants;
32 }
33}
34
nisseacd935b2016-11-11 03:55:13 -080035void VideoSourceBase::RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) {
perkjd6c39542016-03-17 10:35:23 +010036 RTC_DCHECK(sink != nullptr);
37 RTC_DCHECK(FindSinkPair(sink));
38 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(),
39 [sink](const SinkPair& sink_pair) {
40 return sink_pair.sink == sink;
41 }),
42 sinks_.end());
43}
44
45VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
nisseacd935b2016-11-11 03:55:13 -080046 const VideoSinkInterface<webrtc::VideoFrame>* sink) {
perkjd6c39542016-03-17 10:35:23 +010047 auto sink_pair_it = std::find_if(
48 sinks_.begin(), sinks_.end(),
49 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
50 if (sink_pair_it != sinks_.end()) {
51 return &*sink_pair_it;
52 }
53 return nullptr;
54}
55
56} // namespace rtc