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
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 #ifndef _PVIDEOIO
00208 #define _PVIDEOIO
00209
00210 #ifdef P_USE_PRAGMA
00211 #pragma interface
00212 #endif
00213
00214 #include <ptlib/plugin.h>
00215 #include <ptlib/pluginmgr.h>
00216
00217 class PColourConverter;
00218
00249 class PVideoDevice : public PObject
00250 {
00251 PCLASSINFO(PVideoDevice, PObject);
00252
00253 protected:
00256 PVideoDevice();
00257
00258
00259 public:
00262 virtual ~PVideoDevice();
00263
00264 enum VideoFormat {
00265 PAL,
00266 NTSC,
00267 SECAM,
00268 Auto,
00269 NumVideoFormats
00270 };
00271
00272 enum StandardSizes {
00273 CIF16Width = 1408,
00274 CIF16Height = 1152,
00275 CIF4Width = 704,
00276 CIF4Height = 576,
00277 CIFWidth = 352,
00278 CIFHeight = 288,
00279 QCIFWidth = 176,
00280 QCIFHeight = 144,
00281 SQCIFWidth = 144,
00282 SQCIFHeight = 96,
00283 };
00284
00287 const PString & GetDeviceName() const
00288 { return deviceName; }
00289
00292 virtual PStringList GetDeviceNames() const = 0;
00293
00294 struct OpenArgs {
00295 OpenArgs()
00296 : deviceName("#1"),
00297 videoFormat(Auto),
00298 channelNumber(0),
00299 colourFormat("YUV420P"),
00300 convertFormat(TRUE),
00301 rate(0),
00302 width(CIFWidth),
00303 height(CIFHeight),
00304 convertSize(TRUE),
00305 scaleSize(FALSE),
00306 flip(FALSE),
00307 brightness(-1),
00308 whiteness(-1),
00309 contrast(-1),
00310 colour(-1),
00311 hue(-1)
00312 { }
00313 PString deviceName;
00314 PString filename;
00315 VideoFormat videoFormat;
00316 int channelNumber;
00317 PString colourFormat;
00318 bool convertFormat;
00319 unsigned rate;
00320 unsigned width;
00321 unsigned height;
00322 bool convertSize;
00323 bool scaleSize;
00324 bool flip;
00325 int brightness;
00326 int whiteness;
00327 int contrast;
00328 int colour;
00329 int hue;
00330 };
00331
00334 virtual BOOL OpenFull(
00335 const OpenArgs & args,
00336 BOOL startImmediate = TRUE
00337 );
00338
00341 virtual BOOL Open(
00342 const PString & deviceName,
00343 BOOL startImmediate = TRUE
00344 ) = 0;
00345
00348 virtual BOOL IsOpen() = 0;
00349
00352 virtual BOOL Close() = 0;
00353
00356 virtual BOOL Start() = 0;
00357
00360 virtual BOOL Stop() = 0;
00361
00362
00363 #if PTRACING
00364 friend ostream & operator<<(ostream &, VideoFormat);
00365 #endif
00366
00372 virtual BOOL SetVideoFormat(
00373 VideoFormat videoFormat
00374 );
00375
00380 virtual VideoFormat GetVideoFormat() const;
00381
00386 virtual int GetNumChannels();
00387
00395 virtual BOOL SetChannel(
00396 int channelNumber
00397 );
00398
00403 virtual int GetChannel() const;
00404
00411 virtual BOOL SetColourFormatConverter(
00412 const PString & colourFormat
00413 );
00414
00425 virtual BOOL SetColourFormat(
00426 const PString & colourFormat
00427 );
00428
00433 const PString & GetColourFormat() const;
00434
00438 virtual BOOL GetVFlipState();
00439
00443 virtual BOOL SetVFlipState(
00444 BOOL newVFlipState
00445 );
00446
00452 virtual BOOL SetFrameRate(
00453 unsigned rate
00454 );
00455
00460 virtual unsigned GetFrameRate() const;
00461
00467 virtual BOOL GetFrameSizeLimits(
00468 unsigned & minWidth,
00469 unsigned & minHeight,
00470 unsigned & maxWidth,
00471 unsigned & maxHeight
00472 ) ;
00473
00474
00480 virtual BOOL SetFrameSizeConverter(
00481 unsigned width,
00482 unsigned height,
00483 BOOL bScaleNotCrop
00484 );
00485
00494 virtual BOOL SetFrameSize(
00495 unsigned width,
00496 unsigned height
00497 );
00498
00504 virtual BOOL GetFrameSize(
00505 unsigned & width,
00506 unsigned & height
00507 );
00508
00513 virtual unsigned GetFrameWidth() const;
00514
00519 virtual unsigned GetFrameHeight() const;
00520
00526 virtual PINDEX GetMaxFrameBytes() = 0;
00527
00530 static unsigned CalculateFrameBytes(
00531 unsigned width,
00532 unsigned height,
00533 const PString & colourFormat
00534 );
00535
00536
00539 int GetLastError() const { return lastError; }
00540
00541
00544 virtual BOOL CanCaptureVideo() const = 0;
00545
00548 virtual int GetBrightness();
00549
00552 virtual BOOL SetBrightness(unsigned newBrightness);
00553
00554
00557 virtual int GetWhiteness();
00558
00561 virtual BOOL SetWhiteness(unsigned newWhiteness);
00562
00563
00566 virtual int GetColour();
00567
00570 virtual BOOL SetColour(unsigned newColour);
00571
00572
00575 virtual int GetContrast();
00576
00579 virtual BOOL SetContrast(unsigned newContrast);
00580
00581
00584 virtual int GetHue();
00585
00588 virtual BOOL SetHue(unsigned newHue);
00589
00590
00593 virtual BOOL GetParameters(
00594 int *whiteness,
00595 int *brightness,
00596 int *colour,
00597 int *contrast,
00598 int *hue
00599 );
00600
00601
00604 virtual BOOL SetVideoChannelFormat (
00605 int channelNumber,
00606 VideoFormat videoFormat
00607 );
00608
00609
00613 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00614
00618 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00619
00620 protected:
00621 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00622
00623 PString deviceName;
00624 int lastError;
00625 VideoFormat videoFormat;
00626 int channelNumber;
00627 PString colourFormat;
00628
00629 PString preferredColourFormat;
00630 unsigned frameRate;
00631 unsigned frameWidth;
00632 unsigned frameHeight;
00633 BOOL nativeVerticalFlip;
00634
00635 PColourConverter * converter;
00636
00637 int frameBrightness;
00638 int frameWhiteness;
00639 int frameContrast;
00640 int frameColour;
00641 int frameHue;
00642
00643 PTime previousFrameTime;
00644 int msBetweenFrames;
00645 int frameTimeError;
00646 };
00647
00648
00651 class PVideoOutputDevice : public PVideoDevice
00652 {
00653 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00654
00655 public:
00658 PVideoOutputDevice();
00659
00662 virtual ~PVideoOutputDevice() { Close(); };
00663
00666 static PStringList GetDriverNames(
00667 PPluginManager * pluginMgr = NULL
00668 );
00669
00676 static PStringList GetDriversDeviceNames(
00677 const PString & driverName,
00678 PPluginManager * pluginMgr = NULL
00679 );
00680
00683 static PVideoOutputDevice * CreateDevice(
00684 const PString & driverName,
00685 PPluginManager * pluginMgr = NULL
00686 );
00687
00688
00689
00690
00691
00692 static PVideoOutputDevice *CreateDeviceByName(
00693 const PString & deviceName,
00694 PPluginManager * pluginMgr = NULL
00695 );
00696
00702 static PVideoOutputDevice *CreateOpenedDevice(
00703 const PString & driverName,
00704 const PString & deviceName,
00705 BOOL startImmediate = TRUE,
00706 PPluginManager * pluginMgr = NULL
00707 );
00708
00711 virtual BOOL Close() { return TRUE; }
00712
00715 virtual BOOL Start() { return TRUE; }
00716
00719 virtual BOOL Stop() { return TRUE; }
00720
00723 virtual BOOL CanCaptureVideo() const;
00724
00727 virtual BOOL SetFrameData(
00728 unsigned x,
00729 unsigned y,
00730 unsigned width,
00731 unsigned height,
00732 const BYTE * data,
00733 BOOL endFrame = TRUE
00734 ) = 0;
00735 };
00736
00737
00740 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00741 {
00742 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00743
00744 public:
00747 PVideoOutputDeviceRGB();
00748
00759 virtual BOOL SetColourFormat(
00760 const PString & colourFormat
00761 );
00762
00771 virtual BOOL SetFrameSize(
00772 unsigned width,
00773 unsigned height
00774 );
00775
00781 virtual PINDEX GetMaxFrameBytes();
00782
00785 virtual BOOL SetFrameData(
00786 unsigned x,
00787 unsigned y,
00788 unsigned width,
00789 unsigned height,
00790 const BYTE * data,
00791 BOOL endFrame = TRUE
00792 );
00793
00796 virtual BOOL FrameComplete() = 0;
00797
00798 protected:
00799 PMutex mutex;
00800 PBYTEArray frameStore;
00801 PINDEX bytesPerPixel;
00802 PINDEX scanLineWidth;
00803 bool swappedRedAndBlue;
00804 };
00805
00806
00807 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00808
00811 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00812 {
00813 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00814
00815 public:
00818 PVideoOutputDevicePPM();
00819
00822 virtual BOOL Open(
00823 const PString & deviceName,
00824 BOOL startImmediate = TRUE
00825 );
00826
00829 virtual BOOL IsOpen();
00830
00833 virtual BOOL Close();
00834
00837 virtual PStringList GetDeviceNames() const;
00838
00841 virtual BOOL EndFrame();
00842
00843 protected:
00844 unsigned frameNumber;
00845 };
00846
00847 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00848
00849
00852 class PVideoInputDevice : public PVideoDevice
00853 {
00854 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00855
00856 public:
00859
00860
00863 ~PVideoInputDevice() { Close(); }
00864
00867 static PStringList GetDriverNames(
00868 PPluginManager * pluginMgr = NULL
00869 );
00870
00877 static PStringList GetDriversDeviceNames(
00878 const PString & driverName,
00879 PPluginManager * pluginMgr = NULL
00880 );
00881
00884 static PVideoInputDevice *CreateDevice(
00885 const PString & driverName,
00886 PPluginManager * pluginMgr = NULL
00887 );
00888
00889
00890
00891
00892
00893
00894
00895
00896 static PVideoInputDevice *CreateDeviceByName(
00897 const PString & deviceName,
00898 const PString & driverName = PString::Empty(),
00899 PPluginManager * pluginMgr = NULL
00900 );
00901
00907 static PVideoInputDevice *CreateOpenedDevice(
00908 const PString & driverName,
00909 const PString & deviceName,
00910 BOOL startImmediate = TRUE,
00911 PPluginManager * pluginMgr = NULL
00912 );
00913
00916 virtual BOOL Open(
00917 const PString & deviceName,
00918 BOOL startImmediate = TRUE
00919 ) = 0;
00920
00921 virtual BOOL Close(
00922 ) { return TRUE; }
00923
00926 virtual BOOL CanCaptureVideo() const;
00927
00930 virtual BOOL IsCapturing() = 0;
00931
00934 virtual BOOL GetFrame(
00935 PBYTEArray & frame
00936 );
00937
00940 virtual BOOL GetFrameData(
00941 BYTE * buffer,
00942 PINDEX * bytesReturned = NULL
00943 ) = 0;
00944
00947 virtual BOOL GetFrameDataNoDelay(
00948 BYTE * buffer,
00949 PINDEX * bytesReturned = NULL
00950 ) = 0;
00951
00954 virtual BOOL TestAllFormats() = 0;
00955 };
00956
00957
00959
00960
00961
00962
00963 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00964 {
00965 public:
00966 virtual PObject * CreateInstance(int ) const { return new className; }
00967 virtual PStringList GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
00968 };
00969
00970 #define PCREATE_VIDINPUT_PLUGIN(name) \
00971 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
00972 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
00973
00975
00976
00977
00978
00979 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
00980 {
00981 public:
00982 virtual PObject * CreateInstance(int ) const { return new className; }
00983 virtual PStringList GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
00984 };
00985
00986 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
00987 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
00988 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
00989
00991
00992
00993
00994
00995 class PVideoFont : public PObject
00996 {
00997 PCLASSINFO(PVideoFont, PObject);
00998 public:
00999 enum {
01000 MAX_L_HEIGHT = 11
01001 };
01002 struct LetterData {
01003 char ascii;
01004 char *line[MAX_L_HEIGHT];
01005 };
01006
01007 static LetterData * GetLetterData(char ascii);
01008 };
01009
01010
01011 #endif // _PVIDEOIO
01012
01013