duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
core.cpp File Reference
#include "duvc-ctl/core.h"
#include "duvc-ctl/defs.h"
#include <windows.h>
#include <dshow.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stdexcept>
#include <comdef.h>
#include <strmif.h>
#include <control.h>
#include <uuids.h>
#include <dbt.h>
#include <ks.h>
#include <ksproxy.h>
#include <unordered_map>
#include <memory>
#include <mutex>
Include dependency graph for core.cpp:

Go to the source code of this file.

Classes

class  duvc::com_ptr< T >
 
class  duvc::com_apartment
 
class  duvc::DeviceConnection::com_apartment
 

Namespaces

namespace  duvc
 

Macros

#define NOMINMAX
 
#define CameraControl_Pan   0L
 
#define CameraControl_Tilt   1L
 
#define CameraControl_Roll   2L
 
#define CameraControl_Zoom   3L
 
#define CameraControl_Exposure   4L
 
#define CameraControl_Iris   5L
 
#define CameraControl_Focus   6L
 
#define CameraControl_ScanMode   7L
 
#define CameraControl_Privacy   8L
 
#define CameraControl_PanRelative   9L
 
#define CameraControl_TiltRelative   10L
 
#define CameraControl_RollRelative   11L
 
#define CameraControl_ZoomRelative   12L
 
#define CameraControl_ExposureRelative   13L
 
#define CameraControl_IrisRelative   14L
 
#define CameraControl_FocusRelative   15L
 
#define CameraControl_PanTilt   16L
 
#define CameraControl_PanTiltRelative   17L
 
#define CameraControl_FocusSimple   18L
 
#define CameraControl_DigitalZoom   19L
 
#define CameraControl_DigitalZoomRelative   20L
 
#define CameraControl_BacklightCompensation   21L
 
#define CameraControl_Lamp   22L
 
#define CameraControl_Flags_Auto   0x0001
 
#define CameraControl_Flags_Manual   0x0002
 
#define VideoProcAmp_Brightness   0
 
#define VideoProcAmp_Contrast   1
 
#define VideoProcAmp_Hue   2
 
#define VideoProcAmp_Saturation   3
 
#define VideoProcAmp_Sharpness   4
 
#define VideoProcAmp_Gamma   5
 
#define VideoProcAmp_ColorEnable   6
 
#define VideoProcAmp_WhiteBalance   7
 
#define VideoProcAmp_BacklightCompensation   8
 
#define VideoProcAmp_Gain   9
 
#define VideoProcAmp_Flags_Auto   0x0001
 
#define VideoProcAmp_Flags_Manual   0x0002
 

Functions

static std::string duvc::wide_to_utf8 (const wchar_t *ws)
 
static void duvc::throw_hr (HRESULT hr, const char *where)
 
static LRESULT CALLBACK duvc::device_wndproc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
com_ptr< ICreateDevEnumduvc::create_dev_enum ()
 Create DirectShow device enumerator.
 
com_ptr< IEnumMonikerduvc::enum_video_devices (ICreateDevEnum *dev)
 Enumerate video input devices.
 
static std::wstring duvc::read_prop_bstr (IPropertyBag *bag, const wchar_t *key)
 
std::wstring duvc::read_friendly_name (IMoniker *mon)
 Read friendly name from device moniker.
 
std::wstring duvc::read_device_path (IMoniker *mon)
 Read device path from moniker.
 
static com_ptr< IBaseFilterduvc::bind_to_filter (IMoniker *mon)
 
static com_ptr< IAMCameraControlduvc::get_cam_ctrl (IBaseFilter *f)
 
static com_ptr< IAMVideoProcAmpduvc::get_vproc (IBaseFilter *f)
 
static com_ptr< IKsPropertySetduvc::get_property_set (IBaseFilter *f)
 
bool duvc::is_same_device (const Device &d, const std::wstring &name, const std::wstring &path)
 Check if two device identifiers refer to same device.
 
com_ptr< IBaseFilterduvc::open_device_filter (const Device &dev)
 Create DirectShow filter from device.
 
static long duvc::camprop_to_dshow (CamProp p)
 
static long duvc::vidprop_to_dshow (VidProp p)
 
static long duvc::to_flag (CamMode m, bool is_camera_control)
 
static CamMode duvc::from_flag (long flag, bool is_camera_control)
 
DeviceConnectionduvc::get_cached_connection (const Device &dev)
 
void duvc::release_cached_connection (const Device &dev)
 
void duvc::clear_connection_cache ()
 
void duvc::register_device_change_callback (DeviceChangeCallback callback)
 Register callback for device hotplug events.
 
void duvc::unregister_device_change_callback ()
 Unregister device change callback.
 
bool duvc::is_device_connected (const Device &dev)
 Check if a device is currently connected and accessible.
 
bool duvc::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.
 
bool duvc::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.
 
bool duvc::query_vendor_property_support (const Device &dev, const GUID &property_set, ULONG property_id)
 Query whether device supports a vendor-specific property.
 
std::vector< Deviceduvc::list_devices ()
 Enumerate all available video input devices.
 
bool duvc::get_range (const Device &dev, CamProp prop, PropRange &out)
 Get the valid range for a camera control property.
 
bool duvc::get (const Device &dev, CamProp prop, PropSetting &out)
 Get a camera control property value.
 
