-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_avfoundation] Implementation swift migration - part 4 #9219
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] Implementation swift migration - part 4 #9219
Conversation
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.
not a complete review. is this the last remaining work?
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCam.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockFLTCam.swift
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/SampleBufferTests.swift
Outdated
Show resolved
Hide resolved
...a/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPlugin.swift
Outdated
Show resolved
Hide resolved
.../camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.swift
Outdated
Show resolved
Hide resolved
.../camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.swift
Outdated
Show resolved
Hide resolved
.../camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.swift
Outdated
Show resolved
Hide resolved
...avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTImageStreamHandler.swift
Outdated
Show resolved
Hide resolved
This is the main part but it's not the last. There will be a ~3 more PRs I think. ~2 with migration of all the protocols which is a formality and one with the switch to a Swift based pigeon which will include some more significant changes |
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.
Sorry it's really really hard for me to review this PR due to its size and complexity of the logic. Is it possible for you to have separate PRs that break out smaller bits first (e.g. stateless helpers)?
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraTestUtils.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift
Show resolved
Hide resolved
.../camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift
Outdated
Show resolved
Hide resolved
917fe7e
to
d49c640
Compare
@hellohuanlin I've extracted whatever was possible to part 3.5. I will rebase this one on main once 3.5 is merged |
Migrates camera implementation as part of flutter/flutter#119109 This PR consists of everything that was possible to extract from the [part 4](#9219) which includes: * Adds `audioCaptureDeviceFactory` to `FLTCamConfiguration`. * Renames the `lockCaptureOrientation` method of Objective-C type `FLTCam` when exported to Swift. * Renames arguments of the `captureOutput` method of Objective-C type `FLTCam` when exported to Swift. * Changes the `connection` argument type of the `captureOutput` method of the of `FLTCam` class to `AVCaptureConnection`. * Makes `minimum/maximumAvailableZoomFactor` and `minimum/maximumExposureOffset` fields of `FLTCam` readonly. * Remove `@testable` from `camera_avfoundation_objc` imports ## Pre-Review Checklist [^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.
3ba84c1
to
52f0941
Compare
It's still big but at least a bit smaller now |
details: error.domain) | ||
} | ||
|
||
private static func createConnection( |
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 try to further reduce the size of PR again? For example, static members can be moved out since it doesn't depend on camera states. For non-static members, some stateless logic can be factored out, and others can be reorganized into extensions.
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 don't think we can meaningfully reduce the size of this PR without a significant refactor, which I don't have a budget for. What I think we can do instead is try to migrate this class in smaller parts. Keep a "base" implementation in ObjC, subclass it in Swift, and move method implementation in smaller chunks from the "base" ObjC class to the Swift subclass. Let me know what you think
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.
That'd be great. Smaller PRs will be much easier to review. Sorry about the extra work. I really want to make sure this class is done right, since it's the hardest one.
52f0941
to
d0e1eb9
Compare
d0e1eb9
to
18fba53
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.
LGTM! Thanks for splitting it into smaller PRs.
@@ -81,16 +81,16 @@ enum CameraTestUtils { | |||
return configuration | |||
} | |||
|
|||
static func createTestCamera(_ configuration: FLTCamConfiguration) -> FLTCam { | |||
return FLTCam(configuration: configuration, error: nil) | |||
static func createTestCamera(_ configuration: FLTCamConfiguration) -> DefaultCamera { |
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: -> Camera
(same below)
@@ -69,7 +69,7 @@ private class FakeMediaSettingsAVWrapper: FLTCamMediaSettingsAVWrapper { | |||
/// Includes test cases related to sample buffer handling for FLTCam class. | |||
final class CameraSampleBufferTests: XCTestCase { | |||
private func createCamera() -> ( | |||
FLTCam, | |||
DefaultCamera, |
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.
here too, and a few other places
Migrates camera implementation as part of flutter/flutter#119109
This PR migrates a part of
FLTCam
class to Swift. To avoid migrating the whole huge class to Swift at once and a refactor that we don't have a budget for we are extending theFLTCam
class in swift (DefaultCamera
). We will now migrate the methods in smaller chunks.This PR includes the first chunk:
captureOutput
(fromAVCaptureVideoDataOutputSampleBufferDelegate
,AVCaptureAudioDataOutputSampleBufferDelegate
protocols)copyPixelBuffer
(fromFlutterTexture
protocol)Some properties of the
FLTCam
have to be temporarily made public so that they are accessible inDefaultCamera
.The
DefaultCamera
class conforms to the newCamera
protocol. A few properties defined inFLTCam
are now markednullable
to match theCamera
protocol and the reality.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.
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