From 27f909319e5256ba0d9c1435d2087893e6c0fd7a Mon Sep 17 00:00:00 2001 From: Ricardo de Almeida Gonzaga Date: Mon, 11 May 2015 00:42:41 +0000 Subject: [PATCH] AP_HAL_Linux: add get_pixel_formats() to VideoIn This function is being added in order to be used in the next commits, where we will add support for OpticalFlow on MinnowBoardMax. --- libraries/AP_HAL_Linux/VideoIn.cpp | 14 ++++++++++++++ libraries/AP_HAL_Linux/VideoIn.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/libraries/AP_HAL_Linux/VideoIn.cpp b/libraries/AP_HAL_Linux/VideoIn.cpp index 313775c992..507ce7f41d 100644 --- a/libraries/AP_HAL_Linux/VideoIn.cpp +++ b/libraries/AP_HAL_Linux/VideoIn.cpp @@ -159,6 +159,20 @@ bool VideoIn::allocate_buffers(uint32_t nbufs) return true; } +void VideoIn::get_pixel_formats(std::vector *formats) +{ + struct v4l2_fmtdesc fmtdesc; + + memset(&fmtdesc, 0, sizeof fmtdesc); + + fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + while (ioctl(_fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0) { + formats->insert(formats->begin(), fmtdesc.pixelformat); + fmtdesc.index++; + } +} + bool VideoIn::set_format(uint32_t *width, uint32_t *height, uint32_t *format, uint32_t *bytesperline, uint32_t *sizeimage) { diff --git a/libraries/AP_HAL_Linux/VideoIn.h b/libraries/AP_HAL_Linux/VideoIn.h index 1e451e2e92..3d3f4cf59d 100644 --- a/libraries/AP_HAL_Linux/VideoIn.h +++ b/libraries/AP_HAL_Linux/VideoIn.h @@ -16,6 +16,7 @@ #include "AP_HAL_Linux.h" #include +#include struct buffer { unsigned int size; @@ -43,6 +44,7 @@ public: void init(); bool open_device(const char *device_path, uint32_t memtype); bool allocate_buffers(uint32_t nbufs); + void get_pixel_formats(std::vector *formats); bool set_format(uint32_t *width, uint32_t *height, uint32_t *format, uint32_t *bytesperline, uint32_t *sizeimage); bool set_crop(uint32_t left, uint32_t top,