objc2_av_foundation/generated/
AVAssetImageGenerator.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-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9use objc2_core_graphics::*;
10#[cfg(feature = "objc2-core-media")]
11use objc2_core_media::*;
12use objc2_foundation::*;
13
14use crate::*;
15
16/// The type of an aperture mode.
17///
18/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratoraperturemode?language=objc)
19// NS_TYPED_ENUM
20pub type AVAssetImageGeneratorApertureMode = NSString;
21
22extern "C" {
23    /// Both pixel aspect ratio and clean aperture will be applied.
24    ///
25    /// An image's clean aperture is a region of video free from transition artifacts caused by the encoding of the signal.
26    ///
27    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratoraperturemodecleanaperture?language=objc)
28    pub static AVAssetImageGeneratorApertureModeCleanAperture:
29        &'static AVAssetImageGeneratorApertureMode;
30}
31
32extern "C" {
33    /// Only pixel aspect ratio will be applied.
34    ///
35    /// The image is not cropped to the clean aperture region, but it is scaled according to the pixel aspect ratio. Use this option when you want to see all the pixels in your video, including the edges.
36    ///
37    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratoraperturemodeproductionaperture?language=objc)
38    pub static AVAssetImageGeneratorApertureModeProductionAperture:
39        &'static AVAssetImageGeneratorApertureMode;
40}
41
42extern "C" {
43    /// Neither pixel aspect ratio nor clean aperture will be applied.
44    ///
45    /// The image is not cropped to the clean aperture region and is not scaled according to the pixel aspect ratio. The encoded dimensions of the image description are displayed.
46    ///
47    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratoraperturemodeencodedpixels?language=objc)
48    pub static AVAssetImageGeneratorApertureModeEncodedPixels:
49        &'static AVAssetImageGeneratorApertureMode;
50}
51
52/// Configures the video dynamic range for the output CGImage
53///
54/// Default.  Force standard dynamic range by converting PQ or HLG transfer functions to 709, while maintaining color primaries and matrix.
55///
56/// SDR movies will vend SDR CGImages matching the source color parameters.  HDR movies will vend HDR CGImages matching the source color parameters.
57/// HTTP Live Streaming assets will currently vend only SDR CGImages.
58///
59/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratordynamicrangepolicy?language=objc)
60// NS_TYPED_ENUM
61pub type AVAssetImageGeneratorDynamicRangePolicy = NSString;
62
63extern "C" {
64    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratordynamicrangepolicyforcesdr?language=objc)
65    pub static AVAssetImageGeneratorDynamicRangePolicyForceSDR:
66        &'static AVAssetImageGeneratorDynamicRangePolicy;
67}
68
69extern "C" {
70    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratordynamicrangepolicymatchsource?language=objc)
71    pub static AVAssetImageGeneratorDynamicRangePolicyMatchSource:
72        &'static AVAssetImageGeneratorDynamicRangePolicy;
73}
74
75/// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratorresult?language=objc)
76// NS_ENUM
77#[repr(transparent)]
78#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
79pub struct AVAssetImageGeneratorResult(pub NSInteger);
80impl AVAssetImageGeneratorResult {
81    #[doc(alias = "AVAssetImageGeneratorSucceeded")]
82    pub const Succeeded: Self = Self(0);
83    #[doc(alias = "AVAssetImageGeneratorFailed")]
84    pub const Failed: Self = Self(1);
85    #[doc(alias = "AVAssetImageGeneratorCancelled")]
86    pub const Cancelled: Self = Self(2);
87}
88
89unsafe impl Encode for AVAssetImageGeneratorResult {
90    const ENCODING: Encoding = NSInteger::ENCODING;
91}
92
93unsafe impl RefEncode for AVAssetImageGeneratorResult {
94    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
95}
96
97/// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegeneratorcompletionhandler?language=objc)
98#[cfg(all(
99    feature = "block2",
100    feature = "objc2-core-graphics",
101    feature = "objc2-core-media"
102))]
103pub type AVAssetImageGeneratorCompletionHandler = *mut block2::DynBlock<
104    dyn Fn(CMTime, *mut CGImage, CMTime, AVAssetImageGeneratorResult, *mut NSError),
105>;
106
107extern_class!(
108    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetimagegenerator?language=objc)
109    #[unsafe(super(NSObject))]
110    #[derive(Debug, PartialEq, Eq, Hash)]
111    pub struct AVAssetImageGenerator;
112);
113
114extern_conformance!(
115    unsafe impl NSObjectProtocol for AVAssetImageGenerator {}
116);
117
118impl AVAssetImageGenerator {
119    extern_methods!(
120        #[unsafe(method(init))]
121        #[unsafe(method_family = init)]
122        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
123
124        #[unsafe(method(new))]
125        #[unsafe(method_family = new)]
126        pub unsafe fn new() -> Retained<Self>;
127
128        #[cfg(feature = "AVAsset")]
129        #[unsafe(method(asset))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn asset(&self) -> Retained<AVAsset>;
132
133        #[unsafe(method(appliesPreferredTrackTransform))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn appliesPreferredTrackTransform(&self) -> bool;
136
137        /// Setter for [`appliesPreferredTrackTransform`][Self::appliesPreferredTrackTransform].
138        #[unsafe(method(setAppliesPreferredTrackTransform:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn setAppliesPreferredTrackTransform(
141            &self,
142            applies_preferred_track_transform: bool,
143        );
144
145        #[cfg(feature = "objc2-core-foundation")]
146        #[unsafe(method(maximumSize))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn maximumSize(&self) -> CGSize;
149
150        #[cfg(feature = "objc2-core-foundation")]
151        /// Setter for [`maximumSize`][Self::maximumSize].
152        #[unsafe(method(setMaximumSize:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn setMaximumSize(&self, maximum_size: CGSize);
155
156        #[unsafe(method(apertureMode))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn apertureMode(&self) -> Option<Retained<AVAssetImageGeneratorApertureMode>>;
159
160        /// Setter for [`apertureMode`][Self::apertureMode].
161        ///
162        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
163        #[unsafe(method(setApertureMode:))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn setApertureMode(
166            &self,
167            aperture_mode: Option<&AVAssetImageGeneratorApertureMode>,
168        );
169
170        /// Configures the video dynamic range for the output CGImage
171        ///
172        /// Default is AVAssetImageGeneratorDynamicRangePolicyForceSDR
173        #[unsafe(method(dynamicRangePolicy))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn dynamicRangePolicy(
176            &self,
177        ) -> Retained<AVAssetImageGeneratorDynamicRangePolicy>;
178
179        /// Setter for [`dynamicRangePolicy`][Self::dynamicRangePolicy].
180        ///
181        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
182        #[unsafe(method(setDynamicRangePolicy:))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn setDynamicRangePolicy(
185            &self,
186            dynamic_range_policy: &AVAssetImageGeneratorDynamicRangePolicy,
187        );
188
189        #[cfg(feature = "AVVideoComposition")]
190        /// Specifies the video composition to use when extracting images from assets with multiple video tracks.
191        ///
192        /// If no videoComposition is specified, only the first enabled video track will be used.
193        /// If a videoComposition is specified, the value of appliesPreferredTrackTransform is ignored.
194        /// This property throws an exception if a video composition is set with any of the following property values:
195        /// - "renderScale" is not equal to one
196        /// - "renderSize" width or height is less than zero
197        /// - "frameDuration" is invalid or less than or equal to zero
198        /// - "sourceTrackIDForFrameTiming" is less than zero
199        /// - "outputBufferDescription" is non-nil
200        #[unsafe(method(videoComposition))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn videoComposition(&self) -> Option<Retained<AVVideoComposition>>;
203
204        #[cfg(feature = "AVVideoComposition")]
205        /// Setter for [`videoComposition`][Self::videoComposition].
206        ///
207        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
208        #[unsafe(method(setVideoComposition:))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn setVideoComposition(&self, video_composition: Option<&AVVideoComposition>);
211
212        #[cfg(feature = "AVVideoCompositing")]
213        #[unsafe(method(customVideoCompositor))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn customVideoCompositor(
216            &self,
217        ) -> Option<Retained<ProtocolObject<dyn AVVideoCompositing>>>;
218
219        #[cfg(feature = "objc2-core-media")]
220        #[unsafe(method(requestedTimeToleranceBefore))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn requestedTimeToleranceBefore(&self) -> CMTime;
223
224        #[cfg(feature = "objc2-core-media")]
225        /// Setter for [`requestedTimeToleranceBefore`][Self::requestedTimeToleranceBefore].
226        #[unsafe(method(setRequestedTimeToleranceBefore:))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn setRequestedTimeToleranceBefore(
229            &self,
230            requested_time_tolerance_before: CMTime,
231        );
232
233        #[cfg(feature = "objc2-core-media")]
234        #[unsafe(method(requestedTimeToleranceAfter))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn requestedTimeToleranceAfter(&self) -> CMTime;
237
238        #[cfg(feature = "objc2-core-media")]
239        /// Setter for [`requestedTimeToleranceAfter`][Self::requestedTimeToleranceAfter].
240        #[unsafe(method(setRequestedTimeToleranceAfter:))]
241        #[unsafe(method_family = none)]
242        pub unsafe fn setRequestedTimeToleranceAfter(&self, requested_time_tolerance_after: CMTime);
243
244        #[cfg(feature = "AVAsset")]
245        /// Returns an instance of AVAssetImageGenerator for use with the specified asset.
246        ///
247        /// Parameter `asset`: The asset from which images will be extracted.
248        ///
249        /// Returns: An instance of AVAssetImageGenerator
250        ///
251        /// This method may succeed even if the asset possesses no visual tracks at the time of initialization.
252        /// Clients may wish to test whether an asset has any tracks with the visual characteristic via
253        /// -[AVAsset tracksWithMediaCharacteristic:].
254        ///
255        /// Note also that assets that belong to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie,
256        /// may gain visual tracks after initialization of an associated AVAssetImageGenerator.
257        ///
258        /// However, the results of image generation are undefined if mutations of the asset occur while images
259        /// are being generated.
260        ///
261        /// AVAssetImageGenerator will use the default enabled video track(s) to generate images.
262        #[unsafe(method(assetImageGeneratorWithAsset:))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn assetImageGeneratorWithAsset(asset: &AVAsset) -> Retained<Self>;
265
266        #[cfg(feature = "AVAsset")]
267        /// Initializes an instance of AVAssetImageGenerator for use with the specified asset.
268        ///
269        /// Parameter `asset`: The asset from which images will be extracted.
270        ///
271        /// Returns: An instance of AVAssetImageGenerator
272        ///
273        /// This method may succeed even if the asset possesses no visual tracks at the time of initialization.
274        /// Clients may wish to test whether an asset has any tracks with the visual characteristic via
275        /// -[AVAsset tracksWithMediaCharacteristic:].
276        ///
277        /// Note also that assets that belong to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie,
278        /// may gain visual tracks after initialization of an associated AVAssetImageGenerator.
279        ///
280        /// However, the results of image generation are undefined if mutations of the asset occur while images
281        /// are being generated.
282        ///
283        /// AVAssetImageGenerator will use the default enabled video track(s) to generate images.
284        #[unsafe(method(initWithAsset:))]
285        #[unsafe(method_family = init)]
286        pub unsafe fn initWithAsset(this: Allocated<Self>, asset: &AVAsset) -> Retained<Self>;
287
288        #[cfg(all(feature = "objc2-core-graphics", feature = "objc2-core-media"))]
289        /// Returns a CFRetained CGImageRef for an asset at or near the specified time.
290        ///
291        /// Parameter `requestedTime`: The time at which the image of the asset is to be created.
292        ///
293        /// Parameter `actualTime`: A pointer to a CMTime to receive the time at which the image was actually generated. If you are not interested
294        /// in this information, pass NULL.
295        ///
296        /// Parameter `outError`: An error object describing the reason for failure, in the event that this method returns NULL.
297        ///
298        /// Returns: A CGImageRef.
299        ///
300        /// Returns the CGImage synchronously. Ownership follows the Create Rule.
301        ///
302        /// Because of the nature of timed audiovisual media, generating an image may take significant time. AVAssetImageGenerator may have to block the calling thread in order to do so.  In order to avoid blocking, clients can use -generateCGImagesAsynchronouslyForTimes:completionHandler: to request that one or more images be generated asynchronously and to be notified when they become available.
303        ///
304        /// On iOS and tvOS, it is particularly important to avoid blocking.  To preserve responsiveness, a synchronous request that blocks for too long (eg, a request to generate an image from an asset on a slow HTTP server) may lead to media services being reset.
305        ///
306        /// # Safety
307        ///
308        /// `actual_time` must be a valid pointer or null.
309        #[deprecated = "Use generateCGImageAsynchronouslyForTime:completionHandler: instead"]
310        #[unsafe(method(copyCGImageAtTime:actualTime:error:_))]
311        #[unsafe(method_family = copy)]
312        pub unsafe fn copyCGImageAtTime_actualTime_error(
313            &self,
314            requested_time: CMTime,
315            actual_time: *mut CMTime,
316        ) -> Result<Retained<CGImage>, Retained<NSError>>;
317
318        #[cfg(all(
319            feature = "block2",
320            feature = "objc2-core-graphics",
321            feature = "objc2-core-media"
322        ))]
323        /// Returns a series of CGImageRefs for an asset at or near the specified times.
324        ///
325        /// Parameter `requestedTimes`: An NSArray of NSValues, each containing a CMTime, specifying the asset times at which an image is requested.
326        ///
327        /// Parameter `handler`: A block that will be called when an image request is complete.
328        ///
329        /// Employs an efficient "batch mode" for getting images in time order.
330        /// The client will receive exactly one handler callback for each requested time in requestedTimes.
331        /// Changes to generator properties (snap behavior, maximum size, etc...) will not affect outstanding asynchronous image generation requests.
332        /// The generated image is not retained.  Clients should retain the image if they wish it to persist after the completion handler returns.
333        ///
334        /// # Safety
335        ///
336        /// `handler` must be a valid pointer.
337        #[unsafe(method(generateCGImagesAsynchronouslyForTimes:completionHandler:))]
338        #[unsafe(method_family = none)]
339        pub unsafe fn generateCGImagesAsynchronouslyForTimes_completionHandler(
340            &self,
341            requested_times: &NSArray<NSValue>,
342            handler: AVAssetImageGeneratorCompletionHandler,
343        );
344
345        #[cfg(all(
346            feature = "block2",
347            feature = "objc2-core-graphics",
348            feature = "objc2-core-media"
349        ))]
350        /// Returns a CGImageRef for an asset at or near the specified time.
351        ///
352        /// Parameter `requestedTime`: A CMTime, specifying the asset time at which an image is requested.
353        ///
354        /// Parameter `handler`: A block that will be called when the image request is complete.
355        ///
356        /// The client will receive exactly one handler callback for requestedTime.
357        /// Changes to generator properties (snap behavior, maximum size, etc...) will not affect outstanding asynchronous image generation requests.
358        /// The generated image is not retained.  Clients should retain the image if they wish it to persist after the completion handler returns.
359        /// If image generation succeeds, the `image` parameter to the completion handler will be non-NULL and the `error` parameter will be nil.  If image generation fails or was cancelled, the `image` parameter will be NULL and the `error` parameter will describe what went wrong.  For cancelled images, the returned error will be AVErrorOperationCancelled.
360        ///
361        /// # Safety
362        ///
363        /// `handler` block must be sendable.
364        #[unsafe(method(generateCGImageAsynchronouslyForTime:completionHandler:))]
365        #[unsafe(method_family = none)]
366        pub unsafe fn generateCGImageAsynchronouslyForTime_completionHandler(
367            &self,
368            requested_time: CMTime,
369            handler: &block2::DynBlock<dyn Fn(*mut CGImage, CMTime, *mut NSError)>,
370        );
371
372        /// Cancels all outstanding image generation requests.
373        ///
374        /// Calls the handler block with AVAssetImageGeneratorCancelled for each image time in every previous invocation of -generateCGImagesAsynchronouslyForTimes:completionHandler:
375        /// for which images have not yet been supplied.
376        #[unsafe(method(cancelAllCGImageGeneration))]
377        #[unsafe(method_family = none)]
378        pub unsafe fn cancelAllCGImageGeneration(&self);
379    );
380}