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

[camera_windows] Support image streams on Windows platform #7067

Merged
merged 22 commits into from
Jul 26, 2024

Conversation

jlundOverlay
Copy link
Contributor

@jlundOverlay jlundOverlay commented Jul 8, 2024

Adds support to the windows camera implementation to allow streaming of frames.

Fixes flutter/flutter#97542

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] 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/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to 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], or this PR is [exempt from CHANGELOG changes].
  • 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].

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@cbracken
Copy link
Member

cbracken commented Jul 9, 2024

Taking a look, but before I do, looks like some small Dart analysis errors:

   info - lib/camera_windows.dart:9:8 - Use relative imports for files in the 'lib' directory. Try converting the URI to a relative URI. - prefer_relative_imports
   info - lib/type_conversion.dart:19:15 - Missing type annotation. Try adding a type annotation. - always_specify_types
   info - lib/type_conversion.dart:22:24 - Unnecessary use of parentheses. Try removing the parentheses. - unnecessary_parenthesis

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! A few first-round comments.

packages/camera/camera_windows/windows/camera_plugin.cpp Outdated Show resolved Hide resolved
packages/camera/camera_windows/windows/camera_plugin.cpp Outdated Show resolved Hide resolved
packages/camera/camera_windows/windows/camera_plugin.cpp Outdated Show resolved Hide resolved
@jlundOverlay
Copy link
Contributor Author

Looks like the camera windows implementation was just switched to pigeon, unfortunate timing but I'll migrate the changes across

@cbracken
Copy link
Member

Ugh yeah was just thinking about that as I reviewed the other one. On the plus side, the code should be significantly simpler, but frustrating to deal with the merge.

# Conflicts:
#	packages/camera/camera_windows/lib/camera_windows.dart
#	packages/camera/camera_windows/windows/camera_plugin.cpp
#	packages/camera/camera_windows/windows/camera_plugin.h
@jlundOverlay
Copy link
Contributor Author

I think i have worked out how to replace the method channels, just unsure if i still need the frame event channel. flutter/flutter#66711 seems to indicate that pigeon doesn't use an event channel under the hood so I'm assuming its less performant for this use case?

@jlundOverlay jlundOverlay requested a review from cbracken July 10, 2024 01:40
@bparrishMines bparrishMines added federated: all_changes PR that contains changes for all packages for a federated plugin change and removed federated: all_changes PR that contains changes for all packages for a federated plugin change labels Jul 17, 2024
Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

LGTM to the camera change. I will leave the windows review to @cbracken and will approve on version bumps.

@sneurlax
Copy link

I tested this as working :) using @jlundOverlay's fork until this is merged, thanks!

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

lgtm for the change, modulo bot failures:

  • please add a changelog entry.
  • please fix formatting errors reported in the test failure.

LGTM stamp from a Japanese personal seal

@jlundOverlay jlundOverlay changed the title [camera] Support image streams on Windows platform [camera_windows] Support image streams on Windows platform Jul 25, 2024
@jlundOverlay
Copy link
Contributor Author

jlundOverlay commented Jul 25, 2024

I have made a new PR for the camera version bump #7220

@loic-sharma
Copy link
Member

@jlundOverlay Ideally we should have tests for this change. What do you think of updating packages/camera/camera_windows/windows/test/camera_plugin_test.cpp to check that CameraPlugin::StartImageStream and CameraPlugin::StopImageStream interact correctly with the CaptureController?

@jlundOverlay
Copy link
Contributor Author

Took me a bit to work out how to mock the EventSink but i think i got there in the end. let me know what you think.

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

Looks great! Excellent work!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 26, 2024
@auto-submit auto-submit bot merged commit b31a279 into flutter:main Jul 26, 2024
76 checks passed
"Unable to make event channel from windows"));
}

