pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.57k stars 778 forks source link

Issue with Camera2Source in RootEncoder Version 2.5.1 #1609

Closed legosaro closed 1 month ago

legosaro commented 1 month ago

I am experiencing an issue with the Camera2Source library when using version 2.5.1 of RootEncoder. If I place an object in front of the camera, the streaming freezes. This behavior did not occur with version 2.4.9, where the streaming continued to work properly even when an object was placed in front of the camera.

pedroSG94 commented 1 month ago

Hello,

What do you means with "place an object in front of camera"? Do you have a code example to reproduce the error?

legosaro commented 1 month ago

When an object, like a finger, was placed over the lens. The code I am using is the "rotation" example.

pedroSG94 commented 1 month ago

Again, I don't understand you. Can you share a full code example to reproduce the error?

legosaro commented 1 month ago

To reproduce the error, I am using the RootEncoder sample app. I tested the same code on a smartphone, and it works correctly. However, on my device, it only works if I use rootEncoder 2.4.9.

pedroSG94 commented 1 month ago

What are you doing to reproduce it? Can you describe steps?

legosaro commented 1 month ago
  1. Open the RootEncoder streamer application.
  2. In the app, select the "rotation" option.
  3. Cover the camera lens with an object (e.g., use a finger).
  4. Observe that the camera preview freezes
pedroSG94 commented 1 month ago

I'm not able to reproduce it.

Can you reproduce it using the last commit in master branch? Can you reproduce it using other device? If not, can you tell me your device model that fail? Also, check if it is working in version 2.5.0 to know if the error is in that version or last version

legosaro commented 1 month ago

Pedro, thank you for your responses. Yes, I have tried both version 2.5.0 and the last commit on the master branch, and unfortunately, I get the same behavior as with 2.5.1.

pedroSG94 commented 1 month ago

Ok, so version 2.5.0 also have this bug. I did a refactor to camera2 manager in that version

Can you reproduce this error using the library in this commit? https://github.com/pedroSG94/RootEncoder/tree/e4c2575a7fcaa532a7ac3af43e88dc5fdeafaaa5 Also, tell me the Android version of your device

legosaro commented 1 month ago

In this commit, the issue is not reproduced.

Can you reproduce this error using the library in this commit? https://github.com/pedroSG94/RootEncoder/tree/e4c2575a7fcaa532a7ac3af43e88dc5fdeafaaa5

I'm testing it on a device running Android 13.

pedroSG94 commented 1 month ago

Ok, this is related with the camera2 refactor. Try using the last commit in master replace this method: https://github.com/pedroSG94/RootEncoder/blob/master/encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.kt#L853 To:

    @Suppress("DEPRECATION")
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    private fun createCaptureSession(
        cameraDevice: CameraDevice,
        surfaces: List<Surface>,
        onConfigured: (CameraCaptureSession) -> Unit,
        onConfiguredFailed: (CameraCaptureSession) -> Unit,
        handler: Handler?
    ) {
        val callback = object: CameraCaptureSession.StateCallback() {
            override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
                onConfigured(cameraCaptureSession)
            }

            override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {
                onConfiguredFailed(cameraCaptureSession)
            }
        }
        cameraDevice.createCaptureSession(surfaces, callback, handler)
    }
legosaro commented 1 month ago

unfortunately it doesn't fix

pedroSG94 commented 1 month ago

Hello,

Can you try using this branch? https://github.com/pedroSG94/RootEncoder/tree/fix/camera2

legosaro commented 1 month ago

I’m sorry to report that the issue persists

pedroSG94 commented 1 month ago

Get the last commit and try again please.

legosaro commented 1 month ago

The issue persists

pedroSG94 commented 1 month ago

I'm not sure where is the error.

Only to discard. I did a new commit using the old camera2 implementation. Can you confirm me if all is working?

After that, I will do a line by line minimal migration

legosaro commented 1 month ago

Sorry, the problem persists. Just to be safe, I tried this commit again

https://github.com/pedroSG94/RootEncoder/tree/e4c2575a7fcaa532a7ac3af43e88dc5fdeafaaa5

and it works fine.

pedroSG94 commented 1 month ago

Ok, the error is not related with the camera2 implementation. I will need find the exact commit that produce the error. Only to confirm, the version 2.5.0 fail, right?

Try this commits: https://github.com/pedroSG94/RootEncoder/tree/ed2768512df7d179bde119c421abb366811e437c https://github.com/pedroSG94/RootEncoder/tree/6f21355eb795a0312bae53881dac085c8019cbae https://github.com/pedroSG94/RootEncoder/tree/d81223d222c7e427e040d2cc13d2a7f24647bd7a Let me know in which commit fail.

legosaro commented 1 month ago

