luvcview.c

00001 /*******************************************************************************
00002 #                 luvcview: Sdl video Usb Video Class grabber           .        #
00003 #This package work with the Logitech UVC based webcams with the mjpeg feature. #
00004 #All the decoding is in user space with the embedded jpeg decoder              #
00005 #.                                                                             #
00006 #                 Copyright (C) 2005 2006 Laurent Pinchart &&  Michel Xhaard     #
00007 #                                                                              #
00008 # This program is free software; you can redistribute it and/or modify         #
00009 # it under the terms of the GNU General Public License as published by         #
00010 # the Free Software Foundation; either version 2 of the License, or            #
00011 # (at your option) any later version.                                          #
00012 #                                                                              #
00013 # This program is distributed in the hope that it will be useful,              #
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of               #
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
00016 # GNU General Public License for more details.                                 #
00017 #                                                                              #
00018 # You should have received a copy of the GNU General Public License            #
00019 # along with this program; if not, write to the Free Software                  #
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    #
00021 #                                                                              #
00022 *******************************************************************************/
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <unistd.h>
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <sys/file.h>
00030 #include <string.h>
00031 #include <pthread.h>
00032 #include <linux/videodev.h>
00033 #include <sys/ioctl.h>
00034 #include <sys/mman.h>
00035 #include <errno.h>
00036 #include <fcntl.h>
00037 #include <time.h>
00038 #include <sys/time.h>
00039 #include <signal.h>
00040 #include "v4l2uvc.h"
00041 #include "gui.h"
00042 #include "utils.h"
00043 #include "color.h"
00044 /* Fixed point arithmetic */
00045 #define FIXED Sint32
00046 #define FIXED_BITS 16
00047 #define TO_FIXED(X) (((Sint32)(X))<<(FIXED_BITS))
00048 #define FROM_FIXED(X) (((Sint32)(X))>>(FIXED_BITS))
00049 
00050 #define INCPANTILT 64 // 1°
00051 
00052 static const char version[] = VERSION;
00053 struct vdIn *videoIn;
00054 
00055 int main(int argc, char *argv[])
00056 {
00057 
00058         int status;
00059         int currtime;
00060         int lasttime;
00061         unsigned char *p = NULL;
00062         int hwaccel = 0;
00063         const char *videodevice = NULL;
00064         const char *mode = NULL;
00065         //int format = V4L2_PIX_FMT_MJPEG;
00066         int format = V4L2_PIX_FMT_YUYV;
00067         int i;
00068         int grabmethod = 1;
00069         int width = 640;
00070         int height = 480;
00071         int fps = 30;
00072         unsigned char frmrate = 0;
00073         char *avifilename = NULL;
00074         int queryformats = 0;
00075         int querycontrols = 0;
00076         int readconfigfile = 0;
00077         char *separateur;
00078         char *sizestring = NULL;
00079         char *fpsstring  = NULL;
00080         int enableRawStreamCapture = 0;
00081         int enableRawFrameCapture = 0;
00082 
00083         printf("luvcview %s\n\n", version);
00084 
00085   videodevice = "/dev/video0";
00086 
00087         videoIn = (struct vdIn *) calloc(1, sizeof(struct vdIn));
00088         if ( queryformats ) {
00089                 /* if we're supposed to list the video formats, do that now and go out */
00090                 check_videoIn(videoIn,(char *) videodevice);
00091                 free(videoIn);
00092                 exit(1);
00093         }
00094 
00095         if (init_videoIn
00096                         (videoIn, (char *) videodevice, width, height, fps, format,
00097                          grabmethod, avifilename) < 0)
00098                 exit(1);
00099 
00100         /* if we're supposed to list the controls, do that now */
00101         if ( querycontrols )
00102                 enum_controls(videoIn->fd);
00103 
00104   /* if we're supposed to read the control settings from a configfile, do that now */
00105   if ( readconfigfile )
00106     load_controls(videoIn->fd);
00107 
00108 
00109   if (enableRawFrameCapture)
00110     videoIn->rawFrameCapture = enableRawFrameCapture;
00111 
00112         //initLut();
00113 
00114         /* main big loop */
00115         while (videoIn->signalquit) {
00116                 //currtime = SDL_GetTicks();
00117                 //if (currtime - lasttime > 0) {
00118                 //        frmrate = 1000/(currtime - lasttime);
00119                 //}
00120                 lasttime = currtime;
00121                 if (uvcGrab(videoIn) < 0) {
00122                         printf("Error grabbing\n");
00123                         break;
00124                 }
00125 
00126                 /* if we're grabbing video, show the frame rate */
00127     printf("frame rate: %d     \n",frmrate);
00128 
00129                 ////videoIn->framebuffer, videoIn->width * (videoIn->height) * 2);
00130     //
00131     //videoIn->getPict=1;
00132                 if (videoIn->getPict) {
00133                         switch(videoIn->formatIn){
00134                                 case V4L2_PIX_FMT_MJPEG:
00135                                         get_picture(videoIn->tmpbuffer,videoIn->buf.bytesused);
00136                                         break;
00137                                 case V4L2_PIX_FMT_YUYV:
00138                                         get_pictureYV2(videoIn->framebuffer,videoIn->width,videoIn->height);
00139                                         break;
00140                                 default:
00141                                         break;
00142                         }
00143                         videoIn->getPict = 0;
00144                         printf("get picture !\n");
00145                 }
00146 
00147         }
00148 
00149         close_v4l2(videoIn);
00150         free(videoIn);
00151         //freeLut();
00152         printf("Cleanup done. Exiting ...\n");
00153 }
00154 
Generated on Sun May 8 08:41:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3