E/Camera: Unable to configure camera 0, timeout!

4,050 views
Skip to first unread message

박수한

unread,
May 5, 2020, 1:20:51 PM5/5/20
to Android CameraX Discussion Group
When I try to bind camerax to the previewview, I get the following error in bindPreview function (below).

2020-05-06 02:05:09.377 15364-15364/com.dearus.moca E/XN2: bindPreview
2020-05-06 02:05:09.377 15364-15364/com.dearus.moca E/XN2: 1080
2020-05-06 02:05:09.377 15364-15364/com.dearus.moca E/XN2: 1440
2020-05-06 02:05:10.424 15364-15364/com.dearus.moca E/NMLocationListener: onLocationChanged
2020-05-06 02:05:14.487 15364-15477/com.dearus.moca E/Camera: Unable to configure camera 0, timeout!

I know the code is structured awkwardly with this NMSingleton thing, it is because I need to invoke the camera from a native UI component for React Native (there's a lot of room for improvement here).
I would be grateful if someone could explain the possible cause of this timeout.

    fun bindPreview(cameraProvider: ProcessCameraProvider) {
Log.e("XN2", "bindPreview")
Log.e("XN2", NMSingleton.view!!.previewView.width.toString())
Log.e("XN2", NMSingleton.view!!.previewView.height.toString())

var preview: Preview = Preview.Builder()
.setTargetResolution(
Size(NMSingleton.view!!.width, NMSingleton.view!!.height))
.build()

var cameraSelector: CameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
/**
* FOR FUTURE VERSIONS SUPPORTING MULTI-CAMERA PHONES:
* var cameraSelector: CameraSelector = CameraSelector.Builder()
* .requireLensFacing(NMSingleton.desiredLens)
* .build()
*/
//        ImageAnalysis is being reimplemented. Not binding it during meantime.
//        var imageAnalysis: ImageAnalysis = ImageAnalysis.Builder()
// .setTargetResolution(
// Size(NMSingleton.view!!.width, NMSingleton.view!!.height))
// .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
// .build()
//
// imageAnalysis.setAnalyzer(executor, NMImageAnalyzer())

var imageCapture: ImageCapture = ImageCapture.Builder()
.build()

// var camera = cameraProvider.bindToLifecycle(this as LifecycleOwner, cameraSelector, imageAnalysis, preview, imageCapture)
var camera = cameraProvider.bindToLifecycle(this as LifecycleOwner, cameraSelector, preview, imageCapture)
preview.setSurfaceProvider(NMSingleton.view!!.previewView.createSurfaceProvider(camera.cameraInfo))
}

Scott Nien

unread,
May 7, 2020, 3:45:42 AM5/7/20
to 박수한, Android CameraX Discussion Group
Is the previewView visible when you bindToLifecycle ?  

If not,  then it could cause CameraX to fail to get the surface from PreviewView and then the timeout happens. 

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/84eab40e-61de-4a72-bd58-3a3514a32256%40android.com.

박수한

unread,
May 8, 2020, 12:47:15 PM5/8/20
to Android CameraX Discussion Group, sooba...@gmail.com
I believe the view is visible when I bindToLifecycle, the rest of the native view loads successfully and the same code works when I run it without loading it onto the React Native app so I believe it's a problem with how the React Native framework handles view lifecycles. 

2020년 5월 7일 목요일 오후 4시 45분 42초 UTC+9, Scott Nien 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

Scott Nien

unread,
May 10, 2020, 11:34:01 AM5/10/20
to 박수한, Android CameraX Discussion Group
Some ideas.  
(1) try force use TextureView in PreviewView by calling previewView.setPreferredImplementationMode(PreviewView.ImplementationMode.SURFACE_VIEW); 
before preview.setSurfaceProvider(..) 
TextureView is always more compatible than SurfaceView
(2)if you still meet the problem,  try to initiate a TextureView directly and see if it can get 
   TextureView.SurfaceTextureListene$onSurfaceTextureAvailable being called   (you need to set the lister by 
   mTextureView.setSurfaceTextureListener)

To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/f29f7d28-f05d-4a8d-94a6-9a92a12df774%40android.com.

Scott Nien

unread,
May 10, 2020, 11:34:54 AM5/10/20
to 박수한, Android CameraX Discussion Group
sorry ,  it should be TEXTURE_VIEW
(1) try force use TextureView in PreviewView by calling previewView.setPreferredImplementationMode(PreviewView.ImplementationMode.TEXTURE_VIEW); 

박수한

unread,
May 15, 2020, 10:20:06 AM5/15/20
to Android CameraX Discussion Group
Thanks. I have figured that convincing our executives to just stop using React Native everywhere was easier, but I'll try your solution out and write the results here when I have time to do so!

2020년 5월 11일 월요일 오전 12시 34분 54초 UTC+9, Scott Nien 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.
Message has been deleted

Jansel Valentin

unread,
May 24, 2020, 6:26:31 PM5/24/20
to Android CameraX Discussion Group
Basically, the issue is that react-native is not triggering the re-layout pass to the PreviewView after the SurfaceView is added to it because the addition is posted by CameraX to a different task than the currently displaying the view and the SurfaceView never get created in the first place, hence not fulfilling the CameraRequest sent to the Surface provider. 

Somehow in an Android environment, there are no issues because android automatically trigger the re-layout of a view whenever it hierarchy changes, but react-native after the first pass
of the onMeasure, onLayout it doesn't automatically trigger the re-layout pass on the changed view, that said, you need to try to detect that change by yourself and trigger the pass manually.

The related react-native issue is 17968 and for reference, you can see how I overcame it in here

Seph Soliman

unread,
Jun 17, 2020, 7:09:17 PM6/17/20
to Android CameraX Discussion Group
Just chiming in here to confirm that Jansel's hunch was probably on point. I have posted a similar question where the view finder just remains black - and the fix was the same:

I had something like this:
init {
    viewFinder = PreviewView(context)
    viewFinder!!.layoutParams = LinearLayout.LayoutParams(
        LayoutParams.MATCH_PARENT,
        LayoutParams.MATCH_PARENT
    )
    addView(viewFinder, 0)

    viewFinder!!.post {
        startCamera()
    }
    installHierarchyFitter(viewFinder!!) // this was the fix
}

Using that exact code you posted, Jansel. It works. Thank you!

Balasubramanian Maruthavanan

unread,
Dec 8, 2020, 1:32:20 PM12/8/20
to Android CameraX Discussion Group, sca...@gmail.com
I am also facing this exactly problem even after calling the layoutHack on the constructor. Getting similar error. Please let me know what would be the cause? Actually looking out a fix for a long pending task. Thanks in advance.

Balasubramanian Maruthavanan

unread,
Dec 23, 2020, 12:04:31 AM12/23/20
to Android CameraX Discussion Group, sca...@gmail.com
I tried this solution. It worked. But the FPS drastically went down to ~5 (I am getting 15 fps on native). Through this solution, many frames are skipped badly which is no point in using this on RN as we don't have enough information on the frame to do any computation.

 Let me know if we have any worked on this. Thanks!

On Thursday, June 18, 2020 at 4:39:17 AM UTC+5:30 sca...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages