mf-uvc.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include "../backend.h"
6 #include "win/win-helpers.h"
7 
8 #include <mfidl.h>
9 #include <mfreadwrite.h>
10 #include <atlcomcli.h>
11 #include <strmif.h>
12 #include <Ks.h>
13 #include <ksproxy.h>
14 #include <unordered_map>
15 #include <mutex>
16 #include <atomic>
17 
18 #ifndef KSCATEGORY_SENSOR_CAMERA
19 DEFINE_GUIDSTRUCT("24E552D7-6523-47F7-A647-D3465BF1F5CA", KSCATEGORY_SENSOR_CAMERA);
20 #define KSCATEGORY_SENSOR_CAMERA DEFINE_GUIDNAMED(KSCATEGORY_SENSOR_CAMERA)
21 #endif // !KSCATEGORY_SENSOR_CAMERA
22 
23 
24 static const std::vector<std::vector<std::pair<GUID, GUID>>> attributes_params = {
25  {
26  { MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID },
27  { MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY, KSCATEGORY_SENSOR_CAMERA }
28  },
29  {
30  { MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID }
31  },
32 };
33 
34 namespace librealsense
35 {
36  namespace platform
37  {
38  class wmf_backend;
39 
41  {
44  };
45 
46  typedef std::function<void(const uvc_device_info&, IMFActivate*)>
48 
49  typedef struct frame_rate {
50  unsigned int denominator;
51  unsigned int numerator;
52  } frame_rate;
53 
54  typedef struct mf_profile {
59  } mf_profile;
60 
61  template <class T>
62  static void safe_release(T &ppT)
63  {
64  if (ppT)
65  {
66  ppT.Release();
67  ppT = NULL;
68  }
69  }
70 
71  class wmf_uvc_device : public std::enable_shared_from_this<wmf_uvc_device>,
72  public uvc_device
73  {
74  public:
75  wmf_uvc_device(const uvc_device_info& info, std::shared_ptr<const wmf_backend> backend);
76  ~wmf_uvc_device();
77 
78  void probe_and_commit(stream_profile profile, frame_callback callback, int buffers) override;
79  void stream_on(std::function<void(const notification& n)> error_handler = [](const notification& n){}) override;
80  void start_callbacks() override;
81  void stop_callbacks() override;
82  void close(stream_profile profile) override;
83  void set_power_state(power_state state) override;
84  power_state get_power_state() const override { return _power_state; }
85  std::vector<stream_profile> get_profiles() const override;
86 
87  static bool is_connected(const uvc_device_info& info);
88  static void foreach_uvc_device(enumeration_callback action);
89 
90  void init_xu(const extension_unit& xu) override;
91  bool set_xu(const extension_unit& xu, uint8_t ctrl, const uint8_t* data, int len) override;
92  bool get_xu(const extension_unit& xu, uint8_t ctrl, uint8_t* data, int len) const override;
93  control_range get_xu_range(const extension_unit& xu, uint8_t ctrl, int len) const override;
94 
95  bool get_pu(rs2_option opt, int32_t& value) const override;
96  bool set_pu(rs2_option opt, int value) override;
97  control_range get_pu_range(rs2_option opt) const override;
98 
99  void lock() const override { _systemwide_lock.lock(); }
100  void unlock() const override { _systemwide_lock.unlock(); }
101 
102  std::string get_device_location() const override { return _location; }
103  usb_spec get_usb_specification() const override { return _device_usb_spec; }
104  IAMVideoProcAmp* get_video_proc() const;
105  IAMCameraControl* get_camera_control() const;
106 
107  private:
109 
110  void play_profile(stream_profile profile, frame_callback callback);
111  void stop_stream_cleanup(const stream_profile& profile, std::vector<profile_and_callback>::iterator& elem);
112  void flush(int sIndex);
113  void check_connection() const;
114  void close_all();
115  IKsControl* get_ks_control(const extension_unit& xu) const;
116  CComPtr<IMFAttributes> create_device_attrs();
117  CComPtr<IMFAttributes> create_reader_attrs();
118  void foreach_profile(std::function<void(const mf_profile& profile, CComPtr<IMFMediaType> media_type, bool& quit)> action) const;
119 
120  void set_d0();
121  void set_d3();
122 
123  // Don't move the position of wmf_backend member. This object must be destroyed only after COM objects.
124  std::shared_ptr<const wmf_backend> _backend;
125 
127  power_state _power_state = D3;
128 
129  CComPtr<IMFSourceReader> _reader = nullptr;
130  CComPtr<IMFMediaSource> _source = nullptr;
131  CComPtr<IMFAttributes> _device_attrs = nullptr;
132  CComPtr<IMFAttributes> _reader_attrs = nullptr;
133 
134  CComPtr<IAMCameraControl> _camera_control = nullptr;
135  CComPtr<IAMVideoProcAmp> _video_proc = nullptr;
136  std::unordered_map<int, CComPtr<IKsControl>> _ks_controls;
137 
140  HRESULT _readsample_result = S_OK;
141 
143  std::vector<profile_and_callback> _streams;
144  std::mutex _streams_mutex;
145 
150  std::vector<stream_profile> _profiles;
151  std::vector<frame_callback> _frame_callbacks;
152  bool _streaming = false;
153  std::atomic<bool> _is_started = false;
154  std::wstring _device_id;
155  };
156 
157  class source_reader_callback : public IMFSourceReaderCallback
158  {
159  public:
160  explicit source_reader_callback(std::weak_ptr<wmf_uvc_device> owner) : _owner(owner)
161  {
162  };
164  STDMETHODIMP QueryInterface(REFIID iid, void** ppv) override;
165  STDMETHODIMP_(ULONG) AddRef() override;
166  STDMETHODIMP_(ULONG) Release() override;
167  STDMETHODIMP OnReadSample(HRESULT /*hrStatus*/,
168  DWORD dwStreamIndex,
169  DWORD /*dwStreamFlags*/,
170  LONGLONG /*llTimestamp*/,
171  IMFSample *sample) override;
172  STDMETHODIMP OnEvent(DWORD /*sidx*/, IMFMediaEvent* /*event*/) override;
173  STDMETHODIMP OnFlush(DWORD) override;
174  private:
175  std::weak_ptr<wmf_uvc_device> _owner;
176  long _refCount = 0;
177  };
178 
179  }
180 }
std::unordered_map< int, CComPtr< IKsControl > > _ks_controls
Definition: mf-uvc.h:136
std::weak_ptr< wmf_uvc_device > _owner
Definition: mf-uvc.h:175
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
manual_reset_event _has_started
Definition: mf-uvc.h:139
GLfloat value
DEFINE_GUIDSTRUCT("24E552D7-6523-47F7-A647-D3465BF1F5CA", KSCATEGORY_SENSOR_CAMERA)
power_state get_power_state() const override
Definition: mf-uvc.h:84
unsigned short uint16_t
Definition: stdint.h:79
GLsizei const GLchar *const * string
const uvc_device_info _info
Definition: mf-uvc.h:126
GLdouble n
Definition: glext.h:1966
unsigned char uint8_t
Definition: stdint.h:78
void unlock() const override
Definition: mf-uvc.h:100
GLenum GLsizei len
Definition: glext.h:3285
std::string get_device_location() const override
Definition: mf-uvc.h:102
def info(name, value, persistent=False)
Definition: test.py:301
#define KSCATEGORY_SENSOR_CAMERA
Definition: mf-uvc.h:20
def is_connected()
Definition: acroname.py:89
unsigned int uint32_t
Definition: stdint.h:80
static void safe_release(T &ppT)
Definition: mf-uvc.h:62
struct librealsense::platform::mf_profile mf_profile
STDMETHODIMP_(ULONG) source_reader_callback
Definition: mf-uvc.cpp:155
const GLuint * buffers
action
Definition: enums.py:62
std::function< void(stream_profile, frame_object, std::function< void()>)> frame_callback
Definition: backend.h:177
std::vector< frame_callback > _frame_callbacks
Definition: mf-uvc.h:151
std::vector< profile_and_callback > _streams
Definition: mf-uvc.h:143
std::vector< stream_profile > _profiles
Definition: mf-uvc.h:150
#define NULL
Definition: tinycthread.c:47
signed int int32_t
Definition: stdint.h:77
struct librealsense::platform::frame_rate frame_rate
void lock() const override
Definition: mf-uvc.h:99
std::shared_ptr< const wmf_backend > _backend
Definition: mf-uvc.h:124
source_reader_callback(std::weak_ptr< wmf_uvc_device > owner)
Definition: mf-uvc.h:160
static const std::vector< std::vector< std::pair< GUID, GUID > > > attributes_params
Definition: mf-uvc.h:24
usb_spec get_usb_specification() const override
Definition: mf-uvc.h:103
Definition: parser.hpp:150
std::function< void(const uvc_device_info &, IMFActivate *)> enumeration_callback
Definition: mf-uvc.h:47


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21