Ring Daemon 16.0.0
Loading...
Searching...
No Matches
videomanager_interface.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
18#ifndef DENABLE_VIDEOMANAGERI_H
19#define DENABLE_VIDEOMANAGERI_H
20
21#include "jami.h"
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif // HAVE_CONFIG_H
25
26extern "C" {
27struct AVFrame;
28struct AVPacket;
29void av_frame_free(AVFrame** frame);
30void av_packet_free(AVPacket** frame);
31}
32
33#include "def.h"
34
35#include <memory>
36#include <vector>
37#include <map>
38#include <string>
39#include <functional>
40#include <chrono>
41#include <cstdint>
42#include <cstdlib>
43
44#ifdef __APPLE__
45#import "TargetConditionals.h"
46#endif
47
48namespace jami {
49struct AudioFormat;
50}
51
52namespace libjami {
53
54[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerVideoHandlers(
55 const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
56
58{
59 void operator()(AVFrame* frame) const { av_frame_free(&frame); }
60};
61
62typedef std::unique_ptr<AVFrame, AVFrame_deleter> FrameBuffer;
63
65{
66 void operator()(AVPacket* pkt) const { av_packet_free(&pkt); }
67};
68
69typedef std::unique_ptr<AVPacket, AVPacket_deleter> PacketBuffer;
70
72{
73public:
74 // Construct an empty MediaFrame
75 MediaFrame();
76 MediaFrame(const MediaFrame&) = delete;
77 MediaFrame& operator=(const MediaFrame& o) = delete;
78 MediaFrame(MediaFrame&& o) = delete;
80
81 virtual ~MediaFrame() = default;
82
83 // Return a pointer on underlaying buffer
84 const AVFrame* pointer() const noexcept { return frame_.get(); }
85 AVFrame* pointer() noexcept { return frame_.get(); }
86 AVPacket* packet() const noexcept { return packet_.get(); }
87
88 // Fill this MediaFrame with data from o
89 void copyFrom(const MediaFrame& o);
90 void setPacket(PacketBuffer&& pkt);
91
92 // Reset internal buffers (return to an empty MediaFrame)
93 virtual void reset() noexcept;
94
95 FrameBuffer getFrame() { return std::move(frame_); }
96
97protected:
100};
101
103{
104public:
106 : MediaFrame()
107 {}
108 AudioFrame(const jami::AudioFormat& format, size_t nb_samples = 0);
110 void mix(const AudioFrame& o);
111 float calcRMS() const;
112 jami::AudioFormat getFormat() const;
113 size_t getFrameSize() const;
114 bool has_voice {false};
115
116private:
117 void setFormat(const jami::AudioFormat& format);
118 void reserve(size_t nb_samples = 0);
119};
120
122{
123public:
124 // Construct an empty VideoFrame
126 : MediaFrame()
127 {}
129
130 // Reset internal buffers (return to an empty VideoFrame)
131 void reset() noexcept override;
132
133 // Fill this VideoFrame with data from o
134 void copyFrom(const VideoFrame& o);
135
136 // Return frame size in bytes
137 std::size_t size() const noexcept;
138
139 // Return pixel format
140 int format() const noexcept;
141
142 // Return frame width in pixels
143 int width() const noexcept;
144
145 // Return frame height in pixels
146 int height() const noexcept;
147
148 // Allocate internal pixel buffers following given specifications
149 void reserve(int format, int width, int height);
150
151 // Return orientation (in degrees) stored in the frame metadata, or 0 by default.
152 int getOrientation() const;
153
154 // Set internal pixel buffers on given memory buffer
155 // This buffer must follow given specifications.
156 void setFromMemory(uint8_t* data, int format, int width, int height) noexcept;
157 void setFromMemory(uint8_t* data,
158 int format,
159 int width,
160 int height,
161 const std::function<void(uint8_t*)>& cb) noexcept;
162 void setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept;
163
164 void noise();
165
166private:
167 std::function<void(uint8_t*)> releaseBufferCb_ {};
168 uint8_t* ptr_ {nullptr};
169 bool allocated_ {false};
170 void setGeometry(int format, int width, int height) noexcept;
171};
172
174{
175 std::function<FrameBuffer()> pull;
176 std::function<void(FrameBuffer)> push;
177 int /* AVPixelFormat */ preferredFormat {-1 /* AV_PIX_FMT_NONE */};
178};
179
180using VideoCapabilities = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
181
182LIBJAMI_PUBLIC std::vector<std::string> getDeviceList();
184LIBJAMI_PUBLIC std::map<std::string, std::string> getSettings(const std::string& deviceId);
185LIBJAMI_PUBLIC void applySettings(const std::string& deviceId,
186 const std::map<std::string, std::string>& settings);
187LIBJAMI_PUBLIC void setDefaultDevice(const std::string& deviceId);
188LIBJAMI_PUBLIC void setDeviceOrientation(const std::string& deviceId, int angle);
189LIBJAMI_PUBLIC std::map<std::string, std::string> getDeviceParams(const std::string& deviceId);
193
194LIBJAMI_PUBLIC std::string openVideoInput(const std::string& path);
195LIBJAMI_PUBLIC bool closeVideoInput(const std::string& id);
196
197LIBJAMI_PUBLIC std::string createMediaPlayer(const std::string& path);
198LIBJAMI_PUBLIC bool closeMediaPlayer(const std::string& id);
199LIBJAMI_PUBLIC bool pausePlayer(const std::string& id, const bool& pause);
200LIBJAMI_PUBLIC bool mutePlayerAudio(const std::string& id, const bool& mute);
201LIBJAMI_PUBLIC bool playerSeekToTime(const std::string& id, const int& time);
202LIBJAMI_PUBLIC int64_t getPlayerPosition(const std::string& id);
203LIBJAMI_PUBLIC int64_t getPlayerDuration(const std::string& id);
204LIBJAMI_PUBLIC void setAutoRestart(const std::string& id, const bool& restart);
205
206LIBJAMI_PUBLIC bool registerSinkTarget(const std::string& sinkId, SinkTarget target);
207#ifdef ENABLE_SHM
208LIBJAMI_PUBLIC void startShmSink(const std::string& sinkId, bool value);
209#endif
210LIBJAMI_PUBLIC std::map<std::string, std::string> getRenderer(const std::string& callId);
211
212LIBJAMI_PUBLIC std::string startLocalMediaRecorder(const std::string& videoInputId,
213 const std::string& filepath);
214LIBJAMI_PUBLIC void stopLocalRecorder(const std::string& filepath);
215
216#if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
217LIBJAMI_PUBLIC void addVideoDevice(
218 const std::string& node, const std::vector<std::map<std::string, std::string>>& devInfo = {});
219LIBJAMI_PUBLIC void removeVideoDevice(const std::string& node);
220LIBJAMI_PUBLIC VideoFrame* getNewFrame(std::string_view id);
221LIBJAMI_PUBLIC void publishFrame(std::string_view id);
222#endif
223
228
229// player signal type definitions
231{
233 {
234 constexpr static const char* name = "FileOpened";
235 using cb_type = void(const std::string& /*playerId*/,
236 std::map<std::string, std::string> /*playerInfo*/);
237 };
238};
239
240// Video signal type definitions
242{
244 {
245 constexpr static const char* name = "DeviceEvent";
246 using cb_type = void(void);
247 };
249 {
250 constexpr static const char* name = "DecodingStarted";
251 using cb_type = void(const std::string& /*id*/,
252 const std::string& /*shm_path*/,
253 int /*w*/,
254 int /*h*/,
255 bool /*is_mixer*/ id);
256 };
258 {
259 constexpr static const char* name = "DecodingStopped";
260 using cb_type = void(const std::string& /*id*/,
261 const std::string& /*shm_path*/,
262 bool /*is_mixer*/);
263 };
264#ifdef __ANDROID__
265 struct LIBJAMI_PUBLIC SetParameters
266 {
267 constexpr static const char* name = "SetParameters";
268 using cb_type = void(const std::string& device,
269 const int format,
270 const int width,
271 const int height,
272 const int rate);
273 };
274 struct LIBJAMI_PUBLIC GetCameraInfo
275 {
276 constexpr static const char* name = "GetCameraInfo";
277 using cb_type = void(const std::string& device,
278 std::vector<int>* formats,
279 std::vector<unsigned>* sizes,
280 std::vector<unsigned>* rates);
281 };
282 struct LIBJAMI_PUBLIC RequestKeyFrame
283 {
284 constexpr static const char* name = "RequestKeyFrame";
285 using cb_type = void(const std::string& /*device*/);
286 };
287 struct LIBJAMI_PUBLIC SetBitrate
288 {
289 constexpr static const char* name = "SetBitrate";
290 using cb_type = void(const std::string& /*device*/, const int bitrate);
291 };
292#endif
294 {
295 constexpr static const char* name = "StartCapture";
296 using cb_type = void(const std::string& /*device*/);
297 };
299 {
300 constexpr static const char* name = "StopCapture";
301 using cb_type = void(const std::string& /*device*/);
302 };
304 {
305 constexpr static const char* name = "DeviceAdded";
306 using cb_type = void(const std::string& /*device*/);
307 };
309 {
310 constexpr static const char* name = "ParametersChanged";
311 using cb_type = void(const std::string& /*device*/);
312 };
313};
314
315} // namespace libjami
316
317#endif // DENABLE_VIDEOMANAGERI_H
MediaFrame & operator=(const MediaFrame &o)=delete
const AVFrame * pointer() const noexcept
MediaFrame(MediaFrame &&o)=delete
MediaFrame(const MediaFrame &)=delete
AVPacket * packet() const noexcept
MediaFrame & operator=(MediaFrame &&o)=delete
AVFrame * pointer() noexcept
virtual ~MediaFrame()=default
void reset() noexcept override
#define LIBJAMI_PUBLIC
Definition def.h:42
LIBJAMI_PUBLIC void applySettings(const std::string &deviceId, const std::map< std::string, std::string > &settings)
LIBJAMI_PUBLIC std::map< std::string, std::string > getDeviceParams(const std::string &deviceId)
void stopAudioDevice()
bool closeMediaPlayer(const std::string &id)
LIBJAMI_PUBLIC std::string getDefaultDevice()
bool getEncodingAccelerated()
std::string startLocalMediaRecorder(const std::string &videoInputId, const std::string &filepath)
bool playerSeekToTime(const std::string &id, const int &time)
std::unique_ptr< AVFrame, AVFrame_deleter > FrameBuffer
std::map< std::string, std::string > getRenderer(const std::string &callId)
LIBJAMI_PUBLIC VideoCapabilities getCapabilities(const std::string &deviceId)
void setEncodingAccelerated(bool state)
bool registerSinkTarget(const std::string &sinkId, SinkTarget target)
LIBJAMI_PUBLIC void setDefaultDevice(const std::string &deviceId)
LIBJAMI_PUBLIC std::map< std::string, std::string > getSettings(const std::string &deviceId)
std::unique_ptr< AVPacket, AVPacket_deleter > PacketBuffer
bool pausePlayer(const std::string &id, const bool &pause)
LIBJAMI_PUBLIC void registerVideoHandlers(const std::map< std::string, std::shared_ptr< CallbackWrapperBase > > &)
std::string createMediaPlayer(const std::string &path)
void setDecodingAccelerated(bool state)
void stopLocalRecorder(const std::string &filepath)
LIBJAMI_PUBLIC std::vector< std::string > getDeviceList()
bool getDecodingAccelerated()
LIBJAMI_PUBLIC std::string openVideoInput(const std::string &path)
std::map< std::string, std::map< std::string, std::vector< std::string > > > VideoCapabilities
int64_t getPlayerPosition(const std::string &id)
int64_t getPlayerDuration(const std::string &id)
LIBJAMI_PUBLIC void setDeviceOrientation(const std::string &deviceId, int angle)
LIBJAMI_PUBLIC bool closeVideoInput(const std::string &id)
void setAutoRestart(const std::string &id, const bool &restart)
void startAudioDevice()
bool mutePlayerAudio(const std::string &id, const bool &mute)
Structure to hold sample rate and channel number associated with audio data.
void operator()(AVFrame *frame) const
void operator()(AVPacket *pkt) const
void(const std::string &, std::map< std::string, std::string >) cb_type
std::function< FrameBuffer()> pull
std::function< void(FrameBuffer)> push
void(const std::string &, const std::string &, int, int, bool id) cb_type
void(const std::string &, const std::string &, bool) cb_type
void av_packet_free(AVPacket **frame)
void av_frame_free(AVFrame **frame)