Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
44d7828
Add resolution configuration
camsim99 Apr 22, 2023
6281eb5
dart side of impl
bparrishMines Apr 26, 2023
9a74cd1
java impls
bparrishMines Apr 26, 2023
03ef376
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 May 15, 2023
2a5c0fc
Fix implementation
camsim99 May 15, 2023
9001ab0
Small cleanup
camsim99 May 15, 2023
fd19de6
Fixing tests and cleanup minus plugin dart impl test
camsim99 May 17, 2023
c9b62ef
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Jul 18, 2023
725be10
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Jul 18, 2023
6389ae1
Work on Dart side -- tests, cleanup, bug id
camsim99 Jul 18, 2023
16770de
Fix java unit tests
camsim99 Jul 18, 2023
a8144fa
Fix typo
camsim99 Jul 18, 2023
aba4c34
Fix dart tests
camsim99 Jul 19, 2023
ca5604a
Add integration tests
camsim99 Jul 20, 2023
474745c
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Aug 16, 2023
b778894
Add res support
camsim99 Aug 16, 2023
8d2cb3a
correct overrides
camsim99 Aug 16, 2023
a145afe
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Aug 16, 2023
fd3ade2
Self review
camsim99 Aug 16, 2023
1dc6fbd
formatting
camsim99 Aug 16, 2023
fad7cbc
Undo strange change
camsim99 Aug 16, 2023
08edc4c
Fix dart unit tests
camsim99 Aug 16, 2023
1def519
Fix integration test
camsim99 Aug 17, 2023
5bab620
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Aug 17, 2023
caf819e
Nits
camsim99 Aug 17, 2023
c775756
Update readme
camsim99 Aug 17, 2023
fabaab7
Update packages/camera/camera_android_camerax/lib/src/android_camera_…
camsim99 Aug 22, 2023
810cb54
Update packages/camera/camera_android_camerax/lib/src/android_camera_…
camsim99 Aug 22, 2023
60a47ed
Update packages/camera/camera_android_camerax/lib/src/android_camera_…
camsim99 Aug 22, 2023
474d84c
Update packages/camera/camera_android_camerax/lib/src/android_camera_…
camsim99 Aug 22, 2023
6f45ecb
Add comments to integration tests
camsim99 Aug 22, 2023
5c31de4
Merge branch 'camx_resconfig' of github.com:camsim99/packages into ca…
camsim99 Aug 22, 2023
e4134bd
Updated integration test comment
camsim99 Aug 23, 2023
bb35a61
start quality re-write
camsim99 Aug 29, 2023
5ac1c7c
Replace vid qual const with quality/qualitydata
camsim99 Aug 29, 2023
860b4db
Replace Quality indices with VideoQuality/VideoQualityData class
camsim99 Aug 29, 2023
5ea328e
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Aug 29, 2023
a163f0e
Fix versionining
camsim99 Aug 29, 2023
2a9671e
Format
camsim99 Aug 29, 2023
0178493
run tests
camsim99 Aug 29, 2023
ff9bd3a
nits
camsim99 Sep 7, 2023
396091c
Merge remote-tracking branch 'upstream/main' into camx_resconfig
camsim99 Sep 7, 2023
206fbb6
Fix changelog
camsim99 Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix implementation
  • Loading branch information
camsim99 committed May 15, 2023
commit 2a5c0fc48dac9d8a6ecd53c343338dd657b5b5c4
4 changes: 4 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0+3

* Implements resolution configuration for live camera preview, image capture, and image analysis use cases.

## 0.5.0+2

* Adds a dependency on kotlin-bom to align versions of Kotlin transitive dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void setUp(
binaryMessenger, pendingRecordingHostApiImpl);
videoCaptureHostApiImpl = new VideoCaptureHostApiImpl(binaryMessenger, instanceManager);
GeneratedCameraXLibrary.VideoCaptureHostApi.setup(binaryMessenger, videoCaptureHostApiImpl);
GeneratedCameraXLibrary.ResolutionSelectorHostApi.setup(binaryMessenger, new ResolutionSelectorHostApiImpl(binaryMessenger, instanceManager));
GeneratedCameraXLibrary.ResolutionStrategyHostApi.setup(binaryMessenger, new ResolutionStrategyHostApiImpl(binaryMessenger, instanceManager));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,79 +254,6 @@ ArrayList<Object> toList() {
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class CameraSize {
private @NonNull Long width;

public @NonNull Long getWidth() {
return width;
}

public void setWidth(@NonNull Long setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"width\" is null.");
}
this.width = setterArg;
}

private @NonNull Long height;

public @NonNull Long getHeight() {
return height;
}

public void setHeight(@NonNull Long setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"height\" is null.");
}
this.height = setterArg;
}

/** Constructor is non-public to enforce null safety; use Builder. */
CameraSize() {}

public static final class Builder {

private @Nullable Long width;

public @NonNull Builder setWidth(@NonNull Long setterArg) {
this.width = setterArg;
return this;
}

private @Nullable Long height;

public @NonNull Builder setHeight(@NonNull Long setterArg) {
this.height = setterArg;
return this;
}

public @NonNull CameraSize build() {
CameraSize pigeonReturn = new CameraSize();
pigeonReturn.setWidth(width);
pigeonReturn.setHeight(height);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(2);
toListResult.add(width);
toListResult.add(height);
return toListResult;
}

static @NonNull CameraSize fromList(@NonNull ArrayList<Object> list) {
CameraSize pigeonResult = new CameraSize();
Object width = list.get(0);
pigeonResult.setWidth((width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width));
Object height = list.get(1);
pigeonResult.setHeight((height == null) ? null : ((height instanceof Integer) ? (Integer) height : (Long) height));
return pigeonResult;
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class CameraStateTypeData {
private @NonNull CameraStateType value;
Expand Down Expand Up @@ -1303,8 +1230,6 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return ResolutionInfo.fromList((ArrayList<Object>) readValue(buffer));
case (byte) 129:
return ResolutionInfo.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
}
Expand All @@ -1315,9 +1240,6 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof ResolutionInfo) {
stream.write(128);
writeValue(stream, ((ResolutionInfo) value).toList());
} else if (value instanceof ResolutionInfo) {
stream.write(129);
writeValue(stream, ((ResolutionInfo) value).toList());
} else {
super.writeValue(stream, value);
}
Expand All @@ -1327,7 +1249,7 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface PreviewHostApi {

void create(@NonNull Long identifier, @Nullable Long rotation, @Nullable ResolutionInfo targetResolution);
void create(@NonNull Long identifier, @Nullable Long rotation, @Nullable Long resolutionSelectorId);

@NonNull
Long setSurfaceProvider(@NonNull Long identifier);
Expand All @@ -1354,9 +1276,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
Number rotationArg = (Number) args.get(1);
ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2);
Number resolutionSelectorIdArg = (Number) args.get(2);
try {
api.create((identifierArg == null) ? null : identifierArg.longValue(), (rotationArg == null) ? null : rotationArg.longValue(), targetResolutionArg);
api.create((identifierArg == null) ? null : identifierArg.longValue(), (rotationArg == null) ? null : rotationArg.longValue(), (resolutionSelectorIdArg == null) ? null : resolutionSelectorIdArg.longValue());
wrapped.add(0, null);
}
catch (Throwable exception) {
Expand Down Expand Up @@ -1884,45 +1806,18 @@ public void create(@NonNull Long identifierArg, @NonNull Reply<Void> callback) {
channelReply -> callback.reply(null));
}
}

private static class ImageCaptureHostApiCodec extends StandardMessageCodec {
public static final ImageCaptureHostApiCodec INSTANCE = new ImageCaptureHostApiCodec();

private ImageCaptureHostApiCodec() {}

@Override
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return ResolutionInfo.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
}
}

