Allow setting a custom device ID (issue #18).
This commit is contained in:
parent
e3bedce3ce
commit
c0d241d0b4
9 changed files with 79 additions and 14 deletions
|
@ -191,6 +191,10 @@ AkVCam::CmdParser::CmdParser()
|
||||||
"DESCRIPTION",
|
"DESCRIPTION",
|
||||||
"Add a new device.",
|
"Add a new device.",
|
||||||
AKVCAM_BIND_FUNC(CmdParserPrivate::addDevice));
|
AKVCAM_BIND_FUNC(CmdParserPrivate::addDevice));
|
||||||
|
this->addFlags("add-device",
|
||||||
|
{"-i", "--id"},
|
||||||
|
"DEVICEID",
|
||||||
|
"Create device as DEVICEID.");
|
||||||
this->addCommand("remove-device",
|
this->addCommand("remove-device",
|
||||||
"DEVICE",
|
"DEVICE",
|
||||||
"Remove a device.",
|
"Remove a device.",
|
||||||
|
@ -843,6 +847,8 @@ int AkVCam::CmdParserPrivate::showDevices(const StringMap &flags,
|
||||||
if (devices.empty())
|
if (devices.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
std::sort(devices.begin(), devices.end());
|
||||||
|
|
||||||
if (this->m_parseable) {
|
if (this->m_parseable) {
|
||||||
for (auto &device: devices)
|
for (auto &device: devices)
|
||||||
std::cout << device << std::endl;
|
std::cout << device << std::endl;
|
||||||
|
@ -875,7 +881,8 @@ int AkVCam::CmdParserPrivate::addDevice(const StringMap &flags,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto deviceId = this->m_ipcBridge.addDevice(args[1]);
|
auto deviceId = this->flagValue(flags, "add-device", "-i");
|
||||||
|
deviceId = this->m_ipcBridge.addDevice(args[1], deviceId);
|
||||||
|
|
||||||
if (deviceId.empty()) {
|
if (deviceId.empty()) {
|
||||||
std::cerr << "Failed to create device." << std::endl;
|
std::cerr << "Failed to create device." << std::endl;
|
||||||
|
|
|
@ -145,7 +145,8 @@ namespace AkVCam
|
||||||
|
|
||||||
/* Server */
|
/* Server */
|
||||||
|
|
||||||
std::string addDevice(const std::string &description);
|
std::string addDevice(const std::string &description,
|
||||||
|
const std::string &deviceId={});
|
||||||
void removeDevice(const std::string &deviceId);
|
void removeDevice(const std::string &deviceId);
|
||||||
void addFormat(const std::string &deviceId,
|
void addFormat(const std::string &deviceId,
|
||||||
const VideoFormat &format,
|
const VideoFormat &format,
|
||||||
|
|
|
@ -285,10 +285,20 @@ void AkVCam::Preferences::sync()
|
||||||
kCFPreferencesAnyHost);
|
kCFPreferencesAnyHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AkVCam::Preferences::addDevice(const std::string &description)
|
std::string AkVCam::Preferences::addDevice(const std::string &description,
|
||||||
|
const std::string &deviceId)
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
auto path = createDevicePath();
|
std::string path;
|
||||||
|
|
||||||
|
if (deviceId.empty())
|
||||||
|
path = createDevicePath();
|
||||||
|
else if (!idDeviceIdTaken(deviceId))
|
||||||
|
path = deviceId;
|
||||||
|
|
||||||
|
if (path.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
int cameraIndex = readInt("cameras");
|
int cameraIndex = readInt("cameras");
|
||||||
write("cameras", cameraIndex + 1);
|
write("cameras", cameraIndex + 1);
|
||||||
write("cameras."
|
write("cameras."
|
||||||
|
@ -388,6 +398,21 @@ size_t AkVCam::Preferences::camerasCount()
|
||||||
return size_t(nCameras);
|
return size_t(nCameras);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AkVCam::Preferences::idDeviceIdTaken(const std::string &deviceId)
|
||||||
|
{
|
||||||
|
AkLogFunction();
|
||||||
|
|
||||||
|
// List device paths in use.
|
||||||
|
std::vector<std::string> cameraPaths;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < camerasCount(); i++)
|
||||||
|
cameraPaths.push_back(cameraPath(i));
|
||||||
|
|
||||||
|
return std::find(cameraPaths.begin(),
|
||||||
|
cameraPaths.end(),
|
||||||
|
deviceId) != cameraPaths.end();
|
||||||
|
}
|
||||||
|
|
||||||
std::string AkVCam::Preferences::createDevicePath()
|
std::string AkVCam::Preferences::createDevicePath()
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
|
@ -401,7 +426,7 @@ std::string AkVCam::Preferences::createDevicePath()
|
||||||
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 paths 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 path = CMIO_PLUGIN_DEVICE_PREFIX + std::to_string(i);
|
||||||
|
|
|
@ -51,7 +51,8 @@ namespace AkVCam
|
||||||
void move(const std::string &keyFrom, const std::string &keyTo);
|
void move(const std::string &keyFrom, const std::string &keyTo);
|
||||||
void moveAll(const std::string &keyFrom, const std::string &keyTo);
|
void moveAll(const std::string &keyFrom, const std::string &keyTo);
|
||||||
void sync();
|
void sync();
|
||||||
std::string addDevice(const std::string &description);
|
std::string addDevice(const std::string &description,
|
||||||
|
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 &path,
|
||||||
|
@ -59,6 +60,7 @@ namespace AkVCam
|
||||||
const std::vector<VideoFormat> &formats);
|
const std::vector<VideoFormat> &formats);
|
||||||
void removeCamera(const std::string &path);
|
void removeCamera(const std::string &path);
|
||||||
size_t camerasCount();
|
size_t camerasCount();
|
||||||
|
bool idDeviceIdTaken(const std::string &deviceId);
|
||||||
std::string createDevicePath();
|
std::string createDevicePath();
|
||||||
int cameraFromPath(const std::string &path);
|
int cameraFromPath(const std::string &path);
|
||||||
bool cameraExists(const std::string &path);
|
bool cameraExists(const std::string &path);
|
||||||
|
|
|
@ -582,11 +582,12 @@ std::string AkVCam::IpcBridge::clientExe(uint64_t pid) const
|
||||||
return {path};
|
return {path};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AkVCam::IpcBridge::addDevice(const std::string &description)
|
std::string AkVCam::IpcBridge::addDevice(const std::string &description,
|
||||||
|
const std::string &deviceId)
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
|
|
||||||
return Preferences::addDevice(description);
|
return Preferences::addDevice(description, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AkVCam::IpcBridge::removeDevice(const std::string &deviceId)
|
void AkVCam::IpcBridge::removeDevice(const std::string &deviceId)
|
||||||
|
|
|
@ -223,10 +223,16 @@ bool AkVCam::Preferences::move(const std::string &keyFrom,
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AkVCam::Preferences::addDevice(const std::string &description)
|
std::string AkVCam::Preferences::addDevice(const std::string &description,
|
||||||
|
const std::string &deviceId)
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
auto path = createDevicePath();
|
std::string path;
|
||||||
|
|
||||||
|
if (deviceId.empty())
|
||||||
|
path = createDevicePath();
|
||||||
|
else if (!idDeviceIdTaken(deviceId))
|
||||||
|
path = deviceId;
|
||||||
|
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
return {};
|
return {};
|
||||||
|
@ -336,6 +342,26 @@ size_t AkVCam::Preferences::camerasCount()
|
||||||
return size_t(nCameras);
|
return size_t(nCameras);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AkVCam::Preferences::idDeviceIdTaken(const std::string &deviceId)
|
||||||
|
{
|
||||||
|
AkLogFunction();
|
||||||
|
|
||||||
|
// List device paths in use.
|
||||||
|
std::vector<std::string> cameraPaths;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < camerasCount(); i++)
|
||||||
|
cameraPaths.push_back(cameraPath(i));
|
||||||
|
|
||||||
|
// List device CLSIDs in use.
|
||||||
|
auto cameraClsids = listAllCameras();
|
||||||
|
|
||||||
|
auto clsid = createClsidFromStr(deviceId);
|
||||||
|
auto pit = std::find(cameraPaths.begin(), cameraPaths.end(), deviceId);
|
||||||
|
auto cit = std::find(cameraClsids.begin(), cameraClsids.end(), clsid);
|
||||||
|
|
||||||
|
return pit != cameraPaths.end() || cit != cameraClsids.end();
|
||||||
|
}
|
||||||
|
|
||||||
std::string AkVCam::Preferences::createDevicePath()
|
std::string AkVCam::Preferences::createDevicePath()
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
|
|
|
@ -55,7 +55,8 @@ namespace AkVCam
|
||||||
bool move(const std::string &keyFrom,
|
bool move(const std::string &keyFrom,
|
||||||
const std::string &keyTo,
|
const std::string &keyTo,
|
||||||
bool global=false);
|
bool global=false);
|
||||||
std::string addDevice(const std::string &description);
|
std::string addDevice(const std::string &description,
|
||||||
|
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 &path,
|
||||||
|
@ -63,6 +64,7 @@ namespace AkVCam
|
||||||
const std::vector<VideoFormat> &formats);
|
const std::vector<VideoFormat> &formats);
|
||||||
bool removeCamera(const std::string &path);
|
bool removeCamera(const std::string &path);
|
||||||
size_t camerasCount();
|
size_t camerasCount();
|
||||||
|
bool idDeviceIdTaken(const std::string &deviceId);
|
||||||
std::string createDevicePath();
|
std::string createDevicePath();
|
||||||
int cameraFromCLSID(const CLSID &clsid);
|
int cameraFromCLSID(const CLSID &clsid);
|
||||||
int cameraFromPath(const std::string &path);
|
int cameraFromPath(const std::string &path);
|
||||||
|
|
|
@ -568,11 +568,12 @@ std::string AkVCam::IpcBridge::clientExe(uint64_t pid) const
|
||||||
return exe;
|
return exe;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AkVCam::IpcBridge::addDevice(const std::string &description)
|
std::string AkVCam::IpcBridge::addDevice(const std::string &description,
|
||||||
|
const std::string &deviceId)
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
|
|
||||||
return Preferences::addDevice(description);
|
return Preferences::addDevice(description, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AkVCam::IpcBridge::removeDevice(const std::string &deviceId)
|
void AkVCam::IpcBridge::removeDevice(const std::string &deviceId)
|
||||||
|
|
|
@ -295,7 +295,7 @@ void AkVCam::Pin::frameReady(const VideoFrame &frame)
|
||||||
void AkVCam::Pin::setPicture(const std::string &picture)
|
void AkVCam::Pin::setPicture(const std::string &picture)
|
||||||
{
|
{
|
||||||
AkLogFunction();
|
AkLogFunction();
|
||||||
AkLogDebug() << "Picture: " << picture;
|
AkLogDebug() << "Picture: " << picture << std::endl;
|
||||||
this->d->m_testFrame = loadPicture(picture);
|
this->d->m_testFrame = loadPicture(picture);
|
||||||
this->d->updateTestFrame();
|
this->d->updateTestFrame();
|
||||||
this->d->m_mutex.lock();
|
this->d->m_mutex.lock();
|
||||||
|
|
Loading…
Reference in a new issue