Ring Daemon
Loading...
Searching...
No Matches
video_base.cpp
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#include "libav_deps.h" // MUST BE INCLUDED FIRST
19#include "video_base.h"
20#include "media_buffer.h"
21#include "logger.h"
22
23#include <cassert>
24
25namespace jami {
26namespace video {
27
28/*=== VideoGenerator =========================================================*/
29
32{
33 std::lock_guard lk(mutex_);
34 writableFrame_.reset(new VideoFrame());
35 return *writableFrame_.get();
36}
37
38void
40{
41 std::lock_guard lk(mutex_);
42 lastFrame_ = std::move(writableFrame_);
43 notify(std::static_pointer_cast<MediaFrame>(lastFrame_));
44}
45
46void
47VideoGenerator::publishFrame(std::shared_ptr<VideoFrame> frame)
48{
49 std::lock_guard lk(mutex_);
50 lastFrame_ = std::move(frame);
51 notify(std::static_pointer_cast<MediaFrame>(lastFrame_));
52}
53
54void
56{
57 std::lock_guard lk(mutex_);
58 writableFrame_.reset();
59 lastFrame_.reset();
60}
61
62std::shared_ptr<VideoFrame>
64{
65 std::lock_guard lk(mutex_);
66 return lastFrame_;
67}
68
69/*=== VideoSettings =========================================================*/
70
71static std::string
72extractString(const std::map<std::string, std::string>& settings, const std::string& key)
73{
74 auto i = settings.find(key);
75 if (i != settings.cend())
76 return i->second;
77 return {};
78}
79
80VideoSettings::VideoSettings(const std::map<std::string, std::string>& settings)
81{
82 name = extractString(settings, "name");
84 input = extractString(settings, "input");
85 if (input.empty()) {
87 }
88 channel = extractString(settings, "channel");
91}
92
93std::map<std::string, std::string>
95{
96 return {{"name", name},
97 {"id", unique_id},
98 {"input", input},
99 {"size", video_size},
100 {"channel", channel},
101 {"rate", framerate}};
102}
103
104} // namespace video
105} // namespace jami
106
107namespace YAML {
108
109Node
110convert<jami::video::VideoSettings>::encode(const jami::video::VideoSettings& rhs)
111{
112 Node node;
113 node["name"] = rhs.name;
114 node["id"] = rhs.unique_id;
115 node["input"] = rhs.input;
116 node["video_size"] = rhs.video_size;
117 node["channel"] = rhs.channel;
118 node["framerate"] = rhs.framerate;
119 return node;
120}
121
122bool
123convert<jami::video::VideoSettings>::decode(const Node& node, jami::video::VideoSettings& rhs)
124{
125 if (not node.IsMap()) {
126 JAMI_WARN("Unable to decode VideoSettings YAML node");
127 return false;
128 }
129 rhs.name = node["name"].as<std::string>();
130 rhs.unique_id = node["id"].as<std::string>();
131 rhs.input = node["input"].as<std::string>();
132 rhs.video_size = node["video_size"].as<std::string>();
133 rhs.channel = node["channel"].as<std::string>();
134 rhs.framerate = node["framerate"].as<std::string>();
135 return true;
136}
137
138Emitter&
139operator<<(Emitter& out, const jami::video::VideoSettings& v)
140{
141 out << convert<jami::video::VideoSettings>::encode(v);
142 return out;
143}
144
145} // namespace YAML
std::shared_ptr< VideoFrame > obtainLastFrame()
#define JAMI_WARN(...)
Definition logger.h:229
Emitter & operator<<(Emitter &out, const jami::video::VideoSettings &v)
static std::string extractString(const std::map< std::string, std::string > &settings, const std::string &key)
void emitSignal(Args... args)
Definition jami_signal.h:64
libjami::VideoFrame VideoFrame
Definition video_base.h:49
std::map< std::string, std::string > to_map() const