コード例 #1
0
ファイル: buf_op.c プロジェクト: LeMaker/android-actions
int init_buf(unsigned int buffer_size)
{
    int i;
    struct data_buf *p;
    int ret = 0;
    for(i = 0; i<(int)(BUF_COUNT); i++)
    {
        p = calloc(1,sizeof(struct data_buf));
        if (!p) {
        printf("Out of memory\n");
        return -ENOMEM;
        }
        list_add_tail(&(p->list), &qlist);
    }
    switch (io)
    {
        case IO_METHOD_MMAP:
            init_mmap();
            break;
        case IO_METHOD_USERPTR:
            ret = init_userp(buffer_size);
            break;
    }
    return ret;
}
コード例 #2
0
ファイル: v4l2_codec.c プロジェクト: sealaunch/baresip
static int encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
			 struct videnc_param *prm, const char *fmtp,
			 videnc_packet_h *pkth, void *arg)
{
	struct videnc_state *st;
	int err = 0;
	(void)fmtp;

	if (!vesp || !vc || !prm || !pkth)
		return EINVAL;

	if (*vesp)
		return 0;

	st = mem_zalloc(sizeof(*st), enc_destructor);
	if (!st)
		return ENOMEM;

	st->encprm = *prm;
	st->pkth = pkth;
	st->arg = arg;

	st->fd = open(v4l2.device, O_RDWR);
	if (st->fd == -1) {
		err = errno;
		warning("Opening video device (%m)\n", err);
		goto out;
	}

	err = print_caps(st->fd);
	if (err)
		goto out;

	err = init_mmap(st, st->fd);
	if (err)
		goto out;

	err = query_buffer(st->fd);
	if (err)
		goto out;

	err = start_streaming(st->fd);
	if (err)
		goto out;

	err = fd_listen(st->fd, FD_READ, read_handler, st);
	if (err)
		goto out;

	info("v4l2_codec: video encoder %s: %d fps, %d bit/s, pktsize=%u\n",
	      vc->name, prm->fps, prm->bitrate, prm->pktsize);

 out:
	if (err)
		mem_deref(st);
	else
		*vesp = st;

	return err;
}
コード例 #3
0
ファイル: CamCap.cpp プロジェクト: guozhaokui/PiWebCam
//initial camera device 
int init_camera_device(int fd)
{
    //decive fuction, such as video input
    struct v4l2_capability cap;
    //video standard,such as PAL,NTSC
    struct v4l2_standard std;
    //frame format
    struct v4l2_format tv_fmt;
    //check control
    struct v4l2_queryctrl query;
    //detail control value
    struct v4l2_fmtdesc fmt;
    int ret;
    //get the format of video supply
    memset(&fmt, 0, sizeof(fmt));
    fmt.index = 0;
    //supply to image capture
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    // show all format of supply
    printf("Support format:\n");
    while(ioctl(fd, VIDIOC_ENUM_FMT, &fmt) == 0){
        fmt.index++;
        printf("pixelformat = ''%c%c%c%c''\ndescription = ''%s''\n",fmt.pixelformat & 0xFF, (fmt.pixelformat >> 8) & 0xFF,(fmt.pixelformat >> 16) & 0xFF, (fmt.pixelformat >> 24) & 0xFF,fmt.description);
    }
    //check video decive driver capability
    ret = ioctl(fd, VIDIOC_QUERYCAP, &cap);
    if(ret < 0){
        perror("Fail to ioctl VIDEO_QUERYCAP");
        exit(EXIT_FAILURE);
    }
 
    //judge wherher or not to be a video-get device
    if(!(cap.capabilities & V4L2_BUF_TYPE_VIDEO_CAPTURE))
    {
        printf("The Current device is not a video capture device\n");
        exit(-1);
    }
 
    //judge whether or not to supply the form of video stream
    if(!(cap.capabilities & V4L2_CAP_STREAMING))
    {
        printf("The Current device does not support streaming i/o\n");
        exit(EXIT_FAILURE);
    }
 
    //set the form of camera capture data
    tv_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    tv_fmt.fmt.pix.width = 640;
    tv_fmt.fmt.pix.height = 480;
    tv_fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
    tv_fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
    if (ioctl(fd, VIDIOC_S_FMT, &tv_fmt)< 0) {
        printf("VIDIOC_S_FMT\n");
        exit(-1);
        close(fd);
    }
    //initial video capture way(mmap)
    init_mmap(fd);
    return 0;
}
コード例 #4
0
int main(int argc, char **argv)
{
	int ret = 0;

#ifdef TEST_CONTROLS
	if (argc != 8) {
		printf
		    ("%s width height num_of_frames bright contrast saturation sharpness\n",
		     argv[0]);
		printf("EX)  $ %s 640 480  3  0 0 0 24612 \n", argv[0]);
		goto err;
	}
#else
	if (argc != 4) {
		printf
		    ("%s width height num_of_frames bright contrast saturation sharpness\n",
		     argv[0]);
		printf("EX)  $ %s 640 480  3\n", argv[0]);
		goto err;
	}
#endif

	g_pix_width = atoi(argv[1]);
	g_pix_height = atoi(argv[2]);
	g_file_count = atoi(argv[3]) + 1;

#ifdef TEST_CONTROLS
	g_brightness = atoi(argv[4]);
	g_contrast = atoi(argv[5]);
	g_saturation = atoi(argv[6]);
	g_sharpness = atoi(argv[7]);
#endif

	g_img_buf = malloc(g_pix_width * g_pix_height * 3 * sizeof(char));

	open_device();
	set_input_chann(0);
	init_v4l2_device();
	ret = init_mmap(&n_buffers);

	if (ret)
		errno_exit("init_mmap error !!!");

#ifdef TEST_CONTROLS
	start_control_testing();
#endif
	start_capturing(buffers);
	mainloop();
	stop_capturing();
	close_mmap();
	close_device();
	free(g_img_buf);
	exit(EXIT_SUCCESS);

 err:
	return ret;
}
コード例 #5
0
ファイル: v4l2grabber.c プロジェクト: N0NamedGuy/libpointit
static int init_device(void) {
    struct v4l2_capability cap;
    struct v4l2_cropcap cropcap;
    struct v4l2_crop crop;
    struct v4l2_format fmt;
    unsigned int min;

    if (xioctl(cam_fd, VIDIOC_QUERYCAP, &cap)) {
        if (EINVAL == errno) {
            fprintf(stderr, "%s is no V4L2 device\n", cam_dev_name);
            return -1;
        } else {
            return errno_report("VIDIOC_QUERYCAP");
        }
    }

    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
        fprintf(stderr, "%s is no video capture device\n", cam_dev_name);
        return -1;
    }

    /* Using MMAP */
    if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
        fprintf(stderr, "%s does not support streaming i/o\n", cam_dev_name);
        return -1;  
    }

    CLEAR(cropcap);
    cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    if (xioctl(cam_fd, VIDIOC_CROPCAP, &cropcap) == 0) {
        /* If cropping is supported, do not crop */
        crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        crop.c = cropcap.defrect;
        xioctl(cam_fd, VIDIOC_S_CROP, &crop);
    }

    CLEAR(fmt);

    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width = cam_width;
    fmt.fmt.pix.height = cam_height;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
    fmt.fmt.pix.field = V4L2_FIELD_NONE; /* No interlacing, please */

    if (xioctl(cam_fd, VIDIOC_S_FMT, &fmt) == -1) {
        return errno_report("VIDIOC_S_FMT");
    }

    /* Buggy driver paranoia. */
    min = fmt.fmt.pix.width * 2;
    if (fmt.fmt.pix.bytesperline < min) fmt.fmt.pix.bytesperline = min;
    min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
    if (fmt.fmt.pix.sizeimage < min) fmt.fmt.pix.sizeimage = min;

    return init_mmap();
}
コード例 #6
0
int main(int argc, char* argv[]) {
    parse_parameter(argc, argv);

    // prepare some info outside the loop
    int fd;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.7, 0.7, 0, 2); // 0 shear, 3 px wide

    int set_quality[3] = {CV_IMWRITE_JPEG_QUALITY, quality,  0};
    char capture_title[55];
    IplImage* frame;
    CvMat cvmat;

    // startup
    char dev[20];
    sprintf(dev,"/dev/video%i",device);
    fd = open(dev, O_RDWR);
    if (fd == -1) {
        perror("Opening video device");
        return 1;
    }
    if(setup_cam(fd)) {
        return 1;
    }
    if(init_mmap(fd)) {
        return 1;
    }

    // define buffer and activate streaming on the cam
    struct v4l2_buffer buf = {0};
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    buf.memory = V4L2_MEMORY_MMAP;
    buf.index = 0;
    if(-1 == xioctl(fd, VIDIOC_STREAMON, &buf.type)) {
        perror("Start Capture");
        return 1;
    }

    // loop fps measurement
    uint32_t start_time = time(0);
    uint32_t image_count = 0;

    //for(int i=0; i<100; i++){
    /// run forever
    while(1) {
        if(capture_image(fd,&font,set_quality,frame,&cvmat,capture_title,&buf,&start_time,&image_count)) {
            return 1;
        }
    }

    // todo, close gracefully
    printf("closing fd\n");
    close(fd);
    return 0;
}
コード例 #7
0
//初始化视频设备
int init_camer_device(int fd)
{
	struct v4l2_fmtdesc fmt;
	struct v4l2_capability cap;
	struct v4l2_format stream_fmt;
	int ret;
	//当前视频设备支持的视频格式
	memset(&fmt,0,sizeof(fmt));
	fmt.index = 0;
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	//枚举所有摄像头支持的图像格式
	printf("vidoe format Supported\n");
	while((ret = ioctl(fd,VIDIOC_ENUM_FMT,&fmt)) == 0){
		fmt.index ++ ;
		printf("{pixelformat = %c%c%c%c},description = '%s'\n",
		       fmt.pixelformat & 0xff,(fmt.pixelformat >> 8)&0xff,
		       (fmt.pixelformat >> 16) & 0xff,(fmt.pixelformat >> 24)&0xff,
		       fmt.description);
	}
	printf("vidoe format enum end\n");
	//查询视频设备驱动的功能
	ret = ioctl(fd,VIDIOC_QUERYCAP,&cap);
	if(ret < 0){
		perror("FAIL to ioctl VIDIOC_QUERYCAP");
		exit(EXIT_FAILURE);
	}
	//判断是否是一个视频捕捉设备
	if(!(cap.capabilities & V4L2_BUF_TYPE_VIDEO_CAPTURE)){
		printf("The Current device is not a video capture device\n");
		exit(EXIT_FAILURE);
	}
	//判断是否支持视频流形式
	if(!(cap.capabilities & V4L2_CAP_STREAMING)){
		printf("The Current device does not support streaming i/o\n");
		exit(EXIT_FAILURE);
	}
	//设置摄像头采集数据格式,如设置采集数据的
	//长,宽,图像格式(JPEG,YUYV,MJPEG等格式)
	stream_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	stream_fmt.fmt.pix.width = c_width;
	stream_fmt.fmt.pix.height = c_hight;
	stream_fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
//	stream_fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG;
	stream_fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
	printf("set video format..\n");
	if(-1 == ioctl(fd,VIDIOC_S_FMT,&stream_fmt)){
		perror("Fail to ioctl:VIDIOC_S_FMT ");
		exit(EXIT_FAILURE);
	}else{
		printf("set video format ok\n");
	}
	//初始化视频采集方式(mmap)
	init_mmap(fd);
	return 0;
}
コード例 #8
0
ファイル: cap.cpp プロジェクト: sangk54/mia
void V4LCapture::init_device()
{
	CLEAR (cap);

	if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
		errno_exit("VIDIOC_QUERYCAP");
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
		errno_exit("%s is not a V4L2 device", dev_name);
	}

	if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
		errno_exit("%s does not support streaming", dev_name);
	}

	CLEAR (cropcap);

	if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
		CLEAR(crop);

		crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		crop.c = cropcap.defrect;

		if( -1 == xioctl(fd, VIDIOC_S_CROP, &crop) ){
			//errno_exit("CROP");
			// ignore error
		}
	}

	CLEAR (fmt);
	
	fmt.type		= V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width	= param.width;
	fmt.fmt.pix.height	= param.height;
	fmt.fmt.pix.pixelformat	= param.pixelformat;
	fmt.fmt.pix.field	= V4L2_FIELD_INTERLACED;

	if( -1 == xioctl(fd, VIDIOC_S_FMT, &fmt) ){
		errno_exit("VIDIOC_S_FMT");
	}

	struct v4l2_streamparm setfps;
	
	CLEAR (setfps);

	setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	setfps.parm.capture.timeperframe.numerator = 1;
	setfps.parm.capture.timeperframe.denominator = param.fps;
	xioctl (fd, VIDIOC_S_PARM, &setfps);

	init_mmap();
}
コード例 #9
0
ファイル: camera.cpp プロジェクト: jpeasgood/aalib
void aa::camera::init_device()
{
	v4l2_capability cap;
	v4l2_format fmt;

	if (-1 == xioctl(device_fd, VIDIOC_QUERYCAP, &cap))
	{
		if (EINVAL == errno)
		{
			std::stringstream ss;
			ss << device_name << " is not a V4L2 device.";
			throw std::runtime_error(ss.str());
		}
		else
		{
			std::stringstream ss;
			ss << "Can not get the device capabilities of " << device_name << ".";
			throw std::runtime_error(ss.str());
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
	{
		std::stringstream ss;
		ss << device_name << " is not a capture device.";
		throw std::runtime_error(ss.str());
	}

	if (!(cap.capabilities & V4L2_CAP_STREAMING))
	{
		std::stringstream ss;
		ss << device_name << " does not support streaming.";
		throw std::runtime_error(ss.str());
	}

	fmt = {};

	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width = format.width;
	fmt.fmt.pix.height = format.height;
	fmt.fmt.pix.pixelformat = format.pixel_format;
	fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

	if (-1 == xioctl(device_fd, VIDIOC_S_FMT, &fmt))
	{
		std::stringstream ss;
		ss << device_name << " does not support the video format.";
		throw std::runtime_error(ss.str());
	}

	init_mmap();
}
コード例 #10
0
ファイル: caputure.c プロジェクト: yoshixmk/standard_subject
static void init_device(void)
{
    struct v4l2_format fmt;

    CLEAR(fmt);
    fmt.type 		= V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width	= IMG_WIDTH; 	     // キャプチャ画像の解像度:幅
    fmt.fmt.pix.height	= IMG_HEIGHT;	     // キャプチャ画像の解像度:高さ
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;// ピクセルフォーマットの設定:YUYV
    fmt.fmt.pix.field  = V4L2_FIELD_INTERLACED; // 受信するビデオフォーマットの設定
    xioctl(fd, VIDIOC_S_FMT, &fmt);	     // 映像フォーマットの設定
	
    init_mmap();	// メモリマッピングの初期化
}
コード例 #11
0
int main() {
	open_device();
	init_device();
	init_mmap();

	start_capturing();
	mainloop();
	stop_capturing();

	uninit_mmap();
	close_device();

	return EXIT_SUCCESS;
}
コード例 #12
0
ファイル: setseq.c プロジェクト: tkpclark/wraith
main(int argc,char **argv)
{
	if( (argc!=1)&&(argc!=2) )
	{
		printf("arguments error!\n");
		exit(0);
	}
	map=init_mmap();
	if(argc==1)
		read_mmap();
	if(argc==2)
		set_mmap(argv[1]);
		
	
}
コード例 #13
0
ファイル: capture.cpp プロジェクト: jaantti/Firestarter
void init_device( char *dev_name )
{
    v4l2_capability cap;
    v4l2_format fmt;

    unsigned int min;


    if( -1 == xioctl( fd, VIDIOC_QUERYCAP, &cap ) ) {
        if( EINVAL == errno ) {
            fprintf(stderr, "%s is no V4L2 device\n", dev_name);
            exit(EXIT_FAILURE);
        } else {
            fprintf( stderr, "VIDIOC_QUERYCAP error %d, %s\n", errno, strerror(errno) );
            exit( EXIT_FAILURE );
        }
    }

    if( !( cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ) ) {
        fprintf(stderr, "%s is no video capture device\n", dev_name);
        exit(EXIT_FAILURE);
    }

    if( !( cap.capabilities & V4L2_CAP_STREAMING ) ) {
        fprintf(stderr, "%s does not support streaming i/o\n", dev_name);
        exit(EXIT_FAILURE);
    }


    memset( &fmt, 0, sizeof(fmt) );

    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if( -1 == xioctl( fd, VIDIOC_G_FMT, &fmt ) ) {
        fprintf( stderr, "VIDIOC_G_FMT error %d, %s\n", errno, strerror(errno) );
        exit( EXIT_FAILURE );
    }


    // Buggy driver paranoia.
    min = fmt.fmt.pix.width * 2;
    if( fmt.fmt.pix.bytesperline < min )
        fmt.fmt.pix.bytesperline = min;
    min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
    if( fmt.fmt.pix.sizeimage < min )
        fmt.fmt.pix.sizeimage = min;

    init_mmap( dev_name );
}
コード例 #14
0
ファイル: MsMmap.c プロジェクト: nightcap79/kogan-tv-gpl
int list_mmap_id(void)
{
    #define PATTERN_HEAD "/* E_MMAP_ID"
    #define PATTERN_TAIL "*/"
    char *pS=NULL,*pE=NULL;
    char *pBuf=NULL;
    char *strBuf=NULL;
    unsigned int buf_size=mmap_buffer_size;
    UBOOT_TRACE("IN\n");
    if(init_mmap()!=0)
    {
        UBOOT_ERROR("init mmap fail\n");
        return -1;
    }
    strBuf=malloc(CMD_BUF);
    if(strBuf==NULL)
    {
        UBOOT_ERROR("malloc for string buf fail\n");
        return -1;
    }
    memset(strBuf,0,CMD_BUF);
    
    pS=(char *)mmap_buffer;
    pBuf=pS;
    while(buf_size)
    {
        pS=pattern_search((char *)pBuf,buf_size,PATTERN_HEAD);
        if(pS!=NULL)
        {
            buf_size=buf_size-((unsigned int)pS-(unsigned int)pBuf+1);
            pE=pattern_search((char *)pS,buf_size,PATTERN_TAIL);    
            buf_size=buf_size-((unsigned int)pE-(unsigned int)pS+1);
        }
        if((pS==NULL)||(pE==NULL))
        {
            break;
        }
        pS+=3;//+3? skip  "/* "
        pBuf=pE+strlen(PATTERN_TAIL);        
        snprintf(strBuf,((unsigned int)pE-(unsigned int)pS),"%s",pS);
        UBOOT_INFO("%s\n",strBuf);
    }
    
    UBOOT_TRACE("OK\n");
    return 0;

}
コード例 #15
0
ファイル: jayrambhia.c プロジェクト: nitheeshas/cpp-cheat
int main() {
    int fd;
    fd = open("/dev/video0", O_RDWR);
    if (fd == -1) {
        perror("Opening video device");
        return 1;
    }
    if (print_caps(fd))
        return 1;
    if (init_mmap(fd))
        return 1;
    int i;
    if (capture_image(fd))
        return 1;
    close(fd);
    return 0;
}
コード例 #16
0
ファイル: tracer.c プロジェクト: dakov/ITS-dynamic-analysis
void handleSyscall(struct user_regs_struct regs) {

    long syscall = regs.orig_rax;

    push_syscall(syscall);
    // report only after exitting the call
    if (top_syscall()->status == 2) {
	// parameters, cf.:
	// http://www.x86-64.org/documentation/abi.pdf Section A.2.1


	switch (syscall) {

	    case __NR_munlockall: init_munlockall(regs);
		break;

	    case __NR_brk: init_brk(regs);
		break;

	    case __NR_munlock: init_munlock(regs);
		break;

	    case __NR_mlock: init_mlock(regs);
		break;

	    case __NR_munmap: init_munmap(regs);
		break;

	    case __NR_mlockall:init_mlockall(regs);
		break;

	    case __NR_mmap: init_mmap(regs);
		break;

	    case __NR_mprotect: init_mprotect(regs);
		break;

	    case __NR_msync: init_msync(regs);
		break;
	}

	pop_syscall();
    }

}
コード例 #17
0
ファイル: kmain.c プロジェクト: bemk/openLoader
void kmain(ol_mmap_register_t mmr)
{
	textinit();
	clearscreen();

	println("The openLoader kernel is executing. \n");

	print("Current stack pointer: ");
	ol_registers_t regs = getregs();
	printnum(regs->esp, 16, FALSE, FALSE);
	putc(0xa);

	char status = inb(0x60);
	if((status & 2) == 2)
	{
		println("The A20 gate is open.");
		putc(0xa);
	}
	
	pic_init();
	setIDT();
	outb(OL_KBC_COMMAND, OL_KB_INIT);	// enable the keyboard

// display mmap
	init_mmap(mmr);
	println("Multiboot memory map:\n");
	display_mmap(mmr);

#if 0
	uint8_t active = ide_init(bootdrive);
	ide_read(0x100, 1<<20, &bootdrive[active], 60);
	uint8_t eax = ata_identify();
	printnum(active, 16, FALSE, FALSE);
#endif

	putc(0xa);

	println("Waiting for service interrupts..");
	while(1) halt();
	println("End of program reached!");
	endprogram();
}
コード例 #18
0
ファイル: MsMmap.c プロジェクト: nightcap79/kogan-tv-gpl
int get_dram_length(U32 *length)
{
    UBOOT_TRACE("IN\n");
    if(length==NULL)
    {
        UBOOT_ERROR("The 'length' is a null pointer\n");
        return -1;
    }

    if(init_mmap()!=0)
    {
        UBOOT_ERROR("init mmap fail\n");
        return -1;
    }
    UBOOT_DEBUG("dram_length=0x%x\n",dram_length);
    *length=dram_length;
    UBOOT_TRACE("OK\n");    
    return 0;
    
      
}
コード例 #19
0
ファイル: MsMmap.c プロジェクト: nightcap79/kogan-tv-gpl
int get_miu_interval(U32 *interval)
{
    UBOOT_TRACE("IN\n");
    if(interval==NULL)
    {
        UBOOT_ERROR("The 'interval' is a null pointer\n");
        return -1;
    }

    if(init_mmap()!=0)
    {
        UBOOT_ERROR("init mmap fail\n");
        return -1;
    }
    UBOOT_DEBUG("min_interval=0x%x\n",miu_interval);
    *interval=miu_interval;
    UBOOT_TRACE("OK\n");    
    return 0;
    
      
}
コード例 #20
0
ファイル: MsMmap.c プロジェクト: nightcap79/kogan-tv-gpl
int get_mmap(char *id, MMapInfo_s *mmapInfo)
{
    UBOOT_TRACE("IN\n");

    if((id==NULL)||(mmapInfo==NULL))
    {
        UBOOT_ERROR("One of the parameters is a null pointer\n");
        return -1;
    }
    
    if(init_mmap()!=0)
    {
        UBOOT_ERROR("init mmap fail\n");
        return -1;
    }

    _get_mmap(mmap_buffer,id,mmapInfo);
    
    UBOOT_TRACE("OK\n");
    return 0;
}
コード例 #21
0
ファイル: v4l-main.c プロジェクト: Alexoner/linux-snippet
int main(int argc,char **argv)
{
	int fd;
    int i=4;
    struct head_buffer *hbuffer;
 	if(argc>1)
		fd=open(argv[1],O_RDWR);
	else
		fd=open("/dev/video0",O_RDWR);

	hbuffer=(struct head_buffer*)malloc(sizeof(struct head_buffer));
    set_fmt(fd);
    hbuffer=init_mmap(fd,hbuffer);
    start_capturing(fd,IO_METHOD_MMAP,hbuffer);
    while(i--)
    {
        read_frame(fd,IO_METHOD_MMAP,hbuffer);
        sleep(1);
    }
    return 0;
}
コード例 #22
0
ファイル: CameraManager.cpp プロジェクト: chrolss/Quadvisio
void CameraManager::init_device() {
    struct v4l2_format fmt;
    
    CLEAR(fmt);
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width       = width;
    fmt.fmt.pix.height      = height;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
    fmt.fmt.pix.field       = V4L2_FIELD_ANY;
    
    xioctl(fd, VIDIOC_S_FMT, &fmt);
    if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) {
        printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
        exit(EXIT_FAILURE);
    }
    
    std::cout << "Hej8" << std::endl;
    
    init_mmap();
    
    std::cout << "Hej9" << std::endl;

}
コード例 #23
0
static void init_device(void)
{
        struct v4l2_capability cap;
        struct v4l2_cropcap cropcap;
        struct v4l2_crop crop;
        struct v4l2_format fmt;
        unsigned int min;

        if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s is no V4L2 device\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_QUERYCAP");
                }
        }

        if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
                fprintf(stderr, "%s is no video capture device\n",
                         dev_name);
                exit(EXIT_FAILURE);
        }

        switch (io) {
        case IO_METHOD_READ:
                if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
                        fprintf(stderr, "%s does not support read i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
                        fprintf(stderr, "%s does not support streaming i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;
        }

        /* Select video input, video standard and tune here. */

        CLEAR(cropcap);

        cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
                crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                crop.c = cropcap.defrect; /* reset to default */

                if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
                        switch (errno) {
                        case EINVAL:
                                /* Cropping not supported. */
                                break;
                        default:
                                /* Errors ignored. */
                                break;
                        }
                }
        } else {
                /* Errors ignored. */
        }

        CLEAR(fmt);

        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (force_format) {
                fmt.fmt.pix.width       = 1280;
                fmt.fmt.pix.height      = 720;
                fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
                fmt.fmt.pix.field       = V4L2_FIELD_NONE;

                if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                        errno_exit("VIDIOC_S_FMT");

                /* Note VIDIOC_S_FMT may change width and height. */
        } else {
                /* Preserve original settings as set by v4l2-ctl for example */
                if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
                        errno_exit("VIDIOC_G_FMT");
        }

        /* Buggy driver paranoia. */
        min = fmt.fmt.pix.width * 2;
        if (fmt.fmt.pix.bytesperline < min)
                fmt.fmt.pix.bytesperline = min;
        min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
        if (fmt.fmt.pix.sizeimage < min)
                fmt.fmt.pix.sizeimage = min;

        switch (io) {
        case IO_METHOD_READ:
                init_read(fmt.fmt.pix.sizeimage);
                break;

        case IO_METHOD_MMAP:
                init_mmap();
                break;

        case IO_METHOD_USERPTR:
                init_userp(fmt.fmt.pix.sizeimage);
                break;
        }
}
コード例 #24
0
ファイル: camera.cpp プロジェクト: ashiontang/TQ210
bool Camera::init_device(void) {
    struct v4l2_capability cap;
    struct v4l2_cropcap cropcap;
    struct v4l2_crop crop;
    struct v4l2_format fmt;
    unsigned int min;
    if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
        if (EINVAL == errno) {
            fprintf(stderr, "%s is no V4L2 device\n", dev_name);
            return false;
        } else {
            return false;
        }
    }
    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
        fprintf(stderr, "%s is no video capture device\n", dev_name);
        return false;
    }
    switch (io) {
    case IO_METHOD_READ:
        if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
            fprintf(stderr, "%s does not support read i/o\n", dev_name);
            return false;
        }
        break;
    case IO_METHOD_MMAP:
    case IO_METHOD_USERPTR:
        if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
            fprintf(stderr, "%s does not support streaming i/o\n", dev_name);
            return false;
        }
        break;
    }

    v4l2_input input;
    memset(&input, 0, sizeof(struct v4l2_input));
    input.index = 0;
    int rtn = ioctl(fd, VIDIOC_S_INPUT, &input);
    if (rtn < 0) {
        printf("VIDIOC_S_INPUT:rtn(%d)\n", rtn);
        return false;
    }
    printf("-#-#-#-#-#-#-#-#-#-#-#-#-#-\n");
    printf("\n");
    ////////////crop finished!
    //////////set the format
    CLEAR (fmt);
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width = width;
    fmt.fmt.pix.height = height;
    //V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV420 — Planar formats with 1/2 horizontal and vertical chroma resolution, also known as YUV 4:2:0
    //V4L2_PIX_FMT_YUYV — Packed format with 1/2 horizontal chroma resolution, also known as YUV 4:2:2
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV12;//V4L2_PIX_FMT_YUYV;//V4L2_PIX_FMT_YUV420;//V4L2_PIX_FMT_YUYV;
    //fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
    {
        printf("-#-#-#-#-#-#-#-#-#-#-#-#-#-\n");
        printf("=====will set fmt to (%d, %d)--", fmt.fmt.pix.width,
               fmt.fmt.pix.height);
        if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
            printf("V4L2_PIX_FMT_YUYV\n");
        } else if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420) {
            printf("V4L2_PIX_FMT_YUV420\n");
        } else if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_NV12) {
            printf("V4L2_PIX_FMT_NV12\n");
        }
    }
    if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
        return false;
    if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
        return false;
    printf("=====after set fmt\n");
    printf("    fmt.fmt.pix.width = %d\n", fmt.fmt.pix.width);
    printf("    fmt.fmt.pix.height = %d\n", fmt.fmt.pix.height);
    printf("    fmt.fmt.pix.sizeimage = %d\n", fmt.fmt.pix.sizeimage);
    cap_image_size = fmt.fmt.pix.sizeimage;
    printf("    fmt.fmt.pix.bytesperline = %d\n", fmt.fmt.pix.bytesperline);
    printf("-#-#-#-#-#-#-#-#-#-#-#-#-#-\n");
    printf("\n");


    /* Note VIDIOC_S_FMT may change width and height. */
    printf("-#-#-#-#-#-#-#-#-#-#-#-#-#-\n");
    /* Buggy driver paranoia. */
    min = fmt.fmt.pix.width * 2;
    if (fmt.fmt.pix.bytesperline < min)
        fmt.fmt.pix.bytesperline = min;
    min = (unsigned int)width*height*3/2;
    printf("min:%d\n",min);
    if (fmt.fmt.pix.sizeimage < min)
        fmt.fmt.pix.sizeimage = min;
    cap_image_size = fmt.fmt.pix.sizeimage;
    printf("After Buggy driver paranoia\n");
    printf("    >>fmt.fmt.pix.sizeimage = %d\n", fmt.fmt.pix.sizeimage);
    printf("    >>fmt.fmt.pix.bytesperline = %d\n", fmt.fmt.pix.bytesperline);
    printf("-#-#-#-#-#-#-#-#-#-#-#-#-#-\n");
    printf("\n");

    init_mmap();

    return true;
}
コード例 #25
0
ファイル: libcam.cpp プロジェクト: georgeredinger/TYROS
void Camera::Init() {
	struct v4l2_capability cap;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_format fmt;
	unsigned int min;

	if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
		if (EINVAL == errno) {
			fprintf(stderr, "%s is no V4L2 device\n", name);
			exit(1);
		} else {
			errno_exit("VIDIOC_QUERYCAP");
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
		fprintf(stderr, "%s is no video capture device\n", name);
		exit(1);
	}

		if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
			fprintf(stderr, "%s does not support streaming i/o\n", name);
			exit(1);
		}


	CLEAR (cropcap);

	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
		crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		crop.c = cropcap.defrect; /* reset to default */

		if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
			switch (errno) {
			case EINVAL:
				printf("Cropping not supported\n");
				/* Cropping not supported. */
				break;
			default:
				/* Errors ignored. */
				break;
			}
		}
	} else {
		/* Errors ignored. */
	}

	CLEAR (fmt);

	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width = width;
	fmt.fmt.pix.height = height;
	fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
	fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

	if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
		errno_exit("VIDIOC_S_FMT");

	struct v4l2_streamparm p;
	p.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	p.parm.capture.timeperframe.numerator = 1;
	p.parm.capture.timeperframe.denominator = fps;

	if (-1 == xioctl(fd, VIDIOC_S_PARM, &p))
		errno_exit("VIDIOC_S_PARM");

	//default values, mins and maxes


