$search
00001 // The uvc_cam package provides a simple interface to webcams visible through 00002 // the uvcvideo driver. It includes code adapted from 'guvcview', which in 00003 // turn adapted some code from 'luvcview'. 00004 // Copyright (C) 2009 Morgan Quigley 00005 // 00006 // This program is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU General Public License 00008 // as published by the Free Software Foundation; either version 2 00009 // of the License, or (at your option) any later version. 00010 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 00019 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 00022 #ifndef UVC_CAM_H 00023 #define UVC_CAM_H 00024 00025 #include <string> 00026 #include <linux/videodev2.h> 00027 #include <stdint.h> 00028 00029 namespace uvc_cam 00030 { 00031 00032 enum v4l2_uvc_exposure_auto_type 00033 { 00034 V4L2_UVC_EXPOSURE_MANUAL = 1, 00035 V4L2_UVC_EXPOSURE_AUTO = 2, 00036 V4L2_UVC_EXPOSURE_SHUTTER_PRIORITY = 4, 00037 V4L2_UVC_EXPOSURE_APERTURE_PRIORITY = 8 00038 }; 00039 00040 00041 static const int exp_vals[]= 00042 { 00043 V4L2_UVC_EXPOSURE_MANUAL, 00044 V4L2_UVC_EXPOSURE_AUTO, 00045 V4L2_UVC_EXPOSURE_SHUTTER_PRIORITY, 00046 V4L2_UVC_EXPOSURE_APERTURE_PRIORITY 00047 }; 00048 00049 00050 00051 #define CSU32 const static uint32_t 00052 00053 class Cam 00054 { 00055 public: 00056 enum mode_t { MODE_RGB, MODE_MJPG, MODE_YUYV } mode; 00057 Cam(const char *device, mode_t _mode = MODE_RGB, 00058 int _width = 640, int _height = 480, int _fps = 30); 00059 ~Cam(); 00060 static void enumerate(); 00061 int grab(unsigned char **frame, uint32_t &bytes_used); 00062 void release(unsigned buf_idx); 00063 bool set_auto_white_balance(bool on); 00064 void set_motion_thresholds(int lum, int count); 00065 void set_control(uint32_t id, int val); 00066 private: 00067 std::string device; 00068 int fd, motion_threshold_luminance, motion_threshold_count; 00069 unsigned width, height, fps; 00070 v4l2_format fmt; 00071 v4l2_capability cap; 00072 v4l2_streamparm streamparm; 00073 v4l2_requestbuffers rb; 00074 v4l2_buffer buf; 00075 v4l2_timecode timecode; 00076 static const unsigned NUM_BUFFER = 2; 00077 void *mem[NUM_BUFFER]; 00078 unsigned buf_length; 00079 unsigned char *rgb_frame, *last_yuv_frame; 00080 00081 /*------------------------- new camera class controls ---------------------*/ 00082 CSU32 V4L2_CTRL_CLASS_USER_NEW = 0x00980000; 00083 CSU32 V4L2_CID_BASE_NEW = V4L2_CTRL_CLASS_USER_NEW | 0x900; 00084 CSU32 V4L2_CID_POWER_LINE_FREQUENCY_NEW = V4L2_CID_BASE_NEW + 24; 00085 CSU32 V4L2_CID_HUE_AUTO_NEW = V4L2_CID_BASE_NEW + 25; 00086 CSU32 V4L2_CID_WHITE_BALANCE_TEMPERATURE_NEW = V4L2_CID_BASE_NEW + 26; 00087 CSU32 V4L2_CID_SHARPNESS_NEW = V4L2_CID_BASE_NEW + 27; 00088 CSU32 V4L2_CID_BACKLIGHT_COMPENSATION_NEW = V4L2_CID_BASE_NEW + 28; 00089 CSU32 V4L2_CID_LAST_NEW = V4L2_CID_BASE_NEW + 29; 00090 00091 CSU32 V4L2_CTRL_CLASS_CAMERA_NEW = 0x009A0000; /* Camera class controls */ 00092 CSU32 V4L2_CID_CAMERA_CLASS_BASE_NEW = V4L2_CTRL_CLASS_CAMERA_NEW | 0x900; 00093 CSU32 V4L2_CID_EXPOSURE_AUTO_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 1; 00094 CSU32 V4L2_CID_EXPOSURE_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 2; 00095 CSU32 V4L2_CID_EXPOSURE_AUTO_PRIORITY_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW+3; 00096 CSU32 V4L2_CID_PAN_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 4; 00097 CSU32 V4L2_CID_TILT_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 5; 00098 CSU32 V4L2_CID_PAN_RESET_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 6; 00099 CSU32 V4L2_CID_TILT_RESET_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 7; 00100 CSU32 V4L2_CID_PAN_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 8; 00101 CSU32 V4L2_CID_TILT_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 9; 00102 CSU32 V4L2_CID_FOCUS_ABSOLUTE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 10; 00103 CSU32 V4L2_CID_FOCUS_RELATIVE_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 11; 00104 CSU32 V4L2_CID_FOCUS_AUTO_NEW = V4L2_CID_CAMERA_CLASS_BASE_NEW + 12; 00105 CSU32 V4L2_CID_CAMERA_CLASS_LAST = V4L2_CID_CAMERA_CLASS_BASE_NEW + 13; 00106 00107 /*--------------- old private class controls ------------------------------*/ 00108 CSU32 V4L2_CID_PRIVATE_BASE_OLD = 0x08000000; 00109 CSU32 V4L2_CID_BACKLIGHT_COMPENSATION_OLD = V4L2_CID_PRIVATE_BASE_OLD + 0; 00110 CSU32 V4L2_CID_POWER_LINE_FREQUENCY_OLD = V4L2_CID_PRIVATE_BASE_OLD + 1; 00111 CSU32 V4L2_CID_SHARPNESS_OLD = V4L2_CID_PRIVATE_BASE_OLD + 2; 00112 CSU32 V4L2_CID_HUE_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 3; 00113 CSU32 V4L2_CID_FOCUS_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 4; 00114 CSU32 V4L2_CID_FOCUS_ABSOLUTE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 5; 00115 CSU32 V4L2_CID_FOCUS_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 6; 00116 CSU32 V4L2_CID_PAN_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 7; 00117 CSU32 V4L2_CID_TILT_RELATIVE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 8; 00118 CSU32 V4L2_CID_PANTILT_RESET_OLD = V4L2_CID_PRIVATE_BASE_OLD + 9; 00119 CSU32 V4L2_CID_EXPOSURE_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD + 10; 00120 CSU32 V4L2_CID_EXPOSURE_ABSOLUTE_OLD = V4L2_CID_PRIVATE_BASE_OLD + 11; 00121 CSU32 V4L2_CID_WHITE_BALANCE_TEMP_AUTO_OLD = V4L2_CID_PRIVATE_BASE_OLD+12; 00122 CSU32 V4L2_CID_WHITE_BALANCE_TEMP_OLD = V4L2_CID_PRIVATE_BASE_OLD + 13; 00123 CSU32 V4L2_CID_PRIVATE_LAST = V4L2_CID_WHITE_BALANCE_TEMP_OLD + 1; 00124 // dynamic controls 00125 CSU32 UVC_CTRL_DATA_TYPE_RAW = 0; 00126 CSU32 UVC_CTRL_DATA_TYPE_SIGNED = 1; 00127 CSU32 UVC_CTRL_DATA_TYPE_UNSIGNED = 2; 00128 CSU32 UVC_CTRL_DATA_TYPE_BOOLEAN = 3; 00129 CSU32 UVC_CTRL_DATA_TYPE_ENUM = 4; 00130 CSU32 UVC_CTRL_DATA_TYPE_BITMASK = 5; 00131 CSU32 V4L2_CID_BASE_EXTCTR = 0x0A046D01; 00132 CSU32 V4L2_CID_BASE_LOGITECH = V4L2_CID_BASE_EXTCTR; 00133 //CSU32 V4L2_CID_PAN_RELATIVE_LOGITECH = V4L2_CID_BASE_LOGITECH; 00134 //CSU32 V4L2_CID_TILT_RELATIVE_LOGITECH = V4L2_CID_BASE_LOGITECH + 1; 00135 CSU32 V4L2_CID_PANTILT_RESET_LOGITECH = V4L2_CID_BASE_LOGITECH + 2; 00136 CSU32 V4L2_CID_FOCUS_LOGITECH = V4L2_CID_BASE_LOGITECH + 3; 00137 CSU32 V4L2_CID_LED1_MODE_LOGITECH = V4L2_CID_BASE_LOGITECH + 4; 00138 CSU32 V4L2_CID_LED1_FREQUENCY_LOGITECH = V4L2_CID_BASE_LOGITECH + 5; 00139 CSU32 V4L2_CID_DISABLE_PROCESSING_LOGITECH = V4L2_CID_BASE_LOGITECH + 0x70; 00140 CSU32 V4L2_CID_RAW_BITS_PER_PIXEL_LOGITECH = V4L2_CID_BASE_LOGITECH + 0x71; 00141 CSU32 V4L2_CID_LAST_EXTCTR = V4L2_CID_RAW_BITS_PER_PIXEL_LOGITECH; 00142 00143 }; 00144 00145 } 00146 00147 #endif 00148