HVTCamera Class Reference
Inherits from | NSObject |
---|---|
Declared in | HVTCamera.h |
Overview
You can use a HVTCamera object to establish a connection with the device camera, update the attached preview(s) and record to an audio/video container file.
When HVTcamera is running, it processes the flow of data from the camera device in real time, by utilizing the internal leveler and applying filters. You can alter the leveler’s settings using the provided properties. Some properties are animated and can be changed even while recording without producing rough transitions in the resulting video.
Usage
A simple usage scenario of the class requires the following steps in that particular order:
- Instantiate a HVTCamera object.
- Set the interfaceOrientation property.
- (Optional) Implement and set a HVTCameraDelegate object.
- If you want to display the video preview, you can attach one or more HVTView objects by calling addView:.
- Invoke startRunning. Make sure you have handled all the camera & microphone permissions first.
- Invoke startRecordingWithMovieURL: to start recording to a QuickTime movie file.
- Invoke stopRecording.
- Invoke stopRunning.
Camera resolution
HVTCamera receives video frames from an AVCaptureDevice instance, which can be accessed by the cameraDevice
property. You can query the supported resolutions using AVCaptureDevice
’s formats
property.
By default, the resolution used is the one set in the AVCaptureDevice
’s activeFormat
property. If you want to
set a specific resolution, use one of the methods provided by HVTCamera and not the AVFoundation
’s methods.
If you set the resolution or/and frame rate while HVTCamera isRunning, the connection to the deviceCamera will be reset, which can take some time. The call will block until the connection has been established. So set the resolution before calling startRunning if possible.
Performance Considerations
For performance reasons, the maximum supported resolution and frame rate are 1920X1080 and 60 frames/sec respectively. In some devices, it is recommended to use a lower resolution. For example, prefer 1280X720 in iPhone 4S.
The use of video filters can significantly impact performance.
Warning: A single instance of HVTCamera must be running at any time.
Setting the Delegate
delegate
The delegate object.
@property (nonatomic, weak) id<HVTCameraDelegate> delegate
Discussion
Set a delegate object, in order to get updates on HVTCamera object’s status.
The delegate is not retained.
See Also
Declared In
HVTCamera.h
– setSampleBufferDelegate:queue:
Sets the receiver’s delegate that will accept audio & (leveled) video buffers and a dispatch queue on which the delegate will be called.
- (void)setSampleBufferDelegate:(id<HVTBufferDelegate>)sampleBufferDelegate queue:(dispatch_queue_t)sampleBufferCallbackQueue
Parameters
sampleBufferDelegate |
An object conforming to the HVTBufferDelegate protocol that will receive sample buffers. |
---|---|
sampleBufferCallbackQueue |
A dispatch queue on which all sample buffer delegate method will be called. |
Declared In
HVTCamera.h
Configuration
interfaceOrientation
Set this property to the current orientation of the app’s user interface.
@property (nonatomic) UIInterfaceOrientation interfaceOrientation
Discussion
HVTCamera will adjust the orientation of the attached HVTView(s) and the angle returned by [HVTCameraDelegate hvtCamera:didUpdateParams:] to match the supplied interface orientation.
If your app supports multiple orientations, subscribe to the UIDeviceOrientationDidChangeNotification
and set the property as shown in the following code fragment:
For iOS 8 devices:
// When you receive a UIDeviceOrientationDidChangeNotification:
_camera.interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
For iOS 7 devices:
// When you receive a UIDeviceOrientationDidChangeNotification:
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (deviceOrientation == UIDeviceOrientationPortrait
|| deviceOrientation == UIDeviceOrientationLandscapeLeft
|| deviceOrientation == UIDeviceOrientationLandscapeRight) {
_camera._hvtCameraInstance.interfaceOrientation = (UIInterfaceOrientation)deviceOrientation;
}
The default value is UIInterfaceOrientationPortrait
.
Declared In
HVTCamera.h
Managing Running State
– isRunning
Indicates whether the receiver is running.
- (BOOL)isRunning
Return Value
YES
if the receiver is running and NO
if it is stopped.
Declared In
HVTCamera.h
– startRunning
Tells the receiver to start running.
- (void)startRunning
Discussion
Starts the flow of data from the camera device. If HVTView(s) have been added, they will receive updates when new video frames arrive. You can also start video recording.
If the receiver stops running due to an error, it will call the delegate’s [HVTCameraDelegate hvtCamera:didStopRunningWithError:] method.
This call blocks until the receiver has completely started up.
Declared In
HVTCamera.h
– stopRunning
Tells the receiver to stop running.
- (void)stopRunning
Discussion
Call this method to conserve battery life if you don’t need to update the attached HVTView(s) or if you are not recording.
You don’t need to call this explicitly when the apps goes to background. The HVTCamera instance will stop running automatically and resume upon entering foreground.
This call blocks until the receiver has completely stopped.
Declared In
HVTCamera.h
Previewing the Video
Recording Video
outputMovieSize
Specifies the output movie size of the final video file.
@property (nonatomic) CGSize outputMovieSize
Discussion
The outputMovieSize can differ from the cameraResolution. For example, you can have a 1920x1080 camera resolution and a 640x640 final video file.
The default value matches the cameraResolution, until set explicetely via this property.
outputMovieSize cannot be set if the captureMode is set to HVTCaptureModePhoto.
See Also
- setOutputMovieSize:error: For a more fine grained control on whether the property has been successfully set or not.
It is recommended that you call this property setter (or the
setOutputMovieSize:error:
method after setting up the resolution.
Declared In
HVTCamera.h
– setOutputMovieSize:error:
Specifies the output movie size of the final video file, providing more info about whether the method had succeeded or not.
- (BOOL)setOutputMovieSize:(CGSize)outputMovieSize error:(NSError **)outError
Parameters
outputMovieSize |
The desired output movie size |
---|---|
outError |
The error object in case that setting the size was unsuccessful |
Return Value
YES if the outputMovieSize has been set, NO otherwise
Discussion
For example outputMovieSize cannot be set if the captureMode is set
to HVTCaptureModePhoto. If you call just the property setter (setOutputMovieSize:
)
you will not get an error if the method doesn’t allow you to set this
property while in photo mode.
This method will return NO and provide and NSError about it.
Declared In
HVTCamera.h
– isRecording
Reports whether the instance is currently recording video or not.
- (BOOL)isRecording
Return Value
YES
if video recording occures and NO
if it isn’t.
Declared In
HVTCamera.h
– startRecordingWithMovieURL:
Starts the video recording.
- (void)startRecordingWithMovieURL:(NSURL *)movieURL
Parameters
movieURL |
The URL of the output file in which the video will be saved. |
---|
Discussion
You must call this method only if the instance isRunning, or an exception is thrown.
Declared In
HVTCamera.h
– startRecordingWithMovieURL:videoSettings:audioSettings:metadata:
Starts the video recording.
- (void)startRecordingWithMovieURL:(NSURL *)movieURL videoSettings:(NSDictionary *)videoSettings audioSettings:(NSDictionary *)audioSettings metadata:(NSArray *)metadata
Parameters
movieURL |
The URL of the output file in which the video will be saved. |
---|---|
videoSettings |
The settings used for video encoding. See AVVideoSettings.h for more information on how to construct an output settings dictionary. If you only require simple preset-based output settings, see AVOutputSettingsAssistant. Can be |
audioSettings |
The settings used for audio encoding. See AVAudioSettings.h for more information. If you only require simple preset-based output settings, see AVOutputSettingsAssistant. Can be |
metadata |
NSArray of AVMetadataItems that are to be written to the output file by the export session. If the value of this key is nil, any existing metadata in the exported asset will be translated as accurately as possible into the appropriate metadata keyspace for the output file and written to the output. Can be |
Discussion
You must call this method only if the instance isRunning, or an exception is thrown.
Declared In
HVTCamera.h
– isPaused
Reports whether the recording is currently paused
- (BOOL)isPaused
Return Value
YES
if video recording is paused and NO
if it isn’t.
Declared In
HVTCamera.h
– recorderVideoBitRate
Returns the video bitrate of the currently active recorder
- (int)recorderVideoBitRate
Return Value
The video bitrate.
Discussion
If the video recorder is not active, this method returns 0.
Declared In
HVTCamera.h
– recorderAudioBitRate
Returns the audio bitrate of the currently active recorder
- (int)recorderAudioBitRate
Return Value
The audio bitrate.
Discussion
If the video recorder is not active, this method returns 0.
Declared In
HVTCamera.h
Managing Photo Capture
stillImageOrientation
Handles the still image frame for photo mode
@property (nonatomic) HVTStillImageOrientation stillImageOrientation
See Also
Declared In
HVTCamera.h
– setGPSMetadata:
Sets the GPS metadata that can be used for photos
- (void)setGPSMetadata:(NSDictionary *)gpsMetadata
Parameters
gpsMetadata |
The dictionary containing GPS coordinates, conforming kCGImagePropertyGPSDictionary |
---|
Declared In
HVTCamera.h
– captureFullResolutionPhoto
Shoots a full resolution photo.
- (BOOL)captureFullResolutionPhoto
Return Value
NO
if another photo capture is in progress or if photo capturing is not supported and YES
otherwise
Discussion
If used while recording then you will receive a HVTErrorPhotoModeNotEnabled error by the hvtCamera:photoCapturingDidFailWithError: delegate method.
While recording, you can use the captureSnapshot method to take photos.
Declared In
HVTCamera.h
– captureFullResolutionPhotoUsingHDR:
Shoots a full resolution photo.
- (BOOL)captureFullResolutionPhotoUsingHDR:(BOOL)usingHDR
Parameters
usingHDR |
Capture HDR photo |
---|
Return Value
NO
if another photo capture is in progress and YES
otherwise
Discussion
If used while recording then you will hear the shutter sound.
If used while recording then you will receive a HVTErrorPhotoModeNotEnabled error by the hvtCamera:photoCapturingDidFailWithError: delegate method.
While recording, you can use the captureSnapshot method to take photos.
Declared In
HVTCamera.h
– captureSnapshot
Shoots a snapshot photo, right from the video stream. It can be used while recording
- (BOOL)captureSnapshot
Return Value
NO
if another photo capture is in progress and YES
otherwise
Declared In
HVTCamera.h
– isHDRPhotoCaptureAvailable
Returns if the device can capture full resoltion still image HDR photos
- (BOOL)isHDRPhotoCaptureAvailable
Return Value
YES
if HDR photo capture is available, NO
otherwise
Declared In
HVTCamera.h
Managing the Camera Settings
cameraDevice
The currently active AVFoundation device.
@property (nonatomic, readonly) AVCaptureDevice *cameraDevice
Discussion
You can change the camera device properties by first calling the AVCaptureDevice’s lockForConfiguration: method.
Warning: If you want to alter the camera resolution or framerate, do not alter the activeFormat, activeVideoMinFrameDuration or activeVideoMaxFrameDuration properties of the AVFoundation
device. Instead, use the methods supplied by HVTCamera.
Declared In
HVTCamera.h
captureMode
The capture mode used by the camera.
@property (nonatomic) HVTCaptureMode captureMode
Discussion
The two capture modes are listed in the HVTCaptureMode enumeration. The default value is HVTCaptureModeVideo.
Capture mode changes automatically to HVTCaptureModeVideo value when setCameraResolution:error: or setCameraResolution:frameRate:error: methods are called
See Also
Declared In
HVTCamera.h
– setCaptureMode:cameraPosition:
Sets a new capture mode with a specified camera position.
- (void)setCaptureMode:(HVTCaptureMode)captureMode cameraPosition:(AVCaptureDevicePosition)newPosition
Parameters
captureMode |
The new capture mode. |
---|---|
newPosition |
The new camera position. |
See Also
Declared In
HVTCamera.h
flashMode
The current flash mode
@property (nonatomic) AVCaptureFlashMode flashMode
Discussion
You can set or query the current flash mode using this property. Horizon SDK takes care of the availability and the separation between torch/flash for you
Declared In
HVTCamera.h
outputPixelFormat
The pixel format used for the exported videos and frames by the hvtCamera:didOutputSampleBuffer: method.
@property (nonatomic) FourCharCode outputPixelFormat
Discussion
The default value is kCVPixelFormatType_32BGRA.
You can enter only the following two values for the outputPixelFormat:
kCVPixelFormatType_32BGRA and kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
Declared In
HVTCamera.h
brightnessValue
The brightness value, indicating how dark or bright the scene currently is.
@property (nonatomic, readonly) float brightnessValue
Discussion
The value can be negative (for dark scenes) or positive (for bright scenes) and is updated in real-time.
You can observe the changes to this value using KVO.
e.g.
[self addObserver:self
forKeyPath:@"_camera.brightnessValue"
options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
context:(__bridge void *)(self)];
Declared In
HVTCamera.h
– resetFocusExposureWhiteBalance
Clears any focus/exposure/white balance setting that may have been applied by the user, returning them to AVCaptureFocusModeContinuousAutoFocus, AVCaptureExposureModeContinuousAutoExposure and AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance values
- (void)resetFocusExposureWhiteBalance
Declared In
HVTCamera.h
+ isCameraPositionSupported:
Indicated whether the AVCaptureDevicePosition in question is supported by the current device.
+ (BOOL)isCameraPositionSupported:(AVCaptureDevicePosition)cameraPosition
Parameters
cameraPosition |
The camera position in question. |
---|
Return Value
YES if device supports the said AVCaptureDevicePosition, NO otherwise
Discussion
This is a class method so you can use it without first instanciating the HVTCamera object.
Declared In
HVTCamera.h
– isFlashAvailable
Indicates whether a given camera has flash illumination capability.
- (BOOL)isFlashAvailable
Return Value
YES if device has flash and it is available in HVTCaptureModePhoto or if it has torch and it is available in HVTCaptureModeVideo, NO otherwise
Discussion
To get notified on changes on the property, subscribe to receive NSNotifications with HVTFlashIsAvailableNotification name.
Declared In
HVTCamera.h
– cameraResolution
Reports the camera resolution for the current cameraDevice.
- (CGSize)cameraResolution
Return Value
The camera resolution as a CGSize struct.
Declared In
HVTCamera.h
– setCameraResolution:error:
Sets the camera resolution of the current cameraDevice. Frame rate is set to 30 frames/sec.
- (BOOL)setCameraResolution:(CGSize)cameraResolution error:(NSError **)outError
Parameters
cameraResolution |
The new camera resolution. |
---|---|
outError |
The output error. |
Return Value
YES
if the camera resolution has been changed and NO
if there was an error while changing the camera resolution (check outError for more).
Discussion
Warning: If you call the method while the receiver isRunning, the connection to the deviceCamera will be reset, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– setCameraResolution:frameRate:error:
Sets the camera resolution and frame rate of the current cameraDevice.
- (BOOL)setCameraResolution:(CGSize)cameraResolution frameRate:(int)frameRate error:(NSError **)outError
Parameters
cameraResolution |
The new camera resolution. |
---|---|
frameRate |
The new frame rate. |
outError |
The output error. |
Return Value
YES
if the camera resolution has been changed and NO
if there was an error while changing the camera
resolution (check outError for more).
Discussion
Warning: If you call the method while the receiver isRunning, the connection to the deviceCamera will be reset, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– cameraPosition
Reports the camera position of the current cameraDevice.
- (AVCaptureDevicePosition)cameraPosition
Return Value
The position of the camera as a value of AVCaptureDevicePosition.
Declared In
HVTCamera.h
– setCameraPosition:error:
Selects a cameraDevice having the supplied camera position.
- (BOOL)setCameraPosition:(AVCaptureDevicePosition)newPosition error:(NSError **)outError
Parameters
newPosition |
The new camera position. |
---|---|
outError |
The output error. |
Return Value
YES
if the camera position has been changed and NO
if there was an error while changing the camera position
(check outError for more).
Discussion
The camera resolution and frame rate of the cameraDevice is set to its default value or to its previous value if it was explicetely set before.
Warning: If you call the method while the receiver isRunning, a connection to the new cameraDevice will be established, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– setCameraPosition:withResolution:error:
Selects a cameraDevice having the supplied camera position and sets its resolution. Frame rate is set to 30 frames/sec.
- (BOOL)setCameraPosition:(AVCaptureDevicePosition)newPosition withResolution:(CGSize)cameraResolution error:(NSError **)outError
Parameters
newPosition |
The new camera position. |
---|---|
cameraResolution |
The new camera resolution. |
outError |
The output error. |
Return Value
YES
if the camera resolution has been changed and NO
if there was an error while changing the camera resolution
(check outError for more).
Discussion
Warning: If you call the method while the receiver isRunning, a connection to the new cameraDevice will be established, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– setCameraPosition:withResolution:frameRate:error:
Selects a cameraDevice having the supplied camera position and sets its resolution and frame rate.
- (BOOL)setCameraPosition:(AVCaptureDevicePosition)newPosition withResolution:(CGSize)cameraResolution frameRate:(int)frameRate error:(NSError **)outError
Parameters
newPosition |
The new camera position. |
---|---|
cameraResolution |
The new camera resolution. |
frameRate |
The new frame rate. |
outError |
The output error. |
Return Value
YES
if the camera resolution has been changed and NO
if there was an error while changing the camera resolution
(check outError for more).
Discussion
Warning: If you call the method while the receiver isRunning, a connection to the new cameraDevice will be established, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– setCaptureDevice:error:
Sets a specific camera device provided by the user.
- (BOOL)setCaptureDevice:(AVCaptureDevice *)captureDevice error:(NSError **)outError
Parameters
captureDevice |
The new capture device |
---|---|
outError |
The output error |
Return Value
YES
if the camera device has been changed and NO
if there was an error while changing the camera device
Discussion
Warning: If you call the method while the receiver isRunning, a connection to the new cameraDevice will be established, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
– setCaptureDevice:resolution:frameRate:error:
Sets a specific camera device with a given resolution and framerate provided by the user.
- (BOOL)setCaptureDevice:(AVCaptureDevice *)captureDevice resolution:(CGSize)cameraResolution frameRate:(int)frameRate error:(NSError **)outError
Parameters
captureDevice |
The new capture device |
---|---|
cameraResolution |
The new camera resolution. |
frameRate |
The new frame rate. |
outError |
The output error. |
Return Value
YES
if the camera resolution has been changed and NO
if there was an error while changing the camera resolution
(check outError for more).
Discussion
Warning: If you call the method while the receiver isRunning, a connection to the new cameraDevice will be established, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
Managing the Video Stabilization Settings
– isVideoStabilizationModeSupported:
Returns whether the current cameraDevice supports the given video stabilization mode.
- (BOOL)isVideoStabilizationModeSupported:(AVCaptureVideoStabilizationMode)videoStabilizationMode
Parameters
videoStabilizationMode |
An AVCaptureVideoStabilizationMode to be checked. |
---|
Return Value
A boolean value indicating whether the current cameraDevice can be stabilized by setting preferredVideoStabilizationMode to the given mode. .
Discussion
This methdod is a wrapper of AVCaptureDeviceFormat
’s isVideoStabilizationModeSupported:
method. It will not
work on an iOS7 runtime.
Declared In
HVTCamera.h
preferredVideoStabilizationMode
Indicates the prefered stabilization mode to apply when supported by the current cameraDevice.
@property (nonatomic) AVCaptureVideoStabilizationMode preferredVideoStabilizationMode
Discussion
This property is a wrapper of AVCaptureConnection
’s preferredVideoStabilizationMode
property for iOS8 devices.
In iOS7 devices, it sets AVCaptureConnection
’s setEnablesVideoStabilizationWhenAvailable
to YES
when the
preferredVideoStablizationMode is anything but AVCaptureVideoStabilizationModeOff
.
The default value is AVCaptureVideoStabilizationModeOff
.
Warning: If you set the property while the receiver isRunning, the connection to the deviceCamera will be reset, which can take some time. The call will block until the connection has been established.
Declared In
HVTCamera.h
maxRecordingDuration
Maximum recording duration set by the user. If set and the recording gets past this duration, then it is automatically stopped.
@property (nonatomic) CMTime maxRecordingDuration
Discussion
Every recording made after setting this property to a valid CMTime will respect the maxRecordingDuration In order to return to unlimited recording, user can set this property value to kCMTimeInvalid
Declared In
HVTCamera.h
Managing the Leveler Settings
levelerCropMode
Specifies which crop mode will be used by the leveler.
@property (nonatomic) HVTLevelerCropMode levelerCropMode
Discussion
The leveler crops each video frame so that the resulting frame is leveled. This involves rotating and scaling the crop region, prior to cropping the frame, according to the device’s physical orientation at that time. The crop mode is the way the leveler adjusts the rotation and scale of the crop region.
Note that scaling the crop region equals to zooming in the original video frame.
The property is animated.
The default value is HVTLevelerCropModeFlex
.
See Also
Declared In
HVTCamera.h
levelerFlexSpeed
Specifies how fast the leveler zooms when HVTLevelerCropMode is set to HVTLevelerCropModeFlex
.
@property (nonatomic) HVTLevelerFlexSpeed levelerFlexSpeed
Discussion
The default value is HVTLevelerFlexSpeedSmooth
.
See Also
Declared In
HVTCamera.h
levelerLockedOrientation
Informs the leveler of the expected device orientation when HVTLevelerCropMode is set
to HVTLevelerCropModeLocked
.
@property (nonatomic) HVTLevelerLockedOrientation levelerLockedOrientation
Discussion
Since leveling is disabled when crop mode is HVTLevelerCropModeLocked
, this property should match the device’s physical
orientation. For example, if the user is intented to hold the device vertically, use HVTLevelerLockedOrientationVertical
.
However, if the user decides to turn the device horizontally, the recorded video’s orientation will be wrong.
The property is animated.
The default value is HVTLevelerLockedOrientationAuto
.
Warning: This does not control whether the recorded video will be landscape or portrait. This depends on the aspect ratio of outputMovieSize.
See Also
Declared In
HVTCamera.h
Managing Video Filters
– setActiveFilter:
Sets a custom CIFilter to be applied on the camera stream.
- (void)setActiveFilter:(CIFilter *)filter
Parameters
filter |
The CIFilter to be applied |
---|
Discussion
The active filter is applied after the Leveler corrects the video orientation.
Declared In
HVTCamera.h