#if 0
	struct v4l2_queryctrl queryctrl;

	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_BRIGHTNESS;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("brightness error\n");
		} else {
			printf("brightness is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("brightness is not supported\n");
	}
	mb = queryctrl.minimum;
	Mb = queryctrl.maximum;
	db = queryctrl.default_value;

	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_CONTRAST;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("contrast error\n");
		} else {
			printf("contrast is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("contrast is not supported\n");
	}
	mc = queryctrl.minimum;
	Mc = queryctrl.maximum;
	dc = queryctrl.default_value;
#endif

#if 0
	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_SATURATION;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("saturation error\n");
		} else {
			printf("saturation is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("saturation is not supported\n");
	}
	ms = queryctrl.minimum;
	Ms = queryctrl.maximum;
	ds = queryctrl.default_value;
#endif
#if 0
	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_HUE;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("hue error\n");
		} else {
			printf("hue is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("hue is not supported\n");
	}
	mh = queryctrl.minimum;
	Mh = queryctrl.maximum;
	dh = queryctrl.default_value;

#endif

#if 0
	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_HUE_AUTO;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("hueauto error\n");
		} else {
			printf("hueauto is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("hueauto is not supported\n");
	}
	ha = queryctrl.default_value;
#endif


#if 0
	memset(&queryctrl, 0, sizeof(queryctrl));
	queryctrl.id = V4L2_CID_SHARPNESS;
	if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
		if (errno != EINVAL) {
			//perror ("VIDIOC_QUERYCTRL");
			//exit(EXIT_FAILURE);
			printf("sharpness error\n");
		} else {
			printf("sharpness is not supported\n");
		}
	} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
		printf("sharpness is not supported\n");
	}
	msh = queryctrl.minimum;
	Msh = queryctrl.maximum;
	dsh = queryctrl.default_value;

	int index;

	index = 0;

	if (-1 == ioctl (fd, VIDIOC_S_INPUT, &index)) {
        	perror ("VIDIOC_S_INPUT");
        	exit (EXIT_FAILURE);
	}