@Override
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof ResolutionInfo) {
stream.write(128);
writeValue(stream, ((ResolutionInfo) value).toList());
} else {
super.writeValue(stream, value);
}
}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface ImageCaptureHostApi {

void create(@NonNull Long identifier, @Nullable Long flashMode, @Nullable ResolutionInfo targetResolution);
void create(@NonNull Long identifier, @Nullable Long flashMode, @Nullable Long resolutionSelectorId);

void setFlashMode(@NonNull Long identifier, @NonNull Long flashMode);

void takePicture(@NonNull Long identifier, @NonNull Result<String> result);

/** The codec used by ImageCaptureHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
return ImageCaptureHostApiCodec.INSTANCE;
return new StandardMessageCodec();
}
/**Sets up an instance of `ImageCaptureHostApi` to handle messages through the `binaryMessenger`. */
static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptureHostApi api) {
Expand All @@ -1937,9 +1832,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
Number flashModeArg = (Number) args.get(1);
ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2);
Number resolutionSelectorIdArg = (Number) args.get(2);
try {
api.create((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue(), targetResolutionArg);
api.create((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue(), (resolutionSelectorIdArg == null) ? null : resolutionSelectorIdArg.longValue());
wrapped.add(0, null);
}
catch (Throwable exception) {
Expand Down Expand Up @@ -2018,17 +1913,17 @@ private ResolutionStrategyHostApiCodec() {}
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return CameraSize.fromList((ArrayList<Object>) readValue(buffer));
return ResolutionInfo.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
}
}

@Override
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof CameraSize) {
if (value instanceof ResolutionInfo) {
stream.write(128);
writeValue(stream, ((CameraSize) value).toList());
writeValue(stream, ((ResolutionInfo) value).toList());
} else {
super.writeValue(stream, value);
}
Expand All @@ -2046,7 +1941,7 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
*/
public interface ResolutionStrategyHostApi {
/** Create a new native instance and add it to the `InstanceManager`. */
void create(@NonNull Long identifier, @NonNull CameraSize boundSize, @NonNull Long fallbackRule);
void create(@NonNull Long identifier, @Nullable ResolutionInfo boundSize, @Nullable Long fallbackRule);

/** The codec used by ResolutionStrategyHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
Expand All @@ -2064,7 +1959,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable Resolution
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
CameraSize boundSizeArg = (CameraSize) args.get(1);
ResolutionInfo boundSizeArg = (ResolutionInfo) args.get(1);
Number fallbackRuleArg = (Number) args.get(2);
try {
api.create((identifierArg == null) ? null : identifierArg.longValue(), boundSizeArg, (fallbackRuleArg == null) ? null : fallbackRuleArg.longValue());
Expand Down Expand Up @@ -2308,45 +2203,18 @@ public void create(@NonNull Long identifierArg, @NonNull Double minZoomRatioArg,
channelReply -> callback.reply(null));
}
}

private static class ImageAnalysisHostApiCodec extends StandardMessageCodec {
public static final ImageAnalysisHostApiCodec INSTANCE = new ImageAnalysisHostApiCodec();

private ImageAnalysisHostApiCodec() {}

@Override
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return ResolutionInfo.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
}
}

@Override
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof ResolutionInfo) {
stream.write(128);
writeValue(stream, ((ResolutionInfo) value).toList());
} else {
super.writeValue(stream, value);
}
}
}

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface ImageAnalysisHostApi {

void create(@NonNull Long identifier, @Nullable ResolutionInfo targetResolutionIdentifier);
void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId);

void setAnalyzer(@NonNull Long identifier, @NonNull Long analyzerIdentifier);

void clearAnalyzer(@NonNull Long identifier);

/** The codec used by ImageAnalysisHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
return ImageAnalysisHostApiCodec.INSTANCE;
return new StandardMessageCodec();
}
/**Sets up an instance of `ImageAnalysisHostApi` to handle messages through the `binaryMessenger`. */
static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnalysisHostApi api) {
Expand All @@ -2360,9 +2228,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnaly
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
ResolutionInfo targetResolutionIdentifierArg = (ResolutionInfo) args.get(1);
Number resolutionSelectorIdArg = (Number) args.get(1);
try {
api.create((identifierArg == null) ? null : identifierArg.longValue(), targetResolutionIdentifierArg);
api.create((identifierArg == null) ? null : identifierArg.longValue(), (resolutionSelectorIdArg == null) ? null : resolutionSelectorIdArg.longValue());
wrapped.add(0, null);
}
catch (Throwable exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.resolutionselector.ResolutionSelector;
import androidx.core.content.ContextCompat;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ImageAnalysisHostApi;
Expand Down Expand Up @@ -38,11 +39,11 @@ public void setContext(@NonNull Context context) {

/** Creates an {@link ImageAnalysis} instance with the target resolution if specified. */
@Override
public void create(@NonNull Long identifier, @Nullable ResolutionInfo targetResolution) {
public void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId) {
ImageAnalysis.Builder imageAnalysisBuilder = cameraXProxy.createImageAnalysisBuilder();

if (targetResolution != null) {
imageAnalysisBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution));
ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId);
if (resolutionSelector != null) {
imageAnalysisBuilder.setResolutionSelector(resolutionSelector);
}

ImageAnalysis imageAnalysis = imageAnalysisBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageCaptureException;
import androidx.camera.core.resolutionselector.ResolutionSelector;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ImageCaptureHostApi;
import java.io.File;
Expand Down Expand Up @@ -54,14 +55,15 @@ public void setContext(Context context) {
public void create(
@NonNull Long identifier,
@Nullable Long flashMode,
@Nullable GeneratedCameraXLibrary.ResolutionInfo targetResolution) {
@Nullable Long resolutionSelectorId) {
ImageCapture.Builder imageCaptureBuilder = cameraXProxy.createImageCaptureBuilder();
ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId);
if (flashMode != null) {
// This sets the requested flash mode, but may fail silently.
imageCaptureBuilder.setFlashMode(flashMode.intValue());
}
if (targetResolution != null) {
imageCaptureBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution));
if (resolutionSelector != null) {
imageCaptureBuilder.setResolutionSelector(resolutionSelector);
}
ImageCapture imageCapture = imageCaptureBuilder.build();
instanceManager.addDartCreatedInstance(imageCapture, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.camera.core.Preview;
import androidx.camera.core.SurfaceRequest;
import androidx.camera.core.resolutionselector.ResolutionSelector;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.PreviewHostApi;
import io.flutter.view.TextureRegistry;
Expand Down Expand Up @@ -40,13 +41,14 @@ public PreviewHostApiImpl(
public void create(
@NonNull Long identifier,
@Nullable Long rotation,
@Nullable GeneratedCameraXLibrary.ResolutionInfo targetResolution) {
@Nullable Long resolutionSelectorId) {
Preview.Builder previewBuilder = cameraXProxy.createPreviewBuilder();
ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId);
if (rotation != null) {
previewBuilder.setTargetRotation(rotation.intValue());
}
if (targetResolution != null) {
previewBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution));
if (resolutionSelector != null) {
previewBuilder.setResolutionSelector(resolutionSelector);
}
Preview preview = previewBuilder.build();
instanceManager.addDartCreatedInstance(preview, identifier);
Expand Down
Loading