00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef _PVIDEOIO
00033 #define _PVIDEOIO
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #ifndef _PTLIB_H
00040 #include <ptlib.h>
00041 #endif
00042
00043 #if P_VIDEO
00044
00045 #include <ptlib/plugin.h>
00046 #include <ptlib/pluginmgr.h>
00047 #include <list>
00048
00049 class PColourConverter;
00050
00051
00052 class PVideoFrameInfo : public PObject
00053 {
00054 PCLASSINFO(PVideoFrameInfo, PObject);
00055
00056 public:
00057 PVideoFrameInfo();
00058
00059 enum ResizeMode
00060 {
00061 eScale,
00062 eCropCentre,
00063 eCropTopLeft,
00064 eMaxResizeMode
00065 };
00066
00067 enum StandardSizes {
00068 SQCIFWidth = 128, SQCIFHeight = 96,
00069 QCIFWidth = 176, QCIFHeight = 144,
00070 CIFWidth = 352, CIFHeight = 288,
00071 CIF4Width = 704, CIF4Height = 576,
00072 CIF16Width = 1408, CIF16Height = 1152,
00073 i480Width = 640, i480Height = 480,
00074 p720Width = 960, p720Height = 720,
00075 i1080Width = 1920, i1080Height = 1080,
00076 HDTVWidth = 1920, HDTVHeight = 1080,
00077 MaxWidth = 1920, MaxHeight = 1152
00078 };
00079
00085 virtual PBoolean SetFrameSize(
00086 unsigned width,
00087 unsigned height
00088 );
00089
00095 virtual PBoolean GetFrameSize(
00096 unsigned & width,
00097 unsigned & height
00098 ) const;
00099
00104 virtual unsigned GetFrameWidth() const;
00105
00110 virtual unsigned GetFrameHeight() const;
00111
00117 virtual PBoolean SetFrameRate(
00118 unsigned rate
00119 );
00120
00125 virtual unsigned GetFrameRate() const;
00126
00132 virtual PBoolean SetColourFormat(
00133 const PString & colourFormat
00134 );
00135
00140 virtual const PString & GetColourFormat() const;
00141
00144 void SetResizeMode(
00145 ResizeMode mode
00146 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
00147
00150 ResizeMode GetResizeMode() const { return resizeMode; }
00151
00154 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); }
00155 static PINDEX CalculateFrameBytes(
00156 unsigned width,
00157 unsigned height,
00158 const PString & colourFormat
00159 );
00160
00163 static PBoolean ParseSize(
00164 const PString & str,
00165 unsigned & width,
00166 unsigned & height
00167 );
00168
00169 protected:
00170 unsigned frameWidth;
00171 unsigned frameHeight;
00172 unsigned frameRate;
00173 PString colourFormat;
00174 ResizeMode resizeMode;
00175 };
00176
00177
00178 class PVideoControlInfo : public PObject
00179 {
00180 PCLASSINFO(PVideoControlInfo, PObject);
00181
00182 public:
00183
00184 typedef enum {
00185 ControlPan,
00186 ControlTilt,
00187 ControlZoom
00188 } InputControlType;
00189
00190 static PString AsString(const InputControlType & type);
00191
00192 InputControlType type;
00193 long min;
00194 long max;
00195 long step;
00196 long def;
00197 long flags;
00198 long current;
00199 };
00200
00201
00205 class PVideoInputControl : public PVideoControlInfo
00206 {
00207 PCLASSINFO(PVideoInputControl, PVideoControlInfo);
00208
00209 public:
00210 ~PVideoInputControl();
00211
00212 virtual PBoolean Pan(long value, bool absolute = false );
00213 virtual PBoolean Tilt(long value, bool absolute = false);
00214 virtual PBoolean Zoom(long value, bool absolute = false);
00215
00216 long GetPan();
00217 long GetTilt();
00218 long GetZoom();
00219
00220 void Reset();
00221 void SetCurrentPosition(const InputControlType ctype, long current);
00222
00223 typedef std::list<PVideoControlInfo> InputDeviceControls;
00224
00225 protected:
00226 PBoolean GetVideoControlInfo(const InputControlType ctype, PVideoControlInfo & control);
00227 PBoolean GetDefaultPosition(const InputControlType ctype, long & def);
00228 PBoolean GetCurrentPosition(const InputControlType ctype, long & current);
00229
00230 std::list<PVideoControlInfo> m_info;
00231 PMutex ccmutex;
00232
00233 };
00234
00235
00264 class PVideoDevice : public PVideoFrameInfo
00265 {
00266 PCLASSINFO(PVideoDevice, PVideoFrameInfo);
00267
00268 protected:
00271 PVideoDevice();
00272
00273
00274 public:
00277 virtual ~PVideoDevice();
00278
00279 enum VideoFormat {
00280 PAL,
00281 NTSC,
00282 SECAM,
00283 Auto,
00284 NumVideoFormats
00285 };
00286
00289 const PString & GetDeviceName() const
00290 { return deviceName; }
00291
00294 virtual PStringArray GetDeviceNames() const = 0;
00295
00296 struct OpenArgs {
00297 OpenArgs();
00298
00299 PPluginManager * pluginMgr;
00300 PString driverName;
00301 PString deviceName;
00302 VideoFormat videoFormat;
00303 int channelNumber;
00304 PString colourFormat;
00305 bool convertFormat;
00306 unsigned rate;
00307 unsigned width;
00308 unsigned height;
00309 bool convertSize;
00310 ResizeMode resizeMode;
00311 bool flip;
00312 int brightness;
00313 int whiteness;
00314 int contrast;
00315 int colour;
00316 int hue;
00317 };
00318
00321 virtual PBoolean OpenFull(
00322 const OpenArgs & args,
00323 PBoolean startImmediate = PTrue
00324 );
00325
00328 virtual PBoolean Open(
00329 const PString & deviceName,
00330 PBoolean startImmediate = PTrue
00331 ) = 0;
00332
00335 virtual PBoolean IsOpen() = 0;
00336
00339 virtual PBoolean Close() = 0;
00340
00343 virtual PBoolean Start() = 0;
00344
00347 virtual PBoolean Stop() = 0;
00348
00349
00350 #if PTRACING
00351 friend ostream & operator<<(ostream &, VideoFormat);
00352 #endif
00353
00359 virtual PBoolean SetVideoFormat(
00360 VideoFormat videoFormat
00361 );
00362
00367 virtual VideoFormat GetVideoFormat() const;
00368
00373 virtual int GetNumChannels();
00374
00382 virtual PBoolean SetChannel(
00383 int channelNumber
00384 );
00385
00390 virtual int GetChannel() const;
00391
00398 virtual PBoolean SetColourFormatConverter(
00399 const PString & colourFormat
00400 );
00401
00405 virtual PBoolean GetVFlipState();
00406
00410 virtual PBoolean SetVFlipState(
00411 PBoolean newVFlipState
00412 );
00413
00419 virtual PBoolean GetFrameSizeLimits(
00420 unsigned & minWidth,
00421 unsigned & minHeight,
00422 unsigned & maxWidth,
00423 unsigned & maxHeight
00424 ) ;
00425
00426
00432 virtual PBoolean SetFrameSizeConverter(
00433 unsigned width,
00434 unsigned height,
00435 ResizeMode resizeMode = eMaxResizeMode
00436 );
00437
00443 virtual PBoolean SetFrameSizeConverter(
00444 unsigned width,
00445 unsigned height,
00446 PBoolean
00447 ) { return SetFrameSizeConverter(width,height,eScale); }
00448
00449
00458 virtual PBoolean SetFrameSize(
00459 unsigned width,
00460 unsigned height
00461 );
00462
00468 virtual PBoolean GetFrameSize(
00469 unsigned & width,
00470 unsigned & height
00471 ) const;
00472
00478 virtual PINDEX GetMaxFrameBytes() = 0;
00479
00480
00483 int GetLastError() const { return lastError; }
00484
00485
00488 virtual PBoolean CanCaptureVideo() const = 0;
00489
00492 virtual int GetBrightness();
00493
00496 virtual PBoolean SetBrightness(unsigned newBrightness);
00497
00498
00501 virtual int GetWhiteness();
00502
00505 virtual PBoolean SetWhiteness(unsigned newWhiteness);
00506
00507
00510 virtual int GetColour();
00511
00514 virtual PBoolean SetColour(unsigned newColour);
00515
00516
00519 virtual int GetContrast();
00520
00523 virtual PBoolean SetContrast(unsigned newContrast);
00524
00525
00528 virtual int GetHue();
00529
00532 virtual PBoolean SetHue(unsigned newHue);
00533
00534
00537 virtual PBoolean GetParameters(
00538 int *whiteness,
00539 int *brightness,
00540 int *colour,
00541 int *contrast,
00542 int *hue
00543 );
00544
00545
00548 virtual PBoolean SetVideoChannelFormat (
00549 int channelNumber,
00550 VideoFormat videoFormat
00551 );
00552
00553
00557 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00558
00562 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00563
00564 protected:
00565 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00566
00567 PString deviceName;
00568 int lastError;
00569 VideoFormat videoFormat;
00570 int channelNumber;
00571
00572 PString preferredColourFormat;
00573 PBoolean nativeVerticalFlip;
00574
00575 PColourConverter * converter;
00576 PBYTEArray frameStore;
00577
00578 int frameBrightness;
00579 int frameWhiteness;
00580 int frameContrast;
00581 int frameColour;
00582 int frameHue;
00583 };
00584
00585
00588 class PVideoOutputDevice : public PVideoDevice
00589 {
00590 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00591
00592 public:
00595 PVideoOutputDevice();
00596
00599 virtual ~PVideoOutputDevice() { Close(); };
00600
00603 static PStringArray GetDriverNames(
00604 PPluginManager * pluginMgr = NULL
00605 );
00606
00613 static PStringArray GetDriversDeviceNames(
00614 const PString & driverName,
00615 PPluginManager * pluginMgr = NULL
00616 );
00617
00620 static PVideoOutputDevice * CreateDevice(
00621 const PString & driverName,
00622 PPluginManager * pluginMgr = NULL
00623 );
00624
00625
00626
00627
00628
00629 static PVideoOutputDevice *CreateDeviceByName(
00630 const PString & deviceName,
00631 const PString & driverName = PString::Empty(),
00632 PPluginManager * pluginMgr = NULL
00633 );
00634
00640 static PVideoOutputDevice *CreateOpenedDevice(
00641 const PString & driverName,
00642 const PString & deviceName,
00643 PBoolean startImmediate = PTrue,
00644 PPluginManager * pluginMgr = NULL
00645 );
00646
00649 static PVideoOutputDevice *CreateOpenedDevice(
00650 const OpenArgs & args,
00651 PBoolean startImmediate = PTrue
00652 );
00653
00656 virtual PBoolean Close() { return PTrue; }
00657
00660 virtual PBoolean Start() { return PTrue; }
00661
00664 virtual PBoolean Stop() { return PTrue; }
00665
00668 virtual PBoolean CanCaptureVideo() const;
00669
00672 virtual PBoolean SetFrameData(
00673 unsigned x,
00674 unsigned y,
00675 unsigned width,
00676 unsigned height,
00677 const BYTE * data,
00678 PBoolean endFrame = PTrue
00679 ) = 0;
00680 virtual PBoolean SetFrameData(
00681 unsigned x,
00682 unsigned y,
00683 unsigned width,
00684 unsigned height,
00685 const BYTE * data,
00686 PBoolean endFrame,
00687 unsigned flags
00688 );
00689
00696 virtual PBoolean GetPosition(
00697 int & x,
00698 int & y
00699 ) const;
00700 };
00701
00702
00705 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00706 {
00707 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00708
00709 public:
00712 PVideoOutputDeviceRGB();
00713
00724 virtual PBoolean SetColourFormat(
00725 const PString & colourFormat
00726 );
00727
00736 virtual PBoolean SetFrameSize(
00737 unsigned width,
00738 unsigned height
00739 );
00740
00746 virtual PINDEX GetMaxFrameBytes();
00747
00750 virtual PBoolean SetFrameData(
00751 unsigned x,
00752 unsigned y,
00753 unsigned width,
00754 unsigned height,
00755 const BYTE * data,
00756 PBoolean endFrame = PTrue
00757 );
00758
00761 virtual PBoolean FrameComplete() = 0;
00762
00763 protected:
00764 PMutex mutex;
00765 PINDEX bytesPerPixel;
00766 PINDEX scanLineWidth;
00767 bool swappedRedAndBlue;
00768 };
00769
00770
00771 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00772
00775 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00776 {
00777 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00778
00779 public:
00782 PVideoOutputDevicePPM();
00783
00786 virtual PBoolean Open(
00787 const PString & deviceName,
00788 PBoolean startImmediate = PTrue
00789 );
00790
00793 virtual PBoolean IsOpen();
00794
00797 virtual PBoolean Close();
00798
00801 virtual PStringArray GetDeviceNames() const;
00802
00805 virtual PBoolean EndFrame();
00806
00807 protected:
00808 unsigned frameNumber;
00809 };
00810
00811 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00812
00813
00816 class PVideoInputDevice : public PVideoDevice
00817 {
00818 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00819
00820 public:
00823
00824
00827 ~PVideoInputDevice() { Close(); }
00828
00831 static PStringArray GetDriverNames(
00832 PPluginManager * pluginMgr = NULL
00833 );
00834
00841 static PStringArray GetDriversDeviceNames(
00842 const PString & driverName,
00843 PPluginManager * pluginMgr = NULL
00844 );
00845
00848 static PVideoInputDevice *CreateDevice(
00849 const PString & driverName,
00850 PPluginManager * pluginMgr = NULL
00851 );
00852
00853
00854
00855
00856
00857
00858
00859
00860 static PVideoInputDevice *CreateDeviceByName(
00861 const PString & deviceName,
00862 const PString & driverName = PString::Empty(),
00863 PPluginManager * pluginMgr = NULL
00864 );
00865
00871 static PVideoInputDevice *CreateOpenedDevice(
00872 const PString & driverName,
00873 const PString & deviceName,
00874 PBoolean startImmediate = PTrue,
00875 PPluginManager * pluginMgr = NULL
00876 );
00877
00880 static PVideoInputDevice *CreateOpenedDevice(
00881 const OpenArgs & args,
00882 PBoolean startImmediate = PTrue
00883 );
00884
00885 typedef struct {
00886 std::list<PVideoFrameInfo> framesizes;
00887 std::list<PVideoControlInfo> controls;
00888 } Capabilities;
00889
00892 static PBoolean GetDeviceCapabilities(
00893 const PString & deviceName,
00894 Capabilities * capabilities,
00895 PPluginManager * pluginMgr = NULL
00896 );
00897
00900 static PBoolean GetDeviceCapabilities(
00901 const PString & deviceName,
00902 const PString & driverName,
00903 Capabilities * caps,
00904 PPluginManager * pluginMgr = NULL
00905 );
00906
00909 virtual PBoolean Open(
00910 const PString & deviceName,
00911 PBoolean startImmediate = PTrue
00912 ) = 0;
00913
00914 virtual PBoolean Close(
00915 ) { return PTrue; }
00916
00919 virtual PBoolean CanCaptureVideo() const;
00920
00923 virtual PBoolean IsCapturing() = 0;
00924
00927 virtual PBoolean GetFrame(
00928 PBYTEArray & frame
00929 );
00930
00933 virtual PBoolean GetFrameData(
00934 BYTE * buffer,
00935 PINDEX * bytesReturned,
00936 unsigned int & flags
00937 );
00938 virtual PBoolean GetFrameData(
00939 BYTE * buffer,
00940 PINDEX * bytesReturned = NULL
00941 ) = 0;
00942
00945 virtual PBoolean GetFrameDataNoDelay(
00946 BYTE * buffer,
00947 PINDEX * bytesReturned,
00948 unsigned int & flags
00949 );
00950 virtual PBoolean GetFrameDataNoDelay(
00951 BYTE * buffer,
00952 PINDEX * bytesReturned = NULL
00953 ) = 0;
00954
00957 virtual PBoolean TestAllFormats() = 0;
00958 };
00959
00960
00962
00963
00964
00965
00966 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00967 {
00968 public:
00969 virtual PObject * CreateInstance(int ) const { return new className; }
00970 virtual PStringArray GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
00971 virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const
00972 { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); }
00973 };
00974
00975 #define PCREATE_VIDINPUT_PLUGIN(name) \
00976 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
00977 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
00978
00980
00981
00982
00983
00984 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00985 {
00986 public:
00987 virtual PObject * CreateInstance(int ) const { return new className; }
00988 virtual PStringArray GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
00989 };
00990
00991 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
00992 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
00993 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
00994
00996
00997
00998
00999
01000 class PVideoFont : public PObject
01001 {
01002 PCLASSINFO(PVideoFont, PObject);
01003 public:
01004 enum {
01005 MAX_L_HEIGHT = 11
01006 };
01007 struct LetterData {
01008 char ascii;
01009 const char *line[MAX_L_HEIGHT];
01010 };
01011
01012 static const LetterData * GetLetterData(char ascii);
01013 };
01014
01015 #endif // P_VIDEO
01016
01017 #endif // _PVIDEOIO
01018
01019