blob: d8ec4b5060e9c41e778a14df6174728003717779 [file] [log] [blame]
Artem Titov33f9d2b2019-12-05 15:59:00 +01001/*
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
14namespace webrtc {
15namespace test {
16
17FrameForwarder::FrameForwarder() : sink_(nullptr) {}
18FrameForwarder::~FrameForwarder() {}
19
20void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) {
21 rtc::CritScope lock(&crit_);
22 if (sink_)
23 sink_->OnFrame(video_frame);
24}
25
26void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
27 const rtc::VideoSinkWants& wants) {
28 rtc::CritScope lock(&crit_);
Markus Handell16038ab2020-05-28 08:37:30 +020029 AddOrUpdateSinkLocked(sink, wants);
30}
31
32void FrameForwarder::AddOrUpdateSinkLocked(
33 rtc::VideoSinkInterface<VideoFrame>* sink,
34 const rtc::VideoSinkWants& wants) {
Artem Titov33f9d2b2019-12-05 15:59:00 +010035 RTC_DCHECK(!sink_ || sink_ == sink);
36 sink_ = sink;
37 sink_wants_ = wants;
38}
39
40void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
41 rtc::CritScope lock(&crit_);
42 RTC_DCHECK_EQ(sink, sink_);
43 sink_ = nullptr;
44}
45
46rtc::VideoSinkWants FrameForwarder::sink_wants() const {
47 rtc::CritScope lock(&crit_);
48 return sink_wants_;
49}
50
Markus Handell16038ab2020-05-28 08:37:30 +020051rtc::VideoSinkWants FrameForwarder::sink_wants_locked() const {
52 return sink_wants_;
53}
54
Artem Titov33f9d2b2019-12-05 15:59:00 +010055bool FrameForwarder::has_sinks() const {
56 rtc::CritScope lock(&crit_);
57 return sink_ != nullptr;
58}
59
60} // namespace test
61} // namespace webrtc