<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 14.0.0 -",
    "tvOS: 17.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptureDeviceInput/ports(for:sourceDeviceType:sourceDevicePosition:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptureDeviceInput(im)portsWithMediaType:sourceDeviceType:sourceDevicePosition:"
  },
  "title" : "ports(for:sourceDeviceType:sourceDevicePosition:)"
}
-->

# ports(for:sourceDeviceType:sourceDevicePosition:)

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

```
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` to consider all media types.

`sourceDeviceType`

The device type of the port you’re searching for, or `nil` if to consider all device types.

`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`](/documentation/AVFoundation/AVCaptureDevice/Position-swift.enum/unspecified)     indicates to search for all positions.

    When you’re searching for an audio device, [`AVCaptureDevice.Position.unspecified`](/documentation/AVFoundation/AVCaptureDevice/Position-swift.enum/unspecified)     indicates to search omnidirectional audio.

## Return Value

An array of ports that satisfy the search criteria, or an empty array if there are none.

## Discussion

[`AVCaptureMultiCamSession`](/documentation/AVFoundation/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`](/documentation/AVFoundation/AVCaptureInput/ports) property doesn’t include constituent device ports.

Using the dual camera as an example, the [`ports`](/documentation/AVFoundation/AVCaptureInput/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.

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

// Look up the 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`](/documentation/AVFoundation/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`](/documentation/AVFoundation/AVCaptureInput/Port/sourceDevicePosition) is [`AVCaptureDevice.Position.unspecified`](/documentation/AVFoundation/AVCaptureDevice/Position-swift.enum/unspecified) produces omnidirectional sound.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)