TVICameraSource Class Reference

Inherits from NSObject
Conforms to TVIVideoSource
Declared in TVICameraSource.h

Overview

TVICameraSource is a TVIVideoSource that allows you to preview and stream video from the device cameras. This class manages an AVCaptureSession internally.

– init

Initializes a TVICameraSource with default options. You may set a delegate later if you wish.

- (null_unspecified instancetype)init

Return Value

A TVICameraSource, or nil if one could not be created.

Declared In

TVICameraSource.h

– initWithDelegate:

Initializes a TVICameraSource with a delegate, and default options.

- (nullable instancetype)initWithDelegate:(nullable id<TVICameraSourceDelegate>)delegate

Parameters

delegate

A delegate conforming to TVICameraSourceDelegate, or nil.

Return Value

A TVICameraSource, or nil if one could not be created.

Declared In

TVICameraSource.h

– initWithOptions:delegate:

Initializes a TVICameraSource with all configuration options. This is the designated initializer.

- (nullable instancetype)initWithOptions:(nonnull TVICameraSourceOptions *)options delegate:(nullable id<TVICameraSourceDelegate>)delegate

Parameters

options

A TVICameraSourceOptions instance to configure your source.

delegate

A delegate conforming to TVICameraSourceDelegate, or nil.

Return Value

A TVICameraSource, or nil if one could not be created.

Declared In

TVICameraSource.h

  delegate

The source’s delegate.

@property (nonatomic, weak, nullable) id<TVICameraSourceDelegate> delegate

Declared In

TVICameraSource.h

  device

Returns the device that the source is currently capturing from. This property will be set when invoking TVICameraSourceStartedBlock, and reset to nil immediately before invoking TVICameraSourceStoppedBlock.

@property (nonatomic, strong, readonly, nullable) AVCaptureDevice *device

Declared In

TVICameraSource.h

  previewView

A view which allows you to preview the camera source.

@property (nonatomic, strong, readonly, nullable) TVICameraPreviewView *previewView

Discussion

previewView will be nil unless the source is initialized using [TVICameraSource initWithOptions:delegate:], while setting TVICameraSourceOptions.enablePreview to YES.

Declared In

TVICameraSource.h

– startCaptureWithDevice:

Starts video capture with a device. The video pipeline will start asynchronously after this method returns.

- (void)startCaptureWithDevice:(nonnull AVCaptureDevice *)device

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

Discussion

This method will automatically choose a format that works well with your capture device.

Declared In

TVICameraSource.h

– startCaptureWithDevice:completion:

Starts video capture with a device and a completion handler.

- (void)startCaptureWithDevice:(nonnull AVCaptureDevice *)device completion:(nullable TVICameraSourceStartedBlock)completion

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

completion

A handler block to be called on the main thread once capture has started, or failed to start.

Discussion

This method will automatically choose a format that works well with your capture device.

Declared In

TVICameraSource.h

– startCaptureWithDevice:format:completion:

Starts video capture with a device, format and completion handler.

- (void)startCaptureWithDevice:(nonnull AVCaptureDevice *)device format:(nonnull TVIVideoFormat *)format completion:(nullable TVICameraSourceStartedBlock)completion

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

format

The TVIVideoFormat which the source should use. Must be non-null.

completion

A handler block to be called on the main thread once capture has started, or failed to start.

Discussion

Use this method if you have a specific capture device and format in mind for your use case.

Declared In

TVICameraSource.h

– stopCapture

Stops capture asynchronously.

- (void)stopCapture

Discussion

This method is equivalent to calling [TVICameraSource stopCaptureWithCompletion:] with a nil block.

Declared In

TVICameraSource.h

– stopCaptureWithCompletion:

Stops video capture asynchronously with a completion handler.

- (void)stopCaptureWithCompletion:(nullable TVICameraSourceStoppedBlock)completion

Parameters

completion

A handler block to be called on the main thread once the AVCaptureSession is stopped.

Discussion

Use this method to coordinate your application logic with the stopping of the source’s video pipeline. If you are managing your own AVCaptureSession, you should be able to use it safely after the handler is called.

Declared In

TVICameraSource.h

– selectCaptureDevice:

Reconfigures the source to capture from a new device. The video pipeline will start asynchronously after this method returns.

- (void)selectCaptureDevice:(nonnull AVCaptureDevice *)device

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

Discussion

This method will automatically choose a format that works well with your capture device.

Declared In

TVICameraSource.h

– selectCaptureDevice:completion:

Reconfigures the source to capture from a new device. The video pipeline will start asynchronously after this method returns.

- (void)selectCaptureDevice:(nonnull AVCaptureDevice *)device completion:(nullable TVICameraSourceStartedBlock)completion

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

completion

A handler block to be called on the main thread once configuration has completed, or failed.

Discussion

Use this method if you have a specific capture device and format in mind for your use case.

Declared In

TVICameraSource.h

– selectCaptureDevice:format:completion:

Reconfigures the source to capture from a new device and/or format.

- (void)selectCaptureDevice:(nonnull AVCaptureDevice *)device format:(nonnull TVIVideoFormat *)format completion:(nullable TVICameraSourceStartedBlock)completion

Parameters

device

The AVCaptureDevice which the source should use. Must be non-null.

format

The TVIVideoFormat which the source should use. Must be non-null.

completion

A handler block to be called on the main thread once configuration has completed, or failed.

Discussion

Use this method if you have a specific capture device and format in mind for your use case.

Declared In

TVICameraSource.h

+ captureDeviceForPosition:

Discover an AVCaptureDevice by position.

+ (nullable AVCaptureDevice *)captureDeviceForPosition:(AVCaptureDevicePosition)position

Parameters

position

The position that you want to use, or AVCaptureDevicePositionUnspecified if you don’t care.

Return Value

An AVCaptureDevice of type AVMediaTypeVideo, or nil if one could not be found.

Discussion

If you are on an iOS simulator then you should not expect to discover any devices.

Declared In

TVICameraSource.h

+ captureDeviceForPosition:type:

Discover an AVCaptureDevice by position and type.

+ (nullable AVCaptureDevice *)captureDeviceForPosition:(AVCaptureDevicePosition)position type:(nonnull AVCaptureDeviceType)deviceType

Parameters

position

The position that you want to use, or AVCaptureDevicePositionUnspecified if you don’t care.

deviceType

An AVCaptureDeviceType to further refine your query.

Return Value

An AVCaptureDevice of type AVMediaTypeVideo, or nil if one could not be found.

Discussion

If you are on an iOS simulator then you should not expect to discover any devices. This method uses AVCaptureDeviceDiscoverySession.

Declared In

TVICameraSource.h

+ supportedFormatsForDevice:

Determines the formats that are optimal for video streaming from a given AVCaptureDevice.

+ (nonnull NSOrderedSet<TVIVideoFormat*> *)supportedFormatsForDevice:(nonnull AVCaptureDevice *)captureDevice

Parameters

captureDevice

The AVCaptureDevice that you want to query.

Return Value

An NSOrderedSet containing zero or more TVIVideoFormat objects ordered by increasing size.

Discussion

Use this method in conjunction with [TVICameraSource startCaptureWithDevice:format:completion:] for fine-grained control over video format selection.

Declared In

TVICameraSource.h