frame_buffer

[Chinese]

1. Overview

The Frame Buffer module provides video frame buffer memory management functionality, primarily used for display and encoding scenarios. This module has the following core features:

  1. Dual Heap Memory Management: Supports memory allocation from PSRAM’s DISPLAY heap and ENCODE heap respectively to meet different application requirements

  2. Secure Memory Allocation: Uses 32-byte memory alignment to ensure efficient and compatible memory access

  3. CRC Checksum Protection: Generates CRC-8 checksum for each allocated buffer to prevent duplicate freeing and illegal access

  4. Memory Initialization: Newly allocated memory is initialized with a specific pattern (0xFB) for debugging and troubleshooting

  5. Error Handling: Includes safety mechanisms such as null pointer checks and memory allocation failure handling

  • For usage, you can refer to the DVP example project to see how to use frame buffer related API interfaces to implement image memory buffer management:

2. API functions

  • frame_buffer_display_malloc() - Allocate display frame buffer from DISPLAY heap

  • frame_buffer_display_free() - Free display frame buffer

  • frame_buffer_encode_malloc() - Allocate encoding frame buffer from ENCODE heap

  • frame_buffer_encode_free() - Free encoding frame buffer

Suitable for multimedia applications requiring efficient and secure memory management, such as video display systems and video encoding pipelines.

Note

This module depends on the PSRAM module, ensure it is initialized before use. PSRAM initialization consists of two parts: one is the initialization of the entire PSRAM hardware module, the other is the initialization of PSRAM’s DISPLAY heap and ENCODE heap. The initialization of DISPLAY heap and ENCODE heap is based on PSRAM initialization, ensure they are initialized before use. PSRAM module initialization is based on a voting mechanism, as modules using PSRAM are not limited to multimedia and can also use it as Heap. Voting interface reference: bk_pm_module_vote_psram_ctrl. The initialization of DISPLAY heap and ENCODE heap is implemented by calling pre-registered callback functions after PSRAM power-on initialization. Specific reference: bk_psram_frame_buffer_init.

4. Heap Size Definitions

The following macros define PSRAM memory region size configurations, corresponding to memory region definitions in the linker script:

  • PSRAM_MEM_SLAB_USER_SIZE - User heap memory size configuration (CONFIG_PSRAM_MEM_SLAB_USER_SIZE)

  • PSRAM_MEM_SLAB_AUDIO_SIZE - Audio heap memory size configuration (CONFIG_PSRAM_MEM_SLAB_AUDIO_SIZE)

  • PSRAM_MEM_SLAB_ENCODE_SIZE - Encoding heap memory size configuration (CONFIG_PSRAM_MEM_SLAB_ENCODE_SIZE)

  • PSRAM_MEM_SLAB_DISPLAY_SIZE - Display heap memory size configuration (CONFIG_PSRAM_MEM_SLAB_DISPLAY_SIZE)

These macros define PSRAM memory region sizes for configuring memory allocation and management.

Note

Heap size definition: To modify different heap sizes, simply modify the configuration file in the corresponding project. Reference app project: ./projects/app/partitions/bk7258/ram_regions.csv. Where PSRAM_MEM_SLAB_USER_SIZE, PSRAM_MEM_SLAB_AUDIO_SIZE, PSRAM_MEM_SLAB_ENCODE_SIZE, PSRAM_MEM_SLAB_DISPLAY_SIZE correspond to the sizes of memory regions, in bytes.