Ring Daemon 16.0.0
Loading...
Searching...
No Matches
sinkclient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "video_base.h"
25
26#include <string>
27#include <vector>
28#include <memory>
29
30//#define DEBUG_FPS
31
32namespace jami {
33class MediaFilter;
34}
35
36namespace jami {
37namespace video {
38
39#ifdef ENABLE_SHM
40class ShmHolder;
41#endif // ENABLE_SHM
42
43class VideoScaler;
44
46{
47public:
48 SinkClient(const std::string& id = "", bool mixer = false);
49
50 const std::string& getId() const noexcept { return id_; }
51
52 std::string openedName() const noexcept;
53
54 int getWidth() const noexcept { return width_; }
55
56 int getHeight() const noexcept { return height_; }
57
62
63 // as VideoFramePassiveReader
64 void update(Observable<std::shared_ptr<jami::MediaFrame>>*,
65 const std::shared_ptr<jami::MediaFrame>&) override;
66
67 bool start() noexcept;
68 bool stop() noexcept;
69
70 void setFrameSize(int width, int height);
71 void setCrop(int x, int y, int w, int h);
72
74 {
75 std::lock_guard lock(mtx_);
76 target_ = std::move(target);
77 }
78
79#ifdef ENABLE_SHM
80 void enableShm(bool value) { doShmTransfer_.store(value); }
81#endif
82
83private:
84 const std::string id_;
85 // True if the instance is used by a mixer.
86 const bool mixer_ {false};
87 int width_ {0};
88 int height_ {0};
89
90 struct Rect
91 {
92 int x {0}, y {0}, w {0}, h {0};
93 };
94 Rect crop_ {};
95
96 bool started_ {false}; // used to arbitrate client's stop signal.
97 int rotation_ {0};
98 libjami::SinkTarget target_;
99 std::unique_ptr<VideoScaler> scaler_;
100 std::unique_ptr<MediaFilter> filter_;
101 std::mutex mtx_;
102
103 void sendFrameDirect(const std::shared_ptr<jami::MediaFrame>&);
104 void sendFrameTransformed(AVFrame* frame);
105
112 std::shared_ptr<VideoFrame> applyTransform(VideoFrame& frame);
113
114#ifdef DEBUG_FPS
115 unsigned frameCount_;
116 std::chrono::steady_clock::time_point lastFrameDebug_;
117#endif
118
119#ifdef ENABLE_SHM
120 // using shared_ptr and not unique_ptr as ShmHolder is forwared only
121 std::shared_ptr<ShmHolder> shm_;
122 std::atomic_bool doShmTransfer_ {false};
123#endif // ENABLE_SHM
124};
125
126} // namespace video
127} // namespace jami
void setCrop(int x, int y, int w, int h)
int getWidth() const noexcept
Definition sinkclient.h:54
const std::string & getId() const noexcept
Definition sinkclient.h:50
bool start() noexcept
void update(Observable< std::shared_ptr< jami::MediaFrame > > *, const std::shared_ptr< jami::MediaFrame > &) override
void registerTarget(libjami::SinkTarget target) noexcept
Definition sinkclient.h:73
std::string openedName() const noexcept
void setFrameSize(int width, int height)
int getHeight() const noexcept
Definition sinkclient.h:56
AVPixelFormat getPreferredFormat() const noexcept
Definition sinkclient.h:58
void emitSignal(Args... args)
Definition ring_signal.h:64
libjami::VideoFrame VideoFrame
Definition video_base.h:53