📄 vfakeio.cxx
字号:
"**", " ", " ", " ", "**", "**", " ", " " }}, { ';', { " ", " ", " ", " **", " **", " ", " ", " **", " **", "* ", " " }}, { '<', { " *", " * ", " * ", " * ", "* ", " * ", " * ", " * ", " *", " ", " " }}, { '=', { " ", " ", " ", "*****", " ", "*****", " ", " ", " ", " ", " " }}, { '>', { "* ", " * ", " * ", " * ", " *", " * ", " * ", " * ", "* ", " ", " " }}, { '?', { " *** ", "* *", " *", " *", " * ", " * ", " * ", " ", " * ", " ", " " }}, { '@', { " **** ", "* *", "* *", "* ***", "* * *", "* * **", "* * *", "* ", " **** ", " ", " " }}, { '[', { "***", "* ", "* ", "* ", "* ", "* ", "* ", "* ", "***", " ", " " }}, { '\\',{ "* ", "* ", " * ", " * ", " * ", " * ", " * ", " *", " *", " ", " " }}, { ']', { "***", " *", " *", " *", " *", " *", " *", " *", "***", " ", " " }}, { '^', { " * ", " * * ", "* *", " ", " ", " ", " ", " ", " ", " ", " " }}, { '_', { " ", " ", " ", " ", " ", " ", " ", " ", "*****", " ", " " }}, { '`', { "*** ", " ** ", " *", " ", " ", " ", " ", " ", " ", " ", " " }}, { '{', { " *", " * ", " * ", " * ", "* ", " * ", " * ", " * ", " *", " ", " " }}, { '|', { "*", "*", "*", "*", "*", "*", "*", "*", "*", " ", " " }}, { '}', { "* ", " * ", " * ", " * ", " *", " * ", " * ", " * ", "* ", " ", " " }}, { '~', { " * ", "* * *", " * ", " ", " ", " ", " ", " ", " ", " ", " " }},};/** This class defines a video input device that generates fictitous image data.*/class PVideoInputDevice_FakeVideo : public PVideoInputDevice{ PCLASSINFO(PVideoInputDevice_FakeVideo, PVideoInputDevice); public: /** Create a new (fake) video input device. */ PVideoInputDevice_FakeVideo(); /**Open the device given the device name. */ BOOL Open( const PString & deviceName, /// Device name to open BOOL startImmediate = TRUE /// Immediately start device ); /**Determine of the device is currently open. */ BOOL IsOpen() ; /**Close the device. */ BOOL Close(); /**Start the video device I/O. */ BOOL Start(); /**Stop the video device I/O capture. */ BOOL Stop(); /**Determine if the video device I/O capture is in progress. */ BOOL IsCapturing(); /**Get a list of all of the drivers available. */ static PStringList GetInputDeviceNames(); virtual PStringList GetDeviceNames() const { return GetInputDeviceNames(); } /**Get the maximum frame size in bytes. Note a particular device may be able to provide variable length frames (eg motion JPEG) so will be the maximum size of all frames. */ virtual PINDEX GetMaxFrameBytes(); /**Grab a frame. There will be a delay in returning, as specified by frame rate. */ virtual BOOL GetFrameData( BYTE * buffer, /// Buffer to receive frame PINDEX * bytesReturned = NULL /// Optional bytes returned. ); /**Grab a frame. Do not delay according to the current frame rate. */ virtual BOOL GetFrameDataNoDelay( BYTE * buffer, /// Buffer to receive frame PINDEX * bytesReturned = NULL /// OPtional bytes returned. ); /**A test image that contains area of low and high resolution. The picture changes every second*/ void GrabMovingBlocksTestFrame(BYTE *resFrame); /**a test image consisting of a horizontal line moving down the image, with a constantly varying background. */ void GrabMovingLineTestFrame(BYTE *resFrame); /**Generate a constant image, which contains the colours for a NTSC test frame.*/ void GrabNTSCTestFrame(BYTE *resFrame); /**Generate three bouncing boxes, which bounce from a different height */ void GrabBouncingBoxes(BYTE *resFrame); /**Generate a static image, containing a constant field of grey. */ void GrabBlankImage(BYTE *resFrame); /**Generate the original form of the moving blocks test frame. */ void GrabOriginalMovingBlocksFrame(BYTE *resFrame); /**Generate a textual output on the fake video image */ void GrabTextVideoFrame(BYTE *resFrame); /**Get the stucture holding required letter for GetTextVideoFrame() */ OneVFakeLetterData *FindLetter(char ascii); /** Fills a region of the image with a constant colour. */ void FillRect(BYTE * frame, int x, int y, int rectWidth, int rectHeight, int r, int g, int b); /**Set the video format to be used. Default behaviour sets the value of the videoFormat variable and then returns the IsOpen() status. */ virtual BOOL SetVideoFormat( VideoFormat videoFormat /// New video format ); /**Get the number of video channels available on the device. Default behaviour returns 1. */ virtual int GetNumChannels() ; /**Set the video channel to be used on the device. Default behaviour sets the value of the channelNumber variable and then returns the IsOpen() status. */ virtual BOOL SetChannel( int channelNumber /// New channel number for device. ); /**Set the colour format to be used. Default behaviour sets the value of the colourFormat variable and then returns the IsOpen() status. */ virtual BOOL SetColourFormat( const PString & colourFormat // New colour format for device. ); /**Set the video frame rate to be used on the device. Default behaviour sets the value of the frameRate variable and then return the IsOpen() status. */ virtual BOOL SetFrameRate( unsigned rate /// Frames per second ); /**Get the minimum & maximum size of a frame on the device. Default behaviour returns the value 1 to UINT_MAX for both and returns FALSE. */ virtual BOOL GetFrameSizeLimits( unsigned & minWidth, /// Variable to receive minimum width unsigned & minHeight, /// Variable to receive minimum height unsigned & maxWidth, /// Variable to receive maximum width unsigned & maxHeight /// Variable to receive maximum height ) ; /**Set the frame size to be used. Default behaviour sets the frameWidth and frameHeight variables and returns the IsOpen() status. */ virtual BOOL SetFrameSize( unsigned width, /// New width of frame unsigned height /// New height of frame ); void ClearMapping() { return ; } /**Try all known video formats & see which ones are accepted by the video driver */ virtual BOOL TestAllFormats() { return TRUE; } protected: unsigned grabCount; PINDEX videoFrameSize; PINDEX scanLineWidth; PINDEX bytesPerPixel; // 2==YUV420P, 3=RGB24, 4=RGB32 PString textLine[MAX_L_HEIGHT];};PCREATE_VIDINPUT_PLUGIN(FakeVideo);///////////////////////////////////////////////////////////////////////////////// PVideoInputDevice_FakeVideoPVideoInputDevice_FakeVideo::PVideoInputDevice_FakeVideo(){ SetColourFormat("RGB24"); channelNumber = 3; // Blank screen grabCount = 0; SetFrameRate(10);}BOOL PVideoInputDevice_FakeVideo::Open(const PString & /*devName*/, BOOL /*startImmediate*/){ deviceName = "fake"; return TRUE; }BOOL PVideoInputDevice_FakeVideo::IsOpen() { return TRUE;}BOOL PVideoInputDevice_FakeVideo::Close(){ return TRUE;}BOOL PVideoInputDevice_FakeVideo::Start(){ return TRUE;}BOOL PVideoInputDevice_FakeVideo::Stop(){ return TRUE;}BOOL PVideoInputDevice_FakeVideo::IsCapturing(){ return IsOpen();}PStringList PVideoInputDevice_FakeVideo::GetInputDeviceNames(){ PStringList list; list.AppendString("fake"); return list;}BOOL PVideoInputDevice_FakeVideo::SetVideoFormat(VideoFormat newFormat){ return PVideoDevice::SetVideoFormat(newFormat);}int PVideoInputDevice_FakeVideo::GetNumChannels() { return eNumTestPatterns; }BOOL PVideoInputDevice_FakeVideo::SetChannel(int newChannel){ return PVideoDevice::SetChannel(newChannel);}BOOL PVideoInputDevice_FakeVideo::SetColourFormat(const PString & newFormat){ if (newFormat *= "RGB32") bytesPerPixel = 4; else if (newFormat *= "RGB24") bytesPerPixel = 3; else if (newFormat *= "YUV420P") bytesPerPixel = 2; else return FALSE; if (!PVideoDevice::SetColourFormat(newFormat)) return FALSE; return SetFrameSize(frameWidth, frameHeight);}BOOL PVideoInputDevice_FakeVideo::SetFrameRate(unsigned rate){ if (rate < 1) rate = 1; else if (rate > 50) rate = 50; return PVideoDevice::SetFrameRate(rate);}BOOL PVideoInputDevice_FakeVideo::GetFrameSizeLimits(unsigned & minWidth, unsigned & minHeight, unsigned & maxWidth, unsigned & maxHeight) { minWidth = 16; minHeight = 12; maxWidth = 1024; maxHeight = 768; return TRUE;}BOOL PVideoInputDevice_FakeVideo::SetFrameSize(unsigned width, unsigned height){ if (!PVideoDevice::SetFrameSize(width, height)) return FALSE; videoFrameSize = CalculateFrameBytes(frameWidth, frameHeight, colourFormat); scanLineWidth = videoFrameSize/frameHeight; return videoFrameSize > 0;}PINDEX PVideoInputDevice_FakeVideo::GetMaxFrameBytes(){ return GetMaxFrameBytesConverted(videoFrameSize);}BOOL PVideoInputDevice_FakeVideo::GetFrameData(BYTE * buffer, PINDEX * bytesReturned){ frameTimeError += msBetweenFrames; PTime now; PTimeInterval delay = now - previousFrameTime; frameTimeError -= (int)delay.GetMilliSeconds(); previousFrameTime = now; if (frameTimeError > 0) { PTRACE(6, "FakeVideo\t Sleep for " << frameTimeError << " milli seconds"); PThread::Sleep(frameTimeError); } return GetFrameDataNoDelay(buffer, bytesReturned);} BOOL PVideoInputDevice_FakeVideo::GetFrameDataNoDelay(BYTE *destFrame, PINDEX * bytesReturned){ grabCount++; // Make sure are NUM_PATTERNS cases here. switch(channelNumber){ case eMovingBlocks : GrabMovingBlocksTestFrame(destFrame); break; case eMovingLine : GrabMovingLineTestFrame(destFrame); break; case eBouncingBoxes : GrabBouncingBoxes(destFrame); break; case eBlankImage : GrabBlankImage(destFrame); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -