35 #include <sys/ioctl.h> 36 #include <linux/usb/video.h> 37 #include <linux/uvcvideo.h> 38 #include <linux/videodev2.h> 43 #ifdef V4L2_META_FMT_UVC 46 #pragma message ( "\nLibrealsense notification: V4L2_META_FMT_UVC was not defined, adding metadata constructs") 52 #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') 54 #ifndef V4L2_CAP_META_CAPTURE 55 #define V4L2_CAP_META_CAPTURE 0x00800000 56 #endif // V4L2_CAP_META_CAPTURE 58 #endif // V4L2_META_FMT_UVC 60 #ifndef V4L2_META_FMT_D4XX 61 #define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') 66 #define LOG_DEBUG_V4L(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false) 68 #define LOG_DEBUG_V4L(...) 113 static std::map<std::string, std::recursive_mutex>
_dev_mutex;
118 static int xioctl(
int fh,
unsigned long request,
void *
arg);
125 void prepare_for_streaming(
int fd);
129 void attach_buffer(
const v4l2_buffer&
buf);
131 void detach_buffer();
133 void request_next_frame(
int fd,
bool force=
false);
151 bool _must_enqueue =
false;
167 if (_data_buf && (!_managed))
171 if (
xioctl(_file_desc, (
int)VIDIOC_QBUF, &_dq_buf) < 0)
173 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) guard failed for fd " << std::dec << _file_desc);
174 if (
xioctl(_file_desc, (
int)VIDIOC_DQBUF, &_dq_buf) >= 0)
176 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) Re-enqueue succeeded for fd " << std::dec << _file_desc);
177 if (
xioctl(_file_desc, (
int)VIDIOC_QBUF, &_dq_buf) < 0)
178 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) re-deque failed for fd " << std::dec << _file_desc);
180 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) re-deque succeeded for fd " << std::dec << _file_desc);
183 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) Re-enqueue failed for fd " << std::dec << _file_desc);
186 LOG_DEBUG_V4L(
"Enqueue (e) buf " << std::dec << _dq_buf.index <<
" for fd " << _file_desc);
191 std::shared_ptr<platform::buffer> _data_buf=
nullptr;
192 v4l2_buffer _dq_buf{};
204 _mmap_bufs(memory_mapped_buf)
209 void request_next_frame();
211 v4l2_buffer
buf= v4l2_buffer(),
212 std::shared_ptr<platform::buffer> data_buf=
nullptr);
218 { _md_start = md_start; _md_size = md_size; }
219 void set_md_from_video_node(
bool compressed);
220 bool verify_vd_md_sync()
const;
221 bool md_node_present()
const;
223 std::array<kernel_buf_guard, e_max_kernel_buf_type>&
get_buffers()
232 std::array<kernel_buf_guard, e_max_kernel_buf_type>
buffers;
237 virtual void capture_loop() = 0;
239 virtual bool has_metadata()
const = 0;
241 virtual void streamon()
const = 0;
242 virtual void streamoff()
const = 0;
243 virtual void negotiate_kernel_buffers(
size_t num)
const = 0;
245 virtual void allocate_io_buffers(
size_t num) = 0;
246 virtual void map_device_descriptor() = 0;
247 virtual void unmap_device_descriptor() = 0;
249 virtual void prepare_capture_buffers() = 0;
250 virtual void stop_data_capture() = 0;
251 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format) = 0;
274 bool pull_video_with_metadata(std::shared_ptr<v4l2_buffer>& video_buffer, std::shared_ptr<v4l2_buffer>& md_buffer,
int& video_fd,
int& md_fd);
276 inline void start() {_is_ready =
true;}
280 void enqueue_buffer_before_throwing_it(
const sync_buffer& sb)
const;
281 void enqueue_front_buffer_before_throwing_it(std::queue<sync_buffer>& sync_queue);
299 frame_drop_monitor(
double kpi_frames_drops_percentage) : _kpi_frames_drops_pct(kpi_frames_drops_percentage) {}
313 static void foreach_uvc_device(
315 const std::string&)>
action);
317 static std::vector<std::string> get_video_paths();
319 static bool is_usb_path_valid(
const std::string& usb_video_path,
const std::string &dev_name,
320 std::string &busnum, std::string &devnum, std::string &devpath);
322 static bool is_usb_device_path(
const std::string& video_path);
324 static uvc_device_info get_info_from_usb_device_path(
const std::string& video_path,
const std::string&
name);
326 static uvc_device_info get_info_from_mipi_device_path(
const std::string& video_path,
const std::string& name);
328 static void get_mipi_device_info(
const std::string& dev_name,
329 std::string& bus_info, std::string& card);
337 void stream_on(std::function<
void(
const notification&
n)> error_handler)
override;
339 void start_callbacks()
override;
341 void stop_callbacks()
override;
345 std::string fourcc_to_string(
uint32_t id)
const;
365 std::vector<stream_profile> get_profiles()
const override;
367 void lock()
const override;
368 void unlock()
const override;
376 virtual void capture_loop()
override;
378 virtual bool has_metadata()
const override;
380 virtual void streamon()
const override;
381 virtual void streamoff()
const override;
382 virtual void negotiate_kernel_buffers(
size_t num)
const override;
384 virtual void allocate_io_buffers(
size_t num)
override;
385 virtual void map_device_descriptor()
override;
386 virtual void unmap_device_descriptor()
override;
388 virtual void prepare_capture_buffers()
override;
389 virtual void stop_data_capture()
override;
390 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format =
false)
override;
391 virtual void set_metadata_attributes(
buffers_mgr& buf_mgr, __u32 bytesused,
uint8_t* md_start);
392 void subscribe_to_ctrl_event(
uint32_t control_id);
393 void unsubscribe_from_ctrl_event(
uint32_t control_id);
394 bool pend_for_ctrl_status_event();
395 void upload_video_and_metadata_from_syncer(
buffers_mgr& buf_mgr);
404 std::string _device_path =
"";
425 int _stop_pipe_fd[2];
439 void streamon()
const;
440 void streamoff()
const;
441 void negotiate_kernel_buffers(
size_t num)
const;
442 void allocate_io_buffers(
size_t num);
443 void map_device_descriptor();
444 void unmap_device_descriptor();
446 void prepare_capture_buffers();
447 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format=
false);
452 std::string _md_name =
"";
472 void set_metadata_attributes(
buffers_mgr& buf_mgr, __u32 bytesused,
uint8_t* md_start)
override;
490 std::shared_ptr<time_service> create_time_service()
const override;
491 std::shared_ptr<device_watcher> create_device_watcher()
const override;
static const textual_icon lock
static const textual_icon unlock
GLuint const GLchar * name
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
constexpr bool metadata_node
static const textual_icon stop
GLenum GLuint GLenum GLsizei const GLchar * buf
def info(name, value, persistent=False)
constexpr auto LOCAL_V4L2_BUF_TYPE_META_CAPTURE
#define LOG_DEBUG_V4L(...)
GLbitfield GLuint64 timeout