I need to set the exposure on a UVC Camera with Media Foundation in a native C++ application with a resolution of milliseconds.
The standard method for setting exposure on a UVC camera via MediaFoundation appears to be using IAMCameraControl and the CameraControl_Exposure property, using a log2 scaling like this:
ComPtr<IAMCameraControl> videoProc;
HRESULT hr = m_mediaSource.As(&videoProc);
long exposure_val = long(std::roundf(std::log2(exposure_ms/1000.0f)));
hr = videoProc->Set(CameraControl_Exposure, exposure_val, CameraControl_Flags_Manual);
As per the table in the MS docs, this results in a very coarse range of settings in the low end, making it impossible to get accurate exposure control, which is especially important for higher frame rates.
val | Exposure
. | .
-3 | 125ms
-4 | 63ms
-5 | 31ms
-6 | 16ms
-7 | 8ms
-8 | 4ms
-9 | 2ms
. | .
The UVC standard (4.2.2.1.4 Exposure Time (Absolute) Control) defines the exposure resolution as 100us steps, set by the CT_EXPOSURE_TIME_ABSOLUTE_CONTROL
control selector. So in theory, all UVC 1.5 compliant cameras should be capable of being configured at this high resolution of exposure.
I have looked through all the MediaFoundation documentation and cannot find a method for controlling the exposure at this resolution rather than the scaled method. So this seems to be a limitation of MF itself. How can it be done?
A similar question was asked in 2020 but was never properly answered: