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