1145 lines
50 KiB
Java
1145 lines
50 KiB
Java
|
package io.flutter.plugins.camera;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.content.Context;
|
||
|
import android.graphics.Rect;
|
||
|
import android.graphics.SurfaceTexture;
|
||
|
import android.hardware.camera2.CameraAccessException;
|
||
|
import android.hardware.camera2.CameraCaptureSession;
|
||
|
import android.hardware.camera2.CameraDevice;
|
||
|
import android.hardware.camera2.CaptureRequest;
|
||
|
import android.hardware.camera2.TotalCaptureResult;
|
||
|
import android.hardware.camera2.params.OutputConfiguration;
|
||
|
import android.hardware.camera2.params.SessionConfiguration;
|
||
|
import android.media.CamcorderProfile;
|
||
|
import android.media.EncoderProfiles;
|
||
|
import android.media.Image;
|
||
|
import android.media.ImageReader;
|
||
|
import android.media.MediaRecorder;
|
||
|
import android.os.Build;
|
||
|
import android.os.Handler;
|
||
|
import android.os.HandlerThread;
|
||
|
import android.os.Looper;
|
||
|
import android.util.Size;
|
||
|
import android.view.Display;
|
||
|
import android.view.Surface;
|
||
|
import com.kofax.mobile.sdk._internal.impl.extraction.rtti.RttiJsonExactionHelper;
|
||
|
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
|
||
|
import io.flutter.plugin.common.EventChannel;
|
||
|
import io.flutter.plugin.common.MethodChannel;
|
||
|
import io.flutter.plugins.camera.Camera;
|
||
|
import io.flutter.plugins.camera.CameraCaptureCallback;
|
||
|
import io.flutter.plugins.camera.ImageSaver;
|
||
|
import io.flutter.plugins.camera.features.CameraFeature;
|
||
|
import io.flutter.plugins.camera.features.CameraFeatureFactory;
|
||
|
import io.flutter.plugins.camera.features.CameraFeatures;
|
||
|
import io.flutter.plugins.camera.features.Point;
|
||
|
import io.flutter.plugins.camera.features.autofocus.AutoFocusFeature;
|
||
|
import io.flutter.plugins.camera.features.autofocus.FocusMode;
|
||
|
import io.flutter.plugins.camera.features.exposurelock.ExposureLockFeature;
|
||
|
import io.flutter.plugins.camera.features.exposurelock.ExposureMode;
|
||
|
import io.flutter.plugins.camera.features.exposureoffset.ExposureOffsetFeature;
|
||
|
import io.flutter.plugins.camera.features.exposurepoint.ExposurePointFeature;
|
||
|
import io.flutter.plugins.camera.features.flash.FlashFeature;
|
||
|
import io.flutter.plugins.camera.features.flash.FlashMode;
|
||
|
import io.flutter.plugins.camera.features.focuspoint.FocusPointFeature;
|
||
|
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
|
||
|
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
|
||
|
import io.flutter.plugins.camera.features.sensororientation.DeviceOrientationManager;
|
||
|
import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature;
|
||
|
import io.flutter.plugins.camera.media.MediaRecorderBuilder;
|
||
|
import io.flutter.plugins.camera.types.CameraCaptureProperties;
|
||
|
import io.flutter.plugins.camera.types.CaptureTimeoutsWrapper;
|
||
|
import io.flutter.view.TextureRegistry;
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
import java.nio.ByteBuffer;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import java.util.Locale;
|
||
|
import java.util.Map;
|
||
|
import java.util.concurrent.Executors;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class Camera implements CameraCaptureCallback.CameraCaptureStateListener, ImageReader.OnImageAvailableListener {
|
||
|
private static final String TAG = "Camera";
|
||
|
private static final HashMap<String, Integer> supportedImageFormats;
|
||
|
private final Activity activity;
|
||
|
private final Context applicationContext;
|
||
|
private Handler backgroundHandler;
|
||
|
private HandlerThread backgroundHandlerThread;
|
||
|
private final CameraCaptureCallback cameraCaptureCallback;
|
||
|
private CameraDeviceWrapper cameraDevice;
|
||
|
private final CameraFeatureFactory cameraFeatureFactory;
|
||
|
private final CameraFeatures cameraFeatures;
|
||
|
private final CameraProperties cameraProperties;
|
||
|
private File captureFile;
|
||
|
private CameraCaptureProperties captureProps;
|
||
|
private CameraCaptureSession captureSession;
|
||
|
private CaptureTimeoutsWrapper captureTimeouts;
|
||
|
private final DartMessenger dartMessenger;
|
||
|
private final boolean enableAudio;
|
||
|
private MethodChannel.Result flutterResult;
|
||
|
private final TextureRegistry.SurfaceTextureEntry flutterTexture;
|
||
|
private ImageReader imageStreamReader;
|
||
|
private MediaRecorder mediaRecorder;
|
||
|
private boolean pausedPreview;
|
||
|
private ImageReader pictureImageReader;
|
||
|
private CaptureRequest.Builder previewRequestBuilder;
|
||
|
private boolean recordingVideo;
|
||
|
|
||
|
static {
|
||
|
HashMap<String, Integer> hashMap = new HashMap<>();
|
||
|
supportedImageFormats = hashMap;
|
||
|
hashMap.put("yuv420", 35);
|
||
|
hashMap.put("jpeg", 256);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
class DefaultCameraDeviceWrapper implements CameraDeviceWrapper {
|
||
|
private final CameraDevice cameraDevice;
|
||
|
final Camera this$0;
|
||
|
|
||
|
private DefaultCameraDeviceWrapper(Camera camera, CameraDevice cameraDevice) {
|
||
|
this.this$0 = camera;
|
||
|
this.cameraDevice = cameraDevice;
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraDeviceWrapper
|
||
|
public CaptureRequest.Builder createCaptureRequest(int i) throws CameraAccessException {
|
||
|
return this.cameraDevice.createCaptureRequest(i);
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraDeviceWrapper
|
||
|
public void createCaptureSession(SessionConfiguration sessionConfiguration) throws CameraAccessException {
|
||
|
this.cameraDevice.createCaptureSession(sessionConfiguration);
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraDeviceWrapper
|
||
|
public void createCaptureSession(List<Surface> list, CameraCaptureSession.StateCallback stateCallback, Handler handler) throws CameraAccessException {
|
||
|
this.cameraDevice.createCaptureSession(list, stateCallback, this.this$0.backgroundHandler);
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraDeviceWrapper
|
||
|
public void close() {
|
||
|
this.cameraDevice.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Camera(Activity activity, TextureRegistry.SurfaceTextureEntry surfaceTextureEntry, CameraFeatureFactory cameraFeatureFactory, DartMessenger dartMessenger, CameraProperties cameraProperties, ResolutionPreset resolutionPreset, boolean z) {
|
||
|
if (activity == null) {
|
||
|
throw new IllegalStateException("No activity available!");
|
||
|
}
|
||
|
this.activity = activity;
|
||
|
this.enableAudio = z;
|
||
|
this.flutterTexture = surfaceTextureEntry;
|
||
|
this.dartMessenger = dartMessenger;
|
||
|
this.applicationContext = activity.getApplicationContext();
|
||
|
this.cameraProperties = cameraProperties;
|
||
|
this.cameraFeatureFactory = cameraFeatureFactory;
|
||
|
this.cameraFeatures = CameraFeatures.init(cameraFeatureFactory, cameraProperties, activity, dartMessenger, resolutionPreset);
|
||
|
this.captureTimeouts = new CaptureTimeoutsWrapper(3000L, 3000L);
|
||
|
CameraCaptureProperties cameraCaptureProperties = new CameraCaptureProperties();
|
||
|
this.captureProps = cameraCaptureProperties;
|
||
|
this.cameraCaptureCallback = CameraCaptureCallback.create(this, this.captureTimeouts, cameraCaptureProperties);
|
||
|
startBackgroundThread();
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraCaptureCallback.CameraCaptureStateListener
|
||
|
public void onConverged() {
|
||
|
takePictureAfterPrecapture();
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.CameraCaptureCallback.CameraCaptureStateListener
|
||
|
public void onPrecapture() {
|
||
|
runPrecaptureSequence();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public void updateBuilderSettings(CaptureRequest.Builder builder) {
|
||
|
for (CameraFeature cameraFeature : this.cameraFeatures.getAllFeatures()) {
|
||
|
cameraFeature.getDebugName();
|
||
|
cameraFeature.updateBuilder(builder);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void prepareMediaRecorder(String str) throws IOException {
|
||
|
MediaRecorderBuilder mediaRecorderBuilder;
|
||
|
int videoOrientation;
|
||
|
MediaRecorder mediaRecorder = this.mediaRecorder;
|
||
|
if (mediaRecorder != null) {
|
||
|
mediaRecorder.release();
|
||
|
}
|
||
|
PlatformChannel.DeviceOrientation lockedCaptureOrientation = this.cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();
|
||
|
EncoderProfiles recordingProfile = getRecordingProfile();
|
||
|
if (Build.VERSION.SDK_INT >= 31 && recordingProfile != null) {
|
||
|
mediaRecorderBuilder = new MediaRecorderBuilder(recordingProfile, str);
|
||
|
} else {
|
||
|
mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileLegacy(), str);
|
||
|
}
|
||
|
MediaRecorderBuilder enableAudio = mediaRecorderBuilder.setEnableAudio(this.enableAudio);
|
||
|
if (lockedCaptureOrientation == null) {
|
||
|
videoOrientation = getDeviceOrientationManager().getVideoOrientation();
|
||
|
} else {
|
||
|
videoOrientation = getDeviceOrientationManager().getVideoOrientation(lockedCaptureOrientation);
|
||
|
}
|
||
|
this.mediaRecorder = enableAudio.setMediaOrientation(videoOrientation).build();
|
||
|
}
|
||
|
|
||
|
public void open(String str) throws CameraAccessException {
|
||
|
ResolutionFeature resolution = this.cameraFeatures.getResolution();
|
||
|
if (!resolution.checkIsSupported()) {
|
||
|
DartMessenger dartMessenger = this.dartMessenger;
|
||
|
StringBuilder sb = new StringBuilder("Camera with name \"");
|
||
|
sb.append(this.cameraProperties.getCameraName());
|
||
|
sb.append("\" is not supported by this plugin.");
|
||
|
dartMessenger.sendCameraErrorEvent(sb.toString());
|
||
|
return;
|
||
|
}
|
||
|
this.pictureImageReader = ImageReader.newInstance(resolution.getCaptureSize().getWidth(), resolution.getCaptureSize().getHeight(), 256, 1);
|
||
|
Integer num = supportedImageFormats.get(str);
|
||
|
if (num == null) {
|
||
|
num = 35;
|
||
|
}
|
||
|
this.imageStreamReader = ImageReader.newInstance(resolution.getPreviewSize().getWidth(), resolution.getPreviewSize().getHeight(), num.intValue(), 1);
|
||
|
CameraUtils.getCameraManager(this.activity).openCamera(this.cameraProperties.getCameraName(), new CameraDevice.StateCallback(this, resolution) { // from class: io.flutter.plugins.camera.Camera.1
|
||
|
final Camera this$0;
|
||
|
final ResolutionFeature val$resolutionFeature;
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
this.val$resolutionFeature = resolution;
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraDevice.StateCallback
|
||
|
public void onOpened(CameraDevice cameraDevice) {
|
||
|
Camera camera = this.this$0;
|
||
|
camera.cameraDevice = new DefaultCameraDeviceWrapper(cameraDevice);
|
||
|
try {
|
||
|
this.this$0.startPreview();
|
||
|
DartMessenger dartMessenger2 = this.this$0.dartMessenger;
|
||
|
int width = this.val$resolutionFeature.getPreviewSize().getWidth();
|
||
|
int height = this.val$resolutionFeature.getPreviewSize().getHeight();
|
||
|
dartMessenger2.sendCameraInitializedEvent(Integer.valueOf(width), Integer.valueOf(height), this.this$0.cameraFeatures.getExposureLock().getValue(), this.this$0.cameraFeatures.getAutoFocus().getValue(), Boolean.valueOf(this.this$0.cameraFeatures.getExposurePoint().checkIsSupported()), Boolean.valueOf(this.this$0.cameraFeatures.getFocusPoint().checkIsSupported()));
|
||
|
} catch (CameraAccessException e) {
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent(e.getMessage());
|
||
|
this.this$0.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraDevice.StateCallback
|
||
|
public void onClosed(CameraDevice cameraDevice) {
|
||
|
this.this$0.cameraDevice = null;
|
||
|
this.this$0.closeCaptureSession();
|
||
|
this.this$0.dartMessenger.sendCameraClosingEvent();
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraDevice.StateCallback
|
||
|
public void onDisconnected(CameraDevice cameraDevice) {
|
||
|
this.this$0.close();
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent("The camera was disconnected.");
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraDevice.StateCallback
|
||
|
public void onError(CameraDevice cameraDevice, int i) {
|
||
|
this.this$0.close();
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent(i != 1 ? i != 2 ? i != 3 ? i != 4 ? i != 5 ? "Unknown camera error" : "The camera service has encountered a fatal error." : "The camera device has encountered a fatal error" : "The camera device could not be opened due to a device policy." : "Max cameras in use" : "The camera device is in use already.");
|
||
|
}
|
||
|
}, this.backgroundHandler);
|
||
|
}
|
||
|
|
||
|
void createCaptureSession(int i, Surface... surfaceArr) throws CameraAccessException {
|
||
|
createCaptureSession(i, null, surfaceArr);
|
||
|
}
|
||
|
|
||
|
private void createCaptureSession(int i, Runnable runnable, Surface... surfaceArr) throws CameraAccessException {
|
||
|
this.captureSession = null;
|
||
|
this.previewRequestBuilder = this.cameraDevice.createCaptureRequest(i);
|
||
|
ResolutionFeature resolution = this.cameraFeatures.getResolution();
|
||
|
SurfaceTexture surfaceTexture = this.flutterTexture.surfaceTexture();
|
||
|
surfaceTexture.setDefaultBufferSize(resolution.getPreviewSize().getWidth(), resolution.getPreviewSize().getHeight());
|
||
|
Surface surface = new Surface(surfaceTexture);
|
||
|
this.previewRequestBuilder.addTarget(surface);
|
||
|
List asList = Arrays.asList(surfaceArr);
|
||
|
if (i != 1) {
|
||
|
Iterator it = asList.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
this.previewRequestBuilder.addTarget((Surface) it.next());
|
||
|
}
|
||
|
}
|
||
|
Size cameraBoundaries = CameraRegionUtils.getCameraBoundaries(this.cameraProperties, this.previewRequestBuilder);
|
||
|
this.cameraFeatures.getExposurePoint().setCameraBoundaries(cameraBoundaries);
|
||
|
this.cameraFeatures.getFocusPoint().setCameraBoundaries(cameraBoundaries);
|
||
|
CameraCaptureSession.StateCallback anonymousClass2 = new AnonymousClass2(this, runnable);
|
||
|
if (Build.VERSION.SDK_INT >= 28) {
|
||
|
List<OutputConfiguration> arrayList = new ArrayList<>();
|
||
|
arrayList.add(new OutputConfiguration(surface));
|
||
|
Iterator it2 = asList.iterator();
|
||
|
while (it2.hasNext()) {
|
||
|
arrayList.add(new OutputConfiguration((Surface) it2.next()));
|
||
|
}
|
||
|
createCaptureSessionWithSessionConfig(arrayList, anonymousClass2);
|
||
|
return;
|
||
|
}
|
||
|
List<Surface> arrayList2 = new ArrayList<>();
|
||
|
arrayList2.add(surface);
|
||
|
arrayList2.addAll(asList);
|
||
|
createCaptureSession(arrayList2, anonymousClass2);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: io.flutter.plugins.camera.Camera$2, reason: invalid class name */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class AnonymousClass2 extends CameraCaptureSession.StateCallback {
|
||
|
boolean captureSessionClosed = false;
|
||
|
final Camera this$0;
|
||
|
final Runnable val$onSuccessCallback;
|
||
|
|
||
|
AnonymousClass2(Camera camera, Runnable runnable) {
|
||
|
this.this$0 = camera;
|
||
|
this.val$onSuccessCallback = runnable;
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraCaptureSession.StateCallback
|
||
|
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
|
||
|
if (this.this$0.cameraDevice == null || this.captureSessionClosed) {
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent("The camera was closed during configuration.");
|
||
|
return;
|
||
|
}
|
||
|
this.this$0.captureSession = cameraCaptureSession;
|
||
|
Camera camera = this.this$0;
|
||
|
camera.updateBuilderSettings(camera.previewRequestBuilder);
|
||
|
this.this$0.refreshPreviewCaptureSession(this.val$onSuccessCallback, new ErrorCallback(this) { // from class: io.flutter.plugins.camera.Camera$2$$ExternalSyntheticLambda0
|
||
|
public final Camera.AnonymousClass2 f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.m346lambda$onConfigured$0$ioflutterpluginscameraCamera$2(str, str2);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$onConfigured$0$io-flutter-plugins-camera-Camera$2, reason: not valid java name */
|
||
|
public /* synthetic */ void m346lambda$onConfigured$0$ioflutterpluginscameraCamera$2(String str, String str2) {
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent(str2);
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraCaptureSession.StateCallback
|
||
|
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
|
||
|
this.this$0.dartMessenger.sendCameraErrorEvent("Failed to configure camera session.");
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraCaptureSession.StateCallback
|
||
|
public void onClosed(CameraCaptureSession cameraCaptureSession) {
|
||
|
this.captureSessionClosed = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void createCaptureSessionWithSessionConfig(List<OutputConfiguration> list, CameraCaptureSession.StateCallback stateCallback) throws CameraAccessException {
|
||
|
this.cameraDevice.createCaptureSession(new SessionConfiguration(0, list, Executors.newSingleThreadExecutor(), stateCallback));
|
||
|
}
|
||
|
|
||
|
private void createCaptureSession(List<Surface> list, CameraCaptureSession.StateCallback stateCallback) throws CameraAccessException {
|
||
|
this.cameraDevice.createCaptureSession(list, stateCallback, this.backgroundHandler);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public void refreshPreviewCaptureSession(Runnable runnable, ErrorCallback errorCallback) {
|
||
|
CameraCaptureSession cameraCaptureSession = this.captureSession;
|
||
|
if (cameraCaptureSession == null) {
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
if (!this.pausedPreview) {
|
||
|
cameraCaptureSession.setRepeatingRequest(this.previewRequestBuilder.build(), this.cameraCaptureCallback, this.backgroundHandler);
|
||
|
}
|
||
|
if (runnable != null) {
|
||
|
runnable.run();
|
||
|
}
|
||
|
} catch (CameraAccessException e) {
|
||
|
errorCallback.onError("cameraAccess", e.getMessage());
|
||
|
} catch (IllegalStateException e2) {
|
||
|
StringBuilder sb = new StringBuilder("Camera is closed: ");
|
||
|
sb.append(e2.getMessage());
|
||
|
errorCallback.onError("cameraAccess", sb.toString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void startCapture(boolean z, boolean z2) throws CameraAccessException {
|
||
|
Runnable runnable;
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
if (z) {
|
||
|
arrayList.add(this.mediaRecorder.getSurface());
|
||
|
runnable = new Runnable(this) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda17
|
||
|
public final Camera f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.m344lambda$startCapture$0$ioflutterpluginscameraCamera();
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
}
|
||
|
};
|
||
|
} else {
|
||
|
runnable = null;
|
||
|
}
|
||
|
if (z2) {
|
||
|
arrayList.add(this.imageStreamReader.getSurface());
|
||
|
}
|
||
|
createCaptureSession(3, runnable, (Surface[]) arrayList.toArray(new Surface[0]));
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$startCapture$0$io-flutter-plugins-camera-Camera, reason: not valid java name */
|
||
|
public /* synthetic */ void m344lambda$startCapture$0$ioflutterpluginscameraCamera() {
|
||
|
this.mediaRecorder.start();
|
||
|
}
|
||
|
|
||
|
public void takePicture(MethodChannel.Result result) {
|
||
|
if (this.cameraCaptureCallback.getCameraState() != CameraState.STATE_PREVIEW) {
|
||
|
result.error("captureAlreadyActive", "Picture is currently already being captured", null);
|
||
|
return;
|
||
|
}
|
||
|
this.flutterResult = result;
|
||
|
try {
|
||
|
this.captureFile = File.createTempFile("CAP", ".jpg", this.applicationContext.getCacheDir());
|
||
|
this.captureTimeouts.reset();
|
||
|
this.pictureImageReader.setOnImageAvailableListener(this, this.backgroundHandler);
|
||
|
AutoFocusFeature autoFocus = this.cameraFeatures.getAutoFocus();
|
||
|
if (autoFocus.checkIsSupported() && autoFocus.getValue() == FocusMode.auto) {
|
||
|
runPictureAutoFocus();
|
||
|
} else {
|
||
|
runPrecaptureSequence();
|
||
|
}
|
||
|
} catch (IOException | SecurityException e) {
|
||
|
this.dartMessenger.error(this.flutterResult, "cannotCreateFile", e.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void runPrecaptureSequence() {
|
||
|
try {
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, 0);
|
||
|
this.captureSession.capture(this.previewRequestBuilder.build(), this.cameraCaptureCallback, this.backgroundHandler);
|
||
|
refreshPreviewCaptureSession(null, new ErrorCallback(this) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda1
|
||
|
public final Camera f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.m342lambda$runPrecaptureSequence$1$ioflutterpluginscameraCamera(str, str2);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
}
|
||
|
});
|
||
|
this.cameraCaptureCallback.setCameraState(CameraState.STATE_WAITING_PRECAPTURE_START);
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, 1);
|
||
|
this.captureSession.capture(this.previewRequestBuilder.build(), this.cameraCaptureCallback, this.backgroundHandler);
|
||
|
} catch (CameraAccessException unused) {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$runPrecaptureSequence$1$io-flutter-plugins-camera-Camera, reason: not valid java name */
|
||
|
public /* synthetic */ void m342lambda$runPrecaptureSequence$1$ioflutterpluginscameraCamera(String str, String str2) {
|
||
|
this.dartMessenger.error(this.flutterResult, "cameraAccess", str2, null);
|
||
|
}
|
||
|
|
||
|
private void takePictureAfterPrecapture() {
|
||
|
int photoOrientation;
|
||
|
this.cameraCaptureCallback.setCameraState(CameraState.STATE_CAPTURING);
|
||
|
CameraDeviceWrapper cameraDeviceWrapper = this.cameraDevice;
|
||
|
if (cameraDeviceWrapper == null) {
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
CaptureRequest.Builder createCaptureRequest = cameraDeviceWrapper.createCaptureRequest(2);
|
||
|
createCaptureRequest.addTarget(this.pictureImageReader.getSurface());
|
||
|
createCaptureRequest.set(CaptureRequest.SCALER_CROP_REGION, (Rect) this.previewRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION));
|
||
|
updateBuilderSettings(createCaptureRequest);
|
||
|
PlatformChannel.DeviceOrientation lockedCaptureOrientation = this.cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();
|
||
|
CaptureRequest.Key key = CaptureRequest.JPEG_ORIENTATION;
|
||
|
if (lockedCaptureOrientation == null) {
|
||
|
photoOrientation = getDeviceOrientationManager().getPhotoOrientation();
|
||
|
} else {
|
||
|
photoOrientation = getDeviceOrientationManager().getPhotoOrientation(lockedCaptureOrientation);
|
||
|
}
|
||
|
createCaptureRequest.set(key, Integer.valueOf(photoOrientation));
|
||
|
CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback(this) { // from class: io.flutter.plugins.camera.Camera.3
|
||
|
final Camera this$0;
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
}
|
||
|
|
||
|
@Override // android.hardware.camera2.CameraCaptureSession.CaptureCallback
|
||
|
public void onCaptureCompleted(CameraCaptureSession cameraCaptureSession, CaptureRequest captureRequest, TotalCaptureResult totalCaptureResult) {
|
||
|
this.this$0.unlockAutoFocus();
|
||
|
}
|
||
|
};
|
||
|
try {
|
||
|
this.captureSession.stopRepeating();
|
||
|
this.captureSession.capture(createCaptureRequest.build(), captureCallback, this.backgroundHandler);
|
||
|
} catch (CameraAccessException e) {
|
||
|
this.dartMessenger.error(this.flutterResult, "cameraAccess", e.getMessage(), null);
|
||
|
}
|
||
|
} catch (CameraAccessException e2) {
|
||
|
this.dartMessenger.error(this.flutterResult, "cameraAccess", e2.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private Display getDefaultDisplay() {
|
||
|
return this.activity.getWindowManager().getDefaultDisplay();
|
||
|
}
|
||
|
|
||
|
public void startBackgroundThread() {
|
||
|
if (this.backgroundHandlerThread != null) {
|
||
|
return;
|
||
|
}
|
||
|
HandlerThread create = HandlerThreadFactory.create("CameraBackground");
|
||
|
this.backgroundHandlerThread = create;
|
||
|
try {
|
||
|
create.start();
|
||
|
} catch (IllegalThreadStateException unused) {
|
||
|
}
|
||
|
this.backgroundHandler = HandlerFactory.create(this.backgroundHandlerThread.getLooper());
|
||
|
}
|
||
|
|
||
|
public void stopBackgroundThread() {
|
||
|
HandlerThread handlerThread = this.backgroundHandlerThread;
|
||
|
if (handlerThread != null) {
|
||
|
handlerThread.quitSafely();
|
||
|
}
|
||
|
this.backgroundHandlerThread = null;
|
||
|
this.backgroundHandler = null;
|
||
|
}
|
||
|
|
||
|
private void runPictureAutoFocus() {
|
||
|
this.cameraCaptureCallback.setCameraState(CameraState.STATE_WAITING_FOCUS);
|
||
|
lockAutoFocus();
|
||
|
}
|
||
|
|
||
|
private void lockAutoFocus() {
|
||
|
if (this.captureSession == null) {
|
||
|
return;
|
||
|
}
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, 1);
|
||
|
try {
|
||
|
this.captureSession.capture(this.previewRequestBuilder.build(), null, this.backgroundHandler);
|
||
|
} catch (CameraAccessException e) {
|
||
|
this.dartMessenger.sendCameraErrorEvent(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public void unlockAutoFocus() {
|
||
|
if (this.captureSession == null) {
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, 2);
|
||
|
this.captureSession.capture(this.previewRequestBuilder.build(), null, this.backgroundHandler);
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, 0);
|
||
|
this.captureSession.capture(this.previewRequestBuilder.build(), null, this.backgroundHandler);
|
||
|
refreshPreviewCaptureSession(null, new ErrorCallback(this) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda8
|
||
|
public final Camera f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.m345lambda$unlockAutoFocus$2$ioflutterpluginscameraCamera(str, str2);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
}
|
||
|
});
|
||
|
} catch (CameraAccessException e) {
|
||
|
this.dartMessenger.sendCameraErrorEvent(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$unlockAutoFocus$2$io-flutter-plugins-camera-Camera, reason: not valid java name */
|
||
|
public /* synthetic */ void m345lambda$unlockAutoFocus$2$ioflutterpluginscameraCamera(String str, String str2) {
|
||
|
this.dartMessenger.error(this.flutterResult, str, str2, null);
|
||
|
}
|
||
|
|
||
|
public void startVideoRecording(MethodChannel.Result result, EventChannel eventChannel) {
|
||
|
prepareRecording(result);
|
||
|
if (eventChannel != null) {
|
||
|
setStreamHandler(eventChannel);
|
||
|
}
|
||
|
this.recordingVideo = true;
|
||
|
try {
|
||
|
startCapture(true, eventChannel != null);
|
||
|
result.success(null);
|
||
|
} catch (CameraAccessException e) {
|
||
|
this.recordingVideo = false;
|
||
|
this.captureFile = null;
|
||
|
result.error("videoRecordingFailed", e.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void stopVideoRecording(MethodChannel.Result result) {
|
||
|
if (!this.recordingVideo) {
|
||
|
result.success(null);
|
||
|
return;
|
||
|
}
|
||
|
this.cameraFeatures.setAutoFocus(this.cameraFeatureFactory.createAutoFocusFeature(this.cameraProperties, false));
|
||
|
this.recordingVideo = false;
|
||
|
try {
|
||
|
this.captureSession.abortCaptures();
|
||
|
this.mediaRecorder.stop();
|
||
|
} catch (CameraAccessException | IllegalStateException unused) {
|
||
|
}
|
||
|
this.mediaRecorder.reset();
|
||
|
try {
|
||
|
startPreview();
|
||
|
result.success(this.captureFile.getAbsolutePath());
|
||
|
this.captureFile = null;
|
||
|
} catch (CameraAccessException | IllegalStateException e) {
|
||
|
result.error("videoRecordingFailed", e.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void pauseVideoRecording(MethodChannel.Result result) {
|
||
|
if (!this.recordingVideo) {
|
||
|
result.success(null);
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
this.mediaRecorder.pause();
|
||
|
result.success(null);
|
||
|
} catch (IllegalStateException e) {
|
||
|
result.error("videoRecordingFailed", e.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void resumeVideoRecording(MethodChannel.Result result) {
|
||
|
if (!this.recordingVideo) {
|
||
|
result.success(null);
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
this.mediaRecorder.resume();
|
||
|
result.success(null);
|
||
|
} catch (IllegalStateException e) {
|
||
|
result.error("videoRecordingFailed", e.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setFlashMode(final MethodChannel.Result result, FlashMode flashMode) {
|
||
|
FlashFeature flash = this.cameraFeatures.getFlash();
|
||
|
flash.setValue(flashMode);
|
||
|
flash.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda0
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda9
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setFlashModeFailed", "Could not set flash mode.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void setExposureMode(final MethodChannel.Result result, ExposureMode exposureMode) {
|
||
|
ExposureLockFeature exposureLock = this.cameraFeatures.getExposureLock();
|
||
|
exposureLock.setValue(exposureMode);
|
||
|
exposureLock.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda14
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda15
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setExposureModeFailed", "Could not set exposure mode.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void setExposurePoint(final MethodChannel.Result result, Point point) {
|
||
|
ExposurePointFeature exposurePoint = this.cameraFeatures.getExposurePoint();
|
||
|
exposurePoint.setValue(point);
|
||
|
exposurePoint.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda2
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda3
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setExposurePointFailed", "Could not set exposure point.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public double getMaxExposureOffset() {
|
||
|
return this.cameraFeatures.getExposureOffset().getMaxExposureOffset();
|
||
|
}
|
||
|
|
||
|
public double getMinExposureOffset() {
|
||
|
return this.cameraFeatures.getExposureOffset().getMinExposureOffset();
|
||
|
}
|
||
|
|
||
|
public double getExposureOffsetStepSize() {
|
||
|
return this.cameraFeatures.getExposureOffset().getExposureOffsetStepSize();
|
||
|
}
|
||
|
|
||
|
public void setFocusMode(MethodChannel.Result result, FocusMode focusMode) {
|
||
|
AutoFocusFeature autoFocus = this.cameraFeatures.getAutoFocus();
|
||
|
autoFocus.setValue(focusMode);
|
||
|
autoFocus.updateBuilder(this.previewRequestBuilder);
|
||
|
if (!this.pausedPreview) {
|
||
|
int i = AnonymousClass6.$SwitchMap$io$flutter$plugins$camera$features$autofocus$FocusMode[focusMode.ordinal()];
|
||
|
if (i != 1) {
|
||
|
if (i == 2) {
|
||
|
unlockAutoFocus();
|
||
|
}
|
||
|
} else {
|
||
|
if (this.captureSession == null) {
|
||
|
return;
|
||
|
}
|
||
|
lockAutoFocus();
|
||
|
this.previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, 0);
|
||
|
try {
|
||
|
this.captureSession.setRepeatingRequest(this.previewRequestBuilder.build(), null, this.backgroundHandler);
|
||
|
} catch (CameraAccessException e) {
|
||
|
if (result != null) {
|
||
|
StringBuilder sb = new StringBuilder("Error setting focus mode: ");
|
||
|
sb.append(e.getMessage());
|
||
|
result.error("setFocusModeFailed", sb.toString(), null);
|
||
|
return;
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (result != null) {
|
||
|
result.success(null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: io.flutter.plugins.camera.Camera$6, reason: invalid class name */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static /* synthetic */ class AnonymousClass6 {
|
||
|
static final int[] $SwitchMap$io$flutter$plugins$camera$features$autofocus$FocusMode;
|
||
|
|
||
|
static {
|
||
|
int[] iArr = new int[FocusMode.values().length];
|
||
|
$SwitchMap$io$flutter$plugins$camera$features$autofocus$FocusMode = iArr;
|
||
|
try {
|
||
|
iArr[FocusMode.locked.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused) {
|
||
|
}
|
||
|
try {
|
||
|
$SwitchMap$io$flutter$plugins$camera$features$autofocus$FocusMode[FocusMode.auto.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused2) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setFocusPoint(final MethodChannel.Result result, Point point) {
|
||
|
FocusPointFeature focusPoint = this.cameraFeatures.getFocusPoint();
|
||
|
focusPoint.setValue(point);
|
||
|
focusPoint.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda4
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda5
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setFocusPointFailed", "Could not set focus point.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
setFocusMode(null, this.cameraFeatures.getAutoFocus().getValue());
|
||
|
}
|
||
|
|
||
|
public void setExposureOffset(final MethodChannel.Result result, double d) {
|
||
|
final ExposureOffsetFeature exposureOffset = this.cameraFeatures.getExposureOffset();
|
||
|
exposureOffset.setValue(Double.valueOf(d));
|
||
|
exposureOffset.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result, exposureOffset) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda10
|
||
|
public final MethodChannel.Result f$0;
|
||
|
public final ExposureOffsetFeature f$1;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(this.f$1.getValue());
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
this.f$1 = exposureOffset;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda11
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setExposureOffsetFailed", "Could not set exposure offset.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public float getMaxZoomLevel() {
|
||
|
return this.cameraFeatures.getZoomLevel().getMaximumZoomLevel();
|
||
|
}
|
||
|
|
||
|
public float getMinZoomLevel() {
|
||
|
return this.cameraFeatures.getZoomLevel().getMinimumZoomLevel();
|
||
|
}
|
||
|
|
||
|
CamcorderProfile getRecordingProfileLegacy() {
|
||
|
return this.cameraFeatures.getResolution().getRecordingProfileLegacy();
|
||
|
}
|
||
|
|
||
|
EncoderProfiles getRecordingProfile() {
|
||
|
return this.cameraFeatures.getResolution().getRecordingProfile();
|
||
|
}
|
||
|
|
||
|
DeviceOrientationManager getDeviceOrientationManager() {
|
||
|
return this.cameraFeatures.getSensorOrientation().getDeviceOrientationManager();
|
||
|
}
|
||
|
|
||
|
public void setZoomLevel(final MethodChannel.Result result, float f) throws CameraAccessException {
|
||
|
ZoomLevelFeature zoomLevel = this.cameraFeatures.getZoomLevel();
|
||
|
float maximumZoomLevel = zoomLevel.getMaximumZoomLevel();
|
||
|
float minimumZoomLevel = zoomLevel.getMinimumZoomLevel();
|
||
|
if (f > maximumZoomLevel || f < minimumZoomLevel) {
|
||
|
result.error("ZOOM_ERROR", String.format(Locale.ENGLISH, "Zoom level out of bounds (zoom level should be between %f and %f).", Float.valueOf(minimumZoomLevel), Float.valueOf(maximumZoomLevel)), null);
|
||
|
return;
|
||
|
}
|
||
|
zoomLevel.setValue(Float.valueOf(f));
|
||
|
zoomLevel.updateBuilder(this.previewRequestBuilder);
|
||
|
refreshPreviewCaptureSession(new Runnable(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda12
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
}, new ErrorCallback(result) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda13
|
||
|
public final MethodChannel.Result f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.error("setZoomLevelFailed", "Could not set zoom level.", null);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = result;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void lockCaptureOrientation(PlatformChannel.DeviceOrientation deviceOrientation) {
|
||
|
this.cameraFeatures.getSensorOrientation().lockCaptureOrientation(deviceOrientation);
|
||
|
}
|
||
|
|
||
|
public void unlockCaptureOrientation() {
|
||
|
this.cameraFeatures.getSensorOrientation().unlockCaptureOrientation();
|
||
|
}
|
||
|
|
||
|
public void pausePreview() throws CameraAccessException {
|
||
|
this.pausedPreview = true;
|
||
|
this.captureSession.stopRepeating();
|
||
|
}
|
||
|
|
||
|
public void resumePreview() {
|
||
|
this.pausedPreview = false;
|
||
|
refreshPreviewCaptureSession(null, new ErrorCallback(this) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda6
|
||
|
public final Camera f$0;
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ErrorCallback
|
||
|
public final void onError(String str, String str2) {
|
||
|
this.f$0.m341lambda$resumePreview$15$ioflutterpluginscameraCamera(str, str2);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$resumePreview$15$io-flutter-plugins-camera-Camera, reason: not valid java name */
|
||
|
public /* synthetic */ void m341lambda$resumePreview$15$ioflutterpluginscameraCamera(String str, String str2) {
|
||
|
this.dartMessenger.sendCameraErrorEvent(str2);
|
||
|
}
|
||
|
|
||
|
public void startPreview() throws CameraAccessException {
|
||
|
ImageReader imageReader = this.pictureImageReader;
|
||
|
if (imageReader == null || imageReader.getSurface() == null) {
|
||
|
return;
|
||
|
}
|
||
|
createCaptureSession(1, this.pictureImageReader.getSurface());
|
||
|
}
|
||
|
|
||
|
public void startPreviewWithImageStream(EventChannel eventChannel) throws CameraAccessException {
|
||
|
setStreamHandler(eventChannel);
|
||
|
startCapture(false, true);
|
||
|
}
|
||
|
|
||
|
@Override // android.media.ImageReader.OnImageAvailableListener
|
||
|
public void onImageAvailable(ImageReader imageReader) {
|
||
|
this.backgroundHandler.post(new ImageSaver(imageReader.acquireNextImage(), this.captureFile, new ImageSaver.Callback(this) { // from class: io.flutter.plugins.camera.Camera.4
|
||
|
final Camera this$0;
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ImageSaver.Callback
|
||
|
public void onComplete(String str) {
|
||
|
this.this$0.dartMessenger.finish(this.this$0.flutterResult, str);
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugins.camera.ImageSaver.Callback
|
||
|
public void onError(String str, String str2) {
|
||
|
this.this$0.dartMessenger.error(this.this$0.flutterResult, str, str2, null);
|
||
|
}
|
||
|
}));
|
||
|
this.cameraCaptureCallback.setCameraState(CameraState.STATE_PREVIEW);
|
||
|
}
|
||
|
|
||
|
private void prepareRecording(MethodChannel.Result result) {
|
||
|
try {
|
||
|
File createTempFile = File.createTempFile("REC", ".mp4", this.applicationContext.getCacheDir());
|
||
|
this.captureFile = createTempFile;
|
||
|
try {
|
||
|
prepareMediaRecorder(createTempFile.getAbsolutePath());
|
||
|
this.cameraFeatures.setAutoFocus(this.cameraFeatureFactory.createAutoFocusFeature(this.cameraProperties, true));
|
||
|
} catch (IOException e) {
|
||
|
this.recordingVideo = false;
|
||
|
this.captureFile = null;
|
||
|
result.error("videoRecordingFailed", e.getMessage(), null);
|
||
|
}
|
||
|
} catch (IOException | SecurityException e2) {
|
||
|
result.error("cannotCreateFile", e2.getMessage(), null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void setStreamHandler(EventChannel eventChannel) {
|
||
|
eventChannel.setStreamHandler(new EventChannel.StreamHandler(this) { // from class: io.flutter.plugins.camera.Camera.5
|
||
|
final Camera this$0;
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugin.common.EventChannel.StreamHandler
|
||
|
public void onListen(Object obj, EventChannel.EventSink eventSink) {
|
||
|
this.this$0.setImageStreamImageAvailableListener(eventSink);
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugin.common.EventChannel.StreamHandler
|
||
|
public void onCancel(Object obj) {
|
||
|
this.this$0.imageStreamReader.setOnImageAvailableListener(null, this.this$0.backgroundHandler);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public void setImageStreamImageAvailableListener(final EventChannel.EventSink eventSink) {
|
||
|
this.imageStreamReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener(this, eventSink) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda7
|
||
|
public final Camera f$0;
|
||
|
public final EventChannel.EventSink f$1;
|
||
|
|
||
|
@Override // android.media.ImageReader.OnImageAvailableListener
|
||
|
public final void onImageAvailable(ImageReader imageReader) {
|
||
|
this.f$0.m343x299dedda(this.f$1, imageReader);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = this;
|
||
|
this.f$1 = eventSink;
|
||
|
}
|
||
|
}, this.backgroundHandler);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: lambda$setImageStreamImageAvailableListener$17$io-flutter-plugins-camera-Camera, reason: not valid java name */
|
||
|
public /* synthetic */ void m343x299dedda(final EventChannel.EventSink eventSink, ImageReader imageReader) {
|
||
|
Image acquireNextImage = imageReader.acquireNextImage();
|
||
|
if (acquireNextImage == null) {
|
||
|
return;
|
||
|
}
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
for (Image.Plane plane : acquireNextImage.getPlanes()) {
|
||
|
ByteBuffer buffer = plane.getBuffer();
|
||
|
int remaining = buffer.remaining();
|
||
|
byte[] bArr = new byte[remaining];
|
||
|
buffer.get(bArr, 0, remaining);
|
||
|
HashMap hashMap = new HashMap();
|
||
|
hashMap.put("bytesPerRow", Integer.valueOf(plane.getRowStride()));
|
||
|
hashMap.put("bytesPerPixel", Integer.valueOf(plane.getPixelStride()));
|
||
|
hashMap.put("bytes", bArr);
|
||
|
arrayList.add(hashMap);
|
||
|
}
|
||
|
final HashMap hashMap2 = new HashMap();
|
||
|
hashMap2.put(RttiJsonExactionHelper.WIDTH, Integer.valueOf(acquireNextImage.getWidth()));
|
||
|
hashMap2.put(RttiJsonExactionHelper.HEIGHT, Integer.valueOf(acquireNextImage.getHeight()));
|
||
|
hashMap2.put("format", Integer.valueOf(acquireNextImage.getFormat()));
|
||
|
hashMap2.put("planes", arrayList);
|
||
|
hashMap2.put("lensAperture", this.captureProps.getLastLensAperture());
|
||
|
hashMap2.put("sensorExposureTime", this.captureProps.getLastSensorExposureTime());
|
||
|
hashMap2.put("sensorSensitivity", this.captureProps.getLastSensorSensitivity() == null ? null : Double.valueOf(r0.intValue()));
|
||
|
new Handler(Looper.getMainLooper()).post(new Runnable(eventSink, hashMap2) { // from class: io.flutter.plugins.camera.Camera$$ExternalSyntheticLambda16
|
||
|
public final EventChannel.EventSink f$0;
|
||
|
public final Map f$1;
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
this.f$0.success(this.f$1);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.f$0 = eventSink;
|
||
|
this.f$1 = hashMap2;
|
||
|
}
|
||
|
});
|
||
|
acquireNextImage.close();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public void closeCaptureSession() {
|
||
|
CameraCaptureSession cameraCaptureSession = this.captureSession;
|
||
|
if (cameraCaptureSession != null) {
|
||
|
cameraCaptureSession.close();
|
||
|
this.captureSession = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void close() {
|
||
|
CameraDeviceWrapper cameraDeviceWrapper = this.cameraDevice;
|
||
|
if (cameraDeviceWrapper != null) {
|
||
|
cameraDeviceWrapper.close();
|
||
|
this.cameraDevice = null;
|
||
|
this.captureSession = null;
|
||
|
} else {
|
||
|
closeCaptureSession();
|
||
|
}
|
||
|
ImageReader imageReader = this.pictureImageReader;
|
||
|
if (imageReader != null) {
|
||
|
imageReader.close();
|
||
|
this.pictureImageReader = null;
|
||
|
}
|
||
|
ImageReader imageReader2 = this.imageStreamReader;
|
||
|
if (imageReader2 != null) {
|
||
|
imageReader2.close();
|
||
|
this.imageStreamReader = null;
|
||
|
}
|
||
|
MediaRecorder mediaRecorder = this.mediaRecorder;
|
||
|
if (mediaRecorder != null) {
|
||
|
mediaRecorder.reset();
|
||
|
this.mediaRecorder.release();
|
||
|
this.mediaRecorder = null;
|
||
|
}
|
||
|
stopBackgroundThread();
|
||
|
}
|
||
|
|
||
|
public void dispose() {
|
||
|
close();
|
||
|
this.flutterTexture.release();
|
||
|
getDeviceOrientationManager().stop();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static class HandlerThreadFactory {
|
||
|
HandlerThreadFactory() {
|
||
|
}
|
||
|
|
||
|
public static HandlerThread create(String str) {
|
||
|
return new HandlerThread(str);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static class HandlerFactory {
|
||
|
HandlerFactory() {
|
||
|
}
|
||
|
|
||
|
public static Handler create(Looper looper) {
|
||
|
return new Handler(looper);
|
||
|
}
|
||
|
}
|
||
|
}
|