Skip to content
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

Closed
wants to merge 15 commits into from
Closed

Image streaming WIP #8

wants to merge 15 commits into from

Conversation

liff
Copy link
Collaborator

@liff liff commented Dec 3, 2024

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

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

liff added 9 commits November 25, 2024 11:54
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.
liff added 5 commits December 3, 2024 13:39
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.
@liff liff requested a review from jokerttu December 4, 2024 10:05
Copy link

@jokerttu jokerttu left a 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) =>
Copy link

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.

@liff liff closed this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants