31

I just got a Nexus 7 I'm trying to port some code to. The following line works with no problem on a Xoom running Ice Cream:

mCamera.startPreview();

It also works correctly on the Nexus 7, but it logs errors:

E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000

This is a problem because it also logs these errors once per frame when I execute the line

mCamera.takePicture(null, null, null, pictureCallback);

Since I'm taking 10 frames per second, this disturbs me, so I'd like to fix the errors. I've grepped through all the sources (android sdk and ndk) and the text for the above errors doesn't appear anywhere. I believe from a lot of googling that this is happening in Nvidia's implementation of OpenMax, where it seems to be tied to the parameter "nv-stereo-mode" which has possible values of "left", "right", or "stereo" (the Nexus 7 only has one camera, so I don't know why it would care about stereo camera modes, but whatever). I tried setting it to each of the legal values using, for example:

mParams = mCamera.getParameters();
mParams.set("nv-stereo-mode", "right");
mCamera.setParameters(mParams);

But, my log says:

E/NvOmxCameraSettingsParser(  126): Skipping non-standard parameter: nv-stereo-mode

This appears to be related to the source file nvomxcamerasettingsparser.cpp, which I can't find anywhere on the web. I don't really know where to go from here, I've grepped and googled for everything I could think of, so any help would be greatly appreaciated.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
PapaSloth
  • 488
  • 3
  • 7
  • Nope, no luck. However, I did end up rewriting the code to use MediaRecorder instead of taking individual pictures, and to stream the data using H264 instead of series of JPEGs. Since I'm not taking individual pictures anymore, the errors went away. – PapaSloth Jan 13 '13 at 01:26
  • thanks for update. I am still facing problem, so far on Nexus 4 back camera doesn't show same problem but front camera does show same problem. Does it anything to do with front camera thing on Jelly Bean?? – JRC Jan 17 '13 at 08:25

1 Answers1

1

Try below code for you issue. I hope it will works fine.

import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Record extends Activity implements SurfaceHolder.Callback,
    MediaRecorder.OnInfoListener {

Button myButton;
MediaRecorder mediaRecorder;
SurfaceHolder surfaceHolder;
boolean recording;
Camera camera;
int mCount;
TextView msg;
boolean rec = false;
String fileName = "DamageVideo.mp4";
CountDownTimer timer;

/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    recording = false;

    mediaRecorder = new MediaRecorder(); 
    initMediaRecorder();

    setContentView(R.layout.record_view);

    SurfaceView myVideoView = (SurfaceView) findViewById(R.id.videoview);
    surfaceHolder = myVideoView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    myButton = (Button) findViewById(R.id.mybutton);
    msg = (TextView) findViewById(R.id.txttimer);

    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            myButton.setVisibility(View.GONE);
            myButton.setClickable(false);
            try {
                if (recording) {
                    recording = false;

                    myButton.setClickable(true);
                    myButton.setVisibility(View.VISIBLE);

                    Intent intent = new Intent();

                    setResult(100, intent);
                    finish();
                    overridePendingTransition(R.anim.trans_right_in,
                            R.anim.trans_right_out);

                    mediaRecorder.stop();
                    mediaRecorder.release();

                    moveFile();
                } else {

                    recording = true;
                    camera.stopPreview();
                    camera.release();
                    // myButton.setVisibility(View.GONE);
                    timer.start();
                    // myButton.setClickable(false);
                    mediaRecorder.start();

                    new CountDownTimer(21000, 1000) {

                        public void onTick(long millisUntilFinished) {

                            msg.setText(+(22000 - (millisUntilFinished - 0))
                                    / 1000 + "/20");

                        }

                        public void onFinish() {
                            // msg.setText("10/10");
                        }
                    }.start();
                    myButton.setText("STOP");
                    // camera.release();

                }
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }
    });

    timer = new CountDownTimer(1000, 1000) {

        public void onTick(long millisUntilFinished) {

        }

        public void onFinish() {
            myButton.setVisibility(View.VISIBLE);
            myButton.setClickable(true);
        }
    };

}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

    try {
        prepareMediaRecorder();
        camera = Camera.open();

        try {
            camera.setPreviewDisplay(surfaceHolder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        camera.startPreview();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

private void initMediaRecorder() {
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    CamcorderProfile camcorderProfile_HQ = CamcorderProfile
            .get(CamcorderProfile.QUALITY_HIGH);

    mediaRecorder.setProfile(camcorderProfile_HQ);
    // mediaRecorder.setVideoFrameRate(30);
    // File dir = Const.getFilePath();
    File dir = Environment.getExternalStorageDirectory();

    // String fname = "DamageVideo.mp4";

    mediaRecorder.setOutputFile(dir.getAbsolutePath() + "/" + fileName);
    mediaRecorder.setMaxDuration(20000); // Set max duration 60 sec.
    mediaRecorder.setOnInfoListener(this);
}

private void prepareMediaRecorder() {
    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    try {

        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
    // TODO Auto-generated method stub
    if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {

        // mr.stop();
        // mr.release();
        recording = false;

        mediaRecorder.stop();

        Intent intent = new Intent();

        setResult(100, intent);
        finish();
        overridePendingTransition(R.anim.trans_right_in,
                R.anim.trans_right_out);
        mediaRecorder.release();
        moveFile();
    }
}

@Override
public void onBackPressed() {

    super.onBackPressed();

    try {
        if (!recording) {
            File dir = Environment.getExternalStorageDirectory();
            File imgFile = new File(dir.getAbsolutePath(), fileName);
            if (imgFile.exists()) {
                imgFile.delete();
            }

            camera.stopPreview();
            camera.release();
        } else {
            mediaRecorder.stop();
            mediaRecorder.release();

            moveFile();
        }

        recording = false;

        Intent intent = new Intent();

        setResult(100, intent);
        finish();
        overridePendingTransition(R.anim.trans_right_in,
                R.anim.trans_right_out);
    } catch (Exception e) {
        // TODO: handle exception
    }

}

public void moveFile() {
    File temp = Environment.getExternalStorageDirectory();
    File from = new File(temp.getAbsolutePath(), fileName);

    File dir = Const.getFilePath(Record.this);
    File to = new File(dir.getAbsolutePath(), fileName);

    from.renameTo(to);
}

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

}
}

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

<SurfaceView
    android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<Button
    android:id="@+id/mybutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="5dp"
    android:background="#55A5D8"
    android:padding="5dp"
    android:text="REC"
    android:textColor="#ffffff"
    android:textSize="20sp" />

<TextView
    android:id="@+id/txttimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text=""
    android:textColor="#55A5D8"
    android:textSize="20sp"
    android:textStyle="bold" />

</RelativeLayout>
Teraiya Mayur
  • 1,094
  • 10
  • 18