diff --git a/src/api/avmodel.h b/src/api/avmodel.h index 171fdf73eb99b17de2115dfa2890ca9ecbe87792..6232f1dda6f4c826f69220641afa6064a5d10ffb 100644 --- a/src/api/avmodel.h +++ b/src/api/avmodel.h @@ -110,6 +110,11 @@ public: * @return possibilities of the device */ video::Capabilities getDeviceCapabilities(const std::string& deviceId) const; + /** + * Get the deviceId corresponding to a given device friendly name + * @return deviceId + */ + std::string getDeviceIdFromName(const std::string& deviceName) const; /** * Get supported audio managers diff --git a/src/avmodel.cpp b/src/avmodel.cpp index c87737d49bc0627a93c668a500932bcff7ef87b3..081aaf6d29ccfeeaa8021f65adb2399b5eb79065 100644 --- a/src/avmodel.cpp +++ b/src/avmodel.cpp @@ -290,6 +290,22 @@ AVModel::setDeviceSettings(video::Settings& settings) } } +std::string +AVModel::getDeviceIdFromName(const std::string& deviceName) const +{ + auto devices = getDevices(); + auto iter = std::find_if(devices.begin(), devices.end(), + [this, deviceName](const std::string& d) { + auto settings = getDeviceSettings(d); + return settings.name == deviceName; + }); + if (iter == devices.end()) { + qWarning() << "Couldn't find device: " << deviceName.c_str(); + return {}; + } + return *iter; +} + std::vector<std::string> AVModel::getSupportedAudioManagers() const {