Skip to content

Conversation

RobertOdrowaz
Copy link
Contributor

Migrates camera wrappers as part of flutter/flutter#119109

This PR migrates wrappers to Swift:

  • FLTCamConfiguration
  • FLTCamMediaSettingsAVWrapper
  • FLTCaptureOutput
  • FLTCapturePhotoOutput
  • FLTCaptureVideoDataOutput

In line with Swift conventions, the FLT prefixes are removed. The Default class implementations are replaced with protocol conformance on base AV classes.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

…Output, FLTCapturePhotoOutput, FLTCaptureVideoDataOutput to Swift
@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-wrappers-swift-migration-part1 branch from 9cda6e1 to a84d272 Compare September 29, 2025 15:29
@stuartmorgan-g stuartmorgan-g added the triage-ios Should be looked at in iOS triage label Oct 1, 2025
Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only reviewed half of the PR. I wonder if you can split this into multiple PRs so it's easier review? Thanks!


mockCapturePhotoOutput.supportedFlashModes = [
NSNumber(value: AVCaptureDevice.FlashMode.auto.rawValue)
AVCaptureDevice.FlashMode.auto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just .auto

var avOutput = AVCaptureVideoDataOutput()
var alwaysDiscardsLateVideoFrames = false
var videoSettings: [String: Any] = [:]
var videoSettings: [String: Any]! = [:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change here?


import AVFoundation
import CoreMedia
import Foundation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foundation should already be auto imported (@_exported) from UIKit import.

import Foundation
import UIKit

// Import Objective-C part of the implementation when SwiftPM is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably mentioned it before, but could you document both SwiftPM and non-SwiftPM (cocoapod?) behavior in the comment?


/// Factory block returning an FLTCaptureDevice.
/// Used in tests to inject a device into DefaultCamera.
typealias CaptureDeviceFactory = (String) -> FLTCaptureDevice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be "VdieoCaptureDeviceFactory"? (see below)


typealias CaptureSessionFactory = () -> FLTCaptureSession

typealias AssetWriterFactory = (URL, AVFileType, inout NSError?) -> FLTAssetWriter?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add label so it's more readable? You may have to put an underscore there _ assetURL: URL


/// Determines the video dimensions (width and height) for a given capture device format.
/// Used in tests to mock CMVideoFormatDescriptionGetDimensions.
typealias VideoDimensionsForFormat = (FLTCaptureDeviceFormat) -> CMVideoDimensions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: from this naming it's hard to tell it's a typealias for a closure. It sounds like a method name but its first letter is uppercase.
Maybe a clearer name VideoDimensionsConverter?

typealias VideoDimensionsForFormat = (FLTCaptureDeviceFormat) -> CMVideoDimensions

/// A configuration object that centralizes dependencies for `DefaultCamera`.
class FLTCamConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call it CameraConfiguration (or not yet? )

/// `AVCaptureOutput` in tests.
protocol CaptureOutput {
/// Returns a connection with the specified media type, or nil if no such connection exists.
func connection(withMediaType mediaType: AVMediaType) -> FLTCaptureConnection?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection(with mediaType...)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh is it an apple api? if so, maybe createConnection(with mediaType)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants