예제 #1
0
파일: v4l2-cli.c 프로젝트: yucai/BLTS
static int v4l2_case_check_controls(void* user_ptr, int test_num)
{
	v4l2_data* data = (v4l2_data*)user_ptr;

	BLTS_DEBUG("Test number %i:\n", test_num);
	int w = MAX_WIDTH;
	int h = MAX_HEIGHT;


	if( open_device (data->device) && init_device (data->device, w, h))
	{
		BLTS_DEBUG("Device opened\n");
		if(!enum_controls(data->device))
			return -1;
		return 0;
	}
	else
	{
		BLTS_DEBUG("Can't open device %s\n", data->device->dev_name);
		close_device(data->device);
		return -1;
	}
	close_device(data->device);
	return 0;
}
예제 #2
0
파일: luvcview.c 프로젝트: wushifeng/arm
int main(int argc, char *argv[])
{
#ifndef EMBEDED_X210  //PC platform
    const SDL_VideoInfo *info;
    char driver[128];
    SDL_Surface *pscreen;
    SDL_Overlay *overlay;
    SDL_Rect drect;
    SDL_Event sdlevent;
    SDL_Thread *mythread;
    SDL_mutex *affmutex;
    Uint32 currtime;
    Uint32 lasttime;
#endif
    int status;

    unsigned char *p = NULL;
    int hwaccel = 0;
    const char *videodevice = NULL;
    const char *mode = NULL;
    int format = V4L2_PIX_FMT_MJPEG;
    int i;
    int grabmethod = 1;
    int width = 320;
    int height = 240;
    int fps = 15;
    unsigned char frmrate = 0;
    char *avifilename = NULL;
    int queryformats = 0;
    int querycontrols = 0;
    int readconfigfile = 0;
    char *separateur;
    char *sizestring = NULL;
    char *fpsstring  = NULL;
    int enableRawStreamCapture = 0;
    int enableRawFrameCapture = 0;
    char * pRGBData=NULL;



    printf("luvcview version %s \n", version);
    for (i = 1; i < argc; i++)
    {
        /* skip bad arguments */
        if (argv[i] == NULL || *argv[i] == 0 || *argv[i] != '-') {
            continue;
        }
        if (strcmp(argv[i], "-d") == 0) {
            if (i + 1 >= argc) {
                printf("No parameter specified with -d, aborting.\n");
                exit(1);
            }
            videodevice = strdup(argv[i + 1]);
        }
        if (strcmp(argv[i], "-g") == 0) {
            /* Ask for read instead default  mmap */
            grabmethod = 0;
        }
        if (strcmp(argv[i], "-w") == 0) {
            /* disable hw acceleration */
            hwaccel = 1;
        }
        if (strcmp(argv[i], "-f") == 0) {
            if (i + 1 >= argc) {
                printf("No parameter specified with -f, aborting.\n");
                exit(1);
            }
            mode = strdup(argv[i + 1]);

            if (strncmp(mode, "yuv", 3) == 0) {
                format = V4L2_PIX_FMT_YUYV;

            } else if (strncmp(mode, "jpg", 3) == 0) {
                format = V4L2_PIX_FMT_MJPEG;

            } else {
                format = V4L2_PIX_FMT_MJPEG;

            }
        }
        if (strcmp(argv[i], "-s") == 0) {
            if (i + 1 >= argc) {
                printf("No parameter specified with -s, aborting.\n");
                exit(1);
            }

            sizestring = strdup(argv[i + 1]);

            width = strtoul(sizestring, &separateur, 10);
            if (*separateur != 'x') {
                printf("Error in size use -s widthxheight \n");
                exit(1);
            } else {
                ++separateur;
                height = strtoul(separateur, &separateur, 10);
                if (*separateur != 0)
                    printf("hmm.. dont like that!! trying this height \n");
                printf(" size width: %d height: %d \n", width, height);
            }
        }
        if (strcmp(argv[i], "-i") == 0){
            if (i + 1 >= argc) {
                printf("No parameter specified with -i, aborting. \n");
                exit(1);
            }
            fpsstring = strdup(argv[i + 1]);
            fps = strtoul(fpsstring, &separateur, 10);
            printf(" interval: %d fps \n", fps);
        }
        if (strcmp(argv[i], "-S") == 0) {
            /* Enable raw stream capture from the start */
            enableRawStreamCapture = 1;
        }
        if (strcmp(argv[i], "-c") == 0) {
            /* Enable raw frame capture for the first frame */
            enableRawFrameCapture = 1;
        }
        if (strcmp(argv[i], "-C") == 0) {
            /* Enable raw frame stream capture from the start*/
            enableRawFrameCapture = 2;
        }
        if (strcmp(argv[i], "-o") == 0) {
            /* set the avi filename */
            if (i + 1 >= argc) {
                printf("No parameter specified with -o, aborting.\n");
                exit(1);
            }
            avifilename = strdup(argv[i + 1]);
        }
        if (strcmp(argv[i], "-L") == 0) {
            /* query list of valid video formats */
            queryformats = 1;
        }
        if (strcmp(argv[i], "-l") == 0) {
            /* query list of valid video formats */
            querycontrols = 1;
        }

        if (strcmp(argv[i], "-r") == 0) {
            /* query list of valid video formats */
            readconfigfile = 1;
        }
        if (strcmp(argv[i], "-h") == 0) {
            printf("usage: uvcview [-h -d -g -f -s -i -c -o -C -S -L -l -r] \n");
            printf("-h	print this message \n");
            printf("-d	/dev/videoX       use videoX device\n");
            printf("-g	use read method for grab instead mmap \n");
            printf("-w	disable SDL hardware accel. \n");
            printf("-f	video format  default jpg  others options are yuv jpg \n");
            printf("-i	fps           use specified frame interval \n");
            printf("-s	widthxheight      use specified input size \n");
            printf("-c	enable raw frame capturing for the first frame\n");
            printf("-C	enable raw frame stream capturing from the start\n");
            printf("-S	enable raw stream capturing from the start\n");
            printf("-o	avifile  create avifile, default video.avi\n");
            printf("-L	query valid video formats\n");
            printf("-l	query valid controls and settings\n");
            printf("-r	read and set control settings from luvcview.cfg\n");
            exit(0);
        }
    }

#ifndef   EMBEDED_X210 //PC platform

    /************* Test SDL capabilities ************/
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    
    /* For this version, we'll be save and disable hardware acceleration */
    if(hwaccel)
    {
        if ( ! getenv("SDL_VIDEO_YUV_HWACCEL") )
        {
            putenv("SDL_VIDEO_YUV_HWACCEL=0");
        }
    }

    if (SDL_VideoDriverName(driver, sizeof(driver)))
    {
        printf("Video driver: %s\n", driver);
    }
    info = SDL_GetVideoInfo();

    if (info->wm_available) {
        printf("A window manager is available\n");
    }
    if (info->hw_available) {
        printf("Hardware surfaces are available (%dK video memory)\n",
               info->video_mem);
        SDL_VIDEO_Flags |= SDL_HWSURFACE;
    }
    if (info->blit_hw) {
        printf("Copy blits between hardware surfaces are accelerated\n");
        SDL_VIDEO_Flags |= SDL_ASYNCBLIT;
    }
    if (info->blit_hw_CC) {
        printf
                ("Colorkey blits between hardware surfaces are accelerated\n");
    }
    if (info->blit_hw_A) {
        printf("Alpha blits between hardware surfaces are accelerated\n");
    }
    if (info->blit_sw) {
        printf
                ("Copy blits from software surfaces to hardware surfaces are accelerated\n");
    }
    if (info->blit_sw_CC) {
        printf
                ("Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
    }
    if (info->blit_sw_A) {
        printf
                ("Alpha blits from software surfaces to hardware surfaces are accelerated\n");
    }
    if (info->blit_fill) {
        printf("Color fills on hardware surfaces are accelerated\n");
    }



    if (!(SDL_VIDEO_Flags & SDL_HWSURFACE))
        SDL_VIDEO_Flags |= SDL_SWSURFACE;

#endif

    if (videodevice == NULL || *videodevice == 0) {
        videodevice = "/dev/video0";
    }

    if (avifilename == NULL || *avifilename == 0) {
        avifilename = "video.avi";
    }

    videoIn = (struct vdIn *) calloc(1, sizeof(struct vdIn));
    if ( queryformats ) {
        /* if we're supposed to list the video formats, do that now and go out */
        check_videoIn(videoIn,(char *) videodevice);
        free(videoIn);
#ifndef EMBEDED_X210
        SDL_Quit();
#endif
        exit(1);
    }

    if (init_videoIn(videoIn, (char *) videodevice, width, height, fps, format, grabmethod, avifilename) < 0)
        exit(1);
    /* if we're supposed to list the controls, do that now */
    if ( querycontrols )
        enum_controls(videoIn->fd);
    
    /* if we're supposed to read the control settings from a configfile, do that now */
    if ( readconfigfile )
        load_controls(videoIn->fd);


#ifdef EMBEDED_X210
#ifdef SOFT_COLOR_CONVERT
    init_framebuffer();
#else
    x6410_init_Draw(videoIn->width,videoIn->height);
#endif

#else
    pscreen = SDL_SetVideoMode(videoIn->width, videoIn->height+30 , 0,SDL_VIDEO_Flags);
    overlay =SDL_CreateYUVOverlay(videoIn->width, videoIn->height+30 , SDL_YUY2_OVERLAY, pscreen);
    p = (unsigned char *) overlay->pixels[0];

    drect.x = 0;
    drect.y = 0;
    drect.w =pscreen->w;
    drect.h = pscreen->h;

#endif

    if (enableRawStreamCapture)
    {
        videoIn->captureFile = fopen("stream.raw", "wb");
        if(videoIn->captureFile == NULL) {
            perror("Unable to open file for raw stream capturing");
        } else {
            printf("Starting raw stream capturing to stream.raw ...\n");
        }
    }
    if (enableRawFrameCapture)
        videoIn->rawFrameCapture = enableRawFrameCapture;

    initLut();

#ifndef EMBEDED_X210
    SDL_WM_SetCaption(title_act[A_VIDEO].title, NULL);
    lasttime = SDL_GetTicks();
    creatButt(videoIn->width, 32);
    SDL_LockYUVOverlay(overlay);
    memcpy(p + (videoIn->width * (videoIn->height) * 2), YUYVbutt,
           videoIn->width * 64);
    SDL_UnlockYUVOverlay(overlay);

    /* initialize thread data */
    ptdata.ptscreen = &pscreen;
    ptdata.ptvideoIn = videoIn;
    ptdata.ptsdlevent = &sdlevent;
    ptdata.drect = &drect;
    affmutex = SDL_CreateMutex();
    ptdata.affmutex = affmutex;
    mythread = SDL_CreateThread(eventThread, (void *) &ptdata);
#endif



    pRGBData = (unsigned char *)malloc(videoIn->width*videoIn->width*4*sizeof(char));
    if(pRGBData==NULL)
    {
        return ;
	}
    /* main big loop */
    while (videoIn->signalquit)
    {
#ifndef EMBEDED_X210
        currtime = SDL_GetTicks();
        if (currtime - lasttime > 0) {
            frmrate = 1000/(currtime - lasttime);
        }
        lasttime = currtime;
#endif
        if (uvcGrab(videoIn) < 0) {
            printf("Error grabbing \n");
            break;
        }

        /* if we're grabbing video, show the frame rate */
        if (videoIn->toggleAvi)
            printf("\rframe rate: %d     ",frmrate);

#ifndef EMBEDED_X210
        SDL_LockYUVOverlay(overlay);
        memcpy(p, videoIn->framebuffer, videoIn->width * (videoIn->height) * 2);
        SDL_UnlockYUVOverlay(overlay);
        SDL_DisplayYUVOverlay(overlay, &drect);
#endif

#ifdef EMBEDED_X210
#ifdef SOFT_COLOR_CONVERT
        // yuv to rgb565 ,and to frambuffer
        process_image(videoIn->framebuffer,fbp,videoIn->width,videoIn->height,vinfo,finfo);
    
    //    convertYUYVtoRGB565(videoIn->framebuffer,pRGBData,videoIn->width,videoIn->height);

   //   Pyuv422torgb24(videoIn->framebuffer, pRGBData, videoIn->width, videoIn->height);
    //    memcpy(fbp,pRGBData,videoIn->width*videoIn->height*2);
     
     

#else   //X6410 post processor convert yuv to rgb,X210 not suport now.

        /*
        memcpy(pInbuffer, videoIn->framebuffer, videoIn->width * (videoIn->height) * 2);

        ioctl(dev_fb0, GET_FB_INFO, &fb_info);

        pp_param.SrcFrmSt = ioctl(dev_pp, S3C_PP_GET_RESERVED_MEM_ADDR_PHY); //must be  physical adress
        pp_param.DstFrmSt = fb_info.map_dma_f1; //must be physical adress

        ioctl(dev_pp, S3C_PP_SET_PARAMS, &pp_param);
        ioctl(dev_pp, S3C_PP_SET_DST_BUF_ADDR_PHY, &pp_param);
        ioctl(dev_pp, S3C_PP_SET_SRC_BUF_ADDR_PHY, &pp_param);
        ioctl(dev_pp, S3C_PP_START);
        */
#endif
#endif
        if (videoIn->getPict)
        {
            switch(videoIn->formatIn){
            case V4L2_PIX_FMT_MJPEG:
                get_picture(videoIn->tmpbuffer,videoIn->buf.bytesused);
                break;
            case V4L2_PIX_FMT_YUYV:
                get_pictureYV2(videoIn->framebuffer,videoIn->width,videoIn->height);
                break;
            default:
                break;
            }
            videoIn->getPict = 0;
            printf("get picture !\n");
        }

#ifndef EMBEDED_X210
        SDL_LockMutex(affmutex);
        ptdata.frmrate = frmrate;
        SDL_WM_SetCaption(videoIn->status, NULL);
        SDL_UnlockMutex(affmutex);
#endif

#ifdef  EMBEDED_X210
        usleep(10);
#else
        SDL_Delay(10);
#endif


    }
#ifndef EMBEDED_X210
    SDL_WaitThread(mythread, &status);
    SDL_DestroyMutex(affmutex);
#endif
    /* if avifile is defined, we made a video: compute the exact fps and
       set it in the video */
    if (videoIn->avifile != NULL) {
        float fps=(videoIn->framecount/(videoIn->recordtime/1000));
        fprintf(stderr,"setting fps to %f\n",fps);
        AVI_set_video(videoIn->avifile, videoIn->width, videoIn->height,
                      fps, "MJPG");
        AVI_close(videoIn->avifile);
    }

    close_v4l2(videoIn);

#ifdef EMBEDED_X210
#ifdef SOFT_COLOR_CONVERT
    close_frambuffer();
#else
    x6410_DeInit_Draw();
#endif

#endif
    free(pRGBData);
    free(videoIn);
    destroyButt();
    freeLut();
    printf(" Clean Up done Quit \n");
#ifndef EMBEDED_X210
    SDL_Quit();
#endif
}
예제 #3
0
파일: luvcview.c 프로젝트: 0x7d/cameraCodes
int main(int argc, char *argv[]) {
	char driver[128];
	int status;
	//Uint32 currtime;
	//Uint32 lasttime;
	unsigned char *p = NULL;
	int hwaccel = 0;
	const char *videodevice = NULL;
	const char *mode = NULL;
	int format = V4L2_PIX_FMT_MJPEG;
	int i;
	int grabmethod = 1;
	int width = 320;
	int height = 240;
	int fps = 15;
	unsigned char frmrate = 0;
	char *avifilename = NULL;
	int queryformats = 0;
	int querycontrols = 0;
	int readconfigfile = 0;
	char *separateur;
	char *sizestring = NULL;
	char *fpsstring = NULL;
	int enableRawStreamCapture = 0;
	int enableRawFrameCapture = 0;

	printf("luvcview version %s \n", version);
	for (i = 1; i < argc; i++) {
		/* skip bad arguments */
		if (argv[i] == NULL || *argv[i] == 0 || *argv[i] != '-') {
			continue;
		}
		if (strcmp(argv[i], "-d") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -d, aborting.\n");
				exit(1);
			}
			videodevice = strdup(argv[i + 1]);
		}
		if (strcmp(argv[i], "-g") == 0) {
			/* Ask for read instead default  mmap */
			grabmethod = 0;
		}
		if (strcmp(argv[i], "-w") == 0) {
			/* disable hw acceleration */
			hwaccel = 1;
		}
		if (strcmp(argv[i], "-f") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -f, aborting.\n");
				exit(1);
			}
			mode = strdup(argv[i + 1]);

			if (strncmp(mode, "yuv", 3) == 0) {
				format = V4L2_PIX_FMT_YUYV;

			} else if (strncmp(mode, "jpg", 3) == 0) {
				format = V4L2_PIX_FMT_MJPEG;

			} else {
				format = V4L2_PIX_FMT_JPEG;

			}
		}
		if (strcmp(argv[i], "-s") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -s, aborting.\n");
				exit(1);
			}

			sizestring = strdup(argv[i + 1]);

			width = strtoul(sizestring, &separateur, 10);
			if (*separateur != 'x') {
				printf("Error in size use -s widthxheight \n");
				exit(1);
			} else {
				++separateur;
				height = strtoul(separateur, &separateur, 10);
				if (*separateur != 0)
					printf("hmm.. dont like that!! trying this height \n");
				printf(" size width: %d height: %d \n", width, height);
			}
		}
		if (strcmp(argv[i], "-i") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -i, aborting. \n");
				exit(1);
			}
			fpsstring = strdup(argv[i + 1]);
			fps = strtoul(fpsstring, &separateur, 10);
			printf(" interval: %d fps \n", fps);
		}
		if (strcmp(argv[i], "-S") == 0) {
			/* Enable raw stream capture from the start */
			enableRawStreamCapture = 1;
		}
		if (strcmp(argv[i], "-c") == 0) {
			/* Enable raw frame capture for the first frame */
			enableRawFrameCapture = 1;
		}
		if (strcmp(argv[i], "-C") == 0) {
			/* Enable raw frame stream capture from the start*/
			enableRawFrameCapture = 2;
		}
		if (strcmp(argv[i], "-o") == 0) {
			/* set the avi filename */
			if (i + 1 >= argc) {
				printf("No parameter specified with -o, aborting.\n");
				exit(1);
			}
			avifilename = strdup(argv[i + 1]);
		}
		if (strcmp(argv[i], "-L") == 0) {
			/* query list of valid video formats */
			queryformats = 1;
		}
		if (strcmp(argv[i], "-l") == 0) {
			/* query list of valid video formats */
			querycontrols = 1;
		}

		if (strcmp(argv[i], "-r") == 0) {
			/* query list of valid video formats */
			readconfigfile = 1;
		}

		if (strcmp(argv[i], "-O") == 0) {
			/* get picture */
			getpictureflag = 1;
		}

		if (strcmp(argv[i], "-h") == 0) {
			printf(
					"usage: uvcview [-h -d -g -f -s -i -c -o -C -S -L -l -r] \n");
			printf("-h	print this message \n");
			printf("-d	/dev/videoX       use videoX device\n");
			printf("-g	use read method for grab instead mmap \n");
			printf("-w	disable SDL hardware accel. \n");
			printf(
					"-f	video format  default jpg  others options are yuv jpg \n");
			printf("-i	fps           use specified frame interval \n");
			printf("-s	widthxheight      use specified input size \n");
			printf("-c	enable raw frame capturing for the first frame\n");
			printf("-C	enable raw frame stream capturing from the start\n");
			printf("-S	enable raw stream capturing from the start\n");
			printf("-o	avifile  create avifile, default video.avi\n");
			printf("-L	query valid video formats\n");
			printf("-l	query valid controls and settings\n");
			printf("-r	read and set control settings from luvcview.cfg\n");
			printf("-O	get picture.\n");
			exit(0);
		}
	}

	if (videodevice == NULL || *videodevice == 0) {
		videodevice = "/dev/video0";
	}

	if (avifilename == NULL || *avifilename == 0) {
		avifilename = "video.avi";
	}

	videoIn = (struct vdIn *) calloc(1, sizeof(struct vdIn));
	if (queryformats) {
		/* if we're supposed to list the video formats, do that now and go out */
		check_videoIn(videoIn, (char *) videodevice);
		free(videoIn);
		exit(1);
	}
	if (init_videoIn(videoIn, (char *) videodevice, width, height, fps, format,
			grabmethod, avifilename) < 0)
		exit(1);
	/* if we're supposed to list the controls, do that now */
	if (querycontrols)
		enum_controls(videoIn->fd);

	/* if we're supposed to read the control settings from a configfile, do that now */
	if (readconfigfile)
		load_controls(videoIn->fd);

    printf("Enable Raw Stream Capture\n");
	if (enableRawStreamCapture) {
		videoIn->captureFile = fopen("stream.raw", "wb");
		if (videoIn->captureFile == NULL) {
			perror("Unable to open file for raw stream capturing");
		} else {
			printf("Starting raw stream capturing to stream.raw ...\n");
		}
	}
	if (enableRawFrameCapture)
		videoIn->rawFrameCapture = enableRawFrameCapture;

	initLut();

    printf("Begin main big loop\n");
    int loopNum = 0;
	/* main big loop */
	while (videoIn->signalquit) {
		//
		if (uvcGrab(videoIn) < 0) {
			printf("Error grabbing \n");
			break;
		}
		//
		/* if we're grabbing video, show the frame rate */
		if (videoIn->toggleAvi)
			printf("\rframe rate: %d ", frmrate);
		//

		if (getpictureflag) {
			//if (videoIn->getPict) { 
			switch (videoIn->formatIn) {
			case V4L2_PIX_FMT_MJPEG:
				get_picture(videoIn->tmpbuffer, videoIn->buf.bytesused);
				break;
			case V4L2_PIX_FMT_YUYV:
				printf("get picture yuv...\n");
				get_pictureYV2(videoIn->framebuffer, videoIn->width,
						videoIn->height);
				break;
			default:
				break;
			}
			videoIn->getPict = 0;
			printf("get picture !\n");
		}
        printf("loop number %d\n",loopNum);
        loopNum ++;
	}

	/* if avifile is defined, we made a video: compute the exact fps and
	 set it in the video */
	if (videoIn->avifile != NULL) {
		float fps = (videoIn->framecount / (videoIn->recordtime / 1000));
		fprintf(stderr, "setting fps to %f\n", fps);
		AVI_set_video(videoIn->avifile, videoIn->width, videoIn->height, fps,
				"MJPG");
		AVI_close(videoIn->avifile);
	}

	close_v4l2(videoIn);
	free(videoIn);
	freeLut();
	printf(" Clean Up done Quit \n");
}
예제 #4
0
int main(int argc, char **argv)
{
	if (!XInitThreads()) {
		printf("Xlib not thread safe\n");
		exit(1);
	}
	
	//const SDL_VideoInfo *info;
	char driver[128];
	SDL_Surface *pscreen;
	//SDL_Overlay *overlay;
	//SDL_Rect drect, dclip;
	SDL_Event sdlevent;
	SDL_Thread *mythread;
	SDL_mutex *affmutex;
	
	int status;
	Uint32 currtime;
	Uint32 lasttime;
	unsigned char *p = NULL;
	int hwaccel = 0;
	const char *videodevice = NULL;
	const char *mode = NULL;
	int format = V4L2_PIX_FMT_MJPEG;
	//int sdl_format =  SDL_YUY2_OVERLAY;
	int i;
	int grabmethod = 1;
	int width = 640;
	int height = 480;
	float fps = 30.0;			// Requested frame rate
	float frmrate = 0.0;		// Measured frame rate
	char *avifilename = NULL;
	int queryformats = 0;
	int querycontrols = 0;
	int readconfigfile = 0;
	char *separateur;
	char *sizestring = NULL;
	char *fpsstring  = NULL;
	int enableRawStreamCapture = 0;
	int enableRawFrameCapture = 0;
	
	printf("luvcview %s\n\n", version);
	for (i = 1; i < argc; i++) {
		/* skip bad arguments */
		if (argv[i] == NULL || *argv[i] == 0 || *argv[i] != '-') {
			continue;
		}
		if (strcmp(argv[i], "-d") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -d, aborting.\n");
				exit(1);
			}
			videodevice = strdup(argv[i + 1]);
		}
		if (strcmp(argv[i], "-g") == 0) {
			/* Ask for read instead default  mmap */
			grabmethod = 0;
		}
		if (strcmp(argv[i], "-w") == 0) {
			/* disable hw acceleration */
			hwaccel = 1;
		}
		if (strcmp(argv[i], "-f") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -f, aborting.\n");
				exit(1);
			}
			mode = argv[i + 1];
			
			if (strcasecmp(mode, "yuv") == 0 || strcasecmp(mode, "YUYV") == 0) {
				format = V4L2_PIX_FMT_YUYV;
			} else if (strcasecmp(mode, "uyvy") == 0 || strcasecmp(mode, "UYVY") == 0) {
				format = V4L2_PIX_FMT_UYVY;
				//sdl_format = SDL_UYVY_OVERLAY;
			} else if (strcasecmp(mode, "jpg") == 0 || strcasecmp(mode, "MJPG") == 0) {
				format = V4L2_PIX_FMT_MJPEG;
			} else {
				printf("Unknown format specified. Aborting.\n");
				exit(1);
			}
		}
		if (strcmp(argv[i], "-s") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -s, aborting.\n");
				exit(1);
			}
			
			sizestring = strdup(argv[i + 1]);
			
			width = strtoul(sizestring, &separateur, 10);
			if (*separateur != 'x') {
				printf("Error in size use -s widthxheight\n");
				exit(1);
			} else {
				++separateur;
				height = strtoul(separateur, &separateur, 10);
				if (*separateur != 0)
					printf("hmm.. dont like that!! trying this height\n");
			}
		}
		if (strcmp(argv[i], "-i") == 0) {
			if (i + 1 >= argc) {
				printf("No parameter specified with -i, aborting.\n");
				exit(1);
			}
			fpsstring = argv[i + 1];
			fps = strtof(fpsstring, &separateur);
			if(*separateur != '\0') {
				printf("Invalid frame rate '%s' specified with -i. "
				       "Only numbers are supported. Aborting.\n", fpsstring);
				exit(1);
			}
		}
		if (strcmp(argv[i], "-S") == 0) {
			/* Enable raw stream capture from the start */
			enableRawStreamCapture = 1;
		}
		if (strcmp(argv[i], "-c") == 0) {
			/* Enable raw frame capture for the first frame */
			enableRawFrameCapture = 1;
		}
		if (strcmp(argv[i], "-C") == 0) {
			/* Enable raw frame stream capture from the start*/
			enableRawFrameCapture = 2;
		}
		if (strcmp(argv[i], "-o") == 0) {
			/* set the avi filename */
			if (i + 1 >= argc) {
				printf("No parameter specified with -o, aborting.\n");
				exit(1);
			}
			avifilename = strdup(argv[i + 1]);
		}
		if (strcmp(argv[i], "-L") == 0) {
			/* query list of valid video formats */
			queryformats = 1;
		}
		if (strcmp(argv[i], "-l") == 0) {
			/* query list of valid video formats */
			querycontrols = 1;
		}
		
		if (strcmp(argv[i], "-r") == 0) {
			/* query list of valid video formats */
			readconfigfile = 1;
		}
		if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
			printf("usage: uvcview [-h -d -g -f -s -i -c -o -C -S -L -l -r]\n");
			printf("-h   print this message\n");
			printf("-d   /dev/videoX       use videoX device\n");
			printf("-g   use read method for grab instead mmap\n");
			printf("-w   disable SDL hardware accel.\n");
			printf("-f   choose video format (YUYV/yuv, UYVY/uyvy and MJPG/jpg are valid, MJPG is default)\n");
			printf("-i   fps           use specified frame rate\n");
			printf("-s   widthxheight      use specified input size\n");
			printf("-c   enable raw frame capturing for the first frame\n");
			printf("-C   enable raw frame stream capturing from the start\n");
			printf("-S   enable raw stream capturing from the start\n");
			printf("-o   avifile  create avifile, default video.avi\n");
			printf("-L   query valid video formats\n");
			printf("-l   query valid controls and settings\n");
			printf("-r   read and set control settings from luvcview.cfg (save/restore with F1/F2)\n");
			exit(0);
		}
	}
	
	/************* Test SDL capabilities ************/
	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
	
	/* For this version, we'll be save and disable hardware acceleration */
	if(hwaccel)
		if ( ! getenv("SDL_VIDEO_YUV_HWACCEL") ) {
			putenv("SDL_VIDEO_YUV_HWACCEL=0");
		}
		
/*	printf("SDL information:\n");
	if (SDL_VideoDriverName(driver, sizeof(driver))) {
		printf("  Video driver: %s\n", driver);
	}
/*	info = SDL_GetVideoInfo();
	
	if (info->wm_available) {
		printf("  A window manager is available\n");
	}
	if (info->hw_available) {
		printf("  Hardware surfaces are available (%dk video memory)\n",
		       info->video_mem);
		SDL_VIDEO_Flags |= SDL_HWSURFACE;
	}
	if (info->blit_hw) {
		printf("  Copy blits between hardware surfaces are accelerated\n");
		SDL_VIDEO_Flags |= SDL_ASYNCBLIT;
	}
	if (info->blit_hw_CC) {
		printf
		("  Colorkey blits between hardware surfaces are accelerated\n");
	}
	if (info->blit_hw_A) {
		printf("  Alpha blits between hardware surfaces are accelerated\n");
	}
	if (info->blit_sw) {
		printf
		("  Copy blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if (info->blit_sw_CC) {
		printf
		("  Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if (info->blit_sw_A) {
		printf
		("  Alpha blits from software surfaces to hardware surfaces are accelerated\n");
	}
	if (info->blit_fill) {
		printf("  Color fills on hardware surfaces are accelerated\n");
	}
	
	if (!(SDL_VIDEO_Flags & SDL_HWSURFACE))
		SDL_VIDEO_Flags |= SDL_SWSURFACE;
	*/
	if (videodevice == NULL || *videodevice == 0) {
		videodevice = "/dev/video0";
	}
	
	if (avifilename == NULL || *avifilename == 0) {
		avifilename = "video.avi";
	}
	
	char* adev[2] = { "/dev/video0", "/dev/video1" };
	
	//tCam* gM.apCam[2];
	gM.aCam[0].Image_W = width;
	gM.aCam[0].Image_H = height;
	
	gM.Cam_N = 2;
	for (int i = 0; i < gM.Cam_N; ++i) {
		//gM.apCam[i] = malloc(sizeof *gM.apCam[i]);
		memset(&gM.aCam[i], 0, sizeof gM.aCam[i]);
		tCam* pcam = &gM.aCam[i];
		
		pcam->Idx = i;
		pcam->Image_W = width;
		pcam->Image_H = height;
		
		pcam->UVC = (struct vdIn *) calloc(1, sizeof(struct vdIn));
		if ( queryformats ) {
			/* if we're supposed to list the video formats, do that now and go out */
			check_videoIn(pcam->UVC, adev[i]);
			free(pcam->UVC);
			SDL_Quit();
			exit(1);
		}
		if (init_videoIn (pcam->UVC, adev[i], width, height, fps, format, grabmethod, avifilename) < 0)
			exit(1);
		/* if we're supposed to list the controls, do that now */
		if ( querycontrols )
			enum_controls(pcam->UVC->fd);
		
		/* if we're supposed to read the control settings from a configfile, do that now */
		if ( readconfigfile )
			load_controls(pcam->UVC->fd);
		
		
		pcam->SDL_Win = SDL_CreateWindow(title_act[A_VIDEO].title,
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			pcam->UVC->width/2, pcam->UVC->height/2,
			SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
		);
		if (!pcam->SDL_Win)
			abort();

		pcam->SDL_Surf = SDL_GetWindowSurface(pcam->SDL_Win);
		if (!pcam->SDL_Surf)
			abort();
		
	}
	pcam = &gM.aCam[0];
	//gM.pScreen = pscreen = gM.aCam[0]->SDL_Surf;
	
	//gM.pOverlay = overlay = SDL_CreateYUVOverlay(videoIn->width, videoIn->height, sdl_format, pscreen);
	//p = (unsigned char *) overlay->pixels[0];
	
