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

Commit 3c9ba5dc authored by Emilian Peev's avatar Emilian Peev Committed by Automerger Merge Worker
Browse files

Merge changes from topic "b194508189" into sc-dev am: e922ec31

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15376189

Change-Id: I98ed8958d992a814caf8f22c833c4d2a88dd8cb2
parents 685f8223 e922ec31
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -446,10 +446,16 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
        }
    }

    public void release() {
        synchronized (mInterfaceLock) {
    @Override
    protected void finalize() throws Throwable {
        if (mHandlerThread != null) {
            mHandlerThread.quitSafely();
        }
        super.finalize();
    }

    public void release() {
        synchronized (mInterfaceLock) {
            if (mSessionProcessor != null) {
                try {
                    mSessionProcessor.deInitSession();
@@ -812,6 +818,8 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
                    Log.e(TAG,"Failed to parcel buffer fence!");
                }
            }
            parcelImage.width = img.getWidth();
            parcelImage.height = img.getHeight();
            parcelImage.format = img.getFormat();
            parcelImage.timestamp = img.getTimestamp();
            parcelImage.transform = img.getTransform();
+10 −0
Original line number Diff line number Diff line
@@ -696,6 +696,16 @@ public class CameraDeviceImpl extends CameraDevice
                mCurrentSession.replaceSessionClose();
            }

            if (mCurrentExtensionSession != null) {
                mCurrentExtensionSession.release();
                mCurrentExtensionSession = null;
            }

            if (mCurrentAdvancedExtensionSession != null) {
                mCurrentAdvancedExtensionSession.release();
                mCurrentAdvancedExtensionSession = null;
            }

            // TODO: dont block for this
            boolean configureSuccess = true;
            CameraAccessException pendingException = null;
+34 −16
Original line number Diff line number Diff line
@@ -49,8 +49,6 @@ import android.media.ImageWriter;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.IInterface;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.annotation.NonNull;
@@ -265,13 +263,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
            } catch (ClassCastException e) {
                throw new UnsupportedOperationException("Failed casting preview processor!");
            }
            if (mClientRepeatingRequestSurface != null) {
                mPreviewRequestUpdateProcessor.onOutputSurface(mClientRepeatingRequestSurface,
                        nativeGetSurfaceFormat(mClientRepeatingRequestSurface));
                mRepeatingRequestImageWriter = ImageWriter.newInstance(
                        mClientRepeatingRequestSurface, PREVIEW_QUEUE_SIZE,
                        CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT);
            }
            mRepeatingRequestImageReader = ImageReader.newInstance(repeatingSurfaceInfo.mWidth,
                    repeatingSurfaceInfo.mHeight,
                    CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT,
@@ -285,11 +276,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
            mPreviewRequestUpdateProcessor.onImageFormatUpdate(
                    CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT);
        } else {
            if (mClientRepeatingRequestSurface != null) {
                mRepeatingRequestImageWriter = ImageWriter.newInstance(
                        mClientRepeatingRequestSurface, PREVIEW_QUEUE_SIZE,
                        CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT);
            }
            mRepeatingRequestImageReader = ImageReader.newInstance(repeatingSurfaceInfo.mWidth,
                    repeatingSurfaceInfo.mHeight,
                    CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT,
@@ -320,7 +306,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
                mBurstCaptureImageReader = ImageReader.newInstance(surfaceInfo.mWidth,
                        surfaceInfo.mHeight, CameraExtensionCharacteristics.PROCESSING_INPUT_FORMAT,
                        mImageExtender.getMaxCaptureStage());
                mImageProcessor.onOutputSurface(mClientCaptureSurface, surfaceInfo.mFormat);
            } else {
                // The client doesn't intend to trigger multi-frame capture, however the
                // image extender still needs to get initialized and the camera still capture
@@ -367,6 +352,29 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
        }
    }

    private void finishPipelineInitialization() throws RemoteException {
        if (mClientRepeatingRequestSurface != null) {
            if (mPreviewProcessorType == IPreviewExtenderImpl.PROCESSOR_TYPE_REQUEST_UPDATE_ONLY) {
                mPreviewRequestUpdateProcessor.onOutputSurface(mClientRepeatingRequestSurface,
                        nativeGetSurfaceFormat(mClientRepeatingRequestSurface));
                mRepeatingRequestImageWriter = ImageWriter.newInstance(
                        mClientRepeatingRequestSurface,
                        PREVIEW_QUEUE_SIZE,
                        CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT);
            } else if (mPreviewProcessorType == IPreviewExtenderImpl.PROCESSOR_TYPE_NONE) {
                mRepeatingRequestImageWriter = ImageWriter.newInstance(
                        mClientRepeatingRequestSurface,
                        PREVIEW_QUEUE_SIZE,
                        CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT);
            }
        }
        if ((mImageProcessor != null) && (mClientCaptureSurface != null)) {
            CameraExtensionUtils.SurfaceInfo surfaceInfo = CameraExtensionUtils.querySurface(
                    mClientCaptureSurface);
            mImageProcessor.onOutputSurface(mClientCaptureSurface, surfaceInfo.mFormat);
        }
    }

    /**
     * @hide
     */
@@ -622,11 +630,18 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
                new CameraExtensionUtils.HandlerExecutor(mHandler), requestHandler);
    }

    @Override
    protected void finalize() throws Throwable {
        if (mHandlerThread != null) {
            mHandlerThread.quitSafely();
        }
        super.finalize();
    }

    /** @hide */
    public void release() {
        synchronized (mInterfaceLock) {
            mInternalRepeatingRequestEnabled = false;
            mHandlerThread.quitSafely();

            try {
                mPreviewExtender.onDeInit();
@@ -750,6 +765,7 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
            synchronized (mInterfaceLock) {
                mCaptureSession = session;
                try {
                    finishPipelineInitialization();
                    CameraExtensionCharacteristics.initializeSession(mInitializeHandler);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to initialize session! Extension service does"
@@ -1640,6 +1656,8 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
                Log.e(TAG,"Failed to parcel buffer fence!");
            }
        }
        parcelImage.width = img.getWidth();
        parcelImage.height = img.getHeight();
        parcelImage.format = img.getFormat();
        parcelImage.timestamp = img.getTimestamp();
        parcelImage.transform = img.getTransform();
+5 −27
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.ImageFormat;
import android.graphics.PixelFormat;
import android.hardware.HardwareBuffer;
import android.hardware.camera2.CameraExtensionCharacteristics;
import android.hardware.camera2.params.OutputConfiguration;
import android.hardware.camera2.params.StreamConfigurationMap;
@@ -78,41 +77,20 @@ public final class CameraExtensionUtils {
        SurfaceInfo surfaceInfo = new SurfaceInfo();
        int nativeFormat = SurfaceUtils.getSurfaceFormat(s);
        int dataspace = SurfaceUtils.getSurfaceDataspace(s);
        Size surfaceSize = SurfaceUtils.getSurfaceSize(s);
        surfaceInfo.mFormat = nativeFormat;
        surfaceInfo.mWidth = surfaceSize.getWidth();
        surfaceInfo.mHeight = surfaceSize.getHeight();
        surfaceInfo.mUsage = SurfaceUtils.getSurfaceUsage(s);
        // Jpeg surfaces cannot be queried for their usage and other parameters
        // in the usual way below. A buffer can only be de-queued after the
        // producer overrides the surface dimensions to (width*height) x 1.
        if ((nativeFormat == StreamConfigurationMap.HAL_PIXEL_FORMAT_BLOB) &&
                (dataspace == StreamConfigurationMap.HAL_DATASPACE_V0_JFIF)) {
            surfaceInfo.mFormat = ImageFormat.JPEG;
            Size surfaceSize = SurfaceUtils.getSurfaceSize(s);
            surfaceInfo.mWidth = surfaceSize.getWidth();
            surfaceInfo.mHeight = surfaceSize.getHeight();
            return surfaceInfo;
        }

        HardwareBuffer buffer = null;
        try {
            writer = ImageWriter.newInstance(s, 1);
            img = writer.dequeueInputImage();
            buffer = img.getHardwareBuffer();
            surfaceInfo.mFormat = buffer.getFormat();
            surfaceInfo.mWidth = buffer.getWidth();
            surfaceInfo.mHeight = buffer.getHeight();
            surfaceInfo.mUsage = buffer.getUsage();
        } catch (Exception e) {
            Log.e(TAG, "Failed to query surface, returning defaults!");
        } finally {
            if (buffer != null) {
                buffer.close();
            }
            if (img != null) {
                img.close();
            }
            if (writer != null) {
                writer.close();
            }
        }

        return surfaceInfo;
    }

+14 −0
Original line number Diff line number Diff line
@@ -104,6 +104,20 @@ public class SurfaceUtils {
        }
    }

    /**
     * Get the surface usage bits.
     *
     * @param surface The surface to be queried for usage.
     * @return the native object id of the surface, 0 if surface is not backed by a native object.
     */
    public static long getSurfaceUsage(Surface surface) {
        checkNotNull(surface);
        try {
            return nativeDetectSurfaceUsageFlags(surface);
        } catch (IllegalArgumentException e) {
            return 0;
        }
    }
    /**
     * Get the Surface size.
     *