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_avfoundation] Adds support for discovering external camera devices on iOS 17 onwards. #5892

Closed
wants to merge 22 commits into from

Conversation

bibaswan-bhawal
Copy link

@bibaswan-bhawal bibaswan-bhawal commented Jan 14, 2024

This PR adds support for discovering external cameras in iOS devices with USB-C i.e. iPad.

This should address flutter/flutter#130073

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/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 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.

@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.

@bibaswan-bhawal
Copy link
Author

bibaswan-bhawal commented Jan 14, 2024

I was having trouble getting the changelog command working throwing

ProcessException: fatal: Not a valid object name upstream\main
  Command: git merge-base upstream\main HEAD

any insight would be helpful, then I can resolve some of the failing checks

@bibaswan-bhawal
Copy link
Author

The error thrown by XCode says that Use of undeclared identifier 'AVCaptureDeviceTypeExternal' but this is known to be a correct identifer tested on XCode 15 and the package builds and runs correctly when run using XCode 15.2

@stuartmorgan
Copy link
Contributor

I was having trouble getting the changelog command working throwing

ProcessException: fatal: Not a valid object name upstream\main
  Command: git merge-base upstream\main HEAD

any insight would be helpful, then I can resolve some of the failing checks

See https://github.com/flutter/packages/blob/main/script/tool/README.md#update-changelog-and-version, in particular the last paragraph. If you use a different repo setup than our docs recommend, then you need to modify commands that reference repositories and branches accordingly.

@stuartmorgan
Copy link
Contributor

but this is known to be a correct identifer tested on XCode 15

Our CI currently uses Xcode 14; updating is still an ongoing project.

@bibaswan-bhawal
Copy link
Author

I guess the PR is blocked until the CI is updated to xcode 15?

@stuartmorgan
Copy link
Contributor

Landing it is blocked on flutter/flutter#132237, but it can be reviewed in the meantime.

@hellohuanlin
Copy link
Contributor

@bibaswan-bhawal The change makes sense. Does external camera work after this change? (e.g. preview, taking picture/video, etc)

@bibaswan-bhawal
Copy link
Author

Yes they do

packages/camera/camera_avfoundation/CHANGELOG.md Outdated Show resolved Hide resolved
} else if (@available(iOS 13.0, *)) {
XCTAssertTrue([dictionaryResult count] == 4);
} else {
XCTAssertTrue([dictionaryResult count] == 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you verify the actual camera IDs in the result, rather than just the count?

Copy link
Contributor

Choose a reason for hiding this comment

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

i may be missing something. why was this resolved?

Copy link
Author

Choose a reason for hiding this comment

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

it is now verifying that the external camera is actually present in the list returned

Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm, it looks like it's still checking dictionaryResult's count only. can you point me to the code?

Copy link
Author

Choose a reason for hiding this comment

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

image

I think you may be looking at an older commit the latest one looks like the above

Copy link
Author

Choose a reason for hiding this comment

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

@hellohuanlin Just wanted to make sure my previous message wasn't lost in your inbox

Copy link
Contributor

Choose a reason for hiding this comment

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

instead of checking the [dictionaryResult count] == 3, can you manually check the actual items?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the last outstanding comment before this can be merged?

Copy link
Author

Choose a reason for hiding this comment

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

Yes I will work on it today and update the test

@hellohuanlin
Copy link
Contributor

@stuartmorgan does your comment from the other PR (#5957 (comment)) also apply to this PR?

@stuartmorgan
Copy link
Contributor

@stuartmorgan does your comment from the other PR (#5957 (comment)) also apply to this PR?

In theory yes; I realized after writing that though that this specific case is probably not something we need to block on. camera_windows already has this problem, and in some cases Android as well (we don't discover external cameras, but on some Android devices apparently external cameras that are plugged in when the device boots are reported as non-external, and thus are discovered). So on some platforms we already have the problem that if someone removes a camera while using a Flutter app, the app probably doesn't have a good way to gracefully handle that. And it's a pretty niche case; I think most people are probably not going to remove cameras they are actively using most of the time.

So I'll file an issue about the need to add API to get notifications about camera availability changes, but I'm okay not blocking this specific change on that.

@stuartmorgan
Copy link
Contributor

So I'll file an issue about the need to add API to get notifications about camera availability changes

flutter/flutter#142239

@bibaswan-bhawal
Copy link
Author

Fixed all broken tests

@stuartmorgan
Copy link
Contributor

@bibaswan-bhawal Is this ready for re-review?

@vashworth vashworth marked this pull request as draft April 3, 2024 21:03
@vashworth
Copy link
Contributor

@bibaswan-bhawal Please mark as ready for review when you'd like it to be re-reviewed.

@stuartmorgan
Copy link
Contributor

Since this is marked as a draft and hasn't been updated in several months I'm going to close it to clean out our review queue. Please don't hesitate to submit a new PR if you decide to revisit this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants