1 /* 2 * videoio.h 3 * 4 * Classes to support streaming video input (grabbing) and output. 5 * 6 * Portable Windows Library 7 * 8 * Copyright (c) 1993-2000 Equivalence Pty. Ltd. 9 * 10 * The contents of this file are subject to the Mozilla Public License 11 * Version 1.0 (the "License"); you may not use this file except in 12 * compliance with the License. You may obtain a copy of the License at 13 * http://www.mozilla.org/MPL/ 14 * 15 * Software distributed under the License is distributed on an "AS IS" 16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 17 * the License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * The Original Code is Portable Windows Library. 21 * 22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 23 * 24 * Contributor(s): Mark Cooke (mpc@star.sr.bham.ac.uk) 25 * 26 * $Revision: 29328 $ 27 * $Author: rjongbloed $ 28 * $Date: 2013-03-26 18:23:37 -0500 (Tue, 26 Mar 2013) $ 29 */ 30 31 32 #ifndef PTLIB_PVIDEOIO_H 33 #define PTLIB_PVIDEOIO_H 34 35 #ifdef P_USE_PRAGMA 36 #pragma interface 37 #endif 38 #include <ptbuildopts.h> 39 40 #if P_VIDEO 41 42 #include <ptlib/plugin.h> 43 #include <ptlib/pluginmgr.h> 44 #include <list> 45 46 class PColourConverter; 47 48 49 class PVideoFrameInfo : public PObject 50 { 51 PCLASSINFO(PVideoFrameInfo, PObject); 52 53 public: 54 enum ResizeMode 55 { 56 eScale, 57 eCropCentre, 58 eCropTopLeft, 59 eMaxResizeMode 60 }; 61 friend ostream & operator<<(ostream & strm, ResizeMode mode); 62 63 enum StandardSizes { 64 SQCIFWidth = 128, SQCIFHeight = 96, 65 QCIFWidth = 176, QCIFHeight = 144, 66 CIFWidth = 352, CIFHeight = 288, 67 CIF4Width = 704, CIF4Height = 576, 68 CIF16Width = 1408, CIF16Height = 1152, 69 HD480Width = 704, HD480Height = 480, 70 i480Width = 704, i480Height = 480, 71 HD720Width = 1280, HD720Height = 720, 72 p720Width = 1280, p720Height = 720, 73 HD1080Width= 1920, HD1080Height= 1080, 74 i1080Width = 1920, i1080Height = 1080, 75 HDTVWidth = 1920, HDTVHeight = 1080, 76 MaxWidth = 1920, MaxHeight = 1200 77 }; 78 79 /// Construct video frame information 80 PVideoFrameInfo(); 81 PVideoFrameInfo( 82 unsigned frameWidth, 83 unsigned frameHeight, 84 const PString & colourFormat = "YUV420P", 85 unsigned frameRate = 15, 86 ResizeMode resizeMode = eScale 87 ); 88 89 /** Compare the two PVideoFrameInfo and return their relative rank. 90 This ranking is by the relative area of the frame resolution, and 91 frame rate if resolution equal. The final check for equality is on 92 the colourFormat. The SAR and resize mode take no part. 93 94 @return 95 <code>LessThan</code>, <code>EqualTo</code> or <code>GreaterThan</code> 96 according to the relative rank of the objects. 97 */ 98 virtual Comparison Compare( 99 const PObject & obj // Object to compare against. 100 ) const; 101 102 /** Output the contents of the object to the stream. The exact output is 103 dependent on the exact semantics of the descendent class. This is 104 primarily used by the standard <code>#operator<<</code> function. 105 106 The default behaviour is to print the class name. 107 */ 108 virtual void PrintOn( 109 ostream & strm // Stream to print the object into. 110 ) const; 111 112 /**Set the frame size to be used. 113 114 Default behaviour sets the frameWidth and frameHeight variables and 115 returns true. 116 */ 117 virtual PBoolean SetFrameSize( 118 unsigned width, ///< New width of frame 119 unsigned height ///< New height of frame 120 ); 121 122 /**Get the frame size being used. 123 124 Default behaviour returns the value of the frameWidth and frameHeight 125 variable and returns true. 126 */ 127 virtual PBoolean GetFrameSize( 128 unsigned & width, 129 unsigned & height 130 ) const; 131 132 /** Get the width of the frame being used. 133 134 Default behaviour returns the value of the frameWidth variable 135 */ 136 virtual unsigned GetFrameWidth() const; 137 138 /** Get the height of the frame being used. 139 140 Default behaviour returns the value of the frameHeight variable 141 */ 142 virtual unsigned GetFrameHeight() const; 143 144 /**Set the sar size to be used. 145 146 Default behaviour sets the sarWidth and sarHeight variables and 147 returns PTrue. 148 */ 149 virtual PBoolean SetFrameSar(unsigned width, unsigned height); 150 151 /**Get the sar size being used. 152 153 Default behaviour returns the value of the sarWidth and sarHeight 154 variable and returns PTrue. 155 */ 156 virtual PBoolean GetSarSize( 157 unsigned & width, 158 unsigned & height 159 ) const; 160 161 /** Get the width of the sar being used. 162 163 Default behaviour returns the value of the sarWidth variable 164 */ 165 virtual unsigned GetSarWidth() const; 166 167 /** Get the height of the sar being used. 168 169 Default behaviour returns the value of the sarHeight variable 170 */ 171 virtual unsigned GetSarHeight() const; 172 173 /**Set the video frame rate to be used on the device. 174 175 Default behaviour sets the value of the frameRate variable and then 176 returns true. 177 */ 178 virtual PBoolean SetFrameRate( 179 unsigned rate ///< Frames per second 180 ); 181 182 /**Get the video frame rate used on the device. 183 184 Default behaviour returns the value of the frameRate variable. 185 */ 186 virtual unsigned GetFrameRate() const; 187 188 /**Set the colour format to be used. 189 190 Default behaviour sets the value of the colourFormat variable and then 191 returns true if not an empty string. 192 */ 193 virtual PBoolean SetColourFormat( 194 const PString & colourFormat // New colour format for device. 195 ); 196 197 /**Get the colour format to be used. 198 199 Default behaviour returns the value of the colourFormat variable. 200 */ 201 virtual const PString & GetColourFormat() const; 202 203 /**Set the resize mode to be used. 204 */ SetResizeMode(ResizeMode mode)205 void SetResizeMode( 206 ResizeMode mode 207 ) { if (resizeMode < eMaxResizeMode) resizeMode = mode; } 208 209 /**Get the resize mode to be used. 210 */ GetResizeMode()211 ResizeMode GetResizeMode() const { return resizeMode; } 212 213 /** Get the number of bytes of an image, given a particular width, height and colour format. 214 */ CalculateFrameBytes()215 PINDEX CalculateFrameBytes() const { return CalculateFrameBytes(frameWidth, frameHeight, colourFormat); } 216 static PINDEX CalculateFrameBytes( 217 unsigned width, ///< WIdth of frame 218 unsigned height, ///< Height of frame 219 const PString & colourFormat ///< Colour format of frame 220 ); 221 222 /** Parse a descriptor string for the video format. 223 This is of the form [fmt ':' ] size [ '@' rate][ '/' crop ]. The size component 224 is as for the ParseSize() function. 225 226 The fmt string is the colour format such as "RGB32", "YUV420P" etc. 227 228 The rate field is a simple integer from 1 to 100. 229 230 The crop field is one of "scale", "resize" (synonym for "scale"), 231 "centre", "center", "topleft" or "crop" (synonym for "topleft"). 232 233 Note no spaces are allowed in the descriptor. 234 */ 235 bool Parse( 236 const PString & str ///< String to parse 237 ); 238 239 /** Parse the standard size string names. 240 This will parse a size desciption using either standard names: "qcif", 241 "cif", "vga", "hd1080" etc or WxY form e.g. "640x480". 242 */ 243 static bool ParseSize( 244 const PString & str, ///< String to parse 245 unsigned & width, ///< Resultant width 246 unsigned & height ///< Resulatant height 247 ); 248 249 /**Get a width/height as a standard size string name. 250 */ 251 static PString AsString( 252 unsigned width, ///< Width to convert 253 unsigned height ///< Height to convert 254 ); 255 256 /**Get all "known" image size names. 257 Returns all standard names for sizes, e.g. "qcif", "cif", "vga", 258 "hd1080" etc. 259 */ 260 static PStringArray GetSizeNames(); 261 262 protected: 263 unsigned frameWidth; 264 unsigned frameHeight; 265 unsigned sarWidth; 266 unsigned sarHeight; 267 unsigned frameRate; 268 PString colourFormat; 269 ResizeMode resizeMode; 270 }; 271 272 273 class PVideoControlInfo : public PObject 274 { 275 PCLASSINFO(PVideoControlInfo, PObject); 276 277 public: 278 279 typedef enum { 280 ControlPan, 281 ControlTilt, 282 ControlZoom 283 } InputControlType; 284 285 static PString AsString(const InputControlType & type); 286 287 InputControlType type; 288 long min; 289 long max; 290 long step; 291 long def; 292 long flags; 293 long current; 294 }; 295 296 297 /**This class defines a video Input device control (Camera controls PTZ) 298 */ 299 300 class PVideoInputControl : public PVideoControlInfo 301 { 302 PCLASSINFO(PVideoInputControl, PVideoControlInfo); 303 304 public: 305 ~PVideoInputControl(); 306 307 virtual PBoolean Pan(long value, bool absolute = false ); 308 virtual PBoolean Tilt(long value, bool absolute = false); 309 virtual PBoolean Zoom(long value, bool absolute = false); 310 311 long GetPan(); 312 long GetTilt(); 313 long GetZoom(); 314 315 void Reset(); 316 void SetCurrentPosition(const InputControlType ctype, long current); 317 318 typedef std::list<PVideoControlInfo> InputDeviceControls; 319 320 protected: 321 PBoolean GetVideoControlInfo(const InputControlType ctype, PVideoControlInfo & control); 322 PBoolean GetDefaultPosition(const InputControlType ctype, long & def); 323 PBoolean GetCurrentPosition(const InputControlType ctype, long & current); 324 325 std::list<PVideoControlInfo> m_info; 326 PMutex ccmutex; 327 328 }; 329 330 /**This class defines a video Input device Interactions (Remote Inputs/Controls) 331 */ 332 class PVideoInteractionInfo : public PObject 333 { 334 PCLASSINFO(PVideoInteractionInfo, PObject); 335 336 public: 337 338 typedef enum { 339 InteractKey, /// Register remote KeyPresses 340 InteractMouse, /// Register remote Mouse Movement Clicks 341 InteractNavigate, /// Register remote Navigation commands 342 InteractRTSP, /// Register remote RTSP (Real Time Streaming Protocol) Inputs 343 InteractOther /// Register remote application specific Inputs 344 } InputInteractType; 345 346 static PString AsString(const InputInteractType & type); 347 348 InputInteractType type; 349 }; 350 351 352 /**This class defines a video device. 353 This class is used to abstract the few parameters that are common to both\ 354 input and output devices. 355 356 Example colour formats are: 357 358 "Grey" Simple 8 bit linear grey scale 359 "Gray" Synonym for Grey 360 "RGB32" 32 bit RGB 361 "RGB24" 24 bit RGB 362 "RGB565" 16 bit RGB (6 bit green) 363 "RGB555" 15 bit RGB 364 "YUV422" YUV 4:2:2 packed 365 "YUV422P" YUV 4:2:2 planar 366 "YUV411" YUV 4:1:1 packed 367 "YUV411P" YUV 4:1:1 planar 368 "YUV420" YUV 4:2:0 packed 369 "YUV420P" YUV 4:2:0 planar 370 "YUV410" YUV 4:1:0 packed 371 "YUV410P" YUV 4:1:0 planar 372 "MJPEG" Motion JPEG 373 "UYVY422" YUV 4:2:2 packed as U Y V Y U Y V Y ... 374 "UYV444" YUV 4:4:4 packed as U Y V U Y V ... 375 They are used in IEEE 1394 digital cameras. The specification 376 is found at 377 http://www.1394ta.org/Download/Technology/Specifications/2000/IIDC_Spec_v1_30.pdf 378 379 */ 380 class PVideoDevice : public PVideoFrameInfo 381 { 382 PCLASSINFO(PVideoDevice, PVideoFrameInfo); 383 384 protected: 385 /** Create a new video device (input or output). 386 */ 387 PVideoDevice(); 388 389 390 public: 391 /** Delete structures created by PVideoDevice(); 392 */ 393 virtual ~PVideoDevice(); 394 395 enum VideoFormat { 396 PAL, 397 NTSC, 398 SECAM, 399 Auto, 400 NumVideoFormats 401 }; 402 403 /**Get the device name of the open device. 404 */ GetDeviceName()405 const PString & GetDeviceName() const 406 { return deviceName; } 407 408 /**Get a list of all of the drivers available. 409 */ 410 virtual PStringArray GetDeviceNames() const = 0; 411 412 struct OpenArgs { 413 OpenArgs(); 414 415 PPluginManager * pluginMgr; 416 PString driverName; 417 PString deviceName; 418 VideoFormat videoFormat; 419 int channelNumber; 420 PString colourFormat; 421 bool convertFormat; 422 unsigned rate; 423 unsigned width; 424 unsigned height; 425 bool convertSize; 426 ResizeMode resizeMode; 427 bool flip; 428 int brightness; 429 int whiteness; 430 int contrast; 431 int colour; 432 int hue; 433 }; 434 435 /**Open the device given the device name. 436 */ 437 virtual PBoolean OpenFull( 438 const OpenArgs & args, ///< Parameters to set on opened device 439 PBoolean startImmediate = true ///< Immediately start device 440 ); 441 442 /**Open the device given the device name. 443 */ 444 virtual PBoolean Open( 445 const PString & deviceName, ///< Device name to open 446 PBoolean startImmediate = true ///< Immediately start device 447 ) = 0; 448 449 /**Determine if the device is currently open. 450 */ 451 virtual PBoolean IsOpen() = 0; 452 453 /**Close the device. 454 */ 455 virtual PBoolean Close() = 0; 456 457 /**Start the video device I/O capture. 458 */ 459 virtual PBoolean Start() = 0; 460 461 /**Stop the video device I/O capture. 462 */ 463 virtual PBoolean Stop() = 0; 464 465 466 #if PTRACING 467 friend ostream & operator<<(ostream &, VideoFormat); 468 #endif 469 470 /**Set the video format to be used. 471 472 Default behaviour sets the value of the videoFormat variable and then 473 returns true. 474 */ 475 virtual PBoolean SetVideoFormat( 476 VideoFormat videoFormat ///< New video format 477 ); 478 479 /**Get the video format being used. 480 481 Default behaviour returns the value of the videoFormat variable. 482 */ 483 virtual VideoFormat GetVideoFormat() const; 484 485 /**Get the number of video channels available on the device. 486 487 Default behaviour returns 1. 488 */ 489 virtual int GetNumChannels(); 490 491 /**Set the video channel to be used on the device. 492 The channel number is an integer from 0 to GetNumChannels()-1. The 493 special value of -1 will find the first working channel number. 494 495 Default behaviour sets the value of the channelNumber variable and then 496 returns true. 497 */ 498 virtual PBoolean SetChannel( 499 int channelNumber ///< New channel number for device. 500 ); 501 502 /**Get the video channel to be used on the device. 503 504 Default behaviour returns the value of the channelNumber variable. 505 */ 506 virtual int GetChannel() const; 507 508 /**Set the colour format to be used, trying converters if available. 509 510 This function will set the colour format on the device to one that 511 is compatible with a registered converter, and install that converter 512 so that the correct format is used. 513 */ 514 virtual PBoolean SetColourFormatConverter( 515 const PString & colourFormat // New colour format for device. 516 ); 517 518 /**Get the video conversion vertical flip state. 519 Default action is to return false. 520 */ 521 virtual PBoolean GetVFlipState(); 522 523 /**Set the video conversion vertical flip state. 524 Default action is to return false. 525 */ 526 virtual PBoolean SetVFlipState( 527 PBoolean newVFlipState ///< New vertical flip state 528 ); 529 530 /**Get the minimum & maximum size of a frame on the device. 531 532 Default behaviour returns the value 1 to UINT_MAX for both and returns 533 false. 534 */ 535 virtual PBoolean GetFrameSizeLimits( 536 unsigned & minWidth, ///< Variable to receive minimum width 537 unsigned & minHeight, ///< Variable to receive minimum height 538 unsigned & maxWidth, ///< Variable to receive maximum width 539 unsigned & maxHeight ///< Variable to receive maximum height 540 ) ; 541 542 543 /**Set the frame size to be used, trying converters if available. 544 545 If the device does not support the size, a set of alternate resolutions 546 are attempted. A converter is setup if possible. 547 */ 548 virtual PBoolean SetFrameSizeConverter( 549 unsigned width, ///< New width of frame 550 unsigned height, ///< New height of frame 551 ResizeMode resizeMode = eMaxResizeMode ///< Mode to use if resizing is required. 552 ); 553 554 /**Set the frame size to be used, trying converters if available. 555 Function used for Backward compatibility only. 556 If the device does not support the size, a set of alternate resolutions 557 are attempted. A converter is setup if possible. 558 */ SetFrameSizeConverter(unsigned width,unsigned height,PBoolean)559 virtual PBoolean SetFrameSizeConverter( 560 unsigned width, ///< New width of frame 561 unsigned height, ///< New height of frame 562 PBoolean /*bScaleNotCrop*/ ///< Not used. 563 ) { return SetFrameSizeConverter(width,height,eScale); } 564 565 566 /**Set the nearest available frame size to be used. 567 568 Note that devices may not be able to produce the requested size, so 569 this function picks the nearest available size. 570 571 Default behaviour simply calls SetFrameSize(). 572 */ 573 virtual PBoolean SetNearestFrameSize( 574 unsigned width, ///< New width of frame 575 unsigned height ///< New height of frame 576 ); 577 578 /**Set the frame size to be used. 579 580 Note that devices may not be able to produce the requested size, and 581 this function will fail. See SetFrameSizeConverter(). 582 583 Default behaviour sets the frameWidth and frameHeight variables and 584 returns true. 585 */ 586 virtual PBoolean SetFrameSize( 587 unsigned width, ///< New width of frame 588 unsigned height ///< New height of frame 589 ); 590 591 /**Get the frame size being used. 592 593 Default behaviour returns the value of the frameWidth and frameHeight 594 variable and returns true. 595 */ 596 virtual PBoolean GetFrameSize( 597 unsigned & width, 598 unsigned & height 599 ) const; 600 601 /**Get the maximum frame size in bytes. 602 603 Note a particular device may be able to provide variable length 604 frames (eg motion JPEG) so will be the maximum size of all frames. 605 */ 606 virtual PINDEX GetMaxFrameBytes() = 0; 607 608 609 /**Get the last error code. This is a platform dependent number. 610 */ GetLastError()611 int GetLastError() const { return lastError; } 612 613 614 /** Is the device a camera, and obtain video 615 */ 616 virtual PBoolean CanCaptureVideo() const = 0; 617 618 /**Get the brightness of the image. 0xffff-Very bright. -1 is unknown. 619 */ 620 virtual int GetBrightness(); 621 622 /**Set brightness of the image. 0xffff-Very bright. 623 */ 624 virtual PBoolean SetBrightness(unsigned newBrightness); 625 626 627 /**Get the whiteness of the image. 0xffff-Very white. -1 is unknown. 628 */ 629 virtual int GetWhiteness(); 630 631 /**Set whiteness of the image. 0xffff-Very white. 632 */ 633 virtual PBoolean SetWhiteness(unsigned newWhiteness); 634 635 636 /**Get the colour of the image. 0xffff-lots of colour. -1 is unknown. 637 */ 638 virtual int GetColour(); 639 640 /**Set colour of the image. 0xffff-lots of colour. 641 */ 642 virtual PBoolean SetColour(unsigned newColour); 643 644 645 /**Get the contrast of the image. 0xffff-High contrast. -1 is unknown. 646 */ 647 virtual int GetContrast(); 648 649 /**Set contrast of the image. 0xffff-High contrast. 650 */ 651 virtual PBoolean SetContrast(unsigned newContrast); 652 653 654 /**Get the hue of the image. 0xffff-High hue. -1 is unknown. 655 */ 656 virtual int GetHue(); 657 658 /**Set hue of the image. 0xffff-High hue. 659 */ 660 virtual PBoolean SetHue(unsigned newHue); 661 662 663 /**Return whiteness, brightness, colour, contrast and hue in one call. 664 */ 665 virtual PBoolean GetParameters( 666 int *whiteness, 667 int *brightness, 668 int *colour, 669 int *contrast, 670 int *hue 671 ); 672 673 674 /** Set VideoFormat and VideoChannel in one ioctl 675 */ 676 virtual PBoolean SetVideoChannelFormat ( 677 int channelNumber, 678 VideoFormat videoFormat 679 ); 680 681 682 /**Set preferred native colour format from video capture device. 683 Note empty == no preference. 684 */ SetPreferredColourFormat(const PString & colourFmt)685 void SetPreferredColourFormat(const PString & colourFmt) { preferredColourFormat = colourFmt; } 686 687 /**Get preferred native colour format from video capture device. 688 Returns empty == no preference 689 */ GetPreferredColourFormat()690 const PString & GetPreferredColourFormat() { return preferredColourFormat; } 691 692 protected: 693 PINDEX GetMaxFrameBytesConverted(PINDEX rawFrameBytes) const; 694 695 PString deviceName; 696 int lastError; 697 VideoFormat videoFormat; 698 int channelNumber; 699 // Preferred native colour format from video input device, empty == no preference 700 PString preferredColourFormat; 701 PBoolean nativeVerticalFlip; 702 703 PColourConverter * converter; 704 PBYTEArray frameStore; 705 706 int frameBrightness; // 16 bit entity, -1 is no value 707 int frameWhiteness; 708 int frameContrast; 709 int frameColour; 710 int frameHue; 711 }; 712 713 714 /**This class defines a video output device.- typically, a window. 715 */ 716 class PVideoOutputDevice : public PVideoDevice 717 { 718 PCLASSINFO(PVideoOutputDevice, PVideoDevice); 719 720 public: 721 /** Create a new video output device. 722 */ 723 PVideoOutputDevice(); 724 725 /**Close the video output device on destruction. 726 */ ~PVideoOutputDevice()727 virtual ~PVideoOutputDevice() { Close(); }; 728 729 /**Get the list of available video output drivers (plug-ins) 730 */ 731 static PStringArray GetDriverNames( 732 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 733 ); 734 735 /**Get video output devices that correspond to the specified driver name. 736 If driverName is an empty string or the value "*" then this will return 737 a list of unique device names across all of the available drivers. If 738 two drivers have identical names for devices, then the string returned 739 will be of the form driver+'\\t'+device. 740 */ 741 static PStringArray GetDriversDeviceNames( 742 const PString & driverName, ///< Name of driver 743 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 744 ); 745 746 /**Create the video output device that corresponds to the specified driver name. 747 */ 748 static PVideoOutputDevice * CreateDevice( 749 const PString & driverName, ///< Name of driver 750 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 751 ); 752 753 /* Create the matching video output device that corresponds to the device name. 754 755 This is typically used with the return values from GetDriversDeviceNames(). 756 */ 757 static PVideoOutputDevice *CreateDeviceByName( 758 const PString & deviceName, ///< Name of device 759 const PString & driverName = PString::Empty(), ///< Name of driver (if any) 760 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 761 ); 762 763 /**Create an opened video output device that corresponds to the specified names. 764 If the driverName parameter is an empty string or "*" then CreateDeviceByName 765 is used with the deviceName parameter which is assumed to be a value returned 766 from GetDriversDeviceNames(). 767 */ 768 static PVideoOutputDevice *CreateOpenedDevice( 769 const PString & driverName, ///< Name of driver 770 const PString & deviceName, ///< Name of device 771 PBoolean startImmediate = true, ///< Immediately start display 772 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 773 ); 774 775 /**Create an opened video output device that corresponds to the specified arguments. 776 */ 777 static PVideoOutputDevice *CreateOpenedDevice( 778 const OpenArgs & args, ///< Parameters to set on opened device 779 PBoolean startImmediate = true ///< Immediately start display 780 ); 781 782 /**Close the device. 783 */ Close()784 virtual PBoolean Close() { return true; } 785 786 /**Start the video device I/O display. 787 */ Start()788 virtual PBoolean Start() { return true; } 789 790 /**Stop the video device I/O display. 791 */ Stop()792 virtual PBoolean Stop() { return true; } 793 794 /** Is the device a camera, and obtain video 795 */ 796 virtual PBoolean CanCaptureVideo() const; 797 798 /**Set a section of the output frame buffer. 799 */ 800 virtual PBoolean SetFrameData( 801 unsigned x, 802 unsigned y, 803 unsigned width, 804 unsigned height, 805 const BYTE * data, 806 PBoolean endFrame = true 807 ) = 0; 808 virtual PBoolean SetFrameData( 809 unsigned x, 810 unsigned y, 811 unsigned width, 812 unsigned height, 813 const BYTE * data, 814 PBoolean endFrame, 815 unsigned flags 816 ); 817 virtual PBoolean SetFrameData( 818 unsigned x, 819 unsigned y, 820 unsigned width, 821 unsigned height, 822 unsigned sarwidth, 823 unsigned sarheight, 824 const BYTE * data, 825 PBoolean endFrame, 826 unsigned flags, 827 const void * mark 828 ); 829 830 /**Allow the outputdevice decide whether the 831 decoder should ignore decode hence not render 832 any output. 833 834 Returns: false if to decode and render. 835 */ 836 virtual PBoolean DisableDecode(); 837 838 /**Get the position of the output device, where relevant. For devices such as 839 files, this always returns zeros. For devices such as Windows, this is the 840 position of the window on the screen. 841 842 Returns: TRUE if the position is available. 843 */ 844 virtual PBoolean GetPosition( 845 int & x, // X position of device surface 846 int & y // Y position of device surface 847 ) const; 848 849 /**Set the position of the output device, where relevant. For devices such as 850 files, this does nothing. For devices such as Windows, this sets the 851 position of the window on the screen. 852 853 Returns: TRUE if the position can be set. 854 */ 855 virtual bool SetPosition( 856 int x, // X position of device surface 857 int y // Y position of device surface 858 ); 859 }; 860 861 862 /**This class defines a video output device for RGB in a frame store. 863 */ 864 class PVideoOutputDeviceRGB : public PVideoOutputDevice 865 { 866 PCLASSINFO(PVideoOutputDeviceRGB, PVideoOutputDevice); 867 868 public: 869 /** Create a new video output device. 870 */ 871 PVideoOutputDeviceRGB(); 872 873 /**Set the colour format to be used. 874 Note that this function does not do any conversion. If it returns true 875 then the video device does the colour format in native mode. 876 877 To utilise an internal converter use the SetColourFormatConverter() 878 function. 879 880 Default behaviour sets the value of the colourFormat variable and then 881 returns true. 882 */ 883 virtual PBoolean SetColourFormat( 884 const PString & colourFormat // New colour format for device. 885 ); 886 887 /**Set the frame size to be used. 888 889 Note that devices may not be able to produce the requested size, and 890 this function will fail. See SetFrameSizeConverter(). 891 892 Default behaviour sets the frameWidth and frameHeight variables and 893 returns true. 894 */ 895 virtual PBoolean SetFrameSize( 896 unsigned width, ///< New width of frame 897 unsigned height ///< New height of frame 898 ); 899 900 /**Get the maximum frame size in bytes. 901 902 Note a particular device may be able to provide variable length 903 frames (eg motion JPEG) so will be the maximum size of all frames. 904 */ 905 virtual PINDEX GetMaxFrameBytes(); 906 907 /**Set a section of the output frame buffer. 908 */ 909 virtual PBoolean SetFrameData( 910 unsigned x, 911 unsigned y, 912 unsigned width, 913 unsigned height, 914 const BYTE * data, 915 PBoolean endFrame = true 916 ); 917 918 /**Indicate frame may be displayed. 919 */ 920 virtual PBoolean FrameComplete() = 0; 921 922 protected: 923 PMutex mutex; 924 PINDEX bytesPerPixel; 925 PINDEX scanLineWidth; 926 bool swappedRedAndBlue; 927 }; 928 929 930 #ifdef SHOULD_BE_MOVED_TO_PLUGIN 931 932 /**This class defines a video output device which outputs to a series of PPM files. 933 */ 934 class PVideoOutputDevicePPM : public PVideoOutputDeviceRGB 935 { 936 PCLASSINFO(PVideoOutputDevicePPM, PVideoOutputDeviceRGB); 937 938 public: 939 /** Create a new video output device. 940 */ 941 PVideoOutputDevicePPM(); 942 943 /**Open the device given the device name. 944 */ 945 virtual PBoolean Open( 946 const PString & deviceName, ///< Device name (filename base) to open 947 PBoolean startImmediate = true ///< Immediately start device 948 ); 949 950 /**Determine if the device is currently open. 951 */ 952 virtual PBoolean IsOpen(); 953 954 /**Close the device. 955 */ 956 virtual PBoolean Close(); 957 958 /**Get a list of all of the drivers available. 959 */ 960 virtual PStringArray GetDeviceNames() const; 961 962 /**Indicate frame may be displayed. 963 */ 964 virtual PBoolean EndFrame(); 965 966 protected: 967 unsigned frameNumber; 968 }; 969 970 #endif // SHOULD_BE_MOVED_TO_PLUGIN 971 972 973 /**This class defines a video input device. 974 */ 975 class PVideoInputDevice : public PVideoDevice 976 { 977 PCLASSINFO(PVideoInputDevice, PVideoDevice); 978 979 public: 980 /** Create a new video input device. 981 */ 982 //PVideoInputDevice(); 983 984 /**Close the video input device on destruction. 985 */ ~PVideoInputDevice()986 ~PVideoInputDevice() { Close(); } 987 988 /**Get the list of available video input drivers (plug-ins) 989 */ 990 static PStringArray GetDriverNames( 991 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 992 ); 993 994 /**Get video input devices that correspond to the specified driver name. 995 If driverName is an empty string or the value "*" then this will return 996 a list of unique device names across all of the available drivers. If 997 two drivers have identical names for devices, then the string returned 998 will be of the form driver+'\\t'+device. 999 */ 1000 static PStringArray GetDriversDeviceNames( 1001 const PString & driverName, ///< Name of driver 1002 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1003 ); 1004 1005 /**Create the video input device that corresponds to the specified driver name. 1006 */ 1007 static PVideoInputDevice *CreateDevice( 1008 const PString & driverName, ///< Name of driver 1009 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1010 ); 1011 1012 /* Create the matching video input device that corresponds to the device name. 1013 So, for "fake" return a device that will generate fake video. 1014 For "Phillips 680 webcam" (eg) will return appropriate grabber. 1015 Note that Phillips will return the appropriate grabber also. 1016 1017 This is typically used with the return values from GetDriversDeviceNames(). 1018 */ 1019 static PVideoInputDevice *CreateDeviceByName( 1020 const PString & deviceName, ///< Name of device 1021 const PString & driverName = PString::Empty(), ///< Name of driver (if any) 1022 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1023 ); 1024 1025 /**Create an opened video input device that corresponds to the specified names. 1026 If the driverName parameter is an empty string or "*" then CreateDeviceByName 1027 is used with the deviceName parameter which is assumed to be a value returned 1028 from GetDriversDeviceNames(). 1029 */ 1030 static PVideoInputDevice *CreateOpenedDevice( 1031 const PString & driverName, ///< Name of driver 1032 const PString & deviceName, ///< Name of device 1033 PBoolean startImmediate = true, ///< Immediately start grabbing 1034 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1035 ); 1036 1037 /**Create an opened video output device that corresponds to the specified arguments. 1038 */ 1039 static PVideoInputDevice *CreateOpenedDevice( 1040 const OpenArgs & args, ///< Parameters to set on opened device 1041 PBoolean startImmediate = true ///< Immediately start display 1042 ); 1043 1044 typedef struct { 1045 std::list<PVideoFrameInfo> framesizes; 1046 std::list<PVideoControlInfo> controls; 1047 std::list<PVideoInteractionInfo> interactions; 1048 } Capabilities; 1049 1050 /**Retrieve a list of Device Capabilities 1051 */ GetDeviceCapabilities(Capabilities * capabilities)1052 virtual bool GetDeviceCapabilities( 1053 Capabilities * capabilities ///< List of supported capabilities 1054 ) const { return GetDeviceCapabilities(GetDeviceName(), capabilities); } 1055 1056 /**Retrieve a list of Device Capabilities for particular device 1057 */ 1058 static PBoolean GetDeviceCapabilities( 1059 const PString & deviceName, ///< Name of device 1060 Capabilities * capabilities, ///< List of supported capabilities 1061 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1062 ); 1063 1064 /**Retrieve a list of Device Capabilities for a particular driver 1065 */ 1066 static PBoolean GetDeviceCapabilities( 1067 const PString & deviceName, ///< Name of device 1068 const PString & driverName, ///< Device Driver 1069 Capabilities * caps, ///< List of supported capabilities 1070 PPluginManager * pluginMgr = NULL ///< Plug in manager, use default if NULL 1071 ); 1072 1073 /**Get the devices video Input controls 1074 By Default return NULL; 1075 */ 1076 virtual PVideoInputControl * GetVideoInputControls(); 1077 1078 /**Open the device given the device name. 1079 */ 1080 virtual PBoolean Open( 1081 const PString & deviceName, ///< Device name to open 1082 PBoolean startImmediate = true ///< Immediately start device 1083 ) = 0; 1084 Close()1085 virtual PBoolean Close( 1086 ) { return true; } 1087 1088 /** Is the device a camera, and obtain video 1089 */ 1090 virtual PBoolean CanCaptureVideo() const; 1091 1092 /**Determine if the video device I/O capture is in progress. 1093 */ 1094 virtual PBoolean IsCapturing() = 0; 1095 1096 /**Set the nearest available frame size to be used. 1097 1098 Note that devices may not be able to produce the requested size, so 1099 this function picks the nearest available size. 1100 1101 Default behaviour simply calls SetFrameSize(). 1102 */ 1103 virtual PBoolean SetNearestFrameSize( 1104 unsigned width, ///< New width of frame 1105 unsigned height ///< New height of frame 1106 ); 1107 1108 /**Grab a frame. 1109 */ 1110 virtual PBoolean GetFrame( 1111 PBYTEArray & frame 1112 ); 1113 1114 /**Grab a frame, after a delay as specified by the frame rate. 1115 */ 1116 virtual PBoolean GetFrameData( 1117 BYTE * buffer, ///< Buffer to receive frame 1118 PINDEX * bytesReturned, ///< Optional bytes returned. 1119 unsigned int & flags ///< optional flags returned 1120 ); 1121 virtual PBoolean GetFrameData( 1122 BYTE * buffer, ///< Buffer to receive frame 1123 PINDEX * bytesReturned = NULL ///< Optional bytes returned. 1124 ) = 0; 1125 1126 /**Grab a frame. Do not delay according to the current frame rate parameter. 1127 */ 1128 virtual PBoolean GetFrameDataNoDelay( 1129 BYTE * buffer, ///< Buffer to receive frame 1130 PINDEX * bytesReturned, ///< Optional bytes returned. 1131 unsigned int & flags ///< optional flags returned 1132 ); 1133 virtual PBoolean GetFrameDataNoDelay( 1134 BYTE * buffer, ///< Buffer to receive frame 1135 PINDEX * bytesReturned = NULL ///< Optional bytes returned. 1136 ) = 0; 1137 1138 /**Pass data to the inputdevice for flowControl determination. 1139 */ 1140 virtual bool FlowControl(const void * flowData); 1141 1142 /**Set the capture modes for implementations that support them. 1143 For example with Video For Windows, this is used to select picture (0) 1144 or video (1) modes. 1145 1146 In picture-mode the implementation requests a single frame from the 1147 connected camera device. The camera device then does nothing until the 1148 frame has been processed and the next is requested. 1149 1150 In video-mode the camera continuously sends new frames. 1151 1152 The default implementation does nothing but returns PFalse. 1153 */ 1154 virtual bool SetCaptureMode(unsigned mode); 1155 1156 /**Returns the current capture mode. See SetCaptureMode() for more details. 1157 A return value of -1 indicates an error or the mode is not supported. 1158 */ 1159 virtual int GetCaptureMode() const; 1160 }; 1161 1162 1163 //////////////////////////////////////////////////////// 1164 // 1165 // declare macros and structures needed for video input plugins 1166 // 1167 1168 template <class className> class PVideoInputPluginServiceDescriptor : public PDevicePluginServiceDescriptor 1169 { 1170 public: CreateInstance(int)1171 virtual PObject * CreateInstance(int /*userData*/) const { return new className; } GetDeviceNames(int)1172 virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetInputDeviceNames(); } GetDeviceCapabilities(const PString & deviceName,void * caps)1173 virtual bool GetDeviceCapabilities(const PString & deviceName, void * caps) const 1174 { return className::GetDeviceCapabilities(deviceName, (PVideoInputDevice::Capabilities *)caps); } 1175 }; 1176 1177 #define PCREATE_VIDINPUT_PLUGIN(name) \ 1178 static PVideoInputPluginServiceDescriptor<PVideoInputDevice_##name> PVideoInputDevice_##name##_descriptor; \ 1179 PCREATE_PLUGIN(name, PVideoInputDevice, &PVideoInputDevice_##name##_descriptor) 1180 1181 PPLUGIN_STATIC_LOAD(FakeVideo, PVideoInputDevice); 1182 1183 #ifdef P_APPSHARE 1184 PPLUGIN_STATIC_LOAD(Application, PVideoInputDevice); 1185 #endif 1186 1187 #if P_FFVDEV 1188 PPLUGIN_STATIC_LOAD(FFMPEG, PVideoInputDevice); 1189 #endif 1190 1191 #if P_VIDFILE 1192 PPLUGIN_STATIC_LOAD(YUVFile, PVideoInputDevice); 1193 #endif 1194 1195 #ifdef P_DIRECTSHOW 1196 PPLUGIN_STATIC_LOAD(DirectShow, PVideoInputDevice); 1197 #endif 1198 1199 1200 //////////////////////////////////////////////////////// 1201 // 1202 // declare macros and structures needed for video output plugins 1203 // 1204 1205 template <class className> class PVideoOutputPluginServiceDescriptor : public PDevicePluginServiceDescriptor 1206 { 1207 public: CreateInstance(int)1208 virtual PObject * CreateInstance(int /*userData*/) const { return new className; } GetDeviceNames(int)1209 virtual PStringArray GetDeviceNames(int /*userData*/) const { return className::GetOutputDeviceNames(); } 1210 }; 1211 1212 #define PCREATE_VIDOUTPUT_PLUGIN(name) \ 1213 static PVideoOutputPluginServiceDescriptor<PVideoOutputDevice_##name> PVideoOutputDevice_##name##_descriptor; \ 1214 PCREATE_PLUGIN(name, PVideoOutputDevice, &PVideoOutputDevice_##name##_descriptor) 1215 1216 #if _WIN32 1217 PPLUGIN_STATIC_LOAD(Window, PVideoOutputDevice); 1218 #endif 1219 1220 #if P_SDL 1221 PPLUGIN_STATIC_LOAD(SDL, PVideoOutputDevice); 1222 #endif 1223 1224 1225 //////////////////////////////////////////////////////// 1226 // 1227 // declare classes needed for access to simple video font 1228 // 1229 1230 class PVideoFont : public PObject 1231 { 1232 PCLASSINFO(PVideoFont, PObject); 1233 public: 1234 enum { 1235 MAX_L_HEIGHT = 11 1236 }; 1237 struct LetterData { 1238 char ascii; 1239 const char *line[MAX_L_HEIGHT]; 1240 }; 1241 1242 static const LetterData * GetLetterData(char ascii); 1243 }; 1244 1245 #endif // P_VIDEO 1246 1247 #endif // PTLIB_PVIDEOIO_H 1248 1249 // End Of File /////////////////////////////////////////////////////////////// 1250 1251