I tried all of these commits, but the issue is present in all of them

legosaro commented 1 month ago

I tried this one:

https://github.com/pedroSG94/RootEncoder/tree/e4c2575a7fcaa532a7ac3af43e88dc5fdeafaaa5

and work fine

pedroSG94 commented 1 month ago

Ok, Are you sure that the last commit of https://github.com/pedroSG94/RootEncoder/tree/fix/camera2 produce this error?

The last commit is using this camera implementation: https://github.com/pedroSG94/RootEncoder/blob/fix/camera2/encoder/src/main/java/com/pedro/encoder/input/sources/video/Camera2Source.kt#L38 Which is the same that in commit: https://github.com/pedroSG94/RootEncoder/tree/e4c2575a7fcaa532a7ac3af43e88dc5fdeafaaa5

Also, I did a new branch from https://github.com/pedroSG94/RootEncoder/tree/d81223d222c7e427e040d2cc13d2a7f24647bd7a but using old camera implementation to discard that the error is not related with the code migration but it is in other class: https://github.com/pedroSG94/RootEncoder/tree/test/camera2old

Let me know the result of your tests.

Sorry for this but I haven't other way to detect the error.

legosaro commented 1 month ago

The issue was introduced in this commit:

https://github.com/pedroSG94/RootEncoder/tree/d81223d222c7e427e040d2cc13d2a7f24647bd7a

pedroSG94 commented 1 month ago

What about this branch? https://github.com/pedroSG94/RootEncoder/tree/test/camera2old

This is to discard/confirm that the camera2 implementation produce the issue and not other classes of that commit.

After that, please try again get the last commit of this branch: https://github.com/pedroSG94/RootEncoder/tree/fix/camera2

Let me know the results.

legosaro commented 1 month ago

Both branches are experiencing the same problem. I tried revision e4c2575 and it works fine. I also tested revision d81223d, and the problem is present here

pedroSG94 commented 1 month ago

This branch should reverse the error: https://github.com/pedroSG94/RootEncoder/tree/fix/reverse-camera2-fix

legosaro commented 1 month ago

What about this branch? https://github.com/pedroSG94/RootEncoder/tree/test/camera2old

This is to discard/confirm that the camera2 implementation produce the issue and not other classes of that commit.

After that, please try again get the last commit of this branch: https://github.com/pedroSG94/RootEncoder/tree/fix/camera2

Let me know the results.

Sorry Pedro, I recompiled both branches, and they are working correctly

pedroSG94 commented 1 month ago

Ok, this is a good news. I will do migration steps by steps and with that we can know the line that fail.

pedroSG94 commented 1 month ago

Hello,

I did the migration with multiple commits to detect the error. First, test this commit to confirm that all is working: https://github.com/pedroSG94/RootEncoder/tree/49bc4793a0ceb5edc1b5f0ebf76b4627c2770012

After that, test this commits: https://github.com/pedroSG94/RootEncoder/tree/da7e73be00d12ed06bd7e695bc5d2efca015a65c https://github.com/pedroSG94/RootEncoder/tree/614e1a3acebe19213d3c4a20bfb65a490329789f https://github.com/pedroSG94/RootEncoder/tree/614e1a3acebe19213d3c4a20bfb65a490329789f https://github.com/pedroSG94/RootEncoder/tree/9f31066f8ad8ba0292bdb7541489f48cd5d95da9 https://github.com/pedroSG94/RootEncoder/tree/83ce2e768e632da74773db0b2cbeebd4fa6e4c0e https://github.com/pedroSG94/RootEncoder/tree/882c35e917958fb6fbc63228566f62e13bb8dd98 https://github.com/pedroSG94/RootEncoder/tree/49137708453dac411bbade652f4dc39faab33ac2 https://github.com/pedroSG94/RootEncoder/tree/9c1cc84bbe36c839e4f461cbdf136b07624a766b https://github.com/pedroSG94/RootEncoder/tree/a87a4ad2553012e0407406c1997b1da9ba3e3889

All this commits are in order to test. The idea is find the commit that fail

legosaro commented 1 month ago

Hello, thanks a lot Pedro. The commit that failed is: https://github.com/pedroSG94/RootEncoder/tree/83ce2e768e632da74773db0b2cbeebd4fa6e4c0e

pedroSG94 commented 1 month ago

Hello,

I did a fix for that method that should solve the problem: https://github.com/pedroSG94/RootEncoder/tree/bcf95e720e621cb6a72f240a6fc2a3509939ab23

Let me know if this solve the problem and I will merge the error into master

legosaro commented 1 month ago

That's perfect, the problem has been completely resolved now

pedroSG94 commented 1 month ago

Closed as solved. The fix will be available in version 2.5.2