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