1*4882a593SmuzhiyunMedia Process Platform (MPP) module directory description: 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunMPP : Media Process Platform 4*4882a593SmuzhiyunMPI : Media Process Interface 5*4882a593SmuzhiyunHAL : Hardware Abstract Layer 6*4882a593SmuzhiyunOSAL : Operation System Abstract Layer 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunRules: 9*4882a593Smuzhiyun1. header file arrange rule 10*4882a593Smuzhiyuna. inc directory in each module folder is for external module usage. 11*4882a593Smuzhiyunb. module internal header file should be put along with the implement file. 12*4882a593Smuzhiyunc. header file should not contain any relative path or absolute path, all 13*4882a593Smuzhiyun include path should be keep in Makefile. 14*4882a593Smuzhiyun2. compiling system rule 15*4882a593Smuzhiyuna. for cross platform compiling use cmake as the compiling management system. 16*4882a593Smuzhiyunb. use cmake out-of-source build, final binary and library will be install to 17*4882a593Smuzhiyun out/ directory. 18*4882a593Smuzhiyun3. header file include order 19*4882a593Smuzhiyuna. MODULE_TAG 20*4882a593Smuzhiyunb. system header 21*4882a593Smuzhiyunc. osal header 22*4882a593Smuzhiyund. module header 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunNOTE: 25*4882a593Smuzhiyun1. Windows support is NOT maintained any more. 26*4882a593Smuzhiyun2. Mpp support all rockchip chipset now including: 27*4882a593Smuzhiyun RK29XX/RK30XX/RK31XX 28*4882a593Smuzhiyun RK3288/RK3368/RK3399 29*4882a593Smuzhiyun RK3228/RK3229/RK3228H/RK3328 30*4882a593Smuzhiyun RK3566/RK3568 31*4882a593Smuzhiyun RK3588 32*4882a593Smuzhiyun RV1108/RV1107 33*4882a593Smuzhiyun RV1109/RV1126 34*4882a593Smuzhiyun3. Mpp support all format hardware can support except VC1. 35*4882a593Smuzhiyun4. you can get demo about mpp applied to linux and android. 36*4882a593Smuzhiyun Liunx : https://github.com/WainDing/mpp_linux_cpp 37*4882a593Smuzhiyun https://github.com/MUZLATAN/ffmpeg_rtsp_mpp 38*4882a593Smuzhiyun Android : https://github.com/c-xh/RKMediaCodecDemo 39*4882a593Smuzhiyun5. offical github: https://github.com/rockchip-linux/mpp 40*4882a593Smuzhiyun develop github: https://github.com/HermanChen/mpp 41*4882a593Smuzhiyun develop gitee : https://gitee.com/hermanchen82/mpp 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunMore document can be found at http://opensource.rock-chips.com/wiki_Mpp 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun---- top 46*4882a593Smuzhiyun | 47*4882a593Smuzhiyun |----- build CMake out-of-source build directory 48*4882a593Smuzhiyun | | 49*4882a593Smuzhiyun | |----- cmake cmake script directory 50*4882a593Smuzhiyun | | 51*4882a593Smuzhiyun | |----- android android build directory 52*4882a593Smuzhiyun | | 53*4882a593Smuzhiyun | |----- linux linux build directory 54*4882a593Smuzhiyun | | 55*4882a593Smuzhiyun | |----- vc10-x86_64 visual studio 2010 on x86_64 build directory 56*4882a593Smuzhiyun | | 57*4882a593Smuzhiyun | |----- vc12-x86_64 visual studio 2013 on x86_64 build directory 58*4882a593Smuzhiyun | 59*4882a593Smuzhiyun |----- doc design documents of mpp 60*4882a593Smuzhiyun | 61*4882a593Smuzhiyun |----- inc header file for external usage, including 62*4882a593Smuzhiyun | platform header and mpi header 63*4882a593Smuzhiyun | 64*4882a593Smuzhiyun |----- mpp Media Process Platform : mpi function private 65*4882a593Smuzhiyun | | implement and mpp infrastructure (vpu_api 66*4882a593Smuzhiyun | | private layer) 67*4882a593Smuzhiyun | | 68*4882a593Smuzhiyun | |----- base base components including MppBuffer, MppFrame, 69*4882a593Smuzhiyun | | MppPacket, MppTask, MppMeta, etc. 70*4882a593Smuzhiyun | | 71*4882a593Smuzhiyun | |----- common video codec protocol syntax interface for both 72*4882a593Smuzhiyun | | codec parser and hal 73*4882a593Smuzhiyun | | 74*4882a593Smuzhiyun | |----- codec all video codec parser, convert stream to 75*4882a593Smuzhiyun | | | protocol structure 76*4882a593Smuzhiyun | | | 77*4882a593Smuzhiyun | | |----- inc header files provided by codec module for 78*4882a593Smuzhiyun | | | external usage 79*4882a593Smuzhiyun | | | 80*4882a593Smuzhiyun | | |----- dec 81*4882a593Smuzhiyun | | | | 82*4882a593Smuzhiyun | | | |----- dummy decoder parser work flow sample 83*4882a593Smuzhiyun | | | | 84*4882a593Smuzhiyun | | | |----- h263 85*4882a593Smuzhiyun | | | | 86*4882a593Smuzhiyun | | | |----- h264 87*4882a593Smuzhiyun | | | | 88*4882a593Smuzhiyun | | | |----- h265 89*4882a593Smuzhiyun | | | | 90*4882a593Smuzhiyun | | | |----- m2v mpeg2 parser 91*4882a593Smuzhiyun | | | | 92*4882a593Smuzhiyun | | | |----- mpg4 mpeg4 parser 93*4882a593Smuzhiyun | | | | 94*4882a593Smuzhiyun | | | |----- vp8 95*4882a593Smuzhiyun | | | | 96*4882a593Smuzhiyun | | | |----- vp9 97*4882a593Smuzhiyun | | | | 98*4882a593Smuzhiyun | | | |----- jpeg 99*4882a593Smuzhiyun | | | 100*4882a593Smuzhiyun | | |----- enc 101*4882a593Smuzhiyun | | | 102*4882a593Smuzhiyun | | |----- dummy encoder controllor work flow sample 103*4882a593Smuzhiyun | | | 104*4882a593Smuzhiyun | | |----- h264 105*4882a593Smuzhiyun | | | 106*4882a593Smuzhiyun | | |----- h265 107*4882a593Smuzhiyun | | | 108*4882a593Smuzhiyun | | |----- jpeg 109*4882a593Smuzhiyun | | 110*4882a593Smuzhiyun | |----- hal Hardware Abstract Layer (HAL): modules used in mpi 111*4882a593Smuzhiyun | | | 112*4882a593Smuzhiyun | | |----- inc header files provided by hal for external usage 113*4882a593Smuzhiyun | | | 114*4882a593Smuzhiyun | | |----- iep iep user library 115*4882a593Smuzhiyun | | | 116*4882a593Smuzhiyun | | |----- pp post-processor user library 117*4882a593Smuzhiyun | | | 118*4882a593Smuzhiyun | | |----- rga rga user library 119*4882a593Smuzhiyun | | | 120*4882a593Smuzhiyun | | |----- deinter deinterlace function module including pp/iep/rga 121*4882a593Smuzhiyun | | | 122*4882a593Smuzhiyun | | |----- rkdec rockchip hardware decoder register generation 123*4882a593Smuzhiyun | | | | 124*4882a593Smuzhiyun | | | |----- h264d generate register file from H.264 syntax info 125*4882a593Smuzhiyun | | | | 126*4882a593Smuzhiyun | | | |----- h265d generate register file from H.265 syntax info 127*4882a593Smuzhiyun | | | | 128*4882a593Smuzhiyun | | | |----- vp9d generate register file from vp9 syntax info 129*4882a593Smuzhiyun | | | 130*4882a593Smuzhiyun | | |----- vpu vpu register generation library 131*4882a593Smuzhiyun | | | 132*4882a593Smuzhiyun | | |----- h263d generate register file from H.263 syntax info 133*4882a593Smuzhiyun | | | 134*4882a593Smuzhiyun | | |----- h264d generate register file from H.264 syntax info 135*4882a593Smuzhiyun | | | 136*4882a593Smuzhiyun | | |----- h265d generate register file from H.265 syntax info 137*4882a593Smuzhiyun | | | 138*4882a593Smuzhiyun | | |----- jpegd generate register file from jpeg syntax info 139*4882a593Smuzhiyun | | | 140*4882a593Smuzhiyun | | |----- jpege generate register file from jpeg syntax info 141*4882a593Smuzhiyun | | | 142*4882a593Smuzhiyun | | |----- m2vd generate register file from mpeg2 syntax info 143*4882a593Smuzhiyun | | | 144*4882a593Smuzhiyun | | |----- mpg4d generate register file from mpeg4 syntax info 145*4882a593Smuzhiyun | | | 146*4882a593Smuzhiyun | | |----- vp8d generate register file from vp8 syntax info 147*4882a593Smuzhiyun | | 148*4882a593Smuzhiyun | |----- legacy generate new libvpu to include old vpuapi path 149*4882a593Smuzhiyun | | and new mpp path 150*4882a593Smuzhiyun | | 151*4882a593Smuzhiyun | |----- test mpp internal video protocol unit test and demo 152*4882a593Smuzhiyun | 153*4882a593Smuzhiyun |----- test mpp buffer/packet component unit test and 154*4882a593Smuzhiyun | mpp/mpi/vpu_api demo 155*4882a593Smuzhiyun | 156*4882a593Smuzhiyun |----- out final release binary output directory 157*4882a593Smuzhiyun | | 158*4882a593Smuzhiyun | |----- bin executable binary file output directory 159*4882a593Smuzhiyun | | 160*4882a593Smuzhiyun | |----- inc header file output directory 161*4882a593Smuzhiyun | | 162*4882a593Smuzhiyun | |----- lib library file output directory 163*4882a593Smuzhiyun | 164*4882a593Smuzhiyun |----- osal Operation System Abstract Layer: abstract layer 165*4882a593Smuzhiyun | | for different operation system 166*4882a593Smuzhiyun | | 167*4882a593Smuzhiyun | |----- allocator supported allocator including Android ion and 168*4882a593Smuzhiyun | | Linux drm 169*4882a593Smuzhiyun | | 170*4882a593Smuzhiyun | |----- android google's android 171*4882a593Smuzhiyun | | 172*4882a593Smuzhiyun | |----- inc osal header file for mpp modules 173*4882a593Smuzhiyun | | 174*4882a593Smuzhiyun | |----- linux mainline linux kernel 175*4882a593Smuzhiyun | | 176*4882a593Smuzhiyun | |----- windows microsoft's windows 177*4882a593Smuzhiyun | | 178*4882a593Smuzhiyun | |----- test OASL unit test 179*4882a593Smuzhiyun | 180*4882a593Smuzhiyun |----- tools coding style format tools 181*4882a593Smuzhiyun | 182*4882a593Smuzhiyun |----- utils small util functions 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunHere is the mpp implement overall framework: 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun +---------------------------------------+ 188*4882a593Smuzhiyun | | 189*4882a593Smuzhiyun | ffmpeg / OpenMax / gstreamer / libva | 190*4882a593Smuzhiyun | | 191*4882a593Smuzhiyun +---------------------------------------+ 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun +-------------------- MPP ----------------------+ 194*4882a593Smuzhiyun | | 195*4882a593Smuzhiyun | +-------------------------+ +--------+ | 196*4882a593Smuzhiyun | | | | | | 197*4882a593Smuzhiyun | | MPI / MPP | | | | 198*4882a593Smuzhiyun | | buffer queue manage | | | | 199*4882a593Smuzhiyun | | | | | | 200*4882a593Smuzhiyun | +-------------------------+ | | | 201*4882a593Smuzhiyun | | | | 202*4882a593Smuzhiyun | +-------------------------+ | | | 203*4882a593Smuzhiyun | | | | | | 204*4882a593Smuzhiyun | | codec | | OSAL | | 205*4882a593Smuzhiyun | | decoder / encoder | | | | 206*4882a593Smuzhiyun | | | | | | 207*4882a593Smuzhiyun | +-------------------------+ | | | 208*4882a593Smuzhiyun | | | | 209*4882a593Smuzhiyun | +-----------+ +-----------+ | | | 210*4882a593Smuzhiyun | | | | | | | | 211*4882a593Smuzhiyun | | parser | | HAL | | | | 212*4882a593Smuzhiyun | | recoder | | reg_gen | | | | 213*4882a593Smuzhiyun | | | | | | | | 214*4882a593Smuzhiyun | +-----------+ +-----------+ +--------| | 215*4882a593Smuzhiyun | | 216*4882a593Smuzhiyun +-------------------- MPP ----------------------+ 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun +---------------------------------------+ 219*4882a593Smuzhiyun | | 220*4882a593Smuzhiyun | kernel | 221*4882a593Smuzhiyun | RK vcodec_service / v4l2 | 222*4882a593Smuzhiyun | | 223*4882a593Smuzhiyun +---------------------------------------+ 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun 227*4882a593SmuzhiyunHere is the Media Process Interface hierarchical structure 228*4882a593SmuzhiyunMpiPacket and MpiFrame is the stream I/O data structure. 229*4882a593SmuzhiyunAnd MpiBuffer encapsulates different buffer implement like Linux's dma-buf and 230*4882a593SmuzhiyunAndroid's ion. 231*4882a593SmuzhiyunThis part is learned from ffmpeg. 232*4882a593Smuzhiyun 233*4882a593Smuzhiyun +-------------------+ 234*4882a593Smuzhiyun | | 235*4882a593Smuzhiyun | MPI | 236*4882a593Smuzhiyun | | 237*4882a593Smuzhiyun +---------+---------+ 238*4882a593Smuzhiyun | 239*4882a593Smuzhiyun | 240*4882a593Smuzhiyun v 241*4882a593Smuzhiyun +---------+---------+ 242*4882a593Smuzhiyun | | 243*4882a593Smuzhiyun +---+ ctx +---+ 244*4882a593Smuzhiyun | | | | 245*4882a593Smuzhiyun | +-------------------+ | 246*4882a593Smuzhiyun | | 247*4882a593Smuzhiyun v v 248*4882a593Smuzhiyun +-------+-------+ +-------+-------+ 249*4882a593Smuzhiyun | | | | 250*4882a593Smuzhiyun | packet | | frame | 251*4882a593Smuzhiyun | | | | 252*4882a593Smuzhiyun +---------------+ +-------+-------+ 253*4882a593Smuzhiyun | | 254*4882a593Smuzhiyun | | 255*4882a593Smuzhiyun | | 256*4882a593Smuzhiyun | +---------------+ | 257*4882a593Smuzhiyun | | | | 258*4882a593Smuzhiyun +---->+ buffer +<----+ 259*4882a593Smuzhiyun | | 260*4882a593Smuzhiyun +---------------+ 261*4882a593Smuzhiyun 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun 264*4882a593SmuzhiyunTake H.264 deocder for example. Video stream will first queued by MPI/MPP layer, 265*4882a593SmuzhiyunMPP will send the stream to codec layer, codec layer parses the stream header 266*4882a593Smuzhiyunand generates a protocol standard output. This output will be send to HAL to 267*4882a593Smuzhiyungenerate register file set and communicate with hardware. Hardware will complete 268*4882a593Smuzhiyunthe task and resend information back. MPP notify codec by hardware result, codec 269*4882a593Smuzhiyunoutput decoded frame by display order. 270*4882a593Smuzhiyun 271*4882a593SmuzhiyunMPI MPP decoder parser HAL 272*4882a593Smuzhiyun 273*4882a593Smuzhiyun + + + + + 274*4882a593Smuzhiyun | | | | | 275*4882a593Smuzhiyun | open context | | | | 276*4882a593Smuzhiyun +----------------> | | | | 277*4882a593Smuzhiyun | | | | | 278*4882a593Smuzhiyun | init | | | | 279*4882a593Smuzhiyun +----------------> | | | | 280*4882a593Smuzhiyun | | | | | 281*4882a593Smuzhiyun | | init | | | 282*4882a593Smuzhiyun | +----------------> | | | 283*4882a593Smuzhiyun | | | | | 284*4882a593Smuzhiyun | | | init | | 285*4882a593Smuzhiyun | | +----------------> | | 286*4882a593Smuzhiyun | | | | | 287*4882a593Smuzhiyun | | | | open | 288*4882a593Smuzhiyun | | +-----------------------------------> | 289*4882a593Smuzhiyun | | | | | 290*4882a593Smuzhiyun | decode | | | | 291*4882a593Smuzhiyun +----------------> | | | | 292*4882a593Smuzhiyun | | | | | 293*4882a593Smuzhiyun | | send_stream | | | 294*4882a593Smuzhiyun | +----------------> | | | 295*4882a593Smuzhiyun | | | | | 296*4882a593Smuzhiyun | | | parse_stream | | 297*4882a593Smuzhiyun | | +----------------> | | 298*4882a593Smuzhiyun | | | | | 299*4882a593Smuzhiyun | | | | reg generation | 300*4882a593Smuzhiyun | | +-----------------------------------> | 301*4882a593Smuzhiyun | | | | | 302*4882a593Smuzhiyun | | | | send_regs | 303*4882a593Smuzhiyun | | +-----------------------------------> | 304*4882a593Smuzhiyun | | | | | 305*4882a593Smuzhiyun | | | | wait_regs | 306*4882a593Smuzhiyun | | +-----------------------------------> | 307*4882a593Smuzhiyun | | | | | 308*4882a593Smuzhiyun | | | notify_hw_end | | 309*4882a593Smuzhiyun | | +----------------> | | 310*4882a593Smuzhiyun | | | | | 311*4882a593Smuzhiyun | | get_picture | | | 312*4882a593Smuzhiyun | +----------------> | | | 313*4882a593Smuzhiyun | | | | | 314*4882a593Smuzhiyun | | | get_picture | | 315*4882a593Smuzhiyun | | +----------------> | | 316*4882a593Smuzhiyun | | | | | 317*4882a593Smuzhiyun | flush | | | | 318*4882a593Smuzhiyun +----------------> | | | | 319*4882a593Smuzhiyun | | | | | 320*4882a593Smuzhiyun | | flush | | | 321*4882a593Smuzhiyun | +----------------> | | | 322*4882a593Smuzhiyun | | | | | 323*4882a593Smuzhiyun | | | reset | | 324*4882a593Smuzhiyun | | +----------------> | | 325*4882a593Smuzhiyun | | | | | 326*4882a593Smuzhiyun | close | | | | 327*4882a593Smuzhiyun +----------------> | | | | 328*4882a593Smuzhiyun | | | | | 329*4882a593Smuzhiyun | | close | | | 330*4882a593Smuzhiyun | +----------------> | | | 331*4882a593Smuzhiyun | | | | | 332*4882a593Smuzhiyun | | | close | | 333*4882a593Smuzhiyun | | +----------------> | | 334*4882a593Smuzhiyun | | | | | 335*4882a593Smuzhiyun | | | | close | 336*4882a593Smuzhiyun | | +-----------------------------------> | 337*4882a593Smuzhiyun + + + + + 338*4882a593Smuzhiyun 339*4882a593SmuzhiyunThere are three memory usage modes that decoder can support: 340*4882a593Smuzhiyun 341*4882a593SmuzhiyunMode 1: Pure internal mode 342*4882a593SmuzhiyunIn the mode user will NOT call MPP_DEC_SET_EXT_BUF_GROUP control to decoder. 343*4882a593SmuzhiyunOnly call MPP_DEC_SET_INFO_CHANGE_READY to let decoder go on. Then decoder will 344*4882a593Smuzhiyunuse create buffer internally and user need to release each frame they get. 345*4882a593Smuzhiyun 346*4882a593SmuzhiyunAdvantage: 347*4882a593SmuzhiyunEasy to use and get a demo quickly 348*4882a593SmuzhiyunDisadvantage: 349*4882a593Smuzhiyun1. The buffer from decoder may not be return before decoder is close. 350*4882a593Smuzhiyun So memory leak or crash may happen. 351*4882a593Smuzhiyun2. The decoder memory usage can not be control. Decoder is on a free-to-run 352*4882a593Smuzhiyun status and consume all memory it can get. 353*4882a593Smuzhiyun3. Difficult to implement zero-copy display path. 354*4882a593Smuzhiyun 355*4882a593SmuzhiyunMode 2: Half internal mode 356*4882a593SmuzhiyunThis is the mode current mpi_dec_test code using. User need to create 357*4882a593SmuzhiyunMppBufferGroup according to the returned info change MppFrame. 358*4882a593SmuzhiyunUser can use mpp_buffer_group_limit_config to limit decoder memory usage. 359*4882a593Smuzhiyun 360*4882a593SmuzhiyunAdvantage: 361*4882a593Smuzhiyun1. Easy to use 362*4882a593Smuzhiyun2. User can release MppBufferGroup after decoder is closed. 363*4882a593Smuzhiyun So memory can stay longer safely. 364*4882a593Smuzhiyun3. Can limit the memory usage by mpp_buffer_group_limit_config 365*4882a593SmuzhiyunDisadvantage: 366*4882a593Smuzhiyun1. The buffer limitation is still not accurate. Memory usage is 100% fixed. 367*4882a593Smuzhiyun2. Also difficult to implement zero-copy display path. 368*4882a593Smuzhiyun 369*4882a593SmuzhiyunMode 3: Pure external mode 370*4882a593SmuzhiyunIn this mode use need to create empty MppBufferGroup and import memory from 371*4882a593Smuzhiyunexternal allocator by file handle. 372*4882a593SmuzhiyunOn Android surfaceflinger will create buffer. Then mediaserver get file handle 373*4882a593Smuzhiyunfrom surfaceflinger and commit to decoder's MppBufferGroup. 374*4882a593Smuzhiyun 375*4882a593SmuzhiyunAdvantage: 376*4882a593Smuzhiyun1. Most efficient way for zero-copy display 377*4882a593SmuzhiyunDisadvantage: 378*4882a593Smuzhiyun1. Difficult to learn and use. 379*4882a593Smuzhiyun2. Player work flow may limit this usage. 380*4882a593Smuzhiyun3. May need external parser to get the correct buffer size for the external 381*4882a593Smuzhiyun allocator. 382*4882a593Smuzhiyun 383*4882a593SmuzhiyunThe required buffer size caculation: 384*4882a593Smuzhiyunhor_stride * ver_stride * 3 / 2 for pixel data 385*4882a593Smuzhiyunhor_stride * ver_stride / 2 for extra info 386*4882a593SmuzhiyunTotal hor_stride * ver_stride * 2 will be enough. 387*4882a593Smuzhiyun 388*4882a593SmuzhiyunFor H.264/H.265 20+ buffers will be enough. 389*4882a593SmuzhiyunFor other codec 10 buffers will be enough. 390