objc2_av_foundation/generated/AVAsynchronousKeyValueLoading.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avkeyvaluestatus?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct AVKeyValueStatus(pub NSInteger);
15impl AVKeyValueStatus {
16 #[doc(alias = "AVKeyValueStatusUnknown")]
17 pub const Unknown: Self = Self(0);
18 #[doc(alias = "AVKeyValueStatusLoading")]
19 pub const Loading: Self = Self(1);
20 #[doc(alias = "AVKeyValueStatusLoaded")]
21 pub const Loaded: Self = Self(2);
22 #[doc(alias = "AVKeyValueStatusFailed")]
23 pub const Failed: Self = Self(3);
24 #[doc(alias = "AVKeyValueStatusCancelled")]
25 pub const Cancelled: Self = Self(4);
26}
27
28unsafe impl Encode for AVKeyValueStatus {
29 const ENCODING: Encoding = NSInteger::ENCODING;
30}
31
32unsafe impl RefEncode for AVKeyValueStatus {
33 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
34}
35
36extern_protocol!(
37 /// The AVAsynchronousKeyValueLoading protocol defines methods that let clients use an AVAsset or AVAssetTrack object without blocking a thread. Using methods in the protocol, one can find out the current status of a key (for example, whether the corresponding value has been loaded); and ask the object to load values asynchronously, informing the client when the operation has completed.
38 ///
39 ///
40 /// Because of the nature of timed audiovisual media, successful initialization of an asset does not necessarily mean that all its data is immediately available. Instead, an asset will wait to load data until an operation is performed on it (for example, directly invoking any relevant AVAsset methods, playback via an AVPlayerItem object, export using AVAssetExportSession, reading using an instance of AVAssetReader, and so on). This means that although you can request the value of any key at any time, and its value will be returned synchronously, the calling thread may be blocked until the request can be satisfied. To avoid blocking, you can:
41 ///
42 /// 1. First, determine whether the value for a given key is available using statusOfValueForKey:error:.
43 /// 2. If a value has not been loaded yet, you can ask for to load one or more values and be notified when they become available using loadValuesAsynchronouslyForKeys:completionHandler:.
44 ///
45 /// Even for use cases that may typically support ready access to some keys (such as for assets initialized with URLs for files in the local filesystem), slow I/O may require AVAsset to block before returning their values. Although blocking may be acceptable for macOS API clients in cases where assets are being prepared on background threads or in operation queues, in all cases in which blocking should be avoided you should use loadValuesAsynchronouslyForKeys:completionHandler:. For clients of platforms other than macOS, blocking to obtain the value of a key synchronously is never recommended under any circumstances.
46 ///
47 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avasynchronouskeyvalueloading?language=objc)
48 pub unsafe trait AVAsynchronousKeyValueLoading {
49 #[cfg(feature = "block2")]
50 /// Directs the target to load the values of any of the specified keys that are not already loaded.
51 ///
52 /// Parameter `keys`: An instance of NSArray, containing NSStrings for the specified keys.
53 ///
54 /// Parameter `handler`: The block to be invoked when loading succeeds, fails, or is cancelled.
55 ///
56 /// # Safety
57 ///
58 /// `handler` block must be sendable.
59 #[unsafe(method(loadValuesAsynchronouslyForKeys:completionHandler:))]
60 #[unsafe(method_family = none)]
61 unsafe fn loadValuesAsynchronouslyForKeys_completionHandler(
62 &self,
63 keys: &NSArray<NSString>,
64 handler: Option<&block2::DynBlock<dyn Fn()>>,
65 );
66 }
67);