The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_CAMERADEVICE_H_INCLUDED
  18. #define JUCE_CAMERADEVICE_H_INCLUDED
  19. #if JUCE_USE_CAMERA || DOXYGEN
  20. //==============================================================================
  21. /**
  22. Controls any video capture devices that might be available.
  23. Use getAvailableDevices() to list the devices that are attached to the
  24. system, then call openDevice to open one for use. Once you have a CameraDevice
  25. object, you can get a viewer component from it, and use its methods to
  26. stream to a file or capture still-frames.
  27. */
  28. class JUCE_API CameraDevice
  29. {
  30. public:
  31. /** Destructor. */
  32. virtual ~CameraDevice();
  33. //==============================================================================
  34. /** Returns a list of the available cameras on this machine.
  35. You can open one of these devices by calling openDevice().
  36. */
  37. static StringArray getAvailableDevices();
  38. /** Opens a camera device.
  39. The index parameter indicates which of the items returned by getAvailableDevices()
  40. to open.
  41. The size constraints allow the method to choose between different resolutions if
  42. the camera supports this. If the resolution cam't be specified (e.g. on the Mac)
  43. then these will be ignored.
  44. */
  45. static CameraDevice* openDevice (int deviceIndex,
  46. int minWidth = 128, int minHeight = 64,
  47. int maxWidth = 1024, int maxHeight = 768);
  48. //==============================================================================
  49. /** Returns the name of this device */
  50. const String& getName() const noexcept { return name; }
  51. /** Creates a component that can be used to display a preview of the
  52. video from this camera.
  53. */
  54. Component* createViewerComponent();
  55. //==============================================================================
  56. /** Starts recording video to the specified file.
  57. You should use getFileExtension() to find out the correct extension to
  58. use for your filename.
  59. If the file exists, it will be deleted before the recording starts.
  60. This method may not start recording instantly, so if you need to know the
  61. exact time at which the file begins, you can call getTimeOfFirstRecordedFrame()
  62. after the recording has finished.
  63. The quality parameter can be 0, 1, or 2, to indicate low, medium, or high. It may
  64. or may not be used, depending on the driver.
  65. */
  66. void startRecordingToFile (const File& file, int quality = 2);
  67. /** Stops recording, after a call to startRecordingToFile(). */
  68. void stopRecording();
  69. /** Returns the file extension that should be used for the files
  70. that you pass to startRecordingToFile().
  71. This may be platform-specific, e.g. ".mov" or ".avi".
  72. */
  73. static String getFileExtension();
  74. /** After calling stopRecording(), this method can be called to return the timestamp
  75. of the first frame that was written to the file.
  76. */
  77. Time getTimeOfFirstRecordedFrame() const;
  78. //==============================================================================
  79. /**
  80. Receives callbacks with images from a CameraDevice.
  81. @see CameraDevice::addListener
  82. */
  83. class JUCE_API Listener
  84. {
  85. public:
  86. Listener() {}
  87. virtual ~Listener() {}
  88. /** This method is called when a new image arrives.
  89. This may be called by any thread, so be careful about thread-safety,
  90. and make sure that you process the data as quickly as possible to
  91. avoid glitching!
  92. */
  93. virtual void imageReceived (const Image& image) = 0;
  94. };
  95. /** Adds a listener to receive images from the camera.
  96. Be very careful not to delete the listener without first removing it by calling
  97. removeListener().
  98. */
  99. void addListener (Listener* listenerToAdd);
  100. /** Removes a listener that was previously added with addListener(). */
  101. void removeListener (Listener* listenerToRemove);
  102. private:
  103. String name;
  104. struct Pimpl;
  105. friend struct Pimpl;
  106. friend struct ContainerDeletePolicy<Pimpl>;
  107. ScopedPointer<Pimpl> pimpl;
  108. struct ViewerComponent;
  109. friend struct ViewerComponent;
  110. CameraDevice (const String& name, int index,
  111. int minWidth, int minHeight, int maxWidth, int maxHeight);
  112. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CameraDevice)
  113. };
  114. #ifndef DOXYGEN
  115. /** This typedef is just for compatibility with VC6 - newer code should use the CameraDevice::Listener class directly. */
  116. typedef CameraDevice::Listener CameraImageListener;
  117. #endif
  118. #endif
  119. #endif // JUCE_CAMERADEVICE_H_INCLUDED