PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
videoio.h
Go to the documentation of this file.
1 /*
2  * videoio.h
3  *
4  * Classes to support streaming video input (grabbing) and output.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2000 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  * Contributor(s): Mark Cooke (mpc@star.sr.bham.ac.uk)
25  *
26  * $Revision: 25752 $
27  * $Author: rjongbloed $
28  * $Date: 2011-05-11 21:50:32 -0500 (Wed, 11 May 2011) $
29  */
30 
31 
32 #ifndef PTLIB_PVIDEOIO_H
33 #define PTLIB_PVIDEOIO_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 #include <ptbuildopts.h>
39 
40 #if P_VIDEO
41 
42 #include <ptlib/plugin.h>
43 #include <ptlib/pluginmgr.h>
44 #include <list>
45 
46 class PColourConverter;
47 
48 
49 class PVideoFrameInfo : public PObject
50 {
51  PCLASSINFO(PVideoFrameInfo, PObject);
52 
53  public:
55  {
60  };
61  friend ostream & operator<<(ostream & strm, ResizeMode mode);
62 
64  SQCIFWidth = 128, SQCIFHeight = 96,
65  QCIFWidth = 176, QCIFHeight = 144,
66  CIFWidth = 352, CIFHeight = 288,
67  CIF4Width = 704, CIF4Height = 576,
68  CIF16Width = 1408, CIF16Height = 1152,
69  HD480Width = 704, HD480Height = 480,
70  i480Width = 704, i480Height = 480,
71  HD720Width = 1280, HD720Height = 720,
72  p720Width = 1280, p720Height = 720,
73  HD1080Width= 1920, HD1080Height= 1080,
74  i1080Width = 1920, i1080Height = 1080,
75  HDTVWidth = 1920, HDTVHeight = 1080,
76  MaxWidth = 1920, MaxHeight = 1200
77  };
78 
82  unsigned frameWidth,
83  unsigned frameHeight,
84  const PString & colourFormat = "YUV420P",
85  unsigned frameRate = 15,
87  );
88 
95  virtual void PrintOn(
96  ostream & strm // Stream to print the object into.
97  ) const;
98 
104  virtual PBoolean SetFrameSize(
105  unsigned width,
106  unsigned height
107  );
108 
114  virtual PBoolean GetFrameSize(
115  unsigned & width,
116  unsigned & height
117  ) const;
118 
123  virtual unsigned GetFrameWidth() const;
124 
129  virtual unsigned GetFrameHeight() const;
130 
136  virtual PBoolean SetFrameSar(unsigned width, unsigned height);
137 
143  virtual PBoolean GetSarSize(
144  unsigned & width,
145  unsigned & height
146  ) const;
147 
152  virtual unsigned GetSarWidth() const;
153 
158  virtual unsigned GetSarHeight() const;
159 
165  virtual PBoolean SetFrameRate(
166  unsigned rate
167  );
168 
173  virtual unsigned GetFrameRate() const;
174 
180  virtual PBoolean SetColourFormat(
181  const PString & colourFormat // New colour format for device.
182  );
183 
188  virtual const PString & GetColourFormat() const;
189 
193  ResizeMode mode
194  ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
195 
198  ResizeMode GetResizeMode() const { return resizeMode; }
199 
203  static PINDEX CalculateFrameBytes(
204  unsigned width,
205  unsigned height,
206  const PString & colourFormat
207  );
208 
222  bool Parse(
223  const PString & str
224  );
225 
230  static bool ParseSize(
231  const PString & str,
232  unsigned & width,
233  unsigned & height
234  );
235 
238  static PString AsString(
239  unsigned width,
240  unsigned height
241  );
242 
247  static PStringArray GetSizeNames();
248 
249  protected:
250  unsigned frameWidth;
251  unsigned frameHeight;
252  unsigned sarWidth;
253  unsigned sarHeight;
254  unsigned frameRate;
257 };
258 
259 
261 {
262  PCLASSINFO(PVideoControlInfo, PObject);
263 
264  public:
265 
266  typedef enum {
271 
272  static PString AsString(const InputControlType & type);
273 
275  long min;
276  long max;
277  long step;
278  long def;
279  long flags;
280  long current;
281 };
282 
283 
288 {
290 
291 public:
293 
294  virtual PBoolean Pan(long value, bool absolute = false );
295  virtual PBoolean Tilt(long value, bool absolute = false);
296  virtual PBoolean Zoom(long value, bool absolute = false);
297 
298  long GetPan();
299  long GetTilt();
300  long GetZoom();
301 
302  void Reset();
303  void SetCurrentPosition(const InputControlType ctype, long current);
304 
305  typedef std::list<PVideoControlInfo> InputDeviceControls;
306 
307 protected:
309  PBoolean GetDefaultPosition(const InputControlType ctype, long & def);
310  PBoolean GetCurrentPosition(const InputControlType ctype, long & current);
311 
312  std::list<PVideoControlInfo> m_info;
314 
315 };
316 
320 {
321  PCLASSINFO(PVideoInteractionInfo, PObject);
322 
323  public:
324 
325  typedef enum {
332 
333  static PString AsString(const InputInteractType & type);
334 
336 };
337 
338 
368 {
369  PCLASSINFO(PVideoDevice, PVideoFrameInfo);
370 
371  protected:
374  PVideoDevice();
375 
376 
377  public:
380  virtual ~PVideoDevice();
381 
382  enum VideoFormat {
388  };
389 
392  const PString & GetDeviceName() const
393  { return deviceName; }
394 
397  virtual PStringArray GetDeviceNames() const = 0;
398 
399  struct OpenArgs {
400  OpenArgs();
401 
409  unsigned rate;
410  unsigned width;
411  unsigned height;
414  bool flip;
417  int contrast;
418  int colour;
419  int hue;
420  };
421 
424  virtual PBoolean OpenFull(
425  const OpenArgs & args,
426  PBoolean startImmediate = true
427  );
428 
431  virtual PBoolean Open(
432  const PString & deviceName,
433  PBoolean startImmediate = true
434  ) = 0;
435 
438  virtual PBoolean IsOpen() = 0;
439 
442  virtual PBoolean Close() = 0;
443 
446  virtual PBoolean Start() = 0;
447 
450  virtual PBoolean Stop() = 0;
451 
452 
453 #if PTRACING
454  friend ostream & operator<<(ostream &, VideoFormat);
455 #endif
456 
462  virtual PBoolean SetVideoFormat(
464  );
465 
470  virtual VideoFormat GetVideoFormat() const;
471 
476  virtual int GetNumChannels();
477 
485  virtual PBoolean SetChannel(
486  int channelNumber
487  );
488 
493  virtual int GetChannel() const;
494 
502  const PString & colourFormat // New colour format for device.
503  );
504 
508  virtual PBoolean GetVFlipState();
509 
513  virtual PBoolean SetVFlipState(
514  PBoolean newVFlipState
515  );
516 
523  unsigned & minWidth,
524  unsigned & minHeight,
525  unsigned & maxWidth,
526  unsigned & maxHeight
527  ) ;
528 
529 
536  unsigned width,
537  unsigned height,
539  );
540 
547  unsigned width,
548  unsigned height,
549  PBoolean /*bScaleNotCrop*/
550  ) { return SetFrameSizeConverter(width,height,eScale); }
551 
552 
561  unsigned width,
562  unsigned height
563  );
564 
573  virtual PBoolean SetFrameSize(
574  unsigned width,
575  unsigned height
576  );
577 
583  virtual PBoolean GetFrameSize(
584  unsigned & width,
585  unsigned & height
586  ) const;
587 
593  virtual PINDEX GetMaxFrameBytes() = 0;
594 
595 
598  int GetLastError() const { return lastError; }
599 
600 
603  virtual PBoolean CanCaptureVideo() const = 0;
604 
607  virtual int GetBrightness();
608 
611  virtual PBoolean SetBrightness(unsigned newBrightness);
612 
613 
616  virtual int GetWhiteness();
617 
620  virtual PBoolean SetWhiteness(unsigned newWhiteness);
621 
622 
625  virtual int GetColour();
626 
629  virtual PBoolean SetColour(unsigned newColour);
630 
631 
634  virtual int GetContrast();
635 
638  virtual PBoolean SetContrast(unsigned newContrast);
639 
640 
643  virtual int GetHue();
644 
647  virtual PBoolean SetHue(unsigned newHue);
648 
649 
652  virtual PBoolean GetParameters(
653  int *whiteness,
654  int *brightness,
655  int *colour,
656  int *contrast,
657  int *hue
658  );
659 
660 
664  int channelNumber,
666  );
667 
668 
672  void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
673 
678 
679  protected:
680  PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
681 
686  // Preferred native colour format from video input device, empty == no preference
689 
692 
693  int frameBrightness; // 16 bit entity, -1 is no value
697  int frameHue;
698 };
699 
700 
704 {
705  PCLASSINFO(PVideoOutputDevice, PVideoDevice);
706 
707  public:
711 
714  virtual ~PVideoOutputDevice() { Close(); };
715 
719  PPluginManager * pluginMgr = NULL
720  );
721 
729  const PString & driverName,
730  PPluginManager * pluginMgr = NULL
731  );
732 
736  const PString & driverName,
737  PPluginManager * pluginMgr = NULL
738  );
739 
740  /* Create the matching video output device that corresponds to the device name.
741 
742  This is typically used with the return values from GetDriversDeviceNames().
743  */
745  const PString & deviceName,
746  const PString & driverName = PString::Empty(),
747  PPluginManager * pluginMgr = NULL
748  );
749 
756  const PString & driverName,
757  const PString & deviceName,
758  PBoolean startImmediate = true,
759  PPluginManager * pluginMgr = NULL
760  );
761 
765  const OpenArgs & args,
766  PBoolean startImmediate = true
767  );
768 
771  virtual PBoolean Close() { return true; }
772 
775  virtual PBoolean Start() { return true; }
776 
779  virtual PBoolean Stop() { return true; }
780 
783  virtual PBoolean CanCaptureVideo() const;
784 
787  virtual PBoolean SetFrameData(
788  unsigned x,
789  unsigned y,
790  unsigned width,
791  unsigned height,
792  const BYTE * data,
793  PBoolean endFrame = true
794  ) = 0;
795  virtual PBoolean SetFrameData(
796  unsigned x,
797  unsigned y,
798  unsigned width,
799  unsigned height,
800  const BYTE * data,
801  PBoolean endFrame,
802  unsigned flags
803  );
804  virtual PBoolean SetFrameData(
805  unsigned x,
806  unsigned y,
807  unsigned width,
808  unsigned height,
809  unsigned sarwidth,
810  unsigned sarheight,
811  const BYTE * data,
812  PBoolean endFrame,
813  unsigned flags,
814  const void * mark
815  );
816 
823  virtual PBoolean DisableDecode();
824 
831  virtual PBoolean GetPosition(
832  int & x, // X position of device surface
833  int & y // Y position of device surface
834  ) const;
835 
842  virtual bool SetPosition(
843  int x, // X position of device surface
844  int y // Y position of device surface
845  );
846 };
847 
848 
852 {
854 
855  public:
859 
870  virtual PBoolean SetColourFormat(
871  const PString & colourFormat // New colour format for device.
872  );
873 
882  virtual PBoolean SetFrameSize(
883  unsigned width,
884  unsigned height
885  );
886 
892  virtual PINDEX GetMaxFrameBytes();
893 
896  virtual PBoolean SetFrameData(
897  unsigned x,
898  unsigned y,
899  unsigned width,
900  unsigned height,
901  const BYTE * data,
902  PBoolean endFrame = true
903  );
904 
907  virtual PBoolean FrameComplete() = 0;
908 
909  protected:
914 };
915 
916 
917 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
918 
921 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
922 {
923  PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
924 
925  public:
928  PVideoOutputDevicePPM();
929 
932  virtual PBoolean Open(
933  const PString & deviceName,
934  PBoolean startImmediate = true
935  );
936 
939  virtual PBoolean IsOpen();
940 
943  virtual PBoolean Close();
944 
947  virtual PStringArray GetDeviceNames() const;
948 
951  virtual PBoolean EndFrame();
952 
953  protected:
954  unsigned frameNumber;
955 };
956 
957 #endif // SHOULD_BE_MOVED_TO_PLUGIN
958 
959 
963 {
964  PCLASSINFO(PVideoInputDevice, PVideoDevice);
965 
966  public:
969  //PVideoInputDevice();
970 
974 
978  PPluginManager * pluginMgr = NULL
979  );
980 
988  const PString & driverName,
989  PPluginManager * pluginMgr = NULL
990  );
991 
995  const PString & driverName,
996  PPluginManager * pluginMgr = NULL
997  );
998 
999  /* Create the matching video input device that corresponds to the device name.
1000  So, for "fake" return a device that will generate fake video.
1001  For "Phillips 680 webcam" (eg) will return appropriate grabber.
1002  Note that Phillips will return the appropriate grabber also.
1003 
1004  This is typically used with the return values from GetDriversDeviceNames().
1005  */
1007  const PString & deviceName,
1008  const PString & driverName = PString::Empty(),
1009  PPluginManager * pluginMgr = NULL
1010  );
1011 
1018  const PString & driverName,
1019  const PString & deviceName,
1020  PBoolean startImmediate = true,
1021  PPluginManager * pluginMgr = NULL
1022  );
1023 
1027  const OpenArgs & args,
1028  PBoolean startImmediate = true
1029  );
1030 
1031  typedef struct {
1032  std::list<PVideoFrameInfo> framesizes;
1033  std::list<PVideoControlInfo> controls;
1034  std::list<PVideoInteractionInfo> interactions;
1035  } Capabilities;
1036 
1040  Capabilities * capabilities
1041  ) const { return GetDeviceCapabilities(GetDeviceName(), capabilities); }
1042 
1046  const PString & deviceName,
1047  Capabilities * capabilities,
1048  PPluginManager * pluginMgr = NULL
1049  );
1050 
1054  const PString & deviceName,
1055  const PString & driverName,
1056  Capabilities * caps,
1057  PPluginManager * pluginMgr = NULL
1058  );
1059 
1064 
1067  virtual PBoolean Open(
1068  const PString & deviceName,
1069  PBoolean startImmediate = true
1070  ) = 0;
1071 
1072  virtual PBoolean Close(
1073  ) { return true; }
1074 
1077  virtual PBoolean CanCaptureVideo() const;
1078 
1081  virtual PBoolean IsCapturing() = 0;
1082 
1090  virtual PBoolean SetNearestFrameSize(
1091  unsigned width,
1092  unsigned height
1093  );
1094 
1097  virtual PBoolean GetFrame(
1098  PBYTEArray & frame
1099  );
1100 
1103  virtual PBoolean GetFrameData(
1104  BYTE * buffer,
1105  PINDEX * bytesReturned,
1106  unsigned int & flags
1107  );
1108  virtual PBoolean GetFrameData(
1109  BYTE * buffer,
1110  PINDEX * bytesReturned = NULL
1111  ) = 0;
1112 
1115  virtual PBoolean GetFrameDataNoDelay(
1116  BYTE * buffer,
1117  PINDEX * bytesReturned,
1118  unsigned int & flags
1119  );
1120  virtual PBoolean GetFrameDataNoDelay(
1121  BYTE * buffer,
1122  PINDEX * bytesReturned = NULL
1123  ) = 0;
1124 
1127  virtual bool FlowControl(const void * flowData);
1128 
1141  virtual bool SetCaptureMode(unsigned mode);
1142 
1146  virtual int GetCaptureMode() const;
1147 };
1148 
1149 
1151 //
1152 // declare macros and structures needed for video input plugins
1153 //
1154 
1156 {
1157  public:
1158  virtual PObject * CreateInstance(int /*userData*/) const { return new className; }
1159  virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetInputDeviceNames(); }
1160  virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const
1161  { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); }
1162 };
1163 
1164 #define PCREATE_VIDINPUT_PLUGIN(name) \
1165  static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
1166  PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
1167 
1169 
1170 #ifdef P_APPSHARE
1171  PPLUGIN_STATIC_LOAD(Application, PVideoInputDevice);
1172 #endif
1173 
1174 #if P_FFVDEV
1176 #endif
1177 
1178 #if P_VIDFILE
1180 #endif
1181 
1182 #ifdef P_DIRECTSHOW
1184 #endif
1185 
1186 
1188 //
1189 // declare macros and structures needed for video output plugins
1190 //
1191 
1193 {
1194  public:
1195  virtual PObject * CreateInstance(int /*userData*/) const { return new className; }
1196  virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetOutputDeviceNames(); }
1197 };
1198 
1199 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
1200  static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
1201  PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
1202 
1203 #if _WIN32
1205 #endif
1206 
1207 #if P_SDL
1209 #endif
1210 
1211 
1213 //
1214 // declare classes needed for access to simple video font
1215 //
1216 
1217 class PVideoFont : public PObject
1218 {
1219  PCLASSINFO(PVideoFont, PObject);
1220  public:
1221  enum {
1223  };
1224  struct LetterData {
1225  char ascii;
1226  const char *line[MAX_L_HEIGHT];
1227  };
1228 
1229  static const LetterData * GetLetterData(char ascii);
1230 };
1231 
1232 #endif // P_VIDEO
1233 
1234 #endif // PTLIB_PVIDEOIO_H
1235 
1236 // End Of File ///////////////////////////////////////////////////////////////
1237