-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camerax] Wrap classes to implement resolution configuration for video capture #4620
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
50 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 b6f1c5f
start dev
camsim99 ebfccb7
Dev
camsim99 b21d1c2
wrap minus tests and cleanup
camsim99 10cb737
Add new files
camsim99 64d903e
Dart tests
camsim99 6b7c70e
Fix recorder test
camsim99 b975b1d
Modify java side
camsim99 89c76b5
Working on java tests
camsim99 cddc3cd
Fix java tests
camsim99 802218b
Remove unecessary verify
camsim99 52e49ee
Merge remote-tracking branch 'upstream/main' into camx_vidres1
camsim99 fb99807
Cleanup
camsim99 0d6f7b9
Bump version
camsim99 55eeb17
Fix lint and add test for recorder
camsim99 7f58a16
Merge branch 'main' into camx_vidres1
camsim99 949e20d
Merge remote-tracking branch 'upstream/main' into camx_vidres1
camsim99 8c77fab
Update packages/camera/camera_android_camerax/lib/src/fallback_strate…
camsim99 24e7ea5
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 b62c11d
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 acde675
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 957d4fa
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 8bbacb8
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 6f29185
Update packages/camera/camera_android_camerax/pigeons/camerax_library…
camsim99 9c5c436
Address review
camsim99 0ace4e2
Merge branch 'camx_vidres1' of github.com:camsim99/packages into camx…
camsim99 9887f33
Update packages/camera/camera_android_camerax/android/src/main/java/i…
camsim99 cd73662
Update packages/camera/camera_android_camerax/android/src/main/java/i…
camsim99 a42a5dc
Update packages/camera/camera_android_camerax/lib/src/fallback_strate…
camsim99 6db0529
Merge branch 'main' into camx_vidres1
camsim99 eb8ea0c
Fix format
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
Add new files
- Loading branch information
commit 10cb7379b72262047ad3be32810e8cc4f11ed28b
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...camerax/android/src/main/java/io/flutter/plugins/camerax/FallbackStrategyHostApiImpl.java
This file contains hidden or 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,114 @@ | ||
|
|
||
| // 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.annotation.VisibleForTesting; | ||
| import androidx.camera.video.FallbackStrategy; | ||
| import androidx.camera.video.Quality; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.FallbackStrategyHostApi; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.QualityConstraint; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.VideoResolutionFallbackRule; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Host API implementation for {@link FallbackStrategy}. | ||
| * | ||
| * <p>This class may handle 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 FallbackStrategyHostApiImpl implements FallbackStrategyHostApi { | ||
| private final InstanceManager instanceManager; | ||
|
|
||
| private final FallbackStrategyProxy proxy; | ||
|
|
||
| /** Proxy for constructors and static method of {@link FallbackStrategy}. */ | ||
| @VisibleForTesting | ||
| public static class FallbackStrategyProxy { | ||
| /** Creates an instance of {@link FallbackStrategy}. */ | ||
| public FallbackStrategy create( | ||
| @NonNull QualityConstraint qualityConstraint, | ||
| @NonNull VideoResolutionFallbackRule fallbackRule) { | ||
| // Determined proper CameraX Quality. | ||
| Quality quality = null; | ||
| switch (qualityConstraint) { | ||
| case SD: | ||
| quality = Quality.SD; | ||
| break; | ||
| case HD: | ||
| quality = Quality.HD; | ||
| break; | ||
| case FHD: | ||
| quality = Quality.FHD; | ||
| break; | ||
| case UHD: | ||
| quality = Quality.UHD; | ||
| break; | ||
| case LOWEST: | ||
| quality = Quality.LOWEST; | ||
| break; | ||
| case HIGHEST: | ||
| quality = Quality.HIGHEST; | ||
| break; | ||
| } | ||
|
|
||
| if (quality == null) { | ||
| throw new IllegalArgumentException("whoops"); | ||
| } | ||
|
|
||
| // Construct proper FallbackStrategy. | ||
| switch (fallbackRule) { | ||
| case HIGHER_QUALITY_OR_LOWER_THAN: | ||
| return FallbackStrategy.higherQualityOrLowerThan(quality); | ||
| case HIGHER_QUALITY_THAN: | ||
| return FallbackStrategy.higherQualityThan(quality); | ||
| case LOWER_QUALITY_OR_HIGHER_THAN: | ||
| return FallbackStrategy.lowerQualityOrHigherThan(quality); | ||
| case LOWER_QUALITY_THAN: | ||
| return FallbackStrategy.lowerQualityThan(quality); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("whoops"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@link FallbackStrategyHostApiImpl}. | ||
| * | ||
| * @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
| */ | ||
| public FallbackStrategyHostApiImpl(@NonNull InstanceManager instanceManager) { | ||
|
|
||
| this(instanceManager, new FallbackStrategyProxy()); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@link FallbackStrategyHostApiImpl}. | ||
| * | ||
| * @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
| * @param proxy proxy for constructors and static method of {@link FallbackStrategy} | ||
| */ | ||
| @VisibleForTesting | ||
| FallbackStrategyHostApiImpl( | ||
| @NonNull InstanceManager instanceManager, @NonNull FallbackStrategyProxy proxy) { | ||
| this.instanceManager = instanceManager; | ||
| this.proxy = proxy; | ||
| } | ||
|
|
||
| @Override | ||
| public void create( | ||
| @NonNull Long identifier, | ||
| @NonNull QualityConstraint qualityConstraint, | ||
| @NonNull VideoResolutionFallbackRule fallbackRule) { | ||
|
|
||
| instanceManager.addDartCreatedInstance( | ||
| proxy.create(qualityConstraint, fallbackRule), identifier); | ||
| } | ||
|
|
||
| private FallbackStrategy getFallbackStrategyInstance(@NonNull Long identifier) { | ||
| return Objects.requireNonNull(instanceManager.getInstance(identifier)); | ||
| } | ||
| } |
138 changes: 138 additions & 0 deletions
138
..._camerax/android/src/main/java/io/flutter/plugins/camerax/QualitySelectorHostApiImpl.java
This file contains hidden or 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,138 @@ | ||
|
|
||
| // 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.util.Size; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.annotation.VisibleForTesting; | ||
| import androidx.camera.video.FallbackStrategy; | ||
| import androidx.camera.video.Quality; | ||
| import androidx.camera.video.QualitySelector; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.QualityConstraint; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.QualitySelectorHostApi; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionInfo; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Host API implementation for {@link QualitySelector}. | ||
| * | ||
| * <p>This class may handle 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 QualitySelectorHostApiImpl implements QualitySelectorHostApi { | ||
| private final InstanceManager instanceManager; | ||
|
|
||
| private final QualitySelectorProxy proxy; | ||
|
|
||
| /** Proxy for constructors and static method of {@link QualitySelector}. */ | ||
| @VisibleForTesting | ||
| public static class QualitySelectorProxy { | ||
|
|
||
| /** Creates an instance of {@link QualitySelector}. */ | ||
| public QualitySelector create( | ||
| @NonNull List<Long> qualityIndexList, @Nullable FallbackStrategy fallbackStrategy) { | ||
| List<Quality> qualityList = new ArrayList<Quality>(); | ||
| for (Long qualityIndex : qualityIndexList) { | ||
| qualityList.add(getQualityConstant(qualityIndex)); | ||
| } | ||
|
|
||
| if (qualityList.size() == 1) { | ||
| Quality quality = qualityList.get(0); | ||
| if (fallbackStrategy == null) { | ||
| return QualitySelector.from(quality); | ||
| } | ||
| return QualitySelector.from(quality, fallbackStrategy); | ||
| } | ||
|
|
||
| if (fallbackStrategy == null) { | ||
| return QualitySelector.fromOrderedList(qualityList); | ||
| } | ||
| return QualitySelector.fromOrderedList(qualityList); | ||
| } | ||
|
|
||
| private Quality getQualityConstant(@NonNull Long qualityIndex) { | ||
| QualityConstraint quality = QualityConstraint.values()[qualityIndex.intValue()]; | ||
| return getCameraXQualityFromQuality(quality); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@link QualitySelectorHostApiImpl}. | ||
| * | ||
| * @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
| */ | ||
| public QualitySelectorHostApiImpl(@NonNull InstanceManager instanceManager) { | ||
|
|
||
| this(instanceManager, new QualitySelectorProxy()); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@link QualitySelectorHostApiImpl}. | ||
| * | ||
| * @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
| * @param proxy proxy for constructors and static method of {@link QualitySelector} | ||
| */ | ||
| @VisibleForTesting | ||
| QualitySelectorHostApiImpl( | ||
| @NonNull InstanceManager instanceManager, @NonNull QualitySelectorProxy proxy) { | ||
| this.instanceManager = instanceManager; | ||
| this.proxy = proxy; | ||
| } | ||
|
|
||
| @Override | ||
| public void create( | ||
| @NonNull Long identifier, | ||
| @NonNull List<Long> qualityList, | ||
| @Nullable Long fallbackStrategyIdentifier) { | ||
|
|
||
| instanceManager.addDartCreatedInstance( | ||
| proxy.create( | ||
| qualityList, | ||
| fallbackStrategyIdentifier == null | ||
| ? null | ||
| : Objects.requireNonNull(instanceManager.getInstance(fallbackStrategyIdentifier))), | ||
| identifier); | ||
| } | ||
|
|
||
| @Override | ||
| public ResolutionInfo getResolution( | ||
| @NonNull Long cameraInfoIdentifier, @NonNull QualityConstraint quality) { | ||
| final Size result = | ||
| QualitySelector.getResolution( | ||
| Objects.requireNonNull(instanceManager.getInstance(cameraInfoIdentifier)), | ||
| getCameraXQualityFromQuality(quality)); | ||
|
|
||
| return new ResolutionInfo.Builder() | ||
| .setWidth(Long.valueOf(result.getWidth())) | ||
| .setHeight(Long.valueOf(result.getHeight())) | ||
| .build(); | ||
| } | ||
|
|
||
| private QualitySelector getQualitySelectorInstance(@NonNull Long identifier) { | ||
| return Objects.requireNonNull(instanceManager.getInstance(identifier)); | ||
| } | ||
|
|
||
| public static Quality getCameraXQualityFromQuality(QualityConstraint quality) { | ||
| switch (quality) { | ||
| case SD: | ||
| return Quality.SD; | ||
| case HD: | ||
| return Quality.HD; | ||
| case FHD: | ||
| return Quality.FHD; | ||
| case UHD: | ||
| return Quality.UHD; | ||
| case LOWEST: | ||
| return Quality.LOWEST; | ||
| case HIGHEST: | ||
| return Quality.HIGHEST; | ||
| } | ||
| throw new IllegalArgumentException("whoops"); | ||
| } | ||
| } | ||
87 changes: 87 additions & 0 deletions
87
...ndroid_camerax/android/src/test/java/io/flutter/plugins/camerax/FallbackStrategyTest.java
This file contains hidden or 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,87 @@ | ||
|
|
||
| // 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. | ||
|
|
||
| // TODO(bparrishMines): Remove GenApiImpls from filename or copy classes/methods to your own implementation | ||
|
|
||
| package io.flutter.plugins.camerax; | ||
|
|
||
| // TODO(bparrishMines): Import native classes | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import io.flutter.plugin.common.BinaryMessenger; | ||
| import io.flutter.plugins.camerax.GeneratedCameraXLibrary.FallbackStrategyFlutterApi; | ||
| import java.util.Objects; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnit; | ||
| import org.mockito.junit.MockitoRule; | ||
|
|
||
| public class FallbackStrategyTest { | ||
|
|
||
| @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
|
||
| @Mock public FallbackStrategy mockFallbackStrategy; | ||
|
|
||
| @Mock public BinaryMessenger mockBinaryMessenger; | ||
|
|
||
| @Mock public FallbackStrategyFlutterApi mockFlutterApi; | ||
|
|
||
| @Mock public FallbackStrategyHostApiImpl.FallbackStrategyProxy mockProxy; | ||
|
|
||
| InstanceManager instanceManager; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| instanceManager = InstanceManager.open(identifier -> {}); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| instanceManager.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void hostApiCreate() { | ||
|
|
||
| final Quality quality = Quality.SOME_ENUM_VALUE; | ||
|
|
||
| final VideoResolutionFallbackRule fallbackRule = VideoResolutionFallbackRule.SOME_ENUM_VALUE; | ||
|
|
||
| when(mockProxy.create(quality, fallbackRule)).thenReturn(mockFallbackStrategy); | ||
|
|
||
| final FallbackStrategyHostApiImpl hostApi = | ||
| new FallbackStrategyHostApiImpl(mockBinaryMessenger, instanceManager, mockProxy); | ||
|
|
||
| final long instanceIdentifier = 0; | ||
| hostApi.create(instanceIdentifier, quality, fallbackRule); | ||
|
|
||
| assertEquals(instanceManager.getInstance(instanceIdentifier), mockFallbackStrategy); | ||
| } | ||
|
|
||
| @Test | ||
| public void flutterApiCreate() { | ||
| final FallbackStrategyFlutterApiImpl flutterApi = | ||
| new FallbackStrategyFlutterApiImpl(mockBinaryMessenger, instanceManager); | ||
| flutterApi.setApi(mockFlutterApi); | ||
|
|
||
| final Quality quality = Quality.SOME_ENUM_VALUE; | ||
|
|
||
| final VideoResolutionFallbackRule fallbackRule = VideoResolutionFallbackRule.SOME_ENUM_VALUE; | ||
|
|
||
| flutterApi.create(mockFallbackStrategy, quality, fallbackRule, reply -> {}); | ||
|
|
||
| final long instanceIdentifier = | ||
| Objects.requireNonNull( | ||
| instanceManager.getIdentifierForStrongReference(mockFallbackStrategy)); | ||
| verify(mockFlutterApi).create(eq(instanceIdentifier), eq(quality), eq(fallbackRule), any()); | ||
| } | ||
| } |
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.
extreme nit: I had to read this sentence a couple of times to understand it, maybe break it up? Also maybe remove "may"?
Also applies to other instances of this comment
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.
After further discussion, it seems like this comment is coming from the generator for the
...HostApiImpls, correct? Feel free to ignore if so.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.
Ah yes this is coming from the generator.