I currently have an app that I am trying to record video, with the following method to initialize the camera:
private void initRecorder(Surface surface) throws IOException {
if (mCamera == null) {
mCamera = Camera.open();
mCamera.unlock();
}
if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder();
mMediaRecorder.setPreviewDisplay(surface);
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(640, 480);
mMediaRecorder.setOutputFile(videoFile);
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
}
initSuccess = true;
}
When I try to stop the camera or when surfaceDestroyed
is called, I call the following method:
private void resetCamera() {
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mCamera.release();
mCamera = null;
try {
initRecorder(mHolder.getSurface());
} catch (IOException e) {
e.printStackTrace();
}
}
However, somewhere in this code I am getting a Fatal Signal 11 error. Apparently the code is trying to illegally access a portion of memory.
I was wondering, how would I get around this error?
Here is a Logcat dump from when I start recording the video to when I stop recording:
D/dalvikvm: GC_FOR_ALLOC freed 1309K, 27% free 7434K/10168K, paused 9ms, total 9ms
I/dalvikvm: Could not compile trace for Ljava/util/Arrays;fill, offset 5
I/dalvikvm: ++++++++++++++++++++++++++++++++++++++++++++
I/dalvikvm: JIT_INFO: ME Issues while compiling trace Ljava/util/Arrays;fill, offset 5
I/dalvikvm: The trace provoked a spill.
I/dalvikvm: Trying less registerization from 1 to 0
D/dalvikvm: GC_FOR_ALLOC freed 1415K, 27% free 7438K/10168K, paused 10ms, total 10ms
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1), thread 13774 (arch.treadmill3)
After mMediaRecorder.release(); you have to write mMediaRecorder = null; because release() method seems to have few bugs. Like this:
if (mMediaRecorder != null) {
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
}
User contributions licensed under CC BY-SA 3.0