V4L2 Camera HAL questions

4,304 views
Skip to first unread message

satur9nine

unread,
Jun 1, 2018, 1:26:57 PM6/1/18
to android-platform
I am trying to get a USB UVC camera to appear as a normal camera by the android platform.

This appears to be similar to what the discussion in https://groups.google.com/d/msg/android-platform/rqj2SKG7Cx4/UpbPsQRkAAAJ is about.

Google seems to have some code for this. I noticed there are the following modules in the platform:


The usbcamera project seems incomplete, for example the comment "TODO: implement usb camera device open sequence: open device nodes etc." appears in the openDevice function along with no other code. It's unclear to me why Google merges such things into the platform...

The confusingly named camera/3_4 project seems quite promising, it has quite a bit of documentation as you can see and describes itself as: "Camera HALv3 using the Video For Linux 2 (V4L2) interface". Unfortunately upon attempting to use it I see it immediately fails due to the following problem: "Invalid gralloc version 100. Only 0.3 (3) and below are supported by this HAL." So it seems my particular device does not have the old 0.3 gralloc, it has gralloc 1.0. This leads to some questions:

Has anyone gotten this 3_4 V4L2 Camera HAL working in the real world?

Anyone have a guess how hard would it be to upgrade it to support gralloc 1.0?

I already have a built-in camera via existing HAL, does android allow only a single Camera HAL? If not how do I configure two Camera HALs? If not and I want to support both simultaneously would I need some kind of wrapper HAL that merges the two into one?

Final question, does anyone know of any other alternative for an external USB camera which has an Android HAL built already?

Thanks,
Jacob

satur9nine

unread,
Jun 13, 2018, 1:30:58 PM6/13/18
to android-platform
I see that Google announced the following feature on this site: https://developer.android.com/preview/features

Android P also enables support for external USB/UVC cameras on supported deveices.

Does anyone have any more information about this statement from Google? Is this a reference to the camera/3_4 module? Does the https://android-review.googlesource.com/ contain the latest work from Google? I haven't found anything new in there about USB/UVC...

Jacob

Colin Cross

unread,
Jun 13, 2018, 1:38:51 PM6/13/18
to android-...@googlegroups.com
It is not in AOSP yet, it will be pushed to AOSP when P is released.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

satur9nine

unread,
Jul 6, 2018, 11:44:12 AM7/6/18
to android-platform
Thanks, the P Preview release notes indicate the functionality is present in the following preview:

Developer Preview 2 (Beta)
Date: May 2018
Build: PPP2.180412.013

I obtained a Google Pixel device running an even newer build PPP4.180612.004, however when plugging in several USB UVC cameras in via USB OTG the audio drivers appear to be detected based on logs, but no new /dev/video inodes appear and the camera app doesn't appear to detect any. The Camera APIs also did not show any additional cameras. I noticed that the /proc/config.gz does not contain CONFIG_USB_VIDEO_CLASS which I would presume is needed for this feature?

My device shows Kernel version 3.18.100 built on Jun 5 2018.

Is this feature only available on select preview devices?

Jacob

jayapa...@gmail.com

unread,
Mar 7, 2019, 10:50:33 AM3/7/19
to android-platform
how did you add that HAL to your android os? I don't have any clue. please help.

Wasim Nazir

unread,
Mar 8, 2019, 1:51:40 PM3/8/19
to android-...@googlegroups.com
Hi,

You can follow this to get the basic info:

Thanks

On Thu, Mar 7, 2019 at 9:20 PM <jayapa...@gmail.com> wrote:
how did you add that HAL to your android os? I don't have any clue. please help.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

This message contains confidential information and is intended only for the individual(s) named. If you are not the intended recipient, you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this mail and attached file/s is strictly prohibited. Please notify the sender immediately and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secured or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

satur9nine

unread,
Mar 11, 2019, 2:31:02 PM3/11/19
to android-platform


On Thursday, March 7, 2019 at 7:50:33 AM UTC-8, jayapa...@gmail.com wrote:
how did you add that HAL to your android os? I don't have any clue. please help.

To enable the External Camera HAL on Pie you will need to make some changes to various device MK files and include a configuration. Make the following changes to your <device>.mk file:

# Android P backported camera changes do not play nicely with the Camera HAL1.
# It seems unnecessary to expose HAL1 since HAL3.2 exposes the same camera and
# is backwards compatible.
TARGET_SUPPORT_HAL1=false
#PRODUCT_PACKAGES += camera...@1.0-impl

# Camera configuration file. Shared by passthrough/binderized camera HAL
PRODUCT_PACKAGES += camera...@3.2-impl
PRODUCT_PACKAGES += android.hardware...@2.4-impl
# Enable binderized camera HAL
PRODUCT_PACKAGES += android.hardware...@2.4-service
# Enable external USB camera
PRODUCT_PACKAGES += android.hardware...@2.4-external-service

PRODUCT_COPY_FILES += \
    device/<manufacturer>/<device>/external_camera_config.xml:$(TARGET_COPY_OUT_VENDOR)/etc/external_camera_config.xml 

Example external_camera_config.xml file included in vendor partition:

<ExternalCamera>
    <Provider>
        <ignore>
            <!-- Internal video devices to be ignored by external camera HAL -->
            <id>0</id> <!-- No leading/trailing spaces -->
        </ignore>
    </Provider>
    <!-- See ExternalCameraUtils.cpp for default values of Device configurations below -->
    <Device>
        <!-- Max JPEG buffer size in bytes-->
        <MaxJpegBufferSize bytes="3145728"/>
        <!-- Size of v4l2 buffer queue when streaming >= 30fps -->
        <!-- Larger value: more request can be cached pipeline (less janky)  -->
        <!-- Smaller value: use less memory -->
        <NumVideoBuffers count="4"/>
        <!-- Size of v4l2 buffer queue when streaming < 30fps -->
        <NumStillBuffers count="2"/>

        <!-- List of maximum fps for various output sizes -->
        <!-- Any image size smaller than the size listed in Limit row will report
            fps (as minimum frame duration) up to the fpsBound value. -->
        <FpsList>
            <!-- width/height must be increasing, fpsBound must be decreasing-->
            <Limit width="640" height="480" fpsBound="60.0"/>
            <Limit width="1280" height="720" fpsBound="60.0"/>
            <Limit width="1280" height="960" fpsBound="60.0"/>
            <Limit width="1600" height="1200" fpsBound="30.0"/>
            <Limit width="1920" height="1080" fpsBound="30.0"/>
            <Limit width="2592" height="1944" fpsBound="30.0"/>
            <!-- image size larger than the last entry will not be supported-->
        </FpsList>
    </Device>
</ExternalCamera>

In device/<manufacturer>/<device>/manifest.xml:

    <hal format="hidl">
        <name>android.hardware.camera.provider</name>
        <transport>hwbinder</transport>
        <version>2.4</version>
        <interface>
            <name>ICameraProvider</name>
            <instance>legacy/0</instance>
+           <instance>external/0</instance>
        </interface>
    </hal>


hjellinek

unread,
Nov 1, 2019, 12:27:01 PM11/1/19
to android-platform
Can anyone confirm that UVC support made it in to Android Pie?
Has anyone tested it on real shipping hardware?  What devices?

Thanks.

On Friday, June 1, 2018 at 10:26:57 AM UTC-7, satur9nine wrote:

Christy Joseph

unread,
Dec 18, 2019, 10:48:34 AM12/18/19
to android-platform
Hi did you get the usb camera in android build ?

วิไลพร นุกูล

unread,
Dec 18, 2019, 4:33:52 PM12/18/19
to android-...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.

BL Healthcare

unread,
May 14, 2020, 10:44:18 PM5/14/20
to android-platform
There is also Android AOSP - Supporting External USB Camera this page, which defines same thing posted here, with some more details.