#endif
	//TODO: TO ADD SETTINGS
	//here should go custom calls to xioctl
#if 1

    struct v4l2_control control;
    control.id = V4L2_CID_POWER_LINE_FREQUENCY;
    control.value = V4L2_CID_POWER_LINE_FREQUENCY_50HZ;

    if (ioctl(fd, VIDIOC_S_CTRL, &control) < 0) {
	printf("ioctl set_light_frequency_filter error\n");
	return ;
	}

#endif
#if 1

   // struct v4l2_control control;
    control.id = V4L2_CID_AUTOGAIN;
    control.value = 0;

    if (ioctl(fd, VIDIOC_S_CTRL, &control) < 0) {
	printf("ioctl set_autogain error\n");
	return ;
	}

#endif
#if 1

   // struct v4l2_control control;
    control.id = V4L2_CID_GAIN;
    control.value = 10;

    if (ioctl(fd, VIDIOC_S_CTRL, &control) < 0) {
	printf("ioctl set_gain error\n");
	return ;
	}

#endif



	//END TO ADD SETTINGS

	/* Note VIDIOC_S_FMT may change width and height. */

	/* Buggy driver paranoia. */
	min = fmt.fmt.pix.width ;
	if (fmt.fmt.pix.bytesperline < min)
		fmt.fmt.pix.bytesperline = min;
	min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
	if (fmt.fmt.pix.sizeimage < min)
		fmt.fmt.pix.sizeimage = min;

	init_mmap();

}
コード例 #26
0
ファイル: v4l2.c プロジェクト: Studio-Link-v2/baresip
static int v4l2_init_device(struct vidsrc_st *st, const char *dev_name,
			    int width, int height)
{
	struct v4l2_capability cap;
	struct v4l2_format fmt;
	struct v4l2_fmtdesc fmts;
	unsigned int min;
	const char *pix;
	int err;

	if (-1 == xioctl(st->fd, VIDIOC_QUERYCAP, &cap)) {
		if (EINVAL == errno) {
			warning("v4l2: %s is no V4L2 device\n", dev_name);
			return ENODEV;
		}
		else {
			warning("v4l2: VIDIOC_QUERYCAP: %m\n", errno);
			return errno;
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
		warning("v4l2: %s is no video capture device\n", dev_name);
		return ENODEV;
	}

	if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
		warning("v4l2: %s does not support streaming i/o\n",
			dev_name);
		return ENOSYS;
	}

	/* Negotiate video format */
	memset(&fmts, 0, sizeof(fmts));

	fmts.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	for (fmts.index=0; !v4l2_ioctl(st->fd, VIDIOC_ENUM_FMT, &fmts);
			fmts.index++) {
		if (match_fmt(fmts.pixelformat) != VID_FMT_N) {
			st->pixfmt = fmts.pixelformat;
			break;
		}
	}

	if (!st->pixfmt) {
		warning("v4l2: format negotiation failed: %m\n", errno);
		return errno;
	}

	/* Select video input, video standard and tune here. */

	memset(&fmt, 0, sizeof(fmt));

	fmt.type		= V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width       = width;
	fmt.fmt.pix.height      = height;
	fmt.fmt.pix.pixelformat = st->pixfmt;
	fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;

	if (-1 == xioctl(st->fd, VIDIOC_S_FMT, &fmt)) {
		warning("v4l2: VIDIOC_S_FMT: %m\n", errno);
		return errno;
	}

	/* Note VIDIOC_S_FMT may change width and height. */

	/* Buggy driver paranoia. */
	min = fmt.fmt.pix.width * 2;
	if (fmt.fmt.pix.bytesperline < min)
		fmt.fmt.pix.bytesperline = min;
	min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
	if (fmt.fmt.pix.sizeimage < min)
		fmt.fmt.pix.sizeimage = min;

	st->sz.w = fmt.fmt.pix.width;
	st->sz.h = fmt.fmt.pix.height;

	err = init_mmap(st, dev_name);
	if (err)
		return err;

	pix = (char *)&fmt.fmt.pix.pixelformat;

	if (st->pixfmt != fmt.fmt.pix.pixelformat) {
		warning("v4l2: %s: unexpectedly got %c%c%c%c\n", dev_name,
			pix[0], pix[1], pix[2], pix[3]);
		return ENODEV;
	}

	info("v4l2: %s: found valid V4L2 device (%u x %u) pixfmt=%c%c%c%c\n",
	       dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height,
	       pix[0], pix[1], pix[2], pix[3]);

	return 0;
}
コード例 #27
0
ファイル: libcam.cpp プロジェクト: sodeq/Jamtrap
void Camera::Init() {
  struct v4l2_capability cap;
  struct v4l2_cropcap cropcap;
  struct v4l2_crop crop;
  struct v4l2_format fmt;
  unsigned int min;

  if(-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {
    if (EINVAL == errno) {
      fprintf(stderr, "%s is no V4L2 device\n",name);
      exit(1);
    } else {
       errno_exit("VIDIOC_QUERYCAP");
    }
  }

  if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
    fprintf(stderr, "%s is no video capture device\n", name);
    exit(1);
  }

  switch(io) {
    case IO_METHOD_READ:
      if(!(cap.capabilities & V4L2_CAP_READWRITE)) {
        fprintf(stderr, "%s does not support read i/o\n", name);
        exit (1);
      }

      break;

    case IO_METHOD_MMAP:
    case IO_METHOD_USERPTR:
    if(!(cap.capabilities & V4L2_CAP_STREAMING)) {
      fprintf (stderr, "%s does not support streaming i/o\n", name);
      exit(1);
    }

    break;
  }


  CLEAR (cropcap);

  cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

  if(0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
    crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    crop.c = cropcap.defrect; /* reset to default */

    if(-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
      switch (errno) {
        case EINVAL:
          /* Cropping not supported. */
          break;
        default:
          /* Errors ignored. */
          break;
        }
      }
    } else {
      /* Errors ignored. */
    }

    CLEAR (fmt);

    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width       = width;
    fmt.fmt.pix.height      = height;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
    fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;


  if(-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))
    errno_exit ("VIDIOC_S_FMT");



/*
struct v4l2_standard s;
s.name[0]='A';
s.frameperiod.numerator=1;
s.frameperiod.denominator=fps;

if(-1==xioctl(fd, VIDIOC_S_STD, &s))
  errno_exit("VIDIOC_S_STD");
*/


struct v4l2_streamparm p;
p.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
//p.parm.capture.capability=V4L2_CAP_TIMEPERFRAME;
//p.parm.capture.capturemode=V4L2_MODE_HIGHQUALITY;
p.parm.capture.timeperframe.numerator=1;
p.parm.capture.timeperframe.denominator=fps;
p.parm.output.timeperframe.numerator=1;
p.parm.output.timeperframe.denominator=fps;
//p.parm.output.outputmode=V4L2_MODE_HIGHQUALITY;
//p.parm.capture.extendedmode=0;
//p.parm.capture.readbuffers=n_buffers;


if(-1==xioctl(fd, VIDIOC_S_PARM, &p))
  errno_exit("VIDIOC_S_PARM");

  //default values, mins and maxes
  struct v4l2_queryctrl queryctrl;

  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_BRIGHTNESS;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("brightness error\n");
    } else {
      printf("brightness is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("brightness is not supported\n");
  }
  mb=queryctrl.minimum;
  Mb=queryctrl.maximum;
  db=queryctrl.default_value;


  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_CONTRAST;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("contrast error\n");
    } else {
      printf("contrast is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("contrast is not supported\n");
  }
  mc=queryctrl.minimum;
  Mc=queryctrl.maximum;
  dc=queryctrl.default_value;


  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_SATURATION;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("saturation error\n");
    } else {
      printf("saturation is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("saturation is not supported\n");
  }
  ms=queryctrl.minimum;
  Ms=queryctrl.maximum;
  ds=queryctrl.default_value;


  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_HUE;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("hue error\n");
    } else {
      printf("hue is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("hue is not supported\n");
  }
  mh=queryctrl.minimum;
  Mh=queryctrl.maximum;
  dh=queryctrl.default_value;


  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_HUE_AUTO;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("hueauto error\n");
    } else {
      printf("hueauto is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("hueauto is not supported\n");
  }
  ha=queryctrl.default_value;


  memset(&queryctrl, 0, sizeof(queryctrl));
  queryctrl.id = V4L2_CID_SHARPNESS;
  if(-1 == xioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if(errno != EINVAL) {
      //perror ("VIDIOC_QUERYCTRL");
      //exit(EXIT_FAILURE);
      printf("sharpness error\n");
    } else {
      printf("sharpness is not supported\n");
    }
  } else if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf ("sharpness is not supported\n");
  }
  msh=queryctrl.minimum;
  Msh=queryctrl.maximum;
  dsh=queryctrl.default_value;

