@@ -1003,10 +1003,10 @@ static const AMOVIESETUP_PIN sudCaptureSourceOut = {
10031003};
10041004
10051005struct 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