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
69unsafe impl NSObjectProtocol for AVAssetReader {}
70
71impl AVAssetReader {
72    extern_methods!(
73        #[unsafe(method(init))]
74        #[unsafe(method_family = init)]
75        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
76
77        #[unsafe(method(new))]
78        #[unsafe(method_family = new)]
79        pub unsafe fn new() -> Retained<Self>;
80
81        #[cfg(feature = "AVAsset")]
82        /// Returns an instance of AVAssetReader for reading media data from the specified asset.
83        ///
84        ///
85        /// Parameter `asset`: The asset from which media data is to be read.
86        ///
87        /// Parameter `outError`: On return, if initialization of the AVAssetReader fails, points to an NSError describing the nature of the failure.
88        ///
89        /// Returns: An instance of AVAssetReader.
90        ///
91        /// 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.
92        #[unsafe(method(assetReaderWithAsset:error:_))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn assetReaderWithAsset_error(
95            asset: &AVAsset,
96        ) -> Result<Retained<Self>, Retained<NSError>>;
97
98        #[cfg(feature = "AVAsset")]
99        /// Creates an instance of AVAssetReader for reading media data from the specified asset.
100        ///
101        ///
102        /// Parameter `asset`: The asset from which media data is to be read.
103        ///
104        /// Parameter `outError`: On return, if initialization of the AVAssetReader fails, points to an NSError describing the nature of the failure.
105        ///
106        /// Returns: An instance of AVAssetReader.
107        ///
108        /// 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.
109        #[unsafe(method(initWithAsset:error:_))]
110        #[unsafe(method_family = init)]
111        pub unsafe fn initWithAsset_error(
112            this: Allocated<Self>,
113            asset: &AVAsset,
114        ) -> Result<Retained<Self>, Retained<NSError>>;
115
116        #[cfg(feature = "AVAsset")]
117        /// The asset from which the receiver's outputs read sample buffers.
118        ///
119        ///
120        /// 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.
121        #[unsafe(method(asset))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn asset(&self) -> Retained<AVAsset>;
124
125        /// The status of reading sample buffers from the receiver's asset.
126        ///
127        ///
128        /// 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.
129        #[unsafe(method(status))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn status(&self) -> AVAssetReaderStatus;
132
133        /// If the receiver's status is AVAssetReaderStatusFailed, this describes the error that caused the failure.
134        ///
135        ///
136        /// 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.
137        #[unsafe(method(error))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn error(&self) -> Option<Retained<NSError>>;
140
141        #[cfg(feature = "objc2-core-media")]
142        /// Specifies a range of time that may limit the temporal portion of the receiver's asset from which media data will be read.
143        ///
144        ///
145        /// 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).
146        ///
147        /// This property throws an exception if a value is set after reading has started.
148        #[unsafe(method(timeRange))]
149        #[unsafe(method_family = none)]
150        pub unsafe fn timeRange(&self) -> CMTimeRange;
151
152        #[cfg(feature = "objc2-core-media")]
153        /// Setter for [`timeRange`][Self::timeRange].
154        #[unsafe(method(setTimeRange:))]
155        #[unsafe(method_family = none)]
156        pub unsafe fn setTimeRange(&self, time_range: CMTimeRange);
157
158        #[cfg(feature = "AVAssetReaderOutput")]
159        /// The outputs from which clients of receiver can read media data.
160        ///
161        ///
162        /// The value of this property is an NSArray containing concrete instances of AVAssetReaderOutput. Outputs can be added to the receiver using the addOutput: method.
163        #[unsafe(method(outputs))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn outputs(&self) -> Retained<NSArray<AVAssetReaderOutput>>;
166
167        #[cfg(feature = "AVAssetReaderOutput")]
168        /// Tests whether an output can be added to the receiver.
169        ///
170        ///
171        /// Parameter `output`: The AVAssetReaderOutput object to be tested.
172        ///
173        /// Returns: A BOOL indicating whether the output can be added to the receiver.
174        ///
175        ///
176        /// An output that reads from a track of an asset other than the asset used to initialize the receiver cannot be added.
177        #[unsafe(method(canAddOutput:))]
178        #[unsafe(method_family = none)]
179        pub unsafe fn canAddOutput(&self, output: &AVAssetReaderOutput) -> bool;
180
181        #[cfg(feature = "AVAssetReaderOutput")]
182        /// Adds an output to the receiver.
183        ///
184        ///
185        /// Parameter `output`: The AVAssetReaderOutput object to be added.
186        ///
187        ///
188        /// 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.
189        ///
190        /// 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).
191        #[unsafe(method(addOutput:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn addOutput(&self, output: &AVAssetReaderOutput);
194
195        /// Prepares the receiver for reading sample buffers from the asset.
196        ///
197        ///
198        /// Returns: A BOOL indicating whether reading could be started.
199        ///
200        ///
201        /// 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.
202        ///
203        /// If this method returns NO, clients can determine the nature of the failure by checking the value of the status and error properties.
204        ///
205        /// This method throws an exception if reading has already started (`status` has progressed beyond AVAssetReaderStatusUnknown).
206        #[unsafe(method(startReading))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn startReading(&self) -> bool;
209
210        /// Cancels any background work and prevents the receiver's outputs from reading more samples.
211        ///
212        ///
213        /// 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.
214        ///
215        /// This method should not be called concurrently with any calls to -[AVAssetReaderOutput copyNextSampleBuffer].
216        #[unsafe(method(cancelReading))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn cancelReading(&self);
219    );
220}