Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request the camera preview on the main ui thread #324

Merged
merged 1 commit into from
Mar 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public void onPreviewError(Exception e) {
};

private void requestNextPreview() {
if (cameraInstance.isOpen()) {
cameraInstance.requestPreview(previewCallback);
}
cameraInstance.requestPreview(previewCallback);
}

protected LuminanceSource createSource(SourceData sourceData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class CameraInstance {
private DisplayConfiguration displayConfiguration;
private boolean open = false;
private boolean cameraClosed = true;
private Handler mainHandler;

private CameraSettings cameraSettings = new CameraSettings();

Expand All @@ -41,6 +42,7 @@ public CameraInstance(Context context) {
this.cameraThread = CameraThread.getInstance();
this.cameraManager = new CameraManager(context);
this.cameraManager.setCameraSettings(cameraSettings);
this.mainHandler = new Handler();
}

/**
Expand Down Expand Up @@ -166,12 +168,20 @@ public boolean isCameraClosed() {
}

public void requestPreview(final PreviewCallback callback) {
validateOpen();

cameraThread.enqueue(new Runnable() {
mainHandler.post(new Runnable() {
@Override
public void run() {
cameraManager.requestPreviewFrame(callback);
if(!open) {
Log.d(TAG, "Camera is closed, not requesting preview");
return;
}

cameraThread.enqueue(new Runnable() {
@Override
public void run() {
cameraManager.requestPreviewFrame(callback);
}
});
}
});
}
Expand Down