Interrogate LeapUVC controls

This commit is contained in:
Meta Vens 2026-05-21 20:06:18 +01:00
commit a448628b48
4 changed files with 337 additions and 22 deletions

View file

@ -86,3 +86,37 @@ cadence. The useful stereo IR mode is `640x240 YUY2`, advertised at 115 fps and
currently measured at about 83 fps. The next cut should either tune LeapUVC
controls that affect exposure/frame interval or deliberately rebind to a
WinUSB/libusb UVC path if we decide the Windows UVC stack is the bottleneck.
Follow-up control sweep:
- the probe now reports known LeapUVC-ish controls directly through KS;
- it discards a two-second warm-up before the five-second measurement window;
- `640x240 YUY2` steady-state cadence lands at about 110.7 fps;
- `640x120 YUY2` steady-state cadence lands at about 205.9 fps.
Steady-state `640x240 YUY2` control sweep:
| Scenario | Result |
| --- | ---: |
| baseline | 554 frames / 5.007s = 110.65 fps |
| exposure 10us | 554 frames / 5.006s = 110.68 fps |
| gamma off | 554 frames / 5.002s = 110.76 fps |
| HDR off | 554 frames / 5.003s = 110.73 fps |
| LEDs on | 554 frames / 5.003s = 110.72 fps |
| LEDs off | 554 frames / 5.006s = 110.68 fps |
| gain minimum | 554 frames / 5.007s = 110.64 fps |
| dark-frame interval 0 | 555 frames / 5.009s = 110.80 fps |
| fast combined | 554 frames / 5.001s = 110.77 fps |
Rejected controls:
- digital gain via `KSPROPERTY_VIDEOPROCAMP_BRIGHTNESS = 0` returned
`ERROR_INVALID_PARAMETER`;
- the old LeapUVC FPS-ratio selector through `KSPROPERTY_VIDEOPROCAMP_GAIN`
returned `ERROR_INVALID_PARAMETER`.
Conclusion: the earlier 83 fps number was mostly startup drag inside the short
measurement window. Once the Leap is hot, the useful stereo mode is close to its
advertised cadence through the current KS path. The half-height mode can beat
the PS3 Eyes on raw frame rate, but the PS3 Eyes still win when comparing their
full 320x240 frames against Leap's useful 640x240 stereo stream.

View file

