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.

161 lines
5.7KB

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