tor-browser

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

video_source_base.h (2924B)


      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 #ifndef MEDIA_BASE_VIDEO_SOURCE_BASE_H_
     12 #define MEDIA_BASE_VIDEO_SOURCE_BASE_H_
     13 
     14 #include <vector>
     15 
     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/system/no_unique_address.h"
     21 #include "rtc_base/thread_annotations.h"
     22 
     23 namespace webrtc {
     24 
     25 // VideoSourceBase is not thread safe. Before using this class, consider using
     26 // VideoSourceBaseGuarded below instead, which is an identical implementation
     27 // but applies a sequence checker to help protect internal state.
     28 // TODO(bugs.webrtc.org/12780): Delete this class.
     29 class VideoSourceBase : public VideoSourceInterface<VideoFrame> {
     30 public:
     31  VideoSourceBase();
     32  ~VideoSourceBase() override;
     33  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
     34                       const VideoSinkWants& wants) override;
     35  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
     36 
     37 protected:
     38  struct SinkPair {
     39    SinkPair(VideoSinkInterface<VideoFrame>* sink, VideoSinkWants wants)
     40        : sink(sink), wants(wants) {}
     41    VideoSinkInterface<VideoFrame>* sink;
     42    VideoSinkWants wants;
     43  };
     44  SinkPair* FindSinkPair(const VideoSinkInterface<VideoFrame>* sink);
     45 
     46  const std::vector<SinkPair>& sink_pairs() const { return sinks_; }
     47 
     48 private:
     49  std::vector<SinkPair> sinks_;
     50 };
     51 
     52 // VideoSourceBaseGuarded assumes that operations related to sinks, occur on the
     53 // same TQ/thread that the object was constructed on.
     54 class VideoSourceBaseGuarded : public VideoSourceInterface<VideoFrame> {
     55 public:
     56  VideoSourceBaseGuarded();
     57  ~VideoSourceBaseGuarded() override;
     58 
     59  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
     60                       const VideoSinkWants& wants) override;
     61  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
     62 
     63 protected:
     64  struct SinkPair {
     65    SinkPair(VideoSinkInterface<VideoFrame>* sink, VideoSinkWants wants)
     66        : sink(sink), wants(wants) {}
     67    VideoSinkInterface<VideoFrame>* sink;
     68    VideoSinkWants wants;
     69  };
     70 
     71  SinkPair* FindSinkPair(const VideoSinkInterface<VideoFrame>* sink);
     72  const std::vector<SinkPair>& sink_pairs() const;
     73 
     74  // Keep the `source_sequence_` checker protected to allow sub classes the
     75  // ability to call Detach() if/when appropriate.
     76  RTC_NO_UNIQUE_ADDRESS SequenceChecker source_sequence_;
     77 
     78 private:
     79  std::vector<SinkPair> sinks_ RTC_GUARDED_BY(&source_sequence_);
     80 };
     81 
     82 }  //  namespace webrtc
     83 
     84 
     85 #endif  // MEDIA_BASE_VIDEO_SOURCE_BASE_H_