Skip to content

Commit

Permalink
[camerax] Wrap classes to implement resolution configuration for imag…
Browse files Browse the repository at this point in the history
…e capture, image analysis, and preview (flutter#4523)

Wraps classes to implement resolution configuration for image capture, image analysis, and preview. Also bumps CameraX version to latest and removes the deprecated classes used previously.

No functionality changes. Also thanks to @bparrishMines who did majority of the work here!

Part of flutter#120462
  • Loading branch information
camsim99 committed Jul 27, 2023
1 parent 867f2a4 commit 897f695
Show file tree
Hide file tree
Showing 40 changed files with 2,158 additions and 369 deletions.
6 changes: 6 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.0+12

* Wraps classes needed to implement resolution configuration for image capture, image analysis, and preview.
* Removes usages of deprecated APIs for resolution configuration.
* Bumps CameraX version to 1.3.0-beta01.

## 0.5.0+11

* Fixes issue with image data not being emitted after relistening to stream returned by `onStreamedFrameAvailable`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ android {

dependencies {
// CameraX core library using the camera2 implementation must use same version number.
def camerax_version = "1.3.0-alpha05"
def camerax_version = "1.3.0-beta01"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.core.resolutionselector.AspectRatioStrategy;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AspectRatioStrategyHostApi;

/**
* Host API implementation for {@link AspectRatioStrategy}.
*
* <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 AspectRatioStrategyHostApiImpl implements AspectRatioStrategyHostApi {
private final InstanceManager instanceManager;
private final AspectRatioStrategyProxy proxy;

/** Proxy for constructors and static method of {@link AspectRatioStrategy}. */
@VisibleForTesting
public static class AspectRatioStrategyProxy {
/** Creates an instance of {@link AspectRatioStrategy}. */
@NonNull
public AspectRatioStrategy create(
@NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
return new AspectRatioStrategy(preferredAspectRatio.intValue(), fallbackRule.intValue());
}
}

/**
* Constructs an {@link AspectRatioStrategyHostApiImpl}.
*
* @param instanceManager maintains instances stored to communicate with attached Dart objects
*/
public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) {
this(instanceManager, new AspectRatioStrategyProxy());
}

/**
* Constructs an {@link AspectRatioStrategyHostApiImpl}.
*
* @param instanceManager maintains instances stored to communicate with attached Dart objects
* @param proxy proxy for constructors and static method of {@link AspectRatioStrategy}
*/
@VisibleForTesting
AspectRatioStrategyHostApiImpl(
@NonNull InstanceManager instanceManager, @NonNull AspectRatioStrategyProxy proxy) {
this.instanceManager = instanceManager;
this.proxy = proxy;
}

/**
* Creates an {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback
* rule specified.
*/
@Override
public void create(
@NonNull Long identifier, @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
instanceManager.addDartCreatedInstance(
proxy.create(preferredAspectRatio, fallbackRule), identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public void setUp(
binaryMessenger, pendingRecordingHostApiImpl);
videoCaptureHostApiImpl = new VideoCaptureHostApiImpl(binaryMessenger, instanceManager);
GeneratedCameraXLibrary.VideoCaptureHostApi.setup(binaryMessenger, videoCaptureHostApiImpl);
GeneratedCameraXLibrary.ResolutionSelectorHostApi.setup(
binaryMessenger, new ResolutionSelectorHostApiImpl(instanceManager));
GeneratedCameraXLibrary.ResolutionStrategyHostApi.setup(
binaryMessenger, new ResolutionStrategyHostApiImpl(instanceManager));
GeneratedCameraXLibrary.AspectRatioStrategyHostApi.setup(
binaryMessenger, new AspectRatioStrategyHostApiImpl(instanceManager));
}

@Override
Expand Down
Loading

0 comments on commit 897f695

Please sign in to comment.