//TODO: TO ADD SETTINGS
//here should go custom calls to xioctl

//END TO ADD SETTINGS

  /* Note VIDIOC_S_FMT may change width and height. */

  /* Buggy driver paranoia. */
  min = fmt.fmt.pix.width * 2;
  if(fmt.fmt.pix.bytesperline < min)
    fmt.fmt.pix.bytesperline = min;
  min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
  if(fmt.fmt.pix.sizeimage < min)
    fmt.fmt.pix.sizeimage = min;

  switch(io) {
    case IO_METHOD_READ:
      init_read(fmt.fmt.pix.sizeimage);
      break;

    case IO_METHOD_MMAP:
      init_mmap();
      break;

    case IO_METHOD_USERPTR:
      init_userp(fmt.fmt.pix.sizeimage);
      break;
    }

}
コード例 #28
0
ファイル: core.c プロジェクト: rsisto/luaRoboEmb
void init_device()
{
    struct v4l2_capability cap;
    int ret;
    int sizeimage;

    if(xioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)
    {
        if(EINVAL == errno)
        {
            fprintf(stderr, "%s is no V4L2 device\n", dev_name);
            perror("EXIT_FAILURE");
            return;
        } 
        else
        {
            perror("VIDIOC_QUERYCAP");
            return ;
        }
    }

    if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
    {
        fprintf(stderr, "%s is no video capture device\n", dev_name);
        /*exit(EXIT_FAILURE);*/
        perror("EXIT_FAILURE");
        return;
    }

    memset(&(fmt), 0, sizeof(fmt));
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width = w;
    fmt.fmt.pix.height = h;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
    fmt.fmt.pix.field = V4L2_FIELD_NONE;
    
    v4lconvert_data = v4lconvert_create(fd);

    if(v4lconvert_data == NULL)
    {
        perror("v4lconvert_create");
        return;
    }
        
    if(v4lconvert_try_format(v4lconvert_data, &fmt, &src_fmt) != 0)
    {
        /*errno_exit("v4lconvert_try_format");*/
        perror("v4lconvert_try_format");
        return;
    }
    
    ret = xioctl(fd, VIDIOC_S_FMT, &src_fmt);
    sizeimage = src_fmt.fmt.pix.sizeimage;
    dst_buf = (unsigned char *)malloc(fmt.fmt.pix.sizeimage);

#ifdef DEBUG

    printf("raw pixfmt: %c%c%c%c %dx%d\n",
               src_fmt.fmt.pix.pixelformat & 0xff,
               (src_fmt.fmt.pix.pixelformat >> 8) & 0xff,
               (src_fmt.fmt.pix.pixelformat >> 16) & 0xff,
               (src_fmt.fmt.pix.pixelformat >> 24) & 0xff,
               src_fmt.fmt.pix.width, src_fmt.fmt.pix.height);
#endif    
    
    if(ret < 0)
    {
        perror("VIDIOC_S_FMT");
        return;
    }
    
#ifdef DEBUG
    printf("pixfmt: %c%c%c%c %dx%d\n",
           fmt.fmt.pix.pixelformat & 0xff,
           (fmt.fmt.pix.pixelformat >> 8) & 0xff,
           (fmt.fmt.pix.pixelformat >> 16) & 0xff,
           (fmt.fmt.pix.pixelformat >> 24) & 0xff,
           fmt.fmt.pix.width, fmt.fmt.pix.height);
           fmt.fmt.pix.width, fmt.fmt.pix.height);
    
    /* Note VIDIOC_S_FMT may change width and height. */
