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 PTLIB_PVIDEOIO_H
00033 #define PTLIB_PVIDEOIO_H
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 #include <ptbuildopts.h>
00039
00040 #if P_VIDEO
00041
00042 #include <ptlib/plugin.h>
00043 #include <ptlib/pluginmgr.h>
00044 #include <list>
00045
00046 class PColourConverter;
00047
00048
00049 class PVideoFrameInfo : public PObject
00050 {
00051 PCLASSINFO(PVideoFrameInfo, PObject);
00052
00053 public:
00054 enum ResizeMode
00055 {
00056 eScale,
00057 eCropCentre,
00058 eCropTopLeft,
00059 eMaxResizeMode
00060 };
00061
00062 enum StandardSizes {
00063 SQCIFWidth = 128, SQCIFHeight = 96,
00064 QCIFWidth = 176, QCIFHeight = 144,
00065 CIFWidth = 352, CIFHeight = 288,
00066 CIF4Width = 704, CIF4Height = 576,
00067 CIF16Width = 1408, CIF16Height = 1152,
00068 i480Width = 640, i480Height = 480,
00069 p720Width = 960, p720Height = 720,
00070 i1080Width = 1920, i1080Height = 1080,
00071 HDTVWidth = 1920, HDTVHeight = 1080,
00072 MaxWidth = 1920, MaxHeight = 1152
00073 };
00074
00076 PVideoFrameInfo();
00077 PVideoFrameInfo(
00078 unsigned frameWidth,
00079 unsigned frameHeight,
00080 const PString & colourFormat = "YUV420P",
00081 unsigned frameRate = 15,
00082 ResizeMode resizeMode = eScale
00083 );
00084
00090 virtual PBoolean SetFrameSize(
00091 unsigned width,
00092 unsigned height
00093 );
00094
00100 virtual PBoolean GetFrameSize(
00101 unsigned & width,
00102 unsigned & height
00103 ) const;
00104
00109 virtual unsigned GetFrameWidth() const;
00110
00115 virtual unsigned GetFrameHeight() const;
00116
00122 virtual PBoolean SetFrameRate(
00123 unsigned rate
00124 );
00125
00130 virtual unsigned GetFrameRate() const;
00131
00137 virtual PBoolean SetColourFormat(
00138 const PString & colourFormat
00139 );
00140
00145 virtual const PString & GetColourFormat() const;
00146
00149 void SetResizeMode(
00150 ResizeMode mode
00151 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
00152
00155 ResizeMode GetResizeMode() const { return resizeMode; }
00156
00159 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); }
00160 static PINDEX CalculateFrameBytes(
00161 unsigned width,
00162 unsigned height,
00163 const PString & colourFormat
00164 );
00165
00179 bool Parse(
00180 const PString & str
00181 );
00182
00187 static bool ParseSize(
00188 const PString & str,
00189 unsigned & width,
00190 unsigned & height
00191 );
00192
00195 static PString AsString(
00196 unsigned width,
00197 unsigned height
00198 );
00199
00200 protected:
00201 unsigned frameWidth;
00202 unsigned frameHeight;
00203 unsigned frameRate;
00204 PString colourFormat;
00205 ResizeMode resizeMode;
00206 };
00207
00208
00209 class PVideoControlInfo : public PObject
00210 {
00211 PCLASSINFO(PVideoControlInfo, PObject);
00212
00213 public:
00214
00215 typedef enum {
00216 ControlPan,
00217 ControlTilt,
00218 ControlZoom
00219 } InputControlType;
00220
00221 static PString AsString(const InputControlType & type);
00222
00223 InputControlType type;
00224 long min;
00225 long max;
00226 long step;
00227 long def;
00228 long flags;
00229 long current;
00230 };
00231
00232
00236 class PVideoInputControl : public PVideoControlInfo
00237 {
00238 PCLASSINFO(PVideoInputControl, PVideoControlInfo);
00239
00240 public:
00241 ~PVideoInputControl();
00242
00243 virtual PBoolean Pan(long value, bool absolute = false );
00244 virtual PBoolean Tilt(long value, bool absolute = false);
00245 virtual PBoolean Zoom(long value, bool absolute = false);
00246
00247 long GetPan();
00248 long GetTilt();
00249 long GetZoom();
00250
00251 void Reset();
00252 void SetCurrentPosition(const InputControlType ctype, long current);
00253
00254 typedef std::list<PVideoControlInfo> InputDeviceControls;
00255
00256 protected:
00257 PBoolean GetVideoControlInfo(const InputControlType ctype, PVideoControlInfo & control);
00258 PBoolean GetDefaultPosition(const InputControlType ctype, long & def);
00259 PBoolean GetCurrentPosition(const InputControlType ctype, long & current);
00260
00261 std::list<PVideoControlInfo> m_info;
00262 PMutex ccmutex;
00263
00264 };
00265
00268 class PVideoInteractionInfo : public PObject
00269 {
00270 PCLASSINFO(PVideoInteractionInfo, PObject);
00271
00272 public:
00273
00274 typedef enum {
00275 InteractKey,
00276 InteractMouse,
00277 InteractNavigate,
00278 InteractRTSP,
00279 InteractOther
00280 } InputInteractType;
00281
00282 static PString AsString(const InputInteractType & type);
00283
00284 InputInteractType type;
00285 };
00286
00287
00316 class PVideoDevice : public PVideoFrameInfo
00317 {
00318 PCLASSINFO(PVideoDevice, PVideoFrameInfo);
00319
00320 protected:
00323 PVideoDevice();
00324
00325
00326 public:
00329 virtual ~PVideoDevice();
00330
00331 enum VideoFormat {
00332 PAL,
00333 NTSC,
00334 SECAM,
00335 Auto,
00336 NumVideoFormats
00337 };
00338
00341 const PString & GetDeviceName() const
00342 { return deviceName; }
00343
00346 virtual PStringArray GetDeviceNames() const = 0;
00347
00348 struct OpenArgs {
00349 OpenArgs();
00350
00351 PPluginManager * pluginMgr;
00352 PString driverName;
00353 PString deviceName;
00354 VideoFormat videoFormat;
00355 int channelNumber;
00356 PString colourFormat;
00357 bool convertFormat;
00358 unsigned rate;
00359 unsigned width;
00360 unsigned height;
00361 bool convertSize;
00362 ResizeMode resizeMode;
00363 bool flip;
00364 int brightness;
00365 int whiteness;
00366 int contrast;
00367 int colour;
00368 int hue;
00369 };
00370
00373 virtual PBoolean OpenFull(
00374 const OpenArgs & args,
00375 PBoolean startImmediate = true
00376 );
00377
00380 virtual PBoolean Open(
00381 const PString & deviceName,
00382 PBoolean startImmediate = true
00383 ) = 0;
00384
00387 virtual PBoolean IsOpen() = 0;
00388
00391 virtual PBoolean Close() = 0;
00392
00395 virtual PBoolean Start() = 0;
00396
00399 virtual PBoolean Stop() = 0;
00400
00401
00402 #if PTRACING
00403 friend ostream & operator<<(ostream &, VideoFormat);
00404 #endif
00405
00411 virtual PBoolean SetVideoFormat(
00412 VideoFormat videoFormat
00413 );
00414
00419 virtual VideoFormat GetVideoFormat() const;
00420
00425 virtual int GetNumChannels();
00426
00434 virtual PBoolean SetChannel(
00435 int channelNumber
00436 );
00437
00442 virtual int GetChannel() const;
00443
00450 virtual PBoolean SetColourFormatConverter(
00451 const PString & colourFormat
00452 );
00453
00457 virtual PBoolean GetVFlipState();
00458
00462 virtual PBoolean SetVFlipState(
00463 PBoolean newVFlipState
00464 );
00465
00471 virtual PBoolean GetFrameSizeLimits(
00472 unsigned & minWidth,
00473 unsigned & minHeight,
00474 unsigned & maxWidth,
00475 unsigned & maxHeight
00476 ) ;
00477
00478
00484 virtual PBoolean SetFrameSizeConverter(
00485 unsigned width,
00486 unsigned height,
00487 ResizeMode resizeMode = eMaxResizeMode
00488 );
00489
00495 virtual PBoolean SetFrameSizeConverter(
00496 unsigned width,
00497 unsigned height,
00498 PBoolean
00499 ) { return SetFrameSizeConverter(width,height,eScale); }
00500
00501
00510 virtual PBoolean SetFrameSize(
00511 unsigned width,
00512 unsigned height
00513 );
00514
00520 virtual PBoolean GetFrameSize(
00521 unsigned & width,
00522 unsigned & height
00523 ) const;
00524
00530 virtual PINDEX GetMaxFrameBytes() = 0;
00531
00532
00535 int GetLastError() const { return lastError; }
00536
00537
00540 virtual PBoolean CanCaptureVideo() const = 0;
00541
00544 virtual int GetBrightness();
00545
00548 virtual PBoolean SetBrightness(unsigned newBrightness);
00549
00550
00553 virtual int GetWhiteness();
00554
00557 virtual PBoolean SetWhiteness(unsigned newWhiteness);
00558
00559
00562 virtual int GetColour();
00563
00566 virtual PBoolean SetColour(unsigned newColour);
00567
00568
00571 virtual int GetContrast();
00572
00575 virtual PBoolean SetContrast(unsigned newContrast);
00576
00577
00580 virtual int GetHue();
00581
00584 virtual PBoolean SetHue(unsigned newHue);
00585
00586
00589 virtual PBoolean GetParameters(
00590 int *whiteness,
00591 int *brightness,
00592 int *colour,
00593 int *contrast,
00594 int *hue
00595 );
00596
00597
00600 virtual PBoolean SetVideoChannelFormat (
00601 int channelNumber,
00602 VideoFormat videoFormat
00603 );
00604
00605
00609 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00610
00614 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00615
00616 protected:
00617 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00618
00619 PString deviceName;
00620 int lastError;
00621 VideoFormat videoFormat;
00622 int channelNumber;
00623
00624 PString preferredColourFormat;
00625 PBoolean nativeVerticalFlip;
00626
00627 PColourConverter * converter;
00628 PBYTEArray frameStore;
00629
00630 int frameBrightness;
00631 int frameWhiteness;
00632 int frameContrast;
00633 int frameColour;
00634 int frameHue;
00635 };
00636
00637
00640 class PVideoOutputDevice : public PVideoDevice
00641 {
00642 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00643
00644 public:
00647 PVideoOutputDevice();
00648
00651 virtual ~PVideoOutputDevice() { Close(); };
00652
00655 static PStringArray GetDriverNames(
00656 PPluginManager * pluginMgr = NULL
00657 );
00658
00665 static PStringArray GetDriversDeviceNames(
00666 const PString & driverName,
00667 PPluginManager * pluginMgr = NULL
00668 );
00669
00672 static PVideoOutputDevice * CreateDevice(
00673 const PString & driverName,
00674 PPluginManager * pluginMgr = NULL
00675 );
00676
00677
00678
00679
00680
00681 static PVideoOutputDevice *CreateDeviceByName(
00682 const PString & deviceName,
00683 const PString & driverName = PString::Empty(),
00684 PPluginManager * pluginMgr = NULL
00685 );
00686
00692 static PVideoOutputDevice *CreateOpenedDevice(
00693 const PString & driverName,
00694 const PString & deviceName,
00695 PBoolean startImmediate = true,
00696 PPluginManager * pluginMgr = NULL
00697 );
00698
00701 static PVideoOutputDevice *CreateOpenedDevice(
00702 const OpenArgs & args,
00703 PBoolean startImmediate = true
00704 );
00705
00708 virtual PBoolean Close() { return true; }
00709
00712 virtual PBoolean Start() { return true; }
00713
00716 virtual PBoolean Stop() { return true; }
00717
00720 virtual PBoolean CanCaptureVideo() const;
00721
00724 virtual PBoolean SetFrameData(
00725 unsigned x,
00726 unsigned y,
00727 unsigned width,
00728 unsigned height,
00729 const BYTE * data,
00730 PBoolean endFrame = true
00731 ) = 0;
00732 virtual PBoolean SetFrameData(
00733 unsigned x,
00734 unsigned y,
00735 unsigned width,
00736 unsigned height,
00737 const BYTE * data,
00738 PBoolean endFrame,
00739 unsigned flags
00740 );
00741
00748 virtual PBoolean GetPosition(
00749 int & x,
00750 int & y
00751 ) const;
00752
00759 virtual bool SetPosition(
00760 int x,
00761 int y
00762 );
00763 };
00764
00765
00768 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00769 {
00770 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00771
00772 public:
00775 PVideoOutputDeviceRGB();
00776
00787 virtual PBoolean SetColourFormat(
00788 const PString & colourFormat
00789 );
00790
00799 virtual PBoolean SetFrameSize(
00800 unsigned width,
00801 unsigned height
00802 );
00803
00809 virtual PINDEX GetMaxFrameBytes();
00810
00813 virtual PBoolean SetFrameData(
00814 unsigned x,
00815 unsigned y,
00816 unsigned width,
00817 unsigned height,
00818 const BYTE * data,
00819 PBoolean endFrame = true
00820 );
00821
00824 virtual PBoolean FrameComplete() = 0;
00825
00826 protected:
00827 PMutex mutex;
00828 PINDEX bytesPerPixel;
00829 PINDEX scanLineWidth;
00830 bool swappedRedAndBlue;
00831 };
00832
00833
00834 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00835
00838 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00839 {
00840 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00841
00842 public:
00845 PVideoOutputDevicePPM();
00846
00849 virtual PBoolean Open(
00850 const PString & deviceName,
00851 PBoolean startImmediate = true
00852 );
00853
00856 virtual PBoolean IsOpen();
00857
00860 virtual PBoolean Close();
00861
00864 virtual PStringArray GetDeviceNames() const;
00865
00868 virtual PBoolean EndFrame();
00869
00870 protected:
00871 unsigned frameNumber;
00872 };
00873
00874 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00875
00876
00879 class PVideoInputDevice : public PVideoDevice
00880 {
00881 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00882
00883 public:
00886
00887
00890 ~PVideoInputDevice() { Close(); }
00891
00894 static PStringArray GetDriverNames(
00895 PPluginManager * pluginMgr = NULL
00896 );
00897
00904 static PStringArray GetDriversDeviceNames(
00905 const PString & driverName,
00906 PPluginManager * pluginMgr = NULL
00907 );
00908
00911 static PVideoInputDevice *CreateDevice(
00912 const PString & driverName,
00913 PPluginManager * pluginMgr = NULL
00914 );
00915
00916
00917
00918
00919
00920
00921
00922
00923 static PVideoInputDevice *CreateDeviceByName(
00924 const PString & deviceName,
00925 const PString & driverName = PString::Empty(),
00926 PPluginManager * pluginMgr = NULL
00927 );
00928
00934 static PVideoInputDevice *CreateOpenedDevice(
00935 const PString & driverName,
00936 const PString & deviceName,
00937 PBoolean startImmediate = true,
00938 PPluginManager * pluginMgr = NULL
00939 );
00940
00943 static PVideoInputDevice *CreateOpenedDevice(
00944 const OpenArgs & args,
00945 PBoolean startImmediate = true
00946 );
00947
00948 typedef struct {
00949 std::list<PVideoFrameInfo> framesizes;
00950 std::list<PVideoControlInfo> controls;
00951 std::list<PVideoInteractionInfo> interactions;
00952 } Capabilities;
00953
00956 virtual bool GetDeviceCapabilities(
00957 Capabilities * capabilities
00958 ) const { return GetDeviceCapabilities(GetDeviceName(), capabilities); }
00959
00962 static PBoolean GetDeviceCapabilities(
00963 const PString & deviceName,
00964 Capabilities * capabilities,
00965 PPluginManager * pluginMgr = NULL
00966 );
00967
00970 static PBoolean GetDeviceCapabilities(
00971 const PString & deviceName,
00972 const PString & driverName,
00973 Capabilities * caps,
00974 PPluginManager * pluginMgr = NULL
00975 );
00976
00979 virtual PBoolean Open(
00980 const PString & deviceName,
00981 PBoolean startImmediate = true
00982 ) = 0;
00983
00984 virtual PBoolean Close(
00985 ) { return true; }
00986
00989 virtual PBoolean CanCaptureVideo() const;
00990
00993 virtual PBoolean IsCapturing() = 0;
00994
00997 virtual PBoolean GetFrame(
00998 PBYTEArray & frame
00999 );
01000
01003 virtual PBoolean GetFrameData(
01004 BYTE * buffer,
01005 PINDEX * bytesReturned,
01006 unsigned int & flags
01007 );
01008 virtual PBoolean GetFrameData(
01009 BYTE * buffer,
01010 PINDEX * bytesReturned = NULL
01011 ) = 0;
01012
01015 virtual PBoolean GetFrameDataNoDelay(
01016 BYTE * buffer,
01017 PINDEX * bytesReturned,
01018 unsigned int & flags
01019 );
01020 virtual PBoolean GetFrameDataNoDelay(
01021 BYTE * buffer,
01022 PINDEX * bytesReturned = NULL
01023 ) = 0;
01024
01027 virtual PBoolean TestAllFormats() = 0;
01028 };
01029
01030
01032
01033
01034
01035
01036 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01037 {
01038 public:
01039 virtual PObject * CreateInstance(int ) const { return new className; }
01040 virtual PStringArray GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
01041 virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const
01042 { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); }
01043 };
01044
01045 #define PCREATE_VIDINPUT_PLUGIN(name) \
01046 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
01047 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
01048
01049 PPLUGIN_STATIC_LOAD(FakeVideo, PVideoInputDevice);
01050
01051 #ifdef P_APPSHARE
01052 PPLUGIN_STATIC_LOAD(Application, PVideoInputDevice);
01053 #endif
01054
01055 #if P_FFVDEV
01056 PPLUGIN_STATIC_LOAD(FFMPEG, PVideoInputDevice);
01057 #endif
01058
01059 #if P_VIDFILE
01060 PPLUGIN_STATIC_LOAD(YUVFile, PVideoInputDevice);
01061 #endif
01062
01063 #ifdef P_DIRECTSHOW
01064 PPLUGIN_STATIC_LOAD(DirectShow, PVideoInputDevice);
01065 #endif
01066
01067 #ifdef P_DIRECTSHOW2
01068 PPLUGIN_STATIC_LOAD(DirectShow2, PVideoInputDevice);
01069 #endif
01070
01072
01073
01074
01075
01076 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01077 {
01078 public:
01079 virtual PObject * CreateInstance(int ) const { return new className; }
01080 virtual PStringArray GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
01081 };
01082
01083 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
01084 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
01085 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
01086
01087 #if _WIN32
01088 PPLUGIN_STATIC_LOAD(Window, PVideoOutputDevice);
01089 #endif
01090
01091 #if P_SDL
01092 PPLUGIN_STATIC_LOAD(SDL, PVideoOutputDevice);
01093 #endif
01094
01095
01097
01098
01099
01100
01101 class PVideoFont : public PObject
01102 {
01103 PCLASSINFO(PVideoFont, PObject);
01104 public:
01105 enum {
01106 MAX_L_HEIGHT = 11
01107 };
01108 struct LetterData {
01109 char ascii;
01110 const char *line[MAX_L_HEIGHT];
01111 };
01112
01113 static const LetterData * GetLetterData(char ascii);
01114 };
01115
01116 #endif // P_VIDEO
01117
01118 #endif // PTLIB_PVIDEOIO_H
01119
01120