views:

489

answers:

1

On Motorola Droid, Firmware 2.1-update1, Kernel 2.9.29-omap1, Build # ESE81

When attempting to take a picture, mediaserver dies with a segmentation fault.

I've tried putting takePicture in a timer and running it a few seconds after camera initialization to check for race conditions, but no change. Just calling Camera.open() doesn't cause the crash. Also, calling Camera.open() causes what I think is the autofocus motor to make a sort of ticking sound.

Code that breaks:

import android.app.Activity;
import android.os.Bundle;

public final class ChopperMain extends Activity {
    public void onCreate(Bundle savedInstanceState) {
    try {
        Camera camera = Camera.open();
        catch (Exception e) {
            e.printStackTrace();
        }
        camera.takePicture(
                new Camera.ShutterCallback() {
                    public void onShutter() {
                        ;
                    }
                }, 
                new Camera.PictureCallback() {
                    public void onPictureTaken(byte[] data, Camera camera) {
                        ;
                    }
                },
                new Camera.PictureCallback() {
                    public void onPictureTaken(byte[] data, Camera camera) {
                        ;
                    }
                },
            new PictureCallback() {
                public void onPictureTaken(byte[] data, Camera camera) {
                    System.out.println("Ta da.");
                }
            }
        });

    }
    catch (Exception e) {
        e.printStackTrace();
    }
    }
}

Debug Log:

