I am using the Logitech C930e webcam in a video chat application created using DirectShow. So far, I could use the raw stream in YUY2 or mJPEG. Anyway, I found that the webcam supports hardware encoding of H264, although the interface is UVC.
I am currently using standard methods to extract possible webcam capture pin configurations, but there is no H264 output there.
void list_cameras {
ICreateDevEnum *pDevEnum = nullptr;
IEnumMoniker *pEnum = nullptr;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
reinterpret_cast<void**>(&pDevEnum));
if (SUCCEEDED(hr)) {
hr = pDevEnum->CreateClassEnumerator(
CLSID_VideoInputDeviceCategory,
&pEnum, 0);
if (hr == S_FALSE) {
return;
}
}
IMoniker *pMoniker = nullptr;
int index = 0;
while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) {
if (cam.device->BindToObject(nullptr, nullptr, IID_IBaseFilter, reinterpret_cast<void**>(&_pCapture)) != S_OK) {
continue;
}
IAMStreamConfig *pConfig = nullptr;
HRESULT hr = _capture->FindInterface(
&PIN_CATEGORY_CAPTURE,
nullptr,
_pCapture,
IID_IAMStreamConfig, reinterpret_cast<void**>(&pConfig));
if (FAILED(hr)) {
continue;
}
int iCount = 0, iSize = 0;
if (pConfig->GetNumberOfCapabilities(&iCount, &iSize) != S_OK) {
continue;
}
AM_MEDIA_TYPE *pmtConfig;
for (int iFormat = 0; iFormat < iCount; iFormat++) {
VIDEO_STREAM_CONFIG_CAPS scc;
if (pConfig->GetStreamCaps(iFormat, &pmtConfig, reinterpret_cast<BYTE*>(&scc)) != S_OK) {
continue;
}
VIDEOINFOHEADER *pVih = new VIDEOINFOHEADER();
*pVih = *reinterpret_cast<VIDEOINFOHEADER *>(pmtConfig->pbFormat);
AM_MEDIA_TYPE mt;
mt = *pmtConfig;
mt.pbFormat = reinterpret_cast<BYTE *>(pVih);
auto fcc = FOURCCMap(pVih->bmiHeader.biCompression);
CameraConfig config = { mt, pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight, 1000 / (static_cast<float>(pVih->AvgTimePerFrame) / 10000), fcc };
if (config.width == 0 || config.height == 0 )
continue;
cam.configurations.push_back(config);
}
_cameras.push_back(cam);
pConfig->Release();
_pCapture->Release();
}
pEnum->Release();
pDevEnum->Release();
}
_cameras is the camera vector, defined as follows:
typedef struct {
DSDevice device;
string name;
vector<CameraConfig> configurations;
int selected;
} Camera;
_pCapture- pointer to the created capture filter.
CameraConfigdefined as follows:
typedef struct {
AM_MEDIA_TYPE _mediaType;
int width;
int height;
float fps;
FOURCCMap compression;
} CameraConfig;
How to implement support for UVC devices? What parameters of the hardware encoder can be controlled?
Thank.