Skip to content

Commit fe461e8

Browse files
committed
Option to install the filter with a custom name instead of the default 'Unity Video Capture'
1 parent a82e2a0 commit fe461e8

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

Install/InstallCustomName.bat

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@echo off
2+
3+
:: BatchGotAdmin
4+
:-------------------------------------
5+
REM --> Check for permissions
6+
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
7+
8+
REM --> If error flag set, we do not have admin.
9+
if '%errorlevel%' NEQ '0' (
10+
echo Requesting administrative privileges...
11+
goto UACPrompt
12+
) else ( goto gotAdmin )
13+
14+
:UACPrompt
15+
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
16+
set params = %*:"=""
17+
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
18+
19+
"%temp%\getadmin.vbs"
20+
del "%temp%\getadmin.vbs"
21+
exit /B
22+
23+
:gotAdmin
24+
pushd "%CD%"
25+
CD /D "%~dp0"
26+
set /P "UCCAPNAME=Enter a custom filter name to register as (default is 'Unity Video Capture'): "
27+
echo Installing capture device named '%UCCAPNAME%' ...
28+
regsvr32 "UnityCaptureFilter32bit.dll" "/i:UnityCaptureName=%UCCAPNAME%"
29+
regsvr32 "UnityCaptureFilter64bit.dll" "/i:UnityCaptureName=%UCCAPNAME%"
30+
echo "Done"
31+
:--------------------------------------
512 Bytes
Binary file not shown.
1 KB
Binary file not shown.

Source/UnityCaptureFilter.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,10 @@ static const AMOVIESETUP_PIN sudCaptureSourceOut = {
10031003
};
10041004

10051005
struct WStringHolder { wchar_t str[256]; };
1006-
__inline static WStringHolder GetCaptureSourceNameNum(int i, int MaxCapNum)
1006+
__inline static WStringHolder GetCaptureSourceNameNum(const wchar_t* pCaptureSourceName, int i)
10071007
{
10081008
WStringHolder res;
1009-
StringCchPrintfW(res.str, sizeof(res.str)/sizeof(*res.str), (i == 0 ? CaptureSourceName : CaptureSourceName L" #%d"), i + 1);
1009+
StringCchPrintfW(res.str, sizeof(res.str)/sizeof(*res.str), (i == 0 ? L"%s" : L"%s #%d"), pCaptureSourceName, i + 1);
10101010
return res;
10111011
}
10121012

@@ -1044,18 +1044,36 @@ static HRESULT RegisterFilters(BOOL bRegister)
10441044
HRESULT hr = CoInitialize(0);
10451045

10461046
int MaxCapNum = (bRegister ? 1 : SharedImageMemory::MAX_CAPNUM);
1047+
const wchar_t* pCaptureSourceName = CaptureSourceName;
10471048
if (SUCCEEDED(hr) && bRegister)
10481049
{
1049-
for (int i = 0; i != __argc; i++)
1050+
char* CapNumParam = strstr(GetCommandLineA(), "/i:UnityCaptureDevices=");
1051+
if (CapNumParam) MaxCapNum = atoi(CapNumParam + sizeof("/i:UnityCaptureDevices=") - 1);
1052+
1053+
const wchar_t* CapNameParam = wcsstr(GetCommandLineW(), L"/i:UnityCaptureName=");
1054+
if (CapNameParam)
10501055
{
1051-
char* CapNumParam = strstr(__argv[i], "/i:UnityCaptureDevices=");
1052-
if (CapNumParam) MaxCapNum = atoi(CapNumParam + sizeof("/i:UnityCaptureDevices=") - 1);
1056+
//Parse custom filter names from /i:UnityCaptureName=NAME or "/i:UnityCaptureName=NAME NAME" or /i:UnityCaptureName="NAME NAME"
1057+
const wchar_t* CapNameStart = CapNameParam + sizeof("/i:UnityCaptureName=") - 1;
1058+
if (CapNameStart[0] == L'"') CapNameStart++;
1059+
const wchar_t* CapNameEnd = wcsstr(CapNameStart, (CapNameParam[-1] == L'"' || CapNameStart[-1] == L'"' ? L"\"" : L" "));
1060+
if (!CapNameEnd) CapNameEnd = CapNameStart + wcslen(CapNameStart);
1061+
size_t CapNameLen = CapNameEnd - CapNameStart;
1062+
if (CapNameLen > 0 && CapNameLen < 200)
1063+
{
1064+
//Allocate memory to hold the name string (this is never freed until regsvr32 ends, which is soon after this function anyway)
1065+
wchar_t* CustomCaptureSourceName = (wchar_t*)malloc(sizeof(wchar_t) * (CapNameLen + 1));
1066+
memcpy(CustomCaptureSourceName, CapNameStart, sizeof(wchar_t) * CapNameLen);
1067+
CustomCaptureSourceName[CapNameLen] = L'\0';
1068+
pCaptureSourceName = CustomCaptureSourceName;
1069+
}
10531070
}
1071+
10541072
if (MaxCapNum < 1) MaxCapNum = 1;
10551073
if (MaxCapNum > SharedImageMemory::MAX_CAPNUM) MaxCapNum = SharedImageMemory::MAX_CAPNUM;
10561074

10571075
for (int i = 0; SUCCEEDED(hr) && i != MaxCapNum; i++)
1058-
hr = AMovieSetupRegisterServer(GetCLSIDUnityCaptureServiceNum(i), GetCaptureSourceNameNum(i, MaxCapNum).str, achFileName, L"Both", L"InprocServer32");
1076+
hr = AMovieSetupRegisterServer(GetCLSIDUnityCaptureServiceNum(i), GetCaptureSourceNameNum(pCaptureSourceName, i).str, achFileName, L"Both", L"InprocServer32");
10591077
if (SUCCEEDED(hr)) hr = AMovieSetupRegisterServer(CLSID_UnityCaptureProperties, CaptureSourceName L" Configuration", achFileName, L"Both", L"InprocServer32");
10601078
if (FAILED(hr)) MessageBoxA(0, "AMovieSetupRegisterServer failed", "RegisterFilters setup", NULL);
10611079
}
@@ -1076,7 +1094,7 @@ static HRESULT RegisterFilters(BOOL bRegister)
10761094
rf2.rgPins = &sudCaptureSourceOut;
10771095
for (int i = 0; SUCCEEDED(hr) && i != MaxCapNum; i++)
10781096
{
1079-
hr = fm->RegisterFilter(GetCLSIDUnityCaptureServiceNum(i), GetCaptureSourceNameNum(i, MaxCapNum).str, 0, &CLSID_VideoInputDeviceCategory, NULL, &rf2);
1097+
hr = fm->RegisterFilter(GetCLSIDUnityCaptureServiceNum(i), GetCaptureSourceNameNum(pCaptureSourceName, i).str, 0, &CLSID_VideoInputDeviceCategory, NULL, &rf2);
10801098

10811099
//This is needed for Unity and Skype to access the virtual camera
10821100
//Thanks to: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/cd2b9d2d-b961-442d-8946-fdc038fed530/where-to-specify-device-id-in-the-filter?forum=windowsdirectshowdevelopment

0 commit comments

Comments
 (0)