Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
raulsvilar authored Aug 16, 2023
2 parents 6b79899 + 9bf208f commit ab5e9e2
Show file tree
Hide file tree
Showing 38 changed files with 2,266 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .ci/flutter_master.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9b6945b465a104c7dea41f3042a70781abc39718
f0e7c518164167638d55ec848365f1aa8a7cb6b2
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v1.0.26
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v1.0.26
with:
sarif_file: results.sarif
8 changes: 8 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.5.0+15

* Explicitly removes `READ_EXTERNAL_STORAGE` permission that may otherwise be implied from `WRITE_EXTERNAL_STORAGE`.

## 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
@@ -1,8 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.flutter.plugins.camerax">
<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
tools:node="remove" />
</manifest>
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

0 comments on commit ab5e9e2

Please sign in to comment.