Instance Method

ports(for:sourceDeviceType:sourceDevicePosition:)

Retrieves a virtual device’s constituent device ports for use in a multi-camera session.

Declaration

func ports(for mediaType: AVMediaType?, sourceDeviceType: AVCaptureDevice.DeviceType?, sourceDevicePosition: AVCaptureDevice.Position) -> [AVCaptureInput.Port]

Parameters

mediaType

The media type of the port you’re searching for, or nil if all media types should be considered.

sourceDeviceType

The device type of the port you’re searching for, or nil if all device types should be considered.

sourceDevicePosition

The device position of the port you're searching for.

When you're searching for a camera device, a position of AVCaptureDevice.Position.unspecified indicates that all positions should be searched.

When you're searching for an audio device, AVCaptureDevice.Position.unspecified indicates that omnidirectional audio should be searched.

Return Value

An array of AVCaptureInput.Port satisfying the search criteria, or an empty array if none were found.

Discussion

AVCaptureMultiCamSession lets you simultaneously capture from multiple devices. It also lets you capture simultaneous streams from a virtual device, such as the dual camera. You use this method to find the ports associated with a virtual device’s underlying physical devices. A virtual device input’s ports property does not include constituent device ports.

Using the dual camera as an example, the ports property exposes only those ports supported by the virtual device (it switches automatically between wide-angle and telephoto cameras, depending on the zoom factor). You may use this method to find the video ports for the constituent devices.

// Look up wide-angle camera port
let wideVideoPort = dualCameraInput.ports(for: .video,
                                          sourceDeviceType: .builtInWideAngleCamera,
                                          sourceDevicePosition: .back).first

// Look up telephoto camera port
let teleVideoPort = dualCameraInput.ports(for: .video,
                                          sourceDeviceType: .builtInTelephotoCamera,
                                          sourceDevicePosition: .back).first

You can use these ports to create connections to two instances of AVCaptureVideoDataOutput, allowing for synchronized, full-frame-rate delivery of both wide-angle and telephoto streams.

When used in conjunction with an audio device, this method allows you to discover microphones in different positions. You can use the microphone ports to make output connections to simultaneously capture both front-facing and back-facing audio. The audio device port whose sourceDevicePosition is AVCaptureDevice.Position.unspecified produces omnidirectional sound.

See Also

Accessing the Device

var device: AVCaptureDevice

The input’ associated capture device.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software