if (camera->AddPendingVoidResult(PendingResultType::kStartStream,
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are the pending results added in this PR resolved? I don't see anything in the diff that retrieves them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question, when i wrote it figured id deal with that later and forgot. What exactly are these checks used for and are they necessary if the function is synchronous?

Copy link
Contributor

Choose a reason for hiding this comment

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

There will be no result object if the API is made synchronous.

@@ -70,6 +70,14 @@ abstract class CameraApi {
@async
String stopVideoRecording(int cameraId);

/// Starts the image stream for the given camera.
@async
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these @async? It looks like the logic is synchronous.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 29, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 29, 2024
flutter/packages@3d358d9...247fb5f

2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.activity:activity from 1.9.0 to 1.9.1 in /packages/image_picker/image_picker_android/android (flutter/packages#7245)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#7239)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/image_picker/image_picker_android/android (flutter/packages#6763)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [file_selector]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/file_selector/file_selector_android/android (flutter/packages#7240)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [url_launcher]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/url_launcher/url_launcher_android/android (flutter/packages#7243)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.12 to 3.25.15 (flutter/packages#7235)
2024-07-29 [email protected] Roll Flutter from 7d5c1c0 to 031dc3d (97 revisions) (flutter/packages#7225)
2024-07-26 [email protected] [camera_windows] Support image streams on Windows platform (flutter/packages#7067)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
flutter/packages@3d358d9...247fb5f

2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.activity:activity from 1.9.0 to 1.9.1 in /packages/image_picker/image_picker_android/android (flutter/packages#7245)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#7239)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/image_picker/image_picker_android/android (flutter/packages#6763)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [file_selector]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/file_selector/file_selector_android/android (flutter/packages#7240)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [url_launcher]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/url_launcher/url_launcher_android/android (flutter/packages#7243)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.12 to 3.25.15 (flutter/packages#7235)
2024-07-29 [email protected] Roll Flutter from 7d5c1c0 to 031dc3d (97 revisions) (flutter/packages#7225)
2024-07-26 [email protected] [camera_windows] Support image streams on Windows platform (flutter/packages#7067)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
flutter/packages@3d358d9...247fb5f

2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.activity:activity from 1.9.0 to 1.9.1 in /packages/image_picker/image_picker_android/android (flutter/packages#7245)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#7239)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [image_picker]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/image_picker/image_picker_android/android (flutter/packages#6763)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [file_selector]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/file_selector/file_selector_android/android (flutter/packages#7240)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com [url_launcher]: Bump androidx.annotation:annotation from 1.8.0 to 1.8.1 in /packages/url_launcher/url_launcher_android/android (flutter/packages#7243)
2024-07-29 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.12 to 3.25.15 (flutter/packages#7235)
2024-07-29 [email protected] Roll Flutter from 7d5c1c0 to 031dc3d (97 revisions) (flutter/packages#7225)
2024-07-26 [email protected] [camera_windows] Support image streams on Windows platform (flutter/packages#7067)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@yoongyo

This comment was marked as off-topic.

return nullptr;
},
[](auto arguments) {
event_sink.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to do a quick fix to the issues I raised in my previous comments, but then I noticed the code related to event_sink. This is a global, which is already very dangerous, but it's also std::moved between classes while still being referenced persistently in both. This code would likely fail the second time an image stream was started, and would absolutely fail with multiple engines.

Given the scope of issues here, I'm going to revert this. @cbracken FYI.

auto-submit bot pushed a commit that referenced this pull request Nov 4, 2024
…7951)

This reverts commit b31a279 (#7067)

The implementation had significant bugs:
- It had asynchronous results, but never responded to them, violating the engine API contract and preventing futures from completing.
- It `std::move`d pointers between classes, while still keeping them as ivars and global references and referring to them from long-lived handlers.
liff added a commit to CodemateLtd/packages that referenced this pull request Dec 5, 2024
The logic is synchronous, so there is no need to have the `@async`
annotation here.

Addresses:
  flutter#7067 (comment)
liff added a commit to CodemateLtd/packages that referenced this pull request Dec 5, 2024
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.

Addresses:
  flutter#7067 (comment)
liff added a commit to CodemateLtd/packages that referenced this pull request Dec 5, 2024
The logic is synchronous, so there is no need to have the `@async`
annotation here.

Addresses:
  flutter#7067 (comment)
liff added a commit to CodemateLtd/packages that referenced this pull request Dec 5, 2024
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.

Addresses:
  flutter#7067 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camera] Support image streams on Windows platform
7 participants