Android USB camera Open Source Library Uvccamera Tutorial

Source: Internet
Author: User

Https://github.com/saki4510t/UVCCamera

Uvccamera listen to the name to know the Common class library using the UVC (USB vedio Class) protocol. Linux native support with basic support for all free-zone USB cameras on the market.

This open source library contains a library of JNI and Android-encapsulated classes. is currently the best use of the Android USB Camera class library.

Uvccamera to control and manage connections to external devices,
Uvccamera.setframecallback (Final Iframecallback callback, final int pixelformat) gets each frame of data;

Pixel_format_raw = 0;
PIXEL_FORMAT_YUV = 1;
pixel_format_rgb565 = 2;
PIXEL_FORMAT_RGBX = 3;
PIXEL_FORMAT_YUV420SP = 4;
PIXEL_FORMAT_NV21 = 5;

The Uvccameratextureview control makes a preview of the image,

Usbmonitor connection and disconnection of the drive

The coupling of the Uvccamera Test4 class is poor.

TEST4 is to operate the camera in the background service, the latter service is not the same process name as the foreground process, so the definition of the Service IBinder object is Aidl, and the IBinder object is operated through the Aidl defined interface to operate the background service. While the camera operation is not directly in the service operation, the service is responsible for detecting the USB link situation, the USB connection to the device backstage, create a handler (Cameraserver) to operate the camera.

To add a camera to the operation, you have to stack several layers to complete the package. The dependency between class and classes is very serious!!! Think the author has a problem with design. In order to add a camera operation, I took a total of 8 steps to complete.

1. Add related actions in Cameraserver->camerathread
Note: The actual operation of the camera operation is Cameraserver (handler Class)-->camerathread (Class).
Referential relationships: Instances of Cameraserver are referenced by weakly referencing WeakReference instances of class Camerathread during the reference period; Caerathread reference their external cameraserver instances by a strong reference or direct reference

2. Add handler processing in Cameraserver (handler) class, send message via handler, invoke operation in Cameraserver-->camerathread class

1) Add MessageType constant when sending message in Cameraserver class

2) in the Cameraserver#handlemessage () method, add handling of the added Meassagetype constant, similar to thread.xxxx ()

3) Add the relevant action method, used to encapsulate the corresponding Meassagetype constant, Cameraserver#handlemessage () method.

3. Add related method declarations in Iuvcservice.aidl
Note: the interface defined by Iuvcserice.aidl is the ibinder of uvcservice feedback, because the process name that serves the foreground UI is different, so the Uvcservice object is referenced with the Aidl defined interface. For client cameraclient access.

4.uvcservice#musbmonitoruvcservice#mbasicbinder4. An anonymous class instance of Uvcservice#mbasicbinder in Uvcservice, Overrid implements the method declaration added in Iuvcservice.aidl.
Note: Uvcservice is a back-end service that controls USB devices, and Uvcservice#musbmonitor monitors USB devices, Uvcservice#mondeviceconnectlistener (uvcservice# The Musbmonitor callback) Initializes a Cameraserver instance #onConnect () and plugs into the Uvcservice#scameraservers collection. Uvcservice#musbmonitor all operations are on the Uvcservice main thread. Uvcservice#scameraservers#cameraserver is the handler class that really operates the USB camera, and the client cameracilent through uvcservice# Mbasicbinder calls Uvcservice#scameraservers#cameraserver, which calls uvcservice#scameraservers#cameraserver# Camerathread operate the camera.

5. In Cameraclient#camerahandler (handler class, cameraclient static inner Class) #CameraTask (thread class, cameraclient# Camerahandler static inner Class) adds a method that calls the Iuvcserice.aidl Add method.
Note: Cameraclinet is the class that corresponds to the background service of the foreground UI, cameraclient the thread class Cameratask the actual operation of the background service by sending a message through the handler class.

6. Add the MessageType constant for the corresponding operation service in Cameraclient

7. Add code to process the Cameraclient#messagetype constant in the Cameraclient#camerahandler (handler class, Static inner class of Cameraclient) #handleMessage () method

8. Add the relevant code for Operation Cameraclinet in view

Android USB camera Open Source Library Uvccamera Tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.