Final changes before the release.

Removed code to elevate privileges in Windows, now you must explicitly
run the manager as administrator.
Allow setting a device ID in the config file.
Changed wording from 'Device Path' to 'Device ID' (and similar ones),
this breaks previous devices configurations.
Return standard error codes in the manager.
Added plugin install path hint in Windows registry.
This commit is contained in:
Gonzalo Exequiel Pedone 2021-06-21 18:25:48 -03:00
parent c0d241d0b4
commit b0f83b8462
No known key found for this signature in database
GPG key ID: B8B09E63E9B85BAF
16 changed files with 244 additions and 242 deletions

View file

@ -18,6 +18,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <cerrno>
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
#include <codecvt> #include <codecvt>
@ -387,7 +388,7 @@ int AkVCam::CmdParser::parse(int argc, char **argv)
<< "'" << "'"
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
std::string value; std::string value;
@ -421,7 +422,7 @@ int AkVCam::CmdParser::parse(int argc, char **argv)
} else { } else {
std::cout << "Unknown command '" << arg << "'" << std::endl; std::cout << "Unknown command '" << arg << "'" << std::endl;
return -1; return -EINVAL;
} }
} else { } else {
arguments.push_back(arg); arguments.push_back(arg);
@ -451,14 +452,17 @@ int AkVCam::CmdParser::parse(int argc, char **argv)
this->d->drawTable(table, columns, true); this->d->drawTable(table, columns, true);
} }
return -1; return -EBUSY;
} }
if (this->d->m_ipcBridge.needsRoot(command->command) if (this->d->m_ipcBridge.needsRoot(command->command)
|| (command->command == "hack" || (command->command == "hack"
&& arguments.size() >= 2 && arguments.size() >= 2
&& this->d->m_ipcBridge.hackNeedsRoot(arguments[1]))) && this->d->m_ipcBridge.hackNeedsRoot(arguments[1]))) {
return this->d->m_ipcBridge.sudo(argc, argv); std::cerr << "You must run this command with administrator privileges." << std::endl;
return -EPERM;
}
return command->func(flags, arguments); return command->func(flags, arguments);
} }
@ -878,7 +882,7 @@ int AkVCam::CmdParserPrivate::addDevice(const StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Device description not provided." << std::endl; std::cerr << "Device description not provided." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = this->flagValue(flags, "add-device", "-i"); auto deviceId = this->flagValue(flags, "add-device", "-i");
@ -887,7 +891,7 @@ int AkVCam::CmdParserPrivate::addDevice(const StringMap &flags,
if (deviceId.empty()) { if (deviceId.empty()) {
std::cerr << "Failed to create device." << std::endl; std::cerr << "Failed to create device." << std::endl;
return -1; return -EIO;
} }
if (this->m_parseable) if (this->m_parseable)
@ -906,7 +910,7 @@ int AkVCam::CmdParserPrivate::removeDevice(const StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Device not provided." << std::endl; std::cerr << "Device not provided." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -916,7 +920,7 @@ int AkVCam::CmdParserPrivate::removeDevice(const StringMap &flags,
if (it == devices.end()) { if (it == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
this->m_ipcBridge.removeDevice(args[1]); this->m_ipcBridge.removeDevice(args[1]);
@ -945,7 +949,7 @@ int AkVCam::CmdParserPrivate::showDeviceDescription(const StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Device not provided." << std::endl; std::cerr << "Device not provided." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -955,7 +959,7 @@ int AkVCam::CmdParserPrivate::showDeviceDescription(const StringMap &flags,
if (it == devices.end()) { if (it == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
std::cout << this->m_ipcBridge.description(args[1]) << std::endl; std::cout << this->m_ipcBridge.description(args[1]) << std::endl;
@ -971,7 +975,7 @@ int AkVCam::CmdParserPrivate::setDeviceDescription(const AkVCam::StringMap &flag
if (args.size() < 3) { if (args.size() < 3) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -981,7 +985,7 @@ int AkVCam::CmdParserPrivate::setDeviceDescription(const AkVCam::StringMap &flag
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
this->m_ipcBridge.setDescription(deviceId, args[2]); this->m_ipcBridge.setDescription(deviceId, args[2]);
@ -1038,7 +1042,7 @@ int AkVCam::CmdParserPrivate::showFormats(const StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Device not provided." << std::endl; std::cerr << "Device not provided." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1048,7 +1052,7 @@ int AkVCam::CmdParserPrivate::showFormats(const StringMap &flags,
if (it == devices.end()) { if (it == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
if (this->m_parseable) { if (this->m_parseable) {
@ -1093,7 +1097,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (args.size() < 6) { if (args.size() < 6) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1103,7 +1107,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
auto format = VideoFormat::fourccFromString(args[2]); auto format = VideoFormat::fourccFromString(args[2]);
@ -1111,7 +1115,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (!format) { if (!format) {
std::cerr << "Invalid pixel format." << std::endl; std::cerr << "Invalid pixel format." << std::endl;
return -1; return -EINVAL;
} }
auto formats = auto formats =
@ -1121,7 +1125,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (fit == formats.end()) { if (fit == formats.end()) {
std::cerr << "Format not supported." << std::endl; std::cerr << "Format not supported." << std::endl;
return -1; return -EINVAL;
} }
char *p = nullptr; char *p = nullptr;
@ -1130,7 +1134,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Width must be an unsigned integer." << std::endl; std::cerr << "Width must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
p = nullptr; p = nullptr;
@ -1139,7 +1143,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Height must be an unsigned integer." << std::endl; std::cerr << "Height must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
Fraction fps(args[5]); Fraction fps(args[5]);
@ -1147,7 +1151,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (fps.num() < 1 || fps.den() < 1) { if (fps.num() < 1 || fps.den() < 1) {
std::cerr << "Invalid frame rate." << std::endl; std::cerr << "Invalid frame rate." << std::endl;
return -1; return -EINVAL;
} }
auto indexStr = this->flagValue(flags, "add-format", "-i"); auto indexStr = this->flagValue(flags, "add-format", "-i");
@ -1160,7 +1164,7 @@ int AkVCam::CmdParserPrivate::addFormat(const StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Index must be an unsigned integer." << std::endl; std::cerr << "Index must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
} }
@ -1178,7 +1182,7 @@ int AkVCam::CmdParserPrivate::removeFormat(const StringMap &flags,
if (args.size() < 3) { if (args.size() < 3) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1188,7 +1192,7 @@ int AkVCam::CmdParserPrivate::removeFormat(const StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
char *p = nullptr; char *p = nullptr;
@ -1197,7 +1201,7 @@ int AkVCam::CmdParserPrivate::removeFormat(const StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Index must be an unsigned integer." << std::endl; std::cerr << "Index must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
auto formats = this->m_ipcBridge.formats(deviceId); auto formats = this->m_ipcBridge.formats(deviceId);
@ -1205,7 +1209,7 @@ int AkVCam::CmdParserPrivate::removeFormat(const StringMap &flags,
if (index >= formats.size()) { if (index >= formats.size()) {
std::cerr << "Index is out of range." << std::endl; std::cerr << "Index is out of range." << std::endl;
return -1; return -ERANGE;
} }
this->m_ipcBridge.removeFormat(deviceId, int(index)); this->m_ipcBridge.removeFormat(deviceId, int(index));
@ -1221,7 +1225,7 @@ int AkVCam::CmdParserPrivate::removeFormats(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1231,7 +1235,7 @@ int AkVCam::CmdParserPrivate::removeFormats(const AkVCam::StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
this->m_ipcBridge.setFormats(deviceId, {}); this->m_ipcBridge.setFormats(deviceId, {});
@ -1257,7 +1261,7 @@ int AkVCam::CmdParserPrivate::loadSettings(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Settings file not provided." << std::endl; std::cerr << "Settings file not provided." << std::endl;
return -1; return -EINVAL;
} }
Settings settings; Settings settings;
@ -1265,7 +1269,7 @@ int AkVCam::CmdParserPrivate::loadSettings(const AkVCam::StringMap &flags,
if (!settings.load(args[1])) { if (!settings.load(args[1])) {
std::cerr << "Settings file not valid." << std::endl; std::cerr << "Settings file not valid." << std::endl;
return -1; return -EIO;
} }
this->loadGenerals(settings); this->loadGenerals(settings);
@ -1287,7 +1291,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (args.size() < 5) { if (args.size() < 5) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1297,7 +1301,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
auto format = VideoFormat::fourccFromString(args[2]); auto format = VideoFormat::fourccFromString(args[2]);
@ -1305,7 +1309,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (!format) { if (!format) {
std::cerr << "Invalid pixel format." << std::endl; std::cerr << "Invalid pixel format." << std::endl;
return -1; return -EINVAL;
} }
auto formats = auto formats =
@ -1315,7 +1319,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (fit == formats.end()) { if (fit == formats.end()) {
std::cerr << "Format not supported." << std::endl; std::cerr << "Format not supported." << std::endl;
return -1; return -EINVAL;
} }
char *p = nullptr; char *p = nullptr;
@ -1324,7 +1328,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Width must be an unsigned integer." << std::endl; std::cerr << "Width must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
p = nullptr; p = nullptr;
@ -1333,7 +1337,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (*p) { if (*p) {
std::cerr << "Height must be an unsigned integer." << std::endl; std::cerr << "Height must be an unsigned integer." << std::endl;
return -1; return -EINVAL;
} }
auto fpsStr = this->flagValue(flags, "stream", "-f"); auto fpsStr = this->flagValue(flags, "stream", "-f");
@ -1347,7 +1351,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (!Fraction::isFraction(fpsStr)) { if (!Fraction::isFraction(fpsStr)) {
std::cerr << "The framerate must be a number or a fraction." << std::endl; std::cerr << "The framerate must be a number or a fraction." << std::endl;
return -1; return -EINVAL;
} }
fps = Fraction(fpsStr).value(); fps = Fraction(fpsStr).value();
@ -1356,7 +1360,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (fps <= 0 || std::isinf(fps)) { if (fps <= 0 || std::isinf(fps)) {
std::cerr << "The framerate is out of range." << std::endl; std::cerr << "The framerate is out of range." << std::endl;
return -1; return -ERANGE;
} }
} }
@ -1365,7 +1369,7 @@ int AkVCam::CmdParserPrivate::stream(const AkVCam::StringMap &flags,
if (!this->m_ipcBridge.deviceStart(deviceId, fmt)) { if (!this->m_ipcBridge.deviceStart(deviceId, fmt)) {
std::cerr << "Can't start stream." << std::endl; std::cerr << "Can't start stream." << std::endl;
return -1; return -EIO;
} }
static bool exit = false; static bool exit = false;
@ -1497,7 +1501,7 @@ int AkVCam::CmdParserPrivate::showControls(const StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Device not provided." << std::endl; std::cerr << "Device not provided." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1507,7 +1511,7 @@ int AkVCam::CmdParserPrivate::showControls(const StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
if (this->m_parseable) { if (this->m_parseable) {
@ -1551,7 +1555,7 @@ int AkVCam::CmdParserPrivate::readControl(const StringMap &flags,
if (args.size() < 3) { if (args.size() < 3) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1561,7 +1565,7 @@ int AkVCam::CmdParserPrivate::readControl(const StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
for (auto &control: this->m_ipcBridge.controls(deviceId)) for (auto &control: this->m_ipcBridge.controls(deviceId))
@ -1611,7 +1615,7 @@ int AkVCam::CmdParserPrivate::readControl(const StringMap &flags,
std::cerr << "'" << args[2] << "' control not available." << std::endl; std::cerr << "'" << args[2] << "' control not available." << std::endl;
return -1; return -ENOSYS;
} }
int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags, int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
@ -1622,7 +1626,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
if (args.size() < 3) { if (args.size() < 3) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto deviceId = args[1]; auto deviceId = args[1];
@ -1632,7 +1636,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
if (dit == devices.end()) { if (dit == devices.end()) {
std::cerr << "'" << deviceId << "' doesn't exists." << std::endl; std::cerr << "'" << deviceId << "' doesn't exists." << std::endl;
return -1; return -ENODEV;
} }
std::map<std::string, int> controls; std::map<std::string, int> controls;
@ -1644,7 +1648,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " is not in the form KEY=VALUE." << " is not in the form KEY=VALUE."
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
auto pair = splitOnce(args[i], "="); auto pair = splitOnce(args[i], "=");
@ -1655,7 +1659,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " is emty." << " is emty."
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
auto key = trimmed(pair.first); auto key = trimmed(pair.first);
@ -1675,7 +1679,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " must be an integer." << " must be an integer."
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
controls[key] = val; controls[key] = val;
@ -1702,7 +1706,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " must be a boolean." << " must be a boolean."
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
break; break;
@ -1723,7 +1727,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " is not valid." << " is not valid."
<< std::endl; << std::endl;
return -1; return -EINVAL;
} }
controls[key] = int(it - control.menu.begin()); controls[key] = int(it - control.menu.begin());
@ -1734,7 +1738,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< " is out of range." << " is out of range."
<< std::endl; << std::endl;
return -1; return -ERANGE;
} }
controls[key] = int(val); controls[key] = int(val);
@ -1760,7 +1764,7 @@ int AkVCam::CmdParserPrivate::writeControls(const StringMap &flags,
<< "." << "."
<< std::endl; << std::endl;
return -1; return -ENOSYS;
} }
} }
@ -1788,7 +1792,7 @@ int AkVCam::CmdParserPrivate::setPicture(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
this->m_ipcBridge.setPicture(args[1]); this->m_ipcBridge.setPicture(args[1]);
@ -1820,7 +1824,7 @@ int AkVCam::CmdParserPrivate::setLogLevel(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto levelStr = args[1]; auto levelStr = args[1];
@ -2103,7 +2107,7 @@ int AkVCam::CmdParserPrivate::hackInfo(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto hack = args[1]; auto hack = args[1];
@ -2113,7 +2117,7 @@ int AkVCam::CmdParserPrivate::hackInfo(const AkVCam::StringMap &flags,
if (dit == hacks.end()) { if (dit == hacks.end()) {
std::cerr << "Unknown hack: " << hack << "." << std::endl; std::cerr << "Unknown hack: " << hack << "." << std::endl;
return -1; return -ENOSYS;
} }
if (this->containsFlag(flags, "hack-info", "-c")) if (this->containsFlag(flags, "hack-info", "-c"))
@ -2135,7 +2139,7 @@ int AkVCam::CmdParserPrivate::hack(const AkVCam::StringMap &flags,
if (args.size() < 2) { if (args.size() < 2) {
std::cerr << "Not enough arguments." << std::endl; std::cerr << "Not enough arguments." << std::endl;
return -1; return -EINVAL;
} }
auto hack = args[1]; auto hack = args[1];
@ -2145,7 +2149,7 @@ int AkVCam::CmdParserPrivate::hack(const AkVCam::StringMap &flags,
if (dit == hacks.end()) { if (dit == hacks.end()) {
std::cerr << "Unknown hack: " << hack << "." << std::endl; std::cerr << "Unknown hack: " << hack << "." << std::endl;
return -1; return -ENOSYS;
} }
bool accepted = this->m_parseable | this->m_ipcBridge.hackIsSafe(hack); bool accepted = this->m_parseable | this->m_ipcBridge.hackIsSafe(hack);
@ -2176,7 +2180,7 @@ int AkVCam::CmdParserPrivate::hack(const AkVCam::StringMap &flags,
if (!accepted) { if (!accepted) {
std::cerr << "Hack not applied." << std::endl; std::cerr << "Hack not applied." << std::endl;
return -1; return -EIO;
} }
StringVector hargs; StringVector hargs;
@ -2346,7 +2350,8 @@ void AkVCam::CmdParserPrivate::createDevice(Settings &settings,
return; return;
} }
auto deviceId = this->m_ipcBridge.addDevice(description); auto deviceId = settings.value("id");
deviceId = this->m_ipcBridge.addDevice(description, deviceId);
auto supportedFormats = auto supportedFormats =
this->m_ipcBridge.supportedPixelFormats(IpcBridge::StreamTypeOutput); this->m_ipcBridge.supportedPixelFormats(IpcBridge::StreamTypeOutput);

View file

@ -176,7 +176,6 @@ namespace AkVCam
bool isBusyFor(const std::string &operation) const; bool isBusyFor(const std::string &operation) const;
bool needsRoot(const std::string &operation) const; bool needsRoot(const std::string &operation) const;
int sudo(int argc, char **argv) const;
/* Hacks */ /* Hacks */

View file

@ -289,14 +289,14 @@ std::string AkVCam::Preferences::addDevice(const std::string &description,
const std::string &deviceId) const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
std::string path; std::string id;
if (deviceId.empty()) if (deviceId.empty())
path = createDevicePath(); id = createDeviceId();
else if (!idDeviceIdTaken(deviceId)) else if (!idDeviceIdTaken(deviceId))
path = deviceId; id = deviceId;
if (path.empty()) if (id.empty())
return {}; return {};
int cameraIndex = readInt("cameras"); int cameraIndex = readInt("cameras");
@ -307,11 +307,11 @@ std::string AkVCam::Preferences::addDevice(const std::string &description,
description); description);
write("cameras." write("cameras."
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
+ ".path", + ".id",
path); id);
sync(); sync();
return path; return id;
} }
std::string AkVCam::Preferences::addCamera(const std::string &description, std::string AkVCam::Preferences::addCamera(const std::string &description,
@ -320,16 +320,16 @@ std::string AkVCam::Preferences::addCamera(const std::string &description,
return addCamera("", description, formats); return addCamera("", description, formats);
} }
std::string AkVCam::Preferences::addCamera(const std::string &path, std::string AkVCam::Preferences::addCamera(const std::string &deviceId,
const std::string &description, const std::string &description,
const std::vector<VideoFormat> &formats) const std::vector<VideoFormat> &formats)
{ {
AkLogFunction(); AkLogFunction();
if (!path.empty() && cameraExists(path)) if (!deviceId.empty() && cameraExists(deviceId))
return {}; return {};
auto path_ = path.empty()? createDevicePath(): path; auto id = deviceId.empty()? createDeviceId(): deviceId;
int cameraIndex = readInt("cameras"); int cameraIndex = readInt("cameras");
write("cameras", cameraIndex + 1); write("cameras", cameraIndex + 1);
write("cameras." write("cameras."
@ -338,8 +338,8 @@ std::string AkVCam::Preferences::addCamera(const std::string &path,
description); description);
write("cameras." write("cameras."
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
+ ".path", + ".id",
path_); id);
write("cameras." write("cameras."
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
+ ".formats", + ".formats",
@ -360,14 +360,14 @@ std::string AkVCam::Preferences::addCamera(const std::string &path,
sync(); sync();
return path_; return id;
} }
void AkVCam::Preferences::removeCamera(const std::string &path) void AkVCam::Preferences::removeCamera(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
AkLogInfo() << "Device: " << path << std::endl; AkLogInfo() << "Device: " << deviceId << std::endl;
int cameraIndex = cameraFromPath(path); int cameraIndex = cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
@ -402,58 +402,58 @@ bool AkVCam::Preferences::idDeviceIdTaken(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
// List device paths in use. // List device IDs in use.
std::vector<std::string> cameraPaths; std::vector<std::string> cameraIds;
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
cameraPaths.push_back(cameraPath(i)); cameraIds.push_back(cameraId(i));
return std::find(cameraPaths.begin(), return std::find(cameraIds.begin(),
cameraPaths.end(), cameraIds.end(),
deviceId) != cameraPaths.end(); deviceId) != cameraIds.end();
} }
std::string AkVCam::Preferences::createDevicePath() std::string AkVCam::Preferences::createDeviceId()
{ {
AkLogFunction(); AkLogFunction();
// List device paths in use. // List device IDs in use.
std::vector<std::string> cameraPaths; std::vector<std::string> cameraIds;
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
cameraPaths.push_back(cameraPath(i)); cameraIds.push_back(cameraId(i));
const int maxId = 64; const int maxId = 64;
for (int i = 0; i < maxId; i++) { for (int i = 0; i < maxId; i++) {
/* There are no rules for device paths in Mac. Just append an /* There are no rules for device IDs in Mac. Just append an
* incremental index to a common prefix. * incremental index to a common prefix.
*/ */
auto path = CMIO_PLUGIN_DEVICE_PREFIX + std::to_string(i); auto id = CMIO_PLUGIN_DEVICE_PREFIX + std::to_string(i);
// Check if the path is being used, if not return it. // Check if the ID is being used, if not return it.
if (std::find(cameraPaths.begin(), if (std::find(cameraIds.begin(),
cameraPaths.end(), cameraIds.end(),
path) == cameraPaths.end()) id) == cameraIds.end())
return path; return id;
} }
return {}; return {};
} }
int AkVCam::Preferences::cameraFromPath(const std::string &path) int AkVCam::Preferences::cameraFromId(const std::string &deviceId)
{ {
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
if (cameraPath(i) == path) if (cameraId(i) == deviceId)
return int(i); return int(i);
return -1; return -1;
} }
bool AkVCam::Preferences::cameraExists(const std::string &path) bool AkVCam::Preferences::cameraExists(const std::string &deviceId)
{ {
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
if (cameraPath(i) == path) if (cameraId(i) == deviceId)
return true; return true;
return false; return false;
@ -480,11 +480,11 @@ void AkVCam::Preferences::cameraSetDescription(size_t cameraIndex,
sync(); sync();
} }
std::string AkVCam::Preferences::cameraPath(size_t cameraIndex) std::string AkVCam::Preferences::cameraId(size_t cameraIndex)
{ {
return readString("cameras." return readString("cameras."
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
+ ".path"); + ".id");
} }
size_t AkVCam::Preferences::formatsCount(size_t cameraIndex) size_t AkVCam::Preferences::formatsCount(size_t cameraIndex)

View file

@ -55,19 +55,19 @@ namespace AkVCam
const std::string &deviceId); const std::string &deviceId);
std::string addCamera(const std::string &description, std::string addCamera(const std::string &description,
const std::vector<VideoFormat> &formats); const std::vector<VideoFormat> &formats);
std::string addCamera(const std::string &path, std::string addCamera(const std::string &deviceId,
const std::string &description, const std::string &description,
const std::vector<VideoFormat> &formats); const std::vector<VideoFormat> &formats);
void removeCamera(const std::string &path); void removeCamera(const std::string &deviceId);
size_t camerasCount(); size_t camerasCount();
bool idDeviceIdTaken(const std::string &deviceId); bool idDeviceIdTaken(const std::string &deviceId);
std::string createDevicePath(); std::string createDeviceId();
int cameraFromPath(const std::string &path); int cameraFromId(const std::string &deviceId);
bool cameraExists(const std::string &path); bool cameraExists(const std::string &deviceId);
std::string cameraDescription(size_t cameraIndex); std::string cameraDescription(size_t cameraIndex);
void cameraSetDescription(size_t cameraIndex, void cameraSetDescription(size_t cameraIndex,
const std::string &description); const std::string &description);
std::string cameraPath(size_t cameraIndex); std::string cameraId(size_t cameraIndex);
size_t formatsCount(size_t cameraIndex); size_t formatsCount(size_t cameraIndex);
VideoFormat cameraFormat(size_t cameraIndex, size_t formatIndex); VideoFormat cameraFormat(size_t cameraIndex, size_t formatIndex);
std::vector<VideoFormat> cameraFormats(size_t cameraIndex); std::vector<VideoFormat> cameraFormats(size_t cameraIndex);

View file

@ -340,7 +340,7 @@ std::vector<std::string> AkVCam::IpcBridge::devices() const
AkLogInfo() << "Devices:" << std::endl; AkLogInfo() << "Devices:" << std::endl;
for (size_t i = 0; i < nCameras; i++) { for (size_t i = 0; i < nCameras; i++) {
auto deviceId = Preferences::cameraPath(i); auto deviceId = Preferences::cameraId(i);
devices.push_back(deviceId); devices.push_back(deviceId);
AkLogInfo() << " " << deviceId << std::endl; AkLogInfo() << " " << deviceId << std::endl;
} }
@ -351,7 +351,7 @@ std::vector<std::string> AkVCam::IpcBridge::devices() const
std::string AkVCam::IpcBridge::description(const std::string &deviceId) const std::string AkVCam::IpcBridge::description(const std::string &deviceId) const
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -363,7 +363,7 @@ void AkVCam::IpcBridge::setDescription(const std::string &deviceId,
const std::string &description) const std::string &description)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraSetDescription(size_t(cameraIndex), description); Preferences::cameraSetDescription(size_t(cameraIndex), description);
@ -392,7 +392,7 @@ AkVCam::PixelFormat AkVCam::IpcBridge::defaultPixelFormat(StreamType type) const
std::vector<AkVCam::VideoFormat> AkVCam::IpcBridge::formats(const std::string &deviceId) const std::vector<AkVCam::VideoFormat> AkVCam::IpcBridge::formats(const std::string &deviceId) const
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -403,7 +403,7 @@ std::vector<AkVCam::VideoFormat> AkVCam::IpcBridge::formats(const std::string &d
void AkVCam::IpcBridge::setFormats(const std::string &deviceId, void AkVCam::IpcBridge::setFormats(const std::string &deviceId,
const std::vector<VideoFormat> &formats) const std::vector<VideoFormat> &formats)
{ {
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraSetFormats(size_t(cameraIndex), formats); Preferences::cameraSetFormats(size_t(cameraIndex), formats);
@ -442,7 +442,7 @@ std::string AkVCam::IpcBridge::broadcaster(const std::string &deviceId) const
std::vector<AkVCam::DeviceControl> AkVCam::IpcBridge::controls(const std::string &deviceId) std::vector<AkVCam::DeviceControl> AkVCam::IpcBridge::controls(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -462,7 +462,7 @@ void AkVCam::IpcBridge::setControls(const std::string &deviceId,
const std::map<std::string, int> &controls) const std::map<std::string, int> &controls)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
@ -602,7 +602,7 @@ void AkVCam::IpcBridge::addFormat(const std::string &deviceId,
int index) int index)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraAddFormat(size_t(cameraIndex), Preferences::cameraAddFormat(size_t(cameraIndex),
@ -613,7 +613,7 @@ void AkVCam::IpcBridge::addFormat(const std::string &deviceId,
void AkVCam::IpcBridge::removeFormat(const std::string &deviceId, int index) void AkVCam::IpcBridge::removeFormat(const std::string &deviceId, int index)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraRemoveFormat(size_t(cameraIndex), Preferences::cameraRemoveFormat(size_t(cameraIndex),
@ -840,15 +840,6 @@ bool AkVCam::IpcBridge::needsRoot(const std::string &operation) const
return it != operations.end() && !this->d->isRoot(); return it != operations.end() && !this->d->isRoot();
} }
int AkVCam::IpcBridge::sudo(int argc, char **argv) const
{
UNUSED(argc);
UNUSED(argv);
std::cerr << "You must run this command with administrator privileges." << std::endl;
return -1;
}
std::vector<std::string> AkVCam::IpcBridge::hacks() const std::vector<std::string> AkVCam::IpcBridge::hacks() const
{ {
std::vector<std::string> hacks; std::vector<std::string> hacks;
@ -977,7 +968,7 @@ void AkVCam::IpcBridgePrivate::updateDevices(xpc_connection_t port, bool propaga
auto devices = xpc_array_create(nullptr, 0); auto devices = xpc_array_create(nullptr, 0);
for (size_t i = 0; i < Preferences::camerasCount(); i++) { for (size_t i = 0; i < Preferences::camerasCount(); i++) {
auto path = Preferences::cameraPath(i); auto path = Preferences::cameraId(i);
auto pathObj = xpc_string_create(path.c_str()); auto pathObj = xpc_string_create(path.c_str());
xpc_array_append_value(devices, pathObj); xpc_array_append_value(devices, pathObj);
AkLogDebug() << "Device " << i << ": " << path << std::endl; AkLogDebug() << "Device " << i << ": " << path << std::endl;
@ -1009,7 +1000,7 @@ void AkVCam::IpcBridgePrivate::deviceUpdate(xpc_connection_t client,
auto nCameras = Preferences::camerasCount(); auto nCameras = Preferences::camerasCount();
for (size_t i = 0; i < nCameras; i++) for (size_t i = 0; i < nCameras; i++)
devices.push_back(Preferences::cameraPath(i)); devices.push_back(Preferences::cameraId(i));
for (auto bridge: this->m_bridges) for (auto bridge: this->m_bridges)
AKVCAM_EMIT(bridge, DevicesChanged, devices) AKVCAM_EMIT(bridge, DevicesChanged, devices)
@ -1085,7 +1076,7 @@ void AkVCam::IpcBridgePrivate::controlsUpdated(xpc_connection_t client,
std::string deviceId = std::string deviceId =
xpc_dictionary_get_string(event, "device"); xpc_dictionary_get_string(event, "device");
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;

View file

@ -387,7 +387,7 @@ bool AkVCam::PluginInterface::createDevice(const std::string &deviceId,
device->connectRemoveListener(this, &PluginInterface::removeListener); device->connectRemoveListener(this, &PluginInterface::removeListener);
this->m_devices.push_back(device); this->m_devices.push_back(device);
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
auto hflip = Preferences::cameraControlValue(cameraIndex, "hflip"); auto hflip = Preferences::cameraControlValue(cameraIndex, "hflip");
auto vflip = Preferences::cameraControlValue(cameraIndex, "vflip"); auto vflip = Preferences::cameraControlValue(cameraIndex, "vflip");
auto scaling = Preferences::cameraControlValue(cameraIndex, "scaling"); auto scaling = Preferences::cameraControlValue(cameraIndex, "scaling");
@ -493,7 +493,7 @@ void AkVCam::PluginInterfacePrivate::updateDevices()
{ {
for (auto &device: this->self->m_devices) { for (auto &device: this->self->m_devices) {
device->setBroadcasting(this->m_ipcBridge.broadcaster(device->deviceId())); device->setBroadcasting(this->m_ipcBridge.broadcaster(device->deviceId()));
auto cameraIndex = Preferences::cameraFromPath(device->deviceId()); auto cameraIndex = Preferences::cameraFromId(device->deviceId());
auto hflip = Preferences::cameraControlValue(cameraIndex, "hflip"); auto hflip = Preferences::cameraControlValue(cameraIndex, "hflip");
auto vflip = Preferences::cameraControlValue(cameraIndex, "vflip"); auto vflip = Preferences::cameraControlValue(cameraIndex, "vflip");
auto scaling = Preferences::cameraControlValue(cameraIndex, "scaling"); auto scaling = Preferences::cameraControlValue(cameraIndex, "scaling");

View file

@ -503,7 +503,7 @@ void AkVCam::ServicePrivate::devicesUpdate(AkVCam::Message *message)
DeviceConfigs configs; DeviceConfigs configs;
for (size_t i = 0; i < Preferences::camerasCount(); i++) { for (size_t i = 0; i < Preferences::camerasCount(); i++) {
auto device = Preferences::cameraPath(i); auto device = Preferences::cameraId(i);
if (this->m_deviceConfigs.count(device) > 0) if (this->m_deviceConfigs.count(device) > 0)
configs[device] = this->m_deviceConfigs[device]; configs[device] = this->m_deviceConfigs[device];

View file

@ -227,14 +227,14 @@ std::string AkVCam::Preferences::addDevice(const std::string &description,
const std::string &deviceId) const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
std::string path; std::string id;
if (deviceId.empty()) if (deviceId.empty())
path = createDevicePath(); id = createDeviceId();
else if (!idDeviceIdTaken(deviceId)) else if (!idDeviceIdTaken(deviceId))
path = deviceId; id = deviceId;
if (path.empty()) if (id.empty())
return {}; return {};
bool ok = true; bool ok = true;
@ -243,9 +243,9 @@ std::string AkVCam::Preferences::addDevice(const std::string &description,
ok &= write("Cameras\\" + std::to_string(cameraIndex) + "\\description", ok &= write("Cameras\\" + std::to_string(cameraIndex) + "\\description",
description, description,
true); true);
ok &= write("Cameras\\" + std::to_string(cameraIndex) + "\\path", path, true); ok &= write("Cameras\\" + std::to_string(cameraIndex) + "\\id", id, true);
return ok? path: std::string(); return ok? id: std::string();
} }
std::string AkVCam::Preferences::addCamera(const std::string &description, std::string AkVCam::Preferences::addCamera(const std::string &description,
@ -254,18 +254,18 @@ std::string AkVCam::Preferences::addCamera(const std::string &description,
return addCamera("", description, formats); return addCamera("", description, formats);
} }
std::string AkVCam::Preferences::addCamera(const std::string &path, std::string AkVCam::Preferences::addCamera(const std::string &deviceId,
const std::string &description, const std::string &description,
const std::vector<VideoFormat> &formats) const std::vector<VideoFormat> &formats)
{ {
AkLogFunction(); AkLogFunction();
if (!path.empty() && cameraExists(path)) if (!deviceId.empty() && cameraExists(deviceId))
return {}; return {};
auto path_ = path.empty()? createDevicePath(): path; auto id = deviceId.empty()? createDeviceId(): deviceId;
if (path.empty()) if (id.empty())
return {}; return {};
bool ok = true; bool ok = true;
@ -278,8 +278,8 @@ std::string AkVCam::Preferences::addCamera(const std::string &path,
true); true);
ok &= write("Cameras\\" ok &= write("Cameras\\"
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
+ "\\path", + "\\id",
path_, id,
true); true);
ok &= write("Cameras\\" ok &= write("Cameras\\"
+ std::to_string(cameraIndex) + std::to_string(cameraIndex)
@ -302,14 +302,14 @@ std::string AkVCam::Preferences::addCamera(const std::string &path,
true); true);
} }
return ok? path_: std::string(); return ok? id: std::string();
} }
bool AkVCam::Preferences::removeCamera(const std::string &path) bool AkVCam::Preferences::removeCamera(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
AkLogInfo() << "Device: " << path << std::endl; AkLogInfo() << "Device: " << deviceId << std::endl;
int cameraIndex = cameraFromPath(path); int cameraIndex = cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return false; return false;
@ -346,48 +346,48 @@ bool AkVCam::Preferences::idDeviceIdTaken(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
// List device paths in use. // List device IDs in use.
std::vector<std::string> cameraPaths; std::vector<std::string> cameraIds;
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
cameraPaths.push_back(cameraPath(i)); cameraIds.push_back(cameraId(i));
// List device CLSIDs in use. // List device CLSIDs in use.
auto cameraClsids = listAllCameras(); auto cameraClsids = listAllCameras();
auto clsid = createClsidFromStr(deviceId); auto clsid = createClsidFromStr(deviceId);
auto pit = std::find(cameraPaths.begin(), cameraPaths.end(), deviceId); auto pit = std::find(cameraIds.begin(), cameraIds.end(), deviceId);
auto cit = std::find(cameraClsids.begin(), cameraClsids.end(), clsid); auto cit = std::find(cameraClsids.begin(), cameraClsids.end(), clsid);
return pit != cameraPaths.end() || cit != cameraClsids.end(); return pit != cameraIds.end() || cit != cameraClsids.end();
} }
std::string AkVCam::Preferences::createDevicePath() std::string AkVCam::Preferences::createDeviceId()
{ {
AkLogFunction(); AkLogFunction();
// List device paths in use. // List device IDs in use.
std::vector<std::string> cameraPaths; std::vector<std::string> cameraIds;
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
cameraPaths.push_back(cameraPath(i)); cameraIds.push_back(cameraId(i));
// List device CLSIDs in use. // List device CLSIDs in use.
auto cameraClsids = listAllCameras(); auto cameraClsids = listAllCameras();
const int maxId = 64; const int maxId = 64;
for (int i = 0; i < maxId; i++) { for (int i = 0; i < maxId; i++) {
/* There are no rules for device paths in Windows. Just append an /* There are no rules for device IDs in Windows. Just append an
* incremental index to a common prefix. * incremental index to a common prefix.
*/ */
auto path = DSHOW_PLUGIN_DEVICE_PREFIX + std::to_string(i); auto id = DSHOW_PLUGIN_DEVICE_PREFIX + std::to_string(i);
auto clsid = createClsidFromStr(path); auto clsid = createClsidFromStr(id);
auto pit = std::find(cameraPaths.begin(), cameraPaths.end(), path); auto pit = std::find(cameraIds.begin(), cameraIds.end(), id);
auto cit = std::find(cameraClsids.begin(), cameraClsids.end(), clsid); auto cit = std::find(cameraClsids.begin(), cameraClsids.end(), clsid);
// Check if the path is being used, if not return it. // Check if the ID is being used, if not return it.
if (pit == cameraPaths.end() && cit == cameraClsids.end()) if (pit == cameraIds.end() && cit == cameraClsids.end())
return path; return id;
} }
return {}; return {};
@ -399,7 +399,7 @@ int AkVCam::Preferences::cameraFromCLSID(const CLSID &clsid)
AkLogDebug() << "CLSID: " << stringFromIid(clsid) << std::endl; AkLogDebug() << "CLSID: " << stringFromIid(clsid) << std::endl;
for (size_t i = 0; i < camerasCount(); i++) { for (size_t i = 0; i < camerasCount(); i++) {
auto cameraClsid = createClsidFromStr(cameraPath(i)); auto cameraClsid = createClsidFromStr(cameraId(i));
if (IsEqualCLSID(cameraClsid, clsid)) if (IsEqualCLSID(cameraClsid, clsid))
return int(i); return int(i);
@ -408,19 +408,19 @@ int AkVCam::Preferences::cameraFromCLSID(const CLSID &clsid)
return -1; return -1;
} }
int AkVCam::Preferences::cameraFromPath(const std::string &path) int AkVCam::Preferences::cameraFromId(const std::string &deviceId)
{ {
for (size_t i = 0; i < camerasCount(); i++) for (size_t i = 0; i < camerasCount(); i++)
if (cameraPath(i) == path) if (cameraId(i) == deviceId)
return int(i); return int(i);
return -1; return -1;
} }
bool AkVCam::Preferences::cameraExists(const std::string &path) bool AkVCam::Preferences::cameraExists(const std::string &deviceId)
{ {
for (DWORD i = 0; i < camerasCount(); i++) for (DWORD i = 0; i < camerasCount(); i++)
if (cameraPath(i) == path) if (cameraId(i) == deviceId)
return true; return true;
return false; return false;
@ -449,11 +449,11 @@ bool AkVCam::Preferences::cameraSetDescription(size_t cameraIndex,
true); true);
} }
std::string AkVCam::Preferences::cameraPath(size_t cameraIndex) std::string AkVCam::Preferences::cameraId(size_t cameraIndex)
{ {
return readString("Cameras\\" return readString("Cameras\\"
+ std::to_string(cameraIndex + 1) + std::to_string(cameraIndex + 1)
+ "\\path", + "\\id",
{}, {},
true); true);
} }

View file

@ -59,20 +59,20 @@ namespace AkVCam
const std::string &deviceId); const std::string &deviceId);
std::string addCamera(const std::string &description, std::string addCamera(const std::string &description,
const std::vector<VideoFormat> &formats); const std::vector<VideoFormat> &formats);
std::string addCamera(const std::string &path, std::string addCamera(const std::string &deviceId,
const std::string &description, const std::string &description,
const std::vector<VideoFormat> &formats); const std::vector<VideoFormat> &formats);
bool removeCamera(const std::string &path); bool removeCamera(const std::string &deviceId);
size_t camerasCount(); size_t camerasCount();
bool idDeviceIdTaken(const std::string &deviceId); bool idDeviceIdTaken(const std::string &deviceId);
std::string createDevicePath(); std::string createDeviceId();
int cameraFromCLSID(const CLSID &clsid); int cameraFromCLSID(const CLSID &clsid);
int cameraFromPath(const std::string &path); int cameraFromId(const std::string &deviceId);
bool cameraExists(const std::string &path); bool cameraExists(const std::string &deviceId);
std::string cameraDescription(size_t cameraIndex); std::string cameraDescription(size_t cameraIndex);
bool cameraSetDescription(size_t cameraIndex, bool cameraSetDescription(size_t cameraIndex,
const std::string &description); const std::string &description);
std::string cameraPath(size_t cameraIndex); std::string cameraId(size_t cameraIndex);
size_t formatsCount(size_t cameraIndex); size_t formatsCount(size_t cameraIndex);
VideoFormat cameraFormat(size_t cameraIndex, size_t formatIndex); VideoFormat cameraFormat(size_t cameraIndex, size_t formatIndex);
std::vector<VideoFormat> cameraFormats(size_t cameraIndex); std::vector<VideoFormat> cameraFormats(size_t cameraIndex);

View file

@ -122,7 +122,7 @@ namespace AkVCam
void listenerRemove (Message *message); void listenerRemove (Message *message);
bool isRoot() const; bool isRoot() const;
int sudo(const std::vector<std::string> &parameters, int exec(const std::vector<std::string> &parameters,
const std::string &directory={}, const std::string &directory={},
bool show=false); bool show=false);
std::string assistant() const; std::string assistant() const;
@ -313,7 +313,7 @@ std::vector<std::string> AkVCam::IpcBridge::devices() const
AkLogInfo() << "Devices:" << std::endl; AkLogInfo() << "Devices:" << std::endl;
for (size_t i = 0; i < nCameras; i++) { for (size_t i = 0; i < nCameras; i++) {
auto deviceId = Preferences::cameraPath(i); auto deviceId = Preferences::cameraId(i);
devices.push_back(deviceId); devices.push_back(deviceId);
AkLogInfo() << " " << deviceId << std::endl; AkLogInfo() << " " << deviceId << std::endl;
} }
@ -324,7 +324,7 @@ std::vector<std::string> AkVCam::IpcBridge::devices() const
std::string AkVCam::IpcBridge::description(const std::string &deviceId) const std::string AkVCam::IpcBridge::description(const std::string &deviceId) const
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -336,7 +336,7 @@ void AkVCam::IpcBridge::setDescription(const std::string &deviceId,
const std::string &description) const std::string &description)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraSetDescription(size_t(cameraIndex), description); Preferences::cameraSetDescription(size_t(cameraIndex), description);
@ -368,7 +368,7 @@ AkVCam::PixelFormat AkVCam::IpcBridge::defaultPixelFormat(StreamType type) const
std::vector<AkVCam::VideoFormat> AkVCam::IpcBridge::formats(const std::string &deviceId) const std::vector<AkVCam::VideoFormat> AkVCam::IpcBridge::formats(const std::string &deviceId) const
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -380,7 +380,7 @@ void AkVCam::IpcBridge::setFormats(const std::string &deviceId,
const std::vector<VideoFormat> &formats) const std::vector<VideoFormat> &formats)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraSetFormats(size_t(cameraIndex), formats); Preferences::cameraSetFormats(size_t(cameraIndex), formats);
@ -415,7 +415,7 @@ std::string AkVCam::IpcBridge::broadcaster(const std::string &deviceId) const
std::vector<AkVCam::DeviceControl> AkVCam::IpcBridge::controls(const std::string &deviceId) std::vector<AkVCam::DeviceControl> AkVCam::IpcBridge::controls(const std::string &deviceId)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
@ -435,7 +435,7 @@ void AkVCam::IpcBridge::setControls(const std::string &deviceId,
const std::map<std::string, int> &controls) const std::map<std::string, int> &controls)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
@ -588,7 +588,7 @@ void AkVCam::IpcBridge::addFormat(const std::string &deviceId,
int index) int index)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraAddFormat(size_t(cameraIndex), Preferences::cameraAddFormat(size_t(cameraIndex),
@ -599,7 +599,7 @@ void AkVCam::IpcBridge::addFormat(const std::string &deviceId,
void AkVCam::IpcBridge::removeFormat(const std::string &deviceId, int index) void AkVCam::IpcBridge::removeFormat(const std::string &deviceId, int index)
{ {
AkLogFunction(); AkLogFunction();
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex >= 0) if (cameraIndex >= 0)
Preferences::cameraRemoveFormat(size_t(cameraIndex), Preferences::cameraRemoveFormat(size_t(cameraIndex),
@ -643,7 +643,7 @@ void AkVCam::IpcBridge::updateDevices()
auto altManager = this->d->alternativeManager(); auto altManager = this->d->alternativeManager();
if (!altManager.empty()) if (!altManager.empty())
this->d->sudo({altManager, "update"}); this->d->exec({altManager, "update"});
DeleteFileA(lockFileName.c_str()); DeleteFileA(lockFileName.c_str());
} }
@ -857,17 +857,6 @@ bool AkVCam::IpcBridge::needsRoot(const std::string &operation) const
return it != operations.end() && !this->d->isRoot(); return it != operations.end() && !this->d->isRoot();
} }
int AkVCam::IpcBridge::sudo(int argc, char **argv) const
{
AkLogFunction();
std::vector<std::string> arguments;
for (int i = 0; i < argc; i++)
arguments.push_back(argv[i]);
return this->d->sudo(arguments);
}
std::vector<std::string> AkVCam::IpcBridge::hacks() const std::vector<std::string> AkVCam::IpcBridge::hacks() const
{ {
std::vector<std::string> hacks; std::vector<std::string> hacks;
@ -978,16 +967,16 @@ void AkVCam::IpcBridgePrivate::updateDeviceSharedProperties()
AkLogFunction(); AkLogFunction();
for (size_t i = 0; i < Preferences::camerasCount(); i++) { for (size_t i = 0; i < Preferences::camerasCount(); i++) {
auto path = Preferences::cameraPath(i); auto deviceId = Preferences::cameraId(i);
Message message; Message message;
message.messageId = AKVCAM_ASSISTANT_MSG_DEVICE_BROADCASTING; message.messageId = AKVCAM_ASSISTANT_MSG_DEVICE_BROADCASTING;
message.dataSize = sizeof(MsgBroadcasting); message.dataSize = sizeof(MsgBroadcasting);
auto data = messageData<MsgBroadcasting>(&message); auto data = messageData<MsgBroadcasting>(&message);
memcpy(data->device, memcpy(data->device,
path.c_str(), deviceId.c_str(),
(std::min<size_t>)(path.size(), MAX_STRING)); (std::min<size_t>)(deviceId.size(), MAX_STRING));
this->m_mainServer.sendMessage(&message); this->m_mainServer.sendMessage(&message);
this->updateDeviceSharedProperties(path, this->updateDeviceSharedProperties(deviceId,
std::string(data->broadcaster)); std::string(data->broadcaster));
} }
} }
@ -1120,7 +1109,7 @@ void AkVCam::IpcBridgePrivate::deviceUpdate(Message *message)
auto nCameras = Preferences::camerasCount(); auto nCameras = Preferences::camerasCount();
for (size_t i = 0; i < nCameras; i++) for (size_t i = 0; i < nCameras; i++)
devices.push_back(Preferences::cameraPath(i)); devices.push_back(Preferences::cameraId(i));
AKVCAM_EMIT(this->self, DevicesChanged, devices) AKVCAM_EMIT(this->self, DevicesChanged, devices)
} }
@ -1174,7 +1163,7 @@ void AkVCam::IpcBridgePrivate::controlsUpdated(Message *message)
AkLogFunction(); AkLogFunction();
auto data = messageData<MsgControlsUpdated>(message); auto data = messageData<MsgControlsUpdated>(message);
std::string deviceId(data->device); std::string deviceId(data->device);
auto cameraIndex = Preferences::cameraFromPath(deviceId); auto cameraIndex = Preferences::cameraFromId(deviceId);
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
@ -1237,7 +1226,7 @@ bool AkVCam::IpcBridgePrivate::isRoot() const
return elevationInfo.TokenIsElevated; return elevationInfo.TokenIsElevated;
} }
int AkVCam::IpcBridgePrivate::sudo(const std::vector<std::string> &parameters, int AkVCam::IpcBridgePrivate::exec(const std::vector<std::string> &parameters,
const std::string &directory, const std::string &directory,
bool show) bool show)
{ {
@ -1276,7 +1265,7 @@ int AkVCam::IpcBridgePrivate::sudo(const std::vector<std::string> &parameters,
execInfo.cbSize = sizeof(SHELLEXECUTEINFO); execInfo.cbSize = sizeof(SHELLEXECUTEINFO);
execInfo.fMask = SEE_MASK_NOCLOSEPROCESS; execInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
execInfo.hwnd = nullptr; execInfo.hwnd = nullptr;
execInfo.lpVerb = "runas"; execInfo.lpVerb = "";
execInfo.lpFile = command.data(); execInfo.lpFile = command.data();
execInfo.lpParameters = params.data(); execInfo.lpParameters = params.data();
execInfo.lpDirectory = directory.data(); execInfo.lpDirectory = directory.data();
@ -1454,13 +1443,15 @@ int AkVCam::IpcBridgePrivate::setServiceUp(const std::vector<std::string> &args)
if (assistant.empty()) if (assistant.empty())
return -1; return -1;
auto result = this->sudo({assistant, "--install"}); auto result = this->exec({assistant, "--install"});
if (result < 0) if (result < 0)
return result; return result;
} }
// Start the service. // Start the service.
if (!this->isServiceRunning()) {
bool result = false; bool result = false;
auto manager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); auto manager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
@ -1477,7 +1468,16 @@ int AkVCam::IpcBridgePrivate::setServiceUp(const std::vector<std::string> &args)
CloseServiceHandle(manager); CloseServiceHandle(manager);
} }
return result? 0: -1; if (!result)
return -1;
}
auto pluginPath = locatePluginPath();
bool ok = Preferences::write("installPath",
realPath(pluginPath + "\\.."),
true);
return ok? 0: -1;
} }
int AkVCam::IpcBridgePrivate::setServiceDown(const std::vector<std::string> &args) int AkVCam::IpcBridgePrivate::setServiceDown(const std::vector<std::string> &args)
@ -1526,7 +1526,7 @@ int AkVCam::IpcBridgePrivate::setServiceDown(const std::vector<std::string> &arg
// Unistall the service. // Unistall the service.
return this->sudo({servicePath, "--uninstall"}); return this->exec({servicePath, "--uninstall"});
} }
AkVCam::Hack::Hack() AkVCam::Hack::Hack()

View file

@ -160,7 +160,7 @@ std::string AkVCam::BaseFilter::deviceId()
if (cameraIndex < 0) if (cameraIndex < 0)
return {}; return {};
return Preferences::cameraPath(size_t(cameraIndex)); return Preferences::cameraId(size_t(cameraIndex));
} }
std::string AkVCam::BaseFilter::broadcaster() std::string AkVCam::BaseFilter::broadcaster()
@ -363,12 +363,12 @@ void AkVCam::BaseFilter::stateChanged(FILTER_STATE state)
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
auto path = Preferences::cameraPath(size_t(cameraIndex)); auto deviceId = Preferences::cameraId(size_t(cameraIndex));
if (state == State_Running) if (state == State_Running)
this->d->m_ipcBridge.addListener(path); this->d->m_ipcBridge.addListener(deviceId);
else else
this->d->m_ipcBridge.removeListener(path); this->d->m_ipcBridge.removeListener(deviceId);
} }
AkVCam::BaseFilterPrivate::BaseFilterPrivate(AkVCam::BaseFilter *self, AkVCam::BaseFilterPrivate::BaseFilterPrivate(AkVCam::BaseFilter *self,
@ -417,9 +417,9 @@ IEnumPins *AkVCam::BaseFilterPrivate::pinsForDevice(const std::string &deviceId)
if (cameraIndex < 0) if (cameraIndex < 0)
return nullptr; return nullptr;
auto path = Preferences::cameraPath(size_t(cameraIndex)); auto id = Preferences::cameraId(size_t(cameraIndex));
if (path.empty() || path != deviceId) if (id.empty() || id != deviceId)
return nullptr; return nullptr;
IEnumPins *pins = nullptr; IEnumPins *pins = nullptr;
@ -437,20 +437,20 @@ void AkVCam::BaseFilterPrivate::updatePins()
if (cameraIndex < 0) if (cameraIndex < 0)
return; return;
auto path = Preferences::cameraPath(size_t(cameraIndex)); auto deviceId = Preferences::cameraId(size_t(cameraIndex));
auto broadcaster = this->m_ipcBridge.broadcaster(path); auto broadcaster = this->m_ipcBridge.broadcaster(deviceId);
AkVCamDevicePinCall(path, AkVCamDevicePinCall(deviceId,
this, this,
setBroadcasting, setBroadcasting,
broadcaster) broadcaster)
auto controlsList = this->m_ipcBridge.controls(path); auto controlsList = this->m_ipcBridge.controls(deviceId);
std::map<std::string, int> controls; std::map<std::string, int> controls;
for (auto &control: controlsList) for (auto &control: controlsList)
controls[control.id] = control.value; controls[control.id] = control.value;
AkVCamDevicePinCall(path, this, setControls, controls) AkVCamDevicePinCall(deviceId, this, setControls, controls)
} }
void AkVCam::BaseFilterPrivate::serverStateChanged(void *userData, void AkVCam::BaseFilterPrivate::serverStateChanged(void *userData,

View file

@ -112,7 +112,7 @@ AkVCam::Pin::Pin(BaseFilter *baseFilter,
this->d->m_mediaTypes = new AkVCam::EnumMediaTypes(formats); this->d->m_mediaTypes = new AkVCam::EnumMediaTypes(formats);
this->d->m_mediaTypes->AddRef(); this->d->m_mediaTypes->AddRef();
auto cameraIndex = Preferences::cameraFromPath(baseFilter->deviceId()); auto cameraIndex = Preferences::cameraFromId(baseFilter->deviceId());
this->d->m_broadcaster = baseFilter->broadcaster(); this->d->m_broadcaster = baseFilter->broadcaster();
this->d->m_controls["hflip"] = this->d->m_controls["hflip"] =
Preferences::cameraControlValue(cameraIndex, "hflip"); Preferences::cameraControlValue(cameraIndex, "hflip");

View file

@ -103,15 +103,15 @@ STDAPI DllRegisterServer()
for (size_t i = 0; i < AkVCam::Preferences::camerasCount(); i++) { for (size_t i = 0; i < AkVCam::Preferences::camerasCount(); i++) {
auto description = AkVCam::Preferences::cameraDescription(i); auto description = AkVCam::Preferences::cameraDescription(i);
auto path = AkVCam::Preferences::cameraPath(i); auto deviceId = AkVCam::Preferences::cameraId(i);
auto clsid = AkVCam::createClsidFromStr(path); auto clsid = AkVCam::createClsidFromStr(deviceId);
AkLogInfo() << "Creating Camera" << std::endl; AkLogInfo() << "Creating Camera" << std::endl;
AkLogInfo() << "\tDescription: " << description << std::endl; AkLogInfo() << "\tDescription: " << description << std::endl;
AkLogInfo() << "\tPath: " << path << std::endl; AkLogInfo() << "\tID: " << deviceId << std::endl;
AkLogInfo() << "\tCLSID: " << AkVCam::stringFromIid(clsid) << std::endl; AkLogInfo() << "\tCLSID: " << AkVCam::stringFromIid(clsid) << std::endl;
ok &= pluginInterface()->createDevice(path, description); ok &= pluginInterface()->createDevice(deviceId, description);
} }
return ok? S_OK: E_UNEXPECTED; return ok? S_OK: E_UNEXPECTED;

View file

@ -259,7 +259,7 @@ unregisterFilter_failed:
AkLogInfo() << "Result: " << stringFromResult(result) << std::endl; AkLogInfo() << "Result: " << stringFromResult(result) << std::endl;
} }
bool AkVCam::PluginInterface::setDevicePath(const std::string &deviceId) const bool AkVCam::PluginInterface::setDeviceId(const std::string &deviceId) const
{ {
AkLogFunction(); AkLogFunction();
@ -279,7 +279,7 @@ bool AkVCam::PluginInterface::setDevicePath(const std::string &deviceId) const
bool ok = false; bool ok = false;
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
goto setDevicePath_failed; goto setDeviceId_failed;
result = RegSetValueExA(hKey, result = RegSetValueExA(hKey,
"DevicePath", "DevicePath",
@ -289,11 +289,11 @@ bool AkVCam::PluginInterface::setDevicePath(const std::string &deviceId) const
DWORD(deviceId.size() + 1)); DWORD(deviceId.size() + 1));
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
goto setDevicePath_failed; goto setDeviceId_failed;
ok = true; ok = true;
setDevicePath_failed: setDeviceId_failed:
if (hKey) if (hKey)
RegCloseKey(hKey); RegCloseKey(hKey);
@ -313,7 +313,7 @@ bool AkVCam::PluginInterface::createDevice(const std::string &deviceId,
if (!this->registerFilter(deviceId, description)) if (!this->registerFilter(deviceId, description))
goto createDevice_failed; goto createDevice_failed;
if (!this->setDevicePath(deviceId)) if (!this->setDeviceId(deviceId))
goto createDevice_failed; goto createDevice_failed;
return true; return true;

View file

@ -44,7 +44,7 @@ namespace AkVCam
const std::string &description) const; const std::string &description) const;
void unregisterFilter(const std::string &deviceId) const; void unregisterFilter(const std::string &deviceId) const;
void unregisterFilter(const CLSID &clsid) const; void unregisterFilter(const CLSID &clsid) const;
bool setDevicePath(const std::string &deviceId) const; bool setDeviceId(const std::string &deviceId) const;
bool createDevice(const std::string &deviceId, bool createDevice(const std::string &deviceId,
const std::string &description); const std::string &description);
void destroyDevice(const std::string &deviceId); void destroyDevice(const std::string &deviceId);

View file

@ -45,6 +45,13 @@ Function InstallPlugin
ExecShellWait "" "sc" "start AkVCamAssistant" SW_HIDE ExecShellWait "" "sc" "start AkVCamAssistant" SW_HIDE
${Next} ${Next}
${If} ${RunningX64}
SetRegView 64
${EndIf}
WriteRegStr HKLM "SOFTWARE\Webcamoid\VirtualCamera" "installPath" "$INSTDIR"
SetRegView default
FunctionEnd FunctionEnd
Function un.InstallPlugin Function un.InstallPlugin