MPP
MPP (Multimedia Processing Platform) Development Guide.
1. Overview
1.1 Purpose
This document primarily introduces the framework hierarchy and open API interfaces related to multimedia in SpacemiT, facilitating developers to quickly get started or perform secondary development.
1.2 Scope
Applicable to SpacemiT's K1 series SOC.
1.3 Target Audience
- Application Development Engineers
- Multimedia Middleware Development and Maintenance Engineers
1.4 Document Structure
This document first introduces the overall multimedia framework structure and its brief description, followed by detailed explanations of the MPP module, VPU module, JPU module, ISP/CPP/MIPI-CSI module, etc.
2 Multimedia Framework
2.1 Framework Hierarchy Diagram and Description
The framework is divided into 4 layers, from top to bottom:
- APP Layer: Includes third-party apps and self-developed apps. Third-party apps generally use open-source frameworks like GStreamer and FFmpeg for video encoding and decoding. For example, the default mpv player in Bianbu and commonly used Video (totem). Self-developed apps currently include reference demos or tests provided by us that interface with the API.
- mpv: Default local player in the Bianbu desktop system, interfaced with K1 hardware decoder, supports hardware decoding of H.264/HEVC/VP8/VP9/MPEG-4/MPEG-2/MJPEG, etc., up to 4K60 video playback.
- totem: Default local player in the Ubuntu desktop system, interfaced with K1 hardware decoder, supports hardware decoding of H.264/HEVC/VP8/VP9/MPEG-4/MPEG-2/MJPEG, etc., currently up to 4K30 video playback.
- cheese: Default camera app in the Bianbu/Ubuntu desktop system, supports preview, photo capture, and video recording, currently interfaced with K1 hardware encoder/decoder, enabling smooth 1080P30 preview and recording.
- chromium: Default browser in the Bianbu desktop system, interfaced with K1 hardware decoder, supports hardware decoding of H.264/HEVC, etc., up to 4K30 video playback.
- kodi: Open-source player commonly used by developers and enthusiasts, interfaced with K1 hardware decoder, supports hardware decoding of H.264/HEVC/VP8/VP9, etc., up to 4K60 video playback.
- v2d-test: Test program for the V2D module, also serves as a reference demo. The V2D module mainly performs non-compressed image format conversion, rotation, scaling, etc.
- mvx-player: Test program for the VPU module, also serves as a reference demo, performs video encoding and decoding via command line, output saved as files.
- jpu-test: Test program for the JPU module, also serves as a reference demo, performs video encoding and decoding via command line, output saved as files. The JPU module mainly performs JPEG image encoding and decoding.
- camera-test: Test program for the CAMERA pathway, also serves as a reference demo, performs image capture via command line. This test program is mainly for the API provided by K1's CPP-ISP-MIPICSI module, excluding USB cameras. For USB cameras, please use open-source standard test programs like v4l-utils.
- Open Source Multimedia Framework Layer (FRAMEWORK): Commonly includes GStreamer and FFmpeg. GStreamer and FFmpeg are comprehensive multimedia solutions, including muxer/demuxer/decoder/encoder/display implementations, and can be used directly as open-source frameworks. In this layer, we have implemented multiple plugins to interface with the hardware encoding/decoding library via MPP.
- FFmpeg: Interfaced with K1 hardware encoder/decoder, supports hardware decoding of H.264/HEVC/VP8/VP9/MPEG-4/MPEG-2/MJPEG, etc., up to 4K60 video playback, supports AV_PIX_FMT_DRM_PRIME and AV_PIX_FMT_NV12 output pixel formats, supports hardware encoding of H.264/H.265/VP8/VP9/MJPEG, etc., up to 4K30 encoding.
- Gstreamer: Interfaced with K1 hardware encoder/decoder, supports hardware decoding of H.264/HEVC/VP8/VP9/MPEG-4/MPEG-2/MJPEG, etc., up to 4K30 video playback, supports hardware encoding of H.264/H.265/VP8/VP9/MJPEG, etc., up to 1080P60 encoding.
- Openmax IL: Encoding/decoding adaptation in progress.
- MPP: Provides a unified multimedia API to the upper layer and dynamically loads different platform encoding/decoding library plugins to call the encoding/decoding library.
- Driver & Library: Drivers and API dynamic libraries provided by IP vendors.
2.2 Terminology
- VPU: (Video Processing Unit) Hardware with video encoding/decoding capabilities, improving encoding/decoding efficiency and reducing CPU load. K1's VPU is based on the standard V4L2 framework, supporting decoding of H.264/HEVC/VP8/VP9/MJPEG/MPEG4 and encoding of H.264/HEVC/VP8/VP9/MJPEG.
- V2D: Image processing hardware module provided by K1, supporting image format conversion, scaling, cropping, etc.
- JPU: (Jpeg Processing Unit) Hardware for JPEG image encoding/decoding, improving JPEG encoding/decoding efficiency and reducing CPU load.
- ISP: Image processing module, processing image signals output by sensors, achieving desired image effects through a series of digital image processing algorithms.
- CPP: Image post-processing module, offline processing NV12 data output by ISP, pyramid multi-layer time-sharing processing, including lens distortion correction, spatial and temporal noise reduction, frequency domain noise reduction, edge enhancement, etc.
- RVV: Vector extension based on the RISC-V core instruction set architecture. The purpose of vector extension is to achieve parallel data operations at the instruction level to accelerate computation, similar to ARM's neon.
- MPP: (Multimedia Processing Platform) Multimedia processing platform.
- Gstreamer: An open-source multimedia framework for building streaming media applications and processing audio/video data. It provides a set of libraries and tools for creating, processing, and playing various multimedia streams, including audio, video, and streaming media. Gstreamer supports multiple codecs and formats and can run on different platforms, making it a flexible and powerful multimedia processing framework.
- FFmpeg: Open-source cross-platform audio/video processing tool, used for recording, converting, and streaming audio/video content, as well as audio/video editing and processing. It supports multiple audio/video formats and codecs and can run on different operating systems, including Windows, Mac, and Linux. FFmpeg is a powerful and flexible tool widely used in multimedia processing.
- V4L2: Abbreviation for Video for Linux 2, a driver interface for video capture and output devices on Linux systems. It provides a unified way to access video devices, including cameras, video capture cards, and other video input/output devices. The V4L2 interface allows user programs to control and use video devices through a unified API, enabling video capture, processing, and display. This makes developing video applications on Linux systems simpler and more flexible.
- ALSA: Abbreviation for Advanced Linux Sound Architecture, a software architecture for handling audio and audio devices on Linux systems. It provides a unified audio interface, allowing applications to communicate with audio hardware, supporting multiple audio devices and formats, and providing low-latency and high-quality audio processing. ALSA also provides a set of tools and libraries for configuring and managing audio devices, as well as writing audio applications. ALSA has become the mainstream audio architecture on Linux systems and is widely used in various Linux distributions.
3 MPP
3.1 Module Introduction
3.1.1 Background
MPP (Multimedia Processing Platform) is part of the self-developed operating system Bianbu, aiming to encapsulate the usage differences of hardware encoding/decoding across multiple platforms and provide a unified API for developers.
3.1.2 Terminology
- MPP (Multimedia Processing Platform): Multimedia processing platform.
- MPI (Multimedia Processing Interface): API provided by the multimedia processing platform for upper-layer calls.
- MPP AL: Abstraction layer, abstracting multimedia interfaces for different IPs, SOCs, and solutions.
- Packet: Data packet, mainly representing compressed data, i.e., data before decoding or after encoding, such as H.264/H.265 video streams.
- Frame: Data frame, mainly representing uncompressed data, i.e., data after decoding or before encoding, such as YUV420 images.
3.1.3 Module Functions
Currently, MPP mainly includes the following parts:
- VDEC: Video decoding submodule and open API, mainly used for decoding various data stream packets.
- VENC: Video encoding submodule and open API, mainly used for encoding RGB/YUV data frames.
- G2D: 2D graphics processing acceleration submodule and open API, mainly performing format conversion, scaling, rotation, cropping, etc., on data frames.
- BIND System: Supports dynamic binding of multiple modules.
- AL (Abstract Layer): Supports multiple platforms.
- VI: Video input submodule and open API, currently only supports file input and standard V4L2 input.
- VO: Video output submodule and open API, currently only supports file output and SDL2 video output.
Excluded parts:
- AI/AO: Audio input/output, handled by standard pipewire->alsa-lib->alsa driver.
- AENC/ADEC: Pure software implementation, fully supported by open-source frameworks like GStreamer/FFmpeg, currently not supported.
3.1.4 Configuration Instructions
3.1.4.1 Debug Configuration
- MPP_PRINT_BUFFER: Environment variable, default 0, set to 1 to print buffer status in real-time.
- MPP_SAVE_OUTPUT_BUFFER: Environment variable, default 0, set to 1 to save decoded YUV buffer. YUV buffer is large, may cause playback lag and occupy significant storage space, please note.
- MPP_SAVE_OUTPUT_BUFFER_PATH: Environment variable, used to configure the output YUV file path, default /home/bianbu/output.yuv, effective only when MPP_SAVE_OUTPUT_BUFFER is enabled.
- MPP_FRINT_UNFREE_PACKET: Environment variable, default 0, set to 1 to print packet allocation and release status in real-time.
- MPP_FRINT_UNFREE_FRAME: Environment variable, default 0, set to 1 to print frame allocation and release status in real-time.
- MPP_FRINT_UNFREE_DMABUF: Environment variable, default 0, set to 1 to print dmabuf allocation and release status in real-time.
Usage example:
# Need to print buffer status in real-time
export MPP_PRINT_BUFFER=1
# Need to save decoded YUV data to /mnt/a.yuv
export MPP_SAVE_OUTPUT_BUFFER=1
export MPP_SAVE_OUTPUT_BUFFER_PATH=/mnt/a.yuv
3.1.4.2 Parameter Configuration
No configuration parameters provided yet.
3.1.5 Source Code
3.1.5.1 Source Code Location
MPP source code is located at:
bianbu-linux/package-src/mpp
3.1.5.2 Source Code Compilation
The bianbu-linux solution has compilation enabled by default. If code modifications are needed, recompile by executing:
make mpp-rebuild
3.1.5.3 Source Code Structure
MPP source code structure and brief description (simplified):
|-- al ; AL (Abstract Layer) code, interfaces with platform-specific modules or drivers
| |-- CMakeLists.txt
| |-- include
| | |-- al_interface_base.h ; AL layer interface base class
| | |-- al_interface_dec.h ; AL layer decoding interface base class, inherits from base
| | |-- al_interface_enc.h ; AL layer encoding interface base class, inherits from base
| | |-- al_interface_g2d.h ; AL layer image conversion interface base class, inherits from base
| | |-- al_interface_vi.h ; AL layer video input interface base class, inherits from base
| | `-- al_interface_vo.h ; AL layer video output interface base class, inherits from base
| |-- vcodec ; Interfaces with multi-platform codec modules or drivers
| | |-- chipmedia ; Interfaces with chipmedia IP codecs
| | | |-- CMakeLists.txt
| | | `-- starfive ; Interfaces with starfive codec API (not yet implemented)
| | | |-- sfdec_plugin.c
| | | `-- sfenc_plugin.c
| | |-- CMakeLists.txt
| | |-- debug ; Virtual decoding plugin, outputs simple solid color images for debugging
| | | |-- CMakeLists.txt
| | | `-- fake_dec_plugin.c
| | |-- ffmpeg ; Interfaces with ffmpeg software codec for debugging
| | | |-- CMakeLists.txt
| | | |-- ffmpegdec.c
| | | |-- ffmpegenc.c
| | | `-- ffmpegswscale.c
| | |-- k1
| | | |-- CMakeLists.txt
| | | `-- jpu ; Interfaces with K1 Jpu codec (not yet implemented)
| | | |-- include
| | | |-- jpudec.c
| | | `-- jpuenc.c
| | |-- openh264 ; Interfaces with openh264 software codec library for debugging
| | | |-- CMakeLists.txt
| | | |-- include
| | | | `-- wels
| | | | |-- codec_api.h
| | | | |-- codec_app_def.h
| | | | |-- codec_def.h
| | | | `-- codec_ver.h
| | | |-- openh264dec.cpp
| | | |-- openh264enc.cpp
| | | `-- README.md
| | |-- openmax ; Interfaces with openmax
| | | |-- CMakeLists.txt
| | | |-- include
| | | | |-- khronos
| | | | | |-- OMX_Audio.h
| | | | | |-- OMX_ComponentExt.h
| | | | | |-- OMX_Component.h
| | | | | |-- OMX_ContentPipe.h
| | | | | |-- OMX_CoreExt.h
| | | | | |-- OMX_Core.h
| | | | | |-- OMX_ImageExt.h
| | | | | |-- OMX_Image.h
| | | | | |-- OMX_IndexExt.h
| | | | | |-- OMX_Index.h
| | | | | |-- OMX_IVCommon.h
| | | | | |-- OMX_Other.h
| | | | | |-- OMX_Types.h
| | | | | |-- OMX_VideoExt.h
| | | | | `-- OMX_Video.h
| | | | |-- sfomxil_find_dec_library.h
| | | | `-- sfomxil_find_enc_library.h
| | | `-- starfive ; Interfaces with starfive openmaxIL layer video codec
| | | |-- sfomxil_dec_plugin.c
| | | `-- sfomxil_enc_plugin.c
| | |-- v4l2 ; Interfaces with V4L2 codec
| | | |-- CMakeLists.txt
| | | |-- linlonv5v7 ; Interfaces with linlonv5v7 codec (K1)
| | | | |-- include
| | | | | |-- linlonv5v7_buffer.h
| | | | | |-- linlonv5v7_codec.h
| | | | | |-- linlonv5v7_constant.h
| | | | | |-- linlonv5v7_port.h
| | | | | `-- mvx-v4l2-controls.h
| | | | |-- linlonv5v7_buffer.c
| | | | |-- linlonv5v7_codec.c
| | | | |-- linlonv5v7_dec.c
| | | | |-- linlonv5v7_enc.c
| | | | `-- linlonv5v7_port.c
| | `-- verisilicon ; Interfaces with verisilicon codec (not implemented)
| | |-- CMakeLists.txt
| | `-- vc8000.c
| |-- vi ; Interfaces with multi-platform video input modules or drivers
| | |-- CMakeLists.txt
| | |-- file ; Video input through File
| | | |-- include
| | | | |-- defaultparse.h
| | | | |-- h264parse.h
| | | | |-- h265parse.h
| | | | |-- mjpegparse.h
| | | | `-- parse.h
| | | |-- parse
| | | | |-- defaultparse.c
| | | | |-- h264parse.c
| | | | |-- h265parse.c
| | | | |-- mjpegparse.c
| | | | `-- parse.c
| | | `-- vi_file.c
| | |-- k1 ; Video input through K1 ISP, not yet implemented
| | | `-- cam
| | | |-- include
| | | `-- vi_k1_cam.c
| | `-- v4l2 ; Video input through standard V4L2
| | |-- include
| | `-- vi_v4l2.c
| |-- vo ; Interfaces with multi-platform video output modules or drivers
| | |-- CMakeLists.txt
| | |-- file ; Video output to File
| | | `-- vo_file.c
| | `-- sdl2 ; Video output through SDL2
| | |-- include
| | | |-- begin_code.h
| | | |-- close_code.h
| | | |-- SDL_assert.h
| | | |-- SDL_atomic.h
| | | `-- SDL_vulkan.h
| | `-- vo_sdl2.c
| `-- vps ; Interfaces with multi-platform video processing modules or drivers
| |-- CMakeLists.txt
| `-- k1
| |-- CMakeLists.txt
| `-- v2d ; Interfaces with K1 v2d module, implements basic framework
| |-- include
| | |-- asr_v2d_api.h
| | `-- asr_v2d_type.h
| `-- v2d.c
|-- cmake ; Finds system modules
| `-- modules
| |-- Findlibavcodec.cmake
| |-- Findlibopenh264.cmake
| |-- Findlibsfdec.cmake
| |-- Findlibsfenc.cmake
| `-- Findlibsf-omx-il.cmake
|-- CMakeLists.txt
|-- compile_install_completely.sh
|-- debian ; deb package build directory
| |-- bianbu.conf
| |-- changelog
| |-- compat
| |-- control
| |-- copyright
| |-- install
| |-- README.Debian
| |-- rules
| |-- source
| | `-- format
| |-- usr
| | `-- lib
| | `-- udev
| | `-- rules.d
| | `-- 99-video.rules
| `-- watch
|-- doc ; Documentation
| |-- C_naming_conventions.md
| `-- MPP Module Design Document V0.1.pdf
|-- do_test.sh
|-- format.sh
|-- include ; API header files
| |-- data.h ; MppData base class
| |-- dataqueue.h ; Data queue management API
| |-- dmabufwrapper.h ; dmabuf management API
| |-- frame.h ; Frame management API
| |-- g2d.h ; Image processing API
| |-- packet.h ; Packet management API
| |-- para.h ; Parameter structures
| |-- processflow.h
| |-- ringbuffer.h ; Ring buffer management API
| |-- sys.h ; SYS related API
| |-- vdec.h ; Video decoding API
| `-- venc.h ; Video encoding API
| |-- vi.h ; Video input API
| `-- vo.h ; Video output API
|-- LICENSE
|-- mpi ; API interface implementation
| |-- CMakeLists.txt
| |-- g2d.c
| |-- include
| | `-- module.h
| |-- module.c
| |-- sys.c
| |-- vdec.c
| |-- venc.c
| |-- vi.c
| `-- vo.c
|-- mpp.cppcheck
|-- pack_to_tar_gz.sh
|-- pkgconfig
| `-- spacemit_mpp.pc.cmake
|-- remove_space_end_of_line.sh
|-- test ; Test programs, test scripts, test files, etc.
| |-- CMakeLists.txt
| |-- g2d_test.c
| |-- include
| | |-- argument.h
| | |-- const.h
| | |-- defaultparse.h
| | |-- h264parse.h
| | |-- h265parse.h
| | |-- mjpegparse.h
| | `-- parse.h
| |-- parse
| | |-- defaultparse.c
| | |-- h264parse.c
| | |-- h265parse.c
| | |-- mjpegparse.c
| | `-- parse.c
| |-- test_script
| | |-- cases
| | | `-- vdec.csv
| | |-- streams
| | `-- vdec_test.sh
| |-- test_sys_vdec_venc_one_frame.c
| |-- test_sys_vdec_venc_vdec_one_frame.c
| |-- test_sys_venc_vdec_one_frame.c
| |-- vi_file_vdec_venc_sync_userptr_vo_file_test.c
| |-- vi_file_vdec_vo_test.c
| |-- vi_file_venc_sync_userptr_vo_file_test.c
| `-- vi_v4l2_vo_test.c
|-- thirdparty
| |-- ffmpeg_compile_install.md
| `-- openh264_compile_install.md
`-- utils ; Utilities
|-- CMakeLists.txt
|-- dataqueue.c ; Data queue implementation
|-- dmabufwrapper.c ; dmabuf management implementation
|-- env.c
|-- frame.c ; frame management implementation
|-- include
| |-- env.h
| |-- log.h
| |-- resolution_utils.h
| |-- type.h
| `-- v4l2_utils.h
|-- log.c
|-- os
| |-- include
| | |-- os_env.h
| | `-- os_log.h
| `-- linux
| |-- os_env.c
| `-- os_log.c
|-- packet.c ; packet management implementation
|-- resolution_utils.c
|-- ringbuffer.c
|-- utils.c
`-- v4l2_utils.c
3.2 MPP Framework Structure Diagram
From the framework structure, it is mainly divided into 2 layers, as follows:
- MPI: Interface layer, mainly includes the API and its implementation for the upper layer
- MPP AL: Abstraction layer, shielding the differences between different platforms and hardware
From the functional perspective, it is divided into:
- MPI: Interface layer
- MPP AL: Abstraction layer
- TESTS: Test programs, test cases, and test streams
- UTILS: Utility package, basic function implementation, including PACKET/FRAME management, log output, environment variable reading and writing, etc.
- SYS: Mainly implements dynamic loading of plugins and BIND system