-
Notifications
You must be signed in to change notification settings - Fork 3k
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] Set device media type for video preview explicitly #7447
[camera_windows] Set device media type for video preview explicitly #7447
Conversation
0cf1e06
to
6dd71c9
Compare
Thanks for the contribution! This will need a test, per the PR checklist, before it can be reviewed. |
Since the bug arose due to a missing function call to Microsoft's Media Foundation API, the only test I can reasonably add is to verify the function is now called. |
From triage: @cbracken it looks like this should be ready for review. |
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.
@@ -1,6 +1,7 @@ | |||
## NEXT | |||
## 0.2.6 |
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.
For versions <1, Dart convention is to use the build number for bugfixes, so this should be 0.2.5+1
.
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.
I have fixed the versioning in 4ffbedd
|
||
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3. | ||
* Fix black bars on camera preview [#122966](https://github.com/flutter/flutter/issues/122966) |
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.
"Fixes". Also, this is missing a period. Please see the CHANGELOG style guide linked from the PR checklist.
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.
The changelog should now be following the style guide as of 4ffbedd
@@ -479,6 +479,13 @@ HRESULT CaptureControllerImpl::FindBaseMediaTypes() { | |||
return E_FAIL; | |||
} | |||
|
|||
hr = source->SetCurrentDeviceMediaType( |
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.
It seems extremely surprising to have a method called FindBaseMediaTypes()
have the side-effect of setting a media type. Why is this method the place where this is called?
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.
SetCurrentDeviceMediaType
is a class function of IMFCaptureSource
which was conveniently already accessible in the function scope FindBaseMediaType
. For the bug fix, the function only needs to be called after base_preview_media_type_
is set, which is when FindBestMediaType
is called with it.
We can alternatively move it inside the function CaptureControllerImpl::StartPreview
after base_preview_media_type_
is set, but then we would need to prepare a IMFCaptureSource
object for this scope.
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.
For the bug fix, the function only needs to be called after
base_preview_media_type_
is set, which is whenFindBestMediaType
is called with it.
My primary concern is the maintainability of this code in the long term, rather than minimizing the diff. Having a method indicate that it gets a value have a side effect of changing a value is the kind of thing that makes maintaining code correctly a lot harder over the longer term.
We can alternatively move it inside the function
CaptureControllerImpl::StartPreview
That sounds like a much clearer location for setting values related to displaying the preview.
0b73a32
to
4ffbedd
Compare
@dasyad00 Are you still planning on updating this to address the remaining feedback? |
@stuartmorgan Sorry, I was occupied with other things lately. I have just pushed the refactor commit. |
1ecdcf7
to
cdf4f5c
Compare
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.
Thanks, the refactoring makes for a much clearer flow! Just minor comments.
@@ -180,6 +180,7 @@ class CaptureControllerImpl : public CaptureController, | |||
// Enumerates video_sources media types and finds out best resolution | |||
// for preview and video capture. | |||
HRESULT FindBaseMediaTypes(); | |||
HRESULT FindBaseMediaTypes(IMFCaptureSource* source); |
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.
Please give these different names, and their own declaration comments explaining what they do. Function overloading should only be used when the methods do exactly the same thing, just with different input types.
The new method could be called FindBaseMediaTypesForSource
.
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.
hr = capture_engine_->GetSource(&source); | ||
if (FAILED(hr)) { | ||
return OnPreviewStarted(GetCameraResult(hr), | ||
"Failed to initialize video preview"); |
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.
Please don't use the same error message for three different failures; we want to be able to distinguish what failed. Each case in the method should describe what specifically failed.
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.
79610aa
to
923fc4d
Compare
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, thanks!
auto label is removed for flutter/packages/7447, due to - The status or check suite Mac_x64 ios_build_all_packages stable has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/packages@72356fd...26e123a 2024-11-13 [email protected] [camera_windows] Set device media type for video preview explicitly (flutter/packages#7447) 2024-11-13 [email protected] [go_router] Add support for relative routes (flutter/packages#6825) 2024-11-13 [email protected] [vector_graphics_compiler] fix a renamed method parameter lint (flutter/packages#8070) 2024-11-12 [email protected] [in_app_purchase] Add expiration date to Transaction (flutter/packages#8030) 2024-11-12 [email protected] [various] Clean up contributing guides (flutter/packages#8032) 2024-11-12 [email protected] [ci] Remove web renderer option from tools. (flutter/packages#8055) 2024-11-12 [email protected] [url_launcher] Update Pigeon version for Linux (flutter/packages#8065) 2024-11-12 [email protected] [go_router] Add support for preloading branches of StatefulShellRoute (revised solution) (flutter/packages#6467) 2024-11-12 [email protected] [pigeon] Make Linux type declarations public (flutter/packages#8040) 2024-11-11 [email protected] Roll Flutter from 73546b3 to c8510f2 (30 revisions) (flutter/packages#8042) 2024-11-11 [email protected] Use dependabot multi-directory configuration for Android package updates (flutter/packages#8048) 2024-11-11 [email protected] [tools] Run `pub get` before `format` (flutter/packages#8052) 2024-11-11 [email protected] [file_selector] Fix Linux cancel regression (flutter/packages#8051) 2024-11-09 [email protected] [shared_preferences] Fix confusing language in README (flutter/packages#8049) 2024-11-08 [email protected] Use dependabot multi-directory configuration for Android example gradle updates (flutter/packages#8036) 2024-11-08 [email protected] [animations] Remove `.flutter-plugins` reference from example app (flutter/packages#8002) 2024-11-08 [email protected] Group dependabot github-action update PRs, delete dead docker updates (flutter/packages#8044) 2024-11-08 [email protected] [vector_graphics_compiler] fix-null-exception (flutter/packages#8006) 2024-11-08 [email protected] [tools] Format Dart per-package (flutter/packages#8043) 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] 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
Fixes preview aspect ratio on Windows on some webcams (See flutter/flutter#122966).
Before (main branch 7c1a05c):
After:
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.