diff options
author | Benoit Parrot <bparrot@ti.com> | 2018-10-29 12:15:09 -0500 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@iki.fi> | 2018-11-01 16:43:35 +0200 |
commit | 4097a83c68b89a70179244da01db0691a6c7c269 (patch) | |
tree | ff87a7892dd3ecccce1ccf6de19026094fa40a9b /kms++util/src | |
parent | 419babcd8ef423e787e122044601567fbff3457c (diff) |
videodevice: Add selection API support
Add selection API support to the VideoSteamer class.
Signed-off-by: Benoit Parrot <bparrot@ti.com>
Diffstat (limited to 'kms++util/src')
-rw-r--r-- | kms++util/src/videodevice.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/kms++util/src/videodevice.cpp b/kms++util/src/videodevice.cpp index efe1678..cc11357 100644 --- a/kms++util/src/videodevice.cpp +++ b/kms++util/src/videodevice.cpp @@ -96,6 +96,63 @@ static void v4l2_set_format(int fd, PixelFormat fmt, uint32_t width, uint32_t he } } +static void v4l2_get_selection(int fd, uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height, uint32_t buf_type) +{ + int r; + struct v4l2_selection selection; + + if (buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT || + buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + selection.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + selection.target = V4L2_SEL_TGT_CROP; + } else if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE || + buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { + selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + selection.target = V4L2_SEL_TGT_COMPOSE; + } else { + FAIL("buf_type (%d) is not valid\n", buf_type); + } + + r = ioctl(fd, VIDIOC_G_SELECTION, &selection); + ASSERT(r == 0); + + left = selection.r.left; + top = selection.r.top; + width = selection.r.width; + height = selection.r.height; +} + +static void v4l2_set_selection(int fd, uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height, uint32_t buf_type) +{ + int r; + struct v4l2_selection selection; + + if (buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT || + buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + selection.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + selection.target = V4L2_SEL_TGT_CROP; + } else if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE || + buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { + selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + selection.target = V4L2_SEL_TGT_COMPOSE; + } else { + FAIL("buf_type (%d) is not valid\n", buf_type); + } + + selection.r.left = left; + selection.r.top = top; + selection.r.width = width; + selection.r.height = height; + + r = ioctl(fd, VIDIOC_S_SELECTION, &selection); + ASSERT(r == 0); + + left = selection.r.left; + top = selection.r.top; + width = selection.r.width; + height = selection.r.height; +} + static void v4l2_request_bufs(int fd, uint32_t queue_size, uint32_t buf_type) { v4l2_requestbuffers v4lreqbuf { }; @@ -414,6 +471,16 @@ void VideoStreamer::set_format(PixelFormat fmt, uint32_t width, uint32_t height) v4l2_set_format(m_fd, fmt, width, height, get_buf_type(m_type)); } +void VideoStreamer::get_selection(uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height) +{ + v4l2_get_selection(m_fd, left, top, width, height, get_buf_type(m_type)); +} + +void VideoStreamer::set_selection(uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height) +{ + v4l2_set_selection(m_fd, left, top, width, height, get_buf_type(m_type)); +} + void VideoStreamer::set_queue_size(uint32_t queue_size) { v4l2_request_bufs(m_fd, queue_size, get_buf_type(m_type)); |