bool duvc::set (const Device &dev, CamProp prop, const PropSetting &in)
 Set a camera control property value.
 
bool duvc::get_range (const Device &dev, VidProp prop, PropRange &out)
 Get the valid range for a video processing property.
 
bool duvc::get (const Device &dev, VidProp prop, PropSetting &out)
 Get a video processing property value.
 
bool duvc::set (const Device &dev, VidProp prop, const PropSetting &in)
 Set a video processing property value.
 
const charduvc::to_string (CamProp prop)
 Convert camera property enum to string.
 
const wchar_tduvc::to_wstring (CamProp prop)
 Convert camera property enum to wide string.
 
const charduvc::to_string (VidProp prop)
 Convert video property enum to string.
 
const wchar_tduvc::to_wstring (VidProp prop)
 Convert video property enum to wide string.
 
const charduvc::to_string (CamMode mode)
 Convert camera mode enum to string.
 
const wchar_tduvc::to_wstring (CamMode mode)
 Convert camera mode enum to wide string.
 

Variables

static DeviceChangeCallback duvc::g_device_callback = nullptr
 
static HWND duvc::g_notification_window = nullptr
 
static HDEVNOTIFY duvc::g_device_notify = nullptr
 
static std::mutex duvc::g_cache_mutex
 
static std::unordered_map< std::wstring, std::unique_ptr< DeviceConnection > > duvc::g_connection_cache
 

Macro Definition Documentation

◆ CameraControl_BacklightCompensation

#define CameraControl_BacklightCompensation   21L

Definition at line 51 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_DigitalZoom

#define CameraControl_DigitalZoom   19L

Definition at line 49 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_DigitalZoomRelative

#define CameraControl_DigitalZoomRelative   20L

Definition at line 50 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Exposure

#define CameraControl_Exposure   4L

Definition at line 34 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_ExposureRelative

#define CameraControl_ExposureRelative   13L

Definition at line 43 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Flags_Auto

#define CameraControl_Flags_Auto   0x0001

Definition at line 53 of file core.cpp.

Referenced by duvc::from_flag(), and duvc::to_flag().

◆ CameraControl_Flags_Manual

#define CameraControl_Flags_Manual   0x0002

Definition at line 54 of file core.cpp.

Referenced by duvc::to_flag().

◆ CameraControl_Focus

#define CameraControl_Focus   6L

Definition at line 36 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_FocusRelative

#define CameraControl_FocusRelative   15L

Definition at line 45 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_FocusSimple

#define CameraControl_FocusSimple   18L

Definition at line 48 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Iris

#define CameraControl_Iris   5L

Definition at line 35 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_IrisRelative

#define CameraControl_IrisRelative   14L

Definition at line 44 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Lamp

#define CameraControl_Lamp   22L

Definition at line 52 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Pan

#define CameraControl_Pan   0L

Definition at line 30 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_PanRelative

#define CameraControl_PanRelative   9L

Definition at line 39 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_PanTilt

#define CameraControl_PanTilt   16L

Definition at line 46 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_PanTiltRelative

#define CameraControl_PanTiltRelative   17L

Definition at line 47 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Privacy

#define CameraControl_Privacy   8L

Definition at line 38 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Roll

#define CameraControl_Roll   2L

Definition at line 32 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_RollRelative

#define CameraControl_RollRelative   11L

Definition at line 41 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_ScanMode

#define CameraControl_ScanMode   7L

Definition at line 37 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Tilt

#define CameraControl_Tilt   1L

Definition at line 31 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_TiltRelative

#define CameraControl_TiltRelative   10L

Definition at line 40 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_Zoom

#define CameraControl_Zoom   3L

Definition at line 33 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ CameraControl_ZoomRelative

#define CameraControl_ZoomRelative   12L

Definition at line 42 of file core.cpp.

Referenced by duvc::camprop_to_dshow().

◆ NOMINMAX

#define NOMINMAX

Definition at line 7 of file core.cpp.

◆ VideoProcAmp_BacklightCompensation

#define VideoProcAmp_BacklightCompensation   8

Definition at line 67 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Brightness

#define VideoProcAmp_Brightness   0

Definition at line 59 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_ColorEnable

#define VideoProcAmp_ColorEnable   6

Definition at line 65 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Contrast

#define VideoProcAmp_Contrast   1

Definition at line 60 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Flags_Auto

#define VideoProcAmp_Flags_Auto   0x0001

Definition at line 69 of file core.cpp.

Referenced by duvc::from_flag(), and duvc::to_flag().

◆ VideoProcAmp_Flags_Manual

#define VideoProcAmp_Flags_Manual   0x0002

Definition at line 70 of file core.cpp.

Referenced by duvc::to_flag().

◆ VideoProcAmp_Gain

#define VideoProcAmp_Gain   9

Definition at line 68 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Gamma

#define VideoProcAmp_Gamma   5

Definition at line 64 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Hue

#define VideoProcAmp_Hue   2

Definition at line 61 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Saturation

#define VideoProcAmp_Saturation   3

Definition at line 62 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_Sharpness

#define VideoProcAmp_Sharpness   4

Definition at line 63 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().

◆ VideoProcAmp_WhiteBalance

#define VideoProcAmp_WhiteBalance   7

Definition at line 66 of file core.cpp.

Referenced by duvc::vidprop_to_dshow().