#endif

    w = fmt.fmt.pix.width;
    h = fmt.fmt.pix.height;
   
    init_mmap();
}
コード例 #29
0
ファイル: server_board.c プロジェクト: aravinthkumarj1/kemsys
static void init_device(void)
{
    struct v4l2_capability cap;
    struct v4l2_cropcap cropcap;
    struct v4l2_crop crop;
    struct v4l2_format fmt;
    unsigned int min;
    unsigned int i;
    enum v4l2_buf_type type;

    memset(&cap,0,sizeof(struct v4l2_capability));
    if (-1 == ioctl (fd, VIDIOC_QUERYCAP, &cap))
    {
        if (EINVAL == errno)
        {
            fprintf (stderr, "%s is no V4L2 device\n", dev_name);
            exit (EXIT_FAILURE);
        }
        else
            errno_exit ("VIDIOC_QUERYCAP");
    }

    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
    {
        fprintf (stderr, "%s is no video capture device\n", dev_name);
        exit (EXIT_FAILURE);
    }

    /* Select video input, video standard and tune here. */
    CLEAR (cropcap);
    cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if (0 == ioctl (fd, VIDIOC_CROPCAP, &cropcap))
    {
        crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        crop.c = cropcap.defrect; /* reset to default */
        if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop))
        {
            switch (errno)
            {
            case EINVAL:

                /* Cropping not supported. */
                break;

            default:

                /* Errors ignored. */
                break;
            }
        }
    }
    else
    {
        /* Errors ignored. */
        fprintf(stdout, "%s does not support VIDIOC_CROPCAP!!!\n", dev_name);
    }

    CLEAR (fmt);

    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    //fmt.fmt.pix.width       = HRT_DEFAULT_WIDTH;//640;
    //fmt.fmt.pix.height      = HRT_DEFAULT_HEIGHT;//480;
    fmt.fmt.pix.width       = video_width;//640;
    fmt.fmt.pix.height      = video_height;//480;
    //hrtview.depth  =          video_depth;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
    fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;

    if (-1 == ioctl (fd, VIDIOC_S_FMT, &fmt))
        errno_exit ("VIDIOC_S_FMT");

    /* Note VIDIOC_S_FMT may change width and height. */

    /* Buggy driver paranoia. */
    min = fmt.fmt.pix.width * 2;
    if (fmt.fmt.pix.bytesperline < min)
        fmt.fmt.pix.bytesperline = min;

    min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
    if (fmt.fmt.pix.sizeimage < min)
        fmt.fmt.pix.sizeimage = min;

    init_mmap ();
    fprintf(stdout, "%s is in memory mapping mode!\n", dev_name);

    /* start capturing */
    for (i = 0; i < n_buffers; ++i)
    {
        struct v4l2_buffer buf;

        CLEAR (buf);

        buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        buf.memory      = V4L2_MEMORY_MMAP;
        buf.index       = i;

        if (-1 == ioctl (fd, VIDIOC_QBUF, &buf))
            errno_exit ("VIDIOC_QBUF ... !!!");
    }

    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if (-1 == ioctl (fd, VIDIOC_STREAMON, &type))
        errno_exit ("VIDIOC_STREAMON");
}
コード例 #30
0
ファイル: camera.c プロジェクト: eugenelet/Dodgeball
static void init_device(int fd, camera_buffer *cam_buf, const char *dev_name)
{
	struct v4l2_capability cap;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_format fmt;
	unsigned int min;

#ifdef WATCH_SUPPORT_FORMAT
	/* watch support format. */
	struct v4l2_fmtdesc fmtdesc;

	fmtdesc.index=0;
	fmtdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;

	printf("Support formats:\n");
	while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
	{
		printf("\t%d.%s\n",fmtdesc.index+1,fmtdesc.description);
		fmtdesc.index++;
	}
	/* --End-- */
#endif


	if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {
		if (EINVAL == errno) {
			fprintf (stderr, "%s is no V4L2 device\n",
					dev_name);
			exit (EXIT_FAILURE);
		} else {
			errno_exit (__FILE__,__LINE__,"VIDIOC_QUERYCAP");
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
		fprintf (stderr, "%s is no video capture device\n",
				dev_name);
		exit (EXIT_FAILURE);
	}

	if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
		fprintf (stderr, "%s does not support streaming i/o\n",
				dev_name);
		exit (EXIT_FAILURE);
	}


	/* Select video input, video standard and tune here. */

	CLEAR (cropcap);

	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
		crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		crop.c = cropcap.defrect; /* reset to default */

		if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
			switch (errno) {
				case EINVAL:
					/* Cropping not supported. */
					break;
				default:
					/* Errors ignored. */
					break;
			}
		}
	} else {	
		/* Errors ignored. */
	}

	/* Set capture format. */
	CLEAR (fmt);
	fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width       = CAM_WIDTH; /* Camera capture width. */ 
	fmt.fmt.pix.height      = CAM_HEIGHT; /* Camera capture height. */
	fmt.fmt.pix.pixelformat = CAM_FORMAT;
	//fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
	fmt.fmt.pix.field       = V4L2_FIELD_ANY;

	if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))
		errno_exit (__FILE__,__LINE__,"VIDIOC_S_FMT");
	/* --End-- */
	/* Note VIDIOC_S_FMT may change width and height. */

#ifdef WATCH_CAPTURE_FORMAT

	/* Watch capture width, height, format and size. */
	printf("width:%d height:%d format:%x size=%d\n",
			fmt.fmt.pix.width,
			fmt.fmt.pix.height,
			fmt.fmt.pix.pixelformat,
			fmt.fmt.pix.sizeimage
		  );
	/* --end-- */
#endif

#ifdef WATCH_STREAM_PARAMETER
	/* Watch stream parameter */
	struct v4l2_streamparm parm;
	parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	if (-1 == xioctl (fd, VIDIOC_G_PARM, &parm))
		errno_exit (__FILE__,__LINE__,"VIDIOC_G_PARM");

	printf("capability:%u\n"
			"capturemode:%u\n"
			"frame.numerator:%u\n"
			"frame.denominator%u:\n"
			"extendedmode:%u\n"
			"readbuffers:%u\n",
			parm.parm.capture.capability,
			parm.parm.capture.capturemode,
			parm.parm.capture.timeperframe.numerator,
			parm.parm.capture.timeperframe.denominator,
			parm.parm.capture.extendedmode,
			parm.parm.capture.readbuffers
		  );
	/* --end-- */
#endif

	/* Buggy driver paranoia. */
	min = fmt.fmt.pix.width * 2;
	if (fmt.fmt.pix.bytesperline < min)
		fmt.fmt.pix.bytesperline = min;
	min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
	if (fmt.fmt.pix.sizeimage < min)
		fmt.fmt.pix.sizeimage = min;

	init_mmap(fd,cam_buf,dev_name);
}