예제 #1
0
int v4l2_init() {
  struct v4l2_capability video_cap;
  if (xioctl(video_fd, VIDIOC_QUERYCAP, &video_cap) == -1)
    return v4l2_error("VIDIOC_QUERYCAP");
  if (!(video_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
    return v4l2_error("No video capture device");
  if (!(video_cap.capabilities & V4L2_CAP_STREAMING))
    return v4l2_error("No capture streaming");
  
  struct v4l2_format video_fmt;
  video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  video_fmt.fmt.pix.width       = width;
  video_fmt.fmt.pix.height      = height;
  video_fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
  video_fmt.fmt.pix.field       = V4L2_FIELD_ANY;
  if (xioctl(video_fd, VIDIOC_S_FMT, &video_fmt) == -1)
    v4l2_error("VIDIOC_S_FMT");
    
  // Query V4L2 controls:
  v4l2_query_ctrl(V4L2_CID_BASE,
		  V4L2_CID_LASTP1);
  v4l2_query_ctrl(V4L2_CID_PRIVATE_BASE,
		  V4L2_CID_PRIVATE_BASE+20);
  v4l2_query_ctrl(V4L2_CID_CAMERA_CLASS_BASE+1,
		  V4L2_CID_CAMERA_CLASS_BASE+20);

  // Logitech specific controls:
  v4l2_query_ctrl(V4L2_CID_FOCUS,
		  V4L2_CID_FOCUS+1);
  v4l2_query_ctrl(V4L2_CID_LED1_MODE,
		  V4L2_CID_LED1_MODE+1);
  v4l2_query_ctrl(V4L2_CID_LED1_FREQUENCY,
		  V4L2_CID_LED1_FREQUENCY+1);
  v4l2_query_ctrl(V4L2_CID_DISABLE_PROCESSING,
		  V4L2_CID_DISABLE_PROCESSING+1);
  v4l2_query_ctrl(V4L2_CID_RAW_BITS_PER_PIXEL,
		  V4L2_CID_RAW_BITS_PER_PIXEL+1);

  // Initialize memory map
  v4l2_init_mmap();

  return 0;
}
예제 #2
0
bool BaseV4L2VideoCapture::InitializeDevice() {
  Limitation brightness;
  Limitation contrast;
  Limitation hue;
  Limitation saturation;
  Limitation sharpness;
  Limitation gamma;
  Limitation backlightCompensation;

  // 1. Get constraint of each capture filters
  if(!v4l2_query_ctrl(V4L2_CID_BRIGHTNESS, &brightness))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_CONTRAST, &contrast))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_HUE, &hue))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_SATURATION, &saturation))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_SHARPNESS, &sharpness))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_GAMMA, &gamma))
    return false;
  if(!v4l2_query_ctrl(V4L2_CID_BACKLIGHT_COMPENSATION, &backlightCompensation))
    return false;

  // 2. Instantiate VideoCaptureFiltersCapability
  // TODO : polymorphic the constructor for different support
  _pVideoCaptureFiltersCapability = new VideoCaptureFiltersCapability(brightness, contrast, hue, saturation, sharpness, gamma, backlightCompensation);
  // Below is for debug sake
  //_pVideoCaptureFiltersCapability->PrintConstraintValues();

  // Set capture filters to default here if needed

  // 3. Initialize VideoCaptureFilters
  InitVideoCaptureFilters();

  return true;
}