Giter VIP home page Giter VIP logo

camera-samples's People

Contributors

akindofyoga avatar alexcohn avatar bazted avatar borgerag avatar charcoalchen avatar chmod644 avatar codingjeremy avatar donovanfm avatar epeevs avatar ggfan avatar jorisbodin avatar jsaund avatar kailianc avatar kokoro-team avatar lnishan avatar luncliff avatar madebymozart avatar martinl avatar mlykotom avatar owahltinez avatar panabuntu avatar pfmaggi avatar romanofranz avatar ryondev avatar sam5727 avatar subhrajyotisen avatar tiger-google avatar tougee avatar yasith avatar zhaonian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

camera-samples's Issues

Lifecycle binding

in CameraFragment you call

CameraX.bindToLifecycle(this, preview, imageCapture, imageAnalyzer)

meaning you bind it to fragment's lifecycle. But you call this method on onViewCreated() which means you would receive the old lifecycleOwner. To avoid crashing you every time also call CameraX.unbindAll() which is some sort of work around.
Instead it would be better to call CameraX.bindToLifecycle() with viewLifecycleOwner. Then you can delete CameraX.unbindAll()

Thus, it seems like you have misused fragment's lifecycle with view's lifecycle. Correct me I am wrong.
Thanks

Should TextureView be released when preview use case is no more used?

I found in the Preview class documentation:

It is the application's responsibility to release the last SurfaceTexture returned by Preview.PreviewOutput.getSurfaceTexture() when a new SurfaceTexture is provided via an update or when the user is finished with the use case.

Does it mean that in onDestroyView along with unbindAll, the SurfaceTexture of viewFinder shouldn't be released?

CameraX - Preview is wrong sized and the quality is very bad on some devices

I use AutoFitPreviewBuilder in the same way as in sample but there is a problem on some devices e.g. on my Samsung s9 everything works fine but on my older(SM s6) this line:
val newViewFinderDimens = Size(right - left, bottom - top) generate wrong values and there are ugly stripes(left and right side), the height is good. On my friend's phone it works well but there is another issue updateTransform(viewFinder, rotation, it.textureSize, viewFinderDimens) value it.textureSize is wrong. What can cose this problem if on some devices is everything all right. Could it be problem with CamerX API or the problem is on my side?

Preview is stretched in width

While the captured image shows the correct aspect ratio, the preview is obviously stretched in width. I've tried to set different aspect ratios, e.g. 1/1 or viewFinderWidth/viewFinderHeight to the preview config, as well as transforming the scale of the viewFinder by

matrix.setScale(outputTextureWidth/viewFinderWidth, outputTextureHeight/viewFinderHeight); viewFinder.setTransform(matrix);

but none of this could resolve the issue.

(Capture config was setup with the same values as the preview config, i.e. targetAspectRatio and targetResolution)

Phone: Huawei P9 lite
Android: 7.0

How to bind CameraX Preview and other texture

I don't know where CameraX's question should be asked.

I recently tried to develop a flutter plugin with cameraX, but I found that there was no way to simply bind Preview to flutter's Texture.

In the past, I only needed use camera.setPreviewTexture(surfaceTexture.surfaceTexture()) to bind camera and texture, now I can't find the api.

val preview = Preview(previewConfig)
preview.setOnPreviewOutputUpdateListener {
  // it.surfaceTexture // the surfaceTexture is a readable texture.
}

Crash when returning back to camera app from background

When resuming the app from background app is crashing with surface error.

Steps to replicate

  1. Start the sample app
  2. Press Home Button
  3. Start the app again from recent apps

OS, Android 9.0
Device: Google Pixel 2 XL

Stacktrace:
Process: com.android.example.cameraxbasic, PID: 3428
java.lang.IllegalArgumentException: Cannot setSurfaceTexture to a released SurfaceTexture
at android.view.TextureView.setSurfaceTexture(TextureView.java:744)
at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder$1.onUpdated(AutoFitPreviewBuilder.kt:106)
at androidx.camera.core.Preview.updateOutput(Preview.java:448)
at androidx.camera.core.Preview.invalidateMetadata(Preview.java:389)
at androidx.camera.core.Preview.setTargetRotation(Preview.java:307)
at com.android.example.cameraxbasic.fragments.CameraFragment$displayListener$1.onDisplayChanged(CameraFragment.kt:124)
at android.hardware.display.DisplayManagerGlobal$DisplayListenerDelegate.handleMessage(DisplayManagerGlobal.java:633)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Crash in the Camera2RawFragment on a Samsung J5

The Camera2Raw sample is crashing on a Samsung J5 8.1.0 device.
See the stacktrace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.android.camera2raw, PID: 14934
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.hardware.camera2.CameraCharacteristics.get(android.hardware.camera2.CameraCharacteristics$Key)' on a null object reference
        at com.example.android.camera2raw.Camera2RawFragment.configureTransform(Camera2RawFragment.java:1046)
        at com.example.android.camera2raw.Camera2RawFragment.access$000(Camera2RawFragment.java:121)
        at com.example.android.camera2raw.Camera2RawFragment$1.onSurfaceTextureAvailable(Camera2RawFragment.java:212)
        at android.view.TextureView.getHardwareLayer(TextureView.java:390)
        at android.view.TextureView.draw(TextureView.java:339)
        at android.view.View.updateDisplayListIfDirty(View.java:19428)
        at android.view.View.draw(View.java:20206)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4459)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4245)
        at android.view.View.updateDisplayListIfDirty(View.java:19419)
        at android.view.View.draw(View.java:20206)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4459)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4245)
        at android.view.View.draw(View.java:20486)
        at android.view.View.updateDisplayListIfDirty(View.java:19428)
        at android.view.View.draw(View.java:20206)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4459)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4245)
        at android.view.View.updateDisplayListIfDirty(View.java:19419)
        at android.view.View.draw(View.java:20206)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4459)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4245)
        at android.view.View.updateDisplayListIfDirty(View.java:19419)
        at android.view.View.draw(View.java:20206)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4459)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4245)
        at android.view.View.draw(View.java:20486)
        at com.android.internal.policy.DecorView.draw(DecorView.java:990)
        at android.view.View.updateDisplayListIfDirty(View.java:19428)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:719)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:725)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:833)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:3567)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3354)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2889)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1843)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7978)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
        at android.view.Choreographer.doCallbacks(Choreographer.java:723)
        at android.view.Choreographer.doFrame(Choreographer.java:658)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Application terminated.

ImageCapture.OnImageSavedListener

I'm having problem implementing this in my app.
It is single activity application.
File gets created but after that ImageCapture.OnImageSavedListener throws onError
Size of file is 0B.
Error:
error: ImageCapture.UseCaseError:
UNKNOWN_ERROR

message: String:
Failed to encode mImage

exc: Throwable?:
cause = {ImageUtil$EncodeFailedException@5923} "androidx.camera.core.ImageUtil$EncodeFailedException: cropImage failed to encode jpeg." detailMessage = "cropImage failed to encode jpeg."

Have no idea what this could be.
Appreciate any help.
Thanks

Using ImageAnalysis is extremely slow on low-spec Nokia 5.1

The CameraXBasic sample runs really slow on Nokia 5.1 because of the imageAnalyzer when binding the usecase in CameraX.bindToLifecycle(viewLifecycleOwner, preview, imageAnalyzer). If one removes the imageAnalyzer parameter, the frame rate gets normal again.

Are you doing any copy before calling the base function fun analyze(image: ImageProxy, rotationDegrees: Int) { ?

Logo design

Hi, how are you? I'd like to collaborate on your open source project and propose free logo/icon design for this project. If it's something you're interested in, please, let me know!
Best Regards
Zuur

How to specify video resolution for VideoCapture ?

I want to set video resolution width=540 and height=960, but resulted video has width=360 and height=640.
val videoCaptureConfig = VideoCaptureConfig.Builder().apply { setLensFacing(lensFacing) setTargetRotation(viewFinder.display.rotation) setTargetResolution(Size(540, 960)) setMaxResolution(Size(540, 960)) }.build()

Black TextureView after navigation

I use a BottomNavigationView to navigate between my camera fragment and another one.
On the start of my app the camera preview is loaded correctly.
If I navigate to my second fragment and back again, CameraX is successfully bound to the lifecycle, but the TextureView is black.

I can resolve this by adding Thread.sleep(330) before CameraX.bindToLifecycle() but this is a bad solution, because it adds some delay before showing the preview.

What can I do to solve this problem without this delay?

IllegalArgumentException: No supported surface combination is found

I added VideoCapture to the sample

// Create a configuration object for the video use case
        val videoCaptureConfig = VideoCaptureConfig.Builder().apply {
            setLensFacing(lensFacing)
            // We request aspect ratio but no resolution to match preview config but letting
            // CameraX optimize for whatever specific resolution best fits requested capture mode
            setTargetAspectRatio(screenAspectRatio)
            // Set initial target rotation, we will have to call this again if rotation changes
            // during the lifecycle of this use case
            setTargetRotation(viewFinder.display.rotation)
        }.build()

        videoCapture = VideoCapture(videoCaptureConfig)

And modify this line:
CameraX.bindToLifecycle(viewLifecycleOwner, preview, imageCapture, videoCapture)

On some devices y catch exception:

    java.lang.IllegalArgumentException: No supported surface combination is found for camera device - Id : 0.  May be attempting to bind too many use cases.
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.getSuggestedResolutions(Camera2DeviceSurfaceManager.java:176)

I cant find any way to fix it. Can you help me?

Crash CameraXBasic example when revoking CAMERA permission

Hey there!

So I've installed the app example CameraXBasic, have it running, granted camera permission. Then I navigate to settings, revoke that permission, go back to the app and I got a crash. I was expecting rather a warning or a dialog of some kind.

This is not the behaviour in example Camera2BasicKotlin where this exact flow is managed gracefully, and you see a dialog "This sample needs camera permission."

Device: Android Pixel Q, patch 05/07.

Logcat:

     --------- beginning of crash
2019-07-22 17:14:46.154 19934-21147/? E/AndroidRuntime: FATAL EXCEPTION: CameraX-
    Process: com.android.example.cameraxbasic, PID: 19934
    java.lang.SecurityException: validateClientPermissionsLocked:976: Caller "com.android.example.cameraxbasic" (PID 10402, UID 19934) cannot open camera "0" without camera permission
        at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:793)
        at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:426)
        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:588)
        at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:516)
        at androidx.camera.camera2.impl.Camera.openCameraDevice(Camera.java:595)
        at androidx.camera.camera2.impl.Camera.open(Camera.java:151)
        at androidx.camera.camera2.impl.Camera.addOnlineUseCase(Camera.java:505)
        at androidx.camera.camera2.impl.Camera$10.run(Camera.java:488)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: android.os.ServiceSpecificException: validateClientPermissionsLocked:976: Caller "com.android.example.cameraxbasic" (PID 10402, UID 19934) cannot open camera "0" without camera permission (code 1)
        at android.os.Parcel.createException(Parcel.java:2085)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.os.Parcel.readException(Parcel.java:1987)
        at android.hardware.ICameraService$Stub$Proxy.connectDevice(ICameraService.java:583)
        at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:389)
        at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:588) 
        at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:516) 
        at androidx.camera.camera2.impl.Camera.openCameraDevice(Camera.java:595) 
        at androidx.camera.camera2.impl.Camera.open(Camera.java:151) 
        at androidx.camera.camera2.impl.Camera.addOnlineUseCase(Camera.java:505) 
        at androidx.camera.camera2.impl.Camera$10.run(Camera.java:488) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 

