Home » Android » Android Open external UVC camera instead hardware camera

Android Open external UVC camera instead hardware camera

Posted by: admin June 15, 2020 Leave a comment

Questions:

i need to open external UVC camera with

Camera.open(CameraId);

but not working

Please help?

How to&Answers:

Tried and tested : https://github.com/saki4510t/UVCCamera

The above link comes with 8 different apps in a master app, implementing different features in each. Go through the apps.

Use libuvc library to access the external camera.

Answer:

I am researching this topic for several days and will contribute my partial findings here.

  1. There is a native library that can be used to get access to external UVC camera https://github.com/ktossell/libuvc. I’ve found that this project used it and when I compiled and tested it I’ve found the samples only partially stable and the source code it carries overwhelming.
  2. The 2 years old Camera2 API seems to include external Camera support. I’ve found in Android project documentation – Camera device the following statements:

    “External camera (e.g. USB hot-plug camera) support. The API updates specify the camera static info is available only when camera is connected and ready to use for external hot-plug cameras. Calls to get static info will be invalid calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The framework counts solely on device status change callbacks to manage the available external camera list.”

I am yet unable to write code using the Camera2 API that access my webcam.

Last, I’ve even found that in Android source code the following code

(144) // TODO: update to CAMERA_FACING_EXTERNAL once the HAL API changes are merged.

While CAMERA_FACING_EXTERNAL is a new value of CameraInfo class for external camera that are obviously not FRONT and not back.

I hope this will help you progressing toward the complete answer.

Answer:

Unfortunately, while the camera2 API does have the necessary API interfaces for supporting external cameras such as USB webcams, there’s not yet standard low-level support for external cameras.

Some individual device manufacturers do have such support, but that is a very small number of devices currently.

Until then, the only way to have USB webcams be usable by an Android application is to use the raw USB APIs directly, and not use the camera APIs at all. You can either try to find an existing UVC library to use, or write your own.

Answer:

The AOSP contains a Camera3 HAL implementation that is using V4L2. It even comes with a nice readme that also points out its current limitations:
https://github.com/aosp-mirror/platform_hardware_libhardware/tree/master/modules/camera/3_4

Answer:

This feature has been implemented on some platforms by relocating each function in camera_device_ops_t on hardware to the USB_CAMERA function,like below:

camera_device_ops_t usb_camera_camera_ops = {
  set_preview_window:         usb_camera_set_preview_window,
  set_callbacks:              usb_camera_set_CallBacks,
  enable_msg_type:            usb_camera_enable_msg_type,
  disable_msg_type:           usb_camera_disable_msg_type,
  msg_type_enabled:           usb_camera_msg_type_enabled,

  start_preview:              usb_camera_start_preview,
  stop_preview:               usb_camera_stop_preview,
  preview_enabled:            usb_camera_preview_enabled,
  store_meta_data_in_buffers: usb_camera_store_meta_data_in_buffers,

  start_recording:            usb_camera_start_recording,
  stop_recording:             usb_camera_stop_recording,
  recording_enabled:          usb_camera_recording_enabled,
  release_recording_frame:    usb_camera_release_recording_frame,

  auto_focus:                 usb_camera_auto_focus,
  cancel_auto_focus:          usb_camera_cancel_auto_focus,

  take_picture:               usb_camera_take_picture,
  cancel_picture:             usb_camera_cancel_picture,

  set_parameters:             usb_camera_set_parameters,
  get_parameters:             usb_camera_get_parameters,
  put_parameters:             usb_camera_put_parameters,
  send_command:               usb_camera_send_command,

  release:                    usb_camera_release,
  dump:                       usb_camera_dump,
};