@ -11,6 +11,7 @@
#include <cstdio>
#include <string>
#include <vector>
#include <thread>
namespace
{
@ -90,6 +91,38 @@ struct PinCandidate
GUID subtype{};
};
enum class ControlSet
{
Camera,
VideoProcAmp
};
struct SavedControl
{
ControlSet set;
ULONG id = 0;
LONG value = 0;
ULONG flags = 0;
bool valid = false;
};
struct ControlWrite
{
const char* name = "";
ControlSet set;
ULONG id = 0;
LONG value = 0;
ULONG flags = 0;
};
struct ControlScenario
{
const char* name = "";
std::vector<ControlWrite> writes;
};
std::string lastErrorText();
bool ksProperty(HANDLE handle, void* property, DWORD propertyBytes, void* output, DWORD outputBytes, DWORD* returned = nullptr)
{
DWORD bytes = 0;
@ -109,6 +142,142 @@ bool ksProperty(HANDLE handle, void* property, DWORD propertyBytes, void* output
return ok != FALSE;
}
bool getVideoProcAmp(HANDLE filter, ULONG id, LONG& value, ULONG& flags)
{
KSPROPERTY_VIDEOPROCAMP_S property{};
property.Property.Set = PROPSETID_VIDCAP_VIDEOPROCAMP;
property.Property.Id = id;
property.Property.Flags = KSPROPERTY_TYPE_GET;
if (!ksProperty(filter, &property, sizeof(property), &property, sizeof(property)))
{
return false;
}
value = property.Value;
flags = property.Flags;
return true;
}
bool setVideoProcAmp(HANDLE filter, ULONG id, LONG value, ULONG flags)
{
KSPROPERTY_VIDEOPROCAMP_S property{};
property.Property.Set = PROPSETID_VIDCAP_VIDEOPROCAMP;
property.Property.Id = id;
property.Property.Flags = KSPROPERTY_TYPE_SET;
property.Value = value;
property.Flags = flags;
return ksProperty(filter, &property, sizeof(property), &property, sizeof(property));
}
bool getCameraControl(HANDLE filter, ULONG id, LONG& value, ULONG& flags)
{
KSPROPERTY_CAMERACONTROL_S property{};
property.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
property.Property.Id = id;
property.Property.Flags = KSPROPERTY_TYPE_GET;
if (!ksProperty(filter, &property, sizeof(property), &property, sizeof(property)))
{
return false;
}
value = property.Value;
flags = property.Flags;
return true;
}
bool setCameraControl(HANDLE filter, ULONG id, LONG value, ULONG flags)
{
KSPROPERTY_CAMERACONTROL_S property{};
property.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
property.Property.Id = id;
property.Property.Flags = KSPROPERTY_TYPE_SET;
property.Value = value;
property.Flags = flags;
return ksProperty(filter, &property, sizeof(property), &property, sizeof(property));
}
bool getControl(HANDLE filter, ControlSet set, ULONG id, LONG& value, ULONG& flags)
{
return set == ControlSet::Camera
? getCameraControl(filter, id, value, flags)
: getVideoProcAmp(filter, id, value, flags);
}
bool setControl(HANDLE filter, ControlSet set, ULONG id, LONG value, ULONG flags)
{
return set == ControlSet::Camera
? setCameraControl(filter, id, value, flags)
: setVideoProcAmp(filter, id, value, flags);
}
void printKnownControls(HANDLE filter)
{
const ControlWrite controls[] = {
{"camera.zoom/exposure", ControlSet::Camera, KSPROPERTY_CAMERACONTROL_ZOOM, 0, KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL},
{"camera.exposure", ControlSet::Camera, KSPROPERTY_CAMERACONTROL_EXPOSURE, 0, KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL},
{"procamp.contrast/hdr-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 0, KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL},
{"procamp.gamma", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAMMA, 0, KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL},
{"procamp.brightness/digital-gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_BRIGHTNESS, 0, KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL},
{"procamp.gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAIN, 0, KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL},
{"procamp.whitebalance/dark-frame", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_WHITEBALANCE, 0, KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL},
};
std::printf("known LeapUVC-ish controls:\n");
for (const auto& control : controls)
{
LONG value = 0;
ULONG flags = 0;
if (getControl(filter, control.set, control.id, value, flags))
{
std::printf(" %s: value=%ld flags=0x%lx\n", control.name, value, static_cast<unsigned long>(flags));
}
else
{
std::printf(" %s: unavailable (%s)\n", control.name, lastErrorText().c_str());
}
}
}
std::vector<SavedControl> saveControls(HANDLE filter, const ControlScenario& scenario)
{
std::vector<SavedControl> saved;
for (const auto& write : scenario.writes)
{
bool alreadySaved = false;
for (const auto& entry : saved)
{
if (entry.set == write.set && entry.id == write.id)
{
alreadySaved = true;
break;
}
}
if (alreadySaved)
{
continue;
}
SavedControl entry{};
entry.set = write.set;
entry.id = write.id;
entry.valid = getControl(filter, write.set, write.id, entry.value, entry.flags);
saved.push_back(entry);
}
return saved;
}
void restoreControls(HANDLE filter, const std::vector<SavedControl>& saved)
{
for (const auto& entry : saved)
{
if (entry.valid)
{
setControl(filter, entry.set, entry.id, entry.value, entry.flags);
}
}
}
template <typename T>
bool getPinProperty(HANDLE filter, ULONG pinId, ULONG propertyId, T& value)
{
@ -525,8 +694,10 @@ bool measureCandidate(HANDLE filter, const PinCandidate& candidate, int queueDep
};
const auto start = std::chrono::steady_clock::now();
const auto deadline = start + std::chrono::seconds(5);
const auto measureStart = start + std::chrono::seconds(2);
const auto deadline = measureStart + std::chrono::seconds(5);
std::uint64_t frames = 0;
std::uint64_t warmupFrames = 0;
bool usingPendingReads = false;
for (auto& slot : slots)
@ -542,7 +713,14 @@ bool measureCandidate(HANDLE filter, const PinCandidate& candidate, int queueDep
}
else
{
++frames;
if (std::chrono::steady_clock::now() >= measureStart)
{
++frames;
}
else
{
++warmupFrames;
}
}
}
@ -559,7 +737,14 @@ bool measureCandidate(HANDLE filter, const PinCandidate& candidate, int queueDep
usingPendingReads = true;
break;
}
++frames;
if (std::chrono::steady_clock::now() >= measureStart)
{
++frames;
}
else
{
++warmupFrames;
}
}
}
@ -589,7 +774,14 @@ bool measureCandidate(HANDLE filter, const PinCandidate& candidate, int queueDep
break;
}
++frames;
if (std::chrono::steady_clock::now() >= measureStart)
{
++frames;
}
else
{
++warmupFrames;
}
if (std::chrono::steady_clock::now() < deadline)
{
if (!submit(slot, frames))
@ -610,18 +802,41 @@ bool measureCandidate(HANDLE filter, const PinCandidate& candidate, int queueDep
}
}
const double elapsed = std::chrono::duration<double>(end - start).count();
const double elapsed = std::chrono::duration<double>(end - measureStart).count();
const double fps = static_cast<double>(frames) / elapsed;
std::printf(
"measured: %llu frames in %.3fs = %.2f fps, queueDepth=%d, async=%s, bytes/frame=%lu\n",
"measured: %llu frames in %.3fs = %.2f fps, warmup=%llu, queueDepth=%d, async=%s, bytes/frame=%lu\n",
static_cast<unsigned long long>(frames),
elapsed,
fps,
static_cast<unsigned long long>(warmupFrames),
queueDepth,
usingPendingReads ? "yes" : "no",
static_cast<unsigned long>(frameBytes));
return true;
}
bool measureScenario(HANDLE filter, const PinCandidate& candidate, const ControlScenario& scenario)
{
std::printf("scenario: %s\n", scenario.name);
auto saved = saveControls(filter, scenario);
for (const auto& write : scenario.writes)
{
const bool ok = setControl(filter, write.set, write.id, write.value, write.flags);
std::printf(
" set %s=%ld flags=0x%lx -> %s\n",
write.name,
write.value,
static_cast<unsigned long>(write.flags),
ok ? "ok" : lastErrorText().c_str());
}
std::this_thread::sleep_for(std::chrono::milliseconds(250));
const bool measured = measureCandidate(filter, candidate, 8);
restoreControls(filter, saved);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return measured;
}
}
int main()
@ -658,21 +873,85 @@ int main()
return 3;
}
bool measuredAny = false;
printKnownControls(filter.value);
const PinCandidate* target = nullptr;
const PinCandidate* fastTarget = nullptr;
for (const auto& candidate : candidates)
{
std::printf(
"measuring pin %lu %ldx%ld %ld-bit %s target %.2f fps\n",
static_cast<unsigned long>(candidate.pinId),
candidate.width,
candidate.height,
candidate.bitCount,
fourccOrGuid(candidate.subtype).c_str(),
candidate.interval100ns > 0 ? 10000000.0 / static_cast<double>(candidate.interval100ns) : 0.0);
measuredAny = measureCandidate(filter.value, candidate, 8) || measuredAny;
if (candidate.width == 640 && candidate.height == 240)
{
target = &candidate;
}
else if (candidate.width == 640 && candidate.height == 120)
{
fastTarget = &candidate;
}
}
return measuredAny ? 0 : 4;
if (!target)
{
std::printf("No 640x240 Leap stereo candidate found.\n");
return 4;
}
std::printf(
"targeting pin %lu %ldx%ld %ld-bit %s target %.2f fps\n",
static_cast<unsigned long>(target->pinId),
target->width,
target->height,
target->bitCount,
fourccOrGuid(target->subtype).c_str(),
target->interval100ns > 0 ? 10000000.0 / static_cast<double>(target->interval100ns) : 0.0);
const ULONG camManual = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
const ULONG procManual = KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
const std::vector<ControlScenario> scenarios = {
{"baseline", {}},
{"zoom/exposure 10us", {{"camera.zoom/exposure", ControlSet::Camera, KSPROPERTY_CAMERACONTROL_ZOOM, 10, camManual}}},
{"gamma off", {{"procamp.gamma", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAMMA, 0, procManual}}},
{"hdr off", {{"procamp.contrast/hdr", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 0, procManual}}},
{"leds on", {
{"procamp.contrast/left-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 66, procManual},
{"procamp.contrast/center-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 67, procManual},
{"procamp.contrast/right-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 68, procManual}}},
{"leds off", {
{"procamp.contrast/left-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 2, procManual},
{"procamp.contrast/center-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 3, procManual},
{"procamp.contrast/right-led", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 4, procManual}}},
{"gain minimum", {{"procamp.gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAIN, 16, procManual}}},
{"digital gain minimum", {{"procamp.brightness/digital-gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_BRIGHTNESS, 0, procManual}}},
{"old fps-ratio selector 1000", {{"procamp.gain/fps-ratio", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAIN, 0x8000 | 1000, procManual}}},
{"dark-frame interval 0", {{"procamp.whitebalance/dark-frame", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_WHITEBALANCE, 0, procManual}}},
{"fast combined", {
{"camera.zoom/exposure", ControlSet::Camera, KSPROPERTY_CAMERACONTROL_ZOOM, 10, camManual},
{"procamp.gamma", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAMMA, 0, procManual},
{"procamp.contrast/hdr", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_CONTRAST, 0, procManual},
{"procamp.brightness/digital-gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_BRIGHTNESS, 0, procManual},
{"procamp.gain", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_GAIN, 16, procManual},
{"procamp.whitebalance/dark-frame", ControlSet::VideoProcAmp, KSPROPERTY_VIDEOPROCAMP_WHITEBALANCE, 0, procManual}}},
};
bool measuredAny = false;
for (const auto& scenario : scenarios)
{
measuredAny = measureScenario(filter.value, *target, scenario) || measuredAny;
}
if (fastTarget)
{
std::printf(
"fast-mode check pin %lu %ldx%ld %ld-bit %s target %.2f fps\n",
static_cast<unsigned long>(fastTarget->pinId),
fastTarget->width,
fastTarget->height,
fastTarget->bitCount,
fourccOrGuid(fastTarget->subtype).c_str(),
fastTarget->interval100ns > 0 ? 10000000.0 / static_cast<double>(fastTarget->interval100ns) : 0.0);
measuredAny = measureScenario(filter.value, *fastTarget, scenarios.front()) || measuredAny;
}
return measuredAny ? 0 : 5;
}
std::printf("Leap VID_F182 capture interface not found.\n");

View file

@ -5,3 +5,4 @@
{"ts":"2026-05-21T19:30:00+00:00","type":"verification","status":"ok","note":"Raw PS3 Eye libusb/WinUSB cadence probe measured both cameras simultaneously at 320x240 requested 187 Hz: camera 0 delivered 915 frames in 5.005s (182.81 fps), camera 1 delivered 916 frames in 5.005s (183.01 fps). At 640x480 requested 60 Hz they delivered 58.69 fps and 57.09 fps. Leap remains unmeasured in raw UVC/KS mode."}
{"ts":"2026-05-21T20:05:00+00:00","type":"verification","status":"ok","note":"Native LeapUVC Kernel Streaming probe measured VID_F182 through usbvideo.sys without Media Foundation, DirectShow, OpenCV, or frame processing. Advertised 640x240 YUY2 stereo IR mode is 115 fps; the minimal one-buffer blocking KS read loop delivered 415 frames in 5.003s (82.95 fps). 640x120 delivered 155.40 fps against a 214 fps advertised mode. Next driver cut needs queued KS/AVStream streaming, or an explicit WinUSB/libusb UVC driver rebind decision if usbvideo.sys remains the bottleneck."}
{"ts":"2026-05-21T20:25:00+00:00","type":"verification","status":"ok","note":"LeapUVC KS probe now keeps eight asynchronous NtDeviceIoControlFile reads queued. The path reports async=yes but cadence stays effectively unchanged: 640x240 YUY2 delivered 415 frames in 5.004s (82.93 fps), and 640x120 delivered 777 frames in 5.000s (155.39 fps). The limiting factor is not simply an empty user-mode read queue."}
{"ts":"2026-05-21T20:55:00+00:00","type":"verification","status":"ok","note":"LeapUVC KS control sweep showed the short-window 83 fps result was mostly startup drag. With two seconds of warm-up discarded and eight queued async KS reads, 640x240 YUY2 delivered about 110.7 fps against 115 fps advertised; 640x120 YUY2 delivered 1030 frames in 5.003s (205.87 fps) against 214 fps advertised. Exposure, gamma, HDR/LED, gain, and dark-frame controls are reachable through KS; digital gain=0 and the old FPS-ratio selector are rejected with ERROR_INVALID_PARAMETER."}

View file

@ -82,10 +82,11 @@ current_status:
measured both PS3 Eyes simultaneously at about 183 fps each at 320x240 and
57-59 fps each at 640x480. A native Kernel Streaming LeapUVC probe can pull
frames through usbvideo.sys without Media Foundation, DirectShow, OpenCV, or
frame processing; the useful 640x240 stereo IR mode advertises 115 fps and
currently measures about 83 fps even with eight queued asynchronous KS reads.
frame processing; after discarding a two-second warm-up, the useful 640x240
stereo IR mode advertises 115 fps and currently measures about 110.8 fps
with eight queued asynchronous KS reads. The half-height 640x120 mode
advertises 214 fps and currently measures about 205.9 fps.
next_action: >
Test LeapUVC control tuning for exposure/frame interval, then either turn
the queued KS path into an `IMimirVideoCaptureDriver` or make an explicit
WinUSB/libusb UVC driver-rebind decision if usbvideo.sys remains the
bottleneck.
Turn the warmed, queued Leap KS path into an `IMimirVideoCaptureDriver`,
preserving the direct control hooks for exposure, gamma, HDR/LED, gain, and
dark-frame settings so Aquarium can inspect and tune timing-camera state.