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 i480Width = 640, i480Height = 480,
00070 p720Width = 960, p720Height = 720,
00071 i1080Width = 1920, i1080Height = 1080,
00072 HDTVWidth = 1920, HDTVHeight = 1080,
00073 MaxWidth = 1920, MaxHeight = 1152
00074 };
00075
00077 PVideoFrameInfo();
00078 PVideoFrameInfo(
00079 unsigned frameWidth,
00080 unsigned frameHeight,
00081 const PString & colourFormat = "YUV420P",
00082 unsigned frameRate = 15,
00083 ResizeMode resizeMode = eScale
00084 );
00085
00092 virtual void PrintOn(
00093 ostream & strm
00094 ) const;
00095
00101 virtual PBoolean SetFrameSize(
00102 unsigned width,
00103 unsigned height
00104 );
00105
00111 virtual PBoolean GetFrameSize(
00112 unsigned & width,
00113 unsigned & height
00114 ) const;
00115
00120 virtual unsigned GetFrameWidth() const;
00121
00126 virtual unsigned GetFrameHeight() const;
00127
00133 virtual PBoolean SetFrameSar(unsigned width, unsigned height);
00134
00140 virtual PBoolean GetSarSize(
00141 unsigned & width,
00142 unsigned & height
00143 ) const;
00144
00149 virtual unsigned GetSarWidth() const;
00150
00155 virtual unsigned GetSarHeight() const;
00156
00162 virtual PBoolean SetFrameRate(
00163 unsigned rate
00164 );
00165
00170 virtual unsigned GetFrameRate() const;
00171
00177 virtual PBoolean SetColourFormat(
00178 const PString & colourFormat
00179 );
00180
00185 virtual const PString & GetColourFormat() const;
00186
00189 void SetResizeMode(
00190 ResizeMode mode
00191 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; }
00192
00195 ResizeMode GetResizeMode() const { return resizeMode; }
00196
00199 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); }
00200 static PINDEX CalculateFrameBytes(
00201 unsigned width,
00202 unsigned height,
00203 const PString & colourFormat
00204 );
00205
00219 bool Parse(
00220 const PString & str
00221 );
00222
00227 static bool ParseSize(
00228 const PString & str,
00229 unsigned & width,
00230 unsigned & height
00231 );
00232
00235 static PString AsString(
00236 unsigned width,
00237 unsigned height
00238 );
00239
00240 protected:
00241 unsigned frameWidth;
00242 unsigned frameHeight;
00243 unsigned sarWidth;
00244 unsigned sarHeight;
00245 unsigned frameRate;
00246 PString colourFormat;
00247 ResizeMode resizeMode;
00248 };
00249
00250
00251 class PVideoControlInfo : public PObject
00252 {
00253 PCLASSINFO(PVideoControlInfo, PObject);
00254
00255 public:
00256
00257 typedef enum {
00258 ControlPan,
00259 ControlTilt,
00260 ControlZoom
00261 } InputControlType;
00262
00263 static PString AsString(const InputControlType & type);
00264
00265 InputControlType type;
00266 long min;
00267 long max;
00268 long step;
00269 long def;
00270 long flags;
00271 long current;
00272 };
00273
00274
00278 class PVideoInputControl : public PVideoControlInfo
00279 {
00280 PCLASSINFO(PVideoInputControl, PVideoControlInfo);
00281
00282 public:
00283 ~PVideoInputControl();
00284
00285 virtual PBoolean Pan(long value, bool absolute = false );
00286 virtual PBoolean Tilt(long value, bool absolute = false);
00287 virtual PBoolean Zoom(long value, bool absolute = false);
00288
00289 long GetPan();
00290 long GetTilt();
00291 long GetZoom();
00292
00293 void Reset();
00294 void SetCurrentPosition(const InputControlType ctype, long current);
00295
00296 typedef std::list<PVideoControlInfo> InputDeviceControls;
00297
00298 protected:
00299 PBoolean GetVideoControlInfo(const InputControlType ctype, PVideoControlInfo & control);
00300 PBoolean GetDefaultPosition(const InputControlType ctype, long & def);
00301 PBoolean GetCurrentPosition(const InputControlType ctype, long & current);
00302
00303 std::list<PVideoControlInfo> m_info;
00304 PMutex ccmutex;
00305
00306 };
00307
00310 class PVideoInteractionInfo : public PObject
00311 {
00312 PCLASSINFO(PVideoInteractionInfo, PObject);
00313
00314 public:
00315
00316 typedef enum {
00317 InteractKey,
00318 InteractMouse,
00319 InteractNavigate,
00320 InteractRTSP,
00321 InteractOther
00322 } InputInteractType;
00323
00324 static PString AsString(const InputInteractType & type);
00325
00326 InputInteractType type;
00327 };
00328
00329
00358 class PVideoDevice : public PVideoFrameInfo
00359 {
00360 PCLASSINFO(PVideoDevice, PVideoFrameInfo);
00361
00362 protected:
00365 PVideoDevice();
00366
00367
00368 public:
00371 virtual ~PVideoDevice();
00372
00373 enum VideoFormat {
00374 PAL,
00375 NTSC,
00376 SECAM,
00377 Auto,
00378 NumVideoFormats
00379 };
00380
00383 const PString & GetDeviceName() const
00384 { return deviceName; }
00385
00388 virtual PStringArray GetDeviceNames() const = 0;
00389
00390 struct OpenArgs {
00391 OpenArgs();
00392
00393 PPluginManager * pluginMgr;
00394 PString driverName;
00395 PString deviceName;
00396 VideoFormat videoFormat;
00397 int channelNumber;
00398 PString colourFormat;
00399 bool convertFormat;
00400 unsigned rate;
00401 unsigned width;
00402 unsigned height;
00403 bool convertSize;
00404 ResizeMode resizeMode;
00405 bool flip;
00406 int brightness;
00407 int whiteness;
00408 int contrast;
00409 int colour;
00410 int hue;
00411 };
00412
00415 virtual PBoolean OpenFull(
00416 const OpenArgs & args,
00417 PBoolean startImmediate = true
00418 );
00419
00422 virtual PBoolean Open(
00423 const PString & deviceName,
00424 PBoolean startImmediate = true
00425 ) = 0;
00426
00429 virtual PBoolean IsOpen() = 0;
00430
00433 virtual PBoolean Close() = 0;
00434
00437 virtual PBoolean Start() = 0;
00438
00441 virtual PBoolean Stop() = 0;
00442
00443
00444 #if PTRACING
00445 friend ostream & operator<<(ostream &, VideoFormat);
00446 #endif
00447
00453 virtual PBoolean SetVideoFormat(
00454 VideoFormat videoFormat
00455 );
00456
00461 virtual VideoFormat GetVideoFormat() const;
00462
00467 virtual int GetNumChannels();
00468
00476 virtual PBoolean SetChannel(
00477 int channelNumber
00478 );
00479
00484 virtual int GetChannel() const;
00485
00492 virtual PBoolean SetColourFormatConverter(
00493 const PString & colourFormat
00494 );
00495
00499 virtual PBoolean GetVFlipState();
00500
00504 virtual PBoolean SetVFlipState(
00505 PBoolean newVFlipState
00506 );
00507
00513 virtual PBoolean GetFrameSizeLimits(
00514 unsigned & minWidth,
00515 unsigned & minHeight,
00516 unsigned & maxWidth,
00517 unsigned & maxHeight
00518 ) ;
00519
00520
00526 virtual PBoolean SetFrameSizeConverter(
00527 unsigned width,
00528 unsigned height,
00529 ResizeMode resizeMode = eMaxResizeMode
00530 );
00531
00537 virtual PBoolean SetFrameSizeConverter(
00538 unsigned width,
00539 unsigned height,
00540 PBoolean
00541 ) { return SetFrameSizeConverter(width,height,eScale); }
00542
00543
00552 virtual PBoolean SetFrameSize(
00553 unsigned width,
00554 unsigned height
00555 );
00556
00562 virtual PBoolean GetFrameSize(
00563 unsigned & width,
00564 unsigned & height
00565 ) const;
00566
00572 virtual PINDEX GetMaxFrameBytes() = 0;
00573
00574
00577 int GetLastError() const { return lastError; }
00578
00579
00582 virtual PBoolean CanCaptureVideo() const = 0;
00583
00586 virtual int GetBrightness();
00587
00590 virtual PBoolean SetBrightness(unsigned newBrightness);
00591
00592
00595 virtual int GetWhiteness();
00596
00599 virtual PBoolean SetWhiteness(unsigned newWhiteness);
00600
00601
00604 virtual int GetColour();
00605
00608 virtual PBoolean SetColour(unsigned newColour);
00609
00610
00613 virtual int GetContrast();
00614
00617 virtual PBoolean SetContrast(unsigned newContrast);
00618
00619
00622 virtual int GetHue();
00623
00626 virtual PBoolean SetHue(unsigned newHue);
00627
00628
00631 virtual PBoolean GetParameters(
00632 int *whiteness,
00633 int *brightness,
00634 int *colour,
00635 int *contrast,
00636 int *hue
00637 );
00638
00639
00642 virtual PBoolean SetVideoChannelFormat (
00643 int channelNumber,
00644 VideoFormat videoFormat
00645 );
00646
00647
00651 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; }
00652
00656 const PString & GetPreferredColourFormat() { return preferredColourFormat; }
00657
00658 protected:
00659 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const;
00660
00661 PString deviceName;
00662 int lastError;
00663 VideoFormat videoFormat;
00664 int channelNumber;
00665
00666 PString preferredColourFormat;
00667 PBoolean nativeVerticalFlip;
00668
00669 PColourConverter * converter;
00670 PBYTEArray frameStore;
00671
00672 int frameBrightness;
00673 int frameWhiteness;
00674 int frameContrast;
00675 int frameColour;
00676 int frameHue;
00677 };
00678
00679
00682 class PVideoOutputDevice : public PVideoDevice
00683 {
00684 PCLASSINFO(PVideoOutputDevice, PVideoDevice);
00685
00686 public:
00689 PVideoOutputDevice();
00690
00693 virtual ~PVideoOutputDevice() { Close(); };
00694
00697 static PStringArray GetDriverNames(
00698 PPluginManager * pluginMgr = NULL
00699 );
00700
00707 static PStringArray GetDriversDeviceNames(
00708 const PString & driverName,
00709 PPluginManager * pluginMgr = NULL
00710 );
00711
00714 static PVideoOutputDevice * CreateDevice(
00715 const PString & driverName,
00716 PPluginManager * pluginMgr = NULL
00717 );
00718
00719
00720
00721
00722
00723 static PVideoOutputDevice *CreateDeviceByName(
00724 const PString & deviceName,
00725 const PString & driverName = PString::Empty(),
00726 PPluginManager * pluginMgr = NULL
00727 );
00728
00734 static PVideoOutputDevice *CreateOpenedDevice(
00735 const PString & driverName,
00736 const PString & deviceName,
00737 PBoolean startImmediate = true,
00738 PPluginManager * pluginMgr = NULL
00739 );
00740
00743 static PVideoOutputDevice *CreateOpenedDevice(
00744 const OpenArgs & args,
00745 PBoolean startImmediate = true
00746 );
00747
00750 virtual PBoolean Close() { return true; }
00751
00754 virtual PBoolean Start() { return true; }
00755
00758 virtual PBoolean Stop() { return true; }
00759
00762 virtual PBoolean CanCaptureVideo() const;
00763
00766 virtual PBoolean SetFrameData(
00767 unsigned x,
00768 unsigned y,
00769 unsigned width,
00770 unsigned height,
00771 const BYTE * data,
00772 PBoolean endFrame = true
00773 ) = 0;
00774 virtual PBoolean SetFrameData(
00775 unsigned x,
00776 unsigned y,
00777 unsigned width,
00778 unsigned height,
00779 const BYTE * data,
00780 PBoolean endFrame,
00781 unsigned flags
00782 );
00783 virtual PBoolean SetFrameData(
00784 unsigned x,
00785 unsigned y,
00786 unsigned width,
00787 unsigned height,
00788 unsigned sarwidth,
00789 unsigned sarheight,
00790 const BYTE * data,
00791 PBoolean endFrame,
00792 unsigned flags,
00793 const void * mark
00794 );
00795
00802 virtual PBoolean DisableDecode();
00803
00810 virtual PBoolean GetPosition(
00811 int & x,
00812 int & y
00813 ) const;
00814
00821 virtual bool SetPosition(
00822 int x,
00823 int y
00824 );
00825 };
00826
00827
00830 class PVideoOutputDeviceRGB : public PVideoOutputDevice
00831 {
00832 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice);
00833
00834 public:
00837 PVideoOutputDeviceRGB();
00838
00849 virtual PBoolean SetColourFormat(
00850 const PString & colourFormat
00851 );
00852
00861 virtual PBoolean SetFrameSize(
00862 unsigned width,
00863 unsigned height
00864 );
00865
00871 virtual PINDEX GetMaxFrameBytes();
00872
00875 virtual PBoolean SetFrameData(
00876 unsigned x,
00877 unsigned y,
00878 unsigned width,
00879 unsigned height,
00880 const BYTE * data,
00881 PBoolean endFrame = true
00882 );
00883
00886 virtual PBoolean FrameComplete() = 0;
00887
00888 protected:
00889 PMutex mutex;
00890 PINDEX bytesPerPixel;
00891 PINDEX scanLineWidth;
00892 bool swappedRedAndBlue;
00893 };
00894
00895
00896 #ifdef SHOULD_BE_MOVED_TO_PLUGIN
00897
00900 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB
00901 {
00902 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB);
00903
00904 public:
00907 PVideoOutputDevicePPM();
00908
00911 virtual PBoolean Open(
00912 const PString & deviceName,
00913 PBoolean startImmediate = true
00914 );
00915
00918 virtual PBoolean IsOpen();
00919
00922 virtual PBoolean Close();
00923
00926 virtual PStringArray GetDeviceNames() const;
00927
00930 virtual PBoolean EndFrame();
00931
00932 protected:
00933 unsigned frameNumber;
00934 };
00935
00936 #endif // SHOULD_BE_MOVED_TO_PLUGIN
00937
00938
00941 class PVideoInputDevice : public PVideoDevice
00942 {
00943 PCLASSINFO(PVideoInputDevice, PVideoDevice);
00944
00945 public:
00948
00949
00952 ~PVideoInputDevice() { Close(); }
00953
00956 static PStringArray GetDriverNames(
00957 PPluginManager * pluginMgr = NULL
00958 );
00959
00966 static PStringArray GetDriversDeviceNames(
00967 const PString & driverName,
00968 PPluginManager * pluginMgr = NULL
00969 );
00970
00973 static PVideoInputDevice *CreateDevice(
00974 const PString & driverName,
00975 PPluginManager * pluginMgr = NULL
00976 );
00977
00978
00979
00980
00981
00982
00983
00984
00985 static PVideoInputDevice *CreateDeviceByName(
00986 const PString & deviceName,
00987 const PString & driverName = PString::Empty(),
00988 PPluginManager * pluginMgr = NULL
00989 );
00990
00996 static PVideoInputDevice *CreateOpenedDevice(
00997 const PString & driverName,
00998 const PString & deviceName,
00999 PBoolean startImmediate = true,
01000 PPluginManager * pluginMgr = NULL
01001 );
01002
01005 static PVideoInputDevice *CreateOpenedDevice(
01006 const OpenArgs & args,
01007 PBoolean startImmediate = true
01008 );
01009
01010 typedef struct {
01011 std::list<PVideoFrameInfo> framesizes;
01012 std::list<PVideoControlInfo> controls;
01013 std::list<PVideoInteractionInfo> interactions;
01014 } Capabilities;
01015
01018 virtual bool GetDeviceCapabilities(
01019 Capabilities * capabilities
01020 ) const { return GetDeviceCapabilities(GetDeviceName(), capabilities); }
01021
01024 static PBoolean GetDeviceCapabilities(
01025 const PString & deviceName,
01026 Capabilities * capabilities,
01027 PPluginManager * pluginMgr = NULL
01028 );
01029
01032 static PBoolean GetDeviceCapabilities(
01033 const PString & deviceName,
01034 const PString & driverName,
01035 Capabilities * caps,
01036 PPluginManager * pluginMgr = NULL
01037 );
01038
01042 virtual PVideoInputControl * GetVideoInputControls();
01043
01046 virtual PBoolean Open(
01047 const PString & deviceName,
01048 PBoolean startImmediate = true
01049 ) = 0;
01050
01051 virtual PBoolean Close(
01052 ) { return true; }
01053
01056 virtual PBoolean CanCaptureVideo() const;
01057
01060 virtual PBoolean IsCapturing() = 0;
01061
01064 virtual PBoolean GetFrame(
01065 PBYTEArray & frame
01066 );
01067
01070 virtual PBoolean GetFrameData(
01071 BYTE * buffer,
01072 PINDEX * bytesReturned,
01073 unsigned int & flags
01074 );
01075 virtual PBoolean GetFrameData(
01076 BYTE * buffer,
01077 PINDEX * bytesReturned = NULL
01078 ) = 0;
01079
01082 virtual PBoolean GetFrameDataNoDelay(
01083 BYTE * buffer,
01084 PINDEX * bytesReturned,
01085 unsigned int & flags
01086 );
01087 virtual PBoolean GetFrameDataNoDelay(
01088 BYTE * buffer,
01089 PINDEX * bytesReturned = NULL
01090 ) = 0;
01091
01094 virtual bool FlowControl(const void * flowData);
01095
01108 virtual bool SetCaptureMode(unsigned mode);
01109
01113 virtual int GetCaptureMode() const;
01114 };
01115
01116
01118
01119
01120
01121
01122 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01123 {
01124 public:
01125 virtual PObject * CreateInstance(int ) const { return new className; }
01126 virtual PStringArray GetDeviceNames(int ) const { return className::GetInputDeviceNames(); }
01127 virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const
01128 { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); }
01129 };
01130
01131 #define PCREATE_VIDINPUT_PLUGIN(name) \
01132 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \
01133 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor)
01134
01135 PPLUGIN_STATIC_LOAD(FakeVideo, PVideoInputDevice);
01136
01137 #ifdef P_APPSHARE
01138 PPLUGIN_STATIC_LOAD(Application, PVideoInputDevice);
01139 #endif
01140
01141 #if P_FFVDEV
01142 PPLUGIN_STATIC_LOAD(FFMPEG, PVideoInputDevice);
01143 #endif
01144
01145 #if P_VIDFILE
01146 PPLUGIN_STATIC_LOAD(YUVFile, PVideoInputDevice);
01147 #endif
01148
01149 #ifdef P_DIRECTSHOW
01150 PPLUGIN_STATIC_LOAD(DirectShow, PVideoInputDevice);
01151 #endif
01152
01153
01155
01156
01157
01158
01159 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor
01160 {
01161 public:
01162 virtual PObject * CreateInstance(int ) const { return new className; }
01163 virtual PStringArray GetDeviceNames(int ) const { return className::GetOutputDeviceNames(); }
01164 };
01165
01166 #define PCREATE_VIDOUTPUT_PLUGIN(name) \
01167 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \
01168 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor)
01169
01170 #if _WIN32
01171 PPLUGIN_STATIC_LOAD(Window, PVideoOutputDevice);
01172 #endif
01173
01174 #if P_SDL
01175 PPLUGIN_STATIC_LOAD(SDL, PVideoOutputDevice);
01176 #endif
01177
01178
01180
01181
01182
01183
01184 class PVideoFont : public PObject
01185 {
01186 PCLASSINFO(PVideoFont, PObject);
01187 public:
01188 enum {
01189 MAX_L_HEIGHT = 11
01190 };
01191 struct LetterData {
01192 char ascii;
01193 const char *line[MAX_L_HEIGHT];
01194 };
01195
01196 static const LetterData * GetLetterData(char ascii);
01197 };
01198
01199 #endif // P_VIDEO
01200
01201 #endif // PTLIB_PVIDEOIO_H
01202
01203
01204