Commit e99ba772 authored by Ghislain MARY's avatar Ghislain MARY

Add flag to prevent calling the putImage callback if the video recording has been stopped.

parent e256a45b
......@@ -35,6 +35,7 @@ import android.view.SurfaceView;
* This file depends only on Android SDK >= 5
*/
public class AndroidVideoApi5JniWrapper {
public static boolean isRecording = false;
static public native void setAndroidSdkVersion(int version);
public static native void putImage(long nativePtr, byte[] buffer);
......@@ -90,17 +91,21 @@ public class AndroidVideoApi5JniWrapper {
camera.setPreviewCallback(new Camera.PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
// forward image data to JNI
putImage(nativePtr, data);
if (isRecording) {
// forward image data to JNI
putImage(nativePtr, data);
}
}
});
camera.startPreview();
isRecording = true;
Log.d("mediastreamer", "Returning camera object: " + camera);
return camera;
}
public static void stopRecording(Object cam) {
isRecording = false;
Log.d("mediastreamer", "stopRecording(" + cam + ")");
Camera camera = (Camera) cam;
......
......@@ -43,19 +43,22 @@ public class AndroidVideoApi8JniWrapper {
camera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
// forward image data to JNI
AndroidVideoApi5JniWrapper.putImage(nativePtr, data);
camera.addCallbackBuffer(data);
if (AndroidVideoApi5JniWrapper.isRecording) {
// forward image data to JNI
AndroidVideoApi5JniWrapper.putImage(nativePtr, data);
camera.addCallbackBuffer(data);
}
}
});
camera.startPreview();
AndroidVideoApi5JniWrapper.isRecording = true;
Log.d("mediastreamer", "Returning camera object: " + camera);
return camera;
}
public static void stopRecording(Object cam) {
AndroidVideoApi5JniWrapper.isRecording = false;
Log.d("mediastreamer", "stopRecording(" + cam + ")");
Camera camera = (Camera) cam;
......
......@@ -29,7 +29,7 @@ import android.os.Build;
import android.util.Log;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public class AndroidVideoApi9JniWrapper {
public class AndroidVideoApi9JniWrapper {
static public int detectCameras(int[] indexes, int[] frontFacing, int[] orientation) {
return AndroidVideoApi5JniWrapper.detectCameras(indexes, frontFacing, orientation);
}
......@@ -74,7 +74,7 @@ public class AndroidVideoApi9JniWrapper {
Size size = params.getPreviewSize();
int bufferSize = (size.width * size.height * ImageFormat.getBitsPerPixel(params.getPreviewFormat())) / 8;
bufferSize += bufferSize / 20;
} else {
} else if (AndroidVideoApi5JniWrapper.isRecording) {
AndroidVideoApi5JniWrapper.putImage(nativePtr, data);
camera.addCallbackBuffer(data);
}
......@@ -83,6 +83,7 @@ public class AndroidVideoApi9JniWrapper {
setCameraDisplayOrientation(rotation, cameraId, camera);
camera.startPreview();
AndroidVideoApi5JniWrapper.isRecording = true;
Log.d("mediastreamer", "Returning camera object: " + camera);
return camera;
} catch (Exception exc) {
......@@ -92,6 +93,7 @@ public class AndroidVideoApi9JniWrapper {
}
public static void stopRecording(Object cam) {
AndroidVideoApi5JniWrapper.isRecording = false;
AndroidVideoApi8JniWrapper.stopRecording(cam);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment