tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

video_source_base.cc (3047B)


      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 <vector>
     14 
     15 #include "absl/algorithm/container.h"
     16 #include "api/sequence_checker.h"
     17 #include "api/video/video_frame.h"
     18 #include "api/video/video_sink_interface.h"
     19 #include "api/video/video_source_interface.h"
     20 #include "rtc_base/checks.h"
     21 
     22 namespace webrtc {
     23 
     24 VideoSourceBase::VideoSourceBase() = default;
     25 VideoSourceBase::~VideoSourceBase() = default;
     26 
     27 void VideoSourceBase::AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
     28                                      const VideoSinkWants& wants) {
     29  RTC_DCHECK(sink != nullptr);
     30 
     31  SinkPair* sink_pair = FindSinkPair(sink);
     32  if (!sink_pair) {
     33    sinks_.push_back(SinkPair(sink, wants));
     34  } else {
     35    sink_pair->wants = wants;
     36  }
     37 }
     38 
     39 void VideoSourceBase::RemoveSink(VideoSinkInterface<VideoFrame>* sink) {
     40  RTC_DCHECK(sink != nullptr);
     41  RTC_DCHECK(FindSinkPair(sink));
     42  std::erase_if(sinks_, [sink](const SinkPair& sink_pair) {
     43    return sink_pair.sink == sink;
     44  });
     45 }
     46 
     47 VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
     48    const VideoSinkInterface<VideoFrame>* sink) {
     49  auto sink_pair_it = absl::c_find_if(
     50      sinks_,
     51      [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
     52  if (sink_pair_it != sinks_.end()) {
     53    return &*sink_pair_it;
     54  }
     55  return nullptr;
     56 }
     57 
     58 VideoSourceBaseGuarded::VideoSourceBaseGuarded() = default;
     59 VideoSourceBaseGuarded::~VideoSourceBaseGuarded() = default;
     60 
     61 void VideoSourceBaseGuarded::AddOrUpdateSink(
     62    VideoSinkInterface<VideoFrame>* sink,
     63    const VideoSinkWants& wants) {
     64  RTC_DCHECK_RUN_ON(&source_sequence_);
     65  RTC_DCHECK(sink != nullptr);
     66 
     67  SinkPair* sink_pair = FindSinkPair(sink);
     68  if (!sink_pair) {
     69    sinks_.push_back(SinkPair(sink, wants));
     70  } else {
     71    sink_pair->wants = wants;
     72  }
     73 }
     74 
     75 void VideoSourceBaseGuarded::RemoveSink(VideoSinkInterface<VideoFrame>* sink) {
     76  RTC_DCHECK_RUN_ON(&source_sequence_);
     77  RTC_DCHECK(sink != nullptr);
     78  RTC_DCHECK(FindSinkPair(sink));
     79  std::erase_if(sinks_, [sink](const SinkPair& sink_pair) {
     80    return sink_pair.sink == sink;
     81  });
     82 }
     83 
     84 VideoSourceBaseGuarded::SinkPair* VideoSourceBaseGuarded::FindSinkPair(
     85    const VideoSinkInterface<VideoFrame>* sink) {
     86  RTC_DCHECK_RUN_ON(&source_sequence_);
     87  auto sink_pair_it = absl::c_find_if(
     88      sinks_,
     89      [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
     90  if (sink_pair_it != sinks_.end()) {
     91    return &*sink_pair_it;
     92  }
     93  return nullptr;
     94 }
     95 
     96 const std::vector<VideoSourceBaseGuarded::SinkPair>&
     97 VideoSourceBaseGuarded::sink_pairs() const {
     98  RTC_DCHECK_RUN_ON(&source_sequence_);
     99  return sinks_;
    100 }
    101 
    102 }  // namespace webrtc