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
23unsafe impl NSObjectProtocol for AVSampleBufferGenerator {}
24
25impl AVSampleBufferGenerator {
26    extern_methods!(
27        #[unsafe(method(init))]
28        #[unsafe(method_family = init)]
29        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
30
31        #[unsafe(method(new))]
32        #[unsafe(method_family = new)]
33        pub unsafe fn new() -> Retained<Self>;
34
35        #[cfg(all(feature = "AVAsset", feature = "objc2-core-media"))]
36        /// Creates an instance of AVSampleBufferGenerator to generate sample buffers from the specified asset.
37        ///
38        /// Parameter `asset`: The asset from which sample buffers will be created.
39        ///
40        /// Parameter `timebase`: The generator timebase, which governs when sample data for sample buffers is loaded. If NULL, sample data is loaded synchronously.
41        ///
42        /// Returns: An instance of AVSampleBufferGenerator.
43        ///
44        /// If the specified asset is an HTTP Live Streaming asset, the generator cannot create sample buffers.
45        #[unsafe(method(initWithAsset:timebase:))]
46        #[unsafe(method_family = init)]
47        pub unsafe fn initWithAsset_timebase(
48            this: Allocated<Self>,
49            asset: &AVAsset,
50            timebase: Option<&CMTimebase>,
51        ) -> Retained<Self>;
52
53        #[cfg(feature = "objc2-core-media")]
54        #[deprecated = "Use -createSampleBufferForRequest: error:, passing NULL for the error if not required"]
55        #[unsafe(method(createSampleBufferForRequest:))]
56        // required for soundness, method has `returns_retained` attribute.
57        #[unsafe(method_family = copy)]
58        pub unsafe fn createSampleBufferForRequest(
59            &self,
60            request: &AVSampleBufferRequest,
61        ) -> Option<Retained<CMSampleBuffer>>;
62
63        /// Creates a batch to handle multiple sample buffers, allowing to asynchronously load sample data and optimize I/O when possible.
64        ///
65        /// Returns: An instance of an AVSampleBufferGeneratorBatch that can be used in calls to createSampleBufferForRequest:addingToBatch:error: of the same AVSampleBufferGenerator instance.
66        #[unsafe(method(makeBatch))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn makeBatch(&self) -> Retained<AVSampleBufferGeneratorBatch>;
69
70        #[cfg(all(feature = "block2", feature = "objc2-core-media"))]
71        /// Allows the client to get notified when the sample buffer data is ready, or as soon as an error has occured.
72        ///
73        /// Parameter `completionHandler`: The completionHandler will be called, when the sample buffer data is ready, or as soon as an error has occurred.
74        #[unsafe(method(notifyOfDataReadyForSampleBuffer:completionHandler:))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn notifyOfDataReadyForSampleBuffer_completionHandler(
77            sbuf: &CMSampleBuffer,
78            completion_handler: &block2::Block<dyn Fn(Bool, *mut NSError)>,
79        );
80    );
81}
82
83/// Indicates the direction in which the samples should be generated for the AVSampleBufferRequest.
84///
85///
86/// Indicates only one sample will be loaded at [AVSampleBufferRequest startCursor], and the [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount] will be ignored.
87///
88/// Indicates zero or more following samples may be loaded from [AVSampleBufferRequest startCursor], subject to [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount]
89///
90/// Indicates zero or more preceeding samples may be loaded from [AVSampleBufferRequest startCursor], subject to [AVSampleBufferRequest limitCursor], [AVSampleBufferRequest preferredMinSampleCount], and [AVSampleBufferRequest maxSampleCount]
91///
92/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequestdirection?language=objc)
93// NS_ENUM
94#[repr(transparent)]
95#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
96pub struct AVSampleBufferRequestDirection(pub NSInteger);
97impl AVSampleBufferRequestDirection {
98    #[doc(alias = "AVSampleBufferRequestDirectionForward")]
99    pub const Forward: Self = Self(1);
100    #[doc(alias = "AVSampleBufferRequestDirectionNone")]
101    pub const None: Self = Self(0);
102    #[doc(alias = "AVSampleBufferRequestDirectionReverse")]
103    pub const Reverse: Self = Self(-1);
104}
105
106unsafe impl Encode for AVSampleBufferRequestDirection {
107    const ENCODING: Encoding = NSInteger::ENCODING;
108}
109
110unsafe impl RefEncode for AVSampleBufferRequestDirection {
111    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
112}
113
114/// Defines the allowed values for AVSampleBufferRequest's mode property.
115///
116///
117/// 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.
118///
119/// 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.
120///
121/// 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.
122///
123/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequestmode?language=objc)
124// NS_ENUM
125#[repr(transparent)]
126#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
127pub struct AVSampleBufferRequestMode(pub NSInteger);
128impl AVSampleBufferRequestMode {
129    #[doc(alias = "AVSampleBufferRequestModeImmediate")]
130    pub const Immediate: Self = Self(0);
131    #[doc(alias = "AVSampleBufferRequestModeScheduled")]
132    pub const Scheduled: Self = Self(1);
133    #[doc(alias = "AVSampleBufferRequestModeOpportunistic")]
134    pub const Opportunistic: Self = Self(2);
135}
136
137unsafe impl Encode for AVSampleBufferRequestMode {
138    const ENCODING: Encoding = NSInteger::ENCODING;
139}
140
141unsafe impl RefEncode for AVSampleBufferRequestMode {
142    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
143}
144
145extern_class!(
146    /// An AVSampleBufferRequest describes a CMSampleBuffer creation request.
147    ///
148    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrequest?language=objc)
149    #[unsafe(super(NSObject))]
150    #[derive(Debug, PartialEq, Eq, Hash)]
151    pub struct AVSampleBufferRequest;
152);
153
154unsafe impl NSObjectProtocol for AVSampleBufferRequest {}
155
156impl AVSampleBufferRequest {
157    extern_methods!(
158        #[unsafe(method(init))]
159        #[unsafe(method_family = init)]
160        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
161
162        #[unsafe(method(new))]
163        #[unsafe(method_family = new)]
164        pub unsafe fn new() -> Retained<Self>;
165
166        #[cfg(feature = "AVSampleCursor")]
167        #[unsafe(method(initWithStartCursor:))]
168        #[unsafe(method_family = init)]
169        pub unsafe fn initWithStartCursor(
170            this: Allocated<Self>,
171            start_cursor: &AVSampleCursor,
172        ) -> Retained<Self>;
173
174        #[cfg(feature = "AVSampleCursor")]
175        #[unsafe(method(startCursor))]
176        #[unsafe(method_family = none)]
177        pub unsafe fn startCursor(&self) -> Retained<AVSampleCursor>;
178
179        #[unsafe(method(direction))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn direction(&self) -> AVSampleBufferRequestDirection;
182
183        /// Setter for [`direction`][Self::direction].
184        #[unsafe(method(setDirection:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn setDirection(&self, direction: AVSampleBufferRequestDirection);
187
188        #[cfg(feature = "AVSampleCursor")]
189        #[unsafe(method(limitCursor))]
190        #[unsafe(method_family = none)]
191        pub unsafe fn limitCursor(&self) -> Option<Retained<AVSampleCursor>>;
192
193        #[cfg(feature = "AVSampleCursor")]
194        /// Setter for [`limitCursor`][Self::limitCursor].
195        #[unsafe(method(setLimitCursor:))]
196        #[unsafe(method_family = none)]
197        pub unsafe fn setLimitCursor(&self, limit_cursor: Option<&AVSampleCursor>);
198
199        #[unsafe(method(preferredMinSampleCount))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn preferredMinSampleCount(&self) -> NSInteger;
202
203        /// Setter for [`preferredMinSampleCount`][Self::preferredMinSampleCount].
204        #[unsafe(method(setPreferredMinSampleCount:))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn setPreferredMinSampleCount(&self, preferred_min_sample_count: NSInteger);
207
208        #[unsafe(method(maxSampleCount))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn maxSampleCount(&self) -> NSInteger;
211
212        /// Setter for [`maxSampleCount`][Self::maxSampleCount].
213        #[unsafe(method(setMaxSampleCount:))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn setMaxSampleCount(&self, max_sample_count: NSInteger);
216
217        #[unsafe(method(mode))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn mode(&self) -> AVSampleBufferRequestMode;
220
221        /// Setter for [`mode`][Self::mode].
222        #[unsafe(method(setMode:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setMode(&self, mode: AVSampleBufferRequestMode);
225
226        #[cfg(feature = "objc2-core-media")]
227        #[unsafe(method(overrideTime))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn overrideTime(&self) -> CMTime;
230
231        #[cfg(feature = "objc2-core-media")]
232        /// Setter for [`overrideTime`][Self::overrideTime].
233        #[unsafe(method(setOverrideTime:))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn setOverrideTime(&self, override_time: CMTime);
236    );
237}
238
239extern_class!(
240    /// An AVSampleBufferGeneratorBatch provides an optimized way to load sample data asynchronously for multiple CMSampleBuffers in an asset.
241    ///
242    /// The AVSampleBufferGeneratorBatch loads sample data asynchronously, by aggregating adjacent I/O requests and overlapping them when possible for all CMSampleBuffers within a batch.
243    /// An AVSampleBufferGeneratorBatch is associated with an AVSampleBufferGenerator. See -[AVSampleBufferGenerator makeBatch] to create an AVSampleBufferGeneratorBatch.
244    /// See -[AVSampleBufferGeneratorBatch createSampleBufferForRequest: addingToBatch: error:] to create a CMSampleBuffer, defer I/O for its data, and build up a batch.
245    /// Subclasses of this type that are used from Swift must fulfill the requirements of a Sendable type.
246    ///
247    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebuffergeneratorbatch?language=objc)
248    #[unsafe(super(NSObject))]
249    #[derive(Debug, PartialEq, Eq, Hash)]
250    pub struct AVSampleBufferGeneratorBatch;
251);
252
253unsafe impl Send for AVSampleBufferGeneratorBatch {}
254
255unsafe impl Sync for AVSampleBufferGeneratorBatch {}
256
257unsafe impl NSObjectProtocol for AVSampleBufferGeneratorBatch {}
258
259impl AVSampleBufferGeneratorBatch {
260    extern_methods!(
261        #[unsafe(method(init))]
262        #[unsafe(method_family = init)]
263        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
264
265        #[unsafe(method(new))]
266        #[unsafe(method_family = new)]
267        pub unsafe fn new() -> Retained<Self>;
268
269        #[cfg(feature = "block2")]
270        /// Loads sample data asynchronously for all CMSampleBuffers within a batch.
271        /// This can only be called once on a batch, an exception will be thrown otherwise.
272        ///
273        /// Parameter `completionHandler`: The completionHandler is called once, when all CMSampleBuffers in the batch are data-ready, or as soon as an error has occurred.
274        #[unsafe(method(makeDataReadyWithCompletionHandler:))]
275        #[unsafe(method_family = none)]
276        pub unsafe fn makeDataReadyWithCompletionHandler(
277            &self,
278            completion_handler: &block2::Block<dyn Fn(*mut NSError)>,
279        );
280
281        /// Attempt to cancel any I/O for this batch. The associated sample buffers will have their data ready handler invoked with an error.
282        #[unsafe(method(cancel))]
283        #[unsafe(method_family = none)]
284        pub unsafe fn cancel(&self);
285    );
286}