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.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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
  21. //==============================================================================
  22. /**
  23. Receives callbacks with images from a CameraDevice.
  24. @see CameraDevice::addListener
  25. */
  26. class CameraImageListener
  27. {
  28. public:
  29. CameraImageListener() {}
  30. virtual ~CameraImageListener() {}
  31. /** This method is called when a new image arrives.
  32. This may be called by any thread, so be careful about thread-safety,
  33. and make sure that you process the data as quickly as possible to
  34. avoid glitching!
  35. */
  36. virtual void imageReceived (const Image& image) = 0;
  37. };
  38. //==============================================================================
  39. /**
  40. Controls any camera capture devices that might be available.
  41. Use getAvailableDevices() to list the devices that are attached to the
  42. system, then call openDevice to open one for use. Once you have a CameraDevice
  43. object, you can get a viewer component from it, and use its methods to
  44. stream to a file or capture still-frames.
  45. */
  46. class JUCE_API CameraDevice
  47. {
  48. public:
  49. /** Destructor. */
  50. virtual ~CameraDevice();
  51. //==============================================================================
  52. /** Returns a list of the available cameras on this machine.
  53. You can open one of these devices by calling openDevice().
  54. */
  55. static const StringArray getAvailableDevices();
  56. /** Opens a camera device.
  57. The index parameter indicates which of the items returned by getAvailableDevices()
  58. to open.
  59. The size constraints allow the method to choose between different resolutions if
  60. the camera supports this. If the resolution cam't be specified (e.g. on the Mac)
  61. then these will be ignored.
  62. */
  63. static CameraDevice* openDevice (int deviceIndex,
  64. int minWidth = 128, int minHeight = 64,
  65. int maxWidth = 1024, int maxHeight = 768);
  66. //==============================================================================
  67. /** Returns the name of this device */
  68. const String getName() const { return name; }
  69. /** Creates a component that can be used to display a preview of the
  70. video from this camera.
  71. */
  72. Component* createViewerComponent();
  73. //==============================================================================
  74. /** Starts recording video to the specified file.
  75. You should use getFileExtension() to find out the correct extension to
  76. use for your filename.
  77. If the file exists, it will be deleted before the recording starts.
  78. This method may not start recording instantly, so if you need to know the
  79. exact time at which the file begins, you can call getTimeOfFirstRecordedFrame()
  80. after the recording has finished.
  81. The quality parameter can be 0, 1, or 2, to indicate low, medium, or high. It may
  82. or may not be used, depending on the driver.
  83. */
  84. void startRecordingToFile (const File& file, int quality = 2);
  85. /** Stops recording, after a call to startRecordingToFile().
  86. */
  87. void stopRecording();
  88. /** Returns the file extension that should be used for the files
  89. that you pass to startRecordingToFile().
  90. This may be platform-specific, e.g. ".mov" or ".avi".
  91. */
  92. static const String getFileExtension();
  93. /** After calling stopRecording(), this method can be called to return the timestamp
  94. of the first frame that was written to the file.
  95. */
  96. const Time getTimeOfFirstRecordedFrame() const;
  97. //==============================================================================
  98. /** Adds a listener to receive images from the camera.
  99. Be very careful not to delete the listener without first removing it by calling
  100. removeListener().
  101. */
  102. void addListener (CameraImageListener* listenerToAdd);
  103. /** Removes a listener that was previously added with addListener().
  104. */
  105. void removeListener (CameraImageListener* listenerToRemove);
  106. //==============================================================================
  107. juce_UseDebuggingNewOperator
  108. protected:
  109. /** @internal */
  110. CameraDevice (const String& name, int index);
  111. private:
  112. void* internal;
  113. bool isRecording;
  114. String name;
  115. CameraDevice (const CameraDevice&);
  116. CameraDevice& operator= (const CameraDevice&);
  117. };
  118. #endif
  119. #endif // __JUCE_CAMERADEVICE_JUCEHEADER__