Video Data Obtaining
Video data can be obtained through the cooperation between functional modules such as the ISP, MIPI RX, and VI. This section describes the overall API call sequence, API call sequence regarding each module, and precautions for obtaining video data.
Currently, the following functional modules are required to obtain video data:
- ISP system control
The system control function is used to register the 3A algorithm, register the sensor driver, initialize the ISP firmware, run the ISP firmware, exit the ISP firmware, and configure the image signal processing (ISP) attributes.
- MIPI RX ioctl command words
MIPI RX is a collection unit that supports multiple differential video input interfaces. It receives data from the MIPI, LVDS, sub-LVDS, and HiSPI interfaces through the combo PHY. MIPI RX supports data transmission at multiple speeds and resolutions by configuring different function modes and supports multiple external input devices.
- Video Input (VI)
The VI module captures video images, performs operations such as cropping, color optimization, brightness optimization, and noise removal on the images, and outputs YUV or RAW images.
Overall Process

The API call sequence is as follows:
- Call hi_mpi_sys_init to initialize the media data processing system.
- Use the MIPI RX ioctl command word to initialize the MIPI/sensor hardware interconnection information. For details, see Initializing the MIPI/Sensor Hardware Interconnection Information.
- Call the VI functional API to initialize the VI module. For details, see Initializing the VI Module.
- Call the ISP system control API to initialize and run the ISP module. For details, see Initializing and Running the ISP Module.
- Call the VI functional API to obtain the processed image data. For details, see Obtaining Processed Image Data.
- Call the ISP functional API to free ISP module resources. For details, see Releasing the Resources of the ISP Module.
- Call the VI functional API to free VI module resources. For details, see Releasing VI Resources.
- Use the MIPI RX ioctl command word to exit the MIPI/sensor hardware. For details, see Exiting the MIPI/Sensor Hardware.
- Call hi_mpi_sys_exit to free the resources of the media data processing system.
Initializing the MIPI/Sensor Hardware Interconnection Information

- Run the HI_MIPI_SET_HS_MODE command word to set the mode.
- Run the HI_MIPI_ENABLE_MIPI_CLOCK command word to enable the MIPI clock.
- Run the HI_MIPI_RESET_MIPI command word to reset the MIPI connected to the sensor.
- (Optional) Run the HI_MIPI_CONFIG_SENSOR_CLOCK command word to configure the sensor clock.
- (Optional) Run the HI_MIPI_ENABLE_SENSOR_CLOCK command word to enable the sensor clock.
- Run the HI_MIPI_RESET_SENSOR command word to reset the sensor.
- Run the HI_MIPI_SET_DEV_ATTR command word to configure the attributes of the MIPI Rx device.
- Run the HI_MIPI_UNRESET_MIPI command word to deassert the reset on the MIPI device.
- Run the HI_MIPI_UNRESET_SENSOR command word to cancel the sensor resetting.
Initializing the VI Module
The process of initializing the VI module varies according to the data source, data format, and mode.

Initializing and Running the ISP Module

- Call hi_mpi_isp_sensor_reg_callback to register the common algorithm of the sensor driver.
- (Optional) Call hi_mpi_ae_sensor_reg_callback and hi_mpi_awb_sensor_reg_callback to register the AE and AWB algorithms (2A algorithms) of the built-in sensor driver.
You can register a custom algorithm as required.
- (Optional) Call hi_mpi_ae_register and hi_mpi_awb_register to initialize the built-in 2A algorithms.
You can register a custom algorithm as required.
- Call hi_mpi_isp_mem_init to initialize the internal resources of the ISP module.
- Call hi_mpi_isp_set_pub_attr to initialize the algorithm module.
- Call hi_mpi_isp_init to initialize the ISP firmware.
- Enable a separate thread and call hi_mpi_isp_run to run the main scheduling service process of the ISP algorithm.
Obtaining Processed Image Data
- Obtaining YUV data
After images are processed by VI, obtain the images from the VI channel for processing. The typical API call sequence is as follows:
- (Optional) Wait for the image processing completion event by using the system file descriptor and select/epoll wait mechanism. You can obtain the system file descriptor of a specified channel by calling hi_mpi_vi_get_chn_fd. After a frame of image data is obtained and processed, the select/epoll read wait request of the system is woken up.
- Obtain the processed image data by calling hi_mpi_vi_get_chn_frame. In this case, the memory corresponding to the image data is automatically occupied. You must free the memory after processing the image data by calling hi_mpi_vi_release_chn_frame.
- If you want to deliver the image data obtained by calling hi_mpi_vi_get_chn_frame to other processes, obtain the acltdtBuf handle by using the returned hi_video_frame.user_data[0], and then use the shared buffer management API (such as acltdtCopyBufRef) and the shared queue management API (such as acltdtEnqueue) to deliver objects to other processes.
- Obtaining RAW data
After images are processed by VI, obtain the images from the VI pipe for processing. The typical API call sequence is as follows:
- (Optional) Wait for the image processing completion event by using the system file descriptor and select/epoll wait mechanism. You can obtain the system file descriptor of a specified channel by calling hi_mpi_vi_get_pipe_fd. After a frame of image data is obtained and processed in the background, the select/epoll read wait request of the system is woken up.
- Obtain the processed image data by calling hi_mpi_vi_get_pipe_frame. In this case, the memory corresponding to the image data is automatically occupied. You must free the memory after processing the image data by calling hi_mpi_vi_release_pipe_frame.
- If you want to deliver the image data obtained by calling hi_mpi_vi_get_pipe_frame to other processes, obtain the acltdtBuf handle by using the returned hi_video_frame.user_data[0], and then use the shared buffer management API (such as acltdtCopyBufRef) and the shared queue management API (such as acltdtEnqueue) to deliver objects to other processes.
Releasing the Resources of the ISP Module

- Call hi_mpi_isp_exit to deinitialize the ISP firmware.
- Call hi_mpi_ae_unregister and hi_mpi_awb_unregister to deinitialize the AE and AWB algorithms.
- Call hi_mpi_ae_sensor_unreg_callback and hi_mpi_awb_sensor_unreg_callback to deregister the AE and AWB algorithms of the sensor driver.
- Call hi_mpi_isp_sensor_unreg_callback to deregister the common algorithms of the sensor driver.
Exiting the MIPI/Sensor Hardware

- Run the HI_MIPI_RESET_SENSOR command word to reset the sensor.
- Run the HI_MIPI_DISABLE_SENSOR_CLOCK command word to disable the clock connected to the sensor.
- Run the HI_MIPI_RESET_MIPI command word to reset the MIPI connected to the sensor.
- Run the HI_MIPI_DISABLE_MIPI_CLOCK command word to disable the MIPI clock.






