I have a CameraPreview that selects the closest available image size to the available space on the view and picks the correct camera preview size to match it. You might imagine that the CameraPreview looks a bit like this:
private void createCameraPreviewSession() {
try {
mSurfaceView.getHolder().setFixedSize(width, height);
Surface surface = mSurfaceView.getHolder().getSurface();
mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
if (mCameraDevice != null && mImageReader != null && fragmentState == CONNECTING_CAMERA) {
mCameraDevice.createCaptureSession(Arrays.asList(surface), createStateCallback(), null);
}
} catch (CameraAccessException e) {
Log.w(TAG, "Access exception during CaptureSession initialisation: " + e.getMessage());
Log.getStackTraceString(e);
}
}
On the current test device, the width and height are 1280x720 or 720x1280 depending on orientation. The weird part is that when I first open the activity that uses this preview, the camera view is distorted. When I rotate it, it stays distorted, when I rotate it back, it looks fine and the proportions generally, but not always, stay alright after that first rotation.
After a lot of poking around I have finally discovered the dumpsys SurfaceFlinger command, which allows me to see the details of my surface, and that gives me some new information. When the view is bad it looks like this:
Layer name
Z | Comp Type | Disp Frame (LTRB) | Source Crop (LTRB)
SurfaceView - com.myApp/com.myApp.CameraActivity#0
4294967294 | Device | 0 0 720 1229 | 39.0 0.0 960.0 720.0
com.myApp/com.myApp.CameraActivity#0
21055 | Device | 0 20 720 1280 | 0.0 20.0 720.0 1280.0
But when it is good it looks like this:
Layer name
Z | Comp Type | Disp Frame (LTRB) | Source Crop (LTRB)
SurfaceView - com.myApp/com.myApp.CameraActivity#0
4294967294 | Device | 0 0 720 1184 | 0.0 0.0 1280.0 720.0
com.myApp/com.myApp.CameraActivity#0
21055 | Device | 0 20 720 1280 | 0.0 20.0 720.0 1280.0
Clearly the Source Crop is being set completely differently in both cases - but can anyone tell me why? Where does the Source Crop come from and how can I change it? If I can't change it, is there a way to find what the Source Crop is set to for my surface? If I know that I should be able to find a way to compensate for the disparity.
from Android Camera2 dumpsys shows change in "Source Crop" how do I know what has caused it?
No comments:
Post a Comment