The Problem:
In using the camera on the device, I'm getting a number of errors. I have looked over many answers here on StackOverflow and I have tried many solutions to no avail. I'm not sure what the problem is. I have tried this on two different devices and I'm getting the same errors. This is failing on multiple devices... Samsung Galaxy S7 and a Vankyo Z4 Tablet. The logs are from the tablet.
2020-01-27 06:51:43.571 4182-4182/ W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2020-01-27 06:51:43.649 4182-4182/ D/OpenGLRenderer: Skia GL Pipeline
2020-01-27 06:51:44.474 4182-4182/ E/Camera: Error 2
2020-01-27 06:51:44.600 4182-4262/ I/mali_so: [File] : hardware/rockchip/mali_so_src_of_midgard/driver/product/base/src/mali_base_kbase.c; [Line] : 1095; [Func] : base_context_deal_with_version_affairs_rk_ext;
arm_release_ver of this mali_so is 'r12p0-01rel0', rk_so_ver is '9@0 '.
2020-01-27 06:51:44.600 4182-4262/ I/mali_so: [File] : hardware/rockchip/mali_so_src_of_midgard/driver/product/base/src/mali_base_kbase.c; [Line] : 1101; [Func] : base_context_deal_with_version_affairs_rk_ext;
mali_ver_property has been set to 'r12p0-01rel0-x-9@0', to return.
2020-01-27 06:51:44.601 4182-4262/ I/mali_so: [File] : hardware/rockchip/mali_so_src_of_midgard/driver/product/cmem/src/mali_cmem_hoard.c; [Line] : 559; [Func] : should_current_process_not_to_use_hoard;
WOULD use hoard.
2020-01-27 06:51:44.617 4182-4262/ I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2020-01-27 06:51:44.618 4182-4262/ I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2020-01-27 06:51:44.618 4182-4262/ I/OpenGLRenderer: Initialized EGL, version 1.4
2020-01-27 06:51:44.618 4182-4262/ D/OpenGLRenderer: Swap behavior 2
2020-01-27 06:51:44.648 4182-4262/ D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-01-27 06:51:44.670 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:51:44.674 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:51:44.675 4182-4182/ D/Camera: setDisplayOrientation Failed: set display orientation failed
2020-01-27 06:51:44.677 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:51:45.630 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:51:45.818 4182-4182/ I/Choreographer: Skipped 76 frames! The application may be doing too much work on its main thread.
2020-01-27 06:51:46.014 4182-4262/ D/GRALLOC-ROCKCHIP: RK_GRAPHICS_VER=commit-id:69cd12f
2020-01-27 06:51:46.464 4182-4262/ I/OpenGLRenderer: Davey! duration=1946ms; Flags=1, IntendedVsync=15482245744667, Vsync=15483533880219, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15483548307810, AnimationStart=15483548629227, PerformTraversalsStart=15483550124019, DrawStart=15483591003440, SyncQueued=15483639373153, SyncStart=15483640225986, IssueDrawCommandsStart=15483711543452, SwapBuffers=15484188006958, FrameCompleted=15484193184333, DequeueBufferDuration=14675000, QueueBufferDuration=3065000,
2020-01-27 06:51:46.491 4182-4182/ I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
2020-01-27 06:51:46.539 4182-4262/ I/OpenGLRenderer: Davey! duration=709ms; Flags=0, IntendedVsync=15483558409277, Vsync=15484219426205, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15484220349586, AnimationStart=15484220561045, PerformTraversalsStart=15484222148003, DrawStart=15484224182962, SyncQueued=15484224448962, SyncStart=15484224914753, IssueDrawCommandsStart=15484225396878, SwapBuffers=15484260477090, FrameCompleted=15484268449216, DequeueBufferDuration=11816000, QueueBufferDuration=3806000,
2020-01-27 06:53:10.381 4182-4262/ W/libEGL: EGLNativeWindowType 0xee0ea008 disconnect failed
2020-01-27 06:53:11.199 4182-4182/ I/Choreographer: Skipped 49 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:11.283 4182-4262/ D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-01-27 06:53:11.363 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:11.368 4182-4182/ D/Camera: Rotate 0
2020-01-27 06:53:11.369 4182-4182/ D/Camera: setDisplayOrientation Failed: set display orientation failed
2020-01-27 06:53:11.371 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:12.680 4182-4182/ D/Camera: Rotate 0
2020-01-27 06:53:12.691 4182-4182/ E/Camera: Error 2
2020-01-27 06:53:12.729 4182-4182/ I/Choreographer: Skipped 87 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:12.851 4182-4262/ I/OpenGLRenderer: Davey! duration=1608ms; Flags=1, IntendedVsync=15568971643421, Vsync=15570446219645, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15570459148001, AnimationStart=15570459500626, PerformTraversalsStart=15570461186751, DrawStart=15570496844172, SyncQueued=15570546182510, SyncStart=15570546388427, IssueDrawCommandsStart=15570562532470, SwapBuffers=15570576764930, FrameCompleted=15570579908513, DequeueBufferDuration=7076000, QueueBufferDuration=956000,
2020-01-27 06:53:35.328 4182-4262/ W/libEGL: EGLNativeWindowType 0xd48dd008 disconnect failed
2020-01-27 06:53:36.017 4182-4182/ I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:36.096 4182-4262/ D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-01-27 06:53:36.175 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:36.178 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:53:36.179 4182-4182/ D/Camera: setDisplayOrientation Failed: set display orientation failed
2020-01-27 06:53:36.181 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:36.978 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:53:36.990 4182-4182/ E/Camera: Error 2
2020-01-27 06:53:37.040 4182-4182/ I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:37.160 4182-4262/ I/OpenGLRenderer: Davey! duration=1105ms; Flags=1, IntendedVsync=15593784036511, Vsync=15594767087327, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15594770152361, AnimationStart=15594770423902, PerformTraversalsStart=15594772051694, DrawStart=15594807059573, SyncQueued=15594846584202, SyncStart=15594846778160, IssueDrawCommandsStart=15594869251079, SwapBuffers=15594887089997, FrameCompleted=15594889647331, DequeueBufferDuration=7349000, QueueBufferDuration=1031000,
2020-01-27 06:53:51.816 4182-4262/ W/libEGL: EGLNativeWindowType 0xd48dd008 disconnect failed
2020-01-27 06:53:52.497 4182-4182/ I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:52.568 4182-4262/ D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-01-27 06:53:52.655 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:52.659 4182-4182/ D/Camera: Rotate 0
2020-01-27 06:53:52.660 4182-4182/ D/Camera: setDisplayOrientation Failed: set display orientation failed
2020-01-27 06:53:52.661 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:53:53.166 4182-4182/ D/Camera: Rotate 0
2020-01-27 06:53:53.174 4182-4182/ E/Camera: Error 2
2020-01-27 06:53:53.209 4182-4182/ I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
2020-01-27 06:53:53.333 4182-4262/ I/OpenGLRenderer: Davey! duration=781ms; Flags=1, IntendedVsync=15610280644733, Vsync=15610924712509, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15610938505568, AnimationStart=15610938769527, PerformTraversalsStart=15610940187027, DrawStart=15610980021989, SyncQueued=15611021218452, SyncStart=15611021401618, IssueDrawCommandsStart=15611042124829, SwapBuffers=15611058239997, FrameCompleted=15611062475581, DequeueBufferDuration=8643000, QueueBufferDuration=1439000,
2020-01-27 06:54:33.415 4182-4262/ W/libEGL: EGLNativeWindowType 0xd48dd008 disconnect failed
2020-01-27 06:54:34.104 4182-4182/ I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
2020-01-27 06:54:34.172 4182-4262/ D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2020-01-27 06:54:34.250 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:54:34.252 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:54:34.254 4182-4182/ D/Camera: setDisplayOrientation Failed: set display orientation failed
2020-01-27 06:54:34.256 4182-4182/ D/Camera: setPreviewTexture failed
2020-01-27 06:54:34.761 4182-4182/ D/Camera: Rotate 270
2020-01-27 06:54:34.774 4182-4182/ E/Camera: Error 2
2020-01-27 06:54:34.805 4182-4182/ I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
2020-01-27 06:54:34.942 4182-4262/ I/OpenGLRenderer: Davey! duration=794ms; Flags=1, IntendedVsync=15651876176648, Vsync=15652520244424, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15652534305206, AnimationStart=15652534506748, PerformTraversalsStart=15652537321040, DrawStart=15652583784419, SyncQueued=15652629034174, SyncStart=15652629455049, IssueDrawCommandsStart=15652650115843, SwapBuffers=15652667089970, FrameCompleted=15652670663762, DequeueBufferDuration=9324000, QueueBufferDuration=1607000,
2020-01-27 07:03:10.639 4182-4262/ W/libEGL: EGLNativeWindowType 0xd48dd008 disconnect failed
As can be seen from the log, when the orientation changes, surfaceChanged callback gets called twice. The first time, I get the setDisplayOrientation failed. I'm not sure why I'm getting setPreviewTexture failed because I'm not even using TextureView. I also don't know why I'm getting Error 2 for the camera either. I have tried several solutions that I found here and elsewhere to no avail. Here's the code in question:
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Display display;
int rotation;
int degrees = 0;
int result;
// If the holder is null, then just return.
if (mHolder.getSurface() == null) {
return;
}
// Stop the preview.
try {
if (isPreviewRunning) {
mCamera.stopPreview();
isPreviewRunning = false;
}
} catch (Exception e) {
Log.d("Camera", "Stop Preview Failed: " + e.getMessage());
}
// Check the device orientation.
display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
rotation = display.getRotation();
switch (rotation) {
case Surface.ROTATION_0:
Log.d("Camera", "Rotate 0");
degrees = 0;
break;
case Surface.ROTATION_90:
Log.d("Camera", "Rotate 90");
degrees = 90;
break;
case Surface.ROTATION_180:
Log.d("Camera", "Rotate 180");
degrees = 180;
break;
case Surface.ROTATION_270:
Log.d("Camera", "Rotate 270");
degrees = 270;
break;
}
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (cameraInfo.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (cameraInfo.orientation - degrees + 360) % 360;
}
// Not sure why this fails. No reason given.
try {
mCamera.setDisplayOrientation(result);
} catch (Exception e) {
Log.d("Camera", "setDisplayOrientation Failed: " + e.getMessage());
}
// Restart the preview with the new changes.
try {
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
isPreviewRunning = true;
} catch (IOException e) {
Log.d("Camera", e.getMessage());
}
}
Despite the errors, it does work. So should I just ignore the errors or continue to try to fix them? I am writing for API level 19. I know that Camera was depreciated in API 21, but older devices are still out there and I want this code to run on those as well. As for the research, there seems to be two main solutions. I have tried both and they do not work. The one with the getParameters is telling me that getParameters failed that it returned null, which should not happen, but it does.
Research:
As for the research that I have done trying to fix this problem...
https://www.codeproject.com/Questions/626862/Android-Camera-setDisplayOrientation-Failed
Textureview/Surface view for Camera preview - Android
Problem with camera when orientation changes
Android Camera setDisplayOrientation does not work
android camera setDisplayOrientation(90) fails in different devices