-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[camerax] Implements torch mode #4903
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
dec3d69
Merge remote-tracking branch 'upstream/main' into camx_occ
camsim99 0e0333b
Merge remote-tracking branch 'upstream/main'
camsim99 bd7ac99
Merge remote-tracking branch 'upstream/main'
camsim99 5c3363b
Merge remote-tracking branch 'upstream/main'
camsim99 fed9621
Undo changes
camsim99 5aabe34
Merge remote-tracking branch 'upstream/main'
camsim99 2b9a352
Merge remote-tracking branch 'upstream/main'
camsim99 a1173da
Merge remote-tracking branch 'upstream/main'
camsim99 cbc3d6b
Merge remote-tracking branch 'upstream/main'
camsim99 cae5a4c
Merge remote-tracking branch 'upstream/main'
camsim99 72283db
Merge remote-tracking branch 'upstream/main'
camsim99 166a77c
Merge remote-tracking branch 'upstream/main'
camsim99 399780e
Merge remote-tracking branch 'upstream/main'
camsim99 8d5d0e7
Merge remote-tracking branch 'upstream/main'
camsim99 084d960
Merge remote-tracking branch 'upstream/main'
camsim99 d2a59ac
Merge remote-tracking branch 'upstream/main'
camsim99 a1422bf
Merge remote-tracking branch 'upstream/main'
camsim99 bdd87a6
Merge remote-tracking branch 'upstream/main'
camsim99 137a28b
Merge remote-tracking branch 'upstream/main'
camsim99 bc0db5a
Merge remote-tracking branch 'upstream/main'
camsim99 d04b466
Merge remote-tracking branch 'upstream/main'
camsim99 a9cfe87
Merge remote-tracking branch 'upstream/main'
camsim99 a32def1
Merge remote-tracking branch 'upstream/main'
camsim99 4785148
Merge remote-tracking branch 'upstream/main'
camsim99 7a8fc69
Merge remote-tracking branch 'upstream/main'
camsim99 b02e15f
Merge remote-tracking branch 'upstream/main'
camsim99 c6e5868
Merge remote-tracking branch 'upstream/main'
camsim99 0c0065a
Merge remote-tracking branch 'upstream/main'
camsim99 9dfe259
Merge remote-tracking branch 'upstream/main'
camsim99 bfcc0df
Merge remote-tracking branch 'upstream/main'
camsim99 b80cc86
Merge remote-tracking branch 'upstream/main'
camsim99 915332e
Start impl
camsim99 22ea65f
More impl
camsim99 ad46f47
More impl
camsim99 6396ec5
More impl
camsim99 cd0dc35
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 9c9922b
Add dart tests
camsim99 0f64164
Add back example code
camsim99 dc5f95b
Add tests, update docs
camsim99 743c853
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 85e3da7
Fix analysis errors
camsim99 476d4de
Remove redundant context setting
camsim99 b385f1a
Fix img analysis test
camsim99 fb7986d
Nit
camsim99 87a4438
Modify torch tests
camsim99 12ce00c
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 a6f0968
Fix java tests
camsim99 cef5f31
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 81e6cbc
Delete unused proxy
camsim99 2534eae
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 bb0e9d7
Merge remote-tracking branch 'upstream/main' into camx_torch
camsim99 93317eb
Address review
camsim99 54a69ea
Add documentation
camsim99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.5.0+19 | ||
|
||
* Implements torch flash mode. | ||
|
||
## 0.5.0+18 | ||
|
||
* Implements `startVideoCapturing`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlFlutterApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camerax; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.camera.core.CameraControl; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraControlFlutterApi; | ||
|
||
public class CameraControlFlutterApiImpl extends CameraControlFlutterApi { | ||
private final @NonNull InstanceManager instanceManager; | ||
|
||
public CameraControlFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { | ||
super(binaryMessenger); | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
/** | ||
* Creates a {@link CameraControl} instance in Dart. {@code reply} is not used so it can be empty. | ||
*/ | ||
void create(CameraControl cameraControl, Reply<Void> reply) { | ||
if (!instanceManager.containsInstance(cameraControl)) { | ||
create(instanceManager.addHostCreatedInstance(cameraControl), reply); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...id_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlHostApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camerax; | ||
|
||
import android.content.Context; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.VisibleForTesting; | ||
import androidx.camera.core.CameraControl; | ||
import androidx.core.content.ContextCompat; | ||
import com.google.common.util.concurrent.FutureCallback; | ||
import com.google.common.util.concurrent.Futures; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraControlHostApi; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Host API implementation for {@link CameraControl}. | ||
* | ||
* <p>This class handles instantiating and adding native object instances that are attached to a | ||
* Dart instance or handle method calls on the associated native class or an instance of the class. | ||
*/ | ||
public class CameraControlHostApiImpl implements CameraControlHostApi { | ||
private final InstanceManager instanceManager; | ||
private final CameraControlProxy proxy; | ||
|
||
/** Proxy for constructors and static method of {@link CameraControl}. */ | ||
@VisibleForTesting | ||
public static class CameraControlProxy { | ||
Context context; | ||
|
||
/** Enables or disables the torch of the specified {@link CameraControl} instance. */ | ||
@NonNull | ||
public void enableTorch( | ||
@NonNull CameraControl cameraControl, | ||
@NonNull Boolean torch, | ||
@NonNull GeneratedCameraXLibrary.Result<Void> result) { | ||
ListenableFuture<Void> enableTorchFuture = cameraControl.enableTorch(torch); | ||
|
||
Futures.addCallback( | ||
enableTorchFuture, | ||
new FutureCallback<Void>() { | ||
public void onSuccess(Void voidResult) { | ||
result.success(null); | ||
} | ||
|
||
public void onFailure(Throwable t) { | ||
result.error(t); | ||
} | ||
}, | ||
ContextCompat.getMainExecutor(context)); | ||
} | ||
} | ||
|
||
/** | ||
* Constructs an {@link CameraControlHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public CameraControlHostApiImpl( | ||
@NonNull InstanceManager instanceManager, @NonNull Context context) { | ||
this(instanceManager, new CameraControlProxy(), context); | ||
} | ||
|
||
/** | ||
* Constructs an {@link CameraControlHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
* @param proxy proxy for constructors and static method of {@link CameraControl} | ||
* @param context {@link Context} used to retrieve {@code Executor} used to enable torch mode | ||
*/ | ||
@VisibleForTesting | ||
CameraControlHostApiImpl( | ||
@NonNull InstanceManager instanceManager, | ||
@NonNull CameraControlProxy proxy, | ||
@NonNull Context context) { | ||
this.instanceManager = instanceManager; | ||
this.proxy = proxy; | ||
proxy.context = context; | ||
} | ||
|
||
/** | ||
* Sets the context that the {@code ProcessCameraProvider} will use to enable/disable torch mode. | ||
* | ||
* <p>If using the camera plugin in an add-to-app context, ensure that a new instance of the | ||
* {@code CameraControl} is fetched via {@code #enableTorch} anytime the context changes. | ||
*/ | ||
public void setContext(@NonNull Context context) { | ||
this.proxy.context = context; | ||
} | ||
|
||
@Override | ||
public void enableTorch( | ||
@NonNull Long identifier, | ||
@NonNull Boolean torch, | ||
@NonNull GeneratedCameraXLibrary.Result<Void> result) { | ||
proxy.enableTorch( | ||
Objects.requireNonNull(instanceManager.getInstance(identifier)), torch, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This PR also makes a fix to this implementation by adding a
Context
to theImageAnalysisHostApiImpl
constructor to remove an unnecessary call to update the context for the Host API implementations after running this method also setting theContext
for those implementations (see line 131).