JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::CameraDevice Class Reference

Controls any video capture devices that might be available. More...

#include <juce_CameraDevice.h>

Collaboration diagram for juce::CameraDevice:

Classes

class  Listener
 Receives callbacks with individual frames from a CameraDevice. More...
 

Public Types

using OpenCameraResultCallback = std::function< void(CameraDevice *, const String &)>
 

Public Member Functions

virtual ~CameraDevice ()
 Destructor. More...
 
void addListener (Listener *listenerToAdd)
 Adds a listener to receive images from the camera. More...
 
ComponentcreateViewerComponent ()
 Creates a component that can be used to display a preview of the video from this camera. More...
 
const StringgetName () const noexcept
 Returns the name of this device. More...
 
Time getTimeOfFirstRecordedFrame () const
 After calling stopRecording(), this method can be called to return the timestamp of the first frame that was written to the file. More...
 
void removeListener (Listener *listenerToRemove)
 Removes a listener that was previously added with addListener(). More...
 
void startRecordingToFile (const File &file, int quality=2)
 Starts recording video to the specified file. More...
 
void stopRecording ()
 Stops recording, after a call to startRecordingToFile(). More...
 
void takeStillPicture (std::function< void(const Image &)> pictureTakenCallback)
 Triggers a still picture capture. More...
 

Static Public Member Functions

static StringArray getAvailableDevices ()
 Returns a list of the available cameras on this machine. More...
 
static String getFileExtension ()
 Returns the file extension that should be used for the files that you pass to startRecordingToFile(). More...
 
static CameraDeviceopenDevice (int deviceIndex, int minWidth=128, int minHeight=64, int maxWidth=1024, int maxHeight=768, bool highQuality=true)
 Synchronously opens a camera device. More...
 
static void openDeviceAsync (int deviceIndex, OpenCameraResultCallback resultCallback, int minWidth=128, int minHeight=64, int maxWidth=1024, int maxHeight=768, bool highQuality=true)
 Asynchronously opens a camera device on iOS (iOS 7+) or Android (API 21+). More...
 

Public Attributes

std::function< void(const String &)> onErrorOccurred
 Set this callback to be notified whenever an error occurs. More...
 

Private Member Functions

 CameraDevice (const String &name, int index, int minWidth, int minHeight, int maxWidth, int maxHeight, bool highQuality)
 

Private Attributes

String name
 
std::unique_ptr< Pimpl > pimpl
 

Friends

void juce_cameraCaptureSessionActive (int64, void *)
 
void juce_cameraCaptureSessionCaptureCompleted (int64, bool, void *, void *, void *)
 
void juce_cameraCaptureSessionCaptureFailed (int64, bool, void *, void *, void *)
 
void juce_cameraCaptureSessionCaptureProgressed (int64, bool, void *, void *, void *)
 
void juce_cameraCaptureSessionCaptureSequenceAborted (int64, bool, void *, int)
 
void juce_cameraCaptureSessionCaptureSequenceCompleted (int64, bool, void *, int, int64)
 
void juce_cameraCaptureSessionCaptureStarted (int64, bool, void *, void *, int64, int64)
 
void juce_cameraCaptureSessionClosed (int64, void *)
 
void juce_cameraCaptureSessionConfigured (int64, void *)
 
void juce_cameraCaptureSessionConfigureFailed (int64, void *)
 
void juce_cameraCaptureSessionReady (int64, void *)
 
void juce_cameraDeviceStateClosed (int64)
 
void juce_cameraDeviceStateDisconnected (int64)
 
void juce_cameraDeviceStateError (int64, int)
 
void juce_cameraDeviceStateOpened (int64, void *)
 
void juce_deviceOrientationChanged (int64, int)
 
struct ViewerComponent
 

Detailed Description

Controls any video capture devices that might be available.

Use getAvailableDevices() to list the devices that are attached to the system, then call openDevice() or openDeviceAsync() to open one for use. Once you have a CameraDevice object, you can get a viewer component from it, and use its methods to stream to a file or capture still-frames.

@tags{Video}

Member Typedef Documentation

◆ OpenCameraResultCallback

using juce::CameraDevice::OpenCameraResultCallback = std::function<void (CameraDevice*, const String& )>

