Skip to content
Snippets Groups Projects
Commit 2155cc3c authored by Vivien Didelot's avatar Vivien Didelot
Browse files

video_device_monitor: use getCapabilities

This patch makes defaultPreferences() and validatePreferences() use
getCapabilities() instead of relying on get*List() methods.

Refs #49517
Change-Id: I3c073aeea61e6befd630513886f4db9cc3db1385
parent 9faf3034
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <cassert>
#include <sstream> #include <sstream>
#include "config/yamlemitter.h" #include "config/yamlemitter.h"
...@@ -58,17 +59,19 @@ VideoDeviceMonitor::getCapabilities(const std::string& name) const ...@@ -58,17 +59,19 @@ VideoDeviceMonitor::getCapabilities(const std::string& name) const
VideoDeviceMonitor::VideoDevice VideoDeviceMonitor::VideoDevice
VideoDeviceMonitor::defaultPreferences(const std::string& name) const VideoDeviceMonitor::defaultPreferences(const std::string& name) const
{ {
VideoCapabilities cap = getCapabilities(name);
VideoDevice dev; VideoDevice dev;
dev.name = name; dev.name = name;
auto list = getChannelList(dev.name); assert(!cap.empty());
dev.channel = list.empty() ? "" : list[0]; dev.channel = cap.begin()->first;
list = getSizeList(dev.name, dev.channel); assert(!cap[dev.channel].empty());
dev.size = list.empty() ? "" : list[0]; dev.size = cap[dev.channel].begin()->first;
list = getRateList(dev.name, dev.channel, dev.size); assert(!cap[dev.channel][dev.size].empty());
dev.rate = list.empty() ? "" : list[0]; dev.rate = cap[dev.channel][dev.size][0];
return dev; return dev;
} }
...@@ -158,22 +161,22 @@ VideoDeviceMonitor::validatePreference(const VideoDevice& dev) const ...@@ -158,22 +161,22 @@ VideoDeviceMonitor::validatePreference(const VideoDevice& dev) const
DEBUG("prefs: name:%s channel:%s size:%s rate:%s", dev.name.data(), DEBUG("prefs: name:%s channel:%s size:%s rate:%s", dev.name.data(),
dev.channel.data(), dev.size.data(), dev.rate.data()); dev.channel.data(), dev.size.data(), dev.rate.data());
VideoCapabilities cap = getCapabilities(dev.name);
// Validate the channel // Validate the channel
const auto chans = getChannelList(dev.name); if (cap[dev.channel].empty()) {
if (std::find(chans.begin(), chans.end(), dev.channel) == chans.end()) {
DEBUG("Bad channel, ignoring"); DEBUG("Bad channel, ignoring");
return false; return false;
} }
// Validate the size // Validate the size
const auto sizes = getSizeList(dev.name, dev.channel); if (cap[dev.channel][dev.size].empty()) {
if (std::find(sizes.begin(), sizes.end(), dev.size) == sizes.end()) {
DEBUG("Bad size, ignoring"); DEBUG("Bad size, ignoring");
return false; return false;
} }
// Validate the rate // Validate the rate
const auto rates = getRateList(dev.name, dev.channel, dev.size); const auto rates = cap[dev.channel][dev.size];
if (std::find(rates.begin(), rates.end(), dev.rate) == rates.end()) { if (std::find(rates.begin(), rates.end(), dev.rate) == rates.end()) {
DEBUG("Bad rate, ignoring"); DEBUG("Bad rate, ignoring");
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment