Android + OpenCV: SurfaceTexture has been abandoned

asked 2015-02-26 23:58:32 -0600

pedromarques gravatar image

i'm developing an application in eclipse with opencv. The application run the menu with no problems but when I access to the camera it crashes. I debbug, and notice this message error:

queueBuffer: SurfaceTexture has been abandoned!

Here is the code that create the surface and setupCamera:

public void setupCamera(int width, int height) {
//Log.i(TAG, "setupCamera");
synchronized (this) {
    if (mCamera != null) {
        Camera.Parameters params = mCamera.getParameters();
        List<Camera.Size> sizes = params.getSupportedPreviewSizes();
        mFrameWidth = width;
        mFrameHeight = height;

        // selecting optimal camera preview size
        {
            int minDiff = Integer.MAX_VALUE;
            for (Camera.Size size : sizes) {
                if (Math.abs(size.height - height) < minDiff) {
                    mFrameWidth = size.width;
                    mFrameHeight = size.height;
                    minDiff = Math.abs(size.height - height);
                }
            }
        }

        params.setPreviewSize(getFrameWidth(), getFrameHeight());
        //Log.i(TAG, Integer.valueOf(mFrameWidth).toString());
        //Log.i(TAG, Integer.valueOf(mFrameHeight).toString());

        params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        // List<String> FocusModes = params.getSupportedFocusModes();
        // if (FocusModes
        // .contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        // params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        // }

        mCamera.setParameters(params);

        /* Now allocate the buffer */
        params = mCamera.getParameters();
        int size = params.getPreviewSize().width
                * params.getPreviewSize().height;
        size = size
                * ImageFormat
                        .getBitsPerPixel(params.getPreviewFormat()) / 8;
        mBuffer = new byte[size];
        /* The buffer where the current frame will be copied */
        mFrame = new byte[size];
        mCamera.addCallbackBuffer(mBuffer);

        onPreviewStarted(params.getPreviewSize().width,
                params.getPreviewSize().height);

        try {
            setPreview();
        } catch (IOException e) {
            //Log.e(TAG,
                    //"mCamera.setPreviewDisplay/setPreviewTexture fails: "
                            //+ e);
        }

        /*
         * Notify that the preview is about to be started and deliver
         * preview size
         */
        //onPreviewStarted(params.getPreviewSize().width,
                //params.getPreviewSize().height);

        /* Now we can start a preview */
        mCamera.startPreview();

    }
}
}

public void surfaceChanged(SurfaceHolder _holder, int format, int width,
    int height) {
//Log.i(TAG, "surfaceChanged");
setupCamera(width, height);
}

public void surfaceCreated(SurfaceHolder holder) {
//Log.i(TAG, "surfaceCreated");
(new Thread(this)).start();
}

public void surfaceDestroyed(SurfaceHolder holder) {
//Log.i(TAG, "surfaceDestroyed");
releaseCamera();
}

I already checked the solution given in this Post, and changed the order of that line but the problem continues. Any suggestion?

edit retag flag offensive close merge delete