Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

takePicture fails with heap related error

First things first: the following error occurs on 2 different HTC Desires, one with 2.3.3, one with 4.0.4.

I get the following error messages when trying to call .takePicture:

E/MemoryHeapBase(104): error opening /dev/pmem_camera: No such file or directory
E/QualcommCameraHardware(104): failed to construct master heap for pmem pool /dev/pmem_camera
E/QualcommCameraHardware(104): initSnapshot X failed with pmem_camera, trying with pmem_adsp

the corresponding PictureCallback is never invoked after this error.

The only explanations I could find were a) startPreview wasn't called; b) trying to take pictures too fast (before the picture callback was invoked); c) not setting the correct uses/permissions

I do a) here, in onResume() of my FullscreenActivity:

//open the camera resource
cam = Camera.open();

Camera.Parameters params = cam.getParameters();
//change Parameters
params.setJpegQuality(100);//best quality
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
//params.setZoom(2);
List<Size> supportedPreviewSizes = cam.getParameters().getSupportedPreviewSizes();
params.setPreviewSize(supportedPreviewSizes.get(0).width, supportedPreviewSizes.get(0).height);
cam.setParameters(params);

SurfaceView sv = (SurfaceView)this.findViewById(R.id.surfaceView1);
SurfaceHolder mHolder = sv.getHolder(); 
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
mHolder.setSizeFromLayout();
mHolder.addCallback(this);

try {
    cam.setPreviewDisplay(mHolder);
} catch (IOException e) {
    Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}

//Log.d(TAG, "Starting Preview");
cam.startPreview();

b) shouldn't apply to me as I only attempt to take a single picture

c): uses-part of my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.flash"/>

Some additional code:

Where I invoke takePicture (note that recording here means that a AsyncTask is permitted to call takePicture again after it has completed. Irrelevant however as error persists without ever calling the AsyncTask):

findViewById(R.id.snap_button).setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        recording = !recording;

        Button btn = (Button)findViewById(R.id.snap_button);
        if(recording) {
            //update buttontext
            btn.setText("Stop");
            //start recording by taking a picture
            cam.takePicture(null,null, mPicture);

        } else {
            //update button text
            btn.setText("Start");
        }

    }
});

EDIT: After slightly altering my layout the pictureCallback is finally invoked and I get valid data (yay), however the error persists. Here's my current layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <SurfaceView
        android:id="@+id/surfaceView1"
        android:layout_width="0dp"
        android:layout_height="369dp"
        android:layout_weight="1.55" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <Button
            android:id="@+id/snap_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Capture" />

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>
like image 222
Pierre Barbera Avatar asked Feb 15 '13 13:02

Pierre Barbera


1 Answers

I would say that you have some errors in steps.

You should look at this example: cw-android - camera preview (line 127+). I'm guessing that you're not waiting until first time surfaceChanged in your SurfaceHolder.Callback, where usually you should invoke startPreview() method, thus your explanations

a) startPreview wasn't called;

b) trying to take pictures too fast (before the picture callback was invoked);

are, probably, both correct.

like image 65
Tomo Avatar answered Nov 05 '22 14:11

Tomo