嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
RK3588图像采集测试程序
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <poll.h>
#include <linux/videodev2.h>
#include "util.h"
#include "drm.h"
#define V4l2_PLANE_NUM 1
struct Setup s;
/* ctrl c */
volatile bool g_quit = false;
static void sigint_handler(int signo) {
(void)signo;
g_quit = true;
}
static void v4l2_check_capability(int fd) {
struct v4l2_capability caps;
memset(&caps, 0, sizeof caps);
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
BYE_ON(ret, "VIDIOC_QUERYCAP failed: %s\n", ERRSTR);
BYE_ON(~caps.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE,
"video: multiplanar capture is not supported\n");
}
static void v4l2_set_format(int fd) {
struct v4l2_format fmt;
memset(&fmt, 0, sizeof fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
int ret = ioctl(fd, VIDIOC_G_FMT, &fmt);
BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR);
printf("old format: width = %u, height = %u, 4cc = %.4s\n",
fmt.fmt.pix.width, fmt.fmt.pix.height,
(char*)&fmt.fmt.pix.pixelformat);
fmt.fmt.pix.width = s.w;
fmt.fmt.pix.height = s.h;
fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
fmt.fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT;
fmt.fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_601;
if (s.in_fourcc)
fmt.fmt.pix.pixelformat = s.in_fourcc;
ret = ioctl(fd, VIDIOC_S_FMT, &fmt);
BYE_ON(ret < 0, "VIDIOC_S_FMT failed: %s\n", ERRSTR);
ret = ioctl(fd, VIDIOC_G_FMT, &fmt);
BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR);
printf("cur format: width = %u, height = %u, 4cc = %.4s\n",
fmt.fmt.pix.width, fmt.fmt.pix.height,
(char*)&fmt.fmt.pix.pixelformat);
s.in_fourcc = fmt.fmt.pix.pixelformat;
s.w = fmt.fmt.pix.width;
s.h = fmt.fmt.pix.height;
s.size = fmt.fmt.pix.sizeimage;
s.pitch = fmt.fmt.pix.width; /* for NV12 format image */
}
static void v4l2_request_buffers(int fd) {
struct v4l2_requestbuffers rqbufs;
memset(&rqbufs, 0, sizeof(rqbufs));
rqbufs.count = s.buffer_count;
rqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
rqbufs.memory = V4L2_MEMORY_DMABUF;
int ret = ioctl(fd, VIDIOC_REQBUFS, &rqbufs);
BYE_ON(ret < 0, "VIDIOC_REQBUFS failed: %s\n", ERRSTR);
BYE_ON(rqbufs.count < s.buffer_count, "video node allocated only "
"%u of %u buffers\n", rqbufs.count, s.buffer_count);
}
static void v4l2_query_buffers(int fd, uint32_t buffer_count) {
for (unsigned int i = 0; i < buffer_count; i) {
struct v4l2_plane planes[V4l2_PLANE_NUM];
memset(&planes, 0, sizeof(planes) * V4l2_PLANE_NUM);
struct v4l2_buffer buf;
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
buf.memory = V4L2_MEMORY_DMABUF;
buf.index = i;
buf.m.planes = planes;
buf.length = V4l2_PLANE_NUM;
int ret = ioctl(fd, VIDIOC_QUERYBUF, &buf);
BYE_ON(ret < 0, "VIDIOC_QBUF for buffer %d failed: %s\n", buf.index, ERRSTR);
}
}
int main(int argc, char *argv[]) {
signal(SIGINT, sigint_handler);
/* get command line arguments */
int ret;
ret = parse_args(argc, argv, &s);
BYE_ON(ret, "failed to parse arguments\n");
BYE_ON(s.module[0] == 0, "DRM module is missing\n");
BYE_ON(s.video[0] == 0, "video node is missing\n");
/* open drm device */