Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Sample buffer handling on session queue #4709

Conversation

hellohuanlin
Copy link
Contributor

As discussed in the proposal:

SampleBuffer callback on the session queue
SampleBuffer callback is triggered whenever a new video frame or a new audio sample is arrived. This callback powers live previews, image streaming and video recording.
Currently SampleBuffer callback is invoked on either main queue or session queue. It should always be run on the session queue.

Issue here: flutter/flutter#96429

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@hellohuanlin hellohuanlin force-pushed the camera_sample_buffer_on_session_queue branch 2 times, most recently from 3abb010 to 8b908cb Compare January 28, 2022 01:15
@hellohuanlin hellohuanlin marked this pull request as ready for review January 28, 2022 01:15
@hellohuanlin hellohuanlin removed the request for review from bparrishMines January 28, 2022 01:16
@hellohuanlin hellohuanlin force-pushed the camera_sample_buffer_on_session_queue branch from 8b908cb to e68a118 Compare January 28, 2022 01:18
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

Can you also do some manual testing of these before you merge? Want some validation before customers pick up the new version.

orientation:UIDeviceOrientationPortrait
captureSessionQueue:captureSessionQueue
error:nil];
XCTAssertEqual(captureSessionQueue, cam.captureVideoOutput.sampleBufferCallbackQueue);
Copy link
Member

Choose a reason for hiding this comment

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

To use isEqual: and not ==.

Suggested change
XCTAssertEqual(captureSessionQueue, cam.captureVideoOutput.sampleBufferCallbackQueue);
XCTAssertEqualObjects(captureSessionQueue, cam.captureVideoOutput.sampleBufferCallbackQueue);

Copy link
Member

Choose a reason for hiding this comment

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

Never mind these are dispatch_queues not NSObjects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

iirc a few years ago apple made dispatch_queues objc objects. So both should be fine. Most likely isEqual will simply call == internally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

found this flag to turn on/off: OS_OBJECT_HAVE_OBJC_SUPPORT

.andReturn(inputMock);

id sessionMock = OCMClassMock([AVCaptureSession class]);
OCMStub([sessionMock alloc]).andReturn(sessionMock);
Copy link
Member

Choose a reason for hiding this comment

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

If you stub a class method you need to call -stopMock explicitly or the mock will leak between tests, it won't stop mocking when the mock object deallocs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha. good to know!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah looks like stopMocking is called on dealloc, from the doc: https://ocmock.org/reference/

The class can be returned to its original state by calling stopMocking. This is only necessary if the original state must be restored before the end of the test. The mock automatically calls stopMocking during its own deallocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrote a dummy test and verified it.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't think it works stubbing class methods, alloc in this case. Is that what you tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, i tested alloc.
Screen Shot 2022-01-28 at 2 28 23 PM

@hellohuanlin
Copy link
Contributor Author

Can you also do some manual testing of these before you merge? Want some validation before customers pick up the new version.

Sounds good. Just manual tested the sample project and verified its still working.

@hellohuanlin hellohuanlin added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Jan 28, 2022
@fluttergithubbot fluttergithubbot merged commit 72dff1b into flutter:main Jan 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: camera platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants