objc2_av_foundation/generated/AVCaptureAudioDataOutput.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8#[cfg(feature = "objc2-core-audio-types")]
9use objc2_core_audio_types::*;
10#[cfg(feature = "objc2-core-media")]
11use objc2_core_media::*;
12use objc2_foundation::*;
13
14use crate::*;
15
16extern_class!(
17 /// AVCaptureAudioDataOutput is a concrete subclass of AVCaptureOutput that can be used to process uncompressed or compressed samples from the audio being captured.
18 ///
19 ///
20 /// Instances of AVCaptureAudioDataOutput produce audio sample buffers suitable for processing using other media APIs. Applications can access the sample buffers with the captureOutput:didOutputSampleBuffer:fromConnection: delegate method.
21 ///
22 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avcaptureaudiodataoutput?language=objc)
23 #[unsafe(super(AVCaptureOutput, NSObject))]
24 #[derive(Debug, PartialEq, Eq, Hash)]
25 #[cfg(feature = "AVCaptureOutputBase")]
26 pub struct AVCaptureAudioDataOutput;
27);
28
29#[cfg(feature = "AVCaptureOutputBase")]
30extern_conformance!(
31 unsafe impl NSObjectProtocol for AVCaptureAudioDataOutput {}
32);
33
34#[cfg(feature = "AVCaptureOutputBase")]
35impl AVCaptureAudioDataOutput {
36 extern_methods!(
37 #[unsafe(method(init))]
38 #[unsafe(method_family = init)]
39 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
40
41 #[unsafe(method(new))]
42 #[unsafe(method_family = new)]
43 pub unsafe fn new() -> Retained<Self>;
44
45 #[cfg(feature = "dispatch2")]
46 /// Sets the receiver's delegate that will accept captured buffers and dispatch queue on which the delegate will be called.
47 ///
48 ///
49 /// Parameter `sampleBufferDelegate`: An object conforming to the AVCaptureAudioDataOutputSampleBufferDelegate protocol that will receive sample buffers after they are captured.
50 ///
51 /// Parameter `sampleBufferCallbackQueue`: A dispatch queue on which all sample buffer delegate methods will be called.
52 ///
53 ///
54 /// When a new audio sample buffer is captured it will be vended to the sample buffer delegate using the captureOutput:didOutputSampleBuffer:fromConnection: delegate method. All delegate methods will be 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 clients 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.
55 ///
56 /// Clients that need to minimize the chances of samples being dropped should specify a queue on which a sufficiently small amount of processing is being done outside of receiving sample buffers. However, if such clients migrate extra processing to another queue, they are responsible for ensuring that memory usage does not grow without bound from samples that have not been processed.
57 ///
58 /// A serial dispatch queue must be used to guarantee that audio samples will be delivered in order. The sampleBufferCallbackQueue parameter may not be NULL, except when setting sampleBufferDelegate to nil otherwise -setSampleBufferDelegate:queue: throws an NSInvalidArgumentException.
59 ///
60 /// # Safety
61 ///
62 /// `sample_buffer_callback_queue` possibly has additional threading requirements.
63 #[unsafe(method(setSampleBufferDelegate:queue:))]
64 #[unsafe(method_family = none)]
65 pub unsafe fn setSampleBufferDelegate_queue(
66 &self,
67 sample_buffer_delegate: Option<
68 &ProtocolObject<dyn AVCaptureAudioDataOutputSampleBufferDelegate>,
69 >,
70 sample_buffer_callback_queue: Option<&DispatchQueue>,
71 );
72
73 /// The receiver's delegate.
74 ///
75 ///
76 /// The value of this property is an object conforming to the AVCaptureAudioDataOutputSampleBufferDelegate protocol that will receive sample buffers after they are captured. The delegate is set using the setSampleBufferDelegate:queue: method.
77 #[unsafe(method(sampleBufferDelegate))]
78 #[unsafe(method_family = none)]
79 pub unsafe fn sampleBufferDelegate(
80 &self,
81 ) -> Option<Retained<ProtocolObject<dyn AVCaptureAudioDataOutputSampleBufferDelegate>>>;
82
83 #[cfg(feature = "dispatch2")]
84 /// The dispatch queue on which all sample buffer delegate methods will be called.
85 ///
86 ///
87 /// The value of this property is a dispatch_queue_t. The queue is set using the setSampleBufferDelegate:queue: method.
88 #[unsafe(method(sampleBufferCallbackQueue))]
89 #[unsafe(method_family = none)]
90 pub unsafe fn sampleBufferCallbackQueue(&self) -> Option<Retained<DispatchQueue>>;
91
92 /// Specifies the settings used to decode or re-encode audio before it is output by the receiver.
93 ///
94 ///
95 /// The value of this property is an NSDictionary containing values for audio settings keys defined in AVAudioSettings.h. When audioSettings is set to nil, the AVCaptureAudioDataOutput vends samples in their device native format.
96 #[unsafe(method(audioSettings))]
97 #[unsafe(method_family = none)]
98 pub unsafe fn audioSettings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
99
100 /// Setter for [`audioSettings`][Self::audioSettings].
101 ///
102 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
103 ///
104 /// # Safety
105 ///
106 /// `audio_settings` generic should be of the correct type.
107 #[unsafe(method(setAudioSettings:))]
108 #[unsafe(method_family = none)]
109 pub unsafe fn setAudioSettings(
110 &self,
111 audio_settings: Option<&NSDictionary<NSString, AnyObject>>,
112 );
113
114 #[cfg(feature = "objc2-core-audio-types")]
115 /// The audio channel layout tag of the audio sample buffers produced by the audio data output.
116 ///
117 /// When you set your audio data output's associated ``AVCaptureDeviceInput/multichannelAudioMode`` property to ``AVCaptureMultichannelAudioModeFirstOrderAmbisonics``, the ``AVCaptureSession`` allows up to two ``AVCaptureAudioDataOutput`` instances to be connected to the First-order Ambisonsics (FOA) input. If you connect a single ``AVCaptureAudioDataOutput`` instance, you must configure its ``AVCaptureAudioDataOutput/spatialAudioChannelLayoutTag`` property to produce either four channels of FOA audio or two channels of Stereo audio. If you connect two ``AVCaptureAudioDataOutput`` instances, you must configure one to output four channels of FOA audio and the other to output two channels of Stereo audio.
118 ///
119 /// Thus, when you set your associated ``AVCaptureDeviceInput/multichannelAudioMode`` property to ``AVCaptureMultichannelAudioModeFirstOrderAmbisonics``, you must set your connected ``AVCaptureAudioDataOutput`` instance's ``AVCaptureAudioDataOutput/spatialAudioChannelLayoutTag`` property to either `kAudioChannelLayoutTag_Stereo` for stereo, or `(kAudioChannelLayoutTag_HOA_ACN_SN3D | 4)` for FOA (see
120 /// <doc
121 /// ://com.apple.documentation/documentation/coreaudiotypes/audiochannellayouttag>). When you set your associated ``AVCaptureDeviceInput/multichannelAudioMode`` to any other value, the ``AVCaptureSession`` only supports one ``AVCaptureAudioDataOutput``, and you may only set ``AVCaptureAudioDataOutput/spatialAudioChannelLayoutTag`` to `kAudioChannelLayoutTag_Unknown` (the default value).
122 ///
123 /// Your ``AVCaptureSession`` validates your app's adherence to the the above rules when you call ``AVCaptureSession/startRunning:`` or ``AVCaptureSession/commitConfiguration`` and throws a `NSInvalidArgumentException` if necessary.
124 #[unsafe(method(spatialAudioChannelLayoutTag))]
125 #[unsafe(method_family = none)]
126 pub unsafe fn spatialAudioChannelLayoutTag(&self) -> AudioChannelLayoutTag;
127
128 #[cfg(feature = "objc2-core-audio-types")]
129 /// Setter for [`spatialAudioChannelLayoutTag`][Self::spatialAudioChannelLayoutTag].
130 #[unsafe(method(setSpatialAudioChannelLayoutTag:))]
131 #[unsafe(method_family = none)]
132 pub unsafe fn setSpatialAudioChannelLayoutTag(
133 &self,
134 spatial_audio_channel_layout_tag: AudioChannelLayoutTag,
135 );
136
137 #[cfg(feature = "AVMediaFormat")]
138 /// Specifies the recommended settings for use with an AVAssetWriterInput.
139 ///
140 ///
141 /// Parameter `outputFileType`: Specifies the UTI of the file type to be written (see AVMediaFormat.h for a list of file format UTIs).
142 ///
143 /// Returns: A fully populated dictionary of keys and values that are compatible with AVAssetWriter.
144 ///
145 ///
146 /// The value of this property is an NSDictionary containing values for compression settings keys defined in AVAudioSettings.h. This dictionary is suitable for use as the "outputSettings" parameter when creating an AVAssetWriterInput, such as,
147 ///
148 /// [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:outputSettings sourceFormatHint:hint];
149 ///
150 /// The dictionary returned contains all necessary keys and values needed by AVAssetWriter (see AVAssetWriterInput.h, -initWithMediaType:outputSettings: 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.
151 ///
152 /// Note that 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.
153 #[unsafe(method(recommendedAudioSettingsForAssetWriterWithOutputFileType:))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn recommendedAudioSettingsForAssetWriterWithOutputFileType(
156 &self,
157 output_file_type: &AVFileType,
158 ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>;
159 );
160}
161
162extern_protocol!(
163 /// Defines an interface for delegates of AVCaptureAudioDataOutput to receive captured audio sample buffers.
164 ///
165 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avcaptureaudiodataoutputsamplebufferdelegate?language=objc)
166 pub unsafe trait AVCaptureAudioDataOutputSampleBufferDelegate: NSObjectProtocol {
167 #[cfg(all(
168 feature = "AVCaptureOutputBase",
169 feature = "AVCaptureSession",
170 feature = "objc2-core-media"
171 ))]
172 /// Called whenever an AVCaptureAudioDataOutput instance outputs a new audio sample buffer.
173 ///
174 ///
175 /// Parameter `output`: The AVCaptureAudioDataOutput instance that output the samples.
176 ///
177 /// Parameter `sampleBuffer`: A CMSampleBuffer object containing the audio samples and additional information about them, such as their format and presentation time.
178 ///
179 /// Parameter `connection`: The AVCaptureConnection from which the audio was received.
180 ///
181 ///
182 /// Delegates receive this message whenever the output captures and outputs new audio samples, decoding or re-encoding as specified by the audioSettings property. Delegates can use the provided sample buffer in conjunction with other APIs for further processing. This method will be called on the dispatch queue specified by the output's sampleBufferCallbackQueue property. This method is called periodically, so it must be efficient to prevent capture performance problems, including dropped audio samples.
183 ///
184 /// Clients that need to reference the CMSampleBuffer object outside of the scope of this method must CFRetain it and then CFRelease it when they are finished with it.
185 #[optional]
186 #[unsafe(method(captureOutput:didOutputSampleBuffer:fromConnection:))]
187 #[unsafe(method_family = none)]
188 unsafe fn captureOutput_didOutputSampleBuffer_fromConnection(
189 &self,
190 output: &AVCaptureOutput,
191 sample_buffer: &CMSampleBuffer,
192 connection: &AVCaptureConnection,
193 );
194 }
195);