⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v4lcapture.c

📁 机器人仿真软件
💻 C
📖 第 1 页 / 共 2 页
字号:
        return NULL;    }    return fg->sources[ch].name;}//--------------------------------------------------------------------------int fg_get_source_type( FRAMEGRABBER* fg, int ch ){    if ( ch > fg->caps.channels )    {        fprintf( stderr, "fg_get_source_type(): Invalid channel number!\n" );        return -1;    }    return fg->sources[ch].type;}//--------------------------------------------------------------------------int fg_set_channel( FRAMEGRABBER* fg, float freq ){    // The LOW flag means freq in 1/16 MHz, not 1/16 kHz    int scale = ( fg->tuner.flags & VIDEO_TUNER_LOW ) ? 16000 : 16;    int val = (int)( freq * scale );    if ( ioctl( fg->fd, VIDIOCSFREQ, &val ) < 0 )    {        perror( "fg_set_channel(): failed to tune channel" );        return -1;    }    return 0;}//--------------------------------------------------------------------------float fg_get_channel( FRAMEGRABBER* fg ){    // The LOW flag means freq in 1/16 MHz, not 1/16 kHz    int scale = ( fg->tuner.flags & VIDEO_TUNER_LOW ) ? 16 : 16000;    int val = 0;    float freq = 0;    if ( ioctl( fg->fd, VIDIOCGFREQ, &val ) < 0 )    {        perror( "fg_get_channel(): failed to query channel" );        return -1;    }    freq = val / scale;    return 0;}//--------------------------------------------------------------------------FRAME* fg_grab( FRAMEGRABBER* fg ){    return fg_grab_frame( fg,                          frame_new( fg->window.width,                                     fg->window.height,                                     fg->picture.palette ) );}//--------------------------------------------------------------------------FRAME* fg_grab_frame( FRAMEGRABBER* fg, FRAME* fr ){    int capture_frame = fg->cur_frame + 1;    //----------------------    // Very first time only    //----------------------    if ( fg->mbuf.frames > 1 && fg->cur_frame == -1 )    {        fg->cur_frame = 1;        // Set up capture parameters        fg->mmap.format = fg->picture.palette;        fg->mmap.frame  = fg->cur_frame;        fg->mmap.width  = fg->window.width;        fg->mmap.height = fg->window.height;        // Start capture        if ( ioctl( fg->fd, VIDIOCMCAPTURE, &(fg->mmap) ) < 0 )        {            perror( "fg_grab(): failed to capture initial frame" );            return NULL;        }    }    //----------------------------    // Start capturing next frame    //----------------------------    // Wrap counter    if ( capture_frame >= fg->mbuf.frames || capture_frame > fg->max_buffer)    {        capture_frame = 0;    }        // Set up capture parameters    fg->mmap.format = fg->picture.palette;    fg->mmap.frame  = capture_frame;    fg->mmap.width  = fg->window.width;    fg->mmap.height = fg->window.height;    // Start capture    if ( ioctl( fg->fd, VIDIOCMCAPTURE, &(fg->mmap) ) < 0 )    {        perror( "fg_grab(): failed to capture frame" );        return NULL;    }    //--------------------    // Save current frame    //--------------------    // Wait for end of frame    if ( ioctl( fg->fd, VIDIOCSYNC, &(fg->cur_frame) ) < 0 )    {        perror( "fg_grab(): failed to sync frame" );        return NULL;    }    // Save video buffer into our own memory    memcpy( fr->data,            fg->mb_map + fg->mbuf.offsets[fg->cur_frame],            frame_get_size( fr ) );    // Move along to the next one    fg->cur_frame = capture_frame;    return fr;}//--------------------------------------------------------------------------FRAME* fg_grab_read( FRAMEGRABBER* fg ){    FRAME* fr = frame_new( fg->window.width,                           fg->window.height,                           fg->picture.palette );    read( fg->fd,          fr->data,          frame_get_size( fr ) );    return fr;}//--------------------------------------------------------------------------int fg_set_brightness( FRAMEGRABBER* fg, int br ){    fg->picture.brightness = FG_PERCENT( br );    if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )    {        perror( "fg_set_brightness(): set attribute failed" );        return -1;    }    return 0;}//--------------------------------------------------------------------------int fg_set_contrast( FRAMEGRABBER* fg, int ct ){    fg->picture.contrast = FG_PERCENT( ct );    if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )    {        perror( "fg_set_contrast(): set attribute failed" );        return -1;    }    return 0;}//--------------------------------------------------------------------------FRAME* fg_new_compatible_frame( FRAMEGRABBER* fg ){    return frame_new( fg->window.width,                      fg->window.height,                      fg->picture.palette );}//--------------------------------------------------------------------------#define FROM_PC(n)      (n*100/65535)#define TEST_FLAG(v,f)  (((v)|(f))?"Yes":"___")void fg_dump_info(FRAMEGRABBER* fg){  int i;  int type = fg->caps.type;  if ( fg->fd < 1 )  {    fprintf( stderr, "fg_dump_info(): device not open/initialised!" );    return;  }  // Dump out the contents of the capabilities structure  printf( "\nFrame Grabber Details\n" );  printf( "=====================\n" );  printf( "  device    = %s\n", fg->device );  printf( "  fd handle = 0x%08xd\n", fg->fd );  // Capabilities  printf( "  caps.name      = %s\n", fg->caps.name );  printf( "  caps.channels  = %d\n", fg->caps.channels );  printf( "  caps.audio chs = %d\n", fg->caps.audios );  printf( "  caps.maxwidth  = %d\n", fg->caps.maxwidth );  printf( "  caps.maxheight = %d\n", fg->caps.maxheight );  printf( "  caps.minwidth  = %d\n", fg->caps.minwidth );  printf( "  caps.minheight = %d\n", fg->caps.minheight );  printf( "  caps.type = \n" );  printf( "\t%s:    VID_TYPE_CAPTURE"          "\tCan capture to memory\n",          TEST_FLAG(type, VID_TYPE_CAPTURE) );  printf( "\t%s:    VID_TYPE_TUNER"          "\t\tHas a tuner of some form\n",          TEST_FLAG( type, VID_TYPE_TUNER ) );  printf( "\t%s:    VID_TYPE_TELETEXT"          "\tHas teletext capability\n",          TEST_FLAG( type, VID_TYPE_TELETEXT ) );  printf( "\t%s:    VID_TYPE_OVERLAY"          "\tCan overlay images onto the frame buffer\n",          TEST_FLAG( type, VID_TYPE_OVERLAY ) );  printf( "\t%s:    VID_TYPE_CHROMAKEY"          "\tOverlay is Chromakeyed\n",          TEST_FLAG( type, VID_TYPE_CHROMAKEY ) );  printf( "\t%s:    VID_TYPE_CLIPPING"          "\tOverlay clipping is supported\n",          TEST_FLAG( type, VID_TYPE_CLIPPING ) );  printf( "\t%s:    VID_TYPE_FRAMERAM"          "\tOverlay overwrites frame buffer memory\n",          TEST_FLAG( type, VID_TYPE_FRAMERAM ) );  printf( "\t%s:    VID_TYPE_SCALES"          "\t\tThe hardware supports image scaling\n",          TEST_FLAG( type, VID_TYPE_SCALES ) );  printf( "\t%s:    VID_TYPE_MONOCHROME"          "\tImage capture is grey scale only\n",          TEST_FLAG( type, VID_TYPE_MONOCHROME ) );  printf( "\t%s:    VID_TYPE_SUBCAPTURE"          "\tCapture can be of only part of the image\n",          TEST_FLAG( type, VID_TYPE_SUBCAPTURE ) );  // Dump input sources  for ( i = 0; i < fg_get_source_count(fg); i++ )  {    printf( "  sources[%d].name = %s\n", i, fg_get_source_name(fg, i ) );    printf( "  sources[%d].norm = ...\n", i );    // Tuner info    // TODO: multiple tuners?    if (fg->sources[i].tuners > 0)      printf( "  tuner[0].name = %s\n", fg->tuner.name );  }  // Capture window  printf( "  window.x         = %u\n", fg->window.x );  printf( "  window.y         = %u\n", fg->window.y );  printf( "  window.width     = %u\n", fg->window.width );  printf( "  window.height    = %u\n", fg->window.height );  printf( "  window.chromakey = 0x%08x\n", fg->window.chromakey );  printf( "  window.flags     = %u\n", fg->window.flags );  // Picture  printf( "  picture.brightness = %u%%\n", FROM_PC(fg->picture.brightness ));  printf( "  picture.hue        = %u%%\n", FROM_PC(fg->picture.hue ));  printf( "  picture.colour     = %u%%\n", FROM_PC(fg->picture.colour ));  printf( "  picture.contrast   = %u%%\n", FROM_PC(fg->picture.contrast ));  printf( "  picture.whiteness  = %u%%\n", FROM_PC(fg->picture.whiteness ));  printf( "  picture.depth      = %u\n", fg->picture.depth );  printf( "  picture.palette    = %u\n", fg->picture.palette );  // mmap  // Dump out frame buffer setup	printf( "  fbuffer.base         = 0x%08x\n", (int)fg->fbuffer.base );  printf( "  fbuffer.width        = %u\n", fg->fbuffer.width );	printf( "  fbuffer.height       = %u\n", fg->fbuffer.height );	printf( "  fbuffer.depth        = %u\n", fg->fbuffer.depth );	printf( "  fbuffer.bytesperline = %u\n", fg->fbuffer.bytesperline );  // Dump memory buffer info  printf( "  mbuf.size   = %u\n", fg->mbuf.size );  printf( "  mbuf.frames = %u\n", fg->mbuf.frames );  for ( i = 0; i < fg->mbuf.frames; i++ )  {    printf( "  mbuf.offsets[%u] = %u\n", i, fg->mbuf.offsets[i] );  }  printf( "  mb_map      = 0x%08x\n", (int)(fg->mb_map) );}//==========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -