34 #include <glog/logging.h>
43 IBaseFilter **pVideoInputFilter) {
46 IKsNodeControl *pUnk =
nullptr;
52 if (*pVideoInputFilter !=
nullptr) {
53 hr = (*pVideoInputFilter)
54 ->QueryInterface(__uuidof(IKsTopologyInfo),
58 LOG(
WARNING) <<
"setVideoSetting - QueryInterface Error";
59 (*pVideoInputFilter)->Release();
60 *pVideoInputFilter =
nullptr;
65 LOG(
ERROR) <<
"pVideoInputFilter should not be NULL";
74 for (UINT
i = 0;
i < uiNumNodes + 1;
i++) {
77 if (guidNodeType == KSNODETYPE_DEV_SPECIFIC) {
80 i, __uuidof(IKsNodeControl), (
void **)&pUnk);
84 hr = pUnk->QueryInterface(__uuidof(IKsControl),
106 ULONG ulBytesReturned;
109 s.Property.Id = selector;
110 s.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
111 s.NodeId = handle->
node;
113 uint8_t *nonConstBuffer =
const_cast<uint8_t *
>(
buffer);
114 return handle->
pKsUnk->KsProperty(
115 reinterpret_cast<PKSPROPERTY
>(&
s),
sizeof(
s),
116 static_cast<LPVOID
>(nonConstBuffer), nbBytes, &ulBytesReturned);
120 ULONG selector, uint8_t *
buffer,
123 ULONG ulBytesReturned;
126 s.Property.Id = selector;
127 s.Property.Flags = KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_TOPOLOGY;
128 s.NodeId = handle->
node;
130 return handle->
pKsUnk->KsProperty(
reinterpret_cast<PKSPROPERTY
>(&
s),
131 sizeof(
s),
static_cast<LPVOID
>(
buffer),
132 nbBytes, &ulBytesReturned);
136 ULONG selector, int16_t
id,
138 uint32_t bufferLength) {
142 <<
" is greater than the maximum size (255) accepted for an id";
150 LOG(
WARNING) <<
"Failed to find node and get control";
154 uint8_t nbWrPacketBytes =
sizeof(
address) + (
id > -1 ? 1 : 0);
155 uint8_t posAddrInPacket =
id > -1 ? 1 : 0;
157 size_t readBytes = 0;
158 size_t readlength = 0;
161 while (readBytes < bufferLength) {
163 packet[0] =
static_cast<uint8_t
>(
id);
165 *(
reinterpret_cast<uint32_t *
>(&packet[posAddrInPacket])) =
166 static_cast<uint32_t
>(addr);
168 ? bufferLength - readBytes
170 packet[nbWrPacketBytes] =
static_cast<uint8_t
>(readlength);
174 LOG(
WARNING) <<
"Failed to set property via UVC extension unit";
180 LOG(
WARNING) <<
"Failed to read a property via UVC extension unit";
183 memcpy(&
data[readBytes], packet, readlength);
184 readBytes += readlength;
192 ULONG selector, int16_t
id,
195 uint32_t bufferLength) {
199 <<
" is greater than the maximum size (255) accepted for an id";
207 LOG(
WARNING) <<
"Failed to find node and get control";
211 uint8_t nbLeadingBytes =
sizeof(
address) + (
id > -1 ? 1 : 0);
212 uint8_t posAddrInPacket =
id > -1 ? 1 : 0;
215 size_t writtenBytes = 0;
218 packet[0] =
static_cast<uint8_t
>(
id);
221 while (writtenBytes < bufferLength) {
222 *(
reinterpret_cast<uint32_t *
>(&packet[posAddrInPacket])) =
address;
224 bufferLength - writtenBytes >
MAX_BUF_SIZE - (nbLeadingBytes + 1)
226 : bufferLength - writtenBytes;
227 packet[nbLeadingBytes] =
static_cast<uint8_t
>(writeLen);
228 memcpy(&packet[nbLeadingBytes + 1],
data + writtenBytes, writeLen);
232 LOG(
WARNING) <<
"Failed to write a packet via UVC extension unit";
235 writtenBytes += writeLen;
236 address +=
static_cast<uint32_t
>(writeLen);
248 uint16_t bufferLength;
251 pVideoInputFilter, uvcControlId, -1, 0,
252 reinterpret_cast<uint8_t *
>(&bufferLength),
sizeof(bufferLength));
254 pVideoInputFilter->Release();
256 <<
"Failed to read size of buffer holding sensors info. Error: "
258 return Status::GENERIC_ERROR;
261 std::unique_ptr<uint8_t[]>
data(
new uint8_t[bufferLength + 1]);
263 -1,
sizeof(bufferLength),
264 data.get(), bufferLength);
266 pVideoInputFilter->Release();
267 LOG(
WARNING) <<
"Failed to read the content of buffer holding sensors "
270 return Status::GENERIC_ERROR;
273 pVideoInputFilter->Release();
275 data[bufferLength] =
'\0';
276 outStr =
reinterpret_cast<char *
>(
data.get());
286 const ULONG uvcSendRequestControl = 1;
292 LOG(
WARNING) <<
"Failed to find node and get control. Error: " << hr;
293 return Status::GENERIC_ERROR;
297 size_t stringLength = requestStr.size();
299 reinterpret_cast<uint8_t *
>(&stringLength),
303 <<
"Failed to write the length of the request string. Error: "
305 return Status::GENERIC_ERROR;
311 size_t writtenBytes = 0;
312 const char *
data = requestStr.data();
314 while (writtenBytes < stringLength) {
317 : stringLength - writtenBytes;
318 memcpy(&packet,
data + writtenBytes, writeLen);
323 LOG(
WARNING) <<
"Failed to write a packet of the send request "
326 return Status::GENERIC_ERROR;
328 writtenBytes += writeLen;
339 const ULONG uvcGetRequestControl = 2;
345 LOG(
WARNING) <<
"Failed to find node and get control. Error: " << hr;
346 return Status::GENERIC_ERROR;
356 <<
"Failed to read the length of the response string. Error: "
358 return Status::GENERIC_ERROR;
360 size_t stringLength =
reinterpret_cast<size_t *
>(packet)[0];
364 size_t readBytes = 0;
365 size_t readlength = 0;
367 while (readBytes < stringLength) {
370 : stringLength - readBytes;
376 <<
"Failed to read a packet of the response string. Error: "
378 return Status::GENERIC_ERROR;
380 responseStr.append(
reinterpret_cast<const char *
>(packet), readlength);
381 readBytes += readlength;