-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camerax] Implement onCameraClosing #3878
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
Changes from 1 commit
6125eca
5be1371
b2fce3d
ed62a9a
2e3027b
fbd3fe5
dfa477e
a651b92
884fd6c
d5f8b91
060b7e5
ff50c70
fe6f1fc
e2643ae
b7194f7
dadc230
d15e1d4
6dc2b77
f826b62
0f7f29a
1e9739b
9ba20d0
5bf6b17
5e58b2c
4c8c94d
6a0de08
d3ed3e7
d1c684f
c04d8c1
b2322d2
3545aec
e1f5bdb
2d3409b
1f40f47
6c9b04e
6c6cbb4
a0ea3c5
06c1545
681a117
1143a03
d431511
ab3c085
631f972
70c817a
426b438
2bc4877
0fcf7c6
6c49bd9
b9daeb1
3345878
9f6646f
265eb1e
bfc4b5e
4f3c342
e3c7a5b
f341f7f
0d4b021
ca3bd9e
540ee98
debcd3a
a79ee62
438f592
c44fc06
83aea10
5f435e8
581af94
dec3d69
02c039f
ce463ba
c525162
86304c3
b826c18
2cebb18
04976ec
bca72ee
2da0b8f
ea78ab0
d0b160f
bc7ebee
9014d3b
f3d6a06
34cab98
6f701a5
a636525
d5a21cb
bc4ebc1
491ab2c
bff96a9
ad40999
a3667dd
c3732fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,8 +451,9 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| /// Binds [preview] instance to the camera lifecycle controlled by the | ||
| /// [processCameraProvider]. | ||
| /// | ||
| /// [cameraId] used to properly update the live camera state for the camera | ||
| /// in used. | ||
| /// [cameraId] used to build [CameraEvent]s should you wish to filter | ||
| /// these based on a reference to a cameraId received from calling | ||
| /// `createCamera(...)`. | ||
| Future<void> _bindPreviewToLifecycle(int cameraId) async { | ||
| final bool previewIsBound = await processCameraProvider!.isBound(preview!); | ||
| if (previewIsBound || _previewIsPaused) { | ||
|
|
@@ -590,6 +591,9 @@ class AndroidCameraCameraX extends CameraPlatform { | |
|
|
||
| // Callback method used to implement the behavior described above: | ||
| void onChanged(Object stateAsObject) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use a weak reference to the AndroidCameraCameraX instance. Something like: final WeakReference<AndroidCameraCameraX> weakThis = WeakReference<AndroidCameraCameraX>(this);The reason being that callback methods in the Native Wrapper API can cause leaking if they end up referencing themselves. Which there is a good chance to happen if you reference the complex class I forgot to mention in the image streaming PR, so the code for that may need to be updated as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this callback and the image streaming callback!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is important to use a weak reference to make sure something does not leak then we should add a test that covers that behavior.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, test that a weak reference is used in these callbacks and/or that using a weak reference avoids any leaking?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Garbage collection for Dart is non-deterministic, so testing for it is a little difficult. I do have a test for leaking in the I don't think the implementation of the test should block this PR though. Leaks only prevent the release of the strong reference to the object in the Java I can also help with writing the test.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to flutter/flutter#125928 |
||
| // This cast is safe because the Observer implemntation ensures | ||
camsim99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // the type of stateAsObject is the same as the observer this callback | ||
| // is attached to. | ||
| final CameraState state = stateAsObject as CameraState; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have fallback behavior if stateAsObject is not a CameraState?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is handled in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a comment to that effect since one class is relying on the known implementation of another class and not on its api surface. |
||
| if (state.type == CameraStateType.closing) { | ||
| weakThis.target!.cameraEventStreamController | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.