Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions SarTest/SarTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "install.h"
#include "asiohost.h"
#include "wasapi.h"
#include "watch.h"
#include "clockstats.h"

#include <prsht.h>
Expand Down Expand Up @@ -66,6 +67,11 @@ int usage()
" Watch the audio sessions on every active playback endpoint and\n"
" report which processes played and how loud; with --process, fail\n"
" unless that process reached --min-peak (default 0.01).\n"
" SarTest watch [--duration S] [--stop-file <path>] [--poll MS] [--probe MS]\n"
" Log every change in which SAR KS interfaces are enabled and every\n"
" endpoint state change, with timestamps, until S seconds pass or\n"
" the stop file exists. --probe MS also opens every enabled SAR filter\n"
" that often and logs each change in the result.\n"
"\n"
"Layout options: --endpoints N (playback/recording pairs, default 2)\n"
" --channels C (per endpoint, default 2) --prefix <name>\n"
Expand Down Expand Up @@ -855,6 +861,18 @@ int cmdMeter(const Args& args)
return rc;
}

int cmdWatch(const Args& args)
{
WatchOptions options;

options.durationSeconds = args.getDouble(L"duration", 60.0);
options.stopFile = args.get(L"stop-file", L"");
options.pollMs = args.getInt(L"poll", 20);
options.probeMs = args.getInt(L"probe", 0);
writeResults(args, runWatch(options));
return 0;
}

} // namespace

int wmain(int argc, wchar_t **argv)
Expand Down Expand Up @@ -896,6 +914,8 @@ int wmain(int argc, wchar_t **argv)
rc = cmdEndpointNames(args);
} else if (args.command == L"meter") {
rc = cmdMeter(args);
} else if (args.command == L"watch") {
rc = cmdWatch(args);
} else {
rc = usage();
}
Expand Down
4 changes: 3 additions & 1 deletion SarTest/SarTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>setupapi.lib;newdev.lib;shlwapi.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>setupapi.lib;cfgmgr32.lib;newdev.lib;shlwapi.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>

</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -97,12 +97,14 @@
<ClCompile Include="common.cpp" />
<ClCompile Include="install.cpp" />
<ClCompile Include="wasapi.cpp" />
<ClCompile Include="watch.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="asiohost.h" />
<ClInclude Include="common.h" />
<ClInclude Include="install.h" />
<ClInclude Include="wasapi.h" />
<ClInclude Include="watch.h" />
<ClInclude Include="..\SarAsio\tinyasio.h" />
<ClInclude Include="..\SarTestClock\clockstats.h" />
</ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions SarTest/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "install.h"

#include <setupapi.h>
#include <cfgmgr32.h>
#include <newdev.h>
#include <shlobj.h>
#include <shlwapi.h>
Expand Down Expand Up @@ -156,6 +157,32 @@ static int visitSarDeviceNodes(bool remove)
return found;
}

std::wstring sarDeviceInstanceId()
{
HDEVINFO set = SetupDiGetClassDevsW(&kMediaClassGuid, nullptr, nullptr, DIGCF_PRESENT);
std::wstring result;

if (set == INVALID_HANDLE_VALUE) {
return result;
}

SP_DEVINFO_DATA data = {};

data.cbSize = sizeof(data);

for (DWORD i = 0; result.empty() && SetupDiEnumDeviceInfo(set, i, &data); ++i) {
wchar_t id[MAX_DEVICE_ID_LEN] = {};

if (hasSarHardwareId(set, &data) &&
SetupDiGetDeviceInstanceIdW(set, &data, id, MAX_DEVICE_ID_LEN, nullptr)) {
result = id;
}
}

SetupDiDestroyDeviceInfoList(set);
return result;
}

bool deviceNodeExists()
{
return visitSarDeviceNodes(false) > 0;
Expand Down
2 changes: 2 additions & 0 deletions SarTest/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ bool writeDriverConfig(

// Software device node for the SAR driver, matching the INF's hardware ID.
bool deviceNodeExists();
// Device instance ID of the present SAR device node; empty if there is none.
std::wstring sarDeviceInstanceId();
bool createDeviceNode();
bool removeDeviceNode();

Expand Down
Loading
Loading