/*	if (enableRawStreamCapture) {
		videoIn->captureFile = fopen("stream.raw", "wb");
		if(videoIn->captureFile == NULL) {
			perror("Unable to open file for raw stream capturing");
		} else {
			printf("Starting raw stream capturing to stream.raw ...\n");
		}
	}
	if (enableRawFrameCapture)
		videoIn->rawFrameCapture = enableRawFrameCapture;*/
	
	initLut();
	//SDL_WM_SetCaption(title_act[A_VIDEO].title, NULL);
	lasttime = SDL_GetTicks();
//	creatButt(videoIn->width, 32);
	
//	SDL_LockYUVOverlay(overlay);
	
//	memcpy(p + (videoIn->width * (videoIn->height) * 2), YUYVbutt, videoIn->width * 64);
	
//	SDL_UnlockYUVOverlay(overlay);
	
	/* initialize thread data */
	//ptdata.ptscreen = &pscreen;
	//ptdata.ptvideoIn = videoIn;
	ptdata.ptsdlevent = &sdlevent;
	//ptdata.drect = &drect;
	affmutex = SDL_CreateMutex();
	ptdata.affmutex = affmutex;
//	mythread = SDL_CreateThread(eventThread, (void *) &ptdata);
	
	muhaha_Init ();
	gM.pDst = p;
	
	muhaha_Loop ();
	
	muhaha_DeInit ();
	
	SDL_WaitThread(mythread, &status);
	SDL_DestroyMutex(affmutex);
	
	/* if avifile is defined, we made a video: compute the exact fps and
	   set it in the video */
	
	//close_v4l2(videoIn);
	//free(videoIn);
	destroyButt();
	freeLut();
	printf("Cleanup done. Exiting ...\n");
	SDL_Quit();
}