📄 capture.c
字号:
//--------------------------------------------------------------------------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; if ( ioctl( fg->fd, VIDIOCGFREQ, &val ) < 0 ) { perror( "fg_get_channel(): failed to query channel" ); return -1; } return ( val / scale );}//--------------------------------------------------------------------------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 frame (1)" ); return NULL; } } //---------------------------- // Start capturing next frame //---------------------------- // Wrap counter if ( capture_frame >= fg->mbuf.frames ) { 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 (2)" ); 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_hue( FRAMEGRABBER* fg, int hu ){ fg->picture.hue = FG_PERCENT( hu ); if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 ) { perror( "fg_set_hue(): set attribute failed" ); return -1; } return 0;}//--------------------------------------------------------------------------int fg_set_colour( FRAMEGRABBER* fg, int co ){ fg->picture.colour = FG_PERCENT( co ); if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 ) { perror( "fg_set_colour(): set attribute failed" ); return -1; } return 0;}//--------------------------------------------------------------------------int fg_set_color( FRAMEGRABBER* fg, int co ){ // This is the proper way to spell it... return fg_set_colour( fg, co );}//--------------------------------------------------------------------------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;}//--------------------------------------------------------------------------int fg_set_whiteness( FRAMEGRABBER* fg, int wh ){ fg->picture.whiteness = FG_PERCENT( wh ); if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 ) { perror( "fg_set_whiteness(): 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 fprintf(stderr, "\nFrame Grabber Details\n" ); fprintf(stderr, "=====================\n" ); fprintf(stderr, " device = %s\n", fg->device ); fprintf(stderr, " fd handle = 0x%08xd\n", fg->fd ); // Capabilities fprintf(stderr, " caps.name = %s\n", fg->caps.name ); fprintf(stderr, " caps.channels = %d\n", fg->caps.channels ); fprintf(stderr, " caps.audio chs = %d\n", fg->caps.audios ); fprintf(stderr, " caps.maxwidth = %d\n", fg->caps.maxwidth ); fprintf(stderr, " caps.maxheight = %d\n", fg->caps.maxheight ); fprintf(stderr, " caps.minwidth = %d\n", fg->caps.minwidth ); fprintf(stderr, " caps.minheight = %d\n", fg->caps.minheight ); fprintf(stderr, " caps.type = \n" ); fprintf(stderr, "\t%s: VID_TYPE_CAPTURE" "\tCan capture to memory\n", TEST_FLAG(type, VID_TYPE_CAPTURE) ); fprintf(stderr, "\t%s: VID_TYPE_TUNER" "\t\tHas a tuner of some form\n", TEST_FLAG( type, VID_TYPE_TUNER ) ); fprintf(stderr, "\t%s: VID_TYPE_TELETEXT" "\tHas teletext capability\n", TEST_FLAG( type, VID_TYPE_TELETEXT ) ); fprintf(stderr, "\t%s: VID_TYPE_OVERLAY" "\tCan overlay images onto the frame buffer\n", TEST_FLAG( type, VID_TYPE_OVERLAY ) ); fprintf(stderr, "\t%s: VID_TYPE_CHROMAKEY" "\tOverlay is Chromakeyed\n", TEST_FLAG( type, VID_TYPE_CHROMAKEY ) ); fprintf(stderr, "\t%s: VID_TYPE_CLIPPING" "\tOverlay clipping is supported\n", TEST_FLAG( type, VID_TYPE_CLIPPING ) ); fprintf(stderr, "\t%s: VID_TYPE_FRAMERAM" "\tOverlay overwrites frame buffer memory\n", TEST_FLAG( type, VID_TYPE_FRAMERAM ) ); fprintf(stderr, "\t%s: VID_TYPE_SCALES" "\t\tThe hardware supports image scaling\n", TEST_FLAG( type, VID_TYPE_SCALES ) ); fprintf(stderr, "\t%s: VID_TYPE_MONOCHROME" "\tImage capture is grey scale only\n", TEST_FLAG( type, VID_TYPE_MONOCHROME ) ); fprintf(stderr, "\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++ ) { fprintf(stderr, " sources[%d].name = %s\n", i, fg_get_source_name(fg, i ) ); fprintf(stderr, " sources[%d].norm = ...\n", i ); } // Tuner info fprintf(stderr, " tuner[0].name = %s\n", fg->tuner.name ); // Capture window fprintf(stderr, " window.x = %u\n", fg->window.x ); fprintf(stderr, " window.y = %u\n", fg->window.y ); fprintf(stderr, " window.width = %u\n", fg->window.width ); fprintf(stderr, " window.height = %u\n", fg->window.height ); fprintf(stderr, " window.chromakey = 0x%08x\n", fg->window.chromakey ); fprintf(stderr, " window.flags = %u\n", fg->window.flags ); // Picture fprintf(stderr, " picture.brightness = %u%%\n", FROM_PC(fg->picture.brightness )); fprintf(stderr, " picture.hue = %u%%\n", FROM_PC(fg->picture.hue )); fprintf(stderr, " picture.colour = %u%%\n", FROM_PC(fg->picture.colour )); fprintf(stderr, " picture.contrast = %u%%\n", FROM_PC(fg->picture.contrast )); fprintf(stderr, " picture.whiteness = %u%%\n", FROM_PC(fg->picture.whiteness )); fprintf(stderr, " picture.depth = %u\n", fg->picture.depth ); fprintf(stderr, " picture.palette = %u\n", fg->picture.palette ); // mmap // Dump out frame buffer setup fprintf(stderr, " fbuffer.base = %p\n", fg->fbuffer.base ); fprintf(stderr, " fbuffer.width = %u\n", fg->fbuffer.width ); fprintf(stderr, " fbuffer.height = %u\n", fg->fbuffer.height ); fprintf(stderr, " fbuffer.depth = %u\n", fg->fbuffer.depth ); fprintf(stderr, " fbuffer.bytesperline = %u\n", fg->fbuffer.bytesperline ); // Dump memory buffer info fprintf(stderr, " mbuf.size = %u\n", fg->mbuf.size ); fprintf(stderr, " mbuf.frames = %u\n", fg->mbuf.frames ); for ( i = 0; i < fg->mbuf.frames; i++ ) { fprintf(stderr, " mbuf.offsets[%u] = %u\n", i, fg->mbuf.offsets[i] ); } fprintf(stderr, " mb_map = %p\n", fg->mb_map );}//==========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -