Android Camera Learning: Preview

Source: Internet
Author: User
Tags linux

Preview Data Preview Callback

Android Camera Small System:

Well...... Looking directly at the camera HAL layer, it is the main work that is typically done through IOCTL calls V4L2 Command① kernel data from camera Driver① in Linux preview. Then give it to surface (or overlay) to display or save as a file. At the HAL layer, you need to open the corresponding device file and Access camera driver via Ioctrl. Android through this HAL layer to ensure that the underlying hardware (drive) changes, just modify the corresponding HAL layer code, the framework layer and the Java AP does not have to change.

Note: ①v4l2 (video 4 Linux 2)

Note: ① This driver is not the camera itself but the master device that controls camera, the camera controller is abstracted into the V4L2 layer in Linux, and finally connected to each of the different *attach device drivers by (camera). Camera=camera controller + External camera sensor, the controller is integrated in the CPU, the device node under Linux is/dev/video0.

Preview Data Display Process:

Simply summed up as

Java app calls ②jni, Jni calls various. So:  
      
libandroid_runtime.so---> libcamera_client.so---> Binder IPC---> Libcameras ervice.so---> libcamera.so  
      
     Note: ② Please forgive me for using the verb "call", I can't think of a more vivid word.

Detailed description

1. Open the camera driver device file in the Linux kernel, call Opencamerahardware () defined in CameraHardwareInterface.h, and open the camera driver device file (for example,/ Dev/video0).

The setparameters () function defined in 2.camerahardwareinterface.h, which tells the camera HAL which hardware camera to use, as well as its working parameters (size, format, and so on), And the HAL layer allocates the buffers that stores the preview data (if buffers is allocated in camera driver in the Linux kernel and gets the address pointer after these buffers mmap).

3. If you do not use the overlay setting, the display target is in libcameraservice.so and will not go into the camera Hal Dynamic library. And register the preview data buffers address in the previous step to surface. If you use overlay, an instance of the overlay class is created in libcameraservice.so through the incoming isurface, and then the CameraHardwareInterface.h defined in Setoverlay () is invoked. Set to the camera Hal Dynamic library.

4. Start preview, call to Startpreview defined in CameraHardwareInterface.h () function. Startpreviewmode handles preview display media, and if overlay display is used, the corresponding overlay is set, and Mhardware->startpreview () is invoked to start preview Otherwise, call Mhardware->startpreview () to start preview, and then set buffer: Call function Registerpreviewbuffers (), which calls Mhardware-> Getpreviewheap (), from the HAL layer to obtain preview buffer, set it to surface to display preview results.

Preview data can be displayed via overlay and surface two media.

1, using overlay display

Overlay generally used in Camera preview, video playback and other needs of the high frame rate, there is also the possibility of UI design requirements, such as map to view the software needs two layer display information. Overlay requires hardware and driver support. Overlay does not have the Java layer code, there is no JNI call. are generally used in native.

If you want to use overlay, the underlying hardware must support overlay. In the Cameraservice::client constructor, there is a corresponding judgment.

Cameraservice::client::client (const sp<cameraservice>& Cameraservice,

Const sp<icameraclient>& cameraclient, pid_t clientpid) {}

If Museoverlay = Mhardware->useoverlay (), and the return value is true, the hardware supports overlay, otherwise only the surface display is used. The Android system provides a overlay interface that needs to be implemented on its own.

About Multilayer Overlay: For example, you need to support both Overlay1 and overlay2. You need to add overlay_control_device_t and overlay1 structures in the overlay2 of the overlay HAL. such as:

struct overlay_control_context_t {  
      
struct overlay_control_device_t device;  
      
* Our private state goes below here * *
      
struct overlay_t* overlay_video1;//overlay1 struct overlay_t*  
      
Eo2;//overlay2  
      
};

Each overlay_t represents a layer of overlay, each layer ovelay has its own handle. You can use custom parameters to invoke overlay_control_device_t:: Setparameter () to indicate. The Hal layer is specific to achieve, through Overlay object to get Overlay1 and overlay2 of the buffer pointer.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.