Ring Daemon
Loading...
Searching...
No Matches
videomanager_interface.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
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 <cstdint>
41#include <cstdlib>
42
43#ifdef __APPLE__
44#import "TargetConditionals.h"
45#endif
46
47namespace jami {
48struct AudioFormat;
49}
50
51namespace libjami {
52
53[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerVideoHandlers(
54 const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
55
57{
58 inline void operator()(AVFrame* frame) const { av_frame_free(&frame); }
59};
60
61typedef std::unique_ptr<AVFrame, AVFrame_deleter> FrameBuffer;
62
64{
65 inline void operator()(AVPacket* pkt) const { av_packet_free(&pkt); }
66};
67
68typedef std::unique_ptr<AVPacket, AVPacket_deleter> PacketBuffer;
69
71{
72public:
73 // Construct an empty MediaFrame
74 MediaFrame();
75 MediaFrame(const MediaFrame&) = delete;
76 MediaFrame& operator=(const MediaFrame& o) = delete;
77 MediaFrame(MediaFrame&& o) = delete;
79
80 virtual ~MediaFrame() = default;
81
82 // Return a pointer on underlaying buffer
83 const AVFrame* pointer() const noexcept { return frame_.get(); }
84 AVFrame* pointer() noexcept { return frame_.get(); }
85 AVPacket* packet() const noexcept { return packet_.get(); }
86
87 // Fill this MediaFrame with data from o
88 void copyFrom(const MediaFrame& o);
89 void setPacket(PacketBuffer&& pkt);
90
91 // Reset internal buffers (return to an empty MediaFrame)
92 virtual void reset() noexcept;
93
94 FrameBuffer getFrame() { return std::move(frame_); }
95
96protected:
99};
100
102{
103public:
105 : MediaFrame()
106 {}
107 AudioFrame(const jami::AudioFormat& format, size_t nb_samples = 0);
109 void mix(const AudioFrame& o);
110 float calcRMS() const;
111 jami::AudioFormat getFormat() const;
112 size_t getFrameSize() const;
113 bool has_voice {false};
114
115private:
116 void setFormat(const jami::AudioFormat& format);
117 void reserve(size_t nb_samples = 0);
118};
119
121{
122public:
123 // Construct an empty VideoFrame
125 : MediaFrame()
126 {}
128
129 // Reset internal buffers (return to an empty VideoFrame)
130 void reset() noexcept override;
131
132 // Fill this VideoFrame with data from o
133 void copyFrom(const VideoFrame& o);
134
135 // Return frame size in bytes
136 std::size_t size() const noexcept;
137
138 // Return pixel format
139 int format() const noexcept;
140
141 // Return frame width in pixels
142 int width() const noexcept;
143
144 // Return frame height in pixels
145 int height() const noexcept;
146
147 // Allocate internal pixel buffers following given specifications
148 void reserve(int format, int width, int height);
149
150 // Return orientation (in degrees) stored in the frame metadata, or 0 by default.
151 int getOrientation() const;
152
153 // Set internal pixel buffers on given memory buffer
154 // This buffer must follow given specifications.
155 void setFromMemory(uint8_t* data, int format, int width, int height) noexcept;
156 void setFromMemory(
157 uint8_t* data, int format, int width, int height, const std::function<void(uint8_t*)>& cb) noexcept;
158 void setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept;
159
160 void noise();
161
162private:
163 std::function<void(uint8_t*)> releaseBufferCb_ {};
164 uint8_t* ptr_ {nullptr};
165 bool allocated_ {false};
166 void setGeometry(int format, int width, int height) noexcept;
167};
168
170{
171 std::function<FrameBuffer()> pull;
172 std::function<void(FrameBuffer)> push;
173 int /* AVPixelFormat */ preferredFormat {-1 /* AV_PIX_FMT_NONE */};
174};
175
176using VideoCapabilities = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
177
178LIBJAMI_PUBLIC std::vector<std::string> getDeviceList();
180LIBJAMI_PUBLIC std::map<std::string, std::string> getSettings(const std::string& deviceId);
181LIBJAMI_PUBLIC void applySettings(const std::string& deviceId, const std::map<std::string, std::string>& settings);
182LIBJAMI_PUBLIC void setDefaultDevice(const std::string& deviceId);
183LIBJAMI_PUBLIC void setDeviceOrientation(const std::string& deviceId, int angle);
184LIBJAMI_PUBLIC std::map<std::string, std::string> getDeviceParams(const std::string& deviceId);
188
189LIBJAMI_PUBLIC std::string openVideoInput(const std::string& path);
190LIBJAMI_PUBLIC bool closeVideoInput(const std::string& id);
191
192LIBJAMI_PUBLIC std::string createMediaPlayer(const std::string& path);
193LIBJAMI_PUBLIC bool closeMediaPlayer(const std::string& id);
194LIBJAMI_PUBLIC bool pausePlayer(const std::string& id, const bool& pause);
195LIBJAMI_PUBLIC bool mutePlayerAudio(const std::string& id, const bool& mute);
196LIBJAMI_PUBLIC bool playerSeekToTime(const std::string& id, const int& time);
197LIBJAMI_PUBLIC int64_t getPlayerPosition(const std::string& id);
198LIBJAMI_PUBLIC int64_t getPlayerDuration(const std::string& id);
199LIBJAMI_PUBLIC void setAutoRestart(const std::string& id, const bool& restart);
200
201LIBJAMI_PUBLIC bool registerSinkTarget(const std::string& sinkId, SinkTarget target);
202#ifdef ENABLE_SHM
203LIBJAMI_PUBLIC void startShmSink(const std::string& sinkId, bool value);
204#endif
205LIBJAMI_PUBLIC std::map<std::string, std::string> getRenderer(const std::string& callId);
206
207LIBJAMI_PUBLIC std::string startLocalMediaRecorder(const std::string& videoInputId, const std::string& filepath);
208LIBJAMI_PUBLIC void stopLocalRecorder(const std::string& filepath);
209
210#if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
211LIBJAMI_PUBLIC void addVideoDevice(const std::string& node,
212 const std::vector<std::map<std::string, std::string>>& devInfo = {});
213LIBJAMI_PUBLIC void removeVideoDevice(const std::string& node);
214LIBJAMI_PUBLIC VideoFrame* getNewFrame(std::string_view id);
215LIBJAMI_PUBLIC void publishFrame(std::string_view id);
216#endif
217
222
223// player signal type definitions
225{
227 {
228 constexpr static const char* name = "FileOpened";
229 using cb_type = void(const std::string& /*playerId*/, std::map<std::string, std::string> /*playerInfo*/);
230 };
231};
232
233// Video signal type definitions
235{
237 {
238 constexpr static const char* name = "DeviceEvent";
239 using cb_type = void(void);
240 };
242 {
243 constexpr static const char* name = "DecodingStarted";
244 using cb_type = void(
245 const std::string& /*id*/, const std::string& /*shm_path*/, int /*w*/, int /*h*/, bool /*is_mixer*/ id);
246 };
248 {
249 constexpr static const char* name = "DecodingStopped";
250 using cb_type = void(const std::string& /*id*/, const std::string& /*shm_path*/, bool /*is_mixer*/);
251 };
252#ifdef __ANDROID__
253 struct LIBJAMI_PUBLIC SetParameters
254 {
255 constexpr static const char* name = "SetParameters";
256 using cb_type = void(
257 const std::string& device, const int format, const int width, const int height, const int rate);
258 };
259 struct LIBJAMI_PUBLIC GetCameraInfo
260 {
261 constexpr static const char* name = "GetCameraInfo";
262 using cb_type = void(const std::string& device,
263 std::vector<int>* formats,
264 std::vector<unsigned>* sizes,
265 std::vector<unsigned>* rates);
266 };
267 struct LIBJAMI_PUBLIC RequestKeyFrame
268 {
269 constexpr static const char* name = "RequestKeyFrame";
270 using cb_type = void(const std::string& /*device*/);
271 };
272 struct LIBJAMI_PUBLIC SetBitrate
273 {
274 constexpr static const char* name = "SetBitrate";
275 using cb_type = void(const std::string& /*device*/, const int bitrate);
276 };
277#endif
279 {
280 constexpr static const char* name = "StartCapture";
281 using cb_type = void(const std::string& /*device*/);
282 };
284 {
285 constexpr static const char* name = "StopCapture";
286 using cb_type = void(const std::string& /*device*/);
287 };
289 {
290 constexpr static const char* name = "DeviceAdded";
291 using cb_type = void(const std::string& /*device*/);
292 };
294 {
295 constexpr static const char* name = "ParametersChanged";
296 using cb_type = void(const std::string& /*device*/);
297 };
298};
299
300} // namespace libjami
301
302#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)