D/CameraHal(10158): CameraSettings constructor
D/CameraHal(10158): CameraHal constructor
D/CameraHal(10158): Model ID: Droid
D/CameraHal(10158): Software ID 2.1-update1
D/dalvikvm(  988): GC freed 2 objects / 56 bytes in 215ms
D/ViewFlipper( 1074): updateRunning() mVisible=false, mStarted=true, mUserPresent=false, mRunning=false
I/HPAndroidHAL(10158): Version 2988.  Build Time: Oct 26 2009:11:21:55.
D/CameraHal(10158): 19 default parameters
D/CameraHal(10158): Immediate Zoom/1:0. Current zoom level/1:0
D/CameraHal(10158): CameraHal constructor exited ok
D/CameraService(10158): Client::Client X (pid 10400)
D/CameraService(10158): CameraService::connect X
D/CameraService(10158): takePicture (pid 10400)
I/DEBUG   (10159): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (10159): Build fingerprint: 'verizon/voles/sholes/sholes:2.1-update1/ESE81/29593:user/release-keys'
I/DEBUG   (10159): pid: 10158, tid: 10158  >>> /system/bin/mediaserver <<<
I/DEBUG   (10159): signal 11 (SIGSEGV), fault addr 00000008
I/DEBUG   (10159):  r0 00000000  r1 00000000  r2 a969030c  r3 a9d1bfe0
I/DEBUG   (10159):  r4 00045eb0  r5 0000eb10  r6 000153a0  r7 a9c89fd2
I/DEBUG   (10159):  r8 00000000  r9 00000000  10 00000000  fp 00000000
I/DEBUG   (10159):  ip a969085c  sp bec4fba0  lr a9689c65  pc a9d1bfde  cpsr 60000030
I/DEBUG   (10159):          #00  pc 0001bfde  /system/lib/libutils.so
I/DEBUG   (10159):          #01  pc 00009c62  /system/lib/libcamera.so
I/DEBUG   (10159):          #02  pc 00007b0c  /system/lib/libcameraservice.so
I/DEBUG   (10159):          #03  pc 00021f98  /system/lib/libui.so
I/DEBUG   (10159):          #04  pc 00015514  /system/lib/libbinder.so
I/DEBUG   (10159):          #05  pc 00018dd8  /system/lib/libbinder.so
I/DEBUG   (10159):          #06  pc 00018fa6  /system/lib/libbinder.so
I/DEBUG   (10159):          #07  pc 000087d2  /system/bin/mediaserver
I/DEBUG   (10159):          #08  pc 0000c228  /system/lib/libc.so
I/DEBUG   (10159): 
I/DEBUG   (10159): code around pc:
I/DEBUG   (10159): a9d1bfcc bd1061e3 f7f3b510 bd10e97e 4d17b570 
I/DEBUG   (10159): a9d1bfdc 6886a300 460418ed fff4f7ff d10a4286 
I/DEBUG   (10159): a9d1bfec 46234913 20054a13 f06f1869 18aa040a 
I/DEBUG   (10159): 
I/DEBUG   (10159): code around lr:
I/DEBUG   (10159): a9689c54 e0240412 0204f8d0 050cf104 edf0f7fd 
I/DEBUG   (10159): a9689c64 f7fd4628 f8d4ecf2 b1533204 f852681a 
I/DEBUG   (10159): a9689c74 18581c0c 7101f504 ed82f7fd f8c42000 
I/DEBUG   (10159): 
I/DEBUG   (10159): stack:
I/DEBUG   (10159):     bec4fb60  4000902c  /dev/binder
I/DEBUG   (10159):     bec4fb64  a9d19675  /system/lib/libutils.so
I/DEBUG   (10159):     bec4fb68  00002bb4  
I/DEBUG   (10159):     bec4fb6c  a9d1b26f  /system/lib/libutils.so
I/DEBUG   (10159):     bec4fb70  bec4fbbc  [stack]
I/DEBUG   (10159):     bec4fb74  00095080  [heap]
I/DEBUG   (10159):     bec4fb78  a9c8c028  /system/lib/libcameraservice.so
I/DEBUG   (10159):     bec4fb7c  a9c8c028  /system/lib/libcameraservice.so
I/DEBUG   (10159):     bec4fb80  00015390  [heap]
I/DEBUG   (10159):     bec4fb84  a9c89fd2  /system/lib/libcameraservice.so
I/DEBUG   (10159):     bec4fb88  00045ebc  [heap]
I/DEBUG   (10159):     bec4fb8c  afe0f110  /system/lib/libc.so
I/DEBUG   (10159):     bec4fb90  00000000  
I/DEBUG   (10159):     bec4fb94  afe0f028  /system/lib/libc.so
I/DEBUG   (10159):     bec4fb98  df002777  
I/DEBUG   (10159):     bec4fb9c  e3a070ad  
I/DEBUG   (10159): #00 bec4fba0  00045eb0  [heap]
I/DEBUG   (10159):     bec4fba4  00045ebc  [heap]
I/DEBUG   (10159):     bec4fba8  000153a0  [heap]
I/DEBUG   (10159):     bec4fbac  a9689c65  /system/lib/libcamera.so
I/DEBUG   (10159): #01 bec4fbb0  a9c8c028  /system/lib/libcameraservice.so
I/DEBUG   (10159):     bec4fbb4  00015390  [heap]
I/DEBUG   (10159):     bec4fbb8  000153a0  [heap]
I/DEBUG   (10159):     bec4fbbc  a9c87b0f  /system/lib/libcameraservice.so
I/DEBUG   (10159): debuggerd committing suicide to free the zombie!
I/DEBUG   (10426): debuggerd: Mar 22 2010 17:31:05
W/MediaPlayer( 1021): MediaPlayer server died!
I/ServiceManager(  984): service 'media.audio_flinger' died
I/ServiceManager(  984): service 'media.player' died
I/ServiceManager(  984): service 'media.camera' died
I/ServiceManager(  984): service 'media.audio_policy' died
W/Camera  (10400): Camera server died!
W/Camera  (10400): ICamera died
E/Camera  (10400): Error 100
I/System.out(10400): Camera error, code 100
W/AudioSystem( 1021): AudioFlinger server died!
W/AudioSystem( 1021): AudioPolicyService server died!
I/        (10425): ServiceManager: 0xad08
E/AudioPostProcessor(10425): 
E/AudioPostProcessor(10425): AudioMgr Error:Failed to open gains file /data/ap_gain.bin
E/AudioPostProcessor(10425): 
E/AudioPostProcessor(10425): AudioMgr Error:Failed to  read gains/coeffs from /data 
E/AudioPostProcessor(10425): Audio coeffs init success. 
I/CameraService(10425): CameraService started: pid=10425
D/Audio_Unsolicited(10425): in readyToRun
D/Audio_Unsolicited(10425): Create socket successful 10 
I/AudioFlinger(10425): AudioFlinger's thread 0x11c30 ready to run
E/AudioService( 1021): Media server died.
E/AudioService( 1021): Media server started.
W/AudioPolicyManager(10425): setPhoneState() setting same state 0
+1  A: 

You are missing most of the code necessary to work with a Camera. Here is a sample project that is more complete.

CommonsWare
I think by "incomplete" you're referring to the absence of preview code? I don't actually need any kind of preview for my project, or even to save it to file--I just need to keep it in memory. Is there a way to safely work with the camera without setting up a preview? Given that I don't actually need it, it seems like a lot of overhead.
SirBoss
AFAIK, you need the preview -- it's a requirement for privacy reasons. But I also was referring to setting up the camera parameters (image format, image size, etc.), which the code you have above lacks.
CommonsWare
I did some testing--it looks like you don't need to set parameters (it uses default values if you don't), but you're right about the preview. Thanks!
SirBoss
Good to know that the defaults work OK, and good to know that you got your stuff running.
CommonsWare