Skip to content

qtubuntu-camera enable more than two cameras (wide-angle mode)

Created by: zubozrout

Hi, while you can specify camera.deviceId when using QtMultimedia, as per: https://doc.qt.io/qt-5/qml-qtmultimedia-qtmultimedia.html and even QtMultimedia.availableCameras apparently returns more than just two cameras if available, you can see starting on this line: https://github.com/ubports/qtubuntu-camera/blob/1acdfa03047d975091fdb509fd3cf4610f0a4f0e/src/aalcameraservice.cpp#L170 that the user requested device ID is actually never considered and AalCameraService just keeps toggling in between the two fixed devices.

One thing is that it seems to use enum values as defined here: https://github.com/libhybris/libhybris/blob/9d2860a5a78cb5c6c6beacf544682ce75b6adf9b/hybris/include/hybris/camera/camera_compatibility_layer.h#L32 (I am not sure what's the purpose of that in libhybris, but I guess it more or less matches since probably all the devices so far were working with that device assumption where 0 is back, 1 is front, so might be ok to keep as is if useful somewhere)

However, I am not sure if AalCameraService actually has any use for that and that toggling is clearly wrong. If I set camera.deviceId to some id I want it to be followed. And it actually seems after a lot of trial and error (I was initially creating new methods for that, not understanding at all how this behaves, since I still have barely any understanding of how this works) to have an easy fix just by using m_deviceSelectControl->selectedDevice() directly instead.

You can find a test branch here: https://gitlab.com/zubozrout/qtubuntu-camera/-/tree/xenial-dont-limit-camera-device

And test app(s) here:

I am sure this "hack" is not sufficient and it is not going to be accepted. However, that's about as much as I was able to do from my ignorant position.

Bugs

I have not noticed anything extra wrong with neither of the existing/available lenses. However, I have noticed an unpleasant error requiring the lenses app restart in order for the app to be able to access the cameras again ... when trying to access some cameras which QtMultimedia.availableCameras list, but they are physically not present.

For my phone (Redmi Note 9 Pro) I get the following list: [{"deviceId":"0","displayName":"Camera 0 Back facing","position":1,"orientation":270},{"deviceId":"1","displayName":"Camera 1 Front facing","position":2,"orientation":90},{"deviceId":"2","displayName":"Camera 2 Back facing","position":1,"orientation":270},{"deviceId":"3","displayName":"Camera 3 Back facing","position":1,"orientation":270},{"deviceId":"4","displayName":"Camera 4 Back facing","position":1,"orientation":270},{"deviceId":"5","displayName":"Camera 5 Front facing","position":2,"orientation":90}] But for device id 4 and 5 I get the following error:

Already have a texture id and video sink, not creating a new one
	ext1: 1, ext2: 0

after which I just get: no valid device selected: 3 no matter the selection and have to restart the lenses app (camera-app would likely behave the same)

That I guess makes sense, as I have one front camera and 3 back cameras on my device, as per e.g. this image: https://cdn2.smart-gsm.com//2020/03/Xiaomi-Redmi-Note-9-Pro-4.jpg

Then there is a depth sensor (no idea how it works, but doesn't seem accessible with that). Maybe that's what is listed as deviceId 4, and the fifth device (deviceId 5) is a complete mystery to me.

However, I think that if these two cameras were not listed it would have likely worked just fine. Also, I have not noticed any issues/regressions in the default camera app (without tweaks), nor in Tagger or the Corona App which I've tried.

Any thoughts are highly appreciated. Thank you! :)

Edited by Mike Gabriel