Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022 #ifndef UVC_CAM_H
00023 #define UVC_CAM_H
00024
00025 #include <string>
00026 #include <libv4l2.h>
00027 #include <linux/videodev2.h>
00028
00029 #include <stdint.h>
00030
00031 namespace uvc_cam
00032 {
00033
00034 enum v4l2_uvc_exposure_auto_type
00035 {
00036 V4L2_UVC_EXPOSURE_MANUAL = 1,
00037 V4L2_UVC_EXPOSURE_AUTO = 2,
00038 V4L2_UVC_EXPOSURE_SHUTTER_PRIORITY = 4,
00039 V4L2_UVC_EXPOSURE_APERTURE_PRIORITY = 8
00040 };
00041
00042
00043 static const int exp_vals[]=
00044 {
00045 V4L2_UVC_EXPOSURE_MANUAL,
00046 V4L2_UVC_EXPOSURE_AUTO,
00047 V4L2_UVC_EXPOSURE_SHUTTER_PRIORITY,
00048 V4L2_UVC_EXPOSURE_APERTURE_PRIORITY
00049 };
00050
00051
00052
00053 #define CSU32 const static uint32_t
00054
00055 class Cam
00056 {
00057 public:
00058 enum mode_t { MODE_RGB, MODE_MJPG, MODE_YUYV } mode;
00059 Cam(const char *device, mode_t _mode = MODE_RGB,
00060 int _width = 640, int _height = 480, int _fps = 30);
00061 ~Cam();
00062 static void enumerate();
00063 int grab(unsigned char **frame, uint32_t &bytes_used);
00064 void release(unsigned buf_idx);
00065 bool set_auto_white_balance(bool on);
00066 void set_motion_thresholds(int lum, int count);
00067 void set_control(uint32_t id, int val);
00068 bool v4l2_query(int id, const std::string& name);
00069 bool set_v4l2_control(int id, int value, const std::string& name);
00070 private:
00071 std::string device;
00072 int fd, motion_threshold_luminance, motion_threshold_count;
00073 unsigned width, height, fps;
00074 v4l2_format fmt;
00075 v4l2_capability cap;
00076 v4l2_streamparm streamparm;
00077 v4l2_requestbuffers rb;
00078 v4l2_buffer buf;
00079 v4l2_timecode timecode;
00080 static const unsigned NUM_BUFFER = 2;
00081 void *mem[NUM_BUFFER];
00082 unsigned buf_length;
00083 unsigned char *rgb_frame, *last_yuv_frame;
00084
00085
00086 CSU32 V4L2_CTRL_CLASS_USER_NEW = 0x00980000;
00087 CSU32 V4L2_CID_BASE_NEW = V4L2_CTRL_CLASS_USER_NEW | 0x900;
00088 CSU32 V4L2_CID_POWER_LINE_FREQUENCY_NEW = V4L2_CID_BASE_NEW + 24;
00089 CSU32 V4L2_CID_HUE_AUTO_NEW = V4L2_CID_BASE_NEW + 25;
00090 CSU32 V4L2_CID_WHITE_BALANCE_TEMPERATURE_NEW = V4L2_CID_BASE_NEW + 26;
00091 CSU32 V4L2_CID_SHARPNESS_NEW = V4L2_CID_BASE_NEW + 27;
00092 CSU32 V4L2_CID_BACKLIGHT_COMPENSATION_NEW = V4L2_CID_BASE_NEW + 28;
00093 CSU32 V4L2_CID_LAST_NEW = V4L2_CID_BASE_NEW + 29;
00094
00095 CSU32 V4L2_CTRL_CLASS_CAMERA_NEW = 0x009A0000;
00096 CSU32 V4L2_CID_CAMERA_CLASS_BASE_NEW = V4L2_CTRL_CLASS_CAMERA_NEW | 0x900;
00097 CSU32 V4L2_CID_EXPOSURE_AUTO_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 1;
00098 CSU32 V4L2_CID_EXPOSURE_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 2;
00099 CSU32 V4L2_CID_EXPOSURE_AUTO_PRIORITY_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW+3;
00100 CSU32 V4L2_CID_PAN_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 4;
00101 CSU32 V4L2_CID_TILT_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 5;
00102 CSU32 V4L2_CID_PAN_RESET_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 6;
00103 CSU32 V4L2_CID_TILT_RESET_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 7;
00104 CSU32 V4L2_CID_PAN_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 8;
00105 CSU32 V4L2_CID_TILT_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 9;
00106 CSU32 V4L2_CID_FOCUS_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 10;
00107 CSU32 V4L2_CID_FOCUS_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 11;
00108 CSU32 V4L2_CID_FOCUS_AUTO_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 12;
00109 CSU32 V4L2_CID_CAMERA_CLASS_LAST = V4L2_CID_CAMERA_CLASS_BASE_NEW + 13;
00110
00111
00112 CSU32 V4L2_CID_PRIVATE_BASE_OLD = 0x08000000;
00113 CSU32 V4L2_CID_BACKLIGHT_COMPENSATION_OLD = V4L2_CID_PRIVATE_BASE_OLD + 0;
00114 CSU32 V4L2_CID_POWER_LINE_FREQUENCY_OLD = V4L2_CID_PRIVATE_BASE_OLD + 1;
00115 CSU32 V4L2_CID_SHARPNESS_OLD = V4L2_CID_PRIVATE_BASE_OLD + 2;
00116 CSU32 V4L2_CID_HUE_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 3;
00117 CSU32 V4L2_CID_FOCUS_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 4;
00118 CSU32 V4L2_CID_FOCUS_ABSOLUTE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 5;
00119 CSU32 V4L2_CID_FOCUS_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 6;
00120 CSU32 V4L2_CID_PAN_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 7;
00121 CSU32 V4L2_CID_TILT_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 8;
00122 CSU32 V4L2_CID_PANTILT_RESET_OLD = V4L2_CID_PRIVATE_BASE_OLD + 9;
00123 CSU32 V4L2_CID_EXPOSURE_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 10;
00124 CSU32 V4L2_CID_EXPOSURE_ABSOLUTE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 11;
00125 CSU32 V4L2_CID_WHITE_BALANCE_TEMP_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD+12;
00126 CSU32 V4L2_CID_WHITE_BALANCE_TEMP_OLD = V4L2_CID_PRIVATE_BASE_OLD + 13;
00127 CSU32 V4L2_CID_PRIVATE_LAST = V4L2_CID_WHITE_BALANCE_TEMP_OLD + 1;
00128
00129 CSU32 UVC_CTRL_DATA_TYPE_RAW = 0;
00130 CSU32 UVC_CTRL_DATA_TYPE_SIGNED = 1;
00131 CSU32 UVC_CTRL_DATA_TYPE_UNSIGNED = 2;
00132 CSU32 UVC_CTRL_DATA_TYPE_BOOLEAN = 3;
00133 CSU32 UVC_CTRL_DATA_TYPE_ENUM = 4;
00134 CSU32 UVC_CTRL_DATA_TYPE_BITMASK = 5;
00135 CSU32 V4L2_CID_BASE_EXTCTR = 0x0A046D01;
00136 CSU32 V4L2_CID_BASE_LOGITECH = V4L2_CID_BASE_EXTCTR;
00137
00138
00139 CSU32 V4L2_CID_PANTILT_RESET_LOGITECH = V4L2_CID_BASE_LOGITECH + 2;
00140 CSU32 V4L2_CID_FOCUS_LOGITECH = V4L2_CID_BASE_LOGITECH + 3;
00141 CSU32 V4L2_CID_LED1_MODE_LOGITECH = V4L2_CID_BASE_LOGITECH + 4;
00142 CSU32 V4L2_CID_LED1_FREQUENCY_LOGITECH = V4L2_CID_BASE_LOGITECH + 5;
00143 CSU32 V4L2_CID_DISABLE_PROCESSING_LOGITECH = V4L2_CID_BASE_LOGITECH + 0x70;
00144 CSU32 V4L2_CID_RAW_BITS_PER_PIXEL_LOGITECH = V4L2_CID_BASE_LOGITECH + 0x71;
00145 CSU32 V4L2_CID_LAST_EXTCTR = V4L2_CID_RAW_BITS_PER_PIXEL_LOGITECH;
00146
00147 };
00148
00149 }
00150
00151 #endif
00152