Lollipop Camera

789 views
Skip to first unread message

Edgardo Gho

unread,
Apr 17, 2015, 2:00:53 PM4/17/15
to andro...@googlegroups.com
I'm trying to figure out why the camera app crashes on lollipop.

I used a WebRTC app and I was able to access the camera on the browser (this would discard any issue with uvc or usb since this is a usb webcam). I notice that it uses libcamera (on /hardware/libcamera). 

When I try to use the Camera2 App, it crashes. I used a Camera2 example app (so I can debug line by line using Android Studio) and I notice it crashed on frameworks/base/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java.
Apparently it is trying to read the focal-length but the parameters reported by the camera do not provide that so it crashes. I added that parameter (along with 2 other parameters that crashed after that) on the java side. Camera won't crash anymore but it is failing to init the image surface and I get an EGL error.

Did someone manage to get any further with the camera? 

Edgardo Gho

unread,
Apr 17, 2015, 4:43:09 PM4/17/15
to andro...@googlegroups.com
I'm a little confuses about the structure of the build directory.
On one side it has: /hardware/libcamera. This includes the CameraHAL.cpp but seems to be really old (reports API version 1).
On the other side, it has /hardware/libhardware/modules/camera which also includes a newer CameraHAL.cpp, which should be more compatible with Camera2.
When the CameraService starts, it picks up camera.x86.so on /system/lib/hw , instead of using camera.default.so (which can be mm on libhardware).

Is /hardware/libcamera something left in the manifest by error?

Chih-Wei Huang

unread,
Apr 17, 2015, 9:14:13 PM4/17/15
to Android-x86

The hardware/libhardware/modules/camera is a reference code.
I don't think it contains any specific code to support the usb camera.
But you can try it by

setprop ro.hardware.camera default

Then

stop; start

It's right the code in hardware/libcamera is quite old.
(probably no update since ics-x86)
Contributions are welcome.

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-x86.
For more options, visit https://groups.google.com/d/optout.

Edgardo Gho

unread,
Apr 20, 2015, 4:11:16 PM4/20/15
to andro...@googlegroups.com


I got some progress with the camera. I will upload the patch as soon as I make it work. The problem I have right now is this:
D/CameraHardware( 1660): CameraHardware::pictureThread: picture taken
D/CameraHardware( 1660): CameraHardware::pictureThread: took jpeg picture compressed to 67881 bytes, q=90
D/CameraHardware( 1660): Sending the Shutter message
D/CameraHardware( 1660): CameraHardware::disableMsgType: 2
D/CameraHardware( 1660): Sending the jpeg message
D/CameraHardware( 1660): CameraHardware::disableMsgType: 256
D/CameraHardware( 1660): CameraHardware::pictureThread OK
I/RequestThread-0( 2923): Received jpeg.
I/RequestThread-0( 2923): Producing jpeg buffer...
E/GRALLOC-DRM( 2923): bo.usage:x3/usage:x30 is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE
W/GraphicBufferMapper( 2923): lock(...) failed -22 (Invalid argument)
E/Legacy-CameraDevice-JNI( 2923): produceFrame: Failed to lock buffer, error Invalid argument (-22).
E/Legacy-CameraDevice-JNI( 2923): LegacyCameraDevice_nativeProduceFrame: Error while producing frame Invalid argument (-22).
E/AndroidRuntime( 2923): FATAL EXCEPTION: Thread-212
E/AndroidRuntime( 2923): Process: com.android.camera2, PID: 2923
E/AndroidRuntime( 2923): java.lang.UnsupportedOperationException: Unknown error -22
E/AndroidRuntime( 2923): at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:69)
E/AndroidRuntime( 2923): at android.hardware.camera2.legacy.LegacyCameraDevice.produceFrame(LegacyCameraDevice.java:516)
E/AndroidRuntime( 2923): at android.hardware.camera2.legacy.RequestThreadManager$2.onPictureTaken(RequestThreadManager.java:224)
E/AndroidRuntime( 2923): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1094)
E/AndroidRuntime( 2923): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2923): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2923): at android.hardware.camera2.legacy.CameraDeviceUserShim$CameraLooper.run(CameraDeviceUserShim.java:144)
E/AndroidRuntime( 2923): at java.lang.Thread.run(Thread.java:818)
W/ActivityManager( 1934):   Force finishing activity com.android.camera2/com.android.camera.CameraLauncher
D/PermissionCache( 1677): checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (73 us)
I/InputDispatcher( 1934): Dropping event because there is no touchable window at (876, 386).
I/InputDispatcher( 1934): Dropping event because there is no touchable window at (877, 387).
I/InputDispatcher( 1934): Dropping event because there is no touchable window at (878, 388).
D/KbdSensor( 1934): poll_setDelay: dev=0xb4556f80 delay-ns=66667000
I/CAM_PhotoModule( 2923): stopPreview
I/RequestQueue( 2923): Repeating capture request cancelled.
I/InputDispatcher( 1934): Dropping event because there is no touchable window at (879, 389).
D/KbdSensor( 1934): poll_setDelay: dev=0xb4556f80 delay-ns=66667000
I/RequestThread-0( 2923): Flushing all pending requests.
E/RequestQueue( 2923): cancel failed: no repeating request exists.
D/OpenGLRenderer( 1934): Render dirty regions requested: true
I/OpenGLRenderer( 1934): Initialized EGL, version 1.4
W/OpenGLRenderer( 1934): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer( 1934): Enabling debug mode 0

