-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[camera_avfoundation] Wrappers swift migration - part 1 #10119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[camera_avfoundation] Wrappers swift migration - part 1 #10119
Conversation
…Output, FLTCapturePhotoOutput, FLTCaptureVideoDataOutput to Swift
9cda6e1
to
a84d272
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just .auto
...es/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureVideoDataOutput.swift
Show resolved
Hide resolved
|
||
import AVFoundation | ||
import CoreMedia | ||
import Foundation |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connection(with mediaType...)
?
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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
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. TheDefault
class implementations are replaced with protocol conformance on baseAV
classes.Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).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
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