duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
constants.cpp
Go to the documentation of this file.
1
6#ifdef _WIN32
7
8#include <dshow.h>
9#include <duvc-ctl/detail/com_helpers.h>
11#include <ks.h>
12#include <ksproxy.h>
13
14namespace duvc {
15
16using namespace detail;
17
18// Forward declarations
19extern com_ptr<IBaseFilter> open_device_filter(const Device &dev);
20
23 if (FAILED(f->QueryInterface(IID_IKsPropertySet,
24 reinterpret_cast<void **>(props.put())))) {
25 return {};
26 }
27 return props;
28}
29
30bool get_vendor_property(const Device &dev, const GUID &property_set,
31 ULONG property_id, std::vector<uint8_t> &data) {
32 try {
33 com_apartment com;
34 auto filter = open_device_filter(dev);
35 auto props = get_property_set(filter.get());
36 if (!props)
37 return false;
38
39 ULONG bytes_returned = 0;
40 HRESULT hr = props->Get(property_set, property_id, nullptr, 0, nullptr, 0,
41 &bytes_returned);
42 if (FAILED(hr) || bytes_returned == 0)
43 return false;
44
45 data.resize(bytes_returned);
46 hr = props->Get(property_set, property_id, nullptr, 0, data.data(),
47 bytes_returned, &bytes_returned);
48 return SUCCEEDED(hr);
49 } catch (...) {
50 return false;
51 }
52}
53
54bool set_vendor_property(const Device &dev, const GUID &property_set,
55 ULONG property_id, const std::vector<uint8_t> &data) {
56 try {
57 com_apartment com;
58 auto filter = open_device_filter(dev);
59 auto props = get_property_set(filter.get());
60 if (!props)
61 return false;
62
63 HRESULT hr = props->Set(property_set, property_id, nullptr, 0,
64 const_cast<uint8_t *>(data.data()), data.size());
65 return SUCCEEDED(hr);
66 } catch (...) {
67 return false;
68 }
69}
70
71bool query_vendor_property_support(const Device &dev, const GUID &property_set,
72 ULONG property_id) {
73 try {
74 com_apartment com;
75 auto filter = open_device_filter(dev);
76 auto props = get_property_set(filter.get());
77 if (!props)
78 return false;
79
80 ULONG type_support = 0;
81 HRESULT hr =
82 props->QuerySupported(property_set, property_id, &type_support);
83 return SUCCEEDED(hr) &&
85 } catch (...) {
86 return false;
87 }
88}
89
90} // namespace duvc
91
92#endif // _WIN32
Result type that can contain either a value or an error.
Definition result.h:75
Vendor-specific property constants and definitions.
#define KSPROPERTY_SUPPORT_SET
Definition logitech.cpp:18
#define KSPROPERTY_SUPPORT_GET
Definition logitech.cpp:17
Definition core.h:13
com_ptr< IBaseFilter > open_device_filter(const Device &dev)
Create DirectShow filter from device.
Definition core.cpp:260
bool query_vendor_property_support(const Device &dev, const GUID &property_set, ULONG property_id)
Query whether device supports a vendor-specific property.
Definition core.cpp:614
static com_ptr< IKsPropertySet > get_property_set(IBaseFilter *f)
Definition core.cpp:242
bool get_vendor_property(const Device &dev, const GUID &property_set, ULONG property_id, std::vector< uint8_t > &data)
Get vendor-specific property data from device.
Definition core.cpp:584
bool set_vendor_property(const Device &dev, const GUID &property_set, ULONG property_id, const std::vector< uint8_t > &data)
Set vendor-specific property data on device.
Definition core.cpp:602