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


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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be sure, you mean to expand this comment in code to explain the behavior of SwiftPM vs CocoaPods? I'm not sure if it's the best place because this comment occurs in 49 different files

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Could you reply it here, and also update the first PR that first introduced these comments, for future readers


/// 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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this isn't updated yet? Let me know when this PR is ready for another pass


/// 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?

Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartmorgan-g wanna double check if you have any preference

Copy link
Collaborator

Choose a reason for hiding this comment

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

VideoDimensionsConverter sounds good to me; I agree that sounds more like the type of a method rather than a method.

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be renamed to connection(with mediaType...) and it will have to once FLTCaptureConnection is migrated to Swift and AVCaptureOutput conforms to the protocol. So I will change it now

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