AVCaptureAudioDataOutput Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AVFoundation.framework
Availability
Available in iOS 4.0 and later.
Declared in
AVCaptureOutput.h
Related sample code

Overview

AVCaptureAudioDataOutput is a concrete sub-class of AVCaptureOutput that you use, via its delegate, to process audio sample buffers from the audio being captured.

Tasks

Managing the Delegate

Getting and Setting Audio Settings

Properties

sampleBufferCallbackQueue

The queue on which delegate callbacks are invoked (read-only)

@property(nonatomic, readonly) dispatch_queue_t sampleBufferCallbackQueue
Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

sampleBufferDelegate

The capture object’s delegate. (read-only)

@property(nonatomic, readonly) id<AVCaptureAudioDataOutputSampleBufferDelegate> sampleBufferDelegate
Discussion

You use the delegate to manage incoming data.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

Instance Methods

recommendedAudioSettingsForAssetWriterWithOutputFileType:

Specifies the recommended settings for use with an AVAssetWriterInput.

- (NSDictionary *)recommendedAudioSettingsForAssetWriterWithOutputFileType:(NSString *)outputFileType
Parameters
outputFileType

Specifies the UTI of the file type to be written. See File Format UTIs for the defined UTIs.

Return Value

A fully populated dictionary of keys and values that are compatible with AVAssetWriter.

Discussion

The value of this property is an NSDictionary containing values for compression settings keys defined in AV Foundation Audio Settings Constants. This dictionary is suitable for use as the assetWriterInputWithMediaType:outputSettings: method’s outputSettings parameter when creating an AVAssetWriterInputPixelBufferAdaptor, such as,

[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:outputSettings sourceFormatHint:hint];

The dictionary returned contains all necessary keys and values needed to create an AVAssetWriter instance , see the initWithMediaType:outputSettings: method for a more in depth discussion. For QuickTime movie and ISO files, the recommended audio settings will always produce output comparable to that of AVCaptureMovieFileOutput.

The dictionary of settings is dependent on the current configuration of the receiver's AVCaptureSession and its inputs. The settings dictionary may change if the session's configuration changes. As such, you should configure your session first, then query the recommended audio settings.

Availability
  • Available in iOS 7.0 and later.
Declared In
AVCaptureOutput.h

setSampleBufferDelegate:queue:

Sets the delegate that will accept captured buffers and dispatch queue on which the delegate will be called.

- (void)setSampleBufferDelegate:(id<AVCaptureAudioDataOutputSampleBufferDelegate>)sampleBufferDelegate queue:(dispatch_queue_t)sampleBufferCallbackQueue
Parameters
sampleBufferDelegate

An object conforming to the AVCaptureAudioDataOutputSampleBufferDelegate protocol that will receive sample buffers after they are captured..

sampleBufferCallbackQueue

You must pass a serial dispatch to guarantee that audio samples will be delivered in order.

The value may not be NULL, except when setting the sampleBufferDelegate to nil.

Discussion

When a new audio sample buffer is captured it is vended to the sample buffer delegate using the captureOutput:didOutputSampleBuffer:fromConnection: delegate method. All delegate methods are called on the specified dispatch queue.

If the queue is blocked when new samples are captured, those samples will be automatically dropped when they become sufficiently late. This allows you to process existing samples on the same queue without having to manage the potential memory usage increases that would otherwise occur when that processing is unable to keep up with the rate of incoming samples.

If you need to minimize the chances of samples being dropped, you should specify a queue on which a sufficiently small amount of processing is being done outside of receiving sample buffers. When migrating extra processing to another queue, you are responsible for ensuring that memory usage does not grow without bound from samples that have not been processed.

Special Considerations

This method uses dispatch_retain and dispatch_release to manage the queue.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
AVCaptureOutput.h