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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 #ifndef _PVIDEOIO
00175 #define _PVIDEOIO
00176
00177 #ifdef P_USE_PRAGMA
00178 #pragma interface
00179 #endif
00180
00181 #if defined(_WIN32)
00182 PWLIB_STATIC_LOAD_PLUGIN(PVideoInputDevice_VideoForWindows);
00183 PWLIB_STATIC_LOAD_PLUGIN(PVideoInputDevice_FakeVideo);
00184
00185 PWLIB_STATIC_LOAD_PLUGIN(PVideoOutputDevice_NULLOutput);
00186 #endif
00187
00188 class PColourConverter;
00189
00220 class PVideoDevice : public PObject
00221 {
00222 PCLASSINFO(PVideoDevice, PObject);
00223
00224 protected:
00227 PVideoDevice();
00228
00229
00230 public:
00233 virtual ~PVideoDevice();
00234
00235 enum VideoFormat {
00236 PAL,
00237 NTSC,
00238 SECAM,
00239 Auto,
00240 NumVideoFormats
00241 };
00242
00243 enum StandardSizes {
00244 CIF16Width = 1408,
00245 CIF16Height = 1152,
00246 CIF4Width = 704,
00247 CIF4Height = 576,
00248 CIFWidth = 352,
00249 CIFHeight = 288,
00250 QCIFWidth = 176,
00251 QCIFHeight = 144,
00252 SQCIFWidth = 144,
00253 SQCIFHeight = 96,
00254 };
00255
00256 struct OpenArgs {
00257 OpenArgs()
00258 : deviceName("#1"),
00259 videoFormat(Auto),
00260 channelNumber(0),
00261 colourFormat("YUV420P"),
00262 convertFormat(TRUE),
00263 rate(0),
00264 width(CIFWidth),
00265 height(CIFHeight),
00266 convertSize(TRUE),
00267 scaleSize(FALSE),
00268 flip(FALSE),
00269 brightness(-1),
00270 whiteness(-1),
00271 contrast(-1),
00272 colour(-1),
00273 hue(-1)
00274 { }
00275 PString deviceName;
00276 VideoFormat videoFormat;
00277 int channelNumber;
00278 PString colourFormat;
00279 BOOL convertFormat;
00280 unsigned rate;
00281 unsigned width;
00282 unsigned height;
00283 BOOL convertSize;
00284 BOOL scaleSize;
00285 BOOL flip;
00286 int brightness;
00287 int whiteness;
00288 int contrast;
00289 int colour;
00290 int hue;
00291 };
00292
00295 virtual BOOL OpenFull(
00296 const OpenArgs & args,
00297 BOOL startImmediate = TRUE
00298 );
00299
00302 virtual BOOL Open(
00303 const PString & deviceName,
00304 BOOL startImmediate = TRUE
00305 ) = 0;
00306
00309 virtual BOOL IsOpen() = 0;
00310
00313 virtual BOOL Close() = 0;
00314
00317 virtual BOOL Start() = 0;
00318
00321 virtual BOOL Stop() = 0;
00322
00323
00326 const PString & GetDeviceName() const
00327 { return deviceName; }
00328
00331 virtual PStringList GetDeviceNames() const = 0;
00332
00333 #if PTRACING
00334 friend ostream & operator<<(ostream &, VideoFormat);
00335 #endif
00336
00342 virtual BOOL SetVideoFormat(
00343 VideoFormat videoFormat
00344 );
00345
00350 virtual VideoFormat GetVideoFormat() const;
00351
00356 virtual int GetNumChannels();
00357
00365 virtual BOOL SetChannel(
00366 int channelNumber
00367 );
00368
00373 virtual int GetChannel() const;
00374
00381 virtual BOOL SetColourFormatConverter(
00382 const PString & colourFormat
00383 );
00384
00395 virtual BOOL SetColourFormat(
00396 const PString & colourFormat
00397 );
00398
00403 const PString & GetColourFormat() const;
00404
00410 virtual BOOL SetFrameRate(
00411 unsigned rate
00412 );
00413
00418 virtual unsigned GetFrameRate() const;
00419
00425 virtual BOOL GetFrameSizeLimits(
00426 unsigned & minWidth,
00427 unsigned & minHeight,
00428 unsigned & maxWidth,
00429 unsigned & maxHeight
00430 ) ;
00431
00432
00438 virtual BOOL SetFrameSizeConverter(
00439 unsigned width,
00440 unsigned height,
00441 BOOL bScaleNotCrop
00442 );
00443
00452 virtual BOOL SetFrameSize(
00453 unsigned width,
00454 unsigned height
00455 );
00456
00462 virtual BOOL GetFrameSize(
00463 unsigned & width,
00464 unsigned & height
00465 );
00466
00471 virtual unsigned GetFrameWidth() const;
00472
00477 virtual unsigned GetFrameHeight() const;
00478
00484 virtual PINDEX GetMaxFrameBytes() = 0;
00485
00488 static unsigned CalculateFrameBytes(
00489 unsigned width,
00490 unsigned height,
00491 const PString & colourFormat
00492 );
00493
00494
00497 int GetLastError() const { return lastError; }
00498
00499
00502 virtual BOOL CanCaptureVideo() const = 0;
00503
00506 virtual int GetBrightness();
00507
00510 virtual BOOL SetBrightness(unsigned newBrightness);
00511
00512
00515 virtual int GetWhiteness();
00516
00519 virtual BOOL SetWhiteness(unsigned newWhiteness);
00520
00521
00524 virtual int GetColour();
00525
00528 virtual BOOL SetColour(unsigned newColour);
00529
00530
00533 virtual int GetContrast();
00534
00537 virtual BOOL SetContrast(unsigned newContrast);
00538
00539
00542 virtual int GetHue();
00543
00546 virtual BOOL SetHue(unsigned newHue);
00547
00548
00551 virtual BOOL GetParameters(
00552 int *whiteness,
00553 int *brightness,
00554 int *colour,
00555 int *contrast,
00556 int *hue
00557 );
00558
00559
00562 virtual BOOL SetVideoChannelFormat (
00563 int channelNumber,
00564 VideoFormat videoFormat
00565 );
00566
00567
00571 virtual BOOL GetVFlipState();
00572
00576 virtual BOOL SetVFlipState(
00577 BOOL newVFlipState
00578 );
00579
00580
00584 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00585
00589 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00590
00591 protected:
00592 PString deviceName;
00593 int lastError;
00594 VideoFormat videoFormat;
00595 int channelNumber;
00596 PString colourFormat;
00597
00598 PString preferredColourFormat;
00599 unsigned frameRate;
00600 unsigned frameWidth;
00601 unsigned frameHeight;
00602 BOOL doVFlip;
00603
00604 PColourConverter * converter;
00605
00606 int frameBrightness;
00607 int frameWhiteness;
00608 int frameContrast;
00609 int frameColour;
00610 int frameHue;
00611
00612 PTime previousFrameTime;
00613 int msBetweenFrames;
00614 int frameTimeError;
00615 };
00616
00617
00620 class PVideoOutputDevice : public PVideoDevice
00621 {
00622 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00623
00624 public:
00627 PVideoOutputDevice();
00628
00631 virtual ~PVideoOutputDevice() { Close(); };
00632
00636 static PStringList GetDriverNames(PPluginManager * pluginMgr = NULL);
00637
00641 static PStringList GetDriversDeviceNames(
00642 const PString &driverName,
00643 PPluginManager * pluginMgr = NULL
00644 );
00645
00649 static PVideoOutputDevice *CreateDevice(
00650 const PString &driverName,
00651 PPluginManager * pluginMgr = NULL
00652 );
00653
00657 static PVideoOutputDevice *CreateOpenedDevice(
00658 const PString & driverName,
00659 const PString & deviceName,
00660 BOOL startImmediate = TRUE,
00661 PPluginManager * pluginMgr = NULL
00662 );
00663
00666 virtual BOOL Close() { return TRUE; }
00667
00670 virtual BOOL CanCaptureVideo() const;
00671
00674 virtual BOOL SetFrameData(
00675 unsigned x,
00676 unsigned y,
00677 unsigned width,
00678 unsigned height,
00679 const BYTE * data,
00680 BOOL endFrame = TRUE
00681 ) = 0;
00682
00688 virtual BOOL Start() { return TRUE; }
00689
00692 virtual BOOL Stop() { return TRUE; }
00693 };
00694
00695
00696 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00697
00700 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00701 {
00702 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00703
00704 public:
00707 PVideoOutputDeviceRGB();
00708
00719 virtual BOOL SetColourFormat(
00720 const PString & colourFormat
00721 );
00722
00731 virtual BOOL SetFrameSize(
00732 unsigned width,
00733 unsigned height
00734 );
00735
00741 virtual PINDEX GetMaxFrameBytes();
00742
00745 virtual BOOL SetFrameData(
00746 unsigned x,
00747 unsigned y,
00748 unsigned width,
00749 unsigned height,
00750 const BYTE * data,
00751 BOOL endFrame = TRUE
00752 );
00753
00756 virtual BOOL EndFrame() = 0;
00757
00758 protected:
00759 PBYTEArray frameStore;
00760 PINDEX bytesPerPixel;
00761 };
00762
00763 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00764
00765 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00766
00769 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00770 {
00771 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00772
00773 public:
00776 PVideoOutputDevicePPM();
00777
00780 virtual BOOL Open(
00781 const PString & deviceName,
00782 BOOL startImmediate = TRUE
00783 );
00784
00787 virtual BOOL IsOpen();
00788
00791 virtual BOOL Close();
00792
00795 virtual PStringList GetDeviceNames() const;
00796
00799 virtual BOOL EndFrame();
00800
00801 protected:
00802 unsigned frameNumber;
00803 };
00804
00805 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00806
00809 class PVideoInputDevice : public PVideoDevice
00810 {
00811 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00812
00813 public:
00816
00817
00820 ~PVideoInputDevice() { Close(); }
00821
00825 static PStringList GetDriverNames(PPluginManager * pluginMgr = NULL);
00826
00830 static PStringList GetDriversDeviceNames(
00831 const PString &driverName,
00832 PPluginManager * pluginMgr = NULL
00833 );
00834
00838 static PVideoInputDevice *CreateDevice(
00839 const PString &driverName,
00840 PPluginManager * pluginMgr = NULL
00841 );
00842
00843
00844
00845
00846
00847
00848 static PVideoInputDevice *CreateDeviceByName(const PString &deviceName,
00849 PPluginManager * pluginMgr = NULL
00850 );
00851
00855 static PVideoInputDevice *CreateOpenedDevice(
00856 const PString & driverName,
00857 const PString & deviceName,
00858 BOOL startImmediate = TRUE,
00859 PPluginManager * pluginMgr = NULL
00860 );
00861
00864 virtual BOOL CanCaptureVideo() const;
00865
00868 virtual BOOL Open(
00869 const PString & deviceName,
00870 BOOL startImmediate = TRUE
00871 ) = 0;
00872
00873 virtual BOOL Close(
00874 ) { return TRUE; }
00875
00878 virtual BOOL IsCapturing() = 0;
00879
00885 virtual PINDEX GetMaxFrameBytes() = 0;
00886
00889 virtual BOOL GetFrame(
00890 PBYTEArray & frame
00891 ) = 0;
00892
00895 virtual BOOL GetFrameData(
00896 BYTE * buffer,
00897 PINDEX * bytesReturned = NULL
00898 ) = 0;
00899
00902 virtual BOOL GetFrameDataNoDelay(
00903 BYTE * buffer,
00904 PINDEX * bytesReturned = NULL
00905 ) = 0;
00906
00909 virtual BOOL TestAllFormats() = 0;
00910 };
00911
00913
00914
00915
00916
00917 class PVideoInputDevicePluginServiceDescriptor : public PPluginServiceDescriptor
00918 {
00919 public:
00920 PVideoInputDevicePluginServiceDescriptor(
00921 unsigned (*_GetVersion)(),
00922 PVideoInputDevice *(*_CreateInstance)(),
00923 PStringList (*_GetDeviceNames)()
00924 )
00925 : PPluginServiceDescriptor(_GetVersion),
00926 CreateInstance(_CreateInstance),
00927 GetDeviceNames(_GetDeviceNames)
00928 { }
00929
00930 PVideoInputDevice *(*CreateInstance)();
00931 PStringList (*GetDeviceNames) ();
00932 };
00933
00934
00935 #define PCREATE_VIDINPUT_SERVICE_DESCRIPTOR(className, versionFn) \
00936 PVideoInputDevice * className##_CreateInstance () \
00937 { \
00938 return new className; \
00939 } \
00940 \
00941 PStringList className##_GetDeviceNames () \
00942 { \
00943 return className::GetInputDeviceNames(); \
00944 } \
00945 \
00946 PVideoInputDevicePluginServiceDescriptor className##_descriptor(\
00947 versionFn, \
00948 className##_CreateInstance, \
00949 className##_GetDeviceNames \
00950 ); \
00951
00952 #define PCREATE_VIDINPUT_PLUGIN(name, className) \
00953 PCREATE_PLUGIN_VERSION_FN(name, PVideoInputDevice) \
00954 PCREATE_VIDINPUT_SERVICE_DESCRIPTOR(className, PPLUGIN_VERSION_FN(name, PVideoInputDevice)) \
00955 PCREATE_PLUGIN(name, PVideoInputDevice, &className##_descriptor)
00956
00958
00959
00960
00961
00962 class PVideoOutputDevicePluginServiceDescriptor : public PPluginServiceDescriptor
00963 {
00964 public:
00965 PVideoOutputDevicePluginServiceDescriptor(
00966 unsigned (*_GetVersion)(),
00967 PVideoOutputDevice *(*_CreateInstance)(),
00968 PStringList (*_GetDeviceNames)()
00969 )
00970 : PPluginServiceDescriptor(_GetVersion),
00971 CreateInstance(_CreateInstance),
00972 GetDeviceNames(_GetDeviceNames)
00973 { }
00974
00975 PVideoOutputDevice *(*CreateInstance)();
00976 PStringList (*GetDeviceNames) ();
00977 };
00978
00979
00980 #define PCREATE_VIDOUTPUT_SERVICE_DESCRIPTOR(className, versionFn) \
00981 PVideoOutputDevice * className##_CreateInstance () \
00982 { \
00983 return new className; \
00984 } \
00985 \
00986 PStringList className##_GetDeviceNames () \
00987 { \
00988 return className::GetOutputDeviceNames(); \
00989 } \
00990 \
00991 PVideoOutputDevicePluginServiceDescriptor className##_descriptor(\
00992 versionFn, \
00993 className##_CreateInstance, \
00994 className##_GetDeviceNames \
00995 ); \
00996
00997 #define PCREATE_VIDOUTPUT_PLUGIN(name, className) \
00998 PCREATE_PLUGIN_VERSION_FN(name, PVideoOutputDevice) \
00999 PCREATE_VIDOUTPUT_SERVICE_DESCRIPTOR(className, PPLUGIN_VERSION_FN(name, PVideoOutputDevice)) \
01000 PCREATE_PLUGIN(name, PVideoOutputDevice, &className##_descriptor)
01001
01002 #endif // _PVIDEOIO
01003
01004