Constructor & Destructor Documentation

◆ ~CameraDevice()

virtual juce::CameraDevice::~CameraDevice ( )
virtual

Destructor.

◆ CameraDevice()

juce::CameraDevice::CameraDevice ( const String name,
int  index,
int  minWidth,
int  minHeight,
int  maxWidth,
int  maxHeight,
bool  highQuality 
)
private

Member Function Documentation

◆ addListener()

void juce::CameraDevice::addListener ( Listener listenerToAdd)

Adds a listener to receive images from the camera.

Be very careful not to delete the listener without first removing it by calling removeListener().

◆ createViewerComponent()

Component* juce::CameraDevice::createViewerComponent ( )

Creates a component that can be used to display a preview of the video from this camera.

Note: While you can change the size of the preview component, the actual preview display may be smaller than the size requested, because the correct aspect ratio is maintained automatically.

◆ getAvailableDevices()

static StringArray juce::CameraDevice::getAvailableDevices ( )
static

Returns a list of the available cameras on this machine.

You can open one of these devices by calling openDevice() or openDeviceAsync().

◆ getFileExtension()

static String juce::CameraDevice::getFileExtension ( )
static

Returns the file extension that should be used for the files that you pass to startRecordingToFile().

This may be platform-specific, e.g. ".mov" or ".avi".

◆ getName()

const String& juce::CameraDevice::getName ( ) const
inlinenoexcept

Returns the name of this device.

References juce::gl::name.

◆ getTimeOfFirstRecordedFrame()

Time juce::CameraDevice::getTimeOfFirstRecordedFrame ( ) const

After calling stopRecording(), this method can be called to return the timestamp of the first frame that was written to the file.

◆ openDevice()

static CameraDevice* juce::CameraDevice::openDevice ( int  deviceIndex,
int  minWidth = 128,
int  minHeight = 64,
int  maxWidth = 1024,
int  maxHeight = 768,
bool  highQuality = true 
)
static

Synchronously opens a camera device.

This function should not be used on iOS or Android, use openDeviceAsync() instead.

The index parameter indicates which of the items returned by getAvailableDevices() to open.

The size constraints allow the method to choose between different resolutions if the camera supports this. If the resolution can't be specified (e.g. on the Mac) then these will be ignored.

On Mac, if highQuality is false, then the camera will be opened in preview mode which will allow the OS to drop frames if the computer cannot keep up in processing the frames.

◆ openDeviceAsync()

static void juce::CameraDevice::openDeviceAsync ( int  deviceIndex,
OpenCameraResultCallback  resultCallback,
int  minWidth = 128,
int  minHeight = 64,
int  maxWidth = 1024,
int  maxHeight = 768,
bool  highQuality = true 
)
static

Asynchronously opens a camera device on iOS (iOS 7+) or Android (API 21+).

On other platforms, the function will simply call openDevice(). Upon completion, resultCallback will be invoked with valid CameraDevice* and an empty error String on success, or nullptr CameraDevice and a non-empty error String on failure.

This is the preferred method of opening a camera device, because it works on all platforms, whereas synchronous openDevice() does not work on iOS & Android.

The index parameter indicates which of the items returned by getAvailableDevices() to open.

The size constraints allow the method to choose between different resolutions if the camera supports this. If the resolution can't be specified then these will be ignored.

On iOS, if you want to switch a device, it is more efficient to open a new device before closing the older one, because this way both devices can share the same underlying camera session. Otherwise, the session needs to be close first, and this is a lengthy process that can take several seconds.

The Android implementation currently supports a maximum recording resolution of 1080p. Choosing a larger size will result in larger pictures taken, but the video will be capped at 1080p.

◆ removeListener()

void juce::CameraDevice::removeListener ( Listener listenerToRemove)

Removes a listener that was previously added with addListener().

◆ startRecordingToFile()

void juce::CameraDevice::startRecordingToFile ( const File file,
int  quality = 2 
)

Starts recording video to the specified file.

You should use getFileExtension() to find out the correct extension to use for your filename.

If the file exists, it will be deleted before the recording starts.

This method may not start recording instantly, so if you need to know the exact time at which the file begins, you can call getTimeOfFirstRecordedFrame() after the recording has finished.

The quality parameter can be 0, 1, or 2, to indicate low, medium, or high. It may or may not be used, depending on the driver.

On Android, before calling startRecordingToFile(), you need to create a preview with createViewerComponent() and you need to make it visible on screen.

The Android camera also requires exclusive access to the audio device, so make sure you close any open audio devices with AudioDeviceManager::closeAudioDevice() first.

Android does not support simultaneous video recording and still picture capture.

See also
AudioDeviceManager::closeAudioDevice, AudioDeviceManager::restartLastAudioDevice

◆ stopRecording()

void juce::CameraDevice::stopRecording ( )

Stops recording, after a call to startRecordingToFile().

◆ takeStillPicture()

void juce::CameraDevice::takeStillPicture ( std::function< void(const Image &)>  pictureTakenCallback)

Triggers a still picture capture.

Upon completion, pictureTakenCallback will be invoked on a message thread.

On Android, before calling takeStillPicture(), you need to create a preview with createViewerComponent() and you need to make it visible on screen.

Android does not support simultaneous video recording and still picture capture.

Friends And Related Function Documentation

◆ juce_cameraCaptureSessionActive

void juce_cameraCaptureSessionActive ( int64  ,
void *   
)
friend

◆ juce_cameraCaptureSessionCaptureCompleted

void juce_cameraCaptureSessionCaptureCompleted ( int64  ,
bool  ,
void *  ,
void *  ,
void *   
)
friend

◆ juce_cameraCaptureSessionCaptureFailed

void juce_cameraCaptureSessionCaptureFailed ( int64  ,
bool  ,
void *  ,
void *  ,
void *   
)
friend

◆ juce_cameraCaptureSessionCaptureProgressed

void juce_cameraCaptureSessionCaptureProgressed ( int64  ,
bool  ,
void *  ,
void *  ,
void *   
)
friend

◆ juce_cameraCaptureSessionCaptureSequenceAborted

void juce_cameraCaptureSessionCaptureSequenceAborted ( int64  ,
bool  ,
void *  ,
int   
)
friend

◆ juce_cameraCaptureSessionCaptureSequenceCompleted

void juce_cameraCaptureSessionCaptureSequenceCompleted ( int64  ,
bool  ,
void *  ,
int  ,
int64   
)
friend

◆ juce_cameraCaptureSessionCaptureStarted

void juce_cameraCaptureSessionCaptureStarted ( int64  ,
bool  ,
void *  ,
void *  ,
int64  ,
int64   
)
friend

◆ juce_cameraCaptureSessionClosed

void juce_cameraCaptureSessionClosed ( int64  ,
void *   
)
friend

◆ juce_cameraCaptureSessionConfigured

void juce_cameraCaptureSessionConfigured ( int64  ,
void *   
)
friend

◆ juce_cameraCaptureSessionConfigureFailed

void juce_cameraCaptureSessionConfigureFailed ( int64  ,
void *   
)
friend

◆ juce_cameraCaptureSessionReady

void juce_cameraCaptureSessionReady ( int64  ,
void *   
)
friend

◆ juce_cameraDeviceStateClosed

void juce_cameraDeviceStateClosed ( int64  )
friend

◆ juce_cameraDeviceStateDisconnected

void juce_cameraDeviceStateDisconnected ( int64  )
friend

◆ juce_cameraDeviceStateError

void juce_cameraDeviceStateError ( int64  ,
int   
)
friend

◆ juce_cameraDeviceStateOpened

void juce_cameraDeviceStateOpened ( int64  ,
void *   
)
friend

◆ juce_deviceOrientationChanged

void juce_deviceOrientationChanged ( int64  ,
int   
)
friend

◆ ViewerComponent

friend struct ViewerComponent
friend

Member Data Documentation

◆ name

String juce::CameraDevice::name
private

◆ onErrorOccurred

std::function<void (const String& )> juce::CameraDevice::onErrorOccurred

Set this callback to be notified whenever an error occurs.

You may need to close and reopen the device to be able to use it further.

◆ pimpl

std::unique_ptr<Pimpl> juce::CameraDevice::pimpl
private

The documentation for this class was generated from the following file: