• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame> * sink,const VideoSinkWants & wants)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 
RemoveSink(VideoSinkInterface<webrtc::VideoFrame> * sink)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 
FindSinkPair(const VideoSinkInterface<webrtc::VideoFrame> * sink)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