Skip to content

Commit 93e91f3

Browse files
[camera_avfoundation] Fix incorrect types in image stream events (#9418)
Fixes the types used in the image stream events. Most importantly, it corrects the `lensAperture` to `lensAperture**()**` that caused a crash. Some other arguments were also updated to match exactly the types expected by the parsing in `type_conversions.dart`. Resolves: flutter/flutter#170240 ## 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.
1 parent ee7092f commit 93e91f3

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

packages/camera/camera_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
## 0.9.20
2+
3+
* Fixes incorrect types in image stream events.
4+
15
## 0.9.19+3
26

37
* Fixes race condition when starting image stream.
48

5-
69
## 0.9.19+2
710

811
* Adds the `Camera` Swift protocol.

packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,41 @@ final class StreamingTests: XCTestCase {
123123

124124
waitForExpectations(timeout: 30, handler: nil)
125125
}
126+
127+
func testImageStreamEventFormat() {
128+
let (camera, testAudioOutput, sampleBuffer, testAudioConnection) = createCamera()
129+
130+
let expectation = expectation(description: "Received a valid event")
131+
132+
let handlerMock = MockImageStreamHandler()
133+
handlerMock.eventSinkStub = { event in
134+
let imageBuffer = event as! [String: Any]
135+
136+
XCTAssertTrue(imageBuffer["width"] is NSNumber)
137+
XCTAssertTrue(imageBuffer["height"] is NSNumber)
138+
XCTAssertTrue(imageBuffer["format"] is NSNumber)
139+
XCTAssertTrue(imageBuffer["lensAperture"] is NSNumber)
140+
XCTAssertTrue(imageBuffer["sensorExposureTime"] is NSNumber)
141+
XCTAssertTrue(imageBuffer["sensorSensitivity"] is NSNumber)
142+
143+
let planes = imageBuffer["planes"] as! [[String: Any]]
144+
let planeBuffer = planes[0]
145+
146+
XCTAssertTrue(planeBuffer["bytesPerRow"] is NSNumber)
147+
XCTAssertTrue(planeBuffer["width"] is NSNumber)
148+
XCTAssertTrue(planeBuffer["height"] is NSNumber)
149+
XCTAssertTrue(planeBuffer["bytes"] is FlutterStandardTypedData)
150+
151+
expectation.fulfill()
152+
}
153+
let messenger = MockFlutterBinaryMessenger()
154+
camera.startImageStream(with: messenger, imageStreamHandler: handlerMock) { _ in }
155+
156+
waitForQueueRoundTrip(with: DispatchQueue.main)
157+
XCTAssertEqual(camera.isStreamingImages, true)
158+
159+
camera.captureOutput(testAudioOutput, didOutput: sampleBuffer, from: testAudioConnection)
160+
161+
waitForExpectations(timeout: 30, handler: nil)
162+
}
126163
}

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ final class DefaultCamera: FLTCam, Camera {
105105
"height": imageHeight,
106106
"format": videoFormat,
107107
"planes": planes,
108-
"lensAperture": captureDevice.lensAperture,
109-
"sensorExposureTime": NSNumber(
110-
value: captureDevice.exposureDuration().seconds * 1_000_000_000),
111-
"sensorSensitivity": NSNumber(value: captureDevice.iso()),
108+
"lensAperture": Double(captureDevice.lensAperture()),
109+
"sensorExposureTime": Int(captureDevice.exposureDuration().seconds * 1_000_000_000),
110+
"sensorSensitivity": Double(captureDevice.iso()),
112111
]
113112

114113
DispatchQueue.main.async {

packages/camera/camera_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_avfoundation
22
description: iOS implementation of the camera plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.9.19+3
5+
version: 0.9.20
66

77
environment:
88
sdk: ^3.6.0

0 commit comments

Comments
 (0)