-
Notifications
You must be signed in to change notification settings - Fork 0
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
Image streaming WIP #8
Conversation
…tform (flutter#7951)" This reverts commit b3a5e33.
When image stream frames are being received from Media Foundation, it appears to use a separate thread when calling the `OnSample` callback, which results in this error from: The 'plugins.flutter.io/camera_windows/imageStream' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. In order to ensure that we are only ever using the `EventChannel` from a platform thread, create a `TaskRunner` that is backed by a hidden window to submit the frames to the image stream. Based on the suggestion in this comment: flutter/flutter#134346 (comment)
Instead of a global `EventSink` that is re-used for each stream, create a dedicated `EventChannel` for each capture stream. The channel gets an unique name like `plugins.flutter.io/camera_android/imageStream/<cameraId>` for each camera instance.
We don’t really need to keep track of the subscription and controller in instance variables. It’ll work fine with a simple `async*` method, cancellation and all.
We need to have exception-throwing `onPause` and `onResume` callback, as they are required to throw by the camera platform interface.
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
One comment added
final eventChannelName = await _hostApi.startImageStream(cameraId); | ||
final EventChannel imageStreamChannel = | ||
EventChannel(eventChannelName); | ||
imageStreamChannel.receiveBroadcastStream().listen((dynamic image) => |
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.
This creates subscription.
should it be cancelled in onCancel as well.
having
late StreamSubscription subscription;
save the subscription:
subscription = imageStreamChannel.receiveBroadcastStream().listen ...
cancel the subscription:
onCancel: () async {
await subscription.cancel();
await _hostApi.stopImageStream(cameraId);
},
?
Not sure if this is needed though.
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.