E
E
evgeniy1232018-08-23 14:45:43
Java
evgeniy123, 2018-08-23 14:45:43

Why do I get java.lang.RuntimeException: getParameters failed (empty parameters) on some devices?

Tell me why I get an error on some devices java.lang.RuntimeException: getParameters failed (empty parameters)?

public class CameraPreview extends SurfaceView implements
        Callback {

    private static final String TAG = "CameraPreview";
    SurfaceHolder mHolder;
    Camera mCamera;
    Context mContext;

    @SuppressWarnings("deprecation")
    public CameraPreview(Context context, Camera camera) {
        super(context);
        mContext = context;
        mCamera = camera;
        mHolder = getHolder();
        mHolder.addCallback(this);

        // deprecated setting, but required on Android versions prior to 3.0
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        if (mHolder.getSurface() == null)
            return;

        mCamera.stopPreview();

        setCameraDisplayOrientation();

        try {
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();
        } catch (IOException e) {
            Toast.makeText(mContext, "Camera preview2 failed", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        } catch (IOException e) {
            Toast.makeText(mContext, "Camera preview3 failed", Toast.LENGTH_LONG).show();
        }
    }

    public void setCameraDisplayOrientation()
    {
        if (mCamera == null)
            return;


        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(0, info);
        Camera.Parameters parameters = mCamera.getParameters();

        WindowManager winManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        int rotation = winManager.getDefaultDisplay().getRotation();

        int degrees = 0;

        switch (rotation) {
            case Surface.ROTATION_0: degrees = 0; break;
            case Surface.ROTATION_90: degrees = 90; break;
            case Surface.ROTATION_180: degrees = 180; break;
            case Surface.ROTATION_270: degrees = 270; break;
        }

        int result;
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
        {
            result = (info.orientation + degrees) % 360;
            result = (360 - result) % 360;  // + зеркало
        } else {
            result = (info.orientation - degrees + 360) % 360;
        }

        mCamera.setDisplayOrientation(result);

        int rotate = (degrees + 270) % 360;
        parameters.setRotation(rotate);
        mCamera.setParameters(parameters);
    }


    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        //this.getHolder().removeCallback(this);
//        mCamera.stopPreview();


        // Surface will be destroyed when we return, so stop the preview.
        if (mCamera != null) {
            // Call stopPreview() to stop updating the preview surface.
            mCamera.stopPreview();
        }

    }

}

ERROR:
08-23 14:30:01.792 3716-3844/? E/CameraService: setCompanionDisableSysFs : cc.disable property set to 0
08-23 14:30:01.795 3716-3844/? E/SecCameraCoreManager: initialize1
08-23 14:30:01.795 3716-3844/? E/ExynosCamera: Build Date is (__DATE__) (__TIME__)
08-23 14:30:01.803 3716-3844/? E/SecCameraCoreManager: initialize2
08-23 14:30:01.878 3716-3716/? E/SecCameraCoreManager: checkTemperature (0)
08-23 14:30:01.888 3716-4891/? E/ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_alloc[1945]):m_reqBufCount(12)
08-23 14:30:02.259 3716-5047/? E/ExynosCameraNode: [CAM_ID(0)][3AA_OUTPUT]-ERR(m_dqBuf):exynos_v4l2_dqbuf(fd:72) fail (-1)
08-23 14:30:02.259 3716-5047/? E/ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[1942]):node(3AA_OUTPUT)->getBuffer() fail, index(-2), frameCount(0), ret(-1)
08-23 14:30:02.259 3716-5047/? E/ExynosCameraNode: [CAM_ID(0)][SCP_PREVIEW]-ERR(m_polling):poll[74], pollRet(1) event(0x8), cnt(-1)
    [CAM_ID(0)][SCP_PREVIEW]-ERR(polling):m_polling fail
08-23 14:30:02.259 3716-5047/? E/ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_checkPolling[3653]):polling fail, ret(-38)
    [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[2062]):m_checkPolling fail, frameCount(0), ret(-1001)
08-23 14:30:02.259 3716-5047/? E/ExynosCameraNode: [CAM_ID(0)][SCP_PREVIEW]-ERR(getBuffer[1004]):m_nodeState = [4] is not valid
08-23 14:30:02.259 3716-5047/? E/ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[2074]):node(SCP_PREVIEW)->getBuffer() fail, index(-2), frameCount(0), ret(-38)
08-23 14:30:02.260 3716-5047/? E/ExynosCameraNode: [CAM_ID(0)][3AA_CAPTURE]-ERR(getBuffer[1004]):m_nodeState = [4] is not valid
08-23 14:30:02.260 3716-5047/? E/ExynosCameraMCPipe: [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[2074]):node(3AA_CAPTURE)->getBuffer() fail, index(-2), frameCount(0), ret(-38)
    [CAM_ID(0)][PIPE_3AA]-ERR(m_getBuffer[2196]):frameCount(0)                    : captureNodeCount == 0 || checkRet(-1) != NO_ERROR.                    so, setFrameState(FRAME_STATE_SKIPPED)
08-23 14:30:02.303 3716-3844/? E/SecCameraCoreManager: checkTemperature (0)
08-23 14:30:02.308 3716-5064/? E/ExynosCameraBufferManager: [CAM_ID(0)][SCP_BUF]-ERR(m_alloc[1945]):m_reqBufCount(12)
08-23 14:30:02.375 3716-3716/? E/CameraClient: attempt to use a camera after disconnect() (pid 4549)
08-23 14:30:02.385 3716-4557/? E/CameraClient: attempt to use a camera after disconnect() (pid 4549)
08-23 14:30:02.386 3716-3716/? E/CameraClient: attempt to use a camera after disconnect() (pid 4549)
08-23 14:30:02.512 3716-5134/? E/ExynosCamera: [CAM_ID(0)][]-ERR(m_frameFactoryInitThreadFunc[2624]):wait and pop fail, ret(-110)
08-23 14:30:02.560 4549-4549/com.yauheni.kebab E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yauheni.kebab, PID: 4549
    java.lang.RuntimeException: getParameters failed (empty parameters)
        at android.hardware.Camera.native_getParameters(Native Method)
        at android.hardware.Camera.getParameters(Camera.java:1952)
        at com.yauheni.kebab.camera.CameraPreview.setCameraDisplayOrientation(CameraPreview.java:71)
        at com.yauheni.kebab.camera.CameraPreview.surfaceChanged(CameraPreview.java:43)
        at android.view.SurfaceView.updateWindow(SurfaceView.java:668)
        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2542)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
        at android.view.Choreographer.doCallbacks(Choreographer.java:734)
        at android.view.Choreographer.doFrame(Choreographer.java:670)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question