Camera driver example code

Published on September 6, 2010

Archived Notice

This article has been archived and may contain broken links, photos and out-of-date information. If you have any questions, please Contact Us.

In my previous post, I promised a sample program for the camera driver, and you can now find it in our git repository. The sample program is camera_to_fb2 and is compilable both under Android and other Linux environments. It captures frames from the camera and displays them through /dev/fb2, the YUV output frame buffer. Its primary purpose is to validate the driver, so there isn't much in the way of features. You can invoke it like so: user@host:~$ camera_to_fb2 -iw640 -ih480 -ow640 -oh480 -4NV12 -x100 -y100 The command-line parameters are:

  • -iwN        the input (camera) width in pixels
  • -ihN         the input (camera) height in pixels
  • -owN       the output (display) width in pixels
  • -ohN        the output (display) height in pixels
  • -4XXXX the camera and display pixel format as a fourcc code
  • -xN          the X position of the output window
  • -yN          the Y position of the output window
The only currently supported fourcc code is NV12, and the supported input width and heights are:
  • 480x272
  • 640x480
  • 2592x1944
As mentioned in the driver post, more resolutions will follow, as will support for JPEG input.

General Linux usage:

root@device:~# modprobe boundary_camera root@device:~# camera_to_fb2 -iw640 -ih480 -ow640 -oh480 -4NV12 -x100 -y100

Android usage:

user@host:~$ adb shell 'insmod /system/lib/modules/ov5640.ko' user@host:~$ adb shell 'insmod /system/lib/modules/boundary_camera.ko' user@host:~$ adb shell 'camera_to_fb2 -iw640 -ih480 -ow640 -oh480 -4NV12 -x100 -y100' No support is currently present for running this from the Android GUI, since this should be integrated as a proper Android Camera driver instead. Also note that you can add the insmod lines into device/fsl/imx5x/init.rc to skip the manual insmod steps, but you'll need to re-create the ramdisk and update the SD card afterwards.