📄 videoio.cxx
字号:
/* * videoio.cxx * * Classes to support streaming video input (grabbing) and output. * * Portable Windows Library * * Copyright (c) 1993-2000 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Contributor(s): Mark Cooke (mpc@star.sr.bham.ac.uk) * * $Log: videoio.cxx,v $ * Revision 1.55 2005/08/23 12:42:23 rjongbloed * Fixed problems with negative hight native flipping not working with all sizes. * * Revision 1.54 2005/08/09 09:08:12 rjongbloed * Merged new video code from branch back to the trunk. * * Revision 1.53.6.2 2005/07/17 12:17:41 rjongbloed * Fixed deadlock changing size * * Revision 1.53.6.1 2005/07/17 09:27:08 rjongbloed * Major revisions of the PWLib video subsystem including: * removal of F suffix on colour formats for vertical flipping, all done with existing bool * working through use of RGB and BGR formats so now consistent * cleaning up the plug in system to use virtuals instead of pointers to functions. * rewrite of SDL to be a plug in compatible video output device. * extensive enhancement of video test program * * Revision 1.53 2005/01/04 08:09:42 csoutheren * Fixed Linux configure problems * * Revision 1.52 2004/11/17 10:13:14 csoutheren * Fixed compilation with gcc 4.0.0 * * Revision 1.51 2004/10/27 09:24:18 dsandras * Added patch from Nicola Orru' to convert from SBGGR8 to YUV420P. Thanks! * * Revision 1.50 2004/10/23 10:54:39 ykiryanov * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port * * Revision 1.49 2004/08/16 06:40:59 csoutheren * Added adapters template to make device plugins available via the abstract factory interface * * Revision 1.48 2004/04/18 12:49:22 csoutheren * Patches to video code thanks to Guilhem Tardy (hope I get it right this time :) * * Revision 1.47 2004/04/03 23:53:10 csoutheren * Added various changes to improce compatibility with the Sun Forte compiler * Thanks to Brian Cameron * Added detection of readdir_r version * * Revision 1.46 2004/01/18 14:25:58 dereksmithies * New methods to make the opening of video input devices easier. * * Revision 1.45 2004/01/17 17:41:50 csoutheren * Changed to use PString::MakeEmpty * * Revision 1.44 2003/12/14 10:01:02 rjongbloed * Resolved issue with name space conflict os static and virtual forms of GetDeviceNames() function. * * Revision 1.43 2003/11/23 22:17:35 dsandras * Added YUV420P to BGR24 and BGR32 conversion. * * Revision 1.42 2003/11/19 04:30:15 csoutheren * Changed to support video output plugins * * Revision 1.41 2003/11/18 10:40:51 csoutheren * Added pragma implementation to fix vtable link problems * * Revision 1.40 2003/11/18 06:46:38 csoutheren * Changed to support video input plugins * * Revision 1.39 2003/05/14 07:51:23 rjongbloed * Changed SetColourFormatConverter so if converter already in place no * change is made. * Fixed some trace logs. * * Revision 1.38 2003/04/03 23:21:34 robertj * Added reversed RGB byte order versions (BGR24), thanks Damien Sandras * * Revision 1.37 2003/03/21 04:09:33 robertj * Changed PPM video output device so you can specify the full format of the * output file uinng printf command for the frame number eg %u or %03i or * something. If there is no %u in the Opan() argument, a %u is added after * the filename. * Fixed video output RGB SetFrameData so abide by correct semantics. The input * is aways to be what was set using SetColourFormat() or * SetColourFormatConverter(). * * Revision 1.36 2003/03/20 23:42:01 dereks * Make PPM video output device work correctly. * * Revision 1.35 2003/03/17 07:50:41 robertj * Added OpenFull() function to open with all video parameters in one go. * Made sure vflip variable is set in converter even if converter has not * been set yet, should not depend on the order of functions! * Removed canCaptureVideo variable as this is really a virtual function to * distinguish PVideoOutputDevice from PVideoInputDevice, it is not dynamic. * Made significant enhancements to PVideoOutputDevice class. * Added PVideoOutputDevice descendants for NULL and PPM files. * * Revision 1.34 2002/09/01 23:25:26 dereks * Documentation fix from Walter Whitlock. Many thanks. * * Revision 1.33 2002/09/01 22:38:21 dereks * Remove previous clarification, cause it breaks openphone code. * * Revision 1.32 2002/08/30 02:31:43 dereks * Make operation of the code more clear. Thanks Diego Tartara * * Revision 1.31 2002/04/12 08:24:53 robertj * Added text string output for tracing video format. * * Revision 1.30 2002/04/07 22:49:32 rogerh * Add some comments * * Revision 1.29 2002/04/05 06:41:54 rogerh * Apply video changes from Damien Sandras <dsandras@seconix.com>. * The Video Channel and Format are no longer set in Open(). Instead * call the new SetVideoChannelFormat() method. This makes video capture * and GnomeMeeting more stable with certain Linux video capture devices. * * Revision 1.28 2002/02/20 02:37:26 dereks * Initial release of Firewire camera support for linux. * Many thanks to Ryutaroh Matsumoto <ryutaroh@rmatsumoto.org>. * * Revision 1.27 2002/01/17 20:20:46 dereks * Adjust PVideoInputDevice::SetVFlipState to cope better when a converter class is * not attached. Thanks Walter Whitlock. * * Revision 1.26 2002/01/16 07:51:16 robertj * MSVC compatibilty changes * * Revision 1.25 2002/01/14 02:59:41 robertj * Added preferred colour format selection, thanks Walter Whitlock * * Revision 1.24 2002/01/08 01:32:20 robertj * Tidied up some PTRACE debug output. * * Revision 1.23 2002/01/04 04:11:45 dereks * Add video flip code from Walter Whitlock, which flips code at the grabber. * * Revision 1.22 2001/12/10 22:23:43 dereks * Enable resize of CIF source image into QCIF size. * * Revision 1.21 2001/12/06 22:15:09 dereks * Additional debugging lines * * Revision 1.20 2001/11/28 04:45:14 robertj * Added Win32 flipped RGB colour formats. * * Revision 1.19 2001/11/28 00:07:32 dereks * Locking added to PVideoChannel, allowing reader/writer to be changed mid call * Enabled adjustment of the video frame rate * New fictitous image, a blank grey area * * Revision 1.18 2001/09/25 04:25:38 dereks * Add fix from Stelian Pop to improve the field of view for * the small image with a Sony Vaio Motion Eye. Many thanks. * * Revision 1.17 2001/08/03 04:21:51 dereks * Add colour/size conversion for YUV422->YUV411P * Add Get/Set Brightness,Contrast,Hue,Colour for PVideoDevice, and * Linux PVideoInputDevice. * Add lots of PTRACE statement for debugging colour conversion. * Add support for Sony Vaio laptop under linux. Requires 2.4.7 kernel. * * Revision 1.16 2001/06/27 17:23:33 rogerh * Back out my previous change * * Revision 1.15 2001/06/26 15:48:31 rogerh * Do not call GetInputDeviceName if there is no video grabber code * * Revision 1.14 2001/05/22 23:38:45 robertj * Fixed bug in PVideoOutputDevice, removed redundent SetFrameSize. * * Revision 1.13 2001/03/20 02:21:57 robertj * More enhancements from Mark Cooke * * Revision 1.12 2001/03/08 08:31:34 robertj * Numerous enhancements to the video grabbing code including resizing * infrastructure to converters. Thanks a LOT, Mark Cooke. * * Revision 1.11 2001/03/08 02:18:45 robertj * Added improved defaulting of video formats so Open() does not fail. * Removed the requirement that the device be open before you can set * formats such as colour, video, channel number etc. * * Revision 1.10 2001/03/07 01:41:03 dereks * Fix memory leak, on destroying PVideoDevice * Ensure converter class is resized correctly. * * Revision 1.9 2001/03/06 23:34:20 robertj * Added static function to get input device names. * Moved some inline virtuals to non-inline. * * Revision 1.8 2001/03/05 01:12:41 robertj * Added more source formats for conversion, use list. Thanks Mark Cooke. * * Revision 1.7 2001/03/03 05:06:31 robertj * Major upgrade of video conversion and grabbing classes. * * Revision 1.6 2000/12/19 22:20:26 dereks * Add video channel classes to connect to the PwLib PVideoInputDevice class. * Add PFakeVideoInput class to generate test images for video. * * Revision 1.5 2000/11/09 00:20:58 robertj * Added qcif size constants * * Revision 1.4 2000/07/26 03:50:50 robertj * Added last error variable to video device. * * Revision 1.3 2000/07/26 02:13:48 robertj * Added some more "common" bounds checking to video device. * * Revision 1.2 2000/07/25 13:38:26 robertj * Added frame rate parameter to video frame grabber. * * Revision 1.1 2000/07/15 09:47:35 robertj * Added video I/O device classes. * */#ifndef _WIN32_WCE#pragma implementation "videoio.h"#endif // !_WIN32_WCE #include <ptlib.h>#include <ptlib/videoio.h>#include <ptlib/vconvert.h>namespace PWLibStupidWindowsHacks { int loadVideoStuff;};namespace PWLib { PFactory<PDevicePluginAdapterBase>::Worker< PDevicePluginAdapter<PVideoInputDevice> > vidinChannelFactoryAdapter("PVideoInputDevice", TRUE); PFactory<PDevicePluginAdapterBase>::Worker< PDevicePluginAdapter<PVideoOutputDevice> > vidoutChannelFactoryAdapter("PVideoOutputDevice", TRUE);};template <> PVideoInputDevice * PDevicePluginFactory<PVideoInputDevice>::Worker::Create(const PString & type) const{ return PVideoInputDevice::CreateDevice(type);}template <> PVideoOutputDevice * PDevicePluginFactory<PVideoOutputDevice>::Worker::Create(const PString & type) const{ return PVideoOutputDevice::CreateDevice(type);}///////////////////////////////////////////////////////////////////////////////#if PTRACINGostream & operator<<(ostream & strm, PVideoDevice::VideoFormat fmt){ static const char * const VideoFormatNames[PVideoDevice::NumVideoFormats] = { "PAL", "NTSC", "SECAM", "Auto" }; if (fmt < PVideoDevice::NumVideoFormats && VideoFormatNames[fmt] != NULL) strm << VideoFormatNames[fmt]; else strm << "VideoFormat<" << (unsigned)fmt << '>'; return strm;}#endif///////////////////////////////////////////////////////////////////////////////// PVideoDevicePVideoDevice::PVideoDevice(){ lastError = 0; videoFormat = Auto; channelNumber = -1; // -1 will find the first working channel number. frameWidth = CIFWidth; frameHeight = CIFHeight; nativeVerticalFlip = FALSE; converter = NULL; SetFrameRate(0);}PVideoDevice::~PVideoDevice(){ if (converter) delete converter;}BOOL PVideoDevice::OpenFull(const OpenArgs & args, BOOL startImmediate){ if (args.deviceName[0] == '#') { PStringArray devices = GetDeviceNames(); PINDEX id = args.deviceName.Mid(1).AsUnsigned(); if (id == 0 || id > devices.GetSize()) return FALSE; if (!Open(devices[id-1], FALSE)) return FALSE; } else { if (!Open(args.deviceName, FALSE)) return FALSE; } if (!SetVideoFormat(args.videoFormat)) return FALSE; if (!SetChannel(args.channelNumber)) return FALSE; if (args.convertFormat) { if (!SetColourFormatConverter(args.colourFormat)) return FALSE; } else { if (!SetColourFormat(args.colourFormat)) return FALSE; } if (args.rate > 0) { if (!SetFrameRate(args.rate)) return FALSE; } if (args.convertSize) { if (!SetFrameSizeConverter(args.width, args.height, args.scaleSize)) return FALSE; } else { if (!SetFrameSize(args.width, args.height)) return FALSE; } if (!SetVFlipState(args.flip)) return FALSE; if (args.brightness >= 0) { if (!SetBrightness(args.brightness)) return FALSE; } if (args.whiteness >= 0) { if (!SetWhiteness(args.whiteness)) return FALSE; } if (args.contrast >= 0) { if (!SetContrast(args.contrast)) return FALSE; } if (args.colour >= 0) { if (!SetColour(args.colour)) return FALSE; } if (args.hue >= 0) { if (!SetColour(args.hue)) return FALSE; } if (startImmediate) return Start(); return TRUE;}BOOL PVideoDevice::Close(){ return TRUE; }BOOL PVideoDevice::Start(){ return TRUE;}BOOL PVideoDevice::Stop(){ return TRUE;}BOOL PVideoDevice::SetVideoFormat(VideoFormat videoFmt){ videoFormat = videoFmt; return TRUE;}PVideoDevice::VideoFormat PVideoDevice::GetVideoFormat() const{ return videoFormat;}int PVideoDevice::GetNumChannels(){ return 1;}BOOL PVideoDevice::SetChannel(int channelNum){ if (channelNum < 0) { // Seek out the first available channel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -