Classes | Defines | Functions | Variables
usb_cam.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#include <linux/videodev2.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <usb_cam/usb_cam.h>
Include dependency graph for usb_cam.cpp:

Go to the source code of this file.

Classes

struct  buffer

Defines

#define __STDC_CONSTANT_MACROS
#define CLEAR(x)   memset (&(x), 0, sizeof (x))

Functions

static unsigned char CLIPVALUE (int val)
static void close_device (void)
static void errno_exit (const char *s)
static void init_device (int image_width, int image_height)
static int init_mjpeg_decoder (int image_width, int image_height)
static void init_mmap (void)
static void init_read (unsigned int buffer_size)
static void init_userp (unsigned int buffer_size)
static void mjpeg2rgb (char *MJPEG, int len, char *RGB, int NumPixels)
static void open_device (void)
static void process_image (const void *src, int len, usb_cam_camera_image_t *dest)
static int read_frame (usb_cam_camera_image_t *image)
static void start_capturing (void)
static void stop_capturing (void)
static void uninit_device (void)
void usb_cam_camera_grab_image (usb_cam_camera_image_t *image)
void usb_cam_camera_set_auto_focus (int value)
void usb_cam_camera_shutdown (void)
usb_cam_camera_image_tusb_cam_camera_start (const char *dev, usb_cam_io_method io_method, usb_cam_pixel_format pixel_format, int image_width, int image_height)
void uyvy2rgb (char *YUV, char *RGB, int NumPixels)
static int xioctl (int fd, int request, void *arg)
static void YUV2RGB (const unsigned char y, const unsigned char u, const unsigned char v, unsigned char *r, unsigned char *g, unsigned char *b)
static void yuyv2rgb (char *YUV, char *RGB, int NumPixels)

Variables

static AVCodec * avcodec = NULL
static AVCodecContext * avcodec_context = NULL
static AVFrame * avframe_camera = NULL
static int avframe_camera_size = 0
static AVFrame * avframe_rgb = NULL
static int avframe_rgb_size = 0
struct bufferbuffers = NULL
static char * camera_dev
const int clipping_table_offset = 128
static int fd = -1
static usb_cam_io_method io = IO_METHOD_MMAP
static unsigned int n_buffers = 0
static unsigned int pixelformat
const unsigned char uchar_clipping_table []
struct SwsContext * video_sws = NULL

Define Documentation

Definition at line 36 of file usb_cam.cpp.

#define CLEAR (   x)    memset (&(x), 0, sizeof (x))

Definition at line 61 of file usb_cam.cpp.


Function Documentation

static unsigned char CLIPVALUE ( int  val) [static]

Clip a value to the range 0<val<255. For speed this is done using an array, so can only cope with numbers in the range -128<val<383.

Definition at line 172 of file usb_cam.cpp.

static void close_device ( void  ) [static]

Definition at line 795 of file usb_cam.cpp.

static void errno_exit ( const char *  s) [static]

Definition at line 83 of file usb_cam.cpp.

static void init_device ( int  image_width,
int  image_height 
) [static]

Definition at line 684 of file usb_cam.cpp.

static int init_mjpeg_decoder ( int  image_width,
int  image_height 
) [static]

Definition at line 280 of file usb_cam.cpp.

static void init_mmap ( void  ) [static]

Definition at line 591 of file usb_cam.cpp.

static void init_read ( unsigned int  buffer_size) [static]

Definition at line 573 of file usb_cam.cpp.

static void init_userp ( unsigned int  buffer_size) [static]

Definition at line 642 of file usb_cam.cpp.

static void mjpeg2rgb ( char *  MJPEG,
int  len,
char *  RGB,
int  NumPixels 
) [static]

Definition at line 320 of file usb_cam.cpp.

static void open_device ( void  ) [static]

Definition at line 803 of file usb_cam.cpp.

static void process_image ( const void *  src,
int  len,
usb_cam_camera_image_t dest 
) [static]

Definition at line 367 of file usb_cam.cpp.

static int read_frame ( usb_cam_camera_image_t image) [static]

Definition at line 377 of file usb_cam.cpp.

static void start_capturing ( void  ) [static]

Definition at line 493 of file usb_cam.cpp.

static void stop_capturing ( void  ) [static]

Definition at line 473 of file usb_cam.cpp.

static void uninit_device ( void  ) [static]

Definition at line 549 of file usb_cam.cpp.

Definition at line 883 of file usb_cam.cpp.

void usb_cam_camera_set_auto_focus ( int  value)

Definition at line 915 of file usb_cam.cpp.

void usb_cam_camera_shutdown ( void  )

Definition at line 864 of file usb_cam.cpp.

usb_cam_camera_image_t* usb_cam_camera_start ( const char *  dev,
usb_cam_io_method  io_method,
usb_cam_pixel_format  pixel_format,
int  image_width,
int  image_height 
)

Definition at line 825 of file usb_cam.cpp.

void uyvy2rgb ( char *  YUV,
char *  RGB,
int  NumPixels 
)

Definition at line 236 of file usb_cam.cpp.

static int xioctl ( int  fd,
int  request,
void *  arg 
) [static]

Definition at line 90 of file usb_cam.cpp.

static void YUV2RGB ( const unsigned char  y,
const unsigned char  u,
const unsigned char  v,
unsigned char *  r,
unsigned char *  g,
unsigned char *  b 
) [static]

Conversion from YUV to RGB. The normal conversion matrix is due to Julien (surname unknown):

[ R ] [ 1.0 0.0 1.403 ] [ Y ] [ G ] = [ 1.0 -0.344 -0.714 ] [ U ] [ B ] [ 1.0 1.770 0.0 ] [ V ]

and the firewire one is similar:

[ R ] [ 1.0 0.0 0.700 ] [ Y ] [ G ] = [ 1.0 -0.198 -0.291 ] [ U ] [ B ] [ 1.0 1.015 0.0 ] [ V ]

Corrected by BJT (coriander's transforms RGB->YUV and YUV->RGB do not get you back to the same RGB!) [ R ] [ 1.0 0.0 1.136 ] [ Y ] [ G ] = [ 1.0 -0.396 -0.578 ] [ U ] [ B ] [ 1.0 2.041 0.002 ] [ V ]

Definition at line 204 of file usb_cam.cpp.

static void yuyv2rgb ( char *  YUV,
char *  RGB,
int  NumPixels 
) [static]

Definition at line 258 of file usb_cam.cpp.


Variable Documentation

AVCodec* avcodec = NULL [static]

Definition at line 76 of file usb_cam.cpp.

AVCodecContext* avcodec_context = NULL [static]

Definition at line 77 of file usb_cam.cpp.

AVFrame* avframe_camera = NULL [static]

Definition at line 74 of file usb_cam.cpp.

int avframe_camera_size = 0 [static]

Definition at line 78 of file usb_cam.cpp.

AVFrame* avframe_rgb = NULL [static]

Definition at line 75 of file usb_cam.cpp.

int avframe_rgb_size = 0 [static]

Definition at line 79 of file usb_cam.cpp.

struct buffer* buffers = NULL

Definition at line 72 of file usb_cam.cpp.

char* camera_dev [static]

Definition at line 68 of file usb_cam.cpp.

const int clipping_table_offset = 128

Definition at line 166 of file usb_cam.cpp.

int fd = -1 [static]

Definition at line 71 of file usb_cam.cpp.

Definition at line 70 of file usb_cam.cpp.

unsigned int n_buffers = 0 [static]

Definition at line 73 of file usb_cam.cpp.

unsigned int pixelformat [static]

Definition at line 69 of file usb_cam.cpp.

const unsigned char uchar_clipping_table[]

Definition at line 100 of file usb_cam.cpp.

struct SwsContext* video_sws = NULL

Definition at line 81 of file usb_cam.cpp.



usb_cam
Author(s): Benjamin Pitzer
autogenerated on Mon Oct 6 2014 10:09:47