Skip to content

[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 50 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 May 1, 2023
0e0333b
Merge remote-tracking branch 'upstream/main'
camsim99 May 2, 2023
bd7ac99
Merge remote-tracking branch 'upstream/main'
camsim99 May 3, 2023
5c3363b
Merge remote-tracking branch 'upstream/main'
camsim99 May 10, 2023
fed9621
Undo changes
camsim99 May 10, 2023
5aabe34
Merge remote-tracking branch 'upstream/main'
camsim99 May 12, 2023
2b9a352
Merge remote-tracking branch 'upstream/main'
camsim99 May 25, 2023
a1173da
Merge remote-tracking branch 'upstream/main'
camsim99 May 30, 2023
cbc3d6b
Merge remote-tracking branch 'upstream/main'
camsim99 May 30, 2023
cae5a4c
Merge remote-tracking branch 'upstream/main'
camsim99 Jun 1, 2023
72283db
Merge remote-tracking branch 'upstream/main'
camsim99 Jun 5, 2023
166a77c
Merge remote-tracking branch 'upstream/main'
camsim99 Jun 5, 2023
399780e
Merge remote-tracking branch 'upstream/main'
camsim99 Jun 14, 2023
8d5d0e7
Merge remote-tracking branch 'upstream/main'
camsim99 Jun 26, 2023
084d960
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 12, 2023
d2a59ac
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 17, 2023
a1422bf
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 17, 2023
bdd87a6
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 18, 2023
137a28b
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 19, 2023
bc0db5a
Merge remote-tracking branch 'upstream/main'
camsim99 Jul 20, 2023
b6f1c5f
start dev
camsim99 Jul 20, 2023
ebfccb7
Dev
camsim99 Jul 21, 2023
b21d1c2
wrap minus tests and cleanup
camsim99 Jul 25, 2023
10cb737
Add new files
camsim99 Jul 27, 2023
64d903e
Dart tests
camsim99 Aug 1, 2023
6b7c70e
Fix recorder test
camsim99 Aug 1, 2023
b975b1d
Modify java side
camsim99 Aug 1, 2023
89c76b5
Working on java tests
camsim99 Aug 2, 2023
cddc3cd
Fix java tests
camsim99 Aug 2, 2023
802218b
Remove unecessary verify
camsim99 Aug 3, 2023
52e49ee
Merge remote-tracking branch 'upstream/main' into camx_vidres1
camsim99 Aug 3, 2023
fb99807
Cleanup
camsim99 Aug 3, 2023
0d6f7b9
Bump version
camsim99 Aug 3, 2023
55eeb17
Fix lint and add test for recorder
camsim99 Aug 8, 2023
7f58a16
Merge branch 'main' into camx_vidres1
camsim99 Aug 8, 2023
949e20d
Merge remote-tracking branch 'upstream/main' into camx_vidres1
camsim99 Aug 14, 2023
8c77fab
Update packages/camera/camera_android_camerax/lib/src/fallback_strate…
camsim99 Aug 14, 2023
24e7ea5
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 Aug 14, 2023
b62c11d
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 Aug 14, 2023
acde675
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 Aug 14, 2023
957d4fa
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 Aug 14, 2023
8bbacb8
Update packages/camera/camera_android_camerax/lib/src/quality_selecto…
camsim99 Aug 14, 2023
6f29185
Update packages/camera/camera_android_camerax/pigeons/camerax_library…
camsim99 Aug 14, 2023
9c5c436
Address review
camsim99 Aug 14, 2023
0ace4e2
Merge branch 'camx_vidres1' of github.com:camsim99/packages into camx…
camsim99 Aug 14, 2023
9887f33
Update packages/camera/camera_android_camerax/android/src/main/java/i…
camsim99 Aug 15, 2023
cd73662
Update packages/camera/camera_android_camerax/android/src/main/java/i…
camsim99 Aug 15, 2023
a42a5dc
Update packages/camera/camera_android_camerax/lib/src/fallback_strate…
camsim99 Aug 15, 2023
6db0529
Merge branch 'main' into camx_vidres1
camsim99 Aug 15, 2023
eb8ea0c
Fix format
camsim99 Aug 15, 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
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+14

* Wraps classes needed to implement resolution configuration for video recording.

## 0.5.0+13

* Migrates `styleFrom` usage in examples off of deprecated `primary` and `onPrimary` parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public void setUp(
binaryMessenger, new ResolutionStrategyHostApiImpl(instanceManager));
GeneratedCameraXLibrary.AspectRatioStrategyHostApi.setup(
binaryMessenger, new AspectRatioStrategyHostApiImpl(instanceManager));
GeneratedCameraXLibrary.FallbackStrategyHostApi.setup(
binaryMessenger, new FallbackStrategyHostApiImpl(instanceManager));
GeneratedCameraXLibrary.QualitySelectorHostApi.setup(
binaryMessenger, new QualitySelectorHostApiImpl(instanceManager));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.VideoQualityConstraint;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.VideoResolutionFallbackRule;

/**
* 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 @NonNull FallbackStrategy create(
@NonNull VideoQualityConstraint videoQualityConstraint,
@NonNull VideoResolutionFallbackRule fallbackRule) {
Quality videoQuality =
QualitySelectorHostApiImpl.getQualityFromVideoQualityConstraint(videoQualityConstraint);

switch (fallbackRule) {
case HIGHER_QUALITY_OR_LOWER_THAN:
return FallbackStrategy.higherQualityOrLowerThan(videoQuality);
case HIGHER_QUALITY_THAN:
return FallbackStrategy.higherQualityThan(videoQuality);
case LOWER_QUALITY_OR_HIGHER_THAN:
return FallbackStrategy.lowerQualityOrHigherThan(videoQuality);
case LOWER_QUALITY_THAN:
return FallbackStrategy.lowerQualityThan(videoQuality);
}
throw new IllegalArgumentException(
"Specified fallback rule " + fallbackRule + " unrecognized.");
}
}

/**
* 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}
*/
FallbackStrategyHostApiImpl(
@NonNull InstanceManager instanceManager, @NonNull FallbackStrategyProxy proxy) {
this.instanceManager = instanceManager;
this.proxy = proxy;
}

/**
* Creates a {@link FallbackStrategy} instance with the video quality and fallback rule specified.
*/
@Override
public void create(
@NonNull Long identifier,
@NonNull VideoQualityConstraint videoQualityConstraint,
@NonNull VideoResolutionFallbackRule fallbackRule) {
instanceManager.addDartCreatedInstance(
proxy.create(videoQualityConstraint, fallbackRule), identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,43 @@ private LiveDataSupportedType(final int index) {
}
}

/**
* Video quality constraints that will be used by a QualitySelector to choose an appropriate video
* resolution.
*
* <p>These are pre-defined quality constants that are universally used for video.
*
* <p>See https://developer.android.com/reference/androidx/camera/video/Quality.
*/
public enum VideoQualityConstraint {
SD(0),
HD(1),
FHD(2),
UHD(3),
LOWEST(4),
HIGHEST(5);

final int index;

private VideoQualityConstraint(final int index) {
this.index = index;
}
}

/** Fallback rules for selecting video resolution. */
public enum VideoResolutionFallbackRule {
HIGHER_QUALITY_OR_LOWER_THAN(0),
HIGHER_QUALITY_THAN(1),
LOWER_QUALITY_OR_HIGHER_THAN(2),
LOWER_QUALITY_THAN(3);

final int index;

private VideoResolutionFallbackRule(final int index) {
this.index = index;
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class ResolutionInfo {
private @NonNull Long width;
Expand Down Expand Up @@ -1556,7 +1593,11 @@ public void create(@NonNull Long identifierArg, @NonNull Reply<Void> callback) {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface RecorderHostApi {

void create(@NonNull Long identifier, @Nullable Long aspectRatio, @Nullable Long bitRate);
void create(
@NonNull Long identifier,
@Nullable Long aspectRatio,
@Nullable Long bitRate,
@Nullable Long qualitySelectorId);

@NonNull
Long getAspectRatio(@NonNull Long identifier);
Expand Down Expand Up @@ -1587,11 +1628,13 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable RecorderHo
Number identifierArg = (Number) args.get(0);
Number aspectRatioArg = (Number) args.get(1);
Number bitRateArg = (Number) args.get(2);
Number qualitySelectorIdArg = (Number) args.get(3);
try {
api.create(
(identifierArg == null) ? null : identifierArg.longValue(),
(aspectRatioArg == null) ? null : aspectRatioArg.longValue(),
(bitRateArg == null) ? null : bitRateArg.longValue());
(bitRateArg == null) ? null : bitRateArg.longValue(),
(qualitySelectorIdArg == null) ? null : qualitySelectorIdArg.longValue());
wrapped.add(0, null);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
Expand Down Expand Up @@ -2937,4 +2980,165 @@ public void create(
channelReply -> callback.reply(null));
}
}

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

private QualitySelectorHostApiCodec() {}

@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 QualitySelectorHostApi {

void create(
@NonNull Long identifier,
@NonNull List<Long> videoQualityConstraintIndexList,
@Nullable Long fallbackStrategyId);

@NonNull
ResolutionInfo getResolution(
@NonNull Long cameraInfoId, @NonNull VideoQualityConstraint quality);

/** The codec used by QualitySelectorHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
return QualitySelectorHostApiCodec.INSTANCE;
}
/**
* Sets up an instance of `QualitySelectorHostApi` to handle messages through the
* `binaryMessenger`.
*/
static void setup(
@NonNull BinaryMessenger binaryMessenger, @Nullable QualitySelectorHostApi api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.QualitySelectorHostApi.create", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
List<Long> videoQualityConstraintIndexListArg = (List<Long>) args.get(1);
Number fallbackStrategyIdArg = (Number) args.get(2);
try {
api.create(
(identifierArg == null) ? null : identifierArg.longValue(),
videoQualityConstraintIndexListArg,
(fallbackStrategyIdArg == null) ? null : fallbackStrategyIdArg.longValue());
wrapped.add(0, null);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.QualitySelectorHostApi.getResolution",
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number cameraInfoIdArg = (Number) args.get(0);
VideoQualityConstraint qualityArg =
args.get(1) == null ? null : VideoQualityConstraint.values()[(int) args.get(1)];
try {
ResolutionInfo output =
api.getResolution(
(cameraInfoIdArg == null) ? null : cameraInfoIdArg.longValue(),
qualityArg);
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface FallbackStrategyHostApi {

void create(
@NonNull Long identifier,
@NonNull VideoQualityConstraint quality,
@NonNull VideoResolutionFallbackRule fallbackRule);

/** The codec used by FallbackStrategyHostApi. */
static @NonNull MessageCodec<Object> getCodec() {
return new StandardMessageCodec();
}
/**
* Sets up an instance of `FallbackStrategyHostApi` to handle messages through the
* `binaryMessenger`.
*/
static void setup(
@NonNull BinaryMessenger binaryMessenger, @Nullable FallbackStrategyHostApi api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.FallbackStrategyHostApi.create", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
Number identifierArg = (Number) args.get(0);
VideoQualityConstraint qualityArg =
args.get(1) == null ? null : VideoQualityConstraint.values()[(int) args.get(1)];
VideoResolutionFallbackRule fallbackRuleArg =
args.get(2) == null
? null
: VideoResolutionFallbackRule.values()[(int) args.get(2)];
try {
api.create(
(identifierArg == null) ? null : identifierArg.longValue(),
qualityArg,
fallbackRuleArg);
wrapped.add(0, null);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}
}
Loading