webcamoid / akvirtualcamera

akvirtualcamera, virtual camera for Mac and Windows
GNU General Public License v3.0
376 stars 47 forks source link

Non-deterministic creation of devices #18

Closed rse closed 3 years ago

rse commented 3 years ago

I would like to create a Windows application which (with the help of the following batch script AkVCamAssistant.bat and INI file AkVCamAssistant.ini) initially allows the creation of 3 virtual camera devices and later allows to destroy them again:

@echo off
cd /d "%~dp0"

net session >nul 2>&1
if %ERRORLEVEL% GEQ 1 (
    echo ERROR: Administrative rights are required, please re-run this script as Administrator
    goto end
)

set command=%1

if "%command%" == "install" (
    sc query AkVCamAssistant >nul 2>&1
    if not errorlevel 1 (
        echo virtual camera driver already installed
        goto end
    )
    echo installing virtual camera driver
    AkVCamAssistant.exe --install
    timeout /t 2 /nobreak >nul 2>&1
    sc start AkVCamAssistant >nul 2>&1
    timeout /t 2 /nobreak >nul 2>&1
    AkVCamManager.exe load AkVCamAssistant.ini
    AkVCamManager.exe set-picture "%~dp0\camera-placeholder.bmp"
    AkVCamManager.exe update
    goto end
)

if "%command%" == "uninstall" (
    sc query AkVCamAssistant >nul 2>&1
    if errorlevel 1 (
        echo virtual camera driver not installed
        goto end
    )
    echo uninstalling virtual camera driver
    AkVCamManager.exe remove-devices
    AkVCamManager.exe update
    sc stop AkVCamAssistant >nul 2>&1
    timeout /t 2 /nobreak >nul 2>&1
    AkVCamAssistant.exe --uninstall
    timeout /t 2 /nobreak >nul 2>&1
    sc stop AkVCamAssistant >nul 2>&1
    goto end
)

echo USAGE: AkVCamAssistant.bat install
echo USAGE: AkVCamAssistant.bat uninstall
:end
[Cameras]
cameras/size          = 3

cameras/1/description = Ak Virtual Camera 1
cameras/1/formats     = 1, 2, 3, 4

cameras/2/description = Ak Virtual Camera 2
cameras/2/formats     = 1, 2, 3, 4

cameras/3/description = Ak Virtual Camera 3
cameras/3/formats     = 1, 2, 3, 4

[Formats]

formats/size          = 4

formats/1/format      = RGB24, YUY2
formats/1/width       = 480
formats/1/height      = 360
formats/1/fps         = 6, 12, 24, 30, 48, 60

formats/2/format      = RGB24, YUY2
formats/2/width       = 640
formats/2/height      = 480
formats/2/fps         = 6, 12, 24, 30, 48, 60

formats/3/format      = RGB24, YUY2
formats/3/width       = 1280
formats/3/height      = 720
formats/3/fps         = 6, 12, 24, 30, 48, 60

formats/4/format      = RGB24, YUY2
formats/4/width       = 1920
formats/4/height      = 1080
formats/4/fps         = 6, 12, 24, 30, 48, 60

Unfortunately, when running AkVCamAssistant.bat install I always get the three devices, but a AkVCamManager.exe devices shows that the naming of the devices seems to be non-deterministic. Sometimes I get 0/1/2, sometimes 1/2/5, sometimes 1/2/3, etc. In my last attempt I received:

$ ./AkVCamManager.exe devices
+--------------------+---------------------+
| Device             | Description         |
+--------------------+---------------------+
| AkVCamVideoDevice1 | Ak Virtual Camera 1 |
| AkVCamVideoDevice2 | Ak Virtual Camera 2 |
| AkVCamVideoDevice3 | Ak Virtual Camera 3 |
+--------------------+---------------------+

This would be harmless if the other AkVCamManger.exe commands would not expect the device name and instead could also accept the device description (the logical name). As a result, my application first would have to map from the fixed device description to the assigned device names. Especially the AkVCamManager stream command expects the underlying particular assigned device name.

My questions are now:

  1. Is this naming of the devices intended? If I start from scratch (all uninstalled), shouldn't the result be ALWAYS the numbering 0/1/2?
  2. If the assignment of the device names and their numbers is expected to be not fully deterministic, would it be possible to allow the AkVCamManager commands to alternatively also accept the device description and automatically map to the device name? Perhaps if an extra option like -d (for "description") or -m for (for "mapping") is specified, the DEVICE argument is treated as a DESCRIPTION and automatically mapped?
hipersayanX commented 3 years ago

Is this naming of the devices intended? If I start from scratch (all uninstalled), shouldn't the result be ALWAYS the numbering 0/1/2?

Yes, this is a known bug, when deleting the old devices, it's not deleting the files properly, that's the reason because it returns pseudo-random identifiers.

If the assignment of the device names and their numbers is expected to be not fully deterministic, would it be possible to allow the AkVCamManager commands to alternatively also accept the device description and automatically map to the device name? Perhaps if an extra option like -d (for "description") or -m for (for "mapping") is specified, the DEVICE argument is treated as a DESCRIPTION and automatically mapped?

Yes, If it's not much problematic and don't take much time I could add that feature before the final release.

hipersayanX commented 3 years ago

The virtual camera numbering was fixed in the latest commit. I'll try to add a flag for setting the device id, and that's all, no more features for now.

hipersayanX commented 3 years ago

And it's done, custom devices ID feature added and documented. Closing.