1 /* 2 * video.h 3 * 4 * Video interface class. 5 * 6 * Portable Windows Library 7 * 8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 9 * 10 * The contents of this file are subject to the Mozilla Public License 11 * Version 1.0 (the "License"); you may not use this file except in 12 * compliance with the License. You may obtain a copy of the License at 13 * http://www.mozilla.org/MPL/ 14 * 15 * Software distributed under the License is distributed on an "AS IS" 16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 17 * the License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * The Original Code is Portable Windows Library. 21 * 22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 23 * 24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 25 * All Rights Reserved. 26 * 27 * Contributor(s): Derek Smithies (derek@indranet.co.nz) 28 * 29 * $Revision: 24459 $ 30 * $Author: shorne $ 31 * $Date: 2010-06-06 08:59:59 -0500 (Sun, 06 Jun 2010) $ 32 */ 33 34 #ifndef PTLIB_VIDEO_H 35 #define PTLIB_VIDEO_H 36 37 #ifdef P_USE_PRAGMA 38 #pragma interface 39 #endif 40 41 #include <ptbuildopts.h> 42 43 #if P_VIDEO 44 45 #include <ptlib/videoio.h> 46 47 /**A class representing a video channel. This class is provided mainly for 48 the playback or recording of video on the system. 49 50 Note that this video channel is implicitly a series of frames in YUV411P format. 51 No conversion is performed on data to/from the channel. 52 */ 53 class PVideoChannel : public PChannel 54 { 55 PCLASSINFO(PVideoChannel, PChannel); 56 57 public: 58 /**@name Construction */ 59 //@{ 60 enum Directions { 61 Recorder, 62 Player 63 }; 64 65 /// Create a video channel. 66 PVideoChannel(); 67 68 /** Create a video channel. 69 Create a reference to the video drivers for the platform. 70 */ 71 PVideoChannel( 72 const PString & device, ///< Name of video driver/device 73 Directions dir ///< Video I/O direction 74 ); 75 // 76 77 ~PVideoChannel(); 78 // Destroy and close the video driver 79 //@} 80 81 /**@name Open functions */ 82 //@{ 83 /**Open the specified device for playing or recording. The device name is 84 platform specific and is as returned in the GetDevices() function. 85 86 @return 87 true if the video device is valid for playing/recording. 88 */ 89 PBoolean Open( 90 const PString & device, ///< Name of video driver/device 91 Directions dir ///< Video I/O direction 92 ); 93 94 /** return True if one (or both) of the video device class pointers 95 is non NULL. If either pointer is non NULL, then a device is ready 96 to be written to, which indicates this channel is open. 97 */ 98 PBoolean IsOpen() const; 99 100 /**Get all of the names for video devices/drivers that are available on 101 this platform. Note that a named device may not necessarily do both 102 playing and recording so the arrays returned with the <code>dir</code> 103 parameter in each value is not necessarily the same. 104 105 @return 106 An array of platform dependent strings for each video player/recorder. 107 */ 108 static PStringArray GetDeviceNames( 109 Directions dir ///< Video I/O direction 110 ) ; 111 112 /**Get the name for the default video devices/driver that is on this 113 platform. Note that a named device may not necessarily do both 114 playing and recording so the arrays returned with the <code>dir</code> 115 parameter in each value is not necessarily the same. 116 117 @return 118 A platform dependent string for the video player/recorder. 119 */ 120 static PString GetDefaultDevice( 121 Directions dir // Video I/O direction 122 ); 123 //@} 124 125 126 /**Return the width of the currently selected grabbing device. 127 */ 128 virtual PINDEX GetGrabWidth(); 129 130 /**Return the height of the currently selected grabbing device. 131 */ 132 virtual PINDEX GetGrabHeight(); 133 134 virtual PBoolean Read(void * buf, PINDEX len); 135 // Low level read from the video channel. This function will block until the 136 // requested number of characters were read. 137 138 139 /**Low level write to the channel, which is data to be rendered to the 140 local video display device. 141 */ 142 PBoolean Write(const void * buf, //Pointer to the image data to be rendered 143 PINDEX len); 144 145 /** Low level write to the video channel with marker. . 146 */ 147 virtual PBoolean Write( 148 const void * buf, ///< Pointer to a block of memory to write. 149 PINDEX len, ///< Number of bytes to write. 150 void * mark ///< Unique Marker to identify write 151 ); 152 153 /**Cause the referenced data to be drawn to the 154 previously defined media 155 */ 156 virtual PBoolean Redraw(const void * frame); 157 158 /**Return the previously specified width. 159 */ 160 PINDEX GetRenderWidth(); 161 162 /**Return the previously specified height. 163 */ 164 PINDEX GetRenderHeight(); 165 166 /**Specify the width and height of the video stream, which is to be 167 rendered onto the previously specified device. 168 */ 169 virtual void SetRenderFrameSize(int width, int height); 170 171 /**Specify the width and height of the video stream, which is to be 172 rendered onto the previously specified device including sample aspect ratio. 173 */ 174 virtual void SetRenderFrameSize(int width, int height,int sarwidth, int sarheight); 175 176 /**Specifiy the width and height of the video stream, which is to be 177 extracted from the previously specified device. 178 */ 179 virtual void SetGrabberFrameSize(int width, int height); 180 181 /**Attach a user specific class for rendering video 182 183 If keepCurrent is true, an abort is caused when the program attempts to attach 184 a new player when there is already a video player attached. 185 186 If keepCurrent is false, the existing video player is deleted before attaching 187 the new player. 188 */ 189 virtual void AttachVideoPlayer(PVideoOutputDevice * device, PBoolean keepCurrent = true); 190 191 /**Attach a user specific class for acquiring video 192 193 If keepCurrent is true, an abort is caused when the program attempts to attach 194 a new reader when there is already a video reader attached. 195 196 If keepCurrent is false, the existing video reader is deleted before attaching 197 the new reader. 198 */ 199 virtual void AttachVideoReader(PVideoInputDevice * device, PBoolean keepCurrent = true); 200 201 /**Return a pointer to the class for acquiring video 202 */ 203 virtual PVideoInputDevice *GetVideoReader(); 204 205 /**Return a pointer to the class for displaying video 206 */ 207 virtual PVideoOutputDevice *GetVideoPlayer(); 208 209 /**See if the grabber is open 210 */ 211 virtual PBoolean IsGrabberOpen(); 212 213 /**See if the rendering device is open 214 */ 215 virtual PBoolean IsRenderOpen(); 216 217 /**Allow the outputdevice decide whether the 218 decoder should ignore decode hence not render 219 any output. This does not mean the video channel is closed 220 just to not decode and render any frames. 221 */ 222 virtual PBoolean DisableDecode(); 223 224 /**Get data from the attached inputDevice, and display on the 225 attached ouptutDevice. 226 */ 227 PBoolean DisplayRawData(void *videoBuffer); 228 229 /**Destroy the attached grabber class. 230 */ 231 virtual void CloseVideoReader(); 232 233 /**Destroy the attached video display class. 234 */ 235 virtual void CloseVideoPlayer(); 236 237 /**Restrict others from using this video channel. 238 */ 239 void RestrictAccess(); 240 241 /**Allow free access to this video channel. 242 */ 243 void EnableAccess(); 244 245 /**Toggle the vertical flip state of the video grabber. 246 */ 247 PBoolean ToggleVFlipInput(); 248 249 /**Flow Control information 250 Pass data to the channel for flowControl determination. 251 */ 252 virtual bool FlowControl(const void * flowData); 253 254 protected: 255 256 Directions direction; 257 258 PString deviceName; ///Specified video device name, eg /dev/video0. 259 PVideoInputDevice *mpInput; /// For grabbing video from the camera. 260 PVideoOutputDevice *mpOutput; /// For displaying video on the screen. 261 262 PMutex accessMutex; // Ensure that only task is accesing 263 // members in this video channel. 264 private: 265 void Construct(); 266 267 268 // Include platform dependent part of class 269 #ifdef _WIN32 270 #include "msos/ptlib/video.h" 271 #else 272 #include "unix/ptlib/video.h" 273 #endif 274 }; 275 276 #endif // P_VIDEO 277 278 #endif // PTLIB_VIDEO_H 279 280 281 // End Of File /////////////////////////////////////////////////////////////// 282