duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1#pragma once
2
3#include "defs.h"
4#include <vector>
5#include <functional>
6#include <memory>
7#include <cstdint>
8
9#ifdef _WIN32
10#include <windows.h>
11#endif
12
13namespace duvc {
14
15std::vector<Device> list_devices();
16
17bool get_range(const Device&, CamProp, PropRange&);
18bool get(const Device&, CamProp, PropSetting&);
19bool set(const Device&, CamProp, const PropSetting&);
20
21bool get_range(const Device&, VidProp, PropRange&);
22bool get(const Device&, VidProp, PropSetting&);
23bool set(const Device&, VidProp, const PropSetting&);
24
25const char* to_string(CamProp);
26const char* to_string(VidProp);
27const char* to_string(CamMode);
28
29const wchar_t* to_wstring(CamProp);
30const wchar_t* to_wstring(VidProp);
31const wchar_t* to_wstring(CamMode);
32
33// Device monitoring (hotplug detection)
34using DeviceChangeCallback = std::function<void(bool device_added, const std::wstring& device_path)>;
37bool is_device_connected(const Device& dev);
38
39#ifdef _WIN32
40// Extended vendor-specific controls (Windows only)
44 std::vector<uint8_t> data;
45};
46
47bool get_vendor_property(const Device& dev, const GUID& property_set, ULONG property_id,
48 std::vector<uint8_t>& data);
49bool set_vendor_property(const Device& dev, const GUID& property_set, ULONG property_id,
50 const std::vector<uint8_t>& data);
51bool query_vendor_property_support(const Device& dev, const GUID& property_set, ULONG property_id);
52#endif
53
54// Performance optimizations - Connection pooling
56public:
57 explicit DeviceConnection(const Device& dev);
59
60 bool get(CamProp prop, PropSetting& val);
61 bool set(CamProp prop, const PropSetting& val);
62 bool get(VidProp prop, PropSetting& val);
63 bool set(VidProp prop, const PropSetting& val);
64 bool get_range(CamProp prop, PropRange& range);
65 bool get_range(VidProp prop, PropRange& range);
66
67 bool is_valid() const { return filter_ != nullptr; }
68
69private:
70 class com_apartment;
71 std::unique_ptr<com_apartment> com_;
72 void* filter_; // com_ptr<IBaseFilter> - using void* to avoid forward declaration issues
73 void* cam_ctrl_; // com_ptr<IAMCameraControl>
74 void* vid_proc_; // com_ptr<IAMVideoProcAmp>
75};
76
77// Connection pool management
78DeviceConnection* get_cached_connection(const Device& dev);
79void release_cached_connection(const Device& dev);
81
82} // namespace duvc
RAII wrapper for DirectShow device connections.
Definition core.h:55
bool is_valid() const
Definition core.h:67
DeviceConnection(const Device &dev)
Definition core.cpp:358
bool get(CamProp prop, PropSetting &val)
Definition core.cpp:385
bool set(CamProp prop, const PropSetting &val)
Definition core.cpp:401
bool get_range(CamProp prop, PropRange &range)
Definition core.cpp:441
bool get(const Device &, CamProp, PropSetting &)
Get a camera control property value.
Definition duvc.hpp:63
bool set(const Device &, CamProp, const PropSetting &)
Set a camera control property value.
Definition duvc.hpp:81
bool get_range(const Device &, CamProp, PropRange &)
Get the valid range for a camera control property.
Definition duvc.hpp:95
Definition core.h:13
VidProp
Video processing properties (IAMVideoProcAmp interface)
Definition types.h:50
void clear_connection_cache()
Definition core.cpp:505
std::vector< Device > list_devices()
Enumerate all available video input devices.
Definition core.cpp:626
void unregister_device_change_callback()
Unregister device change callback.
Definition core.cpp:537
void release_cached_connection(const Device &dev)
Definition core.cpp:499
CamMode
Property control mode.
Definition types.h:66
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
const wchar_t * to_wstring(CamProp)
Convert camera property enum to wide string.
Definition core.cpp:707
const char * to_string(CamProp)
Convert camera property enum to string.
Definition core.cpp:678
CamProp
Camera control properties (IAMCameraControl interface)
Definition types.h:18
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
DeviceConnection * get_cached_connection(const Device &dev)
Definition core.cpp:480
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
bool is_device_connected(const Device &dev)
Check if a device is currently connected and accessible.
Definition core.cpp:549
void register_device_change_callback(DeviceChangeCallback callback)
Register callback for device hotplug events.
Definition core.cpp:511
std::function< void(bool device_added, const std::wstring &device_path)> DeviceChangeCallback
Device change callback function type.
Definition core.h:34
Represents a camera device.
Definition types.h:131
Property range and default information.
Definition types.h:92
Property setting with value and control mode.
Definition types.h:74
Vendor-specific property data container.
Definition core.h:41
ULONG property_id
Property ID within set (vendor-defined numeric identifier)
Definition core.h:43
GUID property_set
Property set GUID (vendor-specific extension unit)
Definition core.h:42
std::vector< uint8_t > data
Property data payload (opaque vendor-defined binary data)
Definition core.h:44