Ring Daemon
Loading...
Searching...
No Matches
sinkclient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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 <memory>
28
29// #define DEBUG_FPS
30
31namespace jami {
32class MediaFilter;
33}
34
35namespace jami {
36namespace video {
37
38#ifdef ENABLE_SHM
39class ShmHolder;
40#endif // ENABLE_SHM
41
42class VideoScaler;
43
45{
46public:
47 SinkClient(const std::string& id = "", bool mixer = false);
48
49 const std::string& getId() const noexcept { return id_; }
50
51 std::string openedName() const noexcept;
52
53 int getWidth() const noexcept { return width_; }
54
55 int getHeight() const noexcept { return height_; }
56
58
59 // as VideoFramePassiveReader
60 void update(Observable<std::shared_ptr<jami::MediaFrame>>*, const std::shared_ptr<jami::MediaFrame>&) override;
61
62 bool start() noexcept;
63 bool stop() noexcept;
64
65 void setFrameSize(int width, int height);
66 void setCrop(int x, int y, int w, int h);
67
69 {
70 std::lock_guard lock(mtx_);
71 target_ = std::move(target);
72 }
73
74#ifdef ENABLE_SHM
75 void enableShm(bool value) { doShmTransfer_.store(value); }
76#endif
77
78private:
79 const std::string id_;
80 // True if the instance is used by a mixer.
81 const bool mixer_ {false};
82 int width_ {0};
83 int height_ {0};
84
85 struct Rect
86 {
87 int x {0}, y {0}, w {0}, h {0};
88 };
89 Rect crop_ {};
90
91 bool started_ {false}; // used to arbitrate client's stop signal.
92 int rotation_ {0};
93 libjami::SinkTarget target_;
94 std::unique_ptr<VideoScaler> scaler_;
95 std::unique_ptr<MediaFilter> filter_;
96 std::mutex mtx_;
97
98 libjami::FrameBuffer configureFrameDirect(const std::shared_ptr<jami::MediaFrame>&);
99 void sendFrameTransformed(AVFrame* frame);
100
107 std::shared_ptr<VideoFrame> applyTransform(VideoFrame& frame);
108
109#ifdef DEBUG_FPS
110 unsigned frameCount_;
111 std::chrono::steady_clock::time_point lastFrameDebug_;
112#endif
113
114#ifdef ENABLE_SHM
115 // using shared_ptr and not unique_ptr as ShmHolder is forwared only
116 std::shared_ptr<ShmHolder> shm_;
117 std::atomic_bool doShmTransfer_ {false};
118#endif // ENABLE_SHM
119};
120
121} // namespace video
122} // namespace jami
void setCrop(int x, int y, int w, int h)
int getWidth() const noexcept
Definition sinkclient.h:53
const std::string & getId() const noexcept
Definition sinkclient.h:49
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:68
std::string openedName() const noexcept
void setFrameSize(int width, int height)
int getHeight() const noexcept
Definition sinkclient.h:55
AVPixelFormat getPreferredFormat() const noexcept
Definition sinkclient.h:57
void emitSignal(Args... args)
Definition jami_signal.h:64
libjami::VideoFrame VideoFrame
Definition video_base.h:49
std::unique_ptr< AVFrame, AVFrame_deleter > FrameBuffer