Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be05b054 authored by Jayant Chowdhary's avatar Jayant Chowdhary Committed by Android (Google) Code Review
Browse files

Merge "camera: Add FMQ support for camera2 impl SDK" into main

parents 541cf899 9165f171
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ public final class TotalCaptureResult extends CaptureResult {
        mPhysicalCaptureResults = new HashMap<String, TotalCaptureResult>();
        for (PhysicalCaptureResultInfo onePhysicalResult : physicalResults) {
            TotalCaptureResult physicalResult = new TotalCaptureResult(
                    onePhysicalResult.getCameraId(), onePhysicalResult.getCameraMetadata(),
                    onePhysicalResult.getCameraId(),
                    onePhysicalResult.getCameraMetadata(),
                    parent, extras, /*partials*/null, sessionId, new PhysicalCaptureResultInfo[0]);
            mPhysicalCaptureResults.put(onePhysicalResult.getCameraId(),
                    physicalResult);
@@ -115,7 +116,8 @@ public final class TotalCaptureResult extends CaptureResult {
        mPhysicalCaptureResults = new HashMap<String, TotalCaptureResult>();
        for (PhysicalCaptureResultInfo onePhysicalResult : physicalResults) {
            TotalCaptureResult physicalResult = new TotalCaptureResult(
                    onePhysicalResult.getCameraId(), onePhysicalResult.getCameraMetadata(),
                    onePhysicalResult.getCameraId(),
                    onePhysicalResult.getCameraMetadata(),
                    parent, requestId, frameNumber, /*partials*/null, sessionId,
                    new PhysicalCaptureResultInfo[0]);
            mPhysicalCaptureResults.put(onePhysicalResult.getCameraId(),
+58 −10
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraExtensionCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CameraMetadataInfo;
import android.hardware.camera2.CameraOfflineSession;
import android.hardware.camera2.CaptureFailure;
import android.hardware.camera2.CaptureRequest;
@@ -59,6 +60,8 @@ import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.os.SystemClock;
@@ -129,6 +132,8 @@ public class CameraDeviceImpl extends CameraDevice
    final Object mInterfaceLock = new Object(); // access from this class and Session only!
    private final CameraDeviceCallbacks mCallbacks = new CameraDeviceCallbacks();

    private long mFMQReader; // native fmq reader ptr

    private final StateCallback mDeviceCallback;
    private volatile StateCallbackKK mSessionStateCallback;
    private final Executor mDeviceExecutor;
@@ -476,6 +481,9 @@ public class CameraDeviceImpl extends CameraDevice
            if (mInError) return;

            mRemoteDevice = new ICameraDeviceUserWrapper(remoteDevice);
            Parcel resultParcel = Parcel.obtain();
            mRemoteDevice.getCaptureResultMetadataQueue().writeToParcel(resultParcel, 0);
            mFMQReader = nativeCreateFMQReader(resultParcel);

            IBinder remoteDeviceBinder = remoteDevice.asBinder();
            // For legacy camera device, remoteDevice is in the same process, and
@@ -1682,6 +1690,7 @@ public class CameraDeviceImpl extends CameraDevice
            if (mRemoteDevice != null || mInError) {
                mDeviceExecutor.execute(mCallOnClosed);
            }
            nativeClose(mFMQReader);

            mRemoteDevice = null;
        }
@@ -2416,27 +2425,61 @@ public class CameraDeviceImpl extends CameraDevice
                }
            }
        }
        private PhysicalCaptureResultInfo[] readMetadata(
            PhysicalCaptureResultInfo[] srcPhysicalResults) {
            PhysicalCaptureResultInfo[] retVal =
                    new PhysicalCaptureResultInfo[srcPhysicalResults.length];
            int i = 0;
            long fmqSize = 0;
            for (PhysicalCaptureResultInfo srcPhysicalResult : srcPhysicalResults) {
                CameraMetadataNative physicalCameraMetadata = null;
                if (srcPhysicalResult.getCameraMetadataInfo().getTag() ==
                        CameraMetadataInfo.fmqSize) {
                    fmqSize = srcPhysicalResult.getCameraMetadataInfo().getFmqSize();
                    physicalCameraMetadata =
                            new CameraMetadataNative(nativeReadResultMetadata(mFMQReader, fmqSize));
                } else {
                    physicalCameraMetadata = srcPhysicalResult.getCameraMetadata();
                }
                PhysicalCaptureResultInfo physicalResultInfo =
                        new PhysicalCaptureResultInfo(
                                srcPhysicalResult.getCameraId(), physicalCameraMetadata);
                retVal[i] = physicalResultInfo;
                i++;
            }
           return retVal;
        }

        @Override
        public void onResultReceived(CameraMetadataNative result,
        public void onResultReceived(CameraMetadataInfo resultInfo,
                CaptureResultExtras resultExtras, PhysicalCaptureResultInfo physicalResults[])
                throws RemoteException {
            int requestId = resultExtras.getRequestId();
            long frameNumber = resultExtras.getFrameNumber();

            synchronized(mInterfaceLock) {
                if (mRemoteDevice == null) return; // Camera already closed
                PhysicalCaptureResultInfo savedPhysicalResults[] = physicalResults;
                CameraMetadataNative result;
                if (resultInfo.getTag() == CameraMetadataInfo.fmqSize) {
                    CameraMetadataNative fmqMetadata =
                            new CameraMetadataNative(
                                    nativeReadResultMetadata(mFMQReader, resultInfo.getFmqSize()));
                    result = fmqMetadata;
                } else {
                    result = resultInfo.getMetadata();
                }
                physicalResults = readMetadata(savedPhysicalResults);
                if (DEBUG) {
                    Log.v(TAG, "Received result frame " + frameNumber + " for id "
                            + requestId);
                }

            synchronized(mInterfaceLock) {
                if (mRemoteDevice == null) return; // Camera already closed


                // Redirect device callback to the offline session in case we are in the middle
                // of an offline switch
                if (mOfflineSessionImpl != null) {
                    mOfflineSessionImpl.getCallbacks().onResultReceived(result, resultExtras,
                    CameraMetadataInfo resultInfoOffline = CameraMetadataInfo.metadata(result);
                    mOfflineSessionImpl.getCallbacks().onResultReceived(resultInfoOffline,
                            resultExtras,
                            physicalResults);
                    return;
                }
@@ -2824,6 +2867,11 @@ public class CameraDeviceImpl extends CameraDevice
        }
    }

    private static native long nativeCreateFMQReader(Parcel resultQueue);
    //TODO: Investigate adding FastNative b/62791857
    private static native long nativeReadResultMetadata(long ptr, long metadataSize);
    private static native void nativeClose(long ptr);

    @Override
    public @CAMERA_AUDIO_RESTRICTION int getCameraAudioRestriction() throws CameraAccessException {
        synchronized(mInterfaceLock) {
+12 −0
Original line number Diff line number Diff line
@@ -390,6 +390,18 @@ public class CameraMetadataNative implements Parcelable {
        updateNativeAllocation();
    }

    /**
     * Take ownership of native metadata
     */
    public CameraMetadataNative(long metadataPtr) {
        super();
        mMetadataPtr = metadataPtr;
        if (mMetadataPtr == 0) {
            throw new OutOfMemoryError("Failed to allocate native CameraMetadata");
        }
        updateNativeAllocation();
    }

    /**
     * Move the contents from {@code other} into a new camera metadata instance.</p>
     *
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.hardware.camera2.CameraOfflineSession.CameraOfflineSessionCallbac
import android.hardware.camera2.CaptureFailure;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.CameraMetadataInfo;
import android.hardware.camera2.ICameraDeviceCallbacks;
import android.hardware.camera2.ICameraOfflineSession;
import android.hardware.camera2.TotalCaptureResult;
@@ -291,10 +292,10 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
        }

        @Override
        public void onResultReceived(CameraMetadataNative result,
        public void onResultReceived(CameraMetadataInfo resultInfo,
                CaptureResultExtras resultExtras, PhysicalCaptureResultInfo physicalResults[])
                throws RemoteException {

            CameraMetadataNative result = resultInfo.getMetadata();
            int requestId = resultExtras.getRequestId();
            long frameNumber = resultExtras.getFrameNumber();

+13 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.hardware.camera2.params.OutputConfiguration;
import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.ExceptionUtils;
import android.hardware.camera2.utils.SubmitInfo;
import android.hardware.common.fmq.MQDescriptor;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
@@ -313,4 +314,15 @@ public class ICameraDeviceUserWrapper {
            throw ExceptionUtils.throwAsPublicException(e);
        }
    }

    public MQDescriptor<Byte, Byte> getCaptureResultMetadataQueue() throws CameraAccessException {
        try {
            return mRemoteDevice.getCaptureResultMetadataQueue();
        } catch (ServiceSpecificException e) {
            throw ExceptionUtils.throwAsPublicException(e);
        } catch (RemoteException e) {
            throw ExceptionUtils.throwAsPublicException(e);
        }
    }

}
 No newline at end of file
Loading