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

Commit d41fed72 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Camera: Populate Image tranformation in reader and writer" into pi-dev

parents fc841b26 450a5ffd
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -185,6 +185,13 @@ public abstract class Image implements AutoCloseable {
     */
    public abstract long getTimestamp();

    /**
     * Get the transformation associated with this frame.
     * @return The window transformation that needs to be applied for this frame.
     * @hide
     */
    public abstract int getTransform();

    /**
     * Get the {@link android.hardware.HardwareBuffer HardwareBuffer} handle of the input image
     * intended for GPU and/or hardware access.
+11 −0
Original line number Diff line number Diff line
@@ -875,6 +875,12 @@ public class ImageReader implements AutoCloseable {
            return mTimestamp;
        }

        @Override
        public int getTransform() {
            throwISEIfImageIsInvalid();
            return mTransform;
        }

        @Override
        public HardwareBuffer getHardwareBuffer() {
            throwISEIfImageIsInvalid();
@@ -1013,6 +1019,11 @@ public class ImageReader implements AutoCloseable {
         */
        private long mTimestamp;

        /**
         * This field is set by native code during nativeImageSetup().
         */
        private int mTransform;

        private SurfacePlane[] mPlanes;
        private int mFormat = ImageFormat.UNKNOWN;
        // If this image is detached from the ImageReader.
+14 −4
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ public class ImageWriter implements AutoCloseable {

        Rect crop = image.getCropRect();
        nativeQueueInputImage(mNativeContext, image, image.getTimestamp(), crop.left, crop.top,
                crop.right, crop.bottom);
                crop.right, crop.bottom, image.getTransform());

        /**
         * Only remove and cleanup the Images that are owned by this
@@ -557,7 +557,8 @@ public class ImageWriter implements AutoCloseable {
        // buffer caused leak.
        Rect crop = image.getCropRect();
        nativeAttachAndQueueImage(mNativeContext, image.getNativeContext(), image.getFormat(),
                image.getTimestamp(), crop.left, crop.top, crop.right, crop.bottom);
                image.getTimestamp(), crop.left, crop.top, crop.right, crop.bottom,
                image.getTransform());
    }

    /**
@@ -674,6 +675,8 @@ public class ImageWriter implements AutoCloseable {
        private final long DEFAULT_TIMESTAMP = Long.MIN_VALUE;
        private long mTimestamp = DEFAULT_TIMESTAMP;

        private int mTransform = 0; //Default no transform

        public WriterSurfaceImage(ImageWriter writer) {
            mOwner = writer;
        }
@@ -710,6 +713,13 @@ public class ImageWriter implements AutoCloseable {
            return mHeight;
        }

        @Override
        public int getTransform() {
            throwISEIfImageIsInvalid();

            return mTransform;
        }

        @Override
        public long getTimestamp() {
            throwISEIfImageIsInvalid();
@@ -856,11 +866,11 @@ public class ImageWriter implements AutoCloseable {
    private synchronized native void nativeDequeueInputImage(long nativeCtx, Image wi);

    private synchronized native void nativeQueueInputImage(long nativeCtx, Image image,
            long timestampNs, int left, int top, int right, int bottom);
            long timestampNs, int left, int top, int right, int bottom, int transform);

    private synchronized native int nativeAttachAndQueueImage(long nativeCtx,
            long imageNativeBuffer, int imageFormat, long timestampNs, int left,
            int top, int right, int bottom);
            int top, int right, int bottom, int transform);

    private synchronized native void cancelImage(long nativeCtx, Image image);

+8 −0
Original line number Diff line number Diff line
@@ -3528,6 +3528,8 @@ final public class MediaCodec {

        private final static int TYPE_YUV = 1;

        private final int mTransform = 0; //Default no transform

        @Override
        public int getFormat() {
            throwISEIfImageIsInvalid();
@@ -3546,6 +3548,12 @@ final public class MediaCodec {
            return mWidth;
        }

        @Override
        public int getTransform() {
            throwISEIfImageIsInvalid();
            return mTransform;
        }

        @Override
        public long getTimestamp() {
            throwISEIfImageIsInvalid();
+10 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#define ANDROID_MEDIA_IMAGEREADER_CTX_JNI_ID       "mNativeContext"
#define ANDROID_MEDIA_SURFACEIMAGE_BUFFER_JNI_ID   "mNativeBuffer"
#define ANDROID_MEDIA_SURFACEIMAGE_TS_JNI_ID       "mTimestamp"
#define ANDROID_MEDIA_SURFACEIMAGE_TF_JNI_ID       "mTransform"

#define CONSUMER_BUFFER_USAGE_UNKNOWN              0;
// ----------------------------------------------------------------------------
@@ -66,6 +67,7 @@ static struct {
static struct {
    jfieldID mNativeBuffer;
    jfieldID mTimestamp;
    jfieldID mTransform;
    jfieldID mPlanes;
} gSurfaceImageClassInfo;

@@ -307,6 +309,12 @@ static void ImageReader_classInit(JNIEnv* env, jclass clazz)
                        "can't find android/graphics/ImageReader.%s",
                        ANDROID_MEDIA_SURFACEIMAGE_TS_JNI_ID);

    gSurfaceImageClassInfo.mTransform = env->GetFieldID(
            imageClazz, ANDROID_MEDIA_SURFACEIMAGE_TF_JNI_ID, "I");
    LOG_ALWAYS_FATAL_IF(gSurfaceImageClassInfo.mTransform == NULL,
                        "can't find android/graphics/ImageReader.%s",
                        ANDROID_MEDIA_SURFACEIMAGE_TF_JNI_ID);

    gSurfaceImageClassInfo.mPlanes = env->GetFieldID(
            imageClazz, "mPlanes", "[Landroid/media/ImageReader$SurfaceImage$SurfacePlane;");
    LOG_ALWAYS_FATAL_IF(gSurfaceImageClassInfo.mPlanes == NULL,
@@ -596,6 +604,8 @@ static jint ImageReader_imageSetup(JNIEnv* env, jobject thiz, jobject image) {
    Image_setBufferItem(env, image, buffer);
    env->SetLongField(image, gSurfaceImageClassInfo.mTimestamp,
            static_cast<jlong>(buffer->mTimestamp));
    env->SetIntField(image, gSurfaceImageClassInfo.mTransform,
            static_cast<jint>(buffer->mTransform));

    return ACQUIRE_SUCCESS;
}
Loading