Move dev->fd to dev->v4l2.dev_fd
				
					
				
			This commit is contained in:
		| @@ -9,7 +9,6 @@ device_t *device_open(const char *name, const char *path, device_hw_t *hw) { | ||||
|   dev->name = strdup(name); | ||||
|   dev->path = strdup(path); | ||||
|   dev->hw = hw; | ||||
|   dev->fd = -1; | ||||
|   dev->allow_dma = true; | ||||
|  | ||||
|   if (dev->hw->device_open(dev) < 0) { | ||||
| @@ -128,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->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) { | ||||
| @@ -158,7 +157,7 @@ int device_consume_event(device_t *dev) | ||||
|   } | ||||
|  | ||||
| 	E_LOG_DEBUG(dev, "Consuming V4L2 event ..."); | ||||
|   E_XIOCTL(dev, 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: | ||||
|   | ||||
| @@ -32,7 +32,6 @@ typedef struct device_s { | ||||
|   char *name; | ||||
|   char *path; | ||||
|   char bus_info[64]; | ||||
|   int fd; | ||||
|   bool allow_dma; | ||||
|  | ||||
|   device_hw_t *hw; | ||||
| @@ -40,6 +39,7 @@ typedef struct device_s { | ||||
|   buffer_list_t *output_list; | ||||
|  | ||||
|   struct { | ||||
|     int dev_fd; | ||||
|     int subdev_fd; | ||||
|   } v4l2; | ||||
|  | ||||
|   | ||||
| @@ -26,7 +26,7 @@ int v4l2_buffer_open(buffer_t *buf) | ||||
|     v4l2_buf.memory = V4L2_MEMORY_DMABUF; | ||||
|   } | ||||
|  | ||||
|   E_XIOCTL(buf_list, 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; | ||||
|  | ||||
| @@ -39,7 +39,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->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; | ||||
|     } | ||||
| @@ -48,7 +48,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->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; | ||||
|   } | ||||
|  | ||||
| @@ -123,7 +123,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->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; | ||||
|  | ||||
| @@ -144,7 +144,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->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) { | ||||
| @@ -166,7 +166,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->fd; | ||||
|   pollfd->fd = buf_list->device->v4l2.dev_fd; | ||||
|   pollfd->events = POLLHUP; | ||||
|   if (count_enqueued > 0 && can_dequeue) { | ||||
|     if (buf_list->do_capture) | ||||
|   | ||||
| @@ -8,7 +8,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->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) { | ||||
| @@ -56,7 +56,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->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; | ||||
| @@ -84,7 +84,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->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; | ||||
| @@ -143,7 +143,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->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); | ||||
| 	} | ||||
| @@ -158,7 +158,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->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: | ||||
|   | ||||
| @@ -27,7 +27,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->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,18 +4,18 @@ | ||||
|  | ||||
| int v4l2_device_open(device_t *dev) | ||||
| { | ||||
|   dev->fd = -1; | ||||
|   dev->v4l2.dev_fd = -1; | ||||
|   dev->v4l2.subdev_fd = -1; | ||||
|  | ||||
|   dev->fd = open(dev->path, O_RDWR|O_NONBLOCK); | ||||
|   if (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_DEBUG(dev, "Querying device capabilities ..."); | ||||
|   struct v4l2_capability v4l2_cap; | ||||
|   E_XIOCTL(dev, 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"); | ||||
| @@ -23,7 +23,7 @@ int v4l2_device_open(device_t *dev) | ||||
|  | ||||
|   strcpy(dev->bus_info, v4l2_cap.bus_info); | ||||
|   dev->v4l2.subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0); | ||||
| 	E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->fd); | ||||
| 	E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2.dev_fd); | ||||
|  | ||||
|   return 0; | ||||
|  | ||||
| @@ -37,8 +37,8 @@ void v4l2_device_close(device_t *dev) | ||||
|     close(dev->v4l2.subdev_fd); | ||||
|   } | ||||
|  | ||||
|   if(dev->fd >= 0) { | ||||
|     close(dev->fd); | ||||
|   if(dev->v4l2.dev_fd >= 0) { | ||||
|     close(dev->v4l2.dev_fd); | ||||
|   } | ||||
|  | ||||
| } | ||||
| @@ -50,7 +50,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->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 +64,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->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 +83,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->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; | ||||
|   | ||||
| @@ -12,7 +12,7 @@ | ||||
| int v4l2_device_open_media_device(device_t *dev) | ||||
| { | ||||
|   struct stat st; | ||||
|   if (fstat(dev->fd, &st) < 0) { | ||||
|   if (fstat(dev->v4l2.dev_fd, &st) < 0) { | ||||
|     E_LOG_ERROR(dev, "Cannot get fstat"); | ||||
|     return -1; | ||||
|   } | ||||
|   | ||||
| @@ -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->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; | ||||
| @@ -155,7 +155,7 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) | ||||
|   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->fd, keyp, valuep); | ||||
|     ret = v4l2_device_set_option_string_fd(dev, dev->v4l2.dev_fd, keyp, valuep); | ||||
|  | ||||
|   free(keyp); | ||||
|   free(valuep); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kamil Trzcinski
					Kamil Trzcinski