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

Commit ce06ebfd authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android (Google) Code Review
Browse files

Merge "Add support for timestamps into SurfaceTexture."

parents 6764ba44 c5f94d8a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -410,8 +410,9 @@ public class Camera {

    /**
     * Starts capturing and drawing preview frames to the screen.
     * Preview will not actually start until a surface is supplied with
     * {@link #setPreviewDisplay(SurfaceHolder)}.
     * Preview will not actually start until a surface is supplied
     * with {@link #setPreviewDisplay(SurfaceHolder)} or
     * {@link #setPreviewTexture(SurfaceTexture)}.
     *
     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
+8 −1
Original line number Diff line number Diff line
@@ -171,6 +171,12 @@ static void SurfaceTexture_getTransformMatrix(JNIEnv* env, jobject thiz,
    env->ReleaseFloatArrayElements(jmtx, mtx, 0);
}

static jlong SurfaceTexture_getTimestamp(JNIEnv* env, jobject thiz)
{
    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
    return surfaceTexture->getTimestamp();
}

// ----------------------------------------------------------------------------

const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
@@ -181,6 +187,7 @@ static JNINativeMethod gSurfaceTextureMethods[] = {
    {"nativeFinalize",           "()V",   (void*)SurfaceTexture_finalize },
    {"nativeUpdateTexImage",     "()V",   (void*)SurfaceTexture_updateTexImage },
    {"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
    {"nativeGetTimestamp",       "()J",   (void*)SurfaceTexture_getTimestamp }
};

int register_android_graphics_SurfaceTexture(JNIEnv* env)
+16 −0
Original line number Diff line number Diff line
@@ -144,6 +144,21 @@ public class SurfaceTexture {
        nativeGetTransformMatrix(mtx);
    }

    /**
     * Retrieve the timestamp associated with the texture image set by the most recent call to
     * updateTexImage.
     *
     * This timestamp is in nanoseconds, and is guaranteed to be monotonically increasing. The
     * specific meaning and zero point of the timestamp depends on the source providing images to
     * the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot
     * generally be compared across SurfaceTexture instances, or across multiple program
     * invocations. It is mostly useful for determining time offsets between subsequent frames.
     * @hide
     */
    public long getTimestamp() {
        return nativeGetTimestamp();
    }

    protected void finalize() throws Throwable {
        try {
            nativeFinalize();
@@ -182,6 +197,7 @@ public class SurfaceTexture {
    private native void nativeInit(int texName, Object weakSelf);
    private native void nativeFinalize();
    private native void nativeGetTransformMatrix(float[] mtx);
    private native long nativeGetTimestamp();
    private native void nativeUpdateTexImage();

    /*
+5 −2
Original line number Diff line number Diff line
@@ -62,8 +62,11 @@ public:
    // contents of the buffer associated with slot and transfers ownership of
    // that slot back to the server. It is not valid to call queueBuffer on a
    // slot that is not owned by the client or one for which a buffer associated
    // via requestBuffer.
    virtual status_t queueBuffer(int slot) = 0;
    // via requestBuffer. In addition, a timestamp must be provided by the
    // client for this buffer. The timestamp is measured in nanoseconds, and
    // must be monotonically increasing. Its other properties (zero point, etc)
    // are client-dependent, and should be documented by the client.
    virtual status_t queueBuffer(int slot, int64_t timestamp) = 0;

    // cancelBuffer indicates that the client does not wish to fill in the
    // buffer associated with slot and transfers ownership of the slot back to
+22 −1
Original line number Diff line number Diff line
@@ -66,7 +66,12 @@ public:
    // unmodified.
    virtual status_t dequeueBuffer(int *buf);

    virtual status_t queueBuffer(int buf);
    // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
    // timestamp must be provided for the buffer. The timestamp is in
    // nanoseconds, and must be monotonically increasing. Its other semantics
    // (zero point, etc) are client-dependent and should be documented by the
    // client.
    virtual status_t queueBuffer(int buf, int64_t timestamp);
    virtual void cancelBuffer(int buf);
    virtual status_t setCrop(const Rect& reg);
    virtual status_t setTransform(uint32_t transform);
@@ -98,6 +103,14 @@ public:
    // functions.
    void getTransformMatrix(float mtx[16]);

    // getTimestamp retrieves the timestamp associated with the texture image
    // set by the most recent call to updateTexImage.
    //
    // The timestamp is in nanoseconds, and is monotonically increasing. Its
    // other semantics (zero point, etc) are source-dependent and should be
    // documented by the source.
    int64_t getTimestamp();

    // setFrameAvailableListener sets the listener object that will be notified
    // when a new frame becomes available.
    void setFrameAvailableListener(const sp<FrameAvailableListener>& l);
@@ -172,6 +185,10 @@ private:
    // gets set to mLastQueuedTransform each time updateTexImage is called.
    uint32_t mCurrentTransform;

    // mCurrentTimestamp is the timestamp for the current texture. It
    // gets set to mLastQueuedTimestamp each time updateTexImage is called.
    int64_t mCurrentTimestamp;

    // mLastQueued is the buffer slot index of the most recently enqueued buffer.
    // At construction time it is initialized to INVALID_BUFFER_SLOT, and is
    // updated each time queueBuffer is called.
@@ -187,6 +204,10 @@ private:
    // queueBuffer gets called.
    uint32_t mLastQueuedTransform;

    // mLastQueuedTimestamp is the timestamp for the buffer that was most
    // recently queued. This gets set by queueBuffer.
    int64_t mLastQueuedTimestamp;

    // mNextCrop is the crop rectangle that will be used for the next buffer
    // that gets queued. It is set by calling setCrop.
    Rect mNextCrop;
Loading