How can I register my camera as a back camera, not front/selfie camera ?

326 views
Skip to first unread message

NovHak

unread,
Apr 28, 2020, 4:28:55 PM4/28/20
to Android-x86
This poses some problems. For example, 1) Whatsapp inverts the picture, and 2) Google Lens isn't working (probably because it looks for a back camera).

Michael Goffioul

unread,
Apr 28, 2020, 4:37:23 PM4/28/20
to Android-x86
On Tue, Apr 28, 2020 at 4:29 PM NovHak <nov...@gmail.com> wrote:
This poses some problems. For example, 1) Whatsapp inverts the picture, and 2) Google Lens isn't working (probably because it looks for a back camera).

It seems you have 2 possibilities:
- /etc/camera.cfg config file
- hal.camera.0 property

Michael.

NovHak

unread,
Apr 28, 2020, 10:38:00 PM4/28/20
to Android-x86
Thanks, that's interesting !

So I did

setprop hal.camera.0 0,0

Then restarted the camera provider service, but it didn't work, my camera was still inverted. I had to delete /dev/video1 as well and now it's working as expected.

The problem here is that if I'm not mistaken, the USB video class driver (uvcvideo) has been patched some time ago in such a way that each camera device now has two /dev/video* device files. The second one is used to transmit metadata about the video. However, Android x86 still considers each /dev/video* device file as corresponding to a different actual device. So I suppose the "second device" (that doesn't exist) is considered as a back camera when registering new devices, preventing the first device to be considered as one. During my first tests I set the hal.camera.1 property as well, which worked too (instead of deleting /dev/video1), but in the end I consider that to be a dirty trick and prefer to simply delete the device file, which I guess will be good as long as Android doesn't make an effective use of the metadata that's provided.

Michael Goffioul

unread,
Apr 29, 2020, 12:06:43 AM4/29/20
to Android-x86
I think using the config file instead should allow to skip the video1 device (by not defining it in the file). Without a config file, the camera hal will scan all available devices and use the index as _facing_ value, unless you use props.

I don't think android-x86 makes use of the metadata.


--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-x86/719a7688-0118-43a6-8297-911276ec00e4%40googlegroups.com.

NovHak

unread,
Apr 29, 2020, 12:26:12 AM4/29/20
to Android-x86
You're right, but I prefer a read-only /system, as it is by default. Imho, there should be a way to keep a read-only /system while at the same time being able to change some configuration elements. Actually it's possible for some things, such as Input Device Configuration (IDC) files, and I think having the same for a camera configuration file would be good (somewhere in /data/system maybe ?).

So for the time being my changes won't persist, but luckily I'm happy most of the time with an inverted picture. The only problems for now are taking a picture with Whatsapp (which Whatsapp may correct at some point), and Google Lens not working (which Google may correct too), for the rest things are working quite well. Being able to address those problems temporarily when needed makes me happy enough !
To unsubscribe from this group and stop receiving emails from it, send an email to andro...@googlegroups.com.

Chih-Wei Huang

unread,
Apr 30, 2020, 7:15:31 PM4/30/20
to Android-x86
NovHak <nov...@gmail.com> 於 2020年4月29日 週三 上午10:38寫道:
>
> Thanks, that's interesting !
>
> So I did
>
> setprop hal.camera.0 0,0
>
> Then restarted the camera provider service, but it didn't work, my camera was still inverted. I had to delete /dev/video1 as well and now it's working as expected.

Please provide the log before and after you set the property.

NovHak

unread,
May 4, 2020, 12:16:45 PM5/4/20
to Android-x86
Here are the logs (attached), sorry for the delay.

Here was my procedure :
1. Stop the camera provider
2. logcat -f defcam.log -T 1
3. Start the camera provider
4. Use the camera
5. Interrupt logcat
6. Stop the camera provider
7. logcat -f propcam.log -T 1
8. setprop hal.camera.0 0,0
9. Start the camera provider
10. Use the camera
11. Interrupt logcat

And as I said before, despite setting the property, the camera was still inverted, I had to stop the camera provider, delete /dev/video1 and restart the provider service, and only then the camera got the configured facing.

Hope this helps !
defcam.log
propcam.log

Chih-Wei Huang

unread,
May 4, 2020, 11:27:00 PM5/4/20
to Android-x86
NovHak <nov...@gmail.com> 於 2020年5月5日 週二 上午12:17寫道:
>
> Here are the logs (attached), sorry for the delay.

If there is only one camera in the device,
the camera hal will assume the camera is front facing
unless property hal.camera.0 is set.
However, there is a logical error in the HAL that preventing
the "unless clause" from working.
I've fixed it by the patch:
https://osdn.net/projects/android-x86/scm/git/hardware-libcamera/commits/cdab62634d2dbc2ad7556147bcd592e2e8e01879

So with the patch you don't need to delete /dev/video1.
(just set property hal.camera.0)

Thank you for finding and reporting this issue.

--
Chih-Wei
Android-x86 project
http://www.android-x86.org

youli...@gmail.com

unread,
Apr 22, 2021, 11:37:06 PM4/22/21
to Android-x86
use one usb camera as a back and front camera at the same time.
rm /dev/video1
ln -s /dev/video0 /dev/video1
setprop hal.camera.0 0,0
setprop hal.camera.1 1,0
killall cameraserver
Reply all
Reply to author
Forward
0 new messages