1 /* 2 * vidinput_v4l2.h 3 * 4 * Portable Windows Library 5 * 6 * Copyright (c) 1993-2000 Equivalence Pty. Ltd. 7 * 8 * The contents of this file are subject to the Mozilla Public License 9 * Version 1.0 (the "License"); you may not use this file except in 10 * compliance with the License. You may obtain a copy of the License at 11 * http://www.mozilla.org/MPL/ 12 * 13 * Software distributed under the License is distributed on an "AS IS" 14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15 * the License for the specific language governing rights and limitations 16 * under the License. 17 * 18 * The Original Code is Portable Windows Library (V4L plugin). 19 * 20 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 21 * 22 * Contributor(s): Derek Smithies (derek@indranet.co.nz) 23 * Mark Cooke (mpc@star.sr.bham.ac.uk) 24 * Nicola Orru' <nigu@itadinanta.it> 25 * 26 * $Revision: 27739 $ 27 * $Author: rjongbloed $ 28 * $Date: 2012-05-30 18:49:09 -0500 (Wed, 30 May 2012) $ 29 */ 30 #ifndef _PVIDEOIOV4L2 31 #define _PVIDEOIOV4L2 32 33 34 #include <sys/mman.h> 35 #include <sys/time.h> 36 37 #include <ptlib.h> 38 #include <ptlib/videoio.h> 39 #include <ptlib/vconvert.h> 40 #include <ptclib/delaychan.h> 41 42 #include V4L2_HEADER 43 44 #ifndef V4L2_PIX_FMT_SBGGR8 45 #define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */ 46 #endif 47 48 class PVideoInputDevice_V4L2: public PVideoInputDevice 49 { 50 51 PCLASSINFO(PVideoInputDevice_V4L2, PVideoInputDevice); 52 private: PVideoInputDevice_V4L2(const PVideoInputDevice_V4L2 &)53 PVideoInputDevice_V4L2(const PVideoInputDevice_V4L2& ){}; 54 PVideoInputDevice_V4L2& operator=(const PVideoInputDevice_V4L2& ){ return *this; }; 55 public: 56 PVideoInputDevice_V4L2(); 57 virtual ~PVideoInputDevice_V4L2(); 58 59 void ReadDeviceDirectory (PDirectory, POrdinalToString &); 60 61 static PStringList GetInputDeviceNames(); 62 GetDeviceNames()63 PStringArray GetDeviceNames() const 64 { return GetInputDeviceNames(); } 65 66 PBoolean Open(const PString &deviceName, PBoolean startImmediate); 67 68 PBoolean IsOpen(); 69 70 PBoolean Close(); 71 72 PBoolean Start(); 73 PBoolean Stop(); 74 75 PBoolean IsCapturing(); 76 77 PINDEX GetMaxFrameBytes(); 78 79 PBoolean GetFrameData(BYTE*, PINDEX*); 80 PBoolean GetFrameDataNoDelay(BYTE*, PINDEX*); 81 82 PBoolean GetFrameSizeLimits(unsigned int&, unsigned int&, 83 unsigned int&, unsigned int&); 84 85 PBoolean TestAllFormats(); 86 87 PBoolean SetFrameSize(unsigned int, unsigned int); 88 PBoolean SetNearestFrameSize(unsigned int, unsigned int); 89 PBoolean SetFrameRate(unsigned int); 90 91 PBoolean GetParameters(int*, int*, int*, int*, int*); 92 93 PBoolean SetColourFormat(const PString&); 94 95 int GetControlCommon(unsigned int control, int *value); 96 PBoolean SetControlCommon(unsigned int control, int newValue); 97 98 int GetContrast(); 99 PBoolean SetContrast(unsigned int); 100 int GetBrightness(); 101 PBoolean SetBrightness(unsigned int); 102 int GetWhiteness(); 103 PBoolean SetWhiteness(unsigned int); 104 int GetColour(); 105 PBoolean SetColour(unsigned int); 106 int GetHue(); 107 PBoolean SetHue(unsigned int); 108 109 PBoolean SetVideoChannelFormat(int, PVideoDevice::VideoFormat); 110 PBoolean SetVideoFormat(PVideoDevice::VideoFormat); 111 int GetNumChannels(); 112 PBoolean SetChannel(int); 113 114 PBoolean NormalReadProcess(BYTE*, PINDEX*); 115 116 private: 117 void ClearMapping(); 118 119 PBoolean SetMapping(); 120 121 PBoolean VerifyHardwareFrameSize(unsigned int & width, unsigned int & height); 122 123 PBoolean QueueBuffers(); 124 125 PBoolean StartStreaming(); 126 void StopStreaming(); 127 128 struct v4l2_capability videoCapability; 129 struct v4l2_streamparm videoStreamParm; 130 PBoolean canRead; 131 PBoolean canStream; 132 PBoolean canSelect; 133 PBoolean canSetFrameRate; 134 PBoolean isMapped; 135 #define NUM_VIDBUF 4 136 BYTE * videoBuffer[NUM_VIDBUF]; 137 uint videoBufferCount; 138 uint currentvideoBuffer; 139 140 PMutex mmapMutex; /** Has MMAP frame buffers in use? */ 141 PBoolean isOpen; /** Has the Video Input Device successfully been openend? */ 142 PBoolean areBuffersQueued; 143 PBoolean isStreaming; 144 145 int videoFd; 146 int frameBytes; 147 PBoolean started; 148 PAdaptiveDelay m_pacing; 149 }; 150 151 #endif 152