11

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>
  • 1
    Did you solved the problem? – Dinesh Prajapati Feb 28 '13 at 08:54
  • Do you have SD card mounted when this code executes? http://forum.xda-developers.com/showthread.php?t=819037#6 – Marek Sebera Mar 01 '13 at 18:24
  • I'm saving the pictures I take onto the sdcard so one would assume that it is correctly mounted. I just tried un- and remounting but the error message persists. – Pierre Barbera Mar 06 '13 at 14:06
  • I think the key error is the third one where it says that after it fails to find pmem_camera, it switches over to pmem_adsp, which presumably succeeds. I have no idea why pmem_camera isn't initialized on your system. – Mel Nicholson Mar 11 '13 at 18:41

1 Answers1

1

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.

Community
  • 1
  • 1
Tomo
  • 6,847
  • 1
  • 22
  • 32
  • Thats what I'm currently doing and the errormessage persists. Calling startPreview too early causes a different error I believe – Pierre Barbera Mar 21 '13 at 13:02
  • Can you attach full code. I can test on my HTC Desire with Android 2.3.3, so we can eliminate hardware or vendor problems if message persists :) – Tomo Mar 21 '13 at 17:41