1

I have been getting a set of very specific errors when developing a very basic camera application. The code is almost identical to that on the android website.

The Galaxy SII is the only phone giving me the error which appears as follows in my LogCat console:

06-28 16:28:40.098: E/Surface(1650): Surface::init token -2 identity 18

The number that follows "identity" changes (42, 38, etc) but the error persists.

I think this may be related to the following class, but am still unsure as to its meaning:

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback 

What about the Galaxy SII might cause this error? I am also testing on an HTC Vivid and Pantech Burst. I fear this may be leading to larger problems. I am just trying to understand what this error may be about.

Here is the source:

package com.basicam.android;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;

public class CamActivity extends Activity {

    private SurfaceView preview=null;
    private SurfaceHolder previewHolder=null;
    private Camera camera=null;
    private boolean inPreview=false;
    private boolean cameraConfigured=false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d("crap","oncreated");
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        preview=(SurfaceView)findViewById(R.id.preview);
        previewHolder=preview.getHolder();
        previewHolder.addCallback(surfaceCallback);
        previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void onResume() {
        super.onResume();

        camera=Camera.open();
        startPreview();
    }

    @Override
    public void onPause() {
        if (inPreview) {
            camera.stopPreview();
        }

        camera.release();
        camera=null;
        inPreview=false;

        super.onPause();
    }

    private Camera.Size getBestPreviewSize(int width, int height,
            Camera cam) {
        Camera.Size result=null;
        Log.d("crap", "can haz preview sizes?");
        int i = 0;
        for (Camera.Size size : cam.getParameters().getSupportedPictureSizes()) {

            Log.d("sizew", ""+size.width);
            if (size.width<=width && size.height<=height) {
                Log.d("sizew", ""+size.width);
                Log.d("sizeh", ""+size.height);
                if (result==null) {
                    result=size;
                }
                else {
                    int resultArea=result.width*result.height;
                    int newArea=size.width*size.height;

                    if (newArea>resultArea) {
                        result=size;
                    }
                }
            }
        }

        return(result);
    }

    private void initPreview(int width, int height) {
        if (camera!=null && previewHolder.getSurface()!=null) {
            try {
                camera.setPreviewDisplay(previewHolder);
            }
            catch (Throwable t) {
                Log.e("PreviewDemo-surfaceCallback",
                        "Exception in setPreviewDisplay()", t);
            }

            if (!cameraConfigured) {
                Camera.Parameters parameters=camera.getParameters();
                Camera.Size size=getBestPreviewSize(width, height,
                        camera);

                if (size!=null) {
                    parameters.setPreviewSize(size.width, size.height);
                    camera.setParameters(parameters);
                    cameraConfigured=true;
                }
            }
        }
    }

    private void startPreview() {
        if (cameraConfigured && camera!=null) {
            camera.startPreview();
            inPreview=true;
        }
    }

    SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
        public void surfaceCreated(SurfaceHolder holder) {
            // no-op -- wait until surfaceChanged()
        }

        public void surfaceChanged(SurfaceHolder holder,
                int format, int width,
                int height) {

            initPreview(width, height);
            startPreview();
        }

        public void surfaceDestroyed(SurfaceHolder holder) {
            // no-op
        }
    };

}
AeroX
  • 3,387
  • 2
  • 25
  • 39
Daniel Smith
  • 8,561
  • 3
  • 35
  • 58
  • Can you show the source to that? We cannot tell what is happening here plus we do not see the screen on your end either :) – t0mm13b Jun 28 '12 at 23:55
  • Nice log comment - Keep that there - classy :) +1 from me, made me smile :) Good! As matter of interest, does it work okie for the HTC Vivid and Pantech Burst? – t0mm13b Jun 29 '12 at 00:12
  • It might help to re-edit your question to include the android version and indicate if its rooted or not? – t0mm13b Jun 29 '12 at 00:15
  • This question might be of help to you? http://stackoverflow.com/questions/7935292/android-camera-onpause-onresume-issue and here also http://stackoverflow.com/questions/8481402/android-i-get-no-stacktrace-phone-just-hangs – t0mm13b Jun 29 '12 at 00:18
  • FWIW, I don't see a log message that looks like that in AOSP. Possibly some OEM tweak? – fadden Jun 19 '14 at 20:14

0 Answers0