blob: e89f753bd3d2acf446f5aaf9be4160e0b0a4aee5 [file] [log] [blame]
Artem Titov33f9d2b2019-12-05 14:59:001/*
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) {
Markus Handella3765182020-07-08 11:13:3221 MutexLock lock(&mutex_);
Artem Titov33f9d2b2019-12-05 14:59:0022 if (sink_)
23 sink_->OnFrame(video_frame);
24}
25
26void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
27 const rtc::VideoSinkWants& wants) {
Markus Handella3765182020-07-08 11:13:3228 MutexLock lock(&mutex_);
Markus Handell16038ab2020-05-28 06:37:3029 AddOrUpdateSinkLocked(sink, wants);
30}
31
32void FrameForwarder::AddOrUpdateSinkLocked(
33 rtc::VideoSinkInterface<VideoFrame>* sink,
34 const rtc::VideoSinkWants& wants) {
Artem Titov33f9d2b2019-12-05 14:59:0035 RTC_DCHECK(!sink_ || sink_ == sink);
36 sink_ = sink;
37 sink_wants_ = wants;
38}
39
40void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
Markus Handella3765182020-07-08 11:13:3241 MutexLock lock(&mutex_);
Artem Titov33f9d2b2019-12-05 14:59:0042 RTC_DCHECK_EQ(sink, sink_);
43 sink_ = nullptr;
44}
45
46rtc::VideoSinkWants FrameForwarder::sink_wants() const {
Markus Handella3765182020-07-08 11:13:3247 MutexLock lock(&mutex_);
Artem Titov33f9d2b2019-12-05 14:59:0048 return sink_wants_;
49}
50
Markus Handell16038ab2020-05-28 06:37:3051rtc::VideoSinkWants FrameForwarder::sink_wants_locked() const {
52 return sink_wants_;
53}
54
Artem Titov33f9d2b2019-12-05 14:59:0055bool FrameForwarder::has_sinks() const {
Markus Handella3765182020-07-08 11:13:3256 MutexLock lock(&mutex_);
Artem Titov33f9d2b2019-12-05 14:59:0057 return sink_ != nullptr;
58}
59
60} // namespace test
61} // namespace webrtc