Add device_v4l2_t
(private data)
This commit is contained in:
parent
41a42e27a3
commit
5760f5fbac
@ -127,7 +127,7 @@ int device_set_stream(device_t *dev, bool do_on)
|
||||
sub.type = V4L2_EVENT_SOURCE_CHANGE;
|
||||
|
||||
E_LOG_DEBUG(dev, "Subscribing to DV-timings events ...");
|
||||
xioctl(dev_name(dev), dev->v4l2.dev_fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub);
|
||||
xioctl(dev_name(dev), dev->v4l2->dev_fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub);
|
||||
#endif
|
||||
|
||||
if (dev->capture_list) {
|
||||
@ -157,7 +157,7 @@ int device_consume_event(device_t *dev)
|
||||
}
|
||||
|
||||
E_LOG_DEBUG(dev, "Consuming V4L2 event ...");
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_DQEVENT, &event, "Got some V4L2 device event, but where is it?");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DQEVENT, &event, "Got some V4L2 device event, but where is it?");
|
||||
|
||||
switch (event.type) {
|
||||
case V4L2_EVENT_SOURCE_CHANGE:
|
||||
|
@ -37,10 +37,9 @@ typedef struct device_s {
|
||||
buffer_list_t *capture_list;
|
||||
buffer_list_t *output_list;
|
||||
|
||||
struct {
|
||||
int dev_fd;
|
||||
int subdev_fd;
|
||||
} v4l2;
|
||||
union {
|
||||
struct device_v4l2_s *v4l2;
|
||||
};
|
||||
|
||||
device_t *output_device;
|
||||
bool paused;
|
||||
|
@ -27,7 +27,7 @@ int v4l2_buffer_open(buffer_t *buf)
|
||||
v4l2_buf.memory = V4L2_MEMORY_DMABUF;
|
||||
}
|
||||
|
||||
E_XIOCTL(buf_list, dev->v4l2.dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", index);
|
||||
E_XIOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", index);
|
||||
|
||||
uint64_t mem_offset = 0;
|
||||
|
||||
@ -40,7 +40,7 @@ int v4l2_buffer_open(buffer_t *buf)
|
||||
}
|
||||
|
||||
if (buf_list->do_mmap) {
|
||||
buf->start = mmap(NULL, buf->length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->v4l2.dev_fd, mem_offset);
|
||||
buf->start = mmap(NULL, buf->length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->v4l2->dev_fd, mem_offset);
|
||||
if (buf->start == MAP_FAILED) {
|
||||
goto error;
|
||||
}
|
||||
@ -49,7 +49,7 @@ int v4l2_buffer_open(buffer_t *buf)
|
||||
v4l2_exp.type = v4l2_buf.type;
|
||||
v4l2_exp.index = buf->index;
|
||||
v4l2_exp.plane = 0;
|
||||
E_XIOCTL(buf_list, dev->v4l2.dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", index);
|
||||
E_XIOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", index);
|
||||
buf->dma_fd = v4l2_exp.fd;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ int v4l2_buffer_enqueue(buffer_t *buf, const char *who)
|
||||
v4l2_buf.timestamp.tv_usec = buf->captured_time_us % (1000LL * 1000LL);
|
||||
}
|
||||
|
||||
E_XIOCTL(buf, buf->buf_list->device->v4l2.dev_fd, VIDIOC_QBUF, &v4l2_buf, "Can't queue buffer.");
|
||||
E_XIOCTL(buf, buf->buf_list->device->v4l2->dev_fd, VIDIOC_QBUF, &v4l2_buf, "Can't queue buffer.");
|
||||
|
||||
return 0;
|
||||
|
||||
@ -147,7 +147,7 @@ int v4l2_buffer_list_dequeue(buffer_list_t *buf_list, buffer_t **bufp)
|
||||
v4l2_buf.m.planes = &v4l2_plane;
|
||||
}
|
||||
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, VIDIOC_DQBUF, &v4l2_buf, "Can't grab capture buffer (flags=%08x)", v4l2_buf.flags);
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, VIDIOC_DQBUF, &v4l2_buf, "Can't grab capture buffer (flags=%08x)", v4l2_buf.flags);
|
||||
|
||||
buffer_t *buf = *bufp = buf_list->bufs[v4l2_buf.index];
|
||||
if (buf_list->v4l2.do_mplanes) {
|
||||
@ -170,7 +170,7 @@ int v4l2_buffer_list_pollfd(buffer_list_t *buf_list, struct pollfd *pollfd, bool
|
||||
int count_enqueued = buffer_list_count_enqueued(buf_list);
|
||||
|
||||
// Can something be dequeued?
|
||||
pollfd->fd = buf_list->device->v4l2.dev_fd;
|
||||
pollfd->fd = buf_list->device->v4l2->dev_fd;
|
||||
pollfd->events = POLLHUP;
|
||||
if (count_enqueued > 0 && can_dequeue) {
|
||||
if (buf_list->do_capture)
|
||||
|
@ -10,7 +10,7 @@ int v4l2_buffer_list_set_format(buffer_list_t *buf_list, unsigned width, unsigne
|
||||
device_t *dev = buf_list->device;
|
||||
|
||||
struct v4l2_capability v4l2_cap;
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities");
|
||||
|
||||
if (buf_list->do_capture) {
|
||||
if (v4l2_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
|
||||
@ -58,7 +58,7 @@ int v4l2_buffer_list_set_format(buffer_list_t *buf_list, unsigned width, unsigne
|
||||
}
|
||||
|
||||
E_LOG_DEBUG(buf_list, "Get current format ...");
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, VIDIOC_G_FMT, &fmt, "Can't set format");
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, VIDIOC_G_FMT, &fmt, "Can't set format");
|
||||
|
||||
if (buf_list->v4l2.do_mplanes) {
|
||||
fmt.fmt.pix_mp.colorspace = V4L2_COLORSPACE_JPEG;
|
||||
@ -86,7 +86,7 @@ int v4l2_buffer_list_set_format(buffer_list_t *buf_list, unsigned width, unsigne
|
||||
}
|
||||
|
||||
E_LOG_DEBUG(buf_list, "Configuring format (%s)...", fourcc_to_string(format).buf);
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, VIDIOC_S_FMT, &fmt, "Can't set format");
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, VIDIOC_S_FMT, &fmt, "Can't set format");
|
||||
|
||||
if (buf_list->v4l2.do_mplanes) {
|
||||
buf_list->fmt_width = fmt.fmt.pix_mp.width;
|
||||
@ -145,7 +145,7 @@ int v4l2_buffer_list_set_buffers(buffer_list_t *buf_list, int nbufs)
|
||||
|
||||
E_LOG_DEBUG(buf_list, "Requesting %u buffers", v4l2_req.count);
|
||||
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, VIDIOC_REQBUFS, &v4l2_req, "Can't request buffers");
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, VIDIOC_REQBUFS, &v4l2_req, "Can't request buffers");
|
||||
if (v4l2_req.count < 1) {
|
||||
E_LOG_ERROR(buf_list, "Insufficient buffer memory: %u", v4l2_req.count);
|
||||
}
|
||||
@ -160,7 +160,7 @@ error:
|
||||
int v4l2_buffer_list_set_stream(buffer_list_t *buf_list, bool do_on)
|
||||
{
|
||||
enum v4l2_buf_type type = buf_list->v4l2.type;
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, do_on ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type, "Cannot set streaming state");
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, do_on ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type, "Cannot set streaming state");
|
||||
|
||||
return 0;
|
||||
error:
|
||||
|
@ -28,7 +28,7 @@ int v4l2_buffer_list_refresh_states(buffer_list_t *buf_list)
|
||||
for (int i = 0; i < buf_list->nbufs; i++) {
|
||||
v4l2_buf.index = i;
|
||||
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2.dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Can't query buffer (flags=%08x)", i);
|
||||
E_XIOCTL(buf_list, buf_list->device->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Can't query buffer (flags=%08x)", i);
|
||||
E_LOG_INFO(buf_list, "Buffer: %d, Flags: %08x. Offset: %d", i, v4l2_buf.flags,
|
||||
buf_list->v4l2.do_mplanes ? v4l2_plane.m.mem_offset : v4l2_buf.m.offset);
|
||||
}
|
||||
|
@ -4,27 +4,28 @@
|
||||
|
||||
int v4l2_device_open(device_t *dev)
|
||||
{
|
||||
dev->v4l2.dev_fd = -1;
|
||||
dev->v4l2.subdev_fd = -1;
|
||||
dev->v4l2 = calloc(1, sizeof(device_v4l2_t));
|
||||
dev->v4l2->dev_fd = -1;
|
||||
dev->v4l2->subdev_fd = -1;
|
||||
|
||||
dev->v4l2.dev_fd = open(dev->path, O_RDWR|O_NONBLOCK);
|
||||
if (dev->v4l2.dev_fd < 0) {
|
||||
dev->v4l2->dev_fd = open(dev->path, O_RDWR|O_NONBLOCK);
|
||||
if (dev->v4l2->dev_fd < 0) {
|
||||
E_LOG_ERROR(dev, "Can't open device: %s", dev->path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2.dev_fd);
|
||||
E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2->dev_fd);
|
||||
|
||||
E_LOG_DEBUG(dev, "Querying device capabilities ...");
|
||||
struct v4l2_capability v4l2_cap;
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities");
|
||||
|
||||
if (!(v4l2_cap.capabilities & V4L2_CAP_STREAMING)) {
|
||||
E_LOG_ERROR(dev, "Device doesn't support streaming IO");
|
||||
}
|
||||
|
||||
strcpy(dev->bus_info, v4l2_cap.bus_info);
|
||||
dev->v4l2.subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0);
|
||||
dev->v4l2->subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@ -33,14 +34,16 @@ error:
|
||||
|
||||
void v4l2_device_close(device_t *dev)
|
||||
{
|
||||
if (dev->v4l2.subdev_fd >= 0) {
|
||||
close(dev->v4l2.subdev_fd);
|
||||
if (dev->v4l2->subdev_fd >= 0) {
|
||||
close(dev->v4l2->subdev_fd);
|
||||
}
|
||||
|
||||
if(dev->v4l2.dev_fd >= 0) {
|
||||
close(dev->v4l2.dev_fd);
|
||||
if(dev->v4l2->dev_fd >= 0) {
|
||||
close(dev->v4l2->dev_fd);
|
||||
}
|
||||
|
||||
free(dev->v4l2);
|
||||
dev->v4l2 = NULL;
|
||||
}
|
||||
|
||||
int v4l2_device_set_decoder_start(device_t *dev, bool do_on)
|
||||
@ -50,7 +53,7 @@ int v4l2_device_set_decoder_start(device_t *dev, bool do_on)
|
||||
cmd.cmd = do_on ? V4L2_DEC_CMD_START : V4L2_DEC_CMD_STOP;
|
||||
|
||||
E_LOG_DEBUG(dev, "Setting decoder state %s...", do_on ? "Start" : "Stop");
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_DECODER_CMD, &cmd, "Cannot set decoder state");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DECODER_CMD, &cmd, "Cannot set decoder state");
|
||||
|
||||
return 0;
|
||||
|
||||
@ -64,7 +67,7 @@ int v4l2_device_video_force_key(device_t *dev)
|
||||
ctl.id = V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME;
|
||||
ctl.value = 1;
|
||||
E_LOG_DEBUG(dev, "Forcing keyframe ...");
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_S_CTRL, &ctl, "Can't force keyframe");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't force keyframe");
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@ -83,7 +86,7 @@ int v4l2_device_set_fps(device_t *dev, int desired_fps)
|
||||
setfps.parm.output.timeperframe.numerator = 1;
|
||||
setfps.parm.output.timeperframe.denominator = desired_fps;
|
||||
E_LOG_DEBUG(dev, "Configuring FPS ...");
|
||||
E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_S_PARM, &setfps, "Can't set FPS");
|
||||
E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_PARM, &setfps, "Can't set FPS");
|
||||
return 0;
|
||||
error:
|
||||
return -1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
int v4l2_device_open_media_device(device_t *dev)
|
||||
{
|
||||
struct stat st;
|
||||
if (fstat(dev->v4l2.dev_fd, &st) < 0) {
|
||||
if (fstat(dev->v4l2->dev_fd, &st) < 0) {
|
||||
E_LOG_ERROR(dev, "Cannot get fstat");
|
||||
return -1;
|
||||
}
|
||||
@ -114,7 +114,7 @@ int v4l2_device_set_pad_format(device_t *dev, unsigned width, unsigned height, u
|
||||
{
|
||||
struct v4l2_subdev_format fmt = {0};
|
||||
|
||||
if (dev->v4l2.subdev_fd < 0) {
|
||||
if (dev->v4l2->subdev_fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ int v4l2_device_set_pad_format(device_t *dev, unsigned width, unsigned height, u
|
||||
fmt.format.colorspace = V4L2_COLORSPACE_RAW;
|
||||
fmt.format.field = V4L2_FIELD_ANY;
|
||||
|
||||
E_LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->v4l2.subdev_fd);
|
||||
E_XIOCTL(dev, dev->v4l2.subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->v4l2.subdev_fd);
|
||||
E_LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->v4l2->subdev_fd);
|
||||
E_XIOCTL(dev, dev->v4l2->subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->v4l2->subdev_fd);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
|
@ -15,7 +15,7 @@ int v4l2_device_set_option_by_id(device_t *dev, const char *name, uint32_t id, i
|
||||
ctl.id = id;
|
||||
ctl.value = value;
|
||||
E_LOG_DEBUG(dev, "Configuring option %s (%08x) = %d", name, id, value);
|
||||
E_XIOCTL(dev, dev->v4l2.subdev_fd >= 0 ? dev->v4l2.subdev_fd : dev->v4l2.dev_fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name);
|
||||
E_XIOCTL(dev, dev->v4l2->subdev_fd >= 0 ? dev->v4l2->subdev_fd : dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name);
|
||||
return 0;
|
||||
error:
|
||||
return -1;
|
||||
@ -152,10 +152,10 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value)
|
||||
|
||||
v4l2_device_option_normalize_name(keyp);
|
||||
|
||||
if (dev->v4l2.subdev_fd >= 0)
|
||||
ret = v4l2_device_set_option_string_fd(dev, dev->v4l2.subdev_fd, keyp, valuep);
|
||||
if (dev->v4l2->subdev_fd >= 0)
|
||||
ret = v4l2_device_set_option_string_fd(dev, dev->v4l2->subdev_fd, keyp, valuep);
|
||||
if (ret <= 0)
|
||||
ret = v4l2_device_set_option_string_fd(dev, dev->v4l2.dev_fd, keyp, valuep);
|
||||
ret = v4l2_device_set_option_string_fd(dev, dev->v4l2->dev_fd, keyp, valuep);
|
||||
|
||||
free(keyp);
|
||||
free(valuep);
|
||||
|
@ -10,6 +10,11 @@ typedef struct buffer_list_s buffer_list_t;
|
||||
typedef struct device_s device_t;
|
||||
struct pollfd;
|
||||
|
||||
typedef struct device_v4l2_s {
|
||||
int dev_fd;
|
||||
int subdev_fd;
|
||||
} device_v4l2_t;
|
||||
|
||||
int v4l2_device_open(device_t *dev);
|
||||
void v4l2_device_close(device_t *dev);
|
||||
int v4l2_device_set_decoder_start(device_t *dev, bool do_on);
|
||||
|
Loading…
x
Reference in New Issue
Block a user