0

I am creating an application for tablet in android where, I want to use usb camera as a default camera when I start my application. I want to click picture and save them in either jpeg,jpg or png format. I could not find any helpful resources on web. How can I implement such functionality? Any help would be appreciated.

1 Answers1

1

The solutions are all complex with advantages and disadvantages. Information on USB and UVC is freely available from the USB IF web site, although there are many hundreds of pages of detail. The main issue is that the isochronous transfer method is missing from the Android framework, although descriptor retrieval, control, interrupt and bulk are implemented. Hence, most of the usb access can be done in Java or Kotlin, but the streaming side is a real pain. Using method one below and a Logitek C615 webcam, I obtained 640x480@30 fps on a Lenovo Tab10 using Android 6, and 1920x1080@30fps on a Lenovo IdeaPad 520 Miix using Android9 x86. The Tab10 appears to run at USB v1 speeds although it has a USB v2 micro-B socket. The Miix has a type A USB socket and does not need an OTG converter. I know of three methods:

  1. Use Libusb. This requires a separate compilation and build in Android Studio to a shared library. Write C++ code to setup, transfer packets and teardown the webcam. Write Java code for the user interface, decompress MJPEG, display preview and write JPEGs to storage. Connect the two via JNI. The C++ and Java run in separate threads but are non blocking. The inefficiency is in memcopying from a native image frame array to a JNI array and then freeing for garbage collection after each frame. Android apps run in a container, which means a special startup for Libusb and some functions fail, probably because of selinux violations.
  2. Use JNA to wrap the Libc libray. JNA is obtained from a repository and does not require a separate build. Libc is in Android Studio. All the code is Java, but IOCTL is used to control the usb file streams and the small stuff is really sweated. Libusb does much of the low level stuff in design choice 1.
  3. Use the external camera option with the Camera2 API. Non of my devices support an external camera, not even my Samsung Android 13 phone. I suspect this is meant for systems integrators to build custom versions of Android with the appropriate settings as documented by Google, implemented on SBCs for point-of-sale etc.
Cyclops
  • 11
  • 1