Does this make sense? I think it may be missing appropriate permission check?

Cheers! (:

App crashes while starting CameraFragment

App crashes at first run.

2019-05-10 10:11:08.013 3579-3579/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.example.cameraxbasic, PID: 3579
    java.lang.ArithmeticException: divide by zero
        at androidx.camera.camera2.impl.SupportedSurfaceCombination.getAllPossibleSizeArrangements(SupportedSurfaceCombination.java:435)
        at androidx.camera.camera2.impl.SupportedSurfaceCombination.getSuggestedResolutions(SupportedSurfaceCombination.java:195)
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.getSuggestedResolutions(Camera2DeviceSurfaceManager.java:185)
        at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:449)
        at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:144)
        at com.android.example.cameraxbasic.fragments.CameraFragment.bindCameraUseCases(CameraFragment.kt:313)
        at com.android.example.cameraxbasic.fragments.CameraFragment.access$bindCameraUseCases(CameraFragment.kt:104)
        at com.android.example.cameraxbasic.fragments.CameraFragment$onViewCreated$1.run(CameraFragment.kt:241)
        at android.os.Handler.handleCallback(Handler.java:878)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:209)
        at android.app.ActivityThread.main(ActivityThread.java:7046)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
2019-05-10 10:11:32.185 4832-4832/com.android.example.cameraxbasic E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.example.cameraxbasic, PID: 4832
    java.lang.ArithmeticException: divide by zero
        at androidx.camera.camera2.impl.SupportedSurfaceCombination.getAllPossibleSizeArrangements(SupportedSurfaceCombination.java:435)
        at androidx.camera.camera2.impl.SupportedSurfaceCombination.getSuggestedResolutions(SupportedSurfaceCombination.java:195)
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.getSuggestedResolutions(Camera2DeviceSurfaceManager.java:185)
        at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:449)
        at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:144)
        at com.android.example.cameraxbasic.fragments.CameraFragment.bindCameraUseCases(CameraFragment.kt:313)
        at com.android.example.cameraxbasic.fragments.CameraFragment.access$bindCameraUseCases(CameraFragment.kt:104)
        at com.android.example.cameraxbasic.fragments.CameraFragment$onViewCreated$1.run(CameraFragment.kt:241)
        at android.os.Handler.handleCallback(Handler.java:878)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:209)
        at android.app.ActivityThread.main(ActivityThread.java:7046)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)

Preview callback will unregister DisplayListener

I see that you will unregister the DisplayListener here in this line. In my test, the first onUpdate call will remove the viewFinder and then add it again just like what the code does, but it will unregister the listener right away, so when I try to rotate the device it will never be called.

How this supposes to be?

P/S If I try to register the listener in "onViewAttached..." it will be fine.

Bug at CameraXBasic example : camera switch

When calling bindCameraUseCases at camera_switch_button click listener, it doesn't work correctly with Galaxy S10+, Note 8

If I add CameraX.unbindAll() code to bindCameraUseCases() function at start line, it works normarlly.

private fun bindCameraUseCases() {
        CameraX.unbindAll()
        ...
}

HandlerThread need quit

CameraXBasic Demo setup ImageAnalysisConfig Use HandlerThread as worker thread but not quit when Re-bindCameraUseCases.
Worker Threads increasing fast when config changes or switch camera

how to close audio record when video recording

when the app want to video record, can let dev choose if use record audio pls?
I don't want record audio now, and don't want request record audio permission too.
But if I don't request record audio permission , the app will crash.

Capturing DNG

Hi,

so in theory you can change the ImageFormat in the UseCase to something like RAW_SENSOR. However, each Callback of ImageCapture mentions that

The image capture method fully supports the JPEG format.

So I have not looked at what the API does behind the scenes, but is this a bug in the documentation or is this currently not possible because of behind the scenes plumbing?

CameraX: NullPointerException when trying to record video

I have a simple video recording app set up like this:

VideoCaptureConfig videoCaptureConfig = new VideoCaptureConfig.Builder()
        .setLensFacing(CameraX.LensFacing.BACK)
        .setTargetAspectRatio(new Rational(16, 9))
        .setTargetRotation(viewFinder.getDisplay().getRotation())
        .build();
videoCapture = new VideoCapture(videoCaptureConfig);

CameraX.bindToLifecycle(this, preview, videoCapture);

...

 videoCapture.startRecording(file, new VideoCapture.OnVideoSavedListener() { ... });

which leads to the following NullPointerException:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioRecord.startRecording()' on a null object reference
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:262)
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:236)
        at de.twometer.stream.cam.CameraActivity.lambda$onCreate$1$CameraActivity(CameraActivity.java:77)
        at de.twometer.stream.cam.-$$Lambda$CameraActivity$MvEAnqH_74mMgbMAcSbB_pNoJ3k.onClick(Unknown Source:4)
        at android.view.View.performClick(View.java:7352)
        at android.view.View.performClickInternal(View.java:7318)
        at android.view.View.access$3200(View.java:846)
        at android.view.View$PerformClick.run(View.java:27807)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I am using CameraX version 1.0.0-alpha04

CameraX: Camera Crashes After a Few Rotations

Running the sample app located here: https://github.com/android/camera/tree/master/CameraXBasic on my Pixel3.

After rotating the app 4 or 5 times, the TextureView goes black and the live camera feed is gone. Killing the app and restarting it, doesn't fix the issue. Attached are the logs. I also had the same issue with the sample app for Camera2. Not sure if this is an issue with the sample apps or an underlying issue with the camera x library (version: 1.0.0-alpha03).

Cancel coroutineContext

The CameraFragment implements CoroutineScope so it have to implement CoroutineContext. For that context you create new instance of Job and hold in class filed. Later, onDestroy() you call job.cancel(). However, it is better to cancel the coroutineContext itself. So that you also don't need to hold explicit reference to the job.
Moreover you could use
class CameraFragment : Fragment(), CoroutineScope by CoroutineScope(Dispatchers.Default) so that you can remove couroutineContext and it's explicit cancellation in onDestroy().
You can take a look to the best practices described here https://kotlinlang.org/docs/reference/coroutines/coroutine-context-and-dispatchers.html#coroutine-scope

Photo look darker than normal camera

Photo from camerax example look darker than from normal camera

Device : Samsung Galaxy Tab S2 (SM-T819Y)
OS : Android 7.0

Normal Camera Application
64210966_308515680055889_4356966377278406656_n

CameraX Example Application
62649352_361011381267966_5040892769015431168_n

Is there any way to handle camera error?

I've got
CameraDevice.onError(): 0 with error: ERROR_CAMERA_DEVICE in logcat.

Is there any way to intercept this error in camera fragment?

Stacktrace:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2417) at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1106) at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:527) at androidx.camera.camera2.impl.CaptureSession.release(CaptureSession.java:357) at androidx.camera.camera2.impl.Camera.resetCaptureSession(Camera.java:692) at androidx.camera.camera2.impl.Camera$StateCallback.onError(Camera.java:976) at androidx.camera.core.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onError(CameraDeviceStateCallbacks.java:120) at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:1910) at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.lambda$Sm85frAzwGZVMAK-NE_gwckYXVQ(Unknown Source:0) at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$CameraDeviceCallbacks$Sm85frAzwGZVMAK-NE_gwckYXVQ.accept(Unknown Source:8) at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:258) at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:182) at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:77) at android.os.Handler.handleCallback(Handler.java:891) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:207) at android.os.HandlerThread.run(HandlerThread.java:65)

Question: how to enable focus on touch in cameraX

Hello, can you please explain how to enable focus on touch in camerax library. Is it feature currently available. There is no information about it in usage example and in official documentation. Thanks

Some device failed on switch lens

I've been run this demo in several devices, most of them working great, but failed on Moto X Force(android 7.0).
The system camera app working well, so I'm not sure it's a bug of cameraX library, and there are also some error log like this:

E/QCamera2HWI: camera_open failed with return code -87
E/CameraFlashlight: Could not open camera 0: -87
E/CameraClient: initialize: Camera 0: unable to initialize device: Too many users (-87)
E/CameraService: connectHelper: Could not initialize client from HAL module.

[CameraX]Can't find cameraId.

I use a usb camera at arm,the camera app is work well,but the CameraXBasic can't run.

This is the crash log.

2019-08-02 22:13:15.877 30884-30884/com.android.example.cameraxbasic E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.example.cameraxbasic, PID: 30884
    java.lang.IllegalArgumentException: Fail to find supported surface info - CameraId:null
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.requiresCorrectedAspectRatio(Camera2DeviceSurfaceManager.java:273)
        at androidx.camera.core.Preview.updateUseCaseConfig(Preview.java:387)
        at androidx.camera.core.UseCase.<init>(UseCase.java:92)
        at androidx.camera.core.Preview.<init>(Preview.java:99)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:91)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:39)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder$Companion.build(AutoFitPreviewBuilder.kt:243)
        at com.android.example.cameraxbasic.fragments.CameraFragment.bindCameraUseCases(CameraFragment.kt:279)
        at com.android.example.cameraxbasic.fragments.CameraFragment.access$bindCameraUseCases(CameraFragment.kt:89)
        at com.android.example.cameraxbasic.fragments.CameraFragment$onViewCreated$1.run(CameraFragment.kt:249)
        at android.os.Handler.handleCallback(Handler.java:755)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6141)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)


If I don't set the lensFacing


2019-08-02 22:08:40.401 17580-17580/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.example.cameraxbasic, PID: 17580
    java.lang.IllegalArgumentException: Unable to get camera ID for use case androidx.camera.core.Preview-a61300f3-0284-41a8-8845-92d868cda597
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.getCameraIdFromConfig(Camera2DeviceSurfaceManager.java:310)
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.requiresCorrectedAspectRatio(Camera2DeviceSurfaceManager.java:268)
        at androidx.camera.core.Preview.updateUseCaseConfig(Preview.java:387)
        at androidx.camera.core.UseCase.<init>(UseCase.java:92)
        at androidx.camera.core.Preview.<init>(Preview.java:99)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:91)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:39)
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder$Companion.build(AutoFitPreviewBuilder.kt:243)
        at com.android.example.cameraxbasic.fragments.CameraFragment.bindCameraUseCases(CameraFragment.kt:279)
        at com.android.example.cameraxbasic.fragments.CameraFragment.access$bindCameraUseCases(CameraFragment.kt:89)
        at com.android.example.cameraxbasic.fragments.CameraFragment$onViewCreated$1.run(CameraFragment.kt:249)
        at android.os.Handler.handleCallback(Handler.java:755)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6141)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
     Caused by: java.lang.IllegalArgumentException: Option does not exist: Option{id=camerax.core.camera.lensFacing, valueClass=class androidx.camera.core.CameraX$LensFacing, token=null}
        at androidx.camera.core.OptionsBundle.retrieveOption(OptionsBundle.java:107)
        at androidx.camera.core.PreviewConfig.retrieveOption(PreviewConfig.java:73)
        at androidx.camera.core.PreviewConfig.getLensFacing(PreviewConfig.java:178)
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.getCameraIdFromConfig(Camera2DeviceSurfaceManager.java:307)
        at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.requiresCorrectedAspectRatio(Camera2DeviceSurfaceManager.java:268) 
        at androidx.camera.core.Preview.updateUseCaseConfig(Preview.java:387) 
        at androidx.camera.core.UseCase.<init>(UseCase.java:92) 
        at androidx.camera.core.Preview.<init>(Preview.java:99) 
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:91) 
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder.<init>(AutoFitPreviewBuilder.kt:39) 
        at com.android.example.cameraxbasic.utils.AutoFitPreviewBuilder$Companion.build(AutoFitPreviewBuilder.kt:243) 
        at com.android.example.cameraxbasic.fragments.CameraFragment.bindCameraUseCases(CameraFragment.kt:279) 
        at com.android.example.cameraxbasic.fragments.CameraFragment.access$bindCameraUseCases(CameraFragment.kt:89) 
        at com.android.example.cameraxbasic.fragments.CameraFragment$onViewCreated$1.run(CameraFragment.kt:249) 
        at android.os.Handler.handleCallback(Handler.java:755) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6141) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802) 

I use this demo it work well,so what config is wrong?
https://github.com/pranaypatel512/CameraXDemo

How to zoom Camera?

I have tried to zoom camera with below code. Please check and correct me where I am wrong.

First I get a Preview from CameraX and tried to perform zoom using Preview like below.

   var config = CameraX.getDefaultUseCaseConfig(PreviewConfig::class.java, lensFacing)
   var preview = Preview(config)
   preview.zoom(zoom)

After preview.zoom() I just bind again with CameraX and get some error and it's not working.

   CameraX.bindToLifecycle(this, preview, imageCapture, videoCapture)

When the above code was not working, I also tried with CameraX.unbindAll() first and then I call CameraX.bindToLifecycle(). But face some error again and not get succeed.

Please provide an answer on below question or add some description in Wiki or Readme file related to the below question.

  1. How we can zoom camera?
  2. How to get max zoom from CameraX?

And also if possible please provide how to manage flash with CameraX?

Thank you!

Failed to preview when app goes to foreground from background on SC-04E(Samsung Galaxy S4, Android 5.0.1)

I've test the CameraFragment in a SC-04E(Samsung Galaxy S4, Android 5.0.1) and the app won't preview when app goes to foreground from background - It said "Surface with size (w=4128, h=2322) and format 0x1 is not valid". In other devices such as a Zenfone 4 max pro and a Google Pixel 2, it works perfectly.

  • SC-04E

(Pressed home button)

05-31 14:55:02.813 D/Camera: Use cases [Preview:androidx.camera.core.Preview-edb0fbae-d195-431e-8e5a-5390732e5d8e, ImageCapture:androidx.camera.core.ImageCapture-9c0a037b-355a-48aa-8b18-b8f0b5e9a158, ImageAnalysis:androidx.camera.core.ImageAnalysis-52fc8c63-b185-4577-bbb0-46562c4b1f2b] OFFLINE for camera 0
05-31 14:55:02.813 D/Camera: Closing camera: 0
05-31 14:55:02.813 V/ActivityThread: updateVisibility : ActivityRecord{20947a6a token=android.os.BinderProxy@222c7695 {com.android.example.cameraxbasic/com.android.example.cameraxbasic.MainActivity}} show : true
05-31 14:55:03.354 D/CameraXBasic: Average luminosity: 126.43569661458334. Frames per second: 1.0
05-31 14:55:03.404 E/BufferQueueProducer: [unnamed-12479-3] queueBuffer: BufferQueue has been abandoned
05-31 14:55:03.404 E/BufferQueueProducer: [unnamed-12479-3] dequeueBuffer: BufferQueue has been abandoned
05-31 14:55:03.534 E/BufferQueueProducer: [unnamed-12479-3] queueBuffer: BufferQueue has been abandoned
05-31 14:55:03.544 E/BufferQueueProducer: [unnamed-12479-3] dequeueBuffer: BufferQueue has been abandoned
05-31 14:55:03.654 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.654 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.664 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.664 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.664 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.674 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.674 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.674 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.674 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.684 E/BufferQueueProducer: [unnamed-12479-3] cancelBuffer: BufferQueue has been abandoned
05-31 14:55:03.824 D/Camera: Closing Capture Session
05-31 14:55:03.824 D/Camera: CameraDevice.onClosed(): 0
05-31 14:55:03.824 D/Camera: Closing Capture Session
05-31 14:55:05.246 D/CameraXBasic: Average luminosity: 129.89694986979165. Frames per second: 0.9
05-31 14:55:05.866 I/art: Background partial concurrent mark sweep GC freed 232289(5MB) AllocSpace objects, 3(1800KB) LOS objects, 39% free, 22MB/36MB, paused 7.934ms total 104.309ms
05-31 14:55:05.876 W/MessageQueue: Handler (android.os.Handler) {34809b5b} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (android.os.Handler) {34809b5b} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325)
at android.os.Handler.enqueueMessage(Handler.java:631)
at android.os.Handler.sendMessageAtFrontOfQueue(Handler.java:623)
at android.hardware.camera2.legacy.RequestThreadManager.quit(RequestThreadManager.java:941)
at android.hardware.camera2.legacy.LegacyCameraDevice.close(LegacyCameraDevice.java:444)
at android.hardware.camera2.legacy.LegacyCameraDevice.finalize(LegacyCameraDevice.java:468)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:194)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:177)
at java.lang.Thread.run(Thread.java:818)
05-31 14:55:05.876 W/CameraCaptureSession: Session 0: The camera device was already closed:
java.lang.IllegalStateException: CameraDevice was already closed
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1482)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:677)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:328)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.finalize(CameraCaptureSessionImpl.java:561)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:194)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:177)
at java.lang.Thread.run(Thread.java:818)
05-31 14:55:05.876 D/CaptureSession: CameraCaptureSession.onClosed()

(The app has went to foreground)

05-31 14:57:07.455 D/CaptureSession: Opening capture session.
05-31 14:57:07.465 I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
05-31 14:57:07.465 I/RequestThread-0: Configure outputs: 3 surfaces configured.
05-31 14:57:07.465 D/Camera: app passed NULL surface
05-31 14:57:07.465 I/RequestThread-0: configureOutputs - set take picture size to 4128x2322
05-31 14:57:07.515 I/CameraDeviceState: Legacy camera service transitioning to state IDLE
05-31 14:57:07.515 D/Camera: Use case Preview:androidx.camera.core.Preview-edb0fbae-d195-431e-8e5a-5390732e5d8e RESET for camera 0
05-31 14:57:07.525 D/UseCaseAttachState: Active and online use case: [androidx.camera.core.Preview-edb0fbae-d195-431e-8e5a-5390732e5d8e, androidx.camera.core.ImageAnalysis-52fc8c63-b185-4577-bbb0-46562c4b1f2b, androidx.camera.core.ImageCapture-9c0a037b-355a-48aa-8b18-b8f0b5e9a158] for camera: 0
05-31 14:57:07.525 D/UseCaseAttachState: All use case: [androidx.camera.core.Preview-edb0fbae-d195-431e-8e5a-5390732e5d8e, androidx.camera.core.ImageAnalysis-52fc8c63-b185-4577-bbb0-46562c4b1f2b, androidx.camera.core.ImageCapture-9c0a037b-355a-48aa-8b18-b8f0b5e9a158] for camera: 0
05-31 14:57:07.525 D/Camera: Closing Capture Session
05-31 14:57:07.525 D/CaptureSession: Opening capture session.
05-31 14:57:07.525 E/CameraDevice-0-LE: Surface with size (w=4128, h=2322) and format 0x1 is not valid, size not in valid set: [1440x1080, 1280x720, 1056x864, 960x720, 720x480, 640x480, 320x240, 176x144]
05-31 14:57:07.525 W/CameraDevice-JV-0: Stream configuration failed
05-31 14:57:07.525 E/CameraCaptureSession: Session 1: Failed to create capture session; configuration failed
05-31 14:57:07.525 D/CaptureSession: CameraCaptureSession.onConfigured()
05-31 14:57:07.525 E/CaptureSession: CameraCaptureSession.onConfiguredFailed()
05-31 14:57:07.525 D/CaptureSession: CameraCaptureSession.onReady()
05-31 14:57:07.525 D/CaptureSession: CameraCaptureSession.onClosed()

  • Zenfone 4 Max Pro

(Pressed home button)

2019-05-31 15:12:42.514 D/Camera: Use cases [ImageCapture:androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, Preview:androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57, ImageAnalysis:androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728] OFFLINE for camera 0
2019-05-31 15:12:42.516 D/Camera: Closing Capture Session
2019-05-31 15:12:42.520 D/Camera: Start configAndClose.
2019-05-31 15:12:42.521 D/CaptureSession: Opening capture session.
2019-05-31 15:12:42.521 I/RequestQueue: Repeating capture request cancelled.
2019-05-31 15:12:42.574 I/CameraDeviceState: Legacy camera service transitioning to state IDLE
2019-05-31 15:12:42.577 I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
2019-05-31 15:12:42.580 I/RequestThread-0: Configure outputs: 1 surfaces configured.
2019-05-31 15:12:42.650 D/Camera: app passed NULL surface
2019-05-31 15:12:42.708 D/CameraXBasic: Average luminosity: 81.16932709619341. Frames per second: 19.3
2019-05-31 15:12:42.722 I/CameraDeviceState: Legacy camera service transitioning to state IDLE
2019-05-31 15:12:42.724 D/CaptureSession: Attempting to send capture request onConfigured
2019-05-31 15:12:42.724 D/CaptureSession: Skipping issueRepeatingCaptureRequests for no configuration case.
2019-05-31 15:12:42.724 D/CaptureSession: CameraCaptureSession.onConfigured()
2019-05-31 15:12:42.726 D/CaptureSession: CameraCaptureSession.onReady()
2019-05-31 15:12:42.728 D/CaptureSession: CameraCaptureSession.onReady()
2019-05-31 15:12:43.059 E/CameraManagerGlobal: [yinyapeng_cts]
2019-05-31 15:12:43.092 D/Camera: Closing Capture Session
2019-05-31 15:12:43.092 D/CaptureSession: CameraCaptureSession.onClosed()
2019-05-31 15:12:43.093 D/CaptureSession: CameraCaptureSession.onClosed()
2019-05-31 15:12:43.093 D/Camera: CameraDevice.onClosed(): 0
2019-05-31 15:12:43.093 D/Camera: Closing Capture Session

(The app has went to foreground)

2019-05-31 15:12:48.277 D/Camera: Use cases [ImageCapture:androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, Preview:androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57, ImageAnalysis:androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728] ONLINE for camera 0
2019-05-31 15:12:48.278 D/Camera: Opening camera: 0
2019-05-31 15:12:48.279 D/UseCaseAttachState: All use case: [androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728, androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57] for camera: 0
2019-05-31 15:12:48.319 I/CameraManager: Using legacy camera HAL.
2019-05-31 15:12:48.448 E/CameraManagerGlobal: [yinyapeng_cts]
2019-05-31 15:12:48.522 D/UseCaseAttachState: Active and online use case: [androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728, androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57] for camera: 0
2019-05-31 15:12:48.523 D/UseCaseAttachState: All use case: [androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728, androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57] for camera: 0
2019-05-31 15:12:48.524 D/Camera: Closing Capture Session
2019-05-31 15:12:48.524 D/Camera: CameraDevice is null
2019-05-31 15:12:48.524 D/Camera: CameraDevice.onOpened(): 0
2019-05-31 15:12:48.525 D/UseCaseAttachState: All use case: [androidx.camera.core.ImageCapture-c311f535-130e-4820-b1ec-bf7edc5e890f, androidx.camera.core.ImageAnalysis-2cad4b2a-0f2c-423b-a9be-da637d372728, androidx.camera.core.Preview-990f8aa3-2403-4cdb-ac42-4592cf850b57] for camera: 0
2019-05-31 15:12:48.525 D/Camera: Closing Capture Session
2019-05-31 15:12:48.527 D/CaptureSession: Opening capture session.
2019-05-31 15:12:48.531 I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
2019-05-31 15:12:48.531 I/RequestThread-0: Configure outputs: 3 surfaces configured.
2019-05-31 15:12:48.531 D/Camera: app passed NULL surface
2019-05-31 15:12:48.539 I/RequestThread-0: configureOutputs - set take picture size to 3840x2160
2019-05-31 15:12:48.550 I/art: Do partial code cache collection, code=53KB, data=60KB
2019-05-31 15:12:48.550 I/art: After code cache collection, code=51KB, data=59KB
2019-05-31 15:12:48.550 I/art: Increasing code cache capacity to 256KB
2019-05-31 15:12:48.563 I/CameraDeviceState: Legacy camera service transitioning to state IDLE
2019-05-31 15:12:48.565 D/CaptureSession: Attempting to send capture request onConfigured
2019-05-31 15:12:48.565 D/CaptureSession: Issuing request for session.
2019-05-31 15:12:48.568 I/RequestQueue: Repeating capture request set.
2019-05-31 15:12:48.568 D/CaptureSession: CameraCaptureSession.onConfigured()
2019-05-31 15:12:48.568 D/CaptureSession: CameraCaptureSession.onReady()
2019-05-31 15:12:48.574 W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
2019-05-31 15:12:48.574 W/LegacyRequestMapper: Only received metering rectangles with weight 0.
2019-05-31 15:12:48.574 W/LegacyRequestMapper: Only received metering rectangles with weight 0.
2019-05-31 15:12:48.834 I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
2019-05-31 15:12:48.975 D/CameraXBasic: Average luminosity: 42.856079603909464. Frames per second: 1.1
2019-05-31 15:12:50.062 D/CameraXBasic: Average luminosity: 81.39527070473251. Frames per second: 29.5
2019-05-31 15:12:51.052 D/CameraXBasic: Average luminosity: 92.31874115869341. Frames per second: 35.0

CameraXBasic Sample looks horrible on Pixel C tablet

Tablet model: Pixel C
Android Version: 8.1.0
CameraX Version: 1.0.0-alpha03

Here is a screenshot of how the camera in the CameraXBasic sample looks like after I build and run it.

Screenshot_20190815-124813

I tested it on other tablets and it looks good.

DisplayListener will update ViewFinder on the change of ... other display?

In the DisplayListener callback for onChanged(), I see that you will update the transform of TextureView if the change is for other logical display. Can I know why? I guess that if I attach my phone to an external display, and when that display is changed, my ViewFinder on the phone need to be adjusted as well. Is this correct?

Frontal flashlight

Are you going to support frontal flashlight? (set screen brightness to max and back). I assume it would be really handy.

App crashes after switching cameras multiple times

When you try to switch cameras by clicking really fast in a switch button, the app crashes due to this exception:

E/Legacy-CameraDevice-JNI: getNativeWindow: Surface had no valid native window.
E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeDetectSurfaceDimens: Could not retrieve native window from surface.
E/AndroidRuntime: FATAL EXCEPTION: CameraX-
    Process: com.android.example.cameraxbasic, PID: 11109
    java.lang.IllegalArgumentException: Surface was abandoned
        at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:84)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:260)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:145)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:508)
        at androidx.camera.camera2.impl.CaptureSession.open(CaptureSession.java:196)
        at androidx.camera.camera2.impl.Camera.openCaptureSession(Camera.java:535)
        at androidx.camera.camera2.impl.Camera$StateCallback.onOpened(Camera.java:743)
        at androidx.camera.core.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onOpened(CameraDeviceStateCallbacks.java:99)
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
        at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:73)
        at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:606)
        at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:82)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:260) 
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:145) 
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:508) 
        at androidx.camera.camera2.impl.CaptureSession.open(CaptureSession.java:196) 
        at androidx.camera.camera2.impl.Camera.openCaptureSession(Camera.java:535) 
        at androidx.camera.camera2.impl.Camera$StateCallback.onOpened(Camera.java:743) 
        at androidx.camera.core.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onOpened(CameraDeviceStateCallbacks.java:99) 
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 

To reproduce this issue just run the app and tap switch button multiple times (like 15-20). I know this is not production ready app and tapping so many times fakes user behavior, but I have encountered the same issue in my own implementation just because of fragment replacing. It would be much appreciated if someone give a clue or some explanation of this issue.

App crashes after switching to front camera

Hi, I installed the app and when I try to switch to front camera the app crashes.
LG G7, Andorid 9

    Process: com.android.example.cameraxbasic, PID: 729
    java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
        at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:674)
        at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:1093)
        at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:1139)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:298)
        at androidx.camera.camera2.impl.CaptureSession.issueRepeatingCaptureRequests(CaptureSession.java:443)
        at androidx.camera.camera2.impl.CaptureSession$StateCallback.onConfigured(CaptureSession.java:604)
        at androidx.camera.core.CameraCaptureSessionStateCallbacks$ComboSessionStateCallback.onConfigured(CameraCaptureSessionStateCallbacks.java:115)
        at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigured$0(CallbackProxies.java:53)
        at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$soW0qC12Osypoky6AfL3P2-TeDw.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)```

Provide example of how to use takePicture(OnImageCapturedListener)? use Intent(MediaStore.ACTION_IMAGE_CAPTURE) without File Uri?

Could you provide a demo about how to capture and handle in-memory buffer image?
Thanks.
In ImageCapture.Java , I found this snippet

// Wrap the ImageCapture.OnImageSavedListener with an OnImageCapturedListener so it can
// be put into the capture request queue
OnImageCapturedListener imageCaptureCallbackWrapper =
		new OnImageCapturedListener() {
			@Override
			public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
				Handler completionHandler = (mHandler != null) ? mHandler : mMainHandler;
				CameraXExecutors.ioExecutor()
						.execute(
								new ImageSaver(
										image,
										saveLocation,
										rotationDegrees,
										metadata.isReversedHorizontal,
										metadata.isReversedVertical,
										metadata.location,
										imageSavedListenerWrapper,
										completionHandler));
			}

			@Override
			public void onError(
					UseCaseError error, String message, @Nullable Throwable cause) {
				imageSavedListener.onError(error, message, cause);
			}
		};

How to achieve the following code in CameraX with in-memory buffer without use FileUri

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
    startActivityForResult(takePictureIntent, REQUEST_TAKE_IMAGE);

or

    val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    if(intent.resolveActivity(packageManager) != null) {
        mCurrentPhotoPath = fileUri.toString()
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri)
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
        startActivityForResult(intent, TAKE_PHOTO_REQUEST)
    }

Thanks

App crashes after display orientation change

The app crashes when I change the phone orientation from portrait to landscape.

Phone: Xiaomi Redmi 5 Plus
OS: Android 8.1.0, API27

2019-06-08 19:03:14.353 10259-10332/com.android.example.cameraxbasic I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
2019-06-08 19:03:14.354 10259-10540/com.android.example.cameraxbasic I/RequestThread-0: Configure outputs: 3 surfaces configured.
2019-06-08 19:03:14.354 10259-10540/com.android.example.cameraxbasic D/Camera: app passed NULL surface
2019-06-08 19:03:14.354 10259-10540/com.android.example.cameraxbasic E/BufferQueueProducer: [ImageReader-4000x2000f100m2-10259-2] connect: already connected (cur=4 req=4)
2019-06-08 19:03:14.355 10259-10540/com.android.example.cameraxbasic E/Legacy-CameraDevice-JNI: connectSurface: Unable to connect to surface, error Invalid argument (-22).
2019-06-08 19:03:14.355 10259-10540/com.android.example.cameraxbasic E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeConnectSurface: Error while configuring surface Invalid argument (-22).

    --------- beginning of crash
2019-06-08 19:03:14.356 10259-10540/com.android.example.cameraxbasic E/AndroidRuntime: FATAL EXCEPTION: RequestThread-0
    Process: com.android.example.cameraxbasic, PID: 10259
    java.lang.UnsupportedOperationException: Unknown error -22
        at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:77)
        at android.hardware.camera2.legacy.LegacyCameraDevice.connectSurface(LegacyCameraDevice.java:694)
        at android.hardware.camera2.legacy.RequestThreadManager.configureOutputs(RequestThreadManager.java:406)
        at android.hardware.camera2.legacy.RequestThreadManager.-wrap0(Unknown Source:0)
        at android.hardware.camera2.legacy.RequestThreadManager$5.handleMessage(RequestThreadManager.java:713)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:176)
        at android.os.HandlerThread.run(HandlerThread.java:65)
2019-06-08 19:03:14.633 10259-10540/com.android.example.cameraxbasic I/Process: Sending signal. PID: 10259 SIG: 9

I can post the full verbose stacktrace if necessary.

I must say that device manufacturer does not support camera2 (CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) and it's quite a hassle to work with this device...

Device Gallery Displays Deleted Photos

First time adding an issue to a GitHub project. I'd like to start with saying that I really appreciate the demo app - it helped me a lot, and I'm excited for CameraX.

I did notice in my own app, and then tested with this demo app, that missing image preview icons were left in the phone's gallery after deleting an image from the app photo gallery. I would have to separately go back through and delete the thumbnails in the phone gallery after deleting the files.

I found some help via StackOverflow solutions, but I'm not sure if it is the best approach. Currently I've added:

context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(mediaFile)))

just after the mediaFile.delete() line, and that seems to have solved the problem. Another answer suggested using a ContentResolver to delete the image, but again, being new to programming I'm not sure which is the "best" option.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.