Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Separate opening device and setting output
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kim <[email protected]>
  • Loading branch information
Justin Kim committed Jul 25, 2017
1 parent bd452ab commit c8bbd74
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions app/src/main/jni/native-camera2-jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ static void openCamera(ACameraDevice_request_template templateId)

ACaptureSessionOutputContainer_create(&captureSessionOutputContainer);

captureSessionStateCallbacks.onReady = capture_session_on_ready;
captureSessionStateCallbacks.onActive = capture_session_on_active;

ACameraMetadata_free(cameraMetadata);
ACameraManager_deleteCameraIdList(cameraIdList);
ACameraManager_delete(cameraManager);
Expand Down Expand Up @@ -152,37 +155,22 @@ static void closeCamera(void)
JNIEXPORT void JNICALL Java_org_freedesktop_nativecamera2_NativeCamera2_startPreview(JNIEnv *env,
jclass clazz,
jobject surface) {
openCamera(TEMPLATE_PREVIEW);

theNativeWindow = ANativeWindow_fromSurface(env, surface);

LOGI("Surface is prepared in %p.\n", surface);
openCamera(TEMPLATE_PREVIEW);

if (cameraOutputTarget != NULL) {
ACameraOutputTarget_free(cameraOutputTarget);
cameraOutputTarget = NULL;
}
LOGI("Surface is prepared in %p.\n", surface);

ACameraOutputTarget_create(theNativeWindow, &cameraOutputTarget);
ACaptureRequest_addTarget(captureRequest, cameraOutputTarget);

if (sessionOutput != NULL) {
ACaptureSessionOutputContainer_remove(captureSessionOutputContainer, sessionOutput);
ACaptureSessionOutput_free(sessionOutput);
sessionOutput = NULL;
}

ACaptureSessionOutput_create(theNativeWindow, &sessionOutput);
ACaptureSessionOutputContainer_add(captureSessionOutputContainer, sessionOutput);

captureSessionStateCallbacks.onReady = capture_session_on_ready;
captureSessionStateCallbacks.onActive = capture_session_on_active;

ACameraDevice_createCaptureSession(cameraDevice, captureSessionOutputContainer,
&captureSessionStateCallbacks, &captureSession);

ACameraCaptureSession_setRepeatingRequest(captureSession, NULL, 1, &captureRequest, NULL);

}

JNIEXPORT void JNICALL Java_org_freedesktop_nativecamera2_NativeCamera2_stopPreview(JNIEnv *env,
Expand Down

0 comments on commit c8bbd74

Please sign in to comment.