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

try/catch getCameraInfo() on Camera1Engine.java #1244

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 @@ -169,5 +169,21 @@ public void onVideoRecordingEnd() {
public void onPictureShutter() {

}

/**
* Notifies that a finger gesture just triggered a swipe left event.
* This can be used to exchange between different filters or to
* swap between front and back cameras.
*/
@UiThread
public void onSwipeLeft() {}

/**
* Notifies that a finger gesture just triggered a swipe right event.
* This can be used to exchange between different filters or to
* swap between front and back cameras.
*/
@UiThread
public void onSwipeRight() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@VisibleForTesting TapGestureFinder mTapGestureFinder;
@VisibleForTesting ScrollGestureFinder mScrollGestureFinder;

private float x1,x2;
static final int MIN_SWIPE_DISTANCE = 150;

// Views
@VisibleForTesting GridLinesLayout mGridLinesLayout;
@VisibleForTesting MarkerLayout mMarkerLayout;
Expand Down Expand Up @@ -666,6 +669,32 @@ public boolean onTouchEvent(MotionEvent event) {
onGesture(mTapGestureFinder, options);
}

if(event.getAction() == MotionEvent.ACTION_DOWN) x1 = event.getX();
if(event.getAction() == MotionEvent.ACTION_UP) {
x2 = event.getX();
float deltaX = x2 - x1;
if(deltaX > MIN_SWIPE_DISTANCE) {
mUiHandler.post(new Runnable() {
@Override
public void run() {
for (CameraListener listener : mListeners) {
listener.onSwipeRight();
}
}
});
}
if (deltaX < MIN_SWIPE_DISTANCE) {
mUiHandler.post(new Runnable() {
@Override
public void run() {
for (CameraListener listener : mListeners) {
listener.onSwipeLeft();
}
}
});
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ protected boolean collectCameraInfo(@NonNull Facing facing) {
"Cameras:", Camera.getNumberOfCameras());
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) {
Camera.getCameraInfo(i, cameraInfo);
try {
Camera.getCameraInfo(i, cameraInfo);
} catch (RuntimeException e) {
continue;
}
if (cameraInfo.facing == internalFacing) {
getAngles().setSensorOffset(facing, cameraInfo.orientation);
mCameraId = i;
Expand Down Expand Up @@ -524,8 +528,14 @@ public void setFlash(@NonNull Flash flash) {
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyFlash(params, old)) mCamera.setParameters(params);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyFlash(params, old)) mCamera.setParameters(params);
} catch (RuntimeException e) {
LOG.e("onSetFlash:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
}
Expand All @@ -548,8 +558,14 @@ public void setLocation(@Nullable Location location) {
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyLocation(params, oldLocation)) mCamera.setParameters(params);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyLocation(params, oldLocation)) mCamera.setParameters(params);
} catch (RuntimeException e) {
LOG.e("onSetLocation:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
}
Expand All @@ -576,8 +592,14 @@ public void setWhiteBalance(@NonNull WhiteBalance whiteBalance) {
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyWhiteBalance(params, old)) mCamera.setParameters(params);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyWhiteBalance(params, old)) mCamera.setParameters(params);
} catch (RuntimeException e) {
LOG.e("onSetWhiteBalance:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
}
Expand Down Expand Up @@ -605,8 +627,14 @@ public void setHdr(@NonNull Hdr hdr) {
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyHdr(params, old)) mCamera.setParameters(params);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyHdr(params, old)) mCamera.setParameters(params);
} catch (RuntimeException e) {
LOG.e("onSetHdr:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
}
Expand All @@ -631,12 +659,18 @@ public void setZoom(final float zoom, @Nullable final PointF[] points, final boo
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyZoom(params, old)) {
mCamera.setParameters(params);
if (notify) {
getCallback().dispatchOnZoomChanged(mZoomValue, points);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyZoom(params, old)) {
mCamera.setParameters(params);
if (notify) {
getCallback().dispatchOnZoomChanged(mZoomValue, points);
}
}
} catch (RuntimeException e) {
LOG.e("onSetZoom:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
Expand Down Expand Up @@ -666,13 +700,19 @@ public void setExposureCorrection(final float EVvalue, @NonNull final float[] bo
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyExposureCorrection(params, old)) {
mCamera.setParameters(params);
if (notify) {
getCallback().dispatchOnExposureCorrectionChanged(mExposureCorrectionValue,
bounds, points);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyExposureCorrection(params, old)) {
mCamera.setParameters(params);
if (notify) {
getCallback().dispatchOnExposureCorrectionChanged(mExposureCorrectionValue,
bounds, points);
}
}
} catch (RuntimeException e) {
LOG.e("onSetExposureCorrection:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
Expand Down Expand Up @@ -744,8 +784,14 @@ public void setPreviewFrameRate(float previewFrameRate) {
new Runnable() {
@Override
public void run() {
Camera.Parameters params = mCamera.getParameters();
if (applyPreviewFrameRate(params, old)) mCamera.setParameters(params);
try {
Camera.Parameters params = mCamera.getParameters();
if (applyPreviewFrameRate(params, old)) mCamera.setParameters(params);
} catch (RuntimeException e) {
LOG.e("onSetPreviewFrameRate:", "Failed to get params from camera. Maybe low level problem with camera or camera has already released?");
//Should throw exception? Looks inappropriate at this point if camera is working...
//throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW);
}
}
});
}
Expand Down Expand Up @@ -875,7 +921,13 @@ public void run() {
getPreview().getSurfaceSize());
MeteringRegions transformed = regions.transform(transform);

Camera.Parameters params = mCamera.getParameters();
Camera.Parameters params;
try {
params = mCamera.getParameters();
} catch (RuntimeException re) {
LOG.e("startAutoFocus:", "Failed to get camera parameters");
throw new CameraException(re, CameraException.REASON_UNKNOWN);
}
int maxAF = params.getMaxNumFocusAreas();
int maxAE = params.getMaxNumMeteringAreas();
if (maxAF > 0) params.setFocusAreas(transformed.get(maxAF, transform));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ protected void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long
}
mMediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mSurface = mMediaCodec.createInputSurface();
mMediaCodec.start();
try {
mMediaCodec.start();
} catch (MediaCodec.CodecException e) {
throw new RuntimeException(e);
}
}

@EncoderThread
Expand Down
Loading