#[repr(C)]pub struct AVCaptureSession { /* private fields */ }AVCaptureSession only.Expand description
AVCaptureSession is the central hub of the AVFoundation capture classes.
To perform a real-time capture, a client may instantiate AVCaptureSession and add appropriate AVCaptureInputs, such as AVCaptureDeviceInput, and outputs, such as AVCaptureMovieFileOutput. [AVCaptureSession startRunning] starts the flow of data from the inputs to the outputs, and [AVCaptureSession stopRunning] stops the flow. A client may set the sessionPreset property to customize the quality level or bitrate of the output.
See also Apple’s documentation
Implementations§
Source§impl AVCaptureSession
impl AVCaptureSession
Sourcepub unsafe fn canSetSessionPreset(
&self,
preset: &AVCaptureSessionPreset,
) -> bool
Available on crate feature AVCaptureSessionPreset only.
pub unsafe fn canSetSessionPreset( &self, preset: &AVCaptureSessionPreset, ) -> bool
AVCaptureSessionPreset only.Returns whether the receiver can be configured with the given preset.
Parameter preset: An AVCaptureSession preset.
Returns: YES if the receiver can be set to the given preset, NO otherwise.
An AVCaptureSession instance can be associated with a preset that configures its inputs and outputs to fulfill common use cases. This method can be used to determine if the receiver supports the desired preset given its current input and output configuration. The receiver’s sessionPreset property may only be set to a certain preset if this method returns YES for that preset.
Sourcepub unsafe fn sessionPreset(&self) -> Retained<AVCaptureSessionPreset>
Available on crate feature AVCaptureSessionPreset only.
pub unsafe fn sessionPreset(&self) -> Retained<AVCaptureSessionPreset>
AVCaptureSessionPreset only.Indicates the session preset currently in use by the receiver.
The value of this property is an AVCaptureSessionPreset indicating the current session preset in use by the receiver. The sessionPreset property may be set while the receiver is running.
Sourcepub unsafe fn setSessionPreset(&self, session_preset: &AVCaptureSessionPreset)
Available on crate feature AVCaptureSessionPreset only.
pub unsafe fn setSessionPreset(&self, session_preset: &AVCaptureSessionPreset)
AVCaptureSessionPreset only.Setter for sessionPreset.
Sourcepub unsafe fn inputs(&self) -> Retained<NSArray<AVCaptureInput>>
Available on crate feature AVCaptureInput only.
pub unsafe fn inputs(&self) -> Retained<NSArray<AVCaptureInput>>
AVCaptureInput only.An NSArray of AVCaptureInputs currently added to the receiver.
The value of this property is an NSArray of AVCaptureInputs currently added to the receiver. Clients can add AVCaptureInputs to a session by calling -addInput:.
Sourcepub unsafe fn canAddInput(&self, input: &AVCaptureInput) -> bool
Available on crate feature AVCaptureInput only.
pub unsafe fn canAddInput(&self, input: &AVCaptureInput) -> bool
AVCaptureInput only.Returns whether the proposed input can be added to the receiver.
Parameter input: An AVCaptureInput instance.
Returns: YES if the proposed input can be added to the receiver, NO otherwise.
An AVCaptureInput instance can only be added to a session using -addInput: if -canAddInput: returns YES, otherwise an NSInvalidArgumentException is thrown.
Sourcepub unsafe fn addInput(&self, input: &AVCaptureInput)
Available on crate feature AVCaptureInput only.
pub unsafe fn addInput(&self, input: &AVCaptureInput)
AVCaptureInput only.Adds an AVCaptureInput to the session.
Parameter input: An AVCaptureInput instance.
An AVCaptureInput instance can only be added to a session using -addInput: if -canAddInput: returns YES, otherwise an NSInvalidArgumentException is thrown. -addInput: may be called while the session is running.
Sourcepub unsafe fn removeInput(&self, input: &AVCaptureInput)
Available on crate feature AVCaptureInput only.
pub unsafe fn removeInput(&self, input: &AVCaptureInput)
AVCaptureInput only.Removes an AVCaptureInput from the session.
Parameter input: An AVCaptureInput instance.
-removeInput: may be called while the session is running.
Sourcepub unsafe fn outputs(&self) -> Retained<NSArray<AVCaptureOutput>>
Available on crate feature AVCaptureOutputBase only.
pub unsafe fn outputs(&self) -> Retained<NSArray<AVCaptureOutput>>
AVCaptureOutputBase only.An NSArray of AVCaptureOutputs currently added to the receiver.
The value of this property is an NSArray of AVCaptureOutputs currently added to the receiver. Clients can add AVCaptureOutputs to a session by calling -addOutput:.
Sourcepub unsafe fn canAddOutput(&self, output: &AVCaptureOutput) -> bool
Available on crate feature AVCaptureOutputBase only.
pub unsafe fn canAddOutput(&self, output: &AVCaptureOutput) -> bool
AVCaptureOutputBase only.Returns whether the proposed output can be added to the receiver.
Parameter output: An AVCaptureOutput instance.
Returns: YES if the proposed output can be added to the receiver, NO otherwise.
An AVCaptureOutput instance can only be added to a session using -addOutput: if -canAddOutput: returns YES, otherwise an NSInvalidArgumentException is thrown.
On iOS and Mac Catalyst, some limitations to adding combinations of different types of outputs apply:
- A maximum of one output of each type may be added. For applications linked on or after iOS 16.0, this restriction no longer applies to AVCaptureVideoDataOutputs. When adding more than one AVCaptureVideoDataOutput, AVCaptureSession.hardwareCost must be taken into account.
- A session cannot contain both an AVCaptureStillImageOutput and an AVCapturePhotoOutput at the same time.
- Prior to iOS 16.0, an AVCaptureVideoDataOutput and an AVCaptureMovieFileOutput may be added to the same session, but only one may have its connection active. When both have their connections enabled, the AVCaptureMovieFileOutput “wins” and the AVCaptureVideoDataOutput’s connection becomes inactive. For applications linked on or after iOS 16.0, this restriction has been lifted. When adding multiple AVCaptureVideoDataOutputs or a combination of AVCaptureVideoDataOutputs and an AVCaptureMovieFileOutput, AVCaptureSession.hardwareCost must be taken into account.
- Similarly, prior to iOS 16.0, an AVCaptureAudioDataOutput and an AVCaptureMovieFileOutput may be added to the same session, but only one may have its connection active. When both have their connections enabled, the AVCaptureMovieFileOutput “wins” and the AVCaptureAudioDataOutput’s connection becomes inactive. For applications linked on or after iOS 16.0, this restriction has been lifted.
Sourcepub unsafe fn addOutput(&self, output: &AVCaptureOutput)
Available on crate feature AVCaptureOutputBase only.
pub unsafe fn addOutput(&self, output: &AVCaptureOutput)
AVCaptureOutputBase only.Adds an AVCaptureOutput to the session.
Parameter output: An AVCaptureOutput instance.
An AVCaptureOutput instance can only be added to a session using -addOutput: if -canAddOutput: returns YES, otherwise an NSInvalidArgumentException is thrown. -addOutput: may be called while the session is running.
Sourcepub unsafe fn removeOutput(&self, output: &AVCaptureOutput)
Available on crate feature AVCaptureOutputBase only.
pub unsafe fn removeOutput(&self, output: &AVCaptureOutput)
AVCaptureOutputBase only.Removes an AVCaptureOutput from the session.
Parameter output: An AVCaptureOutput instance.
-removeOutput: may be called while the session is running.
Sourcepub unsafe fn addInputWithNoConnections(&self, input: &AVCaptureInput)
Available on crate feature AVCaptureInput only.
pub unsafe fn addInputWithNoConnections(&self, input: &AVCaptureInput)
AVCaptureInput only.Adds an AVCaptureInput to the session without forming any connections.
Parameter input: An AVCaptureInput instance.
An AVCaptureInput instance can only be added to a session using -addInputWithNoConnections: if -canAddInput: returns YES, otherwise an NSInvalidArgumentException is thrown. -addInputWithNoConnections: may be called while the session is running. The -addInput: method is the preferred method for adding an input to an AVCaptureSession. -addInputWithNoConnections: may be called if you need fine-grained control over which inputs are connected to which outputs.
Sourcepub unsafe fn addOutputWithNoConnections(&self, output: &AVCaptureOutput)
Available on crate feature AVCaptureOutputBase only.
pub unsafe fn addOutputWithNoConnections(&self, output: &AVCaptureOutput)
AVCaptureOutputBase only.Adds an AVCaptureOutput to the session without forming any connections.
Parameter output: An AVCaptureOutput instance.
An AVCaptureOutput instance can only be added to a session using -addOutputWithNoConnections: if -canAddOutput: returns YES, otherwise an NSInvalidArgumentException is thrown. -addOutputWithNoConnections: may be called while the session is running. The -addOutput: method is the preferred method for adding an output to an AVCaptureSession. -addOutputWithNoConnections: may be called if you need fine-grained control over which inputs are connected to which outputs.
Sourcepub unsafe fn connections(&self) -> Retained<NSArray<AVCaptureConnection>>
pub unsafe fn connections(&self) -> Retained<NSArray<AVCaptureConnection>>
An NSArray of AVCaptureConnections currently added to the receiver.
The value of this property is an NSArray of AVCaptureConnections currently added to the receiver. Connections are formed implicitly by the receiver when a client calls -addInput: or -addOutput:. Connections are formed explicitly when a client calls -addConnection:.
Sourcepub unsafe fn canAddConnection(&self, connection: &AVCaptureConnection) -> bool
pub unsafe fn canAddConnection(&self, connection: &AVCaptureConnection) -> bool
Returns whether the proposed connection can be added to the receiver.
Parameter connection: An AVCaptureConnection instance.
An AVCaptureConnection instance can only be added to a session using -addConnection: if -canAddConnection: returns YES, otherwise an NSInvalidArgumentException is thrown. When using -addInput: or -addOutput:, connections are formed automatically between all compatible inputs and outputs. Manually adding connections is only necessary when adding an input or output with no connections.
Sourcepub unsafe fn addConnection(&self, connection: &AVCaptureConnection)
pub unsafe fn addConnection(&self, connection: &AVCaptureConnection)
Adds an AVCaptureConnection to the session.
Parameter connection: An AVCaptureConnection instance.
An AVCaptureConnection instance can only be added to a session using -addConnection: if canAddConnection: returns YES, otherwise an NSInvalidArgumentException is thrown. When using -addInput: or -addOutput:, connections are formed automatically between all compatible inputs and outputs. Manually adding connections is only necessary when adding an input or output with no connections. -addConnection: may be called while the session is running.
Sourcepub unsafe fn removeConnection(&self, connection: &AVCaptureConnection)
pub unsafe fn removeConnection(&self, connection: &AVCaptureConnection)
Removes an AVCaptureConnection from the session.
Parameter connection: An AVCaptureConnection instance.
-removeConnection: may be called while the session is running.
Sourcepub unsafe fn supportsControls(&self) -> bool
pub unsafe fn supportsControls(&self) -> bool
Indicates whether session controls are supported on this platform.
AVCaptureControls are only supported on platforms with necessary hardware.
Sourcepub unsafe fn maxControlsCount(&self) -> NSInteger
pub unsafe fn maxControlsCount(&self) -> NSInteger
Specifies the maximum number of controls that can be added to a session.
Sourcepub unsafe fn controlsDelegate(
&self,
) -> Option<Retained<ProtocolObject<dyn AVCaptureSessionControlsDelegate>>>
pub unsafe fn controlsDelegate( &self, ) -> Option<Retained<ProtocolObject<dyn AVCaptureSessionControlsDelegate>>>
The receiver’s controls delegate.
The value of this property is an object conforming to the AVCaptureSessionControlsDelegate protocol that receives events about the session’s controls. The delegate is set using the -setControlsDelegate:queue: method.
A controls delegate must be specified for controls to become active.
Sourcepub unsafe fn controls(&self) -> Retained<NSArray<AVCaptureControl>>
Available on crate feature AVCaptureControl only.
pub unsafe fn controls(&self) -> Retained<NSArray<AVCaptureControl>>
AVCaptureControl only.An NSArray of AVCaptureControls currently added to the session.
The value of this property is an NSArray of AVCaptureControls currently added to the session. Clients can add AVCaptureControls to a session by calling -addControl:.
Sourcepub unsafe fn canAddControl(&self, control: &AVCaptureControl) -> bool
Available on crate feature AVCaptureControl only.
pub unsafe fn canAddControl(&self, control: &AVCaptureControl) -> bool
AVCaptureControl only.Returns whether the proposed control can be added to the session.
Parameter control: An AVCaptureControl instance.
Returns: YES if the proposed control can be added to the session, NO otherwise.
An AVCaptureControl instance can only be added to a session using -addControl: if -canAddControl: returns YES. For example, some platforms do not support controls. Instances of AVCaptureSlider, AVCaptureToggle and AVCaptureIndexPicker must have an action and an action queue set before being added to a session.
Sourcepub unsafe fn addControl(&self, control: &AVCaptureControl)
Available on crate feature AVCaptureControl only.
pub unsafe fn addControl(&self, control: &AVCaptureControl)
AVCaptureControl only.Adds an AVCaptureControl instance to the session.
Parameter control: An AVCaptureControl instance.
An AVCaptureControl instance can only be added to a session using -addControl: if -canAddControl: returns YES, otherwise an NSInvalidArgumentException is thrown. -addControl: may be called while the session is running.
For an AVCaptureControl instance to become active, an AVCaptureSessionControlsDelegate must be set on the session.
Sourcepub unsafe fn removeControl(&self, control: &AVCaptureControl)
Available on crate feature AVCaptureControl only.
pub unsafe fn removeControl(&self, control: &AVCaptureControl)
AVCaptureControl only.Removes an AVCaptureControl instance from the session.
Parameter control: An AVCaptureControl instance.
-removeControl: may be called while the session is running.
Sourcepub unsafe fn beginConfiguration(&self)
pub unsafe fn beginConfiguration(&self)
When paired with commitConfiguration, allows a client to batch multiple configuration operations on a running session into atomic updates.
-beginConfiguration / -commitConfiguration are AVCaptureSession’s mechanism for batching multiple configuration operations on a running session into atomic updates. After calling [session beginConfiguration], clients may add or remove outputs, alter the sessionPreset, or configure individual AVCaptureInput or Output properties. All changes will be pended until the client calls [session commitConfiguration], at which time they will be applied together. -beginConfiguration / -commitConfiguration pairs may be nested, and will only be applied when the outermost commit is invoked. If you’ve called -beginConfiguration, you must call -commitConfiguration before invoking -startRunning or -stopRunning, otherwise an NSGenericException is thrown.
Sourcepub unsafe fn commitConfiguration(&self)
pub unsafe fn commitConfiguration(&self)
When preceded by beginConfiguration, allows a client to batch multiple configuration operations on a running session into atomic updates.
-beginConfiguration / -commitConfiguration are AVCaptureSession’s mechanism for batching multiple configuration operations on a running session into atomic updates. After calling [session beginConfiguration], clients may add or remove outputs, alter the sessionPreset, or configure individual AVCaptureInput or Output properties. All changes will be pended until the client calls [session commitConfiguration], at which time they will be applied together. -beginConfiguration / -commitConfiguration pairs may be nested, and will only be applied when the outermost commit is invoked. If you’ve called -beginConfiguration, you must call -commitConfiguration before invoking -startRunning or -stopRunning, otherwise an NSGenericException is thrown.
Sourcepub unsafe fn isRunning(&self) -> bool
pub unsafe fn isRunning(&self) -> bool
Indicates whether the session is currently running.
The value of this property is a BOOL indicating whether the receiver is running. Clients can key value observe the value of this property to be notified when the session automatically starts or stops running.
Sourcepub unsafe fn isInterrupted(&self) -> bool
pub unsafe fn isInterrupted(&self) -> bool
Indicates whether the session is being interrupted.
The value of this property is a BOOL indicating whether the receiver is currently being interrupted, such as by a phone call or alarm. Clients can key value observe the value of this property to be notified when the session ceases to be interrupted and again has access to needed hardware resources.
Sourcepub unsafe fn isMultitaskingCameraAccessSupported(&self) -> bool
pub unsafe fn isMultitaskingCameraAccessSupported(&self) -> bool
Returns whether the session can be configured to use the camera while multitasking.
This property can be used to determine whether multitaskingCameraAccessEnabled may be set to YES. When this property changes from YES to NO, multitaskingCameraAccessEnabled also reverts to NO.
Prior to iOS 18, this property returns YES on iPads that support Stage Manager with an extended display. In applications linked on or after iOS 18, this property returns YES for video conferencing applications (apps that use “voip” as one of their UIBackgroundModes).
This property also returns YES for iOS applications that have the com.apple.developer.avfoundation.multitasking-camera-access entitlement.
This property returns YES on Apple TV.
This property is key-value observable.
Sourcepub unsafe fn isMultitaskingCameraAccessEnabled(&self) -> bool
pub unsafe fn isMultitaskingCameraAccessEnabled(&self) -> bool
Indicates whether the session is configured to use the camera while multitasking.
The default value is NO. This property may only be set if -isMultitaskingCameraAccessSupported returns YES. This property must be set before the session starts running.
AVCaptureSessions that are configured to use the camera while multitasking will not be interrupted with AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps.
For applications that have the com.apple.developer.avfoundation.multitasking-camera-access entitlement, this property defaults to YES if -isMultitaskingCameraAccessSupported returns YES.
To learn about best practices for using the camera while multitasking, refer to the Accessing the Camera While Multitasking article on developer.apple.com. See https://developer.apple.com/documentation/avkit/accessing_the_camera_while_multitasking .
This property is key-value observable.
Sourcepub unsafe fn setMultitaskingCameraAccessEnabled(
&self,
multitasking_camera_access_enabled: bool,
)
pub unsafe fn setMultitaskingCameraAccessEnabled( &self, multitasking_camera_access_enabled: bool, )
Setter for isMultitaskingCameraAccessEnabled.
Sourcepub unsafe fn usesApplicationAudioSession(&self) -> bool
pub unsafe fn usesApplicationAudioSession(&self) -> bool
Indicates whether the receiver will use the application’s AVAudioSession for recording.
The value of this property is a BOOL indicating whether the receiver is currently using the application’s AVAudioSession (see AVAudioSession.h). Prior to iOS 7, AVCaptureSession uses its own audio session, which can lead to unwanted interruptions when interacting with the application’s audio session. In applications linked on or after iOS 7, AVCaptureSession shares the application’s audio session, allowing for simultaneous play back and recording without unwanted interruptions. Clients desiring the pre-iOS 7 behavior may opt out by setting usesApplicationAudioSession to NO. The default value is YES.
Sourcepub unsafe fn setUsesApplicationAudioSession(
&self,
uses_application_audio_session: bool,
)
pub unsafe fn setUsesApplicationAudioSession( &self, uses_application_audio_session: bool, )
Setter for usesApplicationAudioSession.
Sourcepub unsafe fn automaticallyConfiguresApplicationAudioSession(&self) -> bool
pub unsafe fn automaticallyConfiguresApplicationAudioSession(&self) -> bool
Indicates whether the receiver should configure the application’s audio session for recording.
The value of this property is a BOOL indicating whether the receiver should configure the application’s audio session when needed for optimal recording. When set to YES, the receiver ensures the application’s audio session is set to the PlayAndRecord category, and picks an appropriate microphone and polar pattern to match the video camera being used. When set to NO, and -usesApplicationAudioSession is set to YES, the receiver will use the application’s audio session, but will not change any of its properties. If the session is not set up correctly for input, audio recording may fail. The default value is YES.
Sourcepub unsafe fn setAutomaticallyConfiguresApplicationAudioSession(
&self,
automatically_configures_application_audio_session: bool,
)
pub unsafe fn setAutomaticallyConfiguresApplicationAudioSession( &self, automatically_configures_application_audio_session: bool, )
Setter for automaticallyConfiguresApplicationAudioSession.
Sourcepub unsafe fn configuresApplicationAudioSessionToMixWithOthers(&self) -> bool
pub unsafe fn configuresApplicationAudioSessionToMixWithOthers(&self) -> bool
Indicates whether the receiver should configure the application’s audio session to mix with others.
The value of this property is a BOOL indicating whether the receiver should configure the application’s audio session to mix with, instead of interrupting, any ongoing audio sessions. It has no effect when usesApplicationAudioSession is set to NO. It also has no effect on Live Photo movie complement capture (where music is always mixed with). The default value is NO.
Sourcepub unsafe fn setConfiguresApplicationAudioSessionToMixWithOthers(
&self,
configures_application_audio_session_to_mix_with_others: bool,
)
pub unsafe fn setConfiguresApplicationAudioSessionToMixWithOthers( &self, configures_application_audio_session_to_mix_with_others: bool, )
Setter for configuresApplicationAudioSessionToMixWithOthers.
Sourcepub unsafe fn automaticallyConfiguresCaptureDeviceForWideColor(&self) -> bool
pub unsafe fn automaticallyConfiguresCaptureDeviceForWideColor(&self) -> bool
Indicates whether the receiver automatically configures its video device’s activeFormat and activeColorSpace properties, preferring wide color for photos.
The default value is YES. By default, the receiver automatically adjusts its source video AVCaptureDevice’s activeFormat and activeColorSpace properties based on the supportedColorSpaces of the device’s formats and the current AVCaptureSession topology. Wide color spaces are preferred over sRGB if an AVCapturePhotoOutput is present in the session. If you wish to set AVCaptureDevice’s activeColorSpace manually, and prevent the AVCaptureSession from undoing your work, you must set automaticallyConfiguresCaptureDeviceForWideColor to NO. If the receiver’s sessionPreset is set to AVCaptureSessionPresetInputPriority, the session will not alter the capture device’s activeFormat, but might still alter its activeColorSpace.
Sourcepub unsafe fn setAutomaticallyConfiguresCaptureDeviceForWideColor(
&self,
automatically_configures_capture_device_for_wide_color: bool,
)
pub unsafe fn setAutomaticallyConfiguresCaptureDeviceForWideColor( &self, automatically_configures_capture_device_for_wide_color: bool, )
Setter for automaticallyConfiguresCaptureDeviceForWideColor.
Sourcepub unsafe fn startRunning(&self)
pub unsafe fn startRunning(&self)
Starts an AVCaptureSession instance running.
Clients invoke -startRunning to start the flow of data from inputs to outputs connected to the AVCaptureSession instance. This call blocks until the session object has completely started up or failed. A failure to start running is reported through the AVCaptureSessionRuntimeErrorNotification mechanism. If you’ve called -beginConfiguration, you must call -commitConfiguration before invoking -startRunning, otherwise an NSGenericException is thrown.
Sourcepub unsafe fn stopRunning(&self)
pub unsafe fn stopRunning(&self)
Stops an AVCaptureSession instance that is currently running.
Clients invoke -stopRunning to stop the flow of data from inputs to outputs connected to the AVCaptureSession instance. This call blocks until the session object has completely stopped. -stopRunning may not be called while the session is being configured. If you’ve called -beginConfiguration, you must call -commitConfiguration before invoking -stopRunning, otherwise an NSGenericException is thrown.
Sourcepub unsafe fn synchronizationClock(&self) -> Option<Retained<CMClock>>
Available on crate feature objc2-core-media only.
pub unsafe fn synchronizationClock(&self) -> Option<Retained<CMClock>>
objc2-core-media only.Provides the clock being used for synchronization.
synchronizationClock is readonly. Use synchronizationClock to synchronize AVCaptureOutput data with external data sources (e.g motion samples). All capture output sample buffer timestamps are on the synchronizationClock timebase.
For example, if you want to reverse synchronize the output timestamps to the original timestamps, you can do the following: In captureOutput:didOutputSampleBuffer:fromConnection:
AVCaptureInputPort *port = [[connection inputPorts] objectAtIndex:0]; CMClockRef originalClock = [port clock];
CMTime syncedPTS = CMSampleBufferGetPresentationTime( sampleBuffer ); CMTime originalPTS = CMSyncConvertTime( syncedPTS, [session synchronizationClock], originalClock );
This property is key-value observable.
Sourcepub unsafe fn masterClock(&self) -> Option<Retained<CMClock>>
👎DeprecatedAvailable on crate feature objc2-core-media only.
pub unsafe fn masterClock(&self) -> Option<Retained<CMClock>>
objc2-core-media only.Provides the clock being used for synchronization.
Deprecated. Please use synchronizationClock instead.
Sourcepub unsafe fn hardwareCost(&self) -> c_float
pub unsafe fn hardwareCost(&self) -> c_float
Indicates the percentage of the session’s available hardware budget currently in use.
The value of this property is a float from 0.0 => 1.0 indicating how much of the session’s available hardware is in use as a percentage, given the currently connected inputs and outputs and the features for which you’ve opted in. When your hardwareCost is greater than 1.0, the capture session cannot run your desired configuration due to hardware constraints, so you receive an AVCaptureSessionRuntimeErrorNotification when attempting to start it running. Default value is 0.
Contributors to hardwareCost include:
- Whether the source device’s active format uses the full sensor (4:3) or a crop (16:9). Cropped formats require lower hardware bandwidth, and therefore lower the cost.
- The max frame rate supported by the source device’s active format. The higher the max frame rate, the higher the cost.
- Whether the source device’s active format is binned or not. Binned formats require substantially less hardware bandwidth, and therefore result in a lower cost.
- The number of sources configured to deliver streaming disparity / depth via AVCaptureDepthDataOutput. The higher the number of cameras configured to produce depth, the higher the cost. For AVCaptureMultiCamSessions, all of the source devices’ active formats contribute to hardwareCost. In order to reduce hardwareCost, consider picking a sensor-cropped activeFormat, or a binned format. You may also use AVCaptureDeviceInput’s videoMinFrameDurationOverride property to artificially limit the max frame rate (which is the reciprocal of the min frame duration) of a source device to a lower value. By doing so, you only pay the hardware cost for the max frame rate you intend to use.
AVCaptureMultiCamSessions always computes this hardwareCost. AVCaptureSessions only computes a non-zero hardwareCost when multiple AVCaptureVideoDataOutputs or an AVCaptureMovieFileOutput and one or more AVCaptureVideoDataOutputs are added to the session.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AVCaptureSession> for AVCaptureMultiCamSession
impl AsRef<AVCaptureSession> for AVCaptureMultiCamSession
Source§fn as_ref(&self) -> &AVCaptureSession
fn as_ref(&self) -> &AVCaptureSession
Source§impl AsRef<AVCaptureSession> for AVCaptureSession
impl AsRef<AVCaptureSession> for AVCaptureSession
Source§impl AsRef<AnyObject> for AVCaptureSession
impl AsRef<AnyObject> for AVCaptureSession
Source§impl AsRef<NSObject> for AVCaptureSession
impl AsRef<NSObject> for AVCaptureSession
Source§impl Borrow<AVCaptureSession> for AVCaptureMultiCamSession
impl Borrow<AVCaptureSession> for AVCaptureMultiCamSession
Source§fn borrow(&self) -> &AVCaptureSession
fn borrow(&self) -> &AVCaptureSession
Source§impl Borrow<AnyObject> for AVCaptureSession
impl Borrow<AnyObject> for AVCaptureSession
Source§impl Borrow<NSObject> for AVCaptureSession
impl Borrow<NSObject> for AVCaptureSession
Source§impl ClassType for AVCaptureSession
impl ClassType for AVCaptureSession
Source§const NAME: &'static str = "AVCaptureSession"
const NAME: &'static str = "AVCaptureSession"
Source§type ThreadKind = <<AVCaptureSession as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<AVCaptureSession as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for AVCaptureSession
impl Debug for AVCaptureSession
Source§impl Deref for AVCaptureSession
impl Deref for AVCaptureSession
Source§impl Hash for AVCaptureSession
impl Hash for AVCaptureSession
Source§impl Message for AVCaptureSession
impl Message for AVCaptureSession
Source§impl NSObjectProtocol for AVCaptureSession
impl NSObjectProtocol for AVCaptureSession
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref