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
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 #ifndef _PVIDEOIO
00193 #define _PVIDEOIO
00194
00195 #ifdef P_USE_PRAGMA
00196 #pragma interface
00197 #endif
00198
00199 class PColourConverter;
00200
00231 class PVideoDevice : public PObject
00232 {
00233 PCLASSINFO(PVideoDevice, PObject);
00234
00235 protected:
00238 PVideoDevice();
00239
00240
00241 public:
00244 virtual ~PVideoDevice();
00245
00246 enum VideoFormat {
00247 PAL,
00248 NTSC,
00249 SECAM,
00250 Auto,
00251 NumVideoFormats
00252 };
00253
00254 enum StandardSizes {
00255 CIF16Width = 1408,
00256 CIF16Height = 1152,
00257 CIF4Width = 704,
00258 CIF4Height = 576,
00259 CIFWidth = 352,
00260 CIFHeight = 288,
00261 QCIFWidth = 176,
00262 QCIFHeight = 144,
00263 SQCIFWidth = 144,
00264 SQCIFHeight = 96,
00265 };
00266
00269 const PString & GetDeviceName() const
00270 { return deviceName; }
00271
00274 virtual PStringList GetDeviceNames() const = 0;
00275
00276 struct OpenArgs {
00277 OpenArgs()
00278 : deviceName("#1"),
00279 videoFormat(Auto),
00280 channelNumber(0),
00281 colourFormat("YUV420P"),
00282 convertFormat(TRUE),
00283 rate(0),
00284 width(CIFWidth),
00285 height(CIFHeight),
00286 convertSize(TRUE),
00287 scaleSize(FALSE),
00288 flip(FALSE),
00289 brightness(-1),
00290 whiteness(-1),
00291 contrast(-1),
00292 colour(-1),
00293 hue(-1)
00294 { }
00295 PString deviceName;
00296 VideoFormat videoFormat;
00297 int channelNumber;
00298 PString colourFormat;
00299 bool convertFormat;
00300 unsigned rate;
00301 unsigned width;
00302 unsigned height;
00303 bool convertSize;
00304 bool scaleSize;
00305 bool flip;
00306 int brightness;
00307 int whiteness;
00308 int contrast;
00309 int colour;
00310 int hue;
00311 };
00312
00315 virtual BOOL OpenFull(
00316 const OpenArgs & args,
00317 BOOL startImmediate = TRUE
00318 );
00319
00322 virtual BOOL Open(
00323 const PString & deviceName,
00324 BOOL startImmediate = TRUE
00325 ) = 0;
00326
00329 virtual BOOL IsOpen() = 0;
00330
00333 virtual BOOL Close() = 0;
00334
00337 virtual BOOL Start() = 0;
00338
00341 virtual BOOL Stop() = 0;
00342
00343
00344 #if PTRACING
00345 friend ostream & operator<<(ostream &, VideoFormat);
00346 #endif
00347
00353 virtual BOOL SetVideoFormat(
00354 VideoFormat videoFormat
00355 );
00356
00361 virtual VideoFormat GetVideoFormat() const;
00362
00367 virtual int GetNumChannels();
00368
00376 virtual BOOL SetChannel(
00377 int channelNumber
00378 );
00379
00384 virtual int GetChannel() const;
00385
00392 virtual BOOL SetColourFormatConverter(
00393 const PString & colourFormat
00394 );
00395
00406 virtual BOOL SetColourFormat(
00407 const PString & colourFormat
00408 );
00409
00414 const PString & GetColourFormat() const;
00415
00419 virtual BOOL GetVFlipState();
00420
00424 virtual BOOL SetVFlipState(
00425 BOOL newVFlipState
00426 );
00427
00433 virtual BOOL SetFrameRate(
00434 unsigned rate
00435 );
00436
00441 virtual unsigned GetFrameRate() const;
00442
00448 virtual BOOL GetFrameSizeLimits(
00449 unsigned & minWidth,
00450 unsigned & minHeight,
00451 unsigned & maxWidth,
00452 unsigned & maxHeight
00453 ) ;
00454
00455
00461 virtual BOOL SetFrameSizeConverter(
00462 unsigned width,
00463 unsigned height,
00464 BOOL bScaleNotCrop
00465 );
00466
00475 virtual BOOL SetFrameSize(
00476 unsigned width,
00477 unsigned height
00478 );
00479
00485 virtual BOOL GetFrameSize(
00486 unsigned & width,
00487 unsigned & height
00488 );
00489
00494 virtual unsigned GetFrameWidth() const;
00495
00500 virtual unsigned GetFrameHeight() const;
00501
00507 virtual PINDEX GetMaxFrameBytes() = 0;
00508
00511 static unsigned CalculateFrameBytes(
00512 unsigned width,
00513 unsigned height,
00514 const PString & colourFormat
00515 );
00516
00517
00520 int GetLastError() const { return lastError; }
00521
00522
00525 virtual BOOL CanCaptureVideo() const = 0;
00526
00529 virtual int GetBrightness();
00530
00533 virtual BOOL SetBrightness(unsigned newBrightness);
00534
00535
00538 virtual int GetWhiteness();
00539
00542 virtual BOOL SetWhiteness(unsigned newWhiteness);
00543
00544
00547 virtual int GetColour();
00548
00551 virtual BOOL SetColour(unsigned newColour);
00552
00553
00556 virtual int GetContrast();
00557
00560 virtual BOOL SetContrast(unsigned newContrast);
00561
00562
00565 virtual int GetHue();
00566
00569 virtual BOOL SetHue(unsigned newHue);
00570
00571
00574 virtual BOOL GetParameters(
00575 int *whiteness,
00576 int *brightness,
00577 int *colour,
00578 int *contrast,
00579 int *hue
00580 );
00581
00582
00585 virtual BOOL SetVideoChannelFormat (
00586 int channelNumber,
00587 VideoFormat videoFormat
00588 );
00589
00590
00594 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00595
00599 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00600
00601 protected:
00602 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00603
00604 PString deviceName;
00605 int lastError;
00606 VideoFormat videoFormat;
00607 int channelNumber;
00608 PString colourFormat;
00609
00610 PString preferredColourFormat;
00611 unsigned frameRate;
00612 unsigned frameWidth;
00613 unsigned frameHeight;
00614 BOOL nativeVerticalFlip;
00615
00616 PColourConverter * converter;
00617
00618 int frameBrightness;
00619 int frameWhiteness;
00620 int frameContrast;
00621 int frameColour;
00622 int frameHue;
00623
00624 PTime previousFrameTime;
00625 int msBetweenFrames;
00626 int frameTimeError;
00627 };
00628
00629
00632 class PVideoOutputDevice : public PVideoDevice
00633 {
00634 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00635
00636 public:
00639 PVideoOutputDevice();
00640
00643 virtual ~PVideoOutputDevice() { Close(); };
00644
00647 static PStringList GetDriverNames(
00648 PPluginManager * pluginMgr = NULL
00649 );
00650
00657 static PStringList GetDriversDeviceNames(
00658 const PString & driverName,
00659 PPluginManager * pluginMgr = NULL
00660 );
00661
00664 static PVideoOutputDevice * CreateDevice(
00665 const PString & driverName,
00666 PPluginManager * pluginMgr = NULL
00667 );
00668
00669
00670
00671
00672
00673 static PVideoOutputDevice *CreateDeviceByName(
00674 const PString & deviceName,
00675 PPluginManager * pluginMgr = NULL
00676 );
00677
00683 static PVideoOutputDevice *CreateOpenedDevice(
00684 const PString & driverName,
00685 const PString & deviceName,
00686 BOOL startImmediate = TRUE,
00687 PPluginManager * pluginMgr = NULL
00688 );
00689
00692 virtual BOOL Close() { return TRUE; }
00693
00696 virtual BOOL Start() { return TRUE; }
00697
00700 virtual BOOL Stop() { return TRUE; }
00701
00704 virtual BOOL CanCaptureVideo() const;
00705
00708 virtual BOOL SetFrameData(
00709 unsigned x,
00710 unsigned y,
00711 unsigned width,
00712 unsigned height,
00713 const BYTE * data,
00714 BOOL endFrame = TRUE
00715 ) = 0;
00716 };
00717
00718
00721 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00722 {
00723 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00724
00725 public:
00728 PVideoOutputDeviceRGB();
00729
00740 virtual BOOL SetColourFormat(
00741 const PString & colourFormat
00742 );
00743
00752 virtual BOOL SetFrameSize(
00753 unsigned width,
00754 unsigned height
00755 );
00756
00762 virtual PINDEX GetMaxFrameBytes();
00763
00766 virtual BOOL SetFrameData(
00767 unsigned x,
00768 unsigned y,
00769 unsigned width,
00770 unsigned height,
00771 const BYTE * data,
00772 BOOL endFrame = TRUE
00773 );
00774
00777 virtual BOOL FrameComplete() = 0;
00778
00779 protected:
00780 PMutex mutex;
00781 PBYTEArray frameStore;
00782 PINDEX bytesPerPixel;
00783 PINDEX scanLineWidth;
00784 bool swappedRedAndBlue;
00785 };
00786
00787
00788 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00789
00792 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00793 {
00794 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00795
00796 public:
00799 PVideoOutputDevicePPM();
00800
00803 virtual BOOL Open(
00804 const PString & deviceName,
00805 BOOL startImmediate = TRUE
00806 );
00807
00810 virtual BOOL IsOpen();
00811
00814 virtual BOOL Close();
00815
00818 virtual PStringList GetDeviceNames() const;
00819
00822 virtual BOOL EndFrame();
00823
00824 protected:
00825 unsigned frameNumber;
00826 };
00827
00828 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00829
00830
00833 class PVideoInputDevice : public PVideoDevice
00834 {
00835 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00836
00837 public:
00840
00841
00844 ~PVideoInputDevice() { Close(); }
00845
00848 static PStringList GetDriverNames(
00849 PPluginManager * pluginMgr = NULL
00850 );
00851
00858 static PStringList GetDriversDeviceNames(
00859 const PString & driverName,
00860 PPluginManager * pluginMgr = NULL
00861 );
00862
00865 static PVideoInputDevice *CreateDevice(
00866 const PString & driverName,
00867 PPluginManager * pluginMgr = NULL
00868 );
00869
00870
00871
00872
00873
00874
00875
00876
00877 static PVideoInputDevice *CreateDeviceByName(
00878 const PString & deviceName,
00879 PPluginManager * pluginMgr = NULL
00880 );
00881
00887 static PVideoInputDevice *CreateOpenedDevice(
00888 const PString & driverName,
00889 const PString & deviceName,
00890 BOOL startImmediate = TRUE,
00891 PPluginManager * pluginMgr = NULL
00892 );
00893
00896 virtual BOOL Open(
00897 const PString & deviceName,
00898 BOOL startImmediate = TRUE
00899 ) = 0;
00900
00901 virtual BOOL Close(
00902 ) { return TRUE; }
00903
00906 virtual BOOL CanCaptureVideo() const;
00907
00910 virtual BOOL IsCapturing() = 0;
00911
00914 virtual BOOL GetFrame(
00915 PBYTEArray & frame
00916 );
00917
00920 virtual BOOL GetFrameData(
00921 BYTE * buffer,
00922 PINDEX * bytesReturned = NULL
00923 ) = 0;
00924
00927 virtual BOOL GetFrameDataNoDelay(
00928 BYTE * buffer,
00929 PINDEX * bytesReturned = NULL
00930 ) = 0;
00931
00934 virtual BOOL TestAllFormats() = 0;
00935 };
00936
00937
00939
00940
00941
00942
00943 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00944 {
00945 public:
00946 virtual PObject * CreateInstance(int ) const { return new className; }
00947 virtual PStringList GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
00948 };
00949
00950 #define PCREATE_VIDINPUT_PLUGIN(name) \
00951 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
00952 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
00953
00955
00956
00957
00958
00959 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00960 {
00961 public:
00962 virtual PObject * CreateInstance(int ) const { return new className; }
00963 virtual PStringList GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
00964 };
00965
00966 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
00967 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
00968 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
00969
00970 #endif // _PVIDEOIO
00971
00972