I'm a little lost of how to solve this:
E/GRALLOC-DRM( 2923): bo.usage:x3/usage:x30 is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE

The problem with the CameraHAL was that some values were not being reported. I faked those values adding:
// Missing parameters for Camera2
p.set(CameraParameters::KEY_FOCAL_LENGTH,4.31);
p.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE,90);
p.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE,90);
p.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES,"640x480,320x240,0x0");
On file: hardware/libcamera/CameraHardware.cpp:961

The camera.x86.so can then be transfer to /system/lib/hw and it won't crash during Camera2 startup.
It does crash later on trying to config EGL14.
This requires removing a parameter from the egl configuration code at file: frameworks/base/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer:370

        int[] attribList = {
                EGL14.EGL_RED_SIZE, EGL_COLOR_BITLENGTH,
                EGL14.EGL_GREEN_SIZE, EGL_COLOR_BITLENGTH,
                EGL14.EGL_BLUE_SIZE, EGL_COLOR_BITLENGTH,
                EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
                //EGL_RECORDABLE_ANDROID, 1,
                EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT | EGL14.EGL_WINDOW_BIT,
                EGL14.EGL_NONE
        };

I commented it out so that the line number of the file remains the same and I can debug it with Android Studio.


Edgardo Gho

unread,
Apr 20, 2015, 5:23:33 PM4/20/15
to andro...@googlegroups.com
Interesting...
If I start with nomodeset , Camera shows the preview image (only one frame) and then it becomes unusable.
But I get at least one frame out of it.

pstglia

unread,
Apr 20, 2015, 6:35:05 PM4/20/15
to andro...@googlegroups.com
Hi Edgardo,

I've taken a quick look. Not sure if it will work, but you can try if you wish:



I'm a little lost of how to solve this:
E/GRALLOC-DRM( 2923): bo.usage:x3/usage:x30 is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE

According to your logcat, this drm gralloc msg (see hardware/drm_gralloc/gralloc_drm.c) was returned when trying to lock a buffer on function/method "produceFrame" inside  frameworks/base/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp:

           err = buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
            if (err != NO_ERROR) {
                ALOGE("%s: Failed to lock buffer, error %s (%d).", __FUNCTION__, strerror(-err),
                        err);
                return err;
            }

This call is just passing GRALLOC_USAGE_SW_WRITE_OFTEN flags, and gralloc expects "GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE" as error msg says.

You could try to add "GRALLOC_USAGE_HW_FB" usage flag. Something like this:

            err = buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_FB, (void**)(&img));
            if (err != NO_ERROR) {
                ALOGE("%s: Failed to lock buffer, error %s (%d).", __FUNCTION__, strerror(-err),
                        err);
                return err;
            }


Good luck!

pstglia 

Edgardo Gho

