0

My app crash without a stacktrace like what was asked here. I am also using Samsung Galaxy S. It works fine with my HTC desire. The solution is by "removing the preview view and re-instantiating it"

However, my surfaceview created is done this way

camera = (SurfaceView) findViewById(R.id.cameraview);

How can I solve this problem or how can i reinstantiate this SurfaceView?

02-21 15:57:20.305: ERROR/SecCamera(2357): startPreview: get the first frame of the preview
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): startPreview : return startPreview 0
02-21 15:57:20.305: DEBUG/CameraHardwareSec(2357): MemoryHeapBase(fd(33), size(3686464), width(640), height(480))
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mPostViewWidth = 640 mPostViewHeight = 480 mPostViewSize = 614400
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mRawHeap : MemoryHeapBase(previewHeapSize(614408))
02-21 15:57:20.305: WARN/CameraService(2357): width(640), height(480), format:yuv420sp
02-21 15:57:20.328: ERROR/SecCamera(2357): fimc_v4l2_streamoff()
02-21 15:57:20.336: ERROR/SecCamera(2357): ERR(fimc_v4l2_streamoff):VIDIOC_STREAMOFF failed
02-21 15:57:20.336: ERROR/SecCamera(2357): int android::SecCamera::stopRecord()::1494 fail. errno: No such device
02-21 15:57:20.336: ERROR/CameraHardwareSec(2357): ERR(previewThread):Fail on mSecCamera->stopRecord()
02-21 15:57:20.363: WARN/CameraService(2357): startRecording (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startCameraMode(1) (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startRecordingMode (pid 2357)
02-21 15:57:20.367: DEBUG/SecCamera(2357): passed fmt = 842094164 found pixel format[8]: YUV 4:2:0 planar, Y/CbCr, Tiled
02-21 15:57:20.367: ERROR/SecCamera(2357): startRecord: m_recording_width = 320, m_recording_height = 240
Community
  • 1
  • 1
humansg
  • 735
  • 3
  • 12
  • 30

2 Answers2

0

I think there should be some problem with setting preview parameters. Try below.

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {



if (isPreviewRunning) {
    camera.stopPreview();
}
try{
Camera.Parameters p = camera.getParameters();
if(p!=null){
List<Size> sizes = p.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
p.setPreviewSize(optimalSize.width, optimalSize.height);
camera.setParameters(p);

camera.setPreviewDisplay(holder);;
camera.startPreview();

}
} catch (IOException e) {
    // TODO Auto-generated catch block


    e.printStackTrace();
}

isPreviewRunning = true;
}
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
// TODO Auto-generated method stub
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;

Size optimalSize = null;
double minDiff = Double.MAX_VALUE;

int targetHeight = h;

// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}

// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {



if (isPreviewRunning) {
    camera.stopPreview();
}
try{
Camera.Parameters p = camera.getParameters();
if(p!=null){
List<Size> sizes = p.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
p.setPreviewSize(optimalSize.width, optimalSize.height);
camera.setParameters(p);

camera.setPreviewDisplay(holder);;
camera.startPreview();

}
} catch (IOException e) {
    // TODO Auto-generated catch block


    e.printStackTrace();
}

isPreviewRunning = true;
}

private Size getOptimalPreviewSize(List sizes, int w, int h) {

// TODO Auto-generated method stub
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;

Size optimalSize = null;
double minDiff = Double.MAX_VALUE;

int targetHeight = h;

// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}

// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;

}

Put this code in your surfaceChanged(). getOptimalPreviewSize() is used to set preview parameters according to device resolution.

Dhruvisha
  • 2,538
  • 1
  • 21
  • 31
0

Well, I upgraded the firmware to 2.3.3 and it is working now.

humansg
  • 735
  • 3
  • 12
  • 30