20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22#include <yaml-cpp/yaml.h>
23#pragma GCC diagnostic pop
34constexpr const char*
const VideoDeviceMonitor::CONFIG_LABEL;
43 std::lock_guard
l(lock_);
45 ids.reserve(devices_.size());
46 for (
const auto&
dev : devices_) {
48 ids.emplace_back(
dev.getDeviceId());
56 std::lock_guard
l(lock_);
57 const auto iter = findDeviceById(
id);
58 if (
iter == devices_.end())
61 return iter->getCapabilities();
67 std::lock_guard
l(lock_);
69 const auto prefIter = findPreferencesById(
id);
79 std::lock_guard
l(lock_);
80 const auto iter = findDeviceById(
id);
82 if (
iter == devices_.end())
86 auto it = findPreferencesById(
settings.unique_id);
87 if (
it != preferences_.end())
94 std::lock_guard
l(lock_);
95 const auto it = findDeviceById(defaultDevice_);
98 return it->getDeviceId();
104 std::lock_guard
l(lock_);
105 const auto it = findDeviceById(defaultDevice_);
115 std::lock_guard
l(lock_);
116 const auto itDev = findDeviceById(
id);
117 if (
itDev != devices_.end()) {
118 if (defaultDevice_ ==
itDev->getDeviceId())
120 defaultDevice_ =
itDev->getDeviceId();
123 auto itPref = findPreferencesById(
itDev->getDeviceId());
124 if (
itPref != preferences_.end()) {
125 std::ranges::rotate(preferences_.begin(),
itPref,
itPref+1);
127 preferences_.insert(preferences_.begin(),
itDev->getSettings());
137 std::lock_guard
l(lock_);
138 const auto itd = findDeviceById(
id);
139 if (
itd != devices_.cend()) {
149 std::lock_guard
l(lock_);
150 const auto itd = findDeviceById(
id);
151 if (
itd == devices_.cend())
153 return itd->getDeviceParams();
163 for (
const auto& s : devices)
183 std::lock_guard
l(lock_);
184 if (findDeviceById(
id) != devices_.end())
190 if (
dev.getChannelList().empty())
196 auto it = findPreferencesById(
id);
197 if (
it != preferences_.end()) {
198 dev.applySettings(*
it);
200 dev.applySettings(
dev.getDefaultSettings());
201 preferences_.emplace_back(
dev.getSettings());
206 defaultDevice_ =
dev.getDeviceId();
208 devices_.emplace_back(std::move(
dev));
209 }
catch (
const std::exception&
e) {
221 std::lock_guard
l(lock_);
222 const auto it = findDeviceById(
id);
223 if (
it == devices_.end())
227 if (defaultDevice_.find(
id) != std::string::npos) {
228 defaultDevice_.clear();
229 for (
const auto&
dev : devices_)
231 defaultDevice_ =
dev.getDeviceId();
239vector<VideoDevice>::iterator
240VideoDeviceMonitor::findDeviceById(
const string&
id)
242 for (
auto it = devices_.begin();
it != devices_.end(); ++
it)
243 if (
it->getDeviceId().find(
id) != std::string::npos)
245 return devices_.end();
248vector<VideoDevice>::const_iterator
249VideoDeviceMonitor::findDeviceById(
const string&
id)
const
251 for (
auto it = devices_.cbegin();
it != devices_.cend(); ++
it)
252 if (
it->getDeviceId().find(
id) != std::string::npos)
254 return devices_.end();
257vector<VideoSettings>::iterator
258VideoDeviceMonitor::findPreferencesById(
const string&
id)
260 for (
auto it = preferences_.begin();
it != preferences_.end(); ++
it)
261 if (
it->unique_id.find(
id) != std::string::npos)
263 return preferences_.end();
267VideoDeviceMonitor::overwritePreferences(
const VideoSettings&
settings)
269 auto it = findPreferencesById(
settings.unique_id);
270 if (
it != preferences_.end())
271 preferences_.erase(
it);
272 preferences_.emplace_back(
settings);
278 std::lock_guard
l(lock_);
279 out << YAML::Key <<
"devices" << YAML::Value << preferences_;
285 std::lock_guard
l(lock_);
286 const auto& node =
in[CONFIG_LABEL];
289 const auto& devices = node[
"devices"];
290 for (
const auto&
dev : devices) {
292 if (
pref.unique_id.empty())
294 overwritePreferences(
pref);
295 auto itd = findDeviceById(
pref.unique_id);
296 if (
itd != devices_.end())
301 const string prefId = preferences_.empty() ?
"" : preferences_[0].unique_id;
304 defaultDevice_ =
devIter->getDeviceId();
306 defaultDevice_.clear();
307 for (
const auto&
dev : devices_)
309 defaultDevice_ =
dev.getDeviceId();
static std::atomic_bool initialized
bool addDevice(const std::string &node, const std::vector< std::map< std::string, std::string > > &devInfo={})
bool setDefaultDevice(const std::string &name)
libjami::VideoCapabilities getCapabilities(const std::string &name) const
std::string getDefaultDevice() const
DeviceParams getDeviceParams(const std::string &name) const
Params for libav.
void applySettings(const std::string &name, const VideoSettings &settings)
VideoSettings getSettings(const std::string &name)
void setDeviceOrientation(const std::string &id, int angle)
virtual void unserialize(const YAML::Node &in) override
std::vector< std::string > getDeviceList() const
void removeDevice(const std::string &node)
std::string getMRLForDefaultDevice() const
void serialize(YAML::Emitter &out) const override
static constexpr const char DEVICE_DESKTOP[]
static void giveUniqueName(VideoDevice &dev, const vector< VideoDevice > &devices)
void emitSignal(Args... args)
std::map< std::string, std::map< std::string, std::vector< std::string > > > VideoCapabilities
DeviceParams Parameters used by MediaDecoder and MediaEncoder to open a LibAV device/stream.