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 friend ostream & operator<<(ostream & strm, ResizeMode mode);
00062
00063 enum StandardSizes {
00064 SQCIFWidth = 128, SQCIFHeight = 96,
00065 QCIFWidth = 176, QCIFHeight = 144,
00066 CIFWidth = 352, CIFHeight = 288,
00067 CIF4Width = 704, CIF4Height = 576,
00068 CIF16Width = 1408, CIF16Height = 1152,
00069 HD480Width = 704, HD480Height = 480,
00070 i480Width = 704, i480Height = 480,
00071 HD720Width = 1280, HD720Height = 720,
00072 p720Width = 1280, p720Height = 720,
00073 HD1080Width= 1920, HD1080Height= 1080,
00074 i1080Width = 1920, i1080Height = 1080,
00075 HDTVWidth = 1920, HDTVHeight = 1080,
00076 MaxWidth = 1920, MaxHeight = 1200
00077 };
00078
00080 PVideoFrameInfo();
00081 PVideoFrameInfo(
00082 unsigned frameWidth,
00083 unsigned frameHeight,
00084 const PString & colourFormat = "YUV420P",
00085 unsigned frameRate = 15,
00086 ResizeMode resizeMode = eScale
00087 );
00088
00095 virtual void PrintOn(
00096 ostream & strm
00097 ) const;
00098
00104 virtual PBoolean SetFrameSize(
00105 unsigned width,
00106 unsigned height
00107 );
00108
00114 virtual PBoolean GetFrameSize(
00115 unsigned & width,
00116 unsigned & height
00117 ) const;
00118
00123 virtual unsigned GetFrameWidth() const;
00124
00129 virtual unsigned GetFrameHeight() const;
00130
00136 virtual PBoolean SetFrameSar(unsigned width, unsigned height);
00137
00143 virtual PBoolean GetSarSize(
00144 unsigned & width,
00145 unsigned & height
00146 ) const;
00147
00152 virtual unsigned GetSarWidth() const;
00153
00158 virtual unsigned GetSarHeight() const;
00159
00165 virtual PBoolean SetFrameRate(
00166 unsigned rate
00167 );
00168
00173 virtual unsigned GetFrameRate() const;
00174
00180 virtual PBoolean SetColourFormat(
00181 const PString & colourFormat
00182 );
00183
00188 virtual const PString & GetColourFormat() const;
00189
00192 void SetResizeMode(
00193 ResizeMode mode
00194 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
00195
00198 ResizeMode GetResizeMode() const { return resizeMode; }
00199
00202 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); }
00203 static PINDEX CalculateFrameBytes(
00204 unsigned width,
00205 unsigned height,
00206 const PString & colourFormat
00207 );
00208
00222 bool Parse(
00223 const PString & str
00224 );
00225
00230 static bool ParseSize(
00231 const PString & str,
00232 unsigned & width,
00233 unsigned & height
00234 );
00235
00238 static PString AsString(
00239 unsigned width,
00240 unsigned height
00241 );
00242
00247 static PStringArray GetSizeNames();
00248
00249 protected:
00250 unsigned frameWidth;
00251 unsigned frameHeight;
00252 unsigned sarWidth;
00253 unsigned sarHeight;
00254 unsigned frameRate;
00255 PString colourFormat;
00256 ResizeMode resizeMode;
00257 };
00258
00259
00260 class PVideoControlInfo : public PObject
00261 {
00262 PCLASSINFO(PVideoControlInfo, PObject);
00263
00264 public:
00265
00266 typedef enum {
00267 ControlPan,
00268 ControlTilt,
00269 ControlZoom
00270 } InputControlType;
00271
00272 static PString AsString(const InputControlType & type);
00273
00274 InputControlType type;
00275 long min;
00276 long max;
00277 long step;
00278 long def;
00279 long flags;
00280 long current;
00281 };
00282
00283
00287 class PVideoInputControl : public PVideoControlInfo
00288 {
00289 PCLASSINFO(PVideoInputControl, PVideoControlInfo);
00290
00291 public:
00292 ~PVideoInputControl();
00293
00294 virtual PBoolean Pan(long value, bool absolute = false );
00295 virtual PBoolean Tilt(long value, bool absolute = false);
00296 virtual PBoolean Zoom(long value, bool absolute = false);
00297
00298 long GetPan();
00299 long GetTilt();
00300 long GetZoom();
00301
00302 void Reset();
00303 void SetCurrentPosition(const InputControlType ctype, long current);
00304
00305 typedef std::list<PVideoControlInfo> InputDeviceControls;
00306
00307 protected:
00308 PBoolean GetVideoControlInfo(const InputControlType ctype, PVideoControlInfo & control);
00309 PBoolean GetDefaultPosition(const InputControlType ctype, long & def);
00310 PBoolean GetCurrentPosition(const InputControlType ctype, long & current);
00311
00312 std::list<PVideoControlInfo> m_info;
00313 PMutex ccmutex;
00314
00315 };
00316
00319 class PVideoInteractionInfo : public PObject
00320 {
00321 PCLASSINFO(PVideoInteractionInfo, PObject);
00322
00323 public:
00324
00325 typedef enum {
00326 InteractKey,
00327 InteractMouse,
00328 InteractNavigate,
00329 InteractRTSP,
00330 InteractOther
00331 } InputInteractType;
00332
00333 static PString AsString(const InputInteractType & type);
00334
00335 InputInteractType type;
00336 };
00337
00338
00367 class PVideoDevice : public PVideoFrameInfo
00368 {
00369 PCLASSINFO(PVideoDevice, PVideoFrameInfo);
00370
00371 protected:
00374 PVideoDevice();
00375
00376
00377 public:
00380 virtual ~PVideoDevice();
00381
00382 enum VideoFormat {
00383 PAL,
00384 NTSC,
00385 SECAM,
00386 Auto,
00387 NumVideoFormats
00388 };
00389
00392 const PString & GetDeviceName() const
00393 { return deviceName; }
00394
00397 virtual PStringArray GetDeviceNames() const = 0;
00398
00399 struct OpenArgs {
00400 OpenArgs();
00401
00402 PPluginManager * pluginMgr;
00403 PString driverName;
00404 PString deviceName;
00405 VideoFormat videoFormat;
00406 int channelNumber;
00407 PString colourFormat;
00408 bool convertFormat;
00409 unsigned rate;
00410 unsigned width;
00411 unsigned height;
00412 bool convertSize;
00413 ResizeMode resizeMode;
00414 bool flip;
00415 int brightness;
00416 int whiteness;
00417 int contrast;
00418 int colour;
00419 int hue;
00420 };
00421
00424 virtual PBoolean OpenFull(
00425 const OpenArgs & args,
00426 PBoolean startImmediate = true
00427 );
00428
00431 virtual PBoolean Open(
00432 const PString & deviceName,
00433 PBoolean startImmediate = true
00434 ) = 0;
00435
00438 virtual PBoolean IsOpen() = 0;
00439
00442 virtual PBoolean Close() = 0;
00443
00446 virtual PBoolean Start() = 0;
00447
00450 virtual PBoolean Stop() = 0;
00451
00452
00453 #if PTRACING
00454 friend ostream & operator<<(ostream &, VideoFormat);
00455 #endif
00456
00462 virtual PBoolean SetVideoFormat(
00463 VideoFormat videoFormat
00464 );
00465
00470 virtual VideoFormat GetVideoFormat() const;
00471
00476 virtual int GetNumChannels();
00477
00485 virtual PBoolean SetChannel(
00486 int channelNumber
00487 );
00488
00493 virtual int GetChannel() const;
00494
00501 virtual PBoolean SetColourFormatConverter(
00502 const PString & colourFormat
00503 );
00504
00508 virtual PBoolean GetVFlipState();
00509
00513 virtual PBoolean SetVFlipState(
00514 PBoolean newVFlipState
00515 );
00516
00522 virtual PBoolean GetFrameSizeLimits(
00523 unsigned & minWidth,
00524 unsigned & minHeight,
00525 unsigned & maxWidth,
00526 unsigned & maxHeight
00527 ) ;
00528
00529
00535 virtual PBoolean SetFrameSizeConverter(
00536 unsigned width,
00537 unsigned height,
00538 ResizeMode resizeMode = eMaxResizeMode
00539 );
00540
00546 virtual PBoolean SetFrameSizeConverter(
00547 unsigned width,
00548 unsigned height,
00549 PBoolean
00550 ) { return SetFrameSizeConverter(width,height,eScale); }
00551
00552
00560 virtual PBoolean SetNearestFrameSize(
00561 unsigned width,
00562 unsigned height
00563 );
00564
00573 virtual PBoolean SetFrameSize(
00574 unsigned width,
00575 unsigned height
00576 );
00577
00583 virtual PBoolean GetFrameSize(
00584 unsigned & width,
00585 unsigned & height
00586 ) const;
00587
00593 virtual PINDEX GetMaxFrameBytes() = 0;
00594
00595
00598 int GetLastError() const { return lastError; }
00599
00600
00603 virtual PBoolean CanCaptureVideo() const = 0;
00604
00607 virtual int GetBrightness();
00608
00611 virtual PBoolean SetBrightness(unsigned newBrightness);
00612
00613
00616 virtual int GetWhiteness();
00617
00620 virtual PBoolean SetWhiteness(unsigned newWhiteness);
00621
00622
00625 virtual int GetColour();
00626
00629 virtual PBoolean SetColour(unsigned newColour);
00630
00631
00634 virtual int GetContrast();
00635
00638 virtual PBoolean SetContrast(unsigned newContrast);
00639
00640
00643 virtual int GetHue();
00644
00647 virtual PBoolean SetHue(unsigned newHue);
00648
00649
00652 virtual PBoolean GetParameters(
00653 int *whiteness,
00654 int *brightness,
00655 int *colour,
00656 int *contrast,
00657 int *hue
00658 );
00659
00660
00663 virtual PBoolean SetVideoChannelFormat (
00664 int channelNumber,
00665 VideoFormat videoFormat
00666 );
00667
00668
00672 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00673
00677 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00678
00679 protected:
00680 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00681
00682 PString deviceName;
00683 int lastError;
00684 VideoFormat videoFormat;
00685 int channelNumber;
00686
00687 PString preferredColourFormat;
00688 PBoolean nativeVerticalFlip;
00689
00690 PColourConverter * converter;
00691 PBYTEArray frameStore;
00692
00693 int frameBrightness;
00694 int frameWhiteness;
00695 int frameContrast;
00696 int frameColour;
00697 int frameHue;
00698 };
00699
00700
00703 class PVideoOutputDevice : public PVideoDevice
00704 {
00705 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00706
00707 public:
00710 PVideoOutputDevice();
00711
00714 virtual ~PVideoOutputDevice() { Close(); };
00715
00718 static PStringArray GetDriverNames(
00719 PPluginManager * pluginMgr = NULL
00720 );
00721
00728 static PStringArray GetDriversDeviceNames(
00729 const PString & driverName,
00730 PPluginManager * pluginMgr = NULL
00731 );
00732
00735 static PVideoOutputDevice * CreateDevice(
00736 const PString & driverName,
00737 PPluginManager * pluginMgr = NULL
00738 );
00739
00740
00741
00742
00743
00744 static PVideoOutputDevice *CreateDeviceByName(
00745 const PString & deviceName,
00746 const PString & driverName = PString::Empty(),
00747 PPluginManager * pluginMgr = NULL
00748 );
00749
00755 static PVideoOutputDevice *CreateOpenedDevice(
00756 const PString & driverName,
00757 const PString & deviceName,
00758 PBoolean startImmediate = true,
00759 PPluginManager * pluginMgr = NULL
00760 );
00761
00764 static PVideoOutputDevice *CreateOpenedDevice(
00765 const OpenArgs & args,
00766 PBoolean startImmediate = true
00767 );
00768
00771 virtual PBoolean Close() { return true; }
00772
00775 virtual PBoolean Start() { return true; }
00776
00779 virtual PBoolean Stop() { return true; }
00780
00783 virtual PBoolean CanCaptureVideo() const;
00784
00787 virtual PBoolean SetFrameData(
00788 unsigned x,
00789 unsigned y,
00790 unsigned width,
00791 unsigned height,
00792 const BYTE * data,
00793 PBoolean endFrame = true
00794 ) = 0;
00795 virtual PBoolean SetFrameData(
00796 unsigned x,
00797 unsigned y,
00798 unsigned width,
00799 unsigned height,
00800 const BYTE * data,
00801 PBoolean endFrame,
00802 unsigned flags
00803 );
00804 virtual PBoolean SetFrameData(
00805 unsigned x,
00806 unsigned y,
00807 unsigned width,
00808 unsigned height,
00809 unsigned sarwidth,
00810 unsigned sarheight,
00811 const BYTE * data,
00812 PBoolean endFrame,
00813 unsigned flags,
00814 const void * mark
00815 );
00816
00823 virtual PBoolean DisableDecode();
00824
00831 virtual PBoolean GetPosition(
00832 int & x,
00833 int & y
00834 ) const;
00835
00842 virtual bool SetPosition(
00843 int x,
00844 int y
00845 );
00846 };
00847
00848
00851 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00852 {
00853 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00854
00855 public:
00858 PVideoOutputDeviceRGB();
00859
00870 virtual PBoolean SetColourFormat(
00871 const PString & colourFormat
00872 );
00873
00882 virtual PBoolean SetFrameSize(
00883 unsigned width,
00884 unsigned height
00885 );
00886
00892 virtual PINDEX GetMaxFrameBytes();
00893
00896 virtual PBoolean SetFrameData(
00897 unsigned x,
00898 unsigned y,
00899 unsigned width,
00900 unsigned height,
00901 const BYTE * data,
00902 PBoolean endFrame = true
00903 );
00904
00907 virtual PBoolean FrameComplete() = 0;
00908
00909 protected:
00910 PMutex mutex;
00911 PINDEX bytesPerPixel;
00912 PINDEX scanLineWidth;
00913 bool swappedRedAndBlue;
00914 };
00915
00916
00917 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00918
00921 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00922 {
00923 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00924
00925 public:
00928 PVideoOutputDevicePPM();
00929
00932 virtual PBoolean Open(
00933 const PString & deviceName,
00934 PBoolean startImmediate = true
00935 );
00936
00939 virtual PBoolean IsOpen();
00940
00943 virtual PBoolean Close();
00944
00947 virtual PStringArray GetDeviceNames() const;
00948
00951 virtual PBoolean EndFrame();
00952
00953 protected:
00954 unsigned frameNumber;
00955 };
00956
00957 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00958
00959
00962 class PVideoInputDevice : public PVideoDevice
00963 {
00964 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00965
00966 public:
00969
00970
00973 ~PVideoInputDevice() { Close(); }
00974
00977 static PStringArray GetDriverNames(
00978 PPluginManager * pluginMgr = NULL
00979 );
00980
00987 static PStringArray GetDriversDeviceNames(
00988 const PString & driverName,
00989 PPluginManager * pluginMgr = NULL
00990 );
00991
00994 static PVideoInputDevice *CreateDevice(
00995 const PString & driverName,
00996 PPluginManager * pluginMgr = NULL
00997 );
00998
00999
01000
01001
01002
01003
01004
01005
01006 static PVideoInputDevice *CreateDeviceByName(
01007 const PString & deviceName,
01008 const PString & driverName = PString::Empty(),
01009 PPluginManager * pluginMgr = NULL
01010 );
01011
01017 static PVideoInputDevice *CreateOpenedDevice(
01018 const PString & driverName,
01019 const PString & deviceName,
01020 PBoolean startImmediate = true,
01021 PPluginManager * pluginMgr = NULL
01022 );
01023
01026 static PVideoInputDevice *CreateOpenedDevice(
01027 const OpenArgs & args,
01028 PBoolean startImmediate = true
01029 );
01030
01031 typedef struct {
01032 std::list<PVideoFrameInfo> framesizes;
01033 std::list<PVideoControlInfo> controls;
01034 std::list<PVideoInteractionInfo> interactions;
01035 } Capabilities;
01036
01039 virtual bool GetDeviceCapabilities(
01040 Capabilities * capabilities
01041 ) const { return GetDeviceCapabilities(GetDeviceName(), capabilities); }
01042
01045 static PBoolean GetDeviceCapabilities(
01046 const PString & deviceName,
01047 Capabilities * capabilities,
01048 PPluginManager * pluginMgr = NULL
01049 );
01050
01053 static PBoolean GetDeviceCapabilities(
01054 const PString & deviceName,
01055 const PString & driverName,
01056 Capabilities * caps,
01057 PPluginManager * pluginMgr = NULL
01058 );
01059
01063 virtual PVideoInputControl * GetVideoInputControls();
01064
01067 virtual PBoolean Open(
01068 const PString & deviceName,
01069 PBoolean startImmediate = true
01070 ) = 0;
01071
01072 virtual PBoolean Close(
01073 ) { return true; }
01074
01077 virtual PBoolean CanCaptureVideo() const;
01078
01081 virtual PBoolean IsCapturing() = 0;
01082
01090 virtual PBoolean SetNearestFrameSize(
01091 unsigned width,
01092 unsigned height
01093 );
01094
01097 virtual PBoolean GetFrame(
01098 PBYTEArray & frame
01099 );
01100
01103 virtual PBoolean GetFrameData(
01104 BYTE * buffer,
01105 PINDEX * bytesReturned,
01106 unsigned int & flags
01107 );
01108 virtual PBoolean GetFrameData(
01109 BYTE * buffer,
01110 PINDEX * bytesReturned = NULL
01111 ) = 0;
01112
01115 virtual PBoolean GetFrameDataNoDelay(
01116 BYTE * buffer,
01117 PINDEX * bytesReturned,
01118 unsigned int & flags
01119 );
01120 virtual PBoolean GetFrameDataNoDelay(
01121 BYTE * buffer,
01122 PINDEX * bytesReturned = NULL
01123 ) = 0;
01124
01127 virtual bool FlowControl(const void * flowData);
01128
01141 virtual bool SetCaptureMode(unsigned mode);
01142
01146 virtual int GetCaptureMode() const;
01147 };
01148
01149
01151
01152
01153
01154
01155 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01156 {
01157 public:
01158 virtual PObject * CreateInstance(int ) const { return new className; }
01159 virtual PStringArray GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
01160 virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const
01161 { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); }
01162 };
01163
01164 #define PCREATE_VIDINPUT_PLUGIN(name) \
01165 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
01166 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
01167
01168 PPLUGIN_STATIC_LOAD(FakeVideo, PVideoInputDevice);
01169
01170 #ifdef P_APPSHARE
01171 PPLUGIN_STATIC_LOAD(Application, PVideoInputDevice);
01172 #endif
01173
01174 #if P_FFVDEV
01175 PPLUGIN_STATIC_LOAD(FFMPEG, PVideoInputDevice);
01176 #endif
01177
01178 #if P_VIDFILE
01179 PPLUGIN_STATIC_LOAD(YUVFile, PVideoInputDevice);
01180 #endif
01181
01182 #ifdef P_DIRECTSHOW
01183 PPLUGIN_STATIC_LOAD(DirectShow, PVideoInputDevice);
01184 #endif
01185
01186
01188
01189
01190
01191
01192 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01193 {
01194 public:
01195 virtual PObject * CreateInstance(int ) const { return new className; }
01196 virtual PStringArray GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
01197 };
01198
01199 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
01200 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
01201 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
01202
01203 #if _WIN32
01204 PPLUGIN_STATIC_LOAD(Window, PVideoOutputDevice);
01205 #endif
01206
01207 #if P_SDL
01208 PPLUGIN_STATIC_LOAD(SDL, PVideoOutputDevice);
01209 #endif
01210
01211
01213
01214
01215
01216
01217 class PVideoFont : public PObject
01218 {
01219 PCLASSINFO(PVideoFont, PObject);
01220 public:
01221 enum {
01222 MAX_L_HEIGHT = 11
01223 };
01224 struct LetterData {
01225 char ascii;
01226 const char *line[MAX_L_HEIGHT];
01227 };
01228
01229 static const LetterData * GetLetterData(char ascii);
01230 };
01231
01232 #endif // P_VIDEO
01233
01234 #endif // PTLIB_PVIDEOIO_H
01235
01236
01237