xref: /OK3568_Linux_fs/external/mpp/doc/design/3.mpp_buffer.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1Mpp buffer design (2016.10.12)
2================================================================================
3
4Mpp buffer is the warpper of the buffer used by hardware. Hardware usually can
5not use the buffer malloc by cpu. Then we design MppBuffer for different memory
6allocator on different platform. Currently it is designed for ion buffer on
7Android and drm buffer on Linux. Later may support vb2_buffer in v4l2 devices.
8
9In order to manage buffer usage in different user mpp buffer module introduces
10MppBufferGroup as bufffer manager. All MppBuffer will connect to its manager.
11MppBufferGroup provides allocator service and buffer reuse ability.
12
13Different MppBufferGroup has different allocator. And besides normal malloc/free
14function the allocator can also accept buffer from external file descriptor.
15
16MppBufferGroup has two lists, unused buffer list and used buffer list. When
17buffer is free buffer will not be released immediately. Buffer will be moved to
18unused list for later reuse. There is a good reason for doing so. When video
19resolution comes to 4K the buffer size will be above 12M. It will take a long
20time to allocate buffer and generate map table for it. So reusing the buffer
21will save the allocate/free time.
22
23Here is the diagram of Mpp buffer status transaction.
24
25            +----------+     +---------+
26            |  create  |     |  commit |
27            +-----+----+     +----+----+
28                  |               |
29                  |               |
30                  |          +----v----+
31                  +----------+ unused  <-----------+
32                  |          +---------+           |
33                  |          |         |           |
34                  |          |         |           |
35            +-----v----+     |         |     +-----+----+
36            |  malloc  |     |         |     |   free   |
37            +----------+     |         |     +----------+
38            | inc_ref  |     +---------+     |  dec_ref |
39            +-----+----+                     +-----^----+
40                  |                                |
41                  |                                |
42                  |          +---------+           |
43                  +---------->  used   +-----------+
44                             +---------+
45                             |         |
46                             |         |
47                             |         |
48                             |         |
49                             |         |
50                             +----^----+
51                                  |
52                                  |
53                             +----+----+
54                             | import  |
55                             +---------+
56
57
58