ibmcam.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. README for Linux device driver for the IBM "C-It" USB video camera
  2. INTRODUCTION:
  3. This driver does not use all features known to exist in
  4. the IBM camera. However most of needed features work well.
  5. This driver was developed using logs of observed USB traffic
  6. which was produced by standard Windows driver (c-it98.sys).
  7. I did not have data sheets from Xirlink.
  8. Video formats:
  9. 128x96 [model 1]
  10. 176x144
  11. 320x240 [model 2]
  12. 352x240 [model 2]
  13. 352x288
  14. Frame rate: 3 - 30 frames per second (FPS)
  15. External interface: USB
  16. Internal interface: Video For Linux (V4L)
  17. Supported controls:
  18. - by V4L: Contrast, Brightness, Color, Hue
  19. - by driver options: frame rate, lighting conditions, video format,
  20. default picture settings, sharpness.
  21. SUPPORTED CAMERAS:
  22. Xirlink "C-It" camera, also known as "IBM PC Camera".
  23. The device uses proprietary ASIC (and compression method);
  24. it is manufactured by Xirlink. See http://xirlinkwebcam.sourceforge.net,
  25. http://www.ibmpccamera.com, or http://www.c-itnow.com/ for details and pictures.
  26. This very chipset ("X Chip", as marked at the factory)
  27. is used in several other cameras, and they are supported
  28. as well:
  29. - IBM NetCamera
  30. - Veo Stingray
  31. The Linux driver was developed with camera with following
  32. model number (or FCC ID): KSX-XVP510. This camera has three
  33. interfaces, each with one endpoint (control, iso, iso). This
  34. type of cameras is referred to as "model 1". These cameras are
  35. no longer manufactured.
  36. Xirlink now manufactures new cameras which are somewhat different.
  37. In particular, following models [FCC ID] belong to that category:
  38. XVP300 [KSX-X9903]
  39. XVP600 [KSX-X9902]
  40. XVP610 [KSX-X9902]
  41. (see http://www.xirlink.com/ibmpccamera/ for updates, they refer
  42. to these new cameras by Windows driver dated 12-27-99, v3005 BETA)
  43. These cameras have two interfaces, one endpoint in each (iso, bulk).
  44. Such type of cameras is referred to as "model 2". They are supported
  45. (with exception of 352x288 native mode).
  46. Some IBM NetCameras (Model 4) are made to generate only compressed
  47. video streams. This is great for performance, but unfortunately
  48. nobody knows how to decompress the stream :-( Therefore, these
  49. cameras are *unsupported* and if you try to use one of those, all
  50. you get is random colored horizontal streaks, not the image!
  51. If you have one of those cameras, you probably should return it
  52. to the store and get something that is supported.
  53. Tell me more about all that "model" business
  54. --------------------------------------------
  55. I just invented model numbers to uniquely identify flavors of the
  56. hardware/firmware that were sold. It was very confusing to use
  57. brand names or some other internal numbering schemes. So I found
  58. by experimentation that all Xirlink chipsets fall into four big
  59. classes, and I called them "models". Each model is programmed in
  60. its own way, and each model sends back the video in its own way.
  61. Quirks of Model 2 cameras:
  62. -------------------------
  63. Model 2 does not have hardware contrast control. Corresponding V4L
  64. control is implemented in software, which is not very nice to your
  65. CPU, but at least it works.
  66. This driver provides 352x288 mode by switching the camera into
  67. quasi-352x288 RGB mode (800 Kbits per frame) essentially limiting
  68. this mode to 10 frames per second or less, in ideal conditions on
  69. the bus (USB is shared, after all). The frame rate
  70. has to be programmed very conservatively. Additional concern is that
  71. frame rate depends on brightness setting; therefore the picture can
  72. be good at one brightness and broken at another! I did not want to fix
  73. the frame rate at slowest setting, but I had to move it pretty much down
  74. the scale (so that framerate option barely matters). I also noticed that
  75. camera after first powering up produces frames slightly faster than during
  76. consecutive uses. All this means that if you use 352x288 (which is
  77. default), be warned - you may encounter broken picture on first connect;
  78. try to adjust brightness - brighter image is slower, so USB will be able
  79. to send all data. However if you regularly use Model 2 cameras you may
  80. prefer 176x144 which makes perfectly good I420, with no scaling and
  81. lesser demands on USB (300 Kbits per second, or 26 frames per second).
  82. Another strange effect of 352x288 mode is the fine vertical grid visible
  83. on some colored surfaces. I am sure it is caused by me not understanding
  84. what the camera is trying to say. Blame trade secrets for that.
  85. The camera that I had also has a hardware quirk: if disconnected,
  86. it needs few minutes to "relax" before it can be plugged in again
  87. (poorly designed USB processor reset circuit?)
  88. [Veo Stingray with Product ID 0x800C is also Model 2, but I haven't
  89. observed this particular flaw in it.]
  90. Model 2 camera can be programmed for very high sensitivity (even starlight
  91. may be enough), this makes it convenient for tinkering with. The driver
  92. code has enough comments to help a programmer to tweak the camera
  93. as s/he feels necessary.
  94. WHAT YOU NEED:
  95. - A supported IBM PC (C-it) camera (model 1 or 2)
  96. - A Linux box with USB support (2.3/2.4; 2.2 w/backport may work)
  97. - A Video4Linux compatible frame grabber program such as xawtv.
  98. HOW TO COMPILE THE DRIVER:
  99. You need to compile the driver only if you are a developer
  100. or if you want to make changes to the code. Most distributions
  101. precompile all modules, so you can go directly to the next
  102. section "HOW TO USE THE DRIVER".
  103. The ibmcam driver uses usbvideo helper library (module),
  104. so if you are studying the ibmcam code you will be led there.
  105. The driver itself consists of only one file in usb/ directory:
  106. ibmcam.c. This file is included into the Linux kernel build
  107. process if you configure the kernel for CONFIG_USB_IBMCAM.
  108. Run "make xconfig" and in USB section you will find the IBM
  109. camera driver. Select it, save the configuration and recompile.
  110. HOW TO USE THE DRIVER:
  111. I recommend to compile driver as a module. This gives you an
  112. easier access to its configuration. The camera has many more
  113. settings than V4L can operate, so some settings are done using
  114. module options.
  115. To begin with, on most modern Linux distributions the driver
  116. will be automatically loaded whenever you plug the supported
  117. camera in. Therefore, you don't need to do anything. However
  118. if you want to experiment with some module parameters then
  119. you can load and unload the driver manually, with camera
  120. plugged in or unplugged.
  121. Typically module is installed with command 'modprobe', like this:
  122. # modprobe ibmcam framerate=1
  123. Alternatively you can use 'insmod' in similar fashion:
  124. # insmod /lib/modules/2.x.y/usb/ibmcam.o framerate=1
  125. Module can be inserted with camera connected or disconnected.
  126. The driver can have options, though some defaults are provided.
  127. Driver options: (* indicates that option is model-dependent)
  128. Name Type Range [default] Example
  129. -------------- -------------- -------------- ------------------
  130. debug Integer 0-9 [0] debug=1
  131. flags Integer 0-0xFF [0] flags=0x0d
  132. framerate Integer 0-6 [2] framerate=1
  133. hue_correction Integer 0-255 [128] hue_correction=115
  134. init_brightness Integer 0-255 [128] init_brightness=100
  135. init_contrast Integer 0-255 [192] init_contrast=200
  136. init_color Integer 0-255 [128] init_color=130
  137. init_hue Integer 0-255 [128] init_hue=115
  138. lighting Integer 0-2* [1] lighting=2
  139. sharpness Integer 0-6* [4] sharpness=3
  140. size Integer 0-2* [2] size=1
  141. Options for Model 2 only:
  142. Name Type Range [default] Example
  143. -------------- -------------- -------------- ------------------
  144. init_model2_rg Integer 0..255 [0x70] init_model2_rg=128
  145. init_model2_rg2 Integer 0..255 [0x2f] init_model2_rg2=50
  146. init_model2_sat Integer 0..255 [0x34] init_model2_sat=65
  147. init_model2_yb Integer 0..255 [0xa0] init_model2_yb=200
  148. debug You don't need this option unless you are a developer.
  149. If you are a developer then you will see in the code
  150. what values do what. 0=off.
  151. flags This is a bit mask, and you can combine any number of
  152. bits to produce what you want. Usually you don't want
  153. any of extra features this option provides:
  154. FLAGS_RETRY_VIDIOCSYNC 1 This bit allows to retry failed
  155. VIDIOCSYNC ioctls without failing.
  156. Will work with xawtv, will not
  157. with xrealproducer. Default is
  158. not set.
  159. FLAGS_MONOCHROME 2 Activates monochrome (b/w) mode.
  160. FLAGS_DISPLAY_HINTS 4 Shows colored pixels which have
  161. magic meaning to developers.
  162. FLAGS_OVERLAY_STATS 8 Shows tiny numbers on screen,
  163. useful only for debugging.
  164. FLAGS_FORCE_TESTPATTERN 16 Shows blue screen with numbers.
  165. FLAGS_SEPARATE_FRAMES 32 Shows each frame separately, as
  166. it was received from the camera.
  167. Default (not set) is to mix the
  168. preceding frame in to compensate
  169. for occasional loss of Isoc data
  170. on high frame rates.
  171. FLAGS_CLEAN_FRAMES 64 Forces "cleanup" of each frame
  172. prior to use; relevant only if
  173. FLAGS_SEPARATE_FRAMES is set.
  174. Default is not to clean frames,
  175. this is a little faster but may
  176. produce flicker if frame rate is
  177. too high and Isoc data gets lost.
  178. FLAGS_NO_DECODING 128 This flag turns the video stream
  179. decoder off, and dumps the raw
  180. Isoc data from the camera into
  181. the reading process. Useful to
  182. developers, but not to users.
  183. framerate This setting controls frame rate of the camera. This is
  184. an approximate setting (in terms of "worst" ... "best")
  185. because camera changes frame rate depending on amount
  186. of light available. Setting 0 is slowest, 6 is fastest.
  187. Beware - fast settings are very demanding and may not
  188. work well with all video sizes. Be conservative.
  189. hue_correction This highly optional setting allows to adjust the
  190. hue of the image in a way slightly different from
  191. what usual "hue" control does. Both controls affect
  192. YUV colorspace: regular "hue" control adjusts only
  193. U component, and this "hue_correction" option similarly
  194. adjusts only V component. However usually it is enough
  195. to tweak only U or V to compensate for colored light or
  196. color temperature; this option simply allows more
  197. complicated correction when and if it is necessary.
  198. init_brightness These settings specify _initial_ values which will be
  199. init_contrast used to set up the camera. If your V4L application has
  200. init_color its own controls to adjust the picture then these
  201. init_hue controls will be used too. These options allow you to
  202. preconfigure the camera when it gets connected, before
  203. any V4L application connects to it. Good for webcams.
  204. init_model2_rg These initial settings alter color balance of the
  205. init_model2_rg2 camera on hardware level. All four settings may be used
  206. init_model2_sat to tune the camera to specific lighting conditions. These
  207. init_model2_yb settings only apply to Model 2 cameras.
  208. lighting This option selects one of three hardware-defined
  209. photosensitivity settings of the camera. 0=bright light,
  210. 1=Medium (default), 2=Low light. This setting affects
  211. frame rate: the dimmer the lighting the lower the frame
  212. rate (because longer exposition time is needed). The
  213. Model 2 cameras allow values more than 2 for this option,
  214. thus enabling extremely high sensitivity at cost of frame
  215. rate, color saturation and imaging sensor noise.
  216. sharpness This option controls smoothing (noise reduction)
  217. made by camera. Setting 0 is most smooth, setting 6
  218. is most sharp. Be aware that CMOS sensor used in the
  219. camera is pretty noisy, so if you choose 6 you will
  220. be greeted with "snowy" image. Default is 4. Model 2
  221. cameras do not support this feature.
  222. size This setting chooses one of several image sizes that are
  223. supported by this driver. Cameras may support more, but
  224. it's difficult to reverse-engineer all formats.
  225. Following video sizes are supported:
  226. size=0 128x96 (Model 1 only)
  227. size=1 160x120
  228. size=2 176x144
  229. size=3 320x240 (Model 2 only)
  230. size=4 352x240 (Model 2 only)
  231. size=5 352x288
  232. size=6 640x480 (Model 3 only)
  233. The 352x288 is the native size of the Model 1 sensor
  234. array, so it's the best resolution the camera can
  235. yield. The best resolution of Model 2 is 176x144, and
  236. larger images are produced by stretching the bitmap.
  237. Model 3 has sensor with 640x480 grid, and it works too,
  238. but the frame rate will be exceptionally low (1-2 FPS);
  239. it may be still OK for some applications, like security.
  240. Choose the image size you need. The smaller image can
  241. support faster frame rate. Default is 352x288.
  242. For more information and the Troubleshooting FAQ visit this URL:
  243. http://www.linux-usb.org/ibmcam/
  244. WHAT NEEDS TO BE DONE:
  245. - The button on the camera is not used. I don't know how to get to it.
  246. I know now how to read button on Model 2, but what to do with it?
  247. - Camera reports its status back to the driver; however I don't know
  248. what returned data means. If camera fails at some initialization
  249. stage then something should be done, and I don't do that because
  250. I don't even know that some command failed. This is mostly Model 1
  251. concern because Model 2 uses different commands which do not return
  252. status (and seem to complete successfully every time).
  253. - Some flavors of Model 4 NetCameras produce only compressed video
  254. streams, and I don't know how to decode them.
  255. CREDITS:
  256. The code is based in no small part on the CPiA driver by Johannes Erdfelt,
  257. Randy Dunlap, and others. Big thanks to them for their pioneering work on that
  258. and the USB stack.
  259. I also thank John Lightsey for his donation of the Veo Stingray camera.