unread,
Apr 21, 2015, 10:30:42 AM4/21/15
to andro...@googlegroups.com
Thanks for the info.
It did partially worked. I'm able to take picture with the cam, but the preview mode does not work. So I can press the shutter and it takes the picture, but I don't see anything before that.
Also video mode crashes.
I think the problem is on how the camera is setup when doing preview (it tries to use YUVY and I don't know if the crappy cam that I have supports that). When its taking the picture it puts the camera in JPEG mode and there it seems to work.

I'll look into it a little more and I'll post a patch. I did modify part of the framework/base/core and I really don't want to do this, so I'll see if I can trick EGL14 into ignoring EGL_RECORDABLE_ANDROID which I believe is more cleaner.

Edgardo Gho

unread,
Apr 22, 2015, 2:00:39 AM4/22/15
to andro...@googlegroups.com

I got the camera app working using https://github.com/maurossi/mesa/tree/lollipop-x86_multiarch
Preview mode works fine.
With the previous Mesa I got the camera to take pictures but could not see preview and video crash.
Video works now. I had to set the cam to CIF to make it work.
I recorded a video with sound. But I could not play it. I get a black screen playing videos (same thing using youtube).
Is there any way to fix this?.

I'll cleanup my patches and post them.

Edgardo Gho

unread,
Apr 22, 2015, 12:16:34 PM4/22/15
to andro...@googlegroups.com

Here are the 3 patches needed. It is a simple modification. The CameraHardware Patch adds 3 missing settings to the camera hal. I don't know if other cameras report these values. Mine is a cheap usb2.0 webcam and did not so I hard-coded those values.
The Gralloc Patch allows the camera to get a lock on the buffer. This is required when a picture is taken.
The Egl_patch will accept: private static final int EGL_RECORDABLE_ANDROID = 0x3142; // from EGL/eglext.h
This value is used by SurfaceTextureRenderer.java to init EGL. I tried on Mauro Rossi Mesa and it works. On older mesa it is necessary but it won't display the preview mode. Picture taking works.

CameraHardware_patch.txt
Egl_patch.txt
Gralloc_patch.txt

Chih-Wei Huang

unread,
Apr 24, 2015, 6:08:20 AM4/24/15
to Android-x86
Thank you for the patches.

The CameraHardware patch is merged.

For gralloc patch, I think the following change is enough
(and simpler)?

diff --git a/gralloc_drm.c b/gralloc_drm.c
index 0f1ce72..3478dde 100644
--- a/gralloc_drm.c
+++ b/gralloc_drm.c
@@ -398,8 +398,9 @@ int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo,
if ((bo->handle->usage & usage) != usage) {
/* make FB special for testing software renderer with */

- if (!(bo->handle->usage & GRALLOC_USAGE_HW_FB)
- && !(bo->handle->usage & GRALLOC_USAGE_HW_TEXTURE)) {
+ if (!(bo->handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) &&
+ !(bo->handle->usage & GRALLOC_USAGE_HW_FB) &&
+ !(bo->handle->usage &
GRALLOC_USAGE_HW_TEXTURE)) {
ALOGE("bo.usage:x%X/usage:x%X is not
GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE"
,bo->handle->usage,usage);
return -EINVAL;

For the mesa egl patch, I think it's better to add
EGL_RECORDABLE_ANDROID to _eglOffsetOfConfig
of src/egl/main/eglconfig.h.

Could you please create the patch by git format-patch
next time? That would make me merge the patch easier.
(search the forum for details)
> --
> You received this message because you are subscribed to the Google Groups
> "Android-x86" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-x86...@googlegroups.com.
> To post to this group, send email to andro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/android-x86.
> For more options, visit https://groups.google.com/d/optout.



--
Chih-Wei
Android-x86 project
http://www.android-x86.org

Edgardo Gho

unread,
May 14, 2015, 11:36:24 AM5/14/15
to andro...@googlegroups.com
I've tried the patch on my latest build and I think this is needed on gralloc:
!(bo->handle->usage & GRALLOC_USAGE_SW_WRITE_OFTEN) && 
I'll try to come up with a git patch for it.

Chih-Wei Huang

unread,
May 14, 2015, 12:12:54 PM5/14/15
to Android-x86
Actually I have applied my patch to lollipop-x86.
It works for me.
Thank you for the effort to fix it.

2015-05-14 23:36 GMT+08:00 Edgardo Gho <edgar...@gmail.com>:
> I've tried the patch on my latest build and I think this is needed on
> gralloc:
> !(bo->handle->usage & GRALLOC_USAGE_SW_WRITE_OFTEN) &&
> I'll try to come up with a git patch for it.



Reply all
Reply to author
Forward
0 new messages