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

Commit 91b9aabc authored by Ruben Brunk's avatar Ruben Brunk
Browse files

camera2: Switch to using YV12 for ImageReader.

Bug: 15116722

- Also fixes incorrect frame number for single captures.

Change-Id: I8552124d18ad176e6724f089a1e3a3f49a5eeec4
parent 5776aafc
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -174,13 +174,17 @@ public class LegacyCameraDevice implements AutoCloseable {
    private final RequestThreadManager mRequestThreadManager;

    /**
     * Check if a given surface uses {@link ImageFormat#YUV_420_888} format.
     * Check if a given surface uses {@link ImageFormat#YUV_420_888} or format that can be readily
     * converted to this; YV12 and NV21 are the two currently supported formats.
     *
     * @param s the surface to check.
     * @return {@code true} if the surfaces uses {@link ImageFormat#YUV_420_888}.
     * @return {@code true} if the surfaces uses {@link ImageFormat#YUV_420_888} or a compatible
     *          format.
     */
    static boolean needsConversion(Surface s) {
        return LegacyCameraDevice.nativeDetectSurfaceType(s) == ImageFormat.YUV_420_888;
        int nativeType = LegacyCameraDevice.nativeDetectSurfaceType(s);
        return nativeType == ImageFormat.YUV_420_888 || nativeType == ImageFormat.YV12 ||
                nativeType == ImageFormat.NV21;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class LegacyMetadataMapper {
    private static final int HAL_PIXEL_FORMAT_BLOB = 0x21;

    private static final long APPROXIMATE_CAPTURE_DELAY_MS = 200; // ms
    private static final long APPROXIMATE_SENSOR_AREA = (1 << 20); // 8mp
    private static final long APPROXIMATE_SENSOR_AREA = (1 << 23); // 8mp
    private static final long APPROXIMATE_JPEG_ENCODE_TIME = 600; // ms
    private static final long NS_PER_MS = 1000000;

+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public class RequestQueue {
        for (BurstHolder b : mRequestQueue) {
            total += b.getNumberOfRequests();
            if (b.getRequestId() == requestId) {
                return total;
                return total - 1;
            }
        }
        throw new IllegalStateException(
+6 −1
Original line number Diff line number Diff line
@@ -239,6 +239,9 @@ public class RequestThreadManager {
                        mGLThreadManager.queueNewFrame(holder.getHolderTargets());
                    }

                    /**
                     * TODO: Get timestamp from GL thread after buffer update.
                     */
                    mLastPreviewTimestamp = surfaceTexture.getTimestamp();
                    mReceivedPreview.open();
                }
@@ -495,7 +498,6 @@ public class RequestThreadManager {
                            if (holder.hasJpegTargets()) {
                                mReceivedJpeg.close();
                                doJpegCapture(holder);
                                mReceivedJpeg.block();
                                if (!mReceivedJpeg.block(JPEG_FRAME_TIMEOUT)) {
                                    // TODO: report error to CameraDevice
                                    Log.e(TAG, "Hit timeout for jpeg callback!");
@@ -507,6 +509,9 @@ public class RequestThreadManager {
                            // TODO: err handling
                            throw new IOError(e);
                        }
                        if (timestamp == 0) {
                            timestamp = SystemClock.elapsedRealtimeNanos();
                        }
                        CameraMetadataNative result = LegacyMetadataMapper.convertResultMetadata(mParams,
                                request, timestamp);
                        mDeviceState.setCaptureResult(holder, result);
+1 −1
Original line number Diff line number Diff line
@@ -439,7 +439,7 @@ public class SurfaceTextureRenderer {
        for (Surface s : surfaces) {
            // If pixel conversions aren't handled by egl, use a pbuffer
            if (LegacyCameraDevice.needsConversion(s)) {
                LegacyCameraDevice.nativeSetSurfaceFormat(s, ImageFormat.NV21);
                LegacyCameraDevice.nativeSetSurfaceFormat(s, ImageFormat.YV12);
                EGLSurfaceHolder holder = new EGLSurfaceHolder();
                holder.surface = s;
                mConversionSurfaces.add(holder);
Loading