### MPP Library Compilation and Usage Guide Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Provides guidance on compiling and using the MPP library, directing users to relevant sections for quick setup and understanding. ```APIDOC For quick understanding of MPP usage and demos, refer to Chapter 4: MPP Demo Description. For quick compilation and usage of MPP code, refer to Chapter 5: MPP Library Compilation and Usage. For detailed design insights, consult the readme.txt in the MPP code root directory, documents in the doc directory, and header file comments. ``` -------------------------------- ### MPP C Library Initialization Example Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md A basic C code snippet demonstrating the initialization of the MPP library, which is a prerequisite for using its functionalities. ```C #include int main() { MppCtx ctx; MppApi api; MppCtxCreate(&ctx, &api); // ... use MPP API ... MppCtxDestroy(ctx); return 0; } ``` -------------------------------- ### Pkgconfig File Generation and Installation Source: https://github.com/rockchip-linux/mpp/blob/develop/CMakeLists.txt Configures and installs pkgconfig files ('rockchip_mpp.pc' and 'rockchip_vpu.pc') which are used by other projects to easily find and link against the Rockchip MPP and VPU libraries. ```cmake CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/rockchip_mpp.pc.cmake" "${CMAKE_BINARY_DIR}/rockchip_mpp.pc" @ONLY) CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/rockchip_vpu.pc.cmake" "${CMAKE_BINARY_DIR}/rockchip_vpu.pc" @ONLY) install(FILES "${CMAKE_BINARY_DIR}/rockchip_mpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") install(FILES "${CMAKE_BINARY_DIR}/rockchip_vpu.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") ``` -------------------------------- ### Encoder Demo Usage Example Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md An example command to encode 30 frames of a YUV file using mpi_enc_test. ```bash mpi_enc_test -w 1920 -h 1080 -t 7 -i /data/ocrean.yuv -o /data/out.h264 -n 30 ``` -------------------------------- ### NDK libc.so Replacement Guide Source: https://github.com/rockchip-linux/mpp/blob/develop/build/android/aarch64/fix/readme.txt Instructions on how to replace the default NDK libc.so with a compatible version to resolve undefined reference errors, particularly for `__system_property_get`. ```bash echo "NOTE: Google original ndk libc.so is lack of some symbol and it will cause error as follows:" echo "undefined reference to `__system_property_get'" echo "Please use the libc.so in this directory to fix this issue." echo "Backup original libc.so in ndk first. Then Put lib.so to:" echo "path_to_ndk/platforms/android-21/arch-arm64/usr/lib/" ``` -------------------------------- ### CMake: Git Versioning and Hooks Setup Source: https://github.com/rockchip-linux/mpp/blob/develop/CMakeLists.txt This snippet configures project version information by querying Git history and installs Git hooks. It checks for a .git directory, uses the Git executable to retrieve commit information, and formats it for inclusion in the project's version header. It also copies git hooks from a specified directory. ```cmake set(VERSION_CNT 0) set(VERSION_MAX_CNT 9) set(VERSION_INFO "\"unknown mpp version for missing VCS info\"") foreach (CNT RANGE ${VERSION_MAX_CNT}) set(VERSION_HISTORY_${CNT} "NULL") endforeach(CNT) if(EXISTS "${PROJECT_SOURCE_DIR}/.git") find_host_package(Git) if(GIT_FOUND) # get current version info set(GIT_LOG_FORMAT "%h author: %<|(30)%an %cd %s") execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --date=short --pretty=format:${GIT_LOG_FORMAT} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE EXEC_OUT ERROR_VARIABLE EXEC_ERROR RESULT_VARIABLE EXEC_RET OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE) if (NOT EXEC_RET) set(VERSION_INFO ${EXEC_OUT}) message(STATUS "current version:") message(STATUS "${VERSION_INFO}") string(REPLACE "\"" "\\\"" VERSION_INFO ${VERSION_INFO}) set(VERSION_INFO "\"${VERSION_INFO}\"") else() message(STATUS "git ret ${EXEC_RET}") message(STATUS "${EXEC_ERROR}") endif() set(GIT_LOG_FORMAT "%h author: %<|(30)%an %cd %s %d") # get history version information # setup logs message(STATUS "git version history:") foreach (CNT RANGE ${VERSION_MAX_CNT}) execute_process(COMMAND ${GIT_EXECUTABLE} log HEAD~${CNT} -1 --oneline --date=short --pretty=format:${GIT_LOG_FORMAT} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE EXEC_OUT ERROR_VARIABLE EXEC_ERROR RESULT_VARIABLE EXEC_RET OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE) if (NOT EXEC_RET) set(VERSION_LOG ${EXEC_OUT}) string(REPLACE "\"" "\\\"" VERSION_LOG ${VERSION_LOG}) message(STATUS ${VERSION_LOG}) set(VERSION_HISTORY_${CNT} "\"${VERSION_LOG}\"") math(EXPR VERSION_CNT "${VERSION_CNT}+1") endif() endforeach(CNT) message(STATUS "total ${VERSION_CNT} git version recorded") endif() # add git hooks if (EXISTS "${PROJECT_SOURCE_DIR}/tools/hooks/") set(GIT_HOOK_SRC "${PROJECT_SOURCE_DIR}/tools/hooks/") if(EXISTS "${PROJECT_SOURCE_DIR}/.git/hooks") set(GIT_HOOK_DST "${PROJECT_SOURCE_DIR}/.git/hooks/") file(COPY ${GIT_HOOK_SRC} DESTINATION ${GIT_HOOK_DST}) message(STATUS "Install git hooks done") endif(EXISTS "${PROJECT_SOURCE_DIR}/.git/hooks") endif(EXISTS "${PROJECT_SOURCE_DIR}/tools/hooks/") endif(EXISTS "${PROJECT_SOURCE_DIR}/.git") configure_file( "${PROJECT_SOURCE_DIR}/build/cmake/version.in" "${PROJECT_SOURCE_DIR}/mpp/version.h" ) ``` -------------------------------- ### Example: Decoding H.264 Stream with mpi_dec_test Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md This example demonstrates how to use the mpi_dec_test command to decode 30 frames of an H.264 bitstream located at /data/ocrean.h264. ```bash mpi_dec_test -t 7 -i /data/ocrean.h264 -n 30 ``` -------------------------------- ### MPP Unit Test Examples Source: https://github.com/rockchip-linux/mpp/blob/develop/test/CMakeLists.txt Examples demonstrating the usage of the `add_mpp_test` macro for various MPP components, including `mpp_info`, `mpi_dec` (with and without multi-threading), `mpi_enc`, `mpi_rc2`, and `mpi_dec_multi`. These calls specify the module name and the source file extension. ```cmake # mpp info test add_mpp_test(mpp_info c) # mpi decoder unit test add_mpp_test(mpi_dec c) # mpi decoder multi-thread input / output unit test add_mpp_test(mpi_dec_mt c) # mpi decoder no-thread input / output unit test add_mpp_test(mpi_dec_nt c) # mpi encoder unit test add_mpp_test(mpi_enc c) # mpi encoder multi-thread input / output unit test add_mpp_test(mpi_enc_mt cpp) # new mpi rc unit test add_mpp_test(mpi_rc2 c) # new dec multi unit test add_mpp_test(mpi_dec_multi c) ``` -------------------------------- ### Legacy MPP Unit Test Example Source: https://github.com/rockchip-linux/mpp/blob/develop/test/CMakeLists.txt An example demonstrating the usage of the `add_legacy_test` macro to add a unit test for the legacy `vpu_api` component. This call specifies the module name for the legacy test. ```cmake # legacy vpu_api unit test add_legacy_test(vpu_api) ``` -------------------------------- ### Example Usage of add_kmpp_base_test Macro Source: https://github.com/rockchip-linux/mpp/blob/develop/kmpp/base/test/CMakeLists.txt Demonstrates how to use the `add_kmpp_base_test` macro to add unit tests for different kmpp/base sub-modules, including kmpp_obj, kmpp_frame, kmpp_buffer, and kmpp_meta. ```cmake # kmpp object unit test add_kmpp_base_test(kmpp_obj) # kmpp frame unit test add_kmpp_base_test(kmpp_frame) # kmpp buffer unit test add_kmpp_base_test(kmpp_buffer) # kmpp meta unit test add_kmpp_base_test(kmpp_meta) ``` -------------------------------- ### MppPacket Initialization with External Malloc Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Example demonstrating how to initialize an MppPacket using memory allocated with malloc. Note that the library does not perform free operations on externally allocated memory. ```c // Example for external malloc initialization (no auto-free) void *external_buffer = malloc(1024); if (external_buffer) { MppPacket packet; packet.data = external_buffer; packet.size = 1024; packet.pos = external_buffer; packet.length = 1024; // ... use packet ... // Manual free required: free(external_buffer); } ``` -------------------------------- ### Download MPP Source Code Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Provides the official download address for MPP source code and instructions for cloning the repository. ```bash git clone https://github.com/rockchip-linux/mpp.git ``` -------------------------------- ### Encoder Demo Command-Line Arguments Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Describes the command-line arguments for the mpi_enc_test encoder demo, including input/output files, image properties, encoding parameters, and logging options. ```APIDOC mpi_enc_test command-line arguments: -i: Input image file. -o: Output bitstream file. -w: Image width in pixels. -h: Image height in pixels. -hstride: Distance between adjacent rows in the vertical direction, in bytes. -vstride: Interval number between image component rows, in units of 1. -f: Image color space format and memory layout, defaults to NV12. -t: Protocol type of the bitstream file. -tsrc: Source stream format, used only when testing overall encoding/decoding performance. -n: Maximum number of decoded frames. When testing with a long bitstream, only the first n frames can be output. -g: GOP reference mode, corresponding to different TSVC bitstreams. -rc: Bitrate control mode. 0:VBR; 1:CBR; 2:FIXQP; 3:AVBR. -bps: Bitrate constraint parameters. Command format: bps_target:bps_min:bps_max. -fps: Input/output frame rate control, defaults to 30. This parameter only indicates the ratio between input and output frame rates and is not related to the actual frame rate. -qc: Quality control. Only effective when the output bitstream format is H.264, H.265, VP8, and JPEG. -s: Number of MPP instances, defaults to 1. -v: Log options: 'q' for quiet mode; 'f' for FPS display. -ini: Additional encoding configuration ini (not yet effective). -slt: Verification file corresponding to the output bitstream. ``` -------------------------------- ### Install Headers Source: https://github.com/rockchip-linux/mpp/blob/develop/CMakeLists.txt Installs the header files from the 'inc/' directory into the system's include path, specifically under 'rockchip/', making them available for external projects. ```cmake install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/inc/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rockchip" FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### MPP Project Structure Overview Source: https://github.com/rockchip-linux/mpp/blob/develop/readme.txt Provides a hierarchical view of the MPP project directory structure, indicating the purpose of each major directory and sub-directory. ```makefile ---- top | |----- build CMake out-of-source build directory | | | |----- cmake cmake script directory | | | |----- android android build directory | | | |----- linux linux build directory | | | |----- vc10-x86_64 visual studio 2010 on x86_64 build directory | | | |----- vc12-x86_64 visual studio 2013 on x86_64 build directory | |----- doc design documents of mpp | |----- inc header file for external usage, including | platform header and mpi header | |----- mpp Media Process Platform : mpi function private | | implement and mpp infrastructure (vpu_api | | private layer) | | | |----- base base components including MppBuffer, MppFrame, | | MppPacket, MppTask, MppMeta, etc. | | | |----- common video codec protocol syntax interface for both | | codec parser and hal | | | |----- codec all video codec parser, convert stream to | | | protocol structure | | | | | |----- inc header files provided by codec module for | | | external usage | | | | | |----- dec | | | | | | | |----- dummy decoder parser work flow sample | | | | | | | |----- h263 | | | | | | | |----- h264 | | | | | | | |----- h265 | | | | | | | |----- m2v mpeg2 parser | | | | | | | |----- mpg4 mpeg4 parser | | | | | | | |----- vp8 | | | | | | | |----- vp9 | | | | | | | |----- jpeg | | | | | |----- enc | | | | | |----- dummy encoder controllor work flow sample | | | | | |----- h264 | | | | | |----- h265 | | | | | |----- jpeg | | | |----- hal Hardware Abstract Layer (HAL): modules used in mpi | | | | | |----- inc header files provided by hal for external usage | | | | | |----- iep iep user library | | | | | |----- pp post-processor user library | | | | | |----- rga rga user library | | | | | |----- deinter deinterlace function module including pp/iep/rga | | | | | |----- rkdec rockchip hardware decoder register generation | | | | | | | |----- h264d generate register file from H.264 syntax info | | | | | | | |----- h265d generate register file from H.265 syntax info | | | | | | | |----- vp9d generate register file from vp9 syntax info | | | | | |----- vpu vpu register generation library | | | | | |----- h263d generate register file from H.263 syntax info | | | | | |----- h264d generate register file from H.264 syntax info | | | ``` -------------------------------- ### MPP Utility Tools Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Introduces utility programs for unit testing the MPP library and hardware. These tools help in testing the software and hardware platform and the MPP library itself. ```APIDOC mpp_info_test: Reads and prints MPP library version information. mpp_buffer_test: Tests the kernel memory allocator. mpp_mem_test: Tests the C library memory allocator. mpp_runtime_test: Tests the software and hardware runtime environment. mpp_platform_test: Reads and tests chip platform information. ``` -------------------------------- ### H.264 Encoder Output Stream Format Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Describes the format of the H.264 encoder's output stream, specifically noting the presence of start codes. The encode_get_packet function returns the code stream with a '00 00 00 01' start code prefix. Users can manually remove this prefix if needed. ```c // Example of accessing the stream data from encode_get_packet // Assume 'packet' is the data returned by encode_get_packet // The stream data starts after the 4-byte start code (00 00 00 01) // If start code needs to be removed: // const uint8_t* stream_data = packet.data + 4; // size_t stream_size = packet.size - 4; ``` -------------------------------- ### MppPacket Initialization by Copy Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Illustrates initializing an MppPacket by copying data. In this scenario, the library manages the memory and will free it upon MppPacket release. ```c // Example for copy initialization (auto-free managed by library) MppPacket packet_copy; // Assume packet_source is an existing MppPacket // mpp_packet_copy(&packet_copy, &packet_source); // Hypothetical copy function // ... use packet_copy ... // Library handles free when packet_copy is released. ``` -------------------------------- ### Video Decoding with MppPacket and MppFrame Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Demonstrates a simplified video decoding process using MppPacket for input stream data and MppFrame for output decoded frames. ```APIDOC Video Decoding Example: 1. Input: Stream data is assigned to MppPacket (address and size). 2. Input via put_packet interface. 3. Output: Decoded image obtained as MppFrame via get_frame interface. This process represents a basic video decoding workflow. ``` -------------------------------- ### Get Stream Header Data Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Used to obtain stream header data separately. MPP_ENC_GET_EXTRA_INFO is an older, non-thread-safe command. MPP_ENC_GET_HDR_SYNC is the recommended command. ```c #define MPP_ENC_GET_HDR_SYNC 0x10000004 // Input parameter: MppPacket (user allocates and encapsulates) // Returns: Data copied to MppPacket. #define MPP_ENC_GET_EXTRA_INFO 0x10000003 // Input parameter: MppPacket* (internal MppPacket obtained) // Returns: Internal MppPacket data. Not thread-safe. ``` -------------------------------- ### VP8 Encoding Parameters Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Configuration options for VP8 video encoding, focusing on QP control. ```APIDOC vp8:qp_init: S32 Description: Initial QP value. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_max: S32 Description: Maximum QP value for P and B frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_min: S32 Description: Minimum QP value for P and B frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_max_i: S32 Description: Maximum QP value for I-frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_min_i: S32 Description: Minimum QP value for I-frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_step: S32 Description: QP step between adjacent frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:qp_delta_ip: S32 Description: QP difference between I-frames and P-frames. Used for forward compatibility with MPP versions. Type: RK_S32 vp8:disable_ivf: S32 Description: Disable flag for IVF container encapsulation. If disabled, the hardware encoded bitstream data will not be encapsulated in IVF format. 0 - Enabled. 1 - Disabled. Type: RK_S32 ``` -------------------------------- ### HAL Dummy Library CMake Configuration Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/hal/dummy/CMakeLists.txt Configures the CMake build system to create a static library named 'hal_dummy'. It includes the necessary header and source files for the HAL dummy decoder API. ```cmake # vim: syntax=cmake # hal dummy decoder api set(HAL_DUMMY_API ../inc/hal_dummy_dec_api.h ../inc/hal_dummy_enc_api.h ) # hal dummy header set(HAL_DUMMY_HDR ) # hal dummy decoder sourse set(HAL_DUMMY_SRC hal_dummy_dec_api.c hal_dummy_enc_api.c ) add_library(hal_dummy STATIC ${HAL_DUMMY_API} ${HAL_DUMMY_HDR} ${HAL_DUMMY_SRC} ) set_target_properties(hal_dummy PROPERTIES FOLDER "mpp/hal") ``` -------------------------------- ### H.264 Encoder Output Stream Format Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Describes the format of the encoded bitstream produced by the H.264 encoder, including the presence of start codes and how to handle them. ```APIDOC H.264 Encoder Output Stream: Format: Hardware fixed output includes start codes (00 00 00 01). Handling: To remove start codes, copy data from the address after the start code. ``` -------------------------------- ### MPP Framework Architecture Source: https://github.com/rockchip-linux/mpp/blob/develop/readme.txt Visual representation of the MPP framework, showing its integration with higher-level interfaces like OpenMax/gstreamer/libva and lower-level kernel drivers. ```text +---------------------------------------+ | | | OpenMax / gstreamer / libva | | | +---------------------------------------+ +-------------------- MPP ----------------------+ | | +-------------------------+ +--------+ | | | | | | | | | MPI / MPP | | | | | | buffer queue manage | | | | | | | | | | | +-------------------------+ | | | | | | | | +-------------------------+ | | | | | | | | | | | codec | | OSAL | | | | decoder / encoder | | | | | | | | | | | +-------------------------+ | | | | | | | | +-----------+ +-----------+ | | | | | | | | | | | | | parser | | HAL | | | | | | recoder | | reg_gen | | | | | | | | | | | | | +-----------+ +-----------+ +--------| | | | +-------------------- MPP ----------------------+ +---------------------------------------+ | | | kernel | | RK vcodec_service / v4l2 | | | +---------------------------------------+ ``` -------------------------------- ### MPP Encoder: Get Encoded Packet Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Obtains the packet description information of the completed encoding from the MPP encoder instance. This function retrieves the output bitstream data after encoding is finished. ```APIDOC MPP_RET encode_get_packet(MppCtx ctx, MppPacket *packet) - Obtains the packet description information of the completed encoding from the MPP encoder instance specified by ctx. - Parameters: - ctx: MPP decoder instance - packet: A pointer to get an instance of MppPacket. - Return parameter: Runtime error mode - Function: Retrieves the encoded bitstream packet. ``` -------------------------------- ### MPP System Architecture Overview Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Illustrates the layered architecture of the MPP platform, from hardware acceleration modules to the application layer, highlighting the roles of the hardware, kernel driver, MPP layer, operating system, and application. ```APIDOC Hardware Layer: - Video acceleration modules (vdpu, vepu, rkvdec, rkvenc). Kernel Driver Layer: - Encoder hardware device driver. - MMU, memory, clock, power management modules. - Supports Linux kernel versions: 3.10, 4.4, 4.19, 5.10, 6.1. - MPP library depends on kernel drivers. MPP Layer (User Space): - Abstracts OS and chip platform differences. - Provides unified MPI interfaces. - Components: MPI module, OSAL module, HAL module, Video Decoder, Video Encoder, Video Process modules. Operating System Layer: - Runtime platform for MPP user space (e.g., Android, Debian Linux). Application Layer: - Interacts with MPP via MPI. - Connects to middleware (OpenMax, gstreamer) or direct customer applications. ``` -------------------------------- ### Compile MPP for Android (Cross-Compilation) Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Instructions for cross-compiling the MPP library for Android using NDK. It details setting up the NDK environment and running the compilation script. ```bash # Set up NDK environment (example using r16b) # export ANDROID_NDK=/home/pub/ndk/android-ndk-r16b # Navigate to the build directory for ARM cd build/android/arm/ # Generate Makefiles ./make-Android.bash # Compile with multiple jobs (e.g., 16) make -j16 ``` -------------------------------- ### H.265 Encoding Parameters Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Configuration options for H.265 video encoding, including QP settings and SAO control. ```APIDOC h265:qp_min_i: S32 Description: Minimum QP value for I-frames. Used for forward compatibility with MPP versions. Type: RK_S32 h265:qp_step: S32 Description: QP step between adjacent frames. Used for forward compatibility with MPP versions. Type: RK_S32 h265:qp_delta_ip: S32 Description: QP difference between I-frames and P-frames. Used for forward compatibility with MPP versions. Type: RK_S32 h265:sao_luma_disable: S32 Description: Disable flag for SAO (Sample Adaptive Offset) on the luma component. 0 - SAO enabled for luma. 1 - SAO disabled for luma. Type: RK_S32 h265:sao_chroma_disable: S32 Description: Disable flag for SAO (Sample Adaptive Offset) on the chroma component. 0 - SAO enabled for chroma. 1 - SAO disabled for chroma. Type: RK_S32 ``` -------------------------------- ### Build MPP RC Unit Tests Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/codec/rc/test/CMakeLists.txt Example usage of the `add_mpp_rc_test` macro to build unit tests for the 'rc_base' and 'rc_api' modules of the MPP rate control component. ```cmake # mpp rc unit test add_mpp_rc_test(rc_base) # mpp rc api test add_mpp_rc_test(rc_api) ``` -------------------------------- ### Rate Control API Information Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Commands to query and manage rate control strategies. These include getting all supported APIs, APIs by type, registering custom APIs, and activating specific APIs. ```c #define MPP_ENC_GET_RC_API_ALL 0x10000008 // Input: RcApiQueryAll* pointer // Output: Fills structure with all supported RcApi information. #define MPP_ENC_GET_RC_API_BY_TYPE 0x10000009 // Input: RcApiQueryType* pointer and MppCodingType // Output: Fills structure with RcApi information for the specified coding type. #define MPP_ENC_SET_RC_API_CFG 0x1000000A // Input: RcImplApi* pointer (registers external rate control strategy) #define MPP_ENC_GET_RC_API_CURRENT 0x1000000B // Input: RcApiBrief* pointer // Output: Fills structure with information of the currently used RcApi. #define MPP_ENC_SET_RC_API_CURRENT 0x1000000C // Input: RcApiBrief* pointer (activates RcApi by name) ``` -------------------------------- ### Build HWpq Unit Test Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/vproc/vdpp/test/CMakeLists.txt Configures the build process for the hwpq unit test executable, which calls the libvdpp.so library. It links against vdpp and ASAN_LIB, sets the target folder, and defines a test case. ```cmake # hwpq test (call libvdpp.so) add_executable(hwpq_test hwpq_test.cpp) target_link_libraries(hwpq_test vdpp ${ASAN_LIB}) set_target_properties(hwpq_test PROPERTIES FOLDER "mpp/vproc/vdpp") add_test(NAME hwpq_test COMMAND hwpq_test) endif() ``` -------------------------------- ### MPP Decoder Data Flow Interface Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Details the MPI functions for decoder data flow, enabling users to input streams and receive output images. Includes functions for putting packets and getting frames. ```APIDOC decode_put_packet: Interface definition: MPP_RET decode_put_packet(MppCtx ctx, MppPacket packet) Input parameter: ctx: MPP Decoder instance. packet: Bit stream data to be input. Return parameter: Runtime error code. Function: Inputs stream data 'packet' to MPP decoder instance 'ctx'. ``` -------------------------------- ### CMake Build System Configuration Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/hal/rkenc/CMakeLists.txt This snippet shows the main CMakeLists.txt file for the Rockchip MPP project, which includes subdirectories for common modules and specific video encoding modules (H.264, H.265, JPEG). ```cmake # vim: syntax=cmake add_subdirectory(common) add_subdirectory(h264e) add_subdirectory(h265e) add_subdirectory(jpege) ``` -------------------------------- ### MPP Project Setup and Library Naming Source: https://github.com/rockchip-linux/mpp/blob/develop/CMakeLists.txt Initializes the CMake project named 'rk_mpp'. It sets up default library names for static and shared builds, differentiating between Linux and Android targets for historical reasons. ```cmake project (rk_mpp) cmake_minimum_required (VERSION 2.8.8) # OBJECT libraries require 2.8.8 include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckSymbolExists) include(CheckCXXCompilerFlag) # setup output library name # Linux default name - rockchip_mpp and rockchip_vpu # Android default name - mpp and vpu # For historical reason libraries on Android is named as mpp and vpu. But for # better naming rule on Linux it should add vendor prefix. # So we use this ugly method to avoid massive maintain issue. if (NOT MPP_PROJECT_NAME) set(MPP_PROJECT_NAME rockchip_mpp) endif() set(MPP_STATIC ${MPP_PROJECT_NAME}_static) set(MPP_SHARED ${MPP_PROJECT_NAME}) if (NOT VPU_PROJECT_NAME) set(VPU_PROJECT_NAME rockchip_vpu) endif() set(VPU_STATIC ${VPU_PROJECT_NAME}_static) set(VPU_SHARED ${VPU_PROJECT_NAME}) ``` -------------------------------- ### MPP Plugin-based Custom Rate Control Strategy Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Explains the mechanism for users to define custom rate control strategies using plugin interfaces, with a caution for general users. ```APIDOC Mechanism: Plugin-based custom rate control. Interface: RcImplApi defines hook functions for user-defined processing at specific stages. Reference: Default H.264/H.265 rate control implementations (default_h264e/default_h265e). Status: Plugin mechanism is under development, interfaces and workflows may change. Recommendation: Only for users capable of understanding and maintaining the code. Not recommended for general users. ``` -------------------------------- ### MppEncCfg Set/Get Functions Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Provides C functions for setting and getting various data types (s32, u32, s64, u64, ptr, st) within the MppEncCfg structure. These functions are used with the MPP_ENC_SET_CFG/MPP_ENC_GET_CFG control interface commands. ```c MPP_RET mpp_enc_cfg_set_s32(MppEncCfg cfg, const char *name, RK_S32 val); MPP_RET mpp_enc_cfg_set_u32(MppEncCfg cfg, const char *name, RK_U32 val); MPP_RET mpp_enc_cfg_set_s64(MppEncCfg cfg, const char *name, RK_S64 val); MPP_RET mpp_enc_cfg_set_u64(MppEncCfg cfg, const char *name, RK_U64 val); MPP_RET mpp_enc_cfg_set_ptr(MppEncCfg cfg, const char *name, void *val); MPP_RET mpp_enc_cfg_set_st(MppEncCfg cfg, const char *name, void *val); MPP_RET mpp_enc_cfg_get_s32(MppEncCfg cfg, const char *name, RK_S32 *val); MPP_RET mpp_enc_cfg_get_u32(MppEncCfg cfg, const char *name, RK_U32 *val); MPP_RET mpp_enc_cfg_get_s64(MppEncCfg cfg, const char *name, RK_S64 *val); MPP_RET mpp_enc_cfg_get_u64(MppEncCfg cfg, const char *name, RK_U64 *val); MPP_RET mpp_enc_cfg_get_ptr(MppEncCfg cfg, const char *name, void **val); MPP_RET mpp_enc_cfg_get_st(MppEncCfg cfg, const char *name, void *val); ``` -------------------------------- ### CMake Build Configuration for Rockchip MPP Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/hal/CMakeLists.txt This snippet shows the CMake configuration for the Rockchip MPP project. It includes setting include directories, adding subdirectories for different hardware modules (vpu, rkdec, rkenc, dummy, common), defining a static library 'mpp_hal', setting target properties, and linking against various hardware acceleration libraries. ```cmake # vim: syntax=cmake include_directories(worker/inc) include_directories(common) # ---------------------------------------------------------------------------- # add hardware hal # ---------------------------------------------------------------------------- add_subdirectory(vpu) add_subdirectory(rkdec) add_subdirectory(rkenc) add_subdirectory(dummy) add_subdirectory(common) # ---------------------------------------------------------------------------- # add mpp_hal implement # ---------------------------------------------------------------------------- add_library(mpp_hal STATIC mpp_enc_hal.cpp hal_task.cpp mpp_hal.cpp ) set_target_properties(mpp_hal PROPERTIES FOLDER "mpp/hal") target_link_libraries(mpp_hal ${HAL_AVSD} ${HAL_AVS2D} ${HAL_H263D} ${HAL_H264D} ${HAL_H265D} ${HAL_MPEG2D} ${HAL_MPEG4D} ${HAL_VP8D} ${HAL_VP9D} ${HAL_JPEGD} ${HAL_AV1D} ${HAL_H264E} ${HAL_JPEGE} ${HAL_H265E} ${HAL_VP8E} hal_dummy ) ``` -------------------------------- ### MPP Decoder Demo Source Code Reference Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Points to the source code file for the detailed implementation of the MPP decoder demo. ```c // Source code for the decoder demo is located in: // test/mpi_dec_test.c ``` -------------------------------- ### Decoding an H.264 File with mpi_dec_test Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Example of decoding 30 frames of an H.264 file located at /data/ocrean.h264 using the mpi_dec_test program. The command specifies the codec type for H.264 as 7 and the number of frames to decode as 30. ```bash mpi_dec_test -t 7 -i /data/ocrean.h264 -n 30 ``` -------------------------------- ### MPP Encoder Configuration Interface Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Provides C functions for setting and getting various data types (s32, u32, s64, u64, ptr, st) for MPP encoder configuration using a string-based key map. ```c MPP_RET mpp_enc_cfg_set_s32(MppEncCfg cfg, const char *name, RK_S32 val); MPP_RET mpp_enc_cfg_set_u32(MppEncCfg cfg, const char *name, RK_U32 val); MPP_RET mpp_enc_cfg_set_s64(MppEncCfg cfg, const char *name, RK_S64 val); MPP_RET mpp_enc_cfg_set_u64(MppEncCfg cfg, const char *name, RK_U64 val); MPP_RET mpp_enc_cfg_set_ptr(MppEncCfg cfg, const char *name, void *val); MPP_RET mpp_enc_cfg_set_st(MppEncCfg cfg, const char *name, void *val); MPP_RET mpp_enc_cfg_get_s32(MppEncCfg cfg, const char *name, RK_S32 *val); MPP_RET mpp_enc_cfg_get_u32(MppEncCfg cfg, const char *name, RK_U32 *val); MPP_RET mpp_enc_cfg_get_s64(MppEncCfg cfg, const char *name, RK_S64 *val); MPP_RET mpp_enc_cfg_get_u64(MppEncCfg cfg, const char *name, RK_U64 *val); MPP_RET mpp_enc_cfg_get_ptr(MppEncCfg cfg, const char *name, void **val); MPP_RET mpp_enc_cfg_get_st(MppEncCfg cfg, const char *name, void *val); ``` -------------------------------- ### Simple Video Decoding Process Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Illustrates the basic process of video decoding using MppPacket for bitstream data and MppFrame for image data. It shows how to input bitstream data and retrieve decoded frames. ```C // Example of simple video decoding process // Bitstream data is assigned to MppPacket MppPacket input_packet = create_mpp_packet(bitstream_data, size); // Input the packet through the put_packet interface put_packet(decoder_handle, input_packet); // Get the decoded image frame MppFrame at the output side MppFrame output_frame = get_frame(decoder_handle); // Process the output_frame... ``` -------------------------------- ### Add Legacy Unit Test (CMake Macro) Source: https://github.com/rockchip-linux/mpp/blob/develop/test/CMakeLists.txt Defines a CMake macro `add_legacy_test` for integrating legacy unit tests. This macro creates an executable for the legacy test, links necessary libraries (like `dl` and `pthread`, conditionally `ASAN_LIB` if `ASAN_CHECK` is enabled), sets target properties, and installs the executable. ```cmake macro(add_legacy_test module) set(test_name ${module}_test) string(TOUPPER ${test_name} test_tag) option(${test_tag} "Build legacy ${module} unit test" ${BUILD_TEST}) if(${test_tag}) add_executable(${test_name} ${test_name}.c) if(ASAN_CHECK) target_link_libraries(${test_name} ${ASAN_LIB} pthread dl) else(ASAN_CHECK) target_link_libraries(${test_name} dl) endif(ASAN_CHECK) set_target_properties(${test_name} PROPERTIES FOLDER "test") install(TARGETS ${test_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endmacro() ``` -------------------------------- ### MPP Compilation with CMake Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_CN.md Details the compilation process using CMake, specifying the required CMake version and general compilation steps. ```cmake # Ensure CMake version 2.8.12 or higher is installed. # Recommended version: 3.x. # Example CMake configuration (adjust paths as needed): # cmake -DCMAKE_TOOLCHAIN_FILE=path/to/your/toolchain.cmake .. # Build the project: # make -j16 ``` -------------------------------- ### Build JPEG Encoder Static Library (CMake) Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/codec/enc/jpeg/CMakeLists.txt Configures CMake to build a static library for JPEG encoding. It includes the current directory for header files, defines the library name as 'CODEC_JPEGE', specifies the source file 'jpege_api_v2.c', links it with the 'mpp_base' library, and sets the target property 'FOLDER' to 'mpp/codec'. ```cmake # vim: syntax=cmake include_directories(.) add_library(${CODEC_JPEGE} STATIC jpege_api_v2.c ) target_link_libraries(${CODEC_JPEGE} mpp_base) set_target_properties(${CODEC_JPEGE} PROPERTIES FOLDER "mpp/codec") ``` -------------------------------- ### Configure and Build IEP Unit Test (CMake) Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/vproc/iep/test/CMakeLists.txt This snippet shows how to configure and build the 'iep_test' executable using CMake. It defines an option to enable the test, creates the executable, links necessary libraries (MPP_SHARED and utils), sets the target folder, and adds it as a test case. ```cmake # vim: syntax=cmake # ---------------------------------------------------------------------------- # mpp/vproc/iep built-in unit test case # ---------------------------------------------------------------------------- # iep unit test option(IEP_TEST "Build base iep unit test" ${BUILD_TEST}) if (IEP_TEST) add_executable(iep_test iep_test.cpp) target_link_libraries(iep_test ${MPP_SHARED} utils) set_target_properties(iep_test PROPERTIES FOLDER "mpp/vproc/iep") add_test(NAME iep_test COMMAND iep_test) endif() ``` -------------------------------- ### CMake Build Configuration for HAL Vepu Common Module Source: https://github.com/rockchip-linux/mpp/blob/develop/mpp/hal/vpu/common/CMakeLists.txt This snippet demonstrates how to configure the build system using CMake to create a static library for the HAL Vepu common module. It specifies include directories, source files, and link libraries. ```cmake # vim: syntax=cmake include_directories(.) # hal vepu541 common module add_library(hal_vepu_common STATIC vepu_common.c vepu_common.h ) target_link_libraries(hal_vepu_common mpp_base) set_target_properties(hal_vepu_common PROPERTIES FOLDER "mpp/hal") ``` -------------------------------- ### Add MPP Sub-module Unit Test (CMake Macro) Source: https://github.com/rockchip-linux/mpp/blob/develop/test/CMakeLists.txt Defines a CMake macro `add_mpp_test` to streamline the creation of unit tests for MPP sub-modules. It handles executable creation, linking against MPP shared libraries and utilities, setting target properties, and installation. The macro takes the module name and its file extension as input. ```cmake macro(add_mpp_test module ext) set(test_name ${module}_test) set(file_name ${test_name}.${ext}) string(TOUPPER ${test_name} test_tag) option(${test_tag} "Build mpp ${module}.${ext} unit test" ${BUILD_TEST}) if(${test_tag}) add_executable(${test_name} ${file_name} mpp_event_trigger.c mpp_parse_cfg.c) target_link_libraries(${test_name} ${MPP_SHARED} utils) set_target_properties(${test_name} PROPERTIES FOLDER "test") install(TARGETS ${test_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endmacro() ``` -------------------------------- ### MppCtx for MPP Instance Management Source: https://github.com/rockchip-linux/mpp/blob/develop/doc/Rockchip_Developer_Guide_MPP_EN.md Details the MppCtx structure, which serves as the MPP instance context handle for users (decoder or encoder). It is created via mpp_create, initialized with mpp_init, used with decode/encode functions, and destroyed with mpp_destroy. ```c typedef void MppCtx; // Opaque handle to the MPP context // Usage process: // 1. Create MppCtx instance and MppApi structure using mpp_create() // 2. Initialize type of encoding or decoding and format using mpp_init() // 3. Access context by decode_xxx/encode_xx or poll/dequeuer/enqueue function // 4. Destroy MppCtx using mpp_destroy() at the end of use ```