📄 video_fbsd_bttv.c
字号:
int set_chroma( Fbttv *fbttv_dev, CamConfig *ccfg, int new_chroma ) { int ioctlval; new_chroma = camparam_normalize( CHROMA, new_chroma, &ioctlval ); if( ioctl( fbttv_dev->tune_fd, BT848_SCSAT, &ioctlval ) < 0 ) { camserv_log( MODNAME, "Error setting CHROMA: %s", strerror( errno )); return -1; } fbttv_dev->chroma = new_chroma; camconfig_set_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHROMA, new_chroma ); return 0;}/* * set_contrast: Set the contrast of the camera to a new contrast level. * The new (possibly modified) level will also be written * into the camconfig configuration. * * Arguments: fbttv_dev = Video device to set contrast of * ccfg = Camera configuration within which to set * the contrast * new_contrast = New contrast level. * * Return values: Returns -1 on error, 0 on success. */staticint set_contrast( Fbttv *fbttv_dev, CamConfig *ccfg, int new_contrast ) { int ioctlval; new_contrast = camparam_normalize( CONTR, new_contrast, &ioctlval ); if( ioctl( fbttv_dev->tune_fd, BT848_SCONT, &ioctlval ) < 0 ) { camserv_log( MODNAME, "Error setting contrast: %s", strerror( errno )); return -1; } fbttv_dev->contrast = new_contrast; camconfig_set_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CONTRAST, new_contrast ); return 0;}/* * set_brightness: Set the brightness of the camera to a new brightness level. * The new (possibly modified) level will also be written * into the camconfig configuration. * * Arguments: fbttv_dev = Video device to set brightness of * ccfg = Camera configuration within which to set * the brightness * new_bright = New brightness level. * * Return values: Returns -1 on error, 0 on success. */staticint set_brightness( Fbttv *fbttv_dev, CamConfig *ccfg, int new_bright ) { int ioctlval; new_bright = camparam_normalize( BRIGHT, new_bright, &ioctlval ); if( ioctl( fbttv_dev->tune_fd, BT848_SBRIG, &ioctlval ) < 0 ) { camserv_log( MODNAME, "Error brightness->%d : %s", ioctlval, strerror( errno ) ); return -1; } fbttv_dev->brightness = new_bright; camconfig_set_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_BRIGHTNESS, new_bright ); return 0;}staticint set_channel( Fbttv *fbttv_dev, CamConfig *ccfg, int new_channel ) { int ioctlval; ioctlval = new_channel; if( ioctl( fbttv_dev->tune_fd, TVTUNER_SETCHNL, &ioctlval ) < 0 ) { camserv_log( MODNAME, "Error channel->%d : %s", ioctlval, strerror( errno ) ); return -1; } else { camserv_log( MODNAME, "channel set to %d", ioctlval); } fbttv_dev->channel = new_channel; camconfig_set_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHANNEL, new_channel ); return 0;}staticint set_channelset (Fbttv * fbttv_dev, CamConfig *ccfg, int new_channelset) { int ioctlval; ioctlval = new_channelset; if( ioctl( fbttv_dev->tune_fd, TVTUNER_SETTYPE, &ioctlval ) < 0 ) { camserv_log( MODNAME, "Error channelset->%d : %s", ioctlval, strerror( errno ) ); return -1; } else { camserv_log( MODNAME, "channelset set to %d", ioctlval); } fbttv_dev->channelset = new_channelset; camconfig_set_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHANNELSET, new_channelset ); return 0;}/* * video_init: Initialize the video camera. This routine * will query the video device for the * capabilities, and select the optimal properties * for the given parameters. * * Arguments: fbbtv_dev = valid Fbttv object. * ccfg = Parameters to initialize the device with * * Return Value: Returns -1 on failure, else 0 */int video_init( Fbttv *fbttv_dev, CamConfig *ccfg ){ int capmethod = METEOR_CAP_CONTINOUS; if( fbttv_dev->initialized ) camserv_log( MODNAME, "Double initialization detected!" ); fbttv_dev->initialized = 0; if( set_input( fbttv_dev, ccfg ) == -1 || setup_pixelformat( fbttv_dev ) == -1 || set_geometry( fbttv_dev, ccfg ) == -1 ) { camserv_log( MODNAME, "Error initializing video" ); return -1; } set_brightness( fbttv_dev, ccfg, camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_BRIGHTNESS, CamParams[ BRIGHT ].def) ); set_chroma( fbttv_dev, ccfg, camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHROMA, CamParams[ CHROMA ].def ) ); set_contrast( fbttv_dev, ccfg, camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CONTRAST, CamParams[ CONTR ].def ) ); set_channelset( fbttv_dev, ccfg, camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHANNELSET, FBTTV_DEF_CHANNELSET)); set_channel( fbttv_dev, ccfg, camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_CHANNEL, FBTTV_DEF_CHANNEL)); fbttv_dev->autobright = camconfig_query_def_int( ccfg, fbttv_dev->section_name, FBTTVMOD_DEV_AUTOBRIGHT, FBTTV_DEF_AUTOBRIGHT ); if( ioctl( fbttv_dev->bttv_fd, METEORCAPTUR, &capmethod ) < 0 ){ camserv_log( MODNAME, "CaptureMode: %s", strerror( errno )); return -1; } /* Setup the parameters so the other filters can use the information */ camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_WIDTH, fbttv_dev->width ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_HEIGHT, fbttv_dev->height ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_MAXWIDTH, FBTTV_MAX_WIDTH ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_MINWIDTH, FBTTV_MIN_WIDTH ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_MAXHEIGHT, FBTTV_MAX_HEIGHT ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_MINHEIGHT, FBTTV_MIN_HEIGHT ); camconfig_set_int( ccfg, SEC_VIDEO, VIDCONFIG_ISB_N_W, 0 ); fbttv_dev->initialized = 1; return 0;}/* * video_deinit: Deinitialize a fbbtv device. This clears up captured * frames and the buffers used for storage .. This should * be done everytime the camera is to be re-configured, * (for every init call) * * Arguments: fbbtv_dev = Device to deinitialize * * Return values: Returns -1 on error, 0 on success. */int video_deinit( Fbttv *fbttv_dev ){ int stopcap; if( fbttv_dev->initialized == 0 ){ camserv_log( MODNAME, "Deinitialized without initializing device\n"); return -1; } stopcap = METEOR_CAP_STOP_CONT; if( ioctl( fbttv_dev->bttv_fd, METEORCAPTUR, &stopcap ) < 0 ) camserv_log( MODNAME, "StopCapture: %s", strerror( errno )); fbttv_dev->initialized = 0; return 0;}staticint adjust_contrast( int width, int height, const char *picbuf, int mean, Fbttv *fbttv_dev, CamConfig *ccfg ) { int dev, adjust = 0, newcontr; dev = camserv_get_pic_stddev( width, height, picbuf, 1, mean ); if( dev < (256 / 6) - 3 || dev > (256 / 6) + 3 ) { newcontr = fbttv_dev->contrast; adjust = 1; if( dev > (256 / 6 ) + 3 ) { newcontr--; } else { newcontr++; } } if( adjust ) { set_contrast( fbttv_dev, ccfg, newcontr ); return 1; } else { return 0; }}staticint adjust_bright( int width, int height, const char *picbuf, Fbttv *fbttv_dev, CamConfig *ccfg ){ int totmean, newbright, adjust = 0, adjustcont = 0; if( !fbttv_dev->autobright || --fbttv_dev->autoleft > 0 ) return 0; totmean = camserv_get_pic_mean( width, height, picbuf, 1, 0, 0, width, height ); if( totmean < (256 / 2) - 10 || totmean > (256 / 2) + 10 ) { newbright = fbttv_dev->brightness; if( totmean > (256 / 2) + 10 ){ newbright-=1; } else { newbright+=1; } adjust = 1; } adjustcont = adjust_contrast( width, height, picbuf, totmean, fbttv_dev, ccfg ); if( adjust ) { set_brightness( fbttv_dev, ccfg, newbright ); return 1; } if( adjustcont ) return 1; fbttv_dev->autoleft = fbttv_dev->autobright; return 0;} static voidbgr2rgb (char *out_addr, char *in_addr, int rowstride, int width, int height){ int i, j; for (i=0; i<height; i++){ char *q = out_addr + i * rowstride; char *p = in_addr + i * rowstride; for (j=0; j<width; j++) { q[2] = p[0]; q[1] = p[1]; q[0] = p[2]; q += 3; p += 3; } }}/* * video_snap: Take a snapshot from the video device, and put it into * place_buffer. The format is a RGB format, and place_buffer * is expected to contain enough space to store the * width * height * 3 bytes * * Arguments: fbbtv_dev = Video device to snap the picture of * place_buffer = Storage location to put the picture * vinfo = Storage location for information about the picture * snapped. * * Return values: Returns -1 on error, 0 on success. */int video_snap( Fbttv *fbttv_dev, char *place_buffer, Video_Info *vinfo, CamConfig *ccfg ){ bgr2rgb( place_buffer, fbttv_dev->picbuf, fbttv_dev->width * 3, fbttv_dev->width, fbttv_dev->height ); vinfo->width = fbttv_dev->width; vinfo->height = fbttv_dev->height; vinfo->is_black_white = 0; vinfo->nbytes = vinfo->width * vinfo->height * 3; adjust_bright( vinfo->width, vinfo->height, place_buffer, fbttv_dev, ccfg ); return 0;}/* * video_get_geom: Get geometry information about the video device. * The video device must be opened before the geometry * can be gotten. * * Arguments: fbbtv_dev = Video device as from video_open * geom = Location to place geometry information * * Return values: Returns an ORed combination of VIDEO_GEOM_*, representing * which information in the returned structure is valid. * 0 is returned on function failure. */int video_get_geom( Fbttv *fbttv_dev, Video_Geometry *geom ){ geom->max_width = FBTTV_MAX_WIDTH; geom->max_height = FBTTV_MAX_HEIGHT; geom->min_width = FBTTV_MIN_WIDTH; geom->min_height = FBTTV_MIN_HEIGHT; if( fbttv_dev->initialized == 1 ) { geom->cur_width = fbttv_dev->width; geom->cur_height = fbttv_dev->height; return VIDEO_GEOM_MAX | VIDEO_GEOM_MIN | VIDEO_GEOM_CUR; } return VIDEO_GEOM_MAX | VIDEO_GEOM_MIN;} /* * modinfo_query: Routine to return information about the variables * accessed by this particular module. * * Return values: Returns a malloced ModInfo structure, for which * the caller must free, or NULL on failure. */ModInfo *modinfo_query(){ ModInfo *res; char varname[ 1024 ]; if( (res = modinfo_create( 0 )) == NULL ) return NULL; return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -