• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 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 #include "test/frame_forwarder.h"
11 
12 #include "rtc_base/checks.h"
13 
14 namespace webrtc {
15 namespace test {
16 
FrameForwarder()17 FrameForwarder::FrameForwarder() : sink_(nullptr) {}
~FrameForwarder()18 FrameForwarder::~FrameForwarder() {}
19 
IncomingCapturedFrame(const VideoFrame & video_frame)20 void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) {
21   MutexLock lock(&mutex_);
22   if (sink_)
23     sink_->OnFrame(video_frame);
24 }
25 
AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame> * sink,const rtc::VideoSinkWants & wants)26 void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
27                                      const rtc::VideoSinkWants& wants) {
28   MutexLock lock(&mutex_);
29   AddOrUpdateSinkLocked(sink, wants);
30 }
31 
AddOrUpdateSinkLocked(rtc::VideoSinkInterface<VideoFrame> * sink,const rtc::VideoSinkWants & wants)32 void FrameForwarder::AddOrUpdateSinkLocked(
33     rtc::VideoSinkInterface<VideoFrame>* sink,
34     const rtc::VideoSinkWants& wants) {
35   RTC_DCHECK(!sink_ || sink_ == sink);
36   sink_ = sink;
37   sink_wants_ = wants;
38 }
39 
RemoveSink(rtc::VideoSinkInterface<VideoFrame> * sink)40 void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
41   MutexLock lock(&mutex_);
42   RTC_DCHECK_EQ(sink, sink_);
43   sink_ = nullptr;
44 }
45 
sink_wants() const46 rtc::VideoSinkWants FrameForwarder::sink_wants() const {
47   MutexLock lock(&mutex_);
48   return sink_wants_;
49 }
50 
sink_wants_locked() const51 rtc::VideoSinkWants FrameForwarder::sink_wants_locked() const {
52   return sink_wants_;
53 }
54 
has_sinks() const55 bool FrameForwarder::has_sinks() const {
56   MutexLock lock(&mutex_);
57   return sink_ != nullptr;
58 }
59 
60 }  // namespace test
61 }  // namespace webrtc
62