Analysis of data flow in Android camera preview process

Source: Internet
Author: User

hardware platform: Atmel sama5d3 SoC + OV2640 Camera SensorAndroid version: 4.2.2
The mediaserver process is the container process for the camera service, which dynamically loads the camera HAL and Gralloc HAL. The video data frame must first reach the camera hardware abstraction layer from the camera driver. At the camera hardware abstraction layer, the video data frame is copied from the visual capture buffer to Gralloc buffer.
The Surfaceflinger process as a display server dynamically loads the Hwcomposer Hal and Gralloc HAL. At the Hwcomposer hardware abstraction layer, the data frame is copied from Gralloc buffer to video output buffer.
After this process, the images captured by the Camera sensor are finally displayed on the display via the LCDC Heo.

The red solid line in the figure is the video data frame flow, and the red line connection without the arrows is the same piece of memory at both ends.
involves three blocks of memory, as follows: Video capture Buffer/dev/video1gralloc BufferAnonymous shared memory both the MediaServer process and the Surfacelinger process can access this block of memoryVideo Output Buffer/dev/video0
The data copy operation was performed two times as follows: Media server process camera HAL video capture buffer-Gralloc buffer
Surfaceflinger process Hwcompser HAL gralloc buffer, video output buffer

allocation and memory mapping of video capture bufferHttps://github.com/Android4SAM/platform_hardware_atmel/blob/android4sam_v4.0/camera/CameraHardwareSam.cpphttps ://github.com/android4sam/platform_hardware_atmel/blob/android4sam_v4.0/camera/v4l2camera.cpp
Request Video Capture Buffer
Camerahardwaresam ::startpreviewinternalV4l2camera ::StartpreviewIsi_v4l2_reqbufs
    RET = IOCTL (FP, Vidioc_reqbufs, &req);

Memory mappingCamerahardwaresam ::startpreviewinternal
    Mpreviewheap = MGETMEMORYCB ((int) mv4l2camera->getcamerafd (),                                aligned_buffer_size,                                Kbuffercount,                                

obtain a copy of Gralloc buffer and video data frame from the visual capture buffer to Gralloc bufferHttps://github.com/Android4SAM/platform_hardware_atmel/blob/android4sam_v4.0/camera/CameraHardwareSam.cpp

Camerahardwaresam ::Previewthread
    if (Mpreviewwindow && mgrallochal) {buffer_handle_t *buf_handle;        int stride; if (0! = Mpreviewwindow->dequeue_buffer (Mpreviewwindow, &buf_handle, &stride)) {Aloge ("Could not de            Queue Gralloc buffer!\n ");        Goto callbacks;        } void *vaddr; if (!mgrallochal->lock (Mgrallochal, *buf_handle, Gralloc_us Age_sw_write_often, 0, 0, width, height, &vaddr)) {Char *frame = ((char *) MP            Reviewheap->data) + offset;                The code below assumes YUV, not RGB {int h;                char *src = frame;                Char *ptr = (char *) vaddr;                memcpy (PTR, SRC, frame_size);            YUY2TOYV12 (frame, vaddr, width, height);        } mgrallochal->unlock (Mgrallochal, *buf_handle); } else Aloge ("%s:could not obtain gralLoc Buffer ", __func__); if (0! = Mpreviewwindow->enqueue_buffer (Mpreviewwindow, Buf_handle)) {Aloge ("Could not enqueue gralloc buff            Er!\n ");        Goto callbacks; }    }

allocation and memory mapping of video output bufferHttps://github.com/Android4SAM/platform_hardware_atmel/blob/android4sam_v4.0/hwcomposer/hwcomposer.cpp Https://github.com/Android4SAM/platform_hardware_atmel/blob/android4sam_v4.0/hwcomposer/v4l2_utils.cpp

Request Video Ouput Buffer Hwc_prepareAssign_heo_overlay_window-V4l2_overlay_req_buf
    RET = IOCTL (WIN->FD, Vidioc_reqbufs, &reqbuf);

Memory mapping Hwc_prepareAssign_heo_overlay_window V4l2_overlay_map_buf
    *len = buf.length;    *start = Mmap (NULL, buf.length, Prot_read | Prot_write, map_shared,            FD, Buf.m.offset);

video data frame from Gralloc buffer to video output buffer copy
Hwc_setcopy_heo_src_content
    for (unsigned int i = 0; i < cur_layer->visibleregionscreen.numrects; i++) {        uint8_t *cur_dst_addr = dst_addr;
   uint8_t *cur_src_addr = src_addr;        for (int j = 0; J < H; j + +) {            memcpy (cur_dst_addr, cur_src_addr, cpy_size);            CUR_DST_ADDR = &cur_dst_addr[cpy_size];            CUR_SRC_ADDR = &cur_src_addr[(cur_layer->displayframe.right-cur_layer->displayframe.left) * (prev_ HANDLE->UIBPP/8)];        }        cur_rect++;    }



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.