📄 grabber-bsd.cxx
字号:
/* ========================================================================= grabber-bsd.cxx Grabber code for the Matrox Meteor API and BSD bktr Bt848/878 driver. Copyright (c) 2000 Roger Hardiman <roger@freebsd.org> =========================================================================*/#include <ptlib.h>#include <sys/types.h>#include <sys/fcntl.h> #include <sys/ioctl.h>#include <sys/mman.h>extern "C" {// Basic Meteor API#if defined(P_FREEBSD)#include <machine/ioctl_meteor.h>#endif#if defined(P_OPENBSD)#include <i386/ioctl_meteor.h>#endif// If we want the Bt848 specific ioctls, like the tuner, we will// need these include files too//#if defined(P_FREEBSD)//#include <machine/ioctl_bt848.h>//#endif////#if defined(P_OPENBSD)//#include <i386/ioctl_bt848.h>//#endif}#include "grabber-bsd.h"// Open the grabber-bsd object// Open the grabber device and mmap the grab bufferVideoGrabber::VideoGrabber(int videoInput, BOOL videoIsPal){ int buffer_size = 768*576*3; // Open the device. This could be /dev/bktr0 or /dev/meteor0 fd_ = open("/dev/bktr0", O_RDONLY); if (fd_ >= 0) { operational = 1; /* mmap the grab buffer */ mem = (char *)mmap(0,buffer_size,PROT_READ,0,fd_,0); frame= (u_char *)mem; if (mem == (char*)-1) { cout << "Failed to allocate memory map in grabber-bsd" << endl; close(fd_); operational = 0; } } else { operational = 0; } if(operational==0) { // allocate memory for the test image // if the video capture device cannot be opened // OR if the mmap failed. mem= new char[buffer_size]; frame= (u_char *)mem; } port_ = videoInput; pal_ = videoIsPal; running = 0;}// Close the grabber-bsd objectVideoGrabber::~VideoGrabber(){ if(operational) { close(fd_); } else delete mem;}// Put the grabber into continuous mode// Frames are grabbed continuously into the mmapped buffervoid VideoGrabber::Start(){ if(operational) { int c; c = METEOR_CAP_CONTINOUS; if (-1 == ioctl(fd_, METEORCAPTUR, &c)) { perror("ioctl METEORCAPTUR (start) failed"); } } Grabber::Start(); running = 1;}// Stop the video caputrevoid VideoGrabber::Stop(){ running = 0; if (operational) { int c; c = METEOR_CAP_STOP_CONT; if (-1 == ioctl(fd_, METEORCAPTUR, &c)) { perror("ioctl METEORCAPTUR (stop) failed"); } } Grabber::Stop();}// Get a video frame from the mmapped buffer.// As grabbing goes on continuously, this simply returns a pointer// into the mmapped buffervoid VideoGrabber::Grab(VideoFrame *vf){ SetSize(vf->width,vf->height); vf->ts= grab_count*33; if (operational) { vf->frameptr= frame; vf->crvec = 0; } else { // Grabber is not operational, so generate fictional image. Grabber::Grab(vf); }}// Set the image grab size// If we are already grabbing, we need to stop grabbing,// set the size, and then restart grabbing.void VideoGrabber::SetSize(int _width,int _height){ int was_running = running; if((width!=_width)||(height!=_height)) { if (was_running) { Stop(); Grabber::SetSize(_width,_height); Format(); Start(); } else { Grabber::SetSize(_width,_height); Format(); } }}// Set the video capture format// YUV 420 format, using the input specified in the 'port_' variable.// and the Video Format specified in the 'pal_' variable.// PAL is 768x576// NTSC is 640x480#define HALF_PAL_HEIGHT 288#define HALF_NTSC_HEIGHT 240void VideoGrabber::Format(){ if (operational) { int c; struct meteor_geomet geo; // Set the Video Input c = port_; if (ioctl(fd_, METEORSINPUT, &c) < 0) { perror("ioctl METEORSINPUT failed"); } // Set the Video Format if (pal_ == TRUE) c = METEOR_FMT_PAL; else c = METEOR_FMT_NTSC; if (ioctl(fd_, METEORSFMT, &c) < 0) { perror("ioctl METEORSFMT failed"); } // Set the Video Capture Format geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; geo.rows = height; geo.columns = width; geo.frames = 1; // We want to avoid interlaced video where possible. // If we know the video type (PAL or NTSC) we can enable // single field capture if the height is <= half the video height. if ( ((pal_ == TRUE) && (height <= HALF_PAL_HEIGHT)) || ((pal_ == FALSE) && (height <= HALF_NTSC_HEIGHT)) ) geo.oformat |= METEOR_GEO_EVEN_ONLY; if (ioctl(fd_, METEORSETGEO, &geo) < 0) { perror("ioctl METEORSETGEO failed"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -