2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_CAMERADEVICE_JUCEHEADER__
27 #define __JUCE_CAMERADEVICE_JUCEHEADER__
29 #if JUCE_USE_CAMERA || DOXYGEN
32 //==============================================================================
34 Controls any video capture devices that might be available.
36 Use getAvailableDevices() to list the devices that are attached to the
37 system, then call openDevice to open one for use. Once you have a CameraDevice
38 object, you can get a viewer component from it, and use its methods to
39 stream to a file or capture still-frames.
41 class JUCE_API CameraDevice
45 virtual ~CameraDevice();
47 //==============================================================================
48 /** Returns a list of the available cameras on this machine.
50 You can open one of these devices by calling openDevice().
52 static StringArray
getAvailableDevices();
54 /** Opens a camera device.
56 The index parameter indicates which of the items returned by getAvailableDevices()
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.
63 static CameraDevice
* openDevice (int deviceIndex
,
64 int minWidth
= 128, int minHeight
= 64,
65 int maxWidth
= 1024, int maxHeight
= 768);
67 //==============================================================================
68 /** Returns the name of this device */
69 String
getName() const { return name
; }
71 /** Creates a component that can be used to display a preview of the
72 video from this camera.
74 Component
* createViewerComponent();
76 //==============================================================================
77 /** Starts recording video to the specified file.
79 You should use getFileExtension() to find out the correct extension to
80 use for your filename.
82 If the file exists, it will be deleted before the recording starts.
84 This method may not start recording instantly, so if you need to know the
85 exact time at which the file begins, you can call getTimeOfFirstRecordedFrame()
86 after the recording has finished.
88 The quality parameter can be 0, 1, or 2, to indicate low, medium, or high. It may
89 or may not be used, depending on the driver.
91 void startRecordingToFile (const File
& file
, int quality
= 2);
93 /** Stops recording, after a call to startRecordingToFile().
97 /** Returns the file extension that should be used for the files
98 that you pass to startRecordingToFile().
100 This may be platform-specific, e.g. ".mov" or ".avi".
102 static String
getFileExtension();
104 /** After calling stopRecording(), this method can be called to return the timestamp
105 of the first frame that was written to the file.
107 Time
getTimeOfFirstRecordedFrame() const;
109 //==============================================================================
111 Receives callbacks with images from a CameraDevice.
113 @see CameraDevice::addListener
115 class JUCE_API Listener
119 virtual ~Listener() {}
121 /** This method is called when a new image arrives.
123 This may be called by any thread, so be careful about thread-safety,
124 and make sure that you process the data as quickly as possible to
127 virtual void imageReceived (const Image
& image
) = 0;
130 /** Adds a listener to receive images from the camera.
132 Be very careful not to delete the listener without first removing it by calling
135 void addListener (Listener
* listenerToAdd
);
137 /** Removes a listener that was previously added with addListener().
139 void removeListener (Listener
* listenerToRemove
);
144 CameraDevice (const String
& name
, int index
);
152 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CameraDevice
);
155 /** This typedef is just for compatibility with old code - newer code should use the CameraDevice::Listener class directly. */
156 typedef CameraDevice::Listener CameraImageListener
;
160 #endif // __JUCE_CAMERADEVICE_JUCEHEADER__