We have a device with an USB HUB connected to it. The external cameras are very flaky. I have tried many different varieties of cameras, and it turns out that not all are directly supported. 

Then I found this library called https://github.com/suethan/AndroidUSBCamera based on multiple other projects. I was able to get the camera working by including this project (libuvccamera) as a dependency and using it to build my app. 2/3 cameras worked well. We used mainly generic USB UVC cameras. 

Now for our purposes, we needed the camera buffer callbacks to send video data over a video call. I am not sure how that works. 

On android 8.0 however I have a completely working implementation. I am not sure of the details, as the modifications to the source were made by my Software Architect. But it works perfectly well. Just plug in the camera and we can use it. However there is quite some work involved. 

I'm working on porting those changes over to the Android Pie, however, I am not sure whether it can be done. It looks doable, but without his guidance or support (he is not available) I am not sure I can get it.

In conclusion, I have to say, yes! I was able to successfully compile and build AOSP Pie on sdm660_64, but it doesn't work as an internal camera yet. I am working on it.

BL Healthcare

unread,
May 14, 2020, 10:44:19 PM5/14/20
to android-platform
You have to add couple of Kernel level configs, and also then enable some other services. Follow the guide here External USB Cameras

Rest of the details are really not that clear and would love to have someone explain what they did. (without screwing their NDAs of course :-) )

BL Healthcare

unread,
May 18, 2020, 11:22:52 AM5/18/20
to android-platform
Actually I stand corrected. 

UVC Camera works fine in Android 9.0. Follow the steps and add the required things. 

I was thrown a little off track because we were facing trouble with one particular camera. Now let me tell you how we got it working, and please know this is not a one fix works for all situation. It depends on your requirement and you'll need to lose some to gain some. All cameras may never work.

First things first, install YAWCAM on your PC. Then connect your camera, open yawcam and make sure your device is selected and you can see it's preview. (Note: Yawcam won't start if you have 0 webcams connected).

Next, look under Settings > Device (Device name) > Format Control > Color Space/ Compression. You can have some options or just one option of the following
  • YUV
  • YUV2
  • MJPEG
  • UVY etc.
This helps to find out what formats are supported on your device. 

Now in your AOSP USB Camera HAL, if you check, you might notice that only MJPEG or YUV might be selected. Usually YUV is supported by all cameras. However, MJPEG is not. MJPEG also allows for better resolution. (So that's gonna be a trade off). If you are using Qualcomm HAL, and have enabled all the services and the camera is still not working, then check under ~/android/hardware/qcom/camera/usbcamcore/src/QualcommUsbCamera.cpp 

I noticed that MJPEG was enabled by default, and the 4 cameras I tried, 3 of them supported MJPEG so it worked perfectly. However, we had another camera, which was more important for us than others, and turns out it only supported YUV. So I turned this setting off like so

#define JPEG_ON_USB_CAMERA      0

Notice in this piece how it chooses 

#if JPEG_ON_USB_CAMERA
   rc = initUsbCamera(camHal, camHal->pictWidth, camHal->pictHeight,
                       V4L2_PIX_FMT_MJPEG);
#else
   rc = initUsbCamera(camHal, camHal->pictWidth, camHal->pictHeight,
                       V4L2_PIX_FMT_YUYV);

So that's it people, I hope I have solved all your issues with these damn cameras and the HALs. 

blheal...@gmail.com

unread,
Dec 11, 2020, 4:41:50 PM12/11/20
to android-platform
YUV Support added in UVC Camera: interface 3.4 update
Find attached diff
ext_cam.diff

blheal...@gmail.com

unread,
Dec 11, 2020, 4:41:50 PM12/11/20
to android-platform
Find update for YUV support here: for interface 3.4

On Monday, May 18, 2020 at 11:22:52 AM UTC-4 blheal...@gmail.com wrote:
ext_cam.diff
Reply all
Reply to author
Forward
0 new messages