Solution to Realize the Normal Calling of the Third Party Conference Software UVC Camera on OK3568-C Development Board

1.Camera API

Android FrameWork provides Camera API to implement the ability to take pictures and screen recording, currently Android has three types of API:

Camera

This class is an older API for controlling the device's camera, used on Android 5.0 and below.

Camera2

Android 5.0+ upgraded solution that controls the device camera API and opens up hardware support levels for vendor customization. (Google has opened the official library Camera View to help solve camera compatibility problems, and there are also some other third-party libraries.) Compared with Camera1, Camera2 has changed its architecture, mainly simulating the camera device as a pipeline, processing each frame request in order and returning it to the caller.

CameraX

Introduced in JetPack, based on encapsulation with the Cmaera2 API, which simplifies the development process and adds lifecycle control.

The system camera used by 3568 Android is OK3568-Android11-source/packages/apps/Camera2Although the system camera is called camera2, both camera1 and camera2 are actually used.

Solution to Realize the Normal Calling of the Third Party Conference Software UVC Camera on OK3568-C Development Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

2. Problems

The USB camera can not be opened in the third-party meeting APP. Still, the scanner and system camera works fine, indicating a problem with opening the camera in the third-party meeting APP, while the camera itself is normal.

After giving the customer feedback at the beginning, the customer said that the UVC camera needed to be changed to a front-facing or rear-facing camera.

However, the test found that modifying the

hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp

The facing passed to the ANDROID _ LENS _ FACING in is front, and the default is external.

This is the source code for an external camera device and session implementation, but the test does not work.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

So, the error messages were checked when clicking to open the camera in a third-party meeting APP.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

By comparing the logs from failed attempts and successful ones, it was found that failures resulted in reporting android_hardware_Camera_getCameraInfo: Unknow camera ID 109

The error source code is in frameworks/base/core/jni/android_hardware_Camera.cpp

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

JNI(Java native interface)is a bridge between the Java layer and the native layer. In fact, JNI is a Java call-native method of an "interface."

The android _ hardware _ Camera _ getCameraInfo here is provided for Java to use, so print information is added here, and it is found that the normal opening is also here.

So, the upper-layer application specified opening a device with cameraId 109, but here, since its value is greater than the id obtained from the internal service getNumberOfCameras, an error occurs and exits.

Camera.getNumberOfCameras is the function used by the application layer to get the number of cameras supported by the device, which is actually implemented in frameworks/av/services/camera/libcameraservice/CameraService.cpp.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

The return value of mNumberOfCameras obtained through the pointer numCameras.

While the actual mNumber Of Cameras is in the acquired Hal.

hardware/interfaces/camera/common/1.0/default/CameraModule.cpp

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Named in hardware/rockchip/camera/Camera3HALModule.cpp.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Actually, num is zero, one, two.

So obviously 109 definitely doesn't fit.

Try directly in the android _ hardware _ Camera. cpp.

Fixing cameraId to 0 will result in an error

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

In fact, in the jni direct change is not very good, did not continue to chase the error message, it is better to go directly to the top layer to change the incoming 109.

So earlier, it was examined by checking the print information and moving downwards. Now, it moves upwards in the code.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

In JNI, the JNINativeMethod structure is used to define native methods.

typedef struct {  
    const char* name;  
    const char* signature;  
    void* fnPtr;  
} JNINativeMethod;

The first variable name is the name of the function in Java.

The second variable, signature, describes the parameters and return value of a function in Java in a string.

The third variable is a function pointer to the native function. Be preceded by (void *)

The first variable corresponds to the third variable. One is the Java layer method name, which corresponds to the native method name of the third parameter.

Because Java data types cannot interact directly with C C, JNI provides a set of data types to match.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

The actual java layer calls _getCameraInfo, which is then used in frameworks/base/core/java/android/hardware/Camera.java.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

While getCameraInfo is called by Camera open.call.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Camera open(int cameraId) is the specified id for open.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Looking back at the previous development process of camera 1, there are two open methods, one is to specify open, the other is not to specify open, and adding print information to these two opens, we can find that when specifying the ID, the incoming ID is 109, and the direct open will open according to the current facing situation of USB. So just change Camera open (int cameraId) and redefine cameraId to 0.

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board

When a UVC camera is inserted, two video nodes are generated under dev

Why do UVC devices have two/dev/video * nodes and where did they come from?

On a host running Linux-4.15 or later kernel, plug in a usb camera, there will be two /dev/video*, it's not a bug, it's a feature of V4L2, one node is input, the other is output, the data comes in from input, encoded and sent out from output, which is connected to the USB driver.

Also, when the camera is already turned on, it will cause the video node to move backward after hot plugging.

It can be solved by actually modifying the v4l2 driver.

kernel/drivers/media/v4l2-core/v4l2-dev.c

Solution for Third Party Conference Software to Call UVC Camera on OK3568-C Dev Board




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!