Status Update
Comments
ni...@google.com <ni...@google.com> #2
After some googling I found https://github.com/android/camera-samples/blob/master/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/utils/AutoFitPreviewBuilder.kt which does what I want. Would it be possible to fold this into the main library or at least make it configurable without the need for that class?
Description
Please describe your issue and include details such as the version of CameraX you are using and any relevant logs related to your issue.
Crash logs:
04-16 19:46:36.529 17173-17183/com.android.example.cameraxbasic I/art: Background sticky concurrent mark sweep GC freed 392336(9MB) AllocSpace objects, 1(904KB) LOS objects, 14% free, 32MB/37MB, paused 10.437ms total 204.047ms
04-16 19:46:36.743 17173-17269/com.android.example.cameraxbasic W/ImageReader_JNI: Unable to acquire a lockedBuffer, very likely client tries to lock more than maxImages buffers
04-16 19:46:36.746 17173-17209/com.android.example.cameraxbasic D/CaptureSession: Attempting to send capture request onConfigured
04-16 19:46:36.746 17173-17209/com.android.example.cameraxbasic D/CaptureSession: Issuing request for session.
04-16 19:46:36.751 17173-17209/com.android.example.cameraxbasic D/CaptureSession: CameraCaptureSession.onConfigured() mState=OPENED
04-16 19:46:36.751 17173-17209/com.android.example.cameraxbasic D/CaptureSession: CameraCaptureSession.onReady() OPENED
04-16 19:46:36.751 17173-17209/com.android.example.cameraxbasic D/CaptureSession: CameraCaptureSession.onReady() OPENED
04-16 19:46:36.751 17173-17209/com.android.example.cameraxbasic D/CaptureSession: CameraCaptureSession.onClosed()
04-16 19:46:36.972 17173-17270/com.android.example.cameraxbasic D/CameraXBasic: Average luminosity: 106.80331380208334
04-16 19:46:36.972 17173-17270/com.android.example.cameraxbasic W/ImageReader_JNI: ImageReader#close called before Image#close, consider calling Image#close first
04-16 19:46:36.973 17173-17270/com.android.example.cameraxbasic A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x9bd83000 in tid 17270 (pool-1-thread-1)
<refer last line>
// If at all possible, capture an Android logcat (
CAMERAX VERSION (ex - 1.0.0-alpha07)
camerax-core : 1.0.0-beta01
cameraX-view : 1.0.0-alpha08
CAMERA APPLICATION NAME AND VERSION: (Settings > Apps > (app name) > version)
ANDROID OS BUILD NUMBER: (Settings > About > Build number)
OS 6, 7, 9
DEVICE NAME: (Nexus 5X, Samsung S6, etc)
Pixel, Nexus 5, Samsung s5, Samsung s7
DESCRIPTION:
Issue is reproducible in google sample app as well.
App is crashing while running analyzer if preview usecase is being rebound.
LIST ANY EXPERIMENTAL FEATURES: (As an example - @ExperimentalCamera2Interop)
STEPS TO REPRODUCE:
1. Added below method in sample app
private fun rebindPreview() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()
cameraProvider.unbind(preview)
// Get screen metrics used to setup camera for full screen resolution
val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }
Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")
val screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)
Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")
val rotation = viewFinder.display.rotation
// Preview
preview = Preview.Builder()
// We request aspect ratio but no resolution
.setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation
.setTargetRotation(rotation)
.build()
// Attach the viewfinder's surface provider to preview use case
preview?.setSurfaceProvider(viewFinder.previewSurfaceProvider)
try {
// A variable number of use-cases can be passed here -
// camera provides access to CameraControl & CameraInfo
camera = cameraProvider.bindToLifecycle(
this, cameraSelector, preview)
} catch (exc: Exception) {
Log.e(TAG, "Use case binding failed", exc)
}
}
2. Add a button and register for its click in which we call above method
controls.findViewById<ImageButton>(R.id.rebind_preview_btn).setOnClickListener {
rebindPreview()
}
3. Add below layout in "camera_ui_container.xml" file
<ImageButton
android:id="@+id/rebind_preview_btn"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="@dimen/margin_xlarge"
android:layout_marginStart="@dimen/margin_small"
android:padding="@dimen/spacing_small"
android:scaleType="fitCenter"
android:background="@android:color/white"
app:srcCompat="@drawable/ic_share"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:contentDescription="@string/switch_camera_button_alt" />
please position accordingly
4. Install and run app, click on above added button.
OBSERVED RESULTS:
App is getting crashed with below error:
04-16 19:46:36.972 17173-17270/com.android.example.cameraxbasic W/ImageReader_JNI: ImageReader#close called before Image#close, consider calling Image#close first
04-16 19:46:36.973 17173-17270/com.android.example.cameraxbasic A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x9bd83000 in tid 17270 (pool-1-thread-1)
EXPECTED RESULTS:
App should not crash and work as expected.
REPRODUCIBILITY: (5 of 5, 1 of 100, etc)
100% reproducible
ADDITIONAL INFORMATION:
CODE FRAGMENTS (this will help us troubleshoot your issues):