uvc-device.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 
4 #pragma once
5 #include "../backend.h"
6 #include "uvc-types.h"
7 #include "../usb/usb-messenger.h"
8 #include "../usb/usb-enumerator.h"
9 #include "../concurrency.h"
10 #include "../types.h"
11 #include "uvc-parser.h"
12 #include "uvc-streamer.h"
13 
14 #include "stdio.h"
15 #include "stdlib.h"
16 #include <cstring>
17 #include <string>
18 #include <chrono>
19 #include <thread>
20 
21 typedef void(uvc_frame_callback_t)(struct librealsense::platform::frame_object *frame, void *user_ptr);
22 
23 namespace librealsense
24 {
25  namespace platform
26  {
27  std::vector<uvc_device_info> query_uvc_devices_info();
28  std::shared_ptr<uvc_device> create_rsuvc_device(uvc_device_info info);
29 
30  struct profile_and_callback
31  {
32  stream_profile profile;
33  frame_callback callback = nullptr;
34  };
35 
36  class rs_uvc_device : public uvc_device
37  {
38  public:
39  rs_uvc_device(const rs_usb_device& usb_device, const uvc_device_info &info, uint8_t usb_request_count = 2);
40  virtual ~rs_uvc_device();
41 
42  virtual void probe_and_commit(stream_profile profile, frame_callback callback, int buffers = DEFAULT_V4L2_FRAME_BUFFERS) override;
43  virtual void stream_on(std::function<void(const notification& n)> error_handler = [](const notification& n){}) override;
44  virtual void start_callbacks() override;
45  virtual void stop_callbacks() override;
46  virtual void close(stream_profile profile) override;
47 
48  virtual void set_power_state(power_state state) override;
49  virtual power_state get_power_state() const override;
50 
51  virtual void init_xu(const extension_unit& xu) override;
52  virtual bool set_xu(const extension_unit& xu, uint8_t ctrl, const uint8_t* data, int len) override;
53  virtual bool get_xu(const extension_unit& xu, uint8_t ctrl, uint8_t* data, int len) const override;
54  virtual control_range get_xu_range(const extension_unit& xu, uint8_t ctrl, int len) const override;
55 
56  virtual bool get_pu(rs2_option opt, int32_t& value) const override;
57  virtual bool set_pu(rs2_option opt, int32_t value) override;
58  virtual control_range get_pu_range(rs2_option opt) const override;
59 
60  virtual std::vector<stream_profile> get_profiles() const override;
61 
62  virtual void lock() const override;
63  virtual void unlock() const override;
64 
65  virtual std::string get_device_location() const override;
66  virtual usb_spec get_usb_specification() const override;
67 
68  private:
69  friend class source_reader_callback;
70 
71  void close_uvc_device();
72 
73  usb_status probe_stream_ctrl(const std::shared_ptr<uvc_stream_ctrl_t>& control);
74  usb_status get_stream_ctrl_format_size(uvc_format_t format, const std::shared_ptr<uvc_stream_ctrl_t>& control);
75  usb_status query_stream_ctrl(const std::shared_ptr<uvc_stream_ctrl_t>& control, uint8_t probe, int req);
76  std::vector<uvc_format_t> get_available_formats_all() const;
77 
78  bool uvc_get_ctrl(uint8_t unit, uint8_t ctrl, void *data, int len, uvc_req_code req_code) const;
79  bool uvc_set_ctrl(uint8_t unit, uint8_t ctrl, void *data, int len);
80 
81  int32_t rs2_value_translate(uvc_req_code action, rs2_option option, int32_t value) const;
82  void play_profile(stream_profile profile, frame_callback callback);
83  void stop_stream_cleanup(const stream_profile& profile, std::vector<profile_and_callback>::iterator& elem);
84  void check_connection() const;
85 
86  int rs2_option_to_ctrl_selector(rs2_option option, int &unit) const;
87  int32_t get_data_usb(uvc_req_code action, int control, int unit, unsigned int length = sizeof(uint32_t)) const;
88  void set_data_usb(uvc_req_code action, int control, int unit, int value) const;
89 
90  void listen_to_interrupts();
91 
93  power_state _power_state = D3; // power state change is unsupported
94 
95  std::vector<profile_and_callback> _streams;
96 
98  std::vector<stream_profile> _profiles;
99  std::vector<frame_callback> _frame_callbacks;
100 
101  rs_usb_device _usb_device = nullptr;
106 
108  // uvc internal
109  std::shared_ptr<uvc_parser> _parser;
110  std::vector<std::shared_ptr<uvc_streamer>> _streamers;
111  };
112  }
113 }
static const textual_icon lock
Definition: model-views.h:218
static const textual_icon unlock
Definition: model-views.h:237
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
std::shared_ptr< uvc_device > create_rsuvc_device(uvc_device_info info)
Definition: uvc-device.cpp:62
std::vector< uvc_device_info > query_uvc_devices_info()
Definition: uvc-device.cpp:40
std::shared_ptr< usb_request > rs_usb_request
Definition: usb-request.h:41
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
GLfloat value
GLsizei const GLchar *const * string
GLdouble n
Definition: glext.h:1966
unsigned char uint8_t
Definition: stdint.h:78
enum librealsense::platform::_usb_status usb_status
std::vector< stream_profile > _profiles
Definition: uvc-device.h:98
GLenum GLsizei len
Definition: glext.h:3285
def info(name, value, persistent=False)
Definition: test.py:301
std::vector< profile_and_callback > _streams
Definition: uvc-device.h:95
uvc_req_code
Definition: uvc-types.h:123
rs_usb_request_callback _interrupt_callback
Definition: uvc-device.h:104
unsigned int uint32_t
Definition: stdint.h:80
std::shared_ptr< usb_request_callback > rs_usb_request_callback
Definition: usb-request.h:18
GLint GLint GLsizei GLint GLenum format
std::shared_ptr< usb_messenger > rs_usb_messenger
Definition: usb-messenger.h:26
const base::type::char_t * unit
const GLuint * buffers
action
Definition: enums.py:62
std::vector< std::shared_ptr< uvc_streamer > > _streamers
Definition: uvc-device.h:110
std::function< void(stream_profile, frame_object, std::function< void()>)> frame_callback
Definition: backend.h:177
std::vector< frame_callback > _frame_callbacks
Definition: uvc-device.h:99
void( uvc_frame_callback_t)(struct librealsense::platform::frame_object *frame, void *user_ptr)
Definition: uvc-device.h:21
std::shared_ptr< uvc_parser > _parser
Definition: uvc-device.h:109
GLenum GLuint GLenum GLsizei length
signed int int32_t
Definition: stdint.h:77
const uint8_t DEFAULT_V4L2_FRAME_BUFFERS
Definition: backend.h:31
Definition: parser.hpp:150
std::shared_ptr< usb_device > rs_usb_device
Definition: usb-device.h:29


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