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
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 #ifndef _PVIDEOIO
00256 #define _PVIDEOIO
00257
00258 #ifdef P_USE_PRAGMA
00259 #pragma interface
00260 #endif
00261
00262 #ifndef _PTLIB_H
00263 #include <ptlib.h>
00264 #endif
00265
00266 #if P_VIDEO
00267
00268 #include <ptlib/plugin.h>
00269 #include <ptlib/pluginmgr.h>
00270
00271 class PColourConverter;
00272
00273
00274 class PVideoFrameInfo : public PObject
00275 {
00276 PCLASSINFO(PVideoFrameInfo, PObject);
00277
00278 public:
00279 PVideoFrameInfo();
00280
00281 enum ResizeMode
00282 {
00283 eScale,
00284 eCropCentre,
00285 eCropTopLeft,
00286 eMaxResizeMode
00287 };
00288
00289 enum StandardSizes {
00290 CIF16Width = 1408, CIF16Height = 1152,
00291 CIF4Width = 704, CIF4Height = 576,
00292 CIFWidth = 352, CIFHeight = 288,
00293 QCIFWidth = 176, QCIFHeight = 144,
00294 SQCIFWidth = 144, SQCIFHeight = 96,
00295 };
00296
00302 virtual BOOL SetFrameSize(
00303 unsigned width,
00304 unsigned height
00305 );
00306
00312 virtual BOOL GetFrameSize(
00313 unsigned & width,
00314 unsigned & height
00315 ) const;
00316
00321 virtual unsigned GetFrameWidth() const;
00322
00327 virtual unsigned GetFrameHeight() const;
00328
00334 virtual BOOL SetFrameRate(
00335 unsigned rate
00336 );
00337
00342 virtual unsigned GetFrameRate() const;
00343
00349 virtual BOOL SetColourFormat(
00350 const PString & colourFormat
00351 );
00352
00357 virtual const PString & GetColourFormat() const;
00358
00361 void SetResizeMode(
00362 ResizeMode mode
00363 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
00364
00367 ResizeMode GetResizeMode() const { return resizeMode; }
00368
00371 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); }
00372 static PINDEX CalculateFrameBytes(
00373 unsigned width,
00374 unsigned height,
00375 const PString & colourFormat
00376 );
00377
00380 static BOOL ParseSize(
00381 const PString & str,
00382 unsigned & width,
00383 unsigned & height
00384 );
00385
00386 protected:
00387 unsigned frameWidth;
00388 unsigned frameHeight;
00389 unsigned frameRate;
00390 PString colourFormat;
00391 ResizeMode resizeMode;
00392 };
00393
00394
00423 class PVideoDevice : public PVideoFrameInfo
00424 {
00425 PCLASSINFO(PVideoDevice, PVideoFrameInfo);
00426
00427 protected:
00430 PVideoDevice();
00431
00432
00433 public:
00436 virtual ~PVideoDevice();
00437
00438 enum VideoFormat {
00439 PAL,
00440 NTSC,
00441 SECAM,
00442 Auto,
00443 NumVideoFormats
00444 };
00445
00448 const PString & GetDeviceName() const
00449 { return deviceName; }
00450
00453 virtual PStringList GetDeviceNames() const = 0;
00454
00455 struct OpenArgs {
00456 OpenArgs();
00457
00458 PPluginManager * pluginMgr;
00459 PString driverName;
00460 PString deviceName;
00461 VideoFormat videoFormat;
00462 int channelNumber;
00463 PString colourFormat;
00464 bool convertFormat;
00465 unsigned rate;
00466 unsigned width;
00467 unsigned height;
00468 bool convertSize;
00469 ResizeMode resizeMode;
00470 bool flip;
00471 int brightness;
00472 int whiteness;
00473 int contrast;
00474 int colour;
00475 int hue;
00476 };
00477
00480 virtual BOOL OpenFull(
00481 const OpenArgs & args,
00482 BOOL startImmediate = TRUE
00483 );
00484
00487 virtual BOOL Open(
00488 const PString & deviceName,
00489 BOOL startImmediate = TRUE
00490 ) = 0;
00491
00494 virtual BOOL IsOpen() = 0;
00495
00498 virtual BOOL Close() = 0;
00499
00502 virtual BOOL Start() = 0;
00503
00506 virtual BOOL Stop() = 0;
00507
00508
00509 #if PTRACING
00510 friend ostream & operator<<(ostream &, VideoFormat);
00511 #endif
00512
00518 virtual BOOL SetVideoFormat(
00519 VideoFormat videoFormat
00520 );
00521
00526 virtual VideoFormat GetVideoFormat() const;
00527
00532 virtual int GetNumChannels();
00533
00541 virtual BOOL SetChannel(
00542 int channelNumber
00543 );
00544
00549 virtual int GetChannel() const;
00550
00557 virtual BOOL SetColourFormatConverter(
00558 const PString & colourFormat
00559 );
00560
00564 virtual BOOL GetVFlipState();
00565
00569 virtual BOOL SetVFlipState(
00570 BOOL newVFlipState
00571 );
00572
00578 virtual BOOL GetFrameSizeLimits(
00579 unsigned & minWidth,
00580 unsigned & minHeight,
00581 unsigned & maxWidth,
00582 unsigned & maxHeight
00583 ) ;
00584
00585
00591 virtual BOOL SetFrameSizeConverter(
00592 unsigned width,
00593 unsigned height,
00594 ResizeMode resizeMode = eMaxResizeMode
00595 );
00596
00602 virtual BOOL SetFrameSizeConverter(
00603 unsigned width,
00604 unsigned height,
00605 BOOL
00606 ) { return SetFrameSizeConverter(width,height,eScale); }
00607
00608
00617 virtual BOOL SetFrameSize(
00618 unsigned width,
00619 unsigned height
00620 );
00621
00627 virtual BOOL GetFrameSize(
00628 unsigned & width,
00629 unsigned & height
00630 ) const;
00631
00637 virtual PINDEX GetMaxFrameBytes() = 0;
00638
00639
00642 int GetLastError() const { return lastError; }
00643
00644
00647 virtual BOOL CanCaptureVideo() const = 0;
00648
00651 virtual int GetBrightness();
00652
00655 virtual BOOL SetBrightness(unsigned newBrightness);
00656
00657
00660 virtual int GetWhiteness();
00661
00664 virtual BOOL SetWhiteness(unsigned newWhiteness);
00665
00666
00669 virtual int GetColour();
00670
00673 virtual BOOL SetColour(unsigned newColour);
00674
00675
00678 virtual int GetContrast();
00679
00682 virtual BOOL SetContrast(unsigned newContrast);
00683
00684
00687 virtual int GetHue();
00688
00691 virtual BOOL SetHue(unsigned newHue);
00692
00693
00696 virtual BOOL GetParameters(
00697 int *whiteness,
00698 int *brightness,
00699 int *colour,
00700 int *contrast,
00701 int *hue
00702 );
00703
00704
00707 virtual BOOL SetVideoChannelFormat (
00708 int channelNumber,
00709 VideoFormat videoFormat
00710 );
00711
00712
00716 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00717
00721 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00722
00723 int GetNumberOfFrames () { return numberOfFrames; }
00724
00725 protected:
00726 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00727
00728 PString deviceName;
00729 int lastError;
00730 VideoFormat videoFormat;
00731 int channelNumber;
00732
00733 PString preferredColourFormat;
00734 BOOL nativeVerticalFlip;
00735
00736 PColourConverter * converter;
00737 PBYTEArray frameStore;
00738
00739 int frameBrightness;
00740 int frameWhiteness;
00741 int frameContrast;
00742 int frameColour;
00743 int frameHue;
00744 int numberOfFrames;
00745 };
00746
00747
00750 class PVideoOutputDevice : public PVideoDevice
00751 {
00752 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00753
00754 public:
00757 PVideoOutputDevice();
00758
00761 virtual ~PVideoOutputDevice() { Close(); };
00762
00765 static PStringList GetDriverNames(
00766 PPluginManager * pluginMgr = NULL
00767 );
00768
00775 static PStringList GetDriversDeviceNames(
00776 const PString & driverName,
00777 PPluginManager * pluginMgr = NULL
00778 );
00779
00782 static PVideoOutputDevice * CreateDevice(
00783 const PString & driverName,
00784 PPluginManager * pluginMgr = NULL
00785 );
00786
00787
00788
00789
00790
00791 static PVideoOutputDevice *CreateDeviceByName(
00792 const PString & deviceName,
00793 const PString & driverName = PString::Empty(),
00794 PPluginManager * pluginMgr = NULL
00795 );
00796
00802 static PVideoOutputDevice *CreateOpenedDevice(
00803 const PString & driverName,
00804 const PString & deviceName,
00805 BOOL startImmediate = TRUE,
00806 PPluginManager * pluginMgr = NULL
00807 );
00808
00811 static PVideoOutputDevice *CreateOpenedDevice(
00812 const OpenArgs & args,
00813 BOOL startImmediate = TRUE
00814 );
00815
00818 virtual BOOL Close() { return TRUE; }
00819
00822 virtual BOOL Start() { return TRUE; }
00823
00826 virtual BOOL Stop() { return TRUE; }
00827
00830 virtual BOOL CanCaptureVideo() const;
00831
00834 virtual BOOL SetFrameData(
00835 unsigned x,
00836 unsigned y,
00837 unsigned width,
00838 unsigned height,
00839 const BYTE * data,
00840 BOOL endFrame = TRUE
00841 ) = 0;
00842
00849 virtual BOOL GetPosition(
00850 int & x,
00851 int & y
00852 ) const;
00853 };
00854
00855
00858 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00859 {
00860 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00861
00862 public:
00865 PVideoOutputDeviceRGB();
00866
00877 virtual BOOL SetColourFormat(
00878 const PString & colourFormat
00879 );
00880
00889 virtual BOOL SetFrameSize(
00890 unsigned width,
00891 unsigned height
00892 );
00893
00899 virtual PINDEX GetMaxFrameBytes();
00900
00903 virtual BOOL SetFrameData(
00904 unsigned x,
00905 unsigned y,
00906 unsigned width,
00907 unsigned height,
00908 const BYTE * data,
00909 BOOL endFrame = TRUE
00910 );
00911
00914 virtual BOOL FrameComplete() = 0;
00915
00916 protected:
00917 PMutex mutex;
00918 PINDEX bytesPerPixel;
00919 PINDEX scanLineWidth;
00920 bool swappedRedAndBlue;
00921 };
00922
00923
00924 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00925
00928 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00929 {
00930 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00931
00932 public:
00935 PVideoOutputDevicePPM();
00936
00939 virtual BOOL Open(
00940 const PString & deviceName,
00941 BOOL startImmediate = TRUE
00942 );
00943
00946 virtual BOOL IsOpen();
00947
00950 virtual BOOL Close();
00951
00954 virtual PStringList GetDeviceNames() const;
00955
00958 virtual BOOL EndFrame();
00959
00960 protected:
00961 unsigned frameNumber;
00962 };
00963
00964 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00965
00966
00969 class PVideoInputDevice : public PVideoDevice
00970 {
00971 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00972
00973 public:
00976
00977
00980 ~PVideoInputDevice() { Close(); }
00981
00984 static PStringList GetDriverNames(
00985 PPluginManager * pluginMgr = NULL
00986 );
00987
00994 static PStringList GetDriversDeviceNames(
00995 const PString & driverName,
00996 PPluginManager * pluginMgr = NULL
00997 );
00998
01001 static PVideoInputDevice *CreateDevice(
01002 const PString & driverName,
01003 PPluginManager * pluginMgr = NULL
01004 );
01005
01006
01007
01008
01009
01010
01011
01012
01013 static PVideoInputDevice *CreateDeviceByName(
01014 const PString & deviceName,
01015 const PString & driverName = PString::Empty(),
01016 PPluginManager * pluginMgr = NULL
01017 );
01018
01024 static PVideoInputDevice *CreateOpenedDevice(
01025 const PString & driverName,
01026 const PString & deviceName,
01027 BOOL startImmediate = TRUE,
01028 PPluginManager * pluginMgr = NULL
01029 );
01030
01033 static PVideoInputDevice *CreateOpenedDevice(
01034 const OpenArgs & args,
01035 BOOL startImmediate = TRUE
01036 );
01037
01040 virtual BOOL Open(
01041 const PString & deviceName,
01042 BOOL startImmediate = TRUE
01043 ) = 0;
01044
01045 virtual BOOL Close(
01046 ) { return TRUE; }
01047
01050 virtual BOOL CanCaptureVideo() const;
01051
01054 virtual BOOL IsCapturing() = 0;
01055
01058 virtual BOOL GetFrame(
01059 PBYTEArray & frame
01060 );
01061
01064 virtual BOOL GetFrameData(
01065 BYTE * buffer,
01066 PINDEX * bytesReturned = NULL
01067 ) = 0;
01068
01071 virtual BOOL GetFrameDataNoDelay(
01072 BYTE * buffer,
01073 PINDEX * bytesReturned = NULL
01074 ) = 0;
01075
01078 virtual BOOL TestAllFormats() = 0;
01079 };
01080
01081
01083
01084
01085
01086
01087 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01088 {
01089 public:
01090 virtual PObject * CreateInstance(int ) const { return new className; }
01091 virtual PStringList GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
01092 };
01093
01094 #define PCREATE_VIDINPUT_PLUGIN(name) \
01095 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
01096 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
01097
01099
01100
01101
01102
01103 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01104 {
01105 public:
01106 virtual PObject * CreateInstance(int ) const { return new className; }
01107 virtual PStringList GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
01108 };
01109
01110 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
01111 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
01112 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
01113
01115
01116
01117
01118
01119 class PVideoFont : public PObject
01120 {
01121 PCLASSINFO(PVideoFont, PObject);
01122 public:
01123 enum {
01124 MAX_L_HEIGHT = 11
01125 };
01126 struct LetterData {
01127 char ascii;
01128 const char *line[MAX_L_HEIGHT];
01129 };
01130
01131 static const LetterData * GetLetterData(char ascii);
01132 };
01133
01134 #endif // P_VIDEO
01135
01136 #endif // _PVIDEOIO
01137
01138