Commit 4480fbeb authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improved capture stop() to fix issues

parent 462562b3
...@@ -127,14 +127,18 @@ static void android_camera2_capture_device_on_disconnected(void *context, ACamer ...@@ -127,14 +127,18 @@ static void android_camera2_capture_device_on_disconnected(void *context, ACamer
ms_message("[Camera2 Capture] Camera %s is diconnected", ACameraDevice_getId(device)); ms_message("[Camera2 Capture] Camera %s is diconnected", ACameraDevice_getId(device));
AndroidCamera2Context *d = (AndroidCamera2Context *)context; AndroidCamera2Context *d = (AndroidCamera2Context *)context;
ms_filter_lock(d->filter);
android_camera2_capture_stop(d); android_camera2_capture_stop(d);
ms_filter_unlock(d->filter);
} }
static void android_camera2_capture_device_on_error(void *context, ACameraDevice *device, int error) { static void android_camera2_capture_device_on_error(void *context, ACameraDevice *device, int error) {
ms_error("[Camera2 Capture] Error %d on camera %s", error, ACameraDevice_getId(device)); ms_error("[Camera2 Capture] Error %d on camera %s", error, ACameraDevice_getId(device));
AndroidCamera2Context *d = (AndroidCamera2Context *)context; AndroidCamera2Context *d = (AndroidCamera2Context *)context;
ms_filter_lock(d->filter);
android_camera2_capture_stop(d); android_camera2_capture_stop(d);
ms_filter_unlock(d->filter);
} }
static void android_camera2_capture_session_on_ready(void *context, ACameraCaptureSession *session) { static void android_camera2_capture_session_on_ready(void *context, ACameraCaptureSession *session) {
...@@ -500,14 +504,10 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) { ...@@ -500,14 +504,10 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) {
d->captureSession = nullptr; d->captureSession = nullptr;
} }
if (d->imageReader) { if (d->capturePreviewRequest) {
AImageReader_delete(d->imageReader); ACaptureRequest_removeTarget(d->capturePreviewRequest, d->cameraCaptureOutputTarget);
d->imageReader = nullptr; ACaptureRequest_free(d->capturePreviewRequest);
d->capturePreviewRequest = nullptr;
if (d->imageReaderListener) {
delete d->imageReaderListener;
d->imageReaderListener = nullptr;
}
} }
if (d->cameraCaptureOutputTarget) { if (d->cameraCaptureOutputTarget) {
...@@ -520,11 +520,6 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) { ...@@ -520,11 +520,6 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) {
d->cameraPreviewOutputTarget = nullptr; d->cameraPreviewOutputTarget = nullptr;
} }
if (d->capturePreviewRequest) {
ACaptureRequest_free(d->capturePreviewRequest);
d->capturePreviewRequest = nullptr;
}
if (d->captureSessionOutputContainer) { if (d->captureSessionOutputContainer) {
if (d->sessionCaptureOutput) { if (d->sessionCaptureOutput) {
ACaptureSessionOutputContainer_remove(d->captureSessionOutputContainer, d->sessionCaptureOutput); ACaptureSessionOutputContainer_remove(d->captureSessionOutputContainer, d->sessionCaptureOutput);
...@@ -538,16 +533,27 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) { ...@@ -538,16 +533,27 @@ static void android_camera2_capture_stop(AndroidCamera2Context *d) {
d->sessionPreviewOutput = nullptr; d->sessionPreviewOutput = nullptr;
} }
ACaptureSessionOutputContainer_free(d->captureSessionOutputContainer);
d->captureSessionOutputContainer = nullptr;
}
if (d->captureWindow) { if (d->captureWindow) {
ANativeWindow_release(d->captureWindow); ANativeWindow_release(d->captureWindow);
d->captureWindow = nullptr; d->captureWindow = nullptr;
} }
ACaptureSessionOutputContainer_free(d->captureSessionOutputContainer);
d->captureSessionOutputContainer = nullptr;
}
android_camera2_capture_close_camera(d); android_camera2_capture_close_camera(d);
if (d->imageReader) {
AImageReader_delete(d->imageReader);
d->imageReader = nullptr;
if (d->imageReaderListener) {
delete d->imageReaderListener;
d->imageReaderListener = nullptr;
}
}
android_camera2_capture_destroy_preview(d); android_camera2_capture_destroy_preview(d);
ms_message("[Camera2 Capture] Capture stopped"); ms_message("[Camera2 Capture] Capture stopped");
......
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