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.

170 lines
5.9KB

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