New SDL Camera API not working with certain Android models
Using read-and-draw.c from the examples folder in Android, I encountered several issues on some Android models. I used the latest version of SDL3. Compiled version: 3.1.6 (preview-3.1.6-0-g78cc5c173) Linked version: 3.1.6 (preview-3.1.6-0-g78cc5c173)
On an old phone Moto G5 (XT1676), I get this error message: "Couldn't find any camera devices! Please connect a camera and try again.". ACameraManager reports: Get camera characteristics from camera service failed: Status(-8): '10: getCameraCharacteristics:556: Unable to retrieve camera characteristics for device 0: No such file or directory (-2)'
On an LG92 (LM-Q920N), the image is distorted, jumble of colors, i have attached the screen shot;
Same thing on a Galaxy A52 (SM-A525F/DS), the image is wrong.
Right, this is my take on this. Camera2 API is not backward compatible with Camera 1 API, old phones won't work. Newer phones might work but it is not 100% a sure thing. Regarding the distorted image, it looks like the wrong color pixel format was used.
Google tried to resolve those issues with a new API CameraX. The problem is that this API is not (yet?) available in C/C++, just Kotlin and Java. Previously in SDL2, i used successfully CameraX. I have create a repository on Github for SDL3 and CameraX https://github.com/manupinot/com.example.cameraxsdl3
It might be the fix, adding CameraX in SDLActivity.java. Kind regards
We won't be adding Camera1 support (and unlikely to add CameraX either), but yeah, that picture looks like a pixel format problem (or we failed to pack down multiple loose planes to fit in an SDL_Surface correctly).
Looks like a duplicate of https://github.com/libsdl-org/SDL/issues/11114
(beside the 1 and X api remarks)
@manupinot, your CameraX approach looks good, but I'm concerned about the application requirement to add CameraX dependencies to build.gradle.
Is it possible to detect at runtime whether they're available? That way we could switch to using it as our primary camera implementation and fail the initialization if they're not included?
The latest code, including https://github.com/libsdl-org/SDL/commit/02e85a153f6d56c36d671842faac42b5b83a6ba9, should fix the distortion on your LG92. Can you try it out and confirm?
Hi, I will be back on my computer this evening. I'll check the new code on my lg92. I'll have a look about the gradle build too.
Yahoo Mail: Search, Organize, Conquer
On Thu, Jan 2, 2025 at 7:02, Sam @.***> wrote:
The latest code, including 02e85a1, should fix the distortion on your LG92. Can you try it out and confirm?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Hi, I tried the new code. It works on my LG92 and Samsung Galaxy A52. Please note though that the orientation is wrong and the image is stretched. I will check now about the build gradle for cameraX
Hi, Regarding about checking if the CameraX dependencies exists at run-time. It is possible to do it in java at run time; public static boolean isCameraXAvailable() { try { // Try loading a CameraX class Class.forName("androidx.camera.core.Camera"); Log.i(TAG, "CameraX dependencies are available."); return true; } catch (ClassNotFoundException e) { Log.e(TAG, "CameraX dependencies are missing."); return false; } }
but it wouldn't make sense as anyway the CameraX code would not compile in the first place.
A possible solution is to add the dependencies in the build.gradle of the android-project template that is being packaged with SDL. Please note that as usual with Android, the version of CameraX and its APIs keep on changing and that template and the CameraX code will not be up to date as a result! Kind regards