objc2_av_foundation/generated/
AVSampleBufferGenerator.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-media")]
7use objc2_core_media::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebuffergenerator?language=objc)
14    #[unsafe(super(NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    pub struct AVSampleBufferGenerator;
17);
18
19unsafe impl Send for AVSampleBufferGenerator {}
20
21unsafe impl Sync for AVSampleBufferGenerator {}
22
23extern_conformance!(
24    unsafe impl NSObjectProtocol for AVSampleBufferGenerator {}
25);
26
27impl AVSampleBufferGenerator {
28    extern_methods!(
29        #[unsafe(method(init))]
30        #[unsafe(method_family = init)]
31        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
32
33        #[unsafe(method(new))]
34        #[unsafe(method_family = new)]
35        pub unsafe fn new() -> Retained<Self>;
36
37        #[cfg(all(feature = "AVAsset", feature = "objc2-core-media"))]
38        /// Creates an instance of AVSampleBufferGenerator to generate sample buffers from the specified asset.
39        ///
40        /// Parameter `asset`: The asset from which sample buffers will be created.
41        ///
42        /// Parameter `timebase`: The generator timebase, which governs when sample data for sample buffers is loaded. If NULL, sample data is loaded synchronously.
43        ///
44        /// Returns: An instance of AVSampleBufferGenerator.
45        ///
46        /// If the specified asset is an HTTP Live Streaming asset, the generator cannot create sample buffers.
47        #[unsafe(method(initWithAsset:timebase:))]
48        #[unsafe(method_family = init)]
49        pub unsafe fn initWithAsset_timebase(
50            this: Allocated<Self>,
51            asset: &AVAsset,
52            timebase: Option<&CMTimebase>,
53        ) -> Retained<Self>;
54
55        #[cfg(feature = "objc2-core-media")]
56        /// Creates a sample buffer and if requested, attempts to load its data asynchronously. Attempt may fail based on generator configuration or file format.
57        /// See [AVSampleBufferGenerator notifyOfDataReadyForSampleBuffer: completionHandler:] to get notified when the sample buffer data is available.
58        ///
59        /// Parameter `request`: An instance of AVSampleBufferRequest representing the CMSampleBuffer creation request.
60        ///
61        /// Parameter `outError`: A pointer to an NSError object that will be populated with failure information, if sample buffer creation fails.
62        ///
63        /// Returns: A CMSampleBuffer object referencing the output sample buffer.
64        ///
65        /// If the AVSampleBufferGenerator was created with a NULL timebase, any associated AVSampleBufferRequest will default to using AVSampleBufferRequestModeImmediate.
66        #[unsafe(method(createSampleBufferForRequest:error:_))]
67        // required for soundness, method has `returns_retained` attribute.
68        #[unsafe(method_family = copy)]
69        pub unsafe fn createSampleBufferForRequest_error(
70            &self,
71            request: &AVSampleBufferRequest,
72        ) -> Result<Retained<CMSampleBuffer>, Retained<NSError>>;
73
74        #[cfg(feature = "objc2-core-media")]
75        #[deprecated = "Use -createSampleBufferForRequest: error:, passing NULL for the error if not required"]
76        #[unsafe(method(createSampleBufferForRequest:))]
77        // required for soundness, method has `returns_retained` attribute.
78        #[unsafe(method_family = copy)]
79        pub unsafe fn createSampleBufferForRequest(
80            &self,
81            request: &AVSampleBufferRequest,
82        ) -> Option<Retained<CMSampleBuffer>>;
83
84        /// Creates a batch to handle multiple sample buffers, allowing to asynchronously load sample data and optimize I/O when possible.
85        ///
86        /// Returns: An instance of an AVSampleBufferGeneratorBatch that can be used in calls to createSampleBufferForRequest:addingToBatch:error: of the same AVSampleBufferGenerator instance.
87        #[unsafe(method(makeBatch))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn makeBatch(&self) -> Retained<AVSampleBufferGeneratorBatch>;
90
91        #[cfg(feature = "objc2-core-media")]
92        /// Creates a sample buffer and attempts to defer I/O for its data. Attempt may fail based on generator configuration or file format.
93        /// The [AVSampleBufferGeneratorBatch makeDataReadyWithCompletionHandler:] should be called once to commence I/O and load sample data for all CMSampleBuffers within a batch.
94        /// Any subsequent calls to createSampleBufferForRequest:addingToBatch:error: will throw an exception.
95        ///
96        /// Parameter `request`: An instance of AVSampleBufferRequest representing the CMSampleBuffer creation request
97        ///
98        /// Parameter `batch`: An instance of AVSampleBufferGeneratorBatch to contain the output sample buffer. If nil, an exception is thrown.
99        /// Must be created by calling makeBatch on the same instance of AVSampleBufferGenerator. An exception will be thrown otherwise.
100        ///
101        /// Parameter `outError`: A pointer to an NSError object that will be populated with failure information, if sample buffer creation fails.
102        ///
103        /// Returns: A CMSampleBuffer object referencing the output sample buffer. The generator may defer I/O to fetch sample data depending on the source of the sample data and
104        /// the generator's timebase.
105        #[unsafe(method(createSampleBufferForRequest:addingToBatch:error:_))]
106        // required for soundness, method has `returns_retained` attribute.
107        #[unsafe(method_family = copy)]
108        pub unsafe fn createSampleBufferForRequest_addingToBatch_error(
109            &self,
110            request: &AVSampleBufferRequest,
111            batch: &AVSampleBufferGeneratorBatch,
112        ) -> Result<Retained<CMSampleBuffer>, Retained<NSError>>;
113
114        #[cfg(all(feature = "block2", feature = "objc2-core-media"))]
115        /// Allows the client to get notified when the sample buffer data is ready, or as soon as an error has occured.
116        ///
117        /// Parameter `completionHandler`: The completionHandler will be called, when the sample buffer data is ready, or as soon as an error has occurred.
118        ///
119        /// # Safety
120        ///
121        /// `completion_handler` block must be sendable.
122        #[unsafe(method(notifyOfDataReadyForSampleBuffer:completionHandler:))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn notifyOfDataReadyForSampleBuffer_completionHandler(
125            sbuf: &CMSampleBuffer,
126            completion_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
127        );
128    );
129}
130
131/// Indicates the direction in which the samples should be generated for the AVSampleBufferRequest.
132///
133///
134/// Indicates only one sample will be loaded at [AVSampleBufferRequest startCursor], and the [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount] will be ignored.
135///
136/// Indicates zero or more following samples may be loaded from [AVSampleBufferRequest startCursor], subject to [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount]
137///
138/// Indicates zero or more preceeding samples may be loaded from [AVSampleBufferRequest startCursor], subject to [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount]
139///
140/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequestdirection?language=objc)
141// NS_ENUM
142#[repr(transparent)]
143#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
144pub struct AVSampleBufferRequestDirection(pub NSInteger);
145impl AVSampleBufferRequestDirection {
146    #[doc(alias = "AVSampleBufferRequestDirectionForward")]
147    pub const Forward: Self = Self(1);
148    #[doc(alias = "AVSampleBufferRequestDirectionNone")]
149    pub const None: Self = Self(0);
150    #[doc(alias = "AVSampleBufferRequestDirectionReverse")]
151    pub const Reverse: Self = Self(-1);
152}
153
154unsafe impl Encode for AVSampleBufferRequestDirection {
155    const ENCODING: Encoding = NSInteger::ENCODING;
156}
157
158unsafe impl RefEncode for AVSampleBufferRequestDirection {
159    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
160}
161
162/// Defines the allowed values for AVSampleBufferRequest's mode property.
163///
164///
165/// Sample data for requests with AVSampleBufferRequestModeImmediate will be loaded as soon as possible. The current time represented by AVSampleBufferGenerator's timebase has no influence on these requests.
166///
167/// AVSampleBufferRequestModeScheduled indicates that a request is needed by the time AVSampleBufferGenerator's timebase reaches the CMSampleBuffer's presentationTime or, if specificed, AVSampleBufferRequest's overrideTime. The AVSampleBufferGenerator will attempt to deliver sample data with sufficient leeway for downstream processing. It will also attempt to hold off on loading data until the CMSampleBuffer is needed. If AVSampleBufferGenerator's timebase has a rate of zero, this mode behaves like AVSampleBufferRequestModeImmediate.
168///
169/// The AVSampleBufferGenerator will attempt to read data for opportunistic requests as soon as possible. However, in situations with multiple competing requests, the AVSampleBufferGenerator may defer an opportunistic request in favor of another immediate request or a scheduled requests with a presentation time close to the timebase time. Because a request with AVSampleBufferRequestModeOpportunistic may be postponed indefinitely, this mode should not be used for time-sensitive processing.
170///
171/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequestmode?language=objc)
172// NS_ENUM
173#[repr(transparent)]
174#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
175pub struct AVSampleBufferRequestMode(pub NSInteger);
176impl AVSampleBufferRequestMode {
177    #[doc(alias = "AVSampleBufferRequestModeImmediate")]
178    pub const Immediate: Self = Self(0);
179    #[doc(alias = "AVSampleBufferRequestModeScheduled")]
180    pub const Scheduled: Self = Self(1);
181    #[doc(alias = "AVSampleBufferRequestModeOpportunistic")]
182    pub const Opportunistic: Self = Self(2);
183}
184
185unsafe impl Encode for AVSampleBufferRequestMode {
186    const ENCODING: Encoding = NSInteger::ENCODING;
187}
188
189unsafe impl RefEncode for AVSampleBufferRequestMode {
190    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
191}
192
193extern_class!(
194    /// An AVSampleBufferRequest describes a CMSampleBuffer creation request.
195    ///
196    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequest?language=objc)
197    #[unsafe(super(NSObject))]
198    #[derive(Debug, PartialEq, Eq, Hash)]
199    pub struct AVSampleBufferRequest;
200);
201
202extern_conformance!(
203    unsafe impl NSObjectProtocol for AVSampleBufferRequest {}
204);
205
206impl AVSampleBufferRequest {
207    extern_methods!(
208        #[unsafe(method(init))]
209        #[unsafe(method_family = init)]
210        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
211
212        #[unsafe(method(new))]
213        #[unsafe(method_family = new)]
214        pub unsafe fn new() -> Retained<Self>;
215
216        #[cfg(feature = "AVSampleCursor")]
217        #[unsafe(method(initWithStartCursor:))]
218        #[unsafe(method_family = init)]
219        pub unsafe fn initWithStartCursor(
220            this: Allocated<Self>,
221            start_cursor: &AVSampleCursor,
222        ) -> Retained<Self>;
223
224        #[cfg(feature = "AVSampleCursor")]
225        #[unsafe(method(startCursor))]
226        #[unsafe(method_family = none)]
227        pub unsafe fn startCursor(&self) -> Retained<AVSampleCursor>;
228
229        #[unsafe(method(direction))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn direction(&self) -> AVSampleBufferRequestDirection;
232
233        /// Setter for [`direction`][Self::direction].
234        #[unsafe(method(setDirection:))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn setDirection(&self, direction: AVSampleBufferRequestDirection);
237
238        #[cfg(feature = "AVSampleCursor")]
239        #[unsafe(method(limitCursor))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn limitCursor(&self) -> Option<Retained<AVSampleCursor>>;
242
243        #[cfg(feature = "AVSampleCursor")]
244        /// Setter for [`limitCursor`][Self::limitCursor].
245        #[unsafe(method(setLimitCursor:))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn setLimitCursor(&self, limit_cursor: Option<&AVSampleCursor>);
248
249        #[unsafe(method(preferredMinSampleCount))]
250        #[unsafe(method_family = none)]
251        pub unsafe fn preferredMinSampleCount(&self) -> NSInteger;
252
253        /// Setter for [`preferredMinSampleCount`][Self::preferredMinSampleCount].
254        #[unsafe(method(setPreferredMinSampleCount:))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn setPreferredMinSampleCount(&self, preferred_min_sample_count: NSInteger);
257
258        #[unsafe(method(maxSampleCount))]
259        #[unsafe(method_family = none)]
260        pub unsafe fn maxSampleCount(&self) -> NSInteger;
261
262        /// Setter for [`maxSampleCount`][Self::maxSampleCount].
263        #[unsafe(method(setMaxSampleCount:))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn setMaxSampleCount(&self, max_sample_count: NSInteger);
266
267        #[unsafe(method(mode))]
268        #[unsafe(method_family = none)]
269        pub unsafe fn mode(&self) -> AVSampleBufferRequestMode;
270
271        /// Setter for [`mode`][Self::mode].
272        #[unsafe(method(setMode:))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn setMode(&self, mode: AVSampleBufferRequestMode);
275
276        #[cfg(feature = "objc2-core-media")]
277        #[unsafe(method(overrideTime))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn overrideTime(&self) -> CMTime;
280
281        #[cfg(feature = "objc2-core-media")]
282        /// Setter for [`overrideTime`][Self::overrideTime].
283        #[unsafe(method(setOverrideTime:))]
284        #[unsafe(method_family = none)]
285        pub unsafe fn setOverrideTime(&self, override_time: CMTime);
286    );
287}
288
289extern_class!(
290    /// An AVSampleBufferGeneratorBatch provides an optimized way to load sample data asynchronously for multiple CMSampleBuffers in an asset.
291    ///
292    /// The AVSampleBufferGeneratorBatch loads sample data asynchronously, by aggregating adjacent I/O requests and overlapping them when possible for all CMSampleBuffers within a batch.
293    /// An AVSampleBufferGeneratorBatch is associated with an AVSampleBufferGenerator. See -[AVSampleBufferGenerator makeBatch] to create an AVSampleBufferGeneratorBatch.
294    /// See -[AVSampleBufferGeneratorBatch createSampleBufferForRequest: addingToBatch: error:] to create a CMSampleBuffer, defer I/O for its data, and build up a batch.
295    /// Subclasses of this type that are used from Swift must fulfill the requirements of a Sendable type.
296    ///
297    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebuffergeneratorbatch?language=objc)
298    #[unsafe(super(NSObject))]
299    #[derive(Debug, PartialEq, Eq, Hash)]
300    pub struct AVSampleBufferGeneratorBatch;
301);
302
303unsafe impl Send for AVSampleBufferGeneratorBatch {}
304
305unsafe impl Sync for AVSampleBufferGeneratorBatch {}
306
307extern_conformance!(
308    unsafe impl NSObjectProtocol for AVSampleBufferGeneratorBatch {}
309);
310
311impl AVSampleBufferGeneratorBatch {
312    extern_methods!(
313        #[unsafe(method(init))]
314        #[unsafe(method_family = init)]
315        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
316
317        #[unsafe(method(new))]
318        #[unsafe(method_family = new)]
319        pub unsafe fn new() -> Retained<Self>;
320
321        #[cfg(feature = "block2")]
322        /// Loads sample data asynchronously for all CMSampleBuffers within a batch.
323        /// This can only be called once on a batch, an exception will be thrown otherwise.
324        ///
325        /// Parameter `completionHandler`: The completionHandler is called once, when all CMSampleBuffers in the batch are data-ready, or as soon as an error has occurred.
326        ///
327        /// # Safety
328        ///
329        /// `completion_handler` block must be sendable.
330        #[unsafe(method(makeDataReadyWithCompletionHandler:))]
331        #[unsafe(method_family = none)]
332        pub unsafe fn makeDataReadyWithCompletionHandler(
333            &self,
334            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
335        );
336
337        /// Attempt to cancel any I/O for this batch. The associated sample buffers will have their data ready handler invoked with an error.
338        #[unsafe(method(cancel))]
339        #[unsafe(method_family = none)]
340        pub unsafe fn cancel(&self);
341    );
342}