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;
169 _mmap_bufs(memory_mapped_buf)
174 void request_next_frame();
176 v4l2_buffer
buf= v4l2_buffer(),
177 std::shared_ptr<platform::buffer> data_buf=
nullptr);
183 { _md_start = md_start; _md_size = md_size; }
184 void set_md_from_video_node(
bool compressed);
185 bool verify_vd_md_sync()
const;
186 bool md_node_present()
const;
194 if (_data_buf && (!_managed))
198 if (
xioctl(_file_desc, (
int)VIDIOC_QBUF, &_dq_buf) < 0)
200 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) guard failed for fd " << std::dec << _file_desc);
201 if (
xioctl(_file_desc, (
int)VIDIOC_DQBUF, &_dq_buf) >= 0)
203 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) Re-enqueue succeeded for fd " << std::dec << _file_desc);
204 if (
xioctl(_file_desc, (
int)VIDIOC_QBUF, &_dq_buf) < 0)
205 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) re-deque failed for fd " << std::dec << _file_desc);
207 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) re-deque succeeded for fd " << std::dec << _file_desc);
210 LOG_DEBUG_V4L(
"xioctl(VIDIOC_QBUF) Re-enqueue failed for fd " << std::dec << _file_desc);
213 LOG_DEBUG_V4L(
"Enqueue (e) buf " << std::dec << _dq_buf.index <<
" for fd " << _file_desc);
218 std::shared_ptr<platform::buffer> _data_buf=
nullptr;
219 v4l2_buffer _dq_buf{};
224 std::array<kernel_buf_guard, e_max_kernel_buf_type>&
get_buffers()
233 std::array<kernel_buf_guard, e_max_kernel_buf_type>
buffers;
238 virtual void capture_loop() = 0;
240 virtual bool has_metadata()
const = 0;
242 virtual void streamon()
const = 0;
243 virtual void streamoff()
const = 0;
244 virtual void negotiate_kernel_buffers(
size_t num)
const = 0;
246 virtual void allocate_io_buffers(
size_t num) = 0;
247 virtual void map_device_descriptor() = 0;
248 virtual void unmap_device_descriptor() = 0;
250 virtual void prepare_capture_buffers() = 0;
251 virtual void stop_data_capture() = 0;
252 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format) = 0;
258 static void foreach_uvc_device(
268 void stream_on(std::function<
void(
const notification&
n)> error_handler)
override;
270 void start_callbacks()
override;
272 void stop_callbacks()
override;
296 std::vector<stream_profile> get_profiles()
const override;
298 void lock()
const override;
299 void unlock()
const override;
307 virtual void capture_loop()
override;
309 virtual bool has_metadata()
const override;
311 virtual void streamon()
const override;
312 virtual void streamoff()
const override;
313 virtual void negotiate_kernel_buffers(
size_t num)
const override;
315 virtual void allocate_io_buffers(
size_t num)
override;
316 virtual void map_device_descriptor()
override;
317 virtual void unmap_device_descriptor()
override;
319 virtual void prepare_capture_buffers()
override;
320 virtual void stop_data_capture()
override;
321 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format =
false)
override;
344 int _stop_pipe_fd[2];
358 void streamon()
const;
359 void streamoff()
const;
360 void negotiate_kernel_buffers(
size_t num)
const;
361 void allocate_io_buffers(
size_t num);
362 void map_device_descriptor();
363 void unmap_device_descriptor();
365 void prepare_capture_buffers();
366 virtual void acquire_metadata(
buffers_mgr & buf_mgr,fd_set &fds,
bool compressed_format=
false);
387 std::shared_ptr<time_service> create_time_service()
const override;
388 std::shared_ptr<device_watcher> create_device_watcher()
const override;
static const textual_icon lock
static const textual_icon unlock
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
constexpr bool metadata_node
GLsizei const GLchar *const * string
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