objc2_av_foundation/generated/
AVAssetReader.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
12/// These constants are returned by the AVAssetReader status property to indicate whether it can successfully read samples from its asset.
13///
14///
15/// Indicates that the status of the asset reader is not currently known.
16///
17/// Indicates that the asset reader is successfully reading samples from its asset.
18///
19/// Indicates that the asset reader has successfully read all of the samples in its time range.
20///
21/// Indicates that the asset reader can no longer read samples from its asset because of an error. The error is described by the value of the asset reader's error property.
22///
23/// Indicates that the asset reader can no longer read samples because reading was canceled with the cancelReading method.
24///
25/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetreaderstatus?language=objc)
26// NS_ENUM
27#[repr(transparent)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29pub struct AVAssetReaderStatus(pub NSInteger);
30impl AVAssetReaderStatus {
31    #[doc(alias = "AVAssetReaderStatusUnknown")]
32    pub const Unknown: Self = Self(0);
33    #[doc(alias = "AVAssetReaderStatusReading")]
34    pub const Reading: Self = Self(1);
35    #[doc(alias = "AVAssetReaderStatusCompleted")]
36    pub const Completed: Self = Self(2);
37    #[doc(alias = "AVAssetReaderStatusFailed")]
38    pub const Failed: Self = Self(3);
39    #[doc(alias = "AVAssetReaderStatusCancelled")]
40    pub const Cancelled: Self = Self(4);
41}
42
43unsafe impl Encode for AVAssetReaderStatus {
44    const ENCODING: Encoding = NSInteger::ENCODING;
45}
46
47unsafe impl RefEncode for AVAssetReaderStatus {
48    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
49}
50
51extern_class!(
52    /// AVAssetReader provides services for obtaining media data from an asset.
53    ///
54    ///
55    /// Instances of AVAssetReader read media data from an instance of AVAsset, whether the asset is file-based or represents an assembly of media data from multiple sources, as is the case with AVComposition.
56    ///
57    /// Clients of AVAssetReader can read data from specific tracks of an asset and in specific formats by adding concrete instances of AVAssetReaderOutput to an AVAssetReader instance.
58    ///
59    /// AVAssetReaderTrackOutput, a concrete subclass of AVAssetReaderOutput, can either read the track's media samples in the format in which they are stored by the asset or convert the media samples to a different format.
60    ///
61    /// AVAssetReaderAudioMixOutput mixes multiple audio tracks of the asset after reading them, while AVAssetReaderVideoCompositionOutput composites multiple video tracks after reading them.
62    ///
63    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetreader?language=objc)
64    #[unsafe(super(NSObject))]
65    #[derive(Debug, PartialEq, Eq, Hash)]
66    pub struct AVAssetReader;
67);
68
69extern_conformance!(
70    unsafe impl NSObjectProtocol for AVAssetReader {}
71);
72
73impl AVAssetReader {
74    extern_methods!(
75        #[unsafe(method(init))]
76        #[unsafe(method_family = init)]
77        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
78
79        #[unsafe(method(new))]
80        #[unsafe(method_family = new)]
81        pub unsafe fn new() -> Retained<Self>;
82
83        #[cfg(feature = "AVAsset")]
84        /// Returns an instance of AVAssetReader for reading media data from the specified asset.
85        ///
86        ///
87        /// Parameter `asset`: The asset from which media data is to be read.
88        ///
89        /// Parameter `outError`: On return, if initialization of the AVAssetReader fails, points to an NSError describing the nature of the failure.
90        ///
91        /// Returns: An instance of AVAssetReader.
92        ///
93        /// If the specified asset belongs to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie, the results of any asset reading operation are undefined if you mutate the asset after invoking -startReading.
94        #[unsafe(method(assetReaderWithAsset:error:_))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn assetReaderWithAsset_error(
97            asset: &AVAsset,
98        ) -> Result<Retained<Self>, Retained<NSError>>;
99
100        #[cfg(feature = "AVAsset")]
101        /// Creates an instance of AVAssetReader for reading media data from the specified asset.
102        ///
103        ///
104        /// Parameter `asset`: The asset from which media data is to be read.
105        ///
106        /// Parameter `outError`: On return, if initialization of the AVAssetReader fails, points to an NSError describing the nature of the failure.
107        ///
108        /// Returns: An instance of AVAssetReader.
109        ///
110        /// If the specified asset belongs to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie, the results of any asset reading operation are undefined if you mutate the asset after invoking -startReading.
111        #[unsafe(method(initWithAsset:error:_))]
112        #[unsafe(method_family = init)]
113        pub unsafe fn initWithAsset_error(
114            this: Allocated<Self>,
115            asset: &AVAsset,
116        ) -> Result<Retained<Self>, Retained<NSError>>;
117
118        #[cfg(feature = "AVAsset")]
119        /// The asset from which the receiver's outputs read sample buffers.
120        ///
121        ///
122        /// The value of this property is an AVAsset. Concrete instances of AVAssetReader that are created with specific AVAssetTrack instances must obtain those tracks from the asset returned by this property.
123        #[unsafe(method(asset))]
124        #[unsafe(method_family = none)]
125        pub unsafe fn asset(&self) -> Retained<AVAsset>;
126
127        /// The status of reading sample buffers from the receiver's asset.
128        ///
129        ///
130        /// The value of this property is an AVAssetReaderStatus that indicates whether reading is in progress, has completed successfully, has been canceled, or has failed. Clients of AVAssetReaderOutput objects should check the value of this property after -[AVAssetReaderOutput copyNextSampleBuffer] returns NULL to determine why no more samples could be read. This property is thread safe.
131        #[unsafe(method(status))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn status(&self) -> AVAssetReaderStatus;
134
135        /// If the receiver's status is AVAssetReaderStatusFailed, this describes the error that caused the failure.
136        ///
137        ///
138        /// The value of this property is an NSError that describes what caused the receiver to no longer be able to read its asset. If the receiver's status is not AVAssetReaderStatusFailed, the value of this property is nil. This property is thread safe.
139        #[unsafe(method(error))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn error(&self) -> Option<Retained<NSError>>;
142
143        #[cfg(feature = "objc2-core-media")]
144        /// Specifies a range of time that may limit the temporal portion of the receiver's asset from which media data will be read.
145        ///
146        ///
147        /// The intersection of the value of timeRange and CMTimeRangeMake(kCMTimeZero, asset.duration) will determine the time range of the asset from which media data will be read. The default value of timeRange is CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity).
148        ///
149        /// This property throws an exception if a value is set after reading has started.
150        #[unsafe(method(timeRange))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn timeRange(&self) -> CMTimeRange;
153
154        #[cfg(feature = "objc2-core-media")]
155        /// Setter for [`timeRange`][Self::timeRange].
156        #[unsafe(method(setTimeRange:))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn setTimeRange(&self, time_range: CMTimeRange);
159
160        #[cfg(feature = "AVAssetReaderOutput")]
161        /// The outputs from which clients of receiver can read media data.
162        ///
163        ///
164        /// The value of this property is an NSArray containing concrete instances of AVAssetReaderOutput. Outputs can be added to the receiver using the addOutput: method.
165        #[unsafe(method(outputs))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn outputs(&self) -> Retained<NSArray<AVAssetReaderOutput>>;
168
169        #[cfg(feature = "AVAssetReaderOutput")]
170        /// Tests whether an output can be added to the receiver.
171        ///
172        ///
173        /// Parameter `output`: The AVAssetReaderOutput object to be tested.
174        ///
175        /// Returns: A BOOL indicating whether the output can be added to the receiver.
176        ///
177        ///
178        /// An output that reads from a track of an asset other than the asset used to initialize the receiver cannot be added.
179        #[unsafe(method(canAddOutput:))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn canAddOutput(&self, output: &AVAssetReaderOutput) -> bool;
182
183        #[cfg(feature = "AVAssetReaderOutput")]
184        /// Adds an output to the receiver.
185        ///
186        ///
187        /// Parameter `output`: The AVAssetReaderOutput object to be added.
188        ///
189        ///
190        /// Outputs are created with a reference to one or more AVAssetTrack objects. These tracks must be owned by the asset returned by the receiver's asset property.
191        ///
192        /// This method throws an exception if the output has already been added to an AVAssetReader or if reading has started (`status` has progressed beyond AVAssetReaderStatusUnknown).
193        #[unsafe(method(addOutput:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn addOutput(&self, output: &AVAssetReaderOutput);
196
197        /// Prepares the receiver for reading sample buffers from the asset.
198        ///
199        ///
200        /// Returns: A BOOL indicating whether reading could be started.
201        ///
202        ///
203        /// This method validates the entire collection of settings for outputs for tracks, for audio mixing, and for video composition and initiates reading from the receiver's asset.
204        ///
205        /// If this method returns NO, clients can determine the nature of the failure by checking the value of the status and error properties.
206        ///
207        /// This method throws an exception if reading has already started (`status` has progressed beyond AVAssetReaderStatusUnknown).
208        #[unsafe(method(startReading))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn startReading(&self) -> bool;
211
212        /// Cancels any background work and prevents the receiver's outputs from reading more samples.
213        ///
214        ///
215        /// Clients that want to stop reading samples from the receiver before reaching the end of its time range should call this method to stop any background read ahead operations that the may have been in progress.
216        ///
217        /// This method should not be called concurrently with any calls to -[AVAssetReaderOutput copyNextSampleBuffer].
218        #[unsafe(method(cancelReading))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn cancelReading(&self);
221    );
222}