0

I've got Android app where I shoot a picture with front camera. I've used approach described here: http://android-er.blogspot.sk/2010/12/add-overlay-on-camera-preview.html. It works on Nexus S with Android 2.3.6 and it works on HTC One X with Android 4.1.1

It doesn't work on Asus Nexus 7 with latest Android 4.2.2 and I get this in logs when I try to take a picture:

04-03 22:06:56.181: I/MainSSCActivity(24745): camera take picture START
04-03 22:06:56.191: E/NvOmxCamera(24952): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
04-03 22:06:56.191: E/NvOmxCamera(24952): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000
04-03 22:06:56.191: D/NvOsDebugPrintf(24952): NvMMLiteJPEGEncSetAttribute: Incorrect value 0 for stereo capture type
04-03 22:06:56.191: E/NvOmxCameraSettings(24952): OMX_ERRORTYPE android::programStereoInfo(OMX_HANDLETYPE, const NVX_STEREOCAPTUREINFO&, android::NvxWrappers*): pNvxWrappers->OMX_SetConfigIL failed with 0x80001005
04-03 22:06:56.351: I/MainSSCActivity(24745): camera take picture END
04-03 22:06:56.391: I/MainSSCActivity(24745): ***** surface destroyed
04-03 22:06:56.401: I/hwcomposer(130): Setting interactive mode: On
04-03 22:06:56.481: E/BufferQueue(130): [SurfaceView] queueBuffer: SurfaceTexture has been abandoned!
04-03 22:06:56.491: E/SurfaceTextureClient(24952): queueBuffer: error queuing buffer to SurfaceTexture, -19
04-03 22:06:56.491: E/NvOmxCamera(24952): Queue Buffer Failed
04-03 22:06:56.491: A/libc(24952): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 25019 (Binder_3)
04-03 22:06:56.491: D/MainSSCActivity(24745): RAW bytes: null
04-03 22:06:56.491: D/MainSSCActivity(24745): shutter
04-03 22:06:56.591: I/DEBUG(128): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-03 22:06:56.591: I/DEBUG(128): Build fingerprint: 'google/nakasig/tilapia:4.2.2/JDQ39/573038:user/release-keys'
04-03 22:06:56.591: I/DEBUG(128): Revision: '0'
04-03 22:06:56.591: I/DEBUG(128): pid: 24952, tid: 25019, name: Binder_3  >>> /system/bin/mediaserver <<<
04-03 22:06:56.591: I/DEBUG(128): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
04-03 22:06:56.701: I/DEBUG(128):     r0 00000027  r1 deadbaad  r2 4022f258  r3 00000000
04-03 22:06:56.701: I/DEBUG(128):     r4 00000000  r5 42de4d6c  r6 415dc640  r7 411b7c58
04-03 22:06:56.701: I/DEBUG(128):     r8 411cfe30  r9 415dc8c8  sl 00000000  fp 00000001
04-03 22:06:56.701: I/DEBUG(128):     ip 40be2de4  sp 42de4d68  lr 402022f9  pc 401fe992  cpsr 60000030
04-03 22:06:56.701: I/DEBUG(128):     d0  0000000000000000  d1  000000007fc00000
04-03 22:06:56.701: I/DEBUG(128):     d2  3fb15bd900000000  d3  3f114ee7df28fa15
04-03 22:06:56.701: I/DEBUG(128):     d4  0000000000000000  d5  3ff0000000000000
04-03 22:06:56.701: I/DEBUG(128):     d6  0000000541000000  d7  7fc0000000000000
04-03 22:06:56.701: I/DEBUG(128):     d8  0000000000000000  d9  0000000000000000
04-03 22:06:56.701: I/DEBUG(128):     d10 0000000000000000  d11 0000000000000000

So far, I don't really have a clue what's wrong and how to fix it. Can anybody help me? Thanks in advance.

Ahmad
  • 69,608
  • 17
  • 111
  • 137
MartinC
  • 546
  • 11
  • 26
  • This is a seg fault. A native library tried to write to memory that was passed ot it by Java then deallocated before use, or vice versa. The crash appears to be in libc, which makes this really hard to debug. I'd check anyplace you explicitly call a native library, or anywhere you pass references to something that may use one (like the Camera api). – Gabe Sechan Apr 03 '13 at 20:31

3 Answers3

2

OK, thanks to everybody pointing me to the fact, that surface is destroyed sooner as it should be. I had a specific situation with more views displayed on each other and by calling surfaceView.setVisibility((View.INVISIBLE) at wrong place, it was me actually destroying it. I have put it at the end, so, the way it works for me is following:

myPictureCallback_JPG = new PictureCallback() {

@Override
public void onPictureTaken(byte[] bytes, Camera arg1) {
    Log.d(TAG, "bytes.length: " + bytes.length);
    String image = Base64.encodeToString(bytes, Base64.NO_WRAP);
    Log.i(TAG, "base64 image: " + image);
    String url = "javascript:takePicture('" + image + "');";

    wv.loadUrl(url);

    camera.stopPreview();
    camera.release();
    camera = null;
    surfaceView.setVisibility(View.INVISIBLE);
    wv.setVisibility(View.VISIBLE);
    viewControl.setVisibility(View.INVISIBLE);
}
};
MartinC
  • 546
  • 11
  • 26
0

Try doing this, it might work. Override the "onPause" method in your activity and call "stopPreview()". Looks like the surface gets destroyed even before you have called stopPreview(), hence the error "SurfaceTexture has been abandoned!".

@Override
public void onPause(Bundle savedInstanceState) {
    super.onPause(savedInstanceState);
    if(camera != null) 
        camera.stopPreview();
}


This happens when the Surface (buffers) that app passes to the Camera drivers get destroyed while the driver is still accessing them.

Let me know if that works. If that does not work, post the entire logcat from the start of the camera app to the point where you close the app.

vikky.rk
  • 3,989
  • 5
  • 29
  • 32
  • Hi, thanks, once I get a spare time, I'll have a look. To describe the situation in detail: I've got frame layout with two views, webview and surfaceview. I'm displaying web portal in webview and camerapreview is hidden (surfaceview).Once I press button to take a picture (button is on webportal and I am using Javascript API for communication), webview gets hidden and camerapreview starts.So far, so good. I've inflated button there, so to shoot the picture, user presses button, picture gets taken (it works on 2.3.6, 4.1.1) and then, webview is shown with picture, camera preview is hidden again. – MartinC Apr 04 '13 at 07:03
  • with 4.2.2, I am able to show camera preview, but I shoot the picture, then I get the error which I have pasted from LogCat. – MartinC Apr 04 '13 at 07:28
0

This solved the issue in my case:

I was using mcamera.setOneShotPreviewCallback(mPreviewCallback); to get the Picture from the Camera.

I've changed that by mCamera.takePicture(null, null,mPictureCallback);

In mPictureCallBack I proccess the jpeg and in my case I take another picture restarting the preview between taken pictures (stopPreview and startPreview).

By the way, my Preview is based in which is provided in Samples Api 17 /android-sdks/samples/android-17/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.

Paola G
  • 798
  • 1
  • 6
  • 13
  • sorry I don't understand what you have done in order to get it work. Do you think you could paste the code snippet which didn't work and code which actually does work? Thank you. – MartinC Apr 04 '13 at 16:46