Skip to content

[camera_avfoundation] Fix incorrect types in image stream events #9418

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 0.9.20

* Fixes incorrect types in image stream events.

## 0.9.19+3

* Fixes race condition when starting image stream.


## 0.9.19+2

* Adds the `Camera` Swift protocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,41 @@ final class StreamingTests: XCTestCase {

waitForExpectations(timeout: 30, handler: nil)
}

func testImageStreamEventFormat() {
let (camera, testAudioOutput, sampleBuffer, testAudioConnection) = createCamera()

let expectation = expectation(description: "Received a valid event")

let handlerMock = MockImageStreamHandler()
handlerMock.eventSinkStub = { event in
let imageBuffer = event as! [String: Any]

XCTAssertTrue(imageBuffer["width"] is NSNumber)
XCTAssertTrue(imageBuffer["height"] is NSNumber)
XCTAssertTrue(imageBuffer["format"] is NSNumber)
XCTAssertTrue(imageBuffer["lensAperture"] is NSNumber)
XCTAssertTrue(imageBuffer["sensorExposureTime"] is NSNumber)
XCTAssertTrue(imageBuffer["sensorSensitivity"] is NSNumber)

let planes = imageBuffer["planes"] as! [[String: Any]]
let planeBuffer = planes[0]

XCTAssertTrue(planeBuffer["bytesPerRow"] is NSNumber)
XCTAssertTrue(planeBuffer["width"] is NSNumber)
XCTAssertTrue(planeBuffer["height"] is NSNumber)
XCTAssertTrue(planeBuffer["bytes"] is FlutterStandardTypedData)

expectation.fulfill()
}
let messenger = MockFlutterBinaryMessenger()
camera.startImageStream(with: messenger, imageStreamHandler: handlerMock) { _ in }

waitForQueueRoundTrip(with: DispatchQueue.main)
XCTAssertEqual(camera.isStreamingImages, true)

camera.captureOutput(testAudioOutput, didOutput: sampleBuffer, from: testAudioConnection)

waitForExpectations(timeout: 30, handler: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ final class DefaultCamera: FLTCam, Camera {
"height": imageHeight,
"format": videoFormat,
"planes": planes,
"lensAperture": captureDevice.lensAperture,
"sensorExposureTime": NSNumber(
value: captureDevice.exposureDuration().seconds * 1_000_000_000),
"sensorSensitivity": NSNumber(value: captureDevice.iso()),
"lensAperture": Double(captureDevice.lensAperture()),
Copy link
Contributor

Choose a reason for hiding this comment

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

was it trying to convert a closure (memory address) to double?

"sensorExposureTime": Int(captureDevice.exposureDuration().seconds * 1_000_000_000),
"sensorSensitivity": Double(captureDevice.iso()),
]

DispatchQueue.main.async {
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.19+3
version: 0.9.20

environment:
sdk: ^3.6.0
Expand Down