Skip to content

Commit

Permalink
[v4l2] Fix small bug in fetching image
Browse files Browse the repository at this point in the history
  • Loading branch information
fvantienen committed Feb 24, 2015
1 parent 4a10e51 commit a62ce81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions sw/airborne/modules/computer_vision/lib/v4l/v4l2.c
Expand Up @@ -35,7 +35,6 @@
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/v4l2-subdev.h>
#include <pthread.h>

#include "v4l2.h"
Expand Down Expand Up @@ -208,7 +207,7 @@ struct v4l2_device *v4l2_init(char *device_name, uint16_t width, uint16_t height
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = width;
fmt.fmt.pix.height = height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;//V4L2_PIX_FMT_NV12;//V4L2_PIX_FMT_SGRBG12;//V4L2_PIX_FMT_UYVY;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
fmt.fmt.pix.field = V4L2_FIELD_NONE;

if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
Expand Down Expand Up @@ -261,7 +260,6 @@ struct v4l2_device *v4l2_init(char *device_name, uint16_t width, uint16_t height
close(fd);
return NULL;
}
printf("[v4l2] Mapping buffer %d with length %d from %s\n", i, buf.length, device_name);
}

// Create the device only when everything succeeded
Expand Down
19 changes: 10 additions & 9 deletions sw/airborne/modules/computer_vision/lib/v4l/v4l2.h
Expand Up @@ -29,6 +29,7 @@
#define _CV_LIB_V4L2_H

#include "std.h"
#include <linux/v4l2-subdev.h>

#define V4L2_IMG_NONE 255 //< There currently no image available

Expand All @@ -41,15 +42,15 @@ struct v4l2_img_buf {

/* V4L2 device */
struct v4l2_device {
char *name; //< The name of the device
int fd; //< The file pointer to the device
pthread_t thread; //< The thread that handles the images
uint16_t w; //< The width of the image
uint16_t h; //< The height of the image
uint8_t buffers_cnt; //< The number of image buffers
uint8_t buffers_deq_idx; //< The current dequeued index
pthread_mutex_t mutex; //< Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
struct v4l2_img_buf *buffers; //< The memory mapped image buffers
char *name; //< The name of the device
int fd; //< The file pointer to the device
pthread_t thread; //< The thread that handles the images
uint16_t w; //< The width of the image
uint16_t h; //< The height of the image
uint8_t buffers_cnt; //< The number of image buffers
volatile uint8_t buffers_deq_idx; //< The current dequeued index
pthread_mutex_t mutex; //< Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
struct v4l2_img_buf *buffers; //< The memory mapped image buffers
};

/* External functions */
Expand Down

0 comments on commit a62ce81

Please sign in to comment.