/work/svt-av1/Source/Lib/Codec/pred_structure.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright(c) 2019 Intel Corporation |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license. |
10 | | */ |
11 | | |
12 | | #include <stdlib.h> |
13 | | |
14 | | #include "pred_structure.h" |
15 | | #include "utility.h" |
16 | | #include "common_dsp_rtcd.h" |
17 | | #include "sequence_control_set.h" |
18 | | /********************************************************** |
19 | | * Macros |
20 | | **********************************************************/ |
21 | 9.00k | #define PRED_STRUCT_INDEX(hierarchicalLevelCount, predType) ((hierarchicalLevelCount) * PRED_TOTAL_COUNT + (predType)) |
22 | | |
23 | | // clang-format off |
24 | | /********************************************************** |
25 | | * Instructions for how to create a Predicion Structure |
26 | | * |
27 | | * Overview: |
28 | | * The prediction structure consists of a collection |
29 | | * of Prediction Structure Entires, which themselves |
30 | | * consist of reference and dependent lists. The |
31 | | * reference lists are exactly like those found in |
32 | | * the standard and can be clipped in order to reduce |
33 | | * the number of references. |
34 | | * |
35 | | * Dependent lists are the corollary to reference lists, |
36 | | * the describe how a particular picture is referenced. |
37 | | * Dependent lists can also be clipped at predefined |
38 | | * junctions (i.e. the list_count array) in order |
39 | | * to reduce the number of references. Note that the |
40 | | * dependent deltaPOCs must be grouped together in order |
41 | | * of ascending referencePicture in order for the Dependent |
42 | | * List clip to work properly. |
43 | | * |
44 | | * All control and RPS information is derived from |
45 | | * these lists. The lists for a structure are defined |
46 | | * for both P & b-picture variants. In the case of |
47 | | * P-pictures, only Lists 0 are used. |
48 | | * |
49 | | * Negative deltaPOCs are for backward-referencing pictures |
50 | | * in display order and positive deltaPOCs are for |
51 | | * forward-referencing pictures. |
52 | | * |
53 | | * Please note that there is no assigned coding order, |
54 | | * the PictureManager will start pictures as soon as |
55 | | * their references become available. |
56 | | * |
57 | | * Any prediction structure is possible; however, we are |
58 | | * restricting usage to the following controls: |
59 | | * # Hierarchical Levels |
60 | | * # Number of References |
61 | | * # b-pictures enabled |
62 | | * # Intra Refresh Period |
63 | | * |
64 | | * To Get Low Delay P, only use List 0 |
65 | | * To Get Low Delay b, replace List 1 with List 0 |
66 | | * To Get Random Access, use the preduction structure as is |
67 | | **********************************************************/ |
68 | | /************************************************ |
69 | | * Flat |
70 | | * |
71 | | * I-b-b-b-b-b-b-b-b |
72 | | * |
73 | | * Display & Coding Order: |
74 | | * 0 1 2 3 4 5 6 7 8 |
75 | | * |
76 | | ************************************************/ |
77 | | static PredictionStructureEntry flat_pred_struct[] = {{ |
78 | | 0, // GOP Index 0 - Temporal Layer |
79 | | 0 // GOP Index 0 - Decode Order |
80 | | }}; |
81 | | |
82 | | /************************************************ |
83 | | * Random Access - Two-Level Hierarchical |
84 | | * |
85 | | * b b b b Temporal Layer 1 |
86 | | * / \ / \ / \ / \ |
87 | | * I---b---b---b---b Temporal Layer 0 |
88 | | * |
89 | | * Display Order: |
90 | | * 0 1 2 3 4 5 6 7 8 |
91 | | * |
92 | | * Coding Order: |
93 | | * 0 2 1 4 3 6 5 8 7 |
94 | | ************************************************/ |
95 | | static PredictionStructureEntry two_level_hierarchical_pred_struct[] = { |
96 | | { |
97 | | 0, // GOP Index 0 - Temporal Layer |
98 | | 0 // GOP Index 0 - Decode Order |
99 | | }, |
100 | | { |
101 | | 1, // GOP Index 1 - Temporal Layer |
102 | | 1 // GOP Index 1 - Decode Order |
103 | | } |
104 | | }; |
105 | | |
106 | | /************************************************ |
107 | | * Three-Level Hierarchical |
108 | | * |
109 | | * b b b b b b Temporal Layer 2 |
110 | | * / \ / \ / \ / \ / \ / \ |
111 | | * / b \ / b \ / b \ Temporal Layer 1 |
112 | | * / / \ \ / / \ \ / / \ \ |
113 | | * I-----------b-----------b-----------b Temporal Layer 0 |
114 | | * |
115 | | * Display Order: |
116 | | * 0 1 2 3 4 5 6 7 8 9 1 1 1 |
117 | | * 0 1 2 |
118 | | * |
119 | | * Coding Order: |
120 | | * 0 3 2 4 1 7 6 8 5 1 1 1 9 |
121 | | * 1 0 2 |
122 | | ************************************************/ |
123 | | static PredictionStructureEntry three_level_hierarchical_pred_struct[] = { |
124 | | { |
125 | | 0, // GOP Index 0 - Temporal Layer |
126 | | 0 // GOP Index 0 - Decode Order |
127 | | }, |
128 | | { |
129 | | 2, // GOP Index 1 - Temporal Layer |
130 | | 2 // GOP Index 1 - Decode Order |
131 | | }, |
132 | | { |
133 | | 1, // GOP Index 2 - Temporal Layer |
134 | | 1 // GOP Index 2 - Decode Order |
135 | | }, |
136 | | { |
137 | | 2, // GOP Index 3 - Temporal Layer |
138 | | 3 // GOP Index 3 - Decode Order |
139 | | } |
140 | | }; |
141 | | |
142 | | /************************************************************************************************************ |
143 | | * Four-Level Hierarchical |
144 | | * |
145 | | * |
146 | | * b b b b b b b b Temporal Layer 3 |
147 | | * / \ / \ / \ / \ / \ / \ / \ / \ |
148 | | * / \ / \ / \ / \ / \ / \ / \ / \ |
149 | | * / b \ / b \ / b \ / b \ Temporal Layer 2 |
150 | | * / / \ \ / / \ \ / / \ \ / / \ \ |
151 | | * / / \ \ / / \ \ / / \ \ / / \ \ |
152 | | * / / ------b------ \ \ / / ------b------ \ \ Temporal Layer 1 |
153 | | * / / / \ \ \ / / / \ \ \ |
154 | | * I---------------------------------------b---------------------------------------b Temporal Layer 0 |
155 | | * |
156 | | * Display Order: |
157 | | * 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 |
158 | | * 0 1 2 3 4 5 6 |
159 | | * |
160 | | * Coding Order: |
161 | | * 0 4 3 5 2 7 6 8 1 1 1 1 1 1 1 1 9 |
162 | | * 2 1 3 0 5 4 6 |
163 | | * |
164 | | ***********************************************************************************************************/ |
165 | | static PredictionStructureEntry four_level_hierarchical_pred_struct[] = { |
166 | | { |
167 | | 0, // GOP Index 0 - Temporal Layer |
168 | | 0 // GOP Index 0 - Decode Order |
169 | | }, |
170 | | { |
171 | | 3, // GOP Index 1 - Temporal Layer |
172 | | 3 // GOP Index 1 - Decode Order |
173 | | }, |
174 | | { |
175 | | 2, // GOP Index 2 - Temporal Layer |
176 | | 2 // GOP Index 2 - Decode Order |
177 | | }, |
178 | | { |
179 | | 3, // GOP Index 3 - Temporal Layer |
180 | | 4 // GOP Index 3 - Decode Order |
181 | | }, |
182 | | { |
183 | | 1, // GOP Index 4 - Temporal Layer |
184 | | 1 // GOP Index 4 - Decode Order |
185 | | }, |
186 | | { |
187 | | 3, // GOP Index 5 - Temporal Layer |
188 | | 6 // GOP Index 5 - Decode Order |
189 | | }, |
190 | | { |
191 | | 2, // GOP Index 6 - Temporal Layer |
192 | | 5 // GOP Index 6 - Decode Order |
193 | | }, |
194 | | { |
195 | | 3, // GOP Index 7 - Temporal Layer |
196 | | 7 // GOP Index 7 - Decode Order |
197 | | } |
198 | | }; |
199 | | |
200 | | /*********************************************************************************************************** |
201 | | * Five-Level Level Hierarchical |
202 | | * |
203 | | * b b b b b b b b Temporal Layer 4 |
204 | | * / \ / \ / \ / \ / \ / \ / \ / \ |
205 | | * / \ / \ / \ / \ / \ / \ / \ / \ |
206 | | * / b \ / b \ / b \ / b \ Temporal Layer 3 |
207 | | * / / \ \ / / \ \ / / \ \ / / \ \ |
208 | | * / / \ \ / / \ \ / / \ \ / / \ \ |
209 | | * / / ------b------ \ \ / / ------b------ \ \ Temporal Layer 2 |
210 | | * / / / \ \ \ / / / \ \ \ |
211 | | * / / / \-----------------b------------------ \ \ \ Temporal Layer 1 |
212 | | * / / / / \ \ \ \ |
213 | | * I-----------------------------------------------------------------------------------b Temporal Layer 0 |
214 | | * |
215 | | * Display Order: |
216 | | * 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 |
217 | | * 0 1 2 3 4 5 6 |
218 | | * |
219 | | * Coding Order: |
220 | | * 0 5 4 6 3 8 7 9 2 1 1 1 1 1 1 1 1 |
221 | | * 2 1 3 0 5 4 6 |
222 | | * |
223 | | ***********************************************************************************************************/ |
224 | | static PredictionStructureEntry five_level_hierarchical_pred_struct[] = { |
225 | | { |
226 | | 0, // GOP Index 0 - Temporal Layer |
227 | | 0 // GOP Index 0 - Decode Order |
228 | | }, |
229 | | { |
230 | | 4, // GOP Index 1 - Temporal Layer |
231 | | 4 // GOP Index 1 - Decode Order |
232 | | }, |
233 | | { |
234 | | 3, // GOP Index 2 - Temporal Layer |
235 | | 3 // GOP Index 2 - Decode Order |
236 | | }, |
237 | | { |
238 | | 4, // GOP Index 3 - Temporal Layer |
239 | | 5 // GOP Index 3 - Decode Order |
240 | | }, |
241 | | { |
242 | | 2, // GOP Index 4 - Temporal Layer |
243 | | 2 // GOP Index 4 - Decode Order |
244 | | }, |
245 | | { |
246 | | 4, // GOP Index 5 - Temporal Layer |
247 | | 7 // GOP Index 5 - Decode Order |
248 | | }, |
249 | | { |
250 | | 3, // GOP Index 6 - Temporal Layer |
251 | | 6 // GOP Index 6 - Decode Order |
252 | | }, |
253 | | { |
254 | | 4, // GOP Index 7 - Temporal Layer |
255 | | 8 // GOP Index 7 - Decode Order |
256 | | }, |
257 | | { |
258 | | 1, // GOP Index 8 - Temporal Layer |
259 | | 1 // GOP Index 8 - Decode Order |
260 | | }, |
261 | | { |
262 | | 4, // GOP Index 9 - Temporal Layer |
263 | | 11 // GOP Index 9 - Decode Order |
264 | | }, |
265 | | { |
266 | | 3, // GOP Index 10 - Temporal Layer |
267 | | 10 // GOP Index 10 - Decode Order |
268 | | }, |
269 | | { |
270 | | 4, // GOP Index 11 - Temporal Layer |
271 | | 12 // GOP Index 11 - Decode Order |
272 | | }, |
273 | | { |
274 | | 2, // GOP Index 12 - Temporal Layer |
275 | | 9 // GOP Index 12 - Decode Order |
276 | | }, |
277 | | { |
278 | | 4, // GOP Index 13 - Temporal Layer |
279 | | 14 // GOP Index 13 - Decode Order |
280 | | }, |
281 | | { |
282 | | 3, // GOP Index 14 - Temporal Layer |
283 | | 13 // GOP Index 14 - Decode Order |
284 | | |
285 | | }, |
286 | | { |
287 | | 4, // GOP Index 15 - Temporal Layer |
288 | | 15 // GOP Index 15 - Decode Order |
289 | | } |
290 | | }; |
291 | | |
292 | | /********************************************************************************************************************************************************************************************************************** |
293 | | * Six-Level Level Hierarchical |
294 | | * |
295 | | * |
296 | | * b b b b b b b b b b b b b b b b Temporal Layer 5 |
297 | | * / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ |
298 | | * / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ |
299 | | * / b \ / b \ / b \ / b \ / b \ / b \ / b \ / b \ Temporal Layer 4 |
300 | | * / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ |
301 | | * / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ |
302 | | * / / ------b------ \ \ / / ------b------ \ \ / / ------b------ \ \ / / ------b------ \ \ Temporal Layer 3 |
303 | | * / / / \ \ \ / / / \ \ \ / / / \ \ \ / / / \ \ \ |
304 | | * / / / \-----------------b------------------ \ \ \ / / / \-----------------b------------------ \ \ \ Temporal Layer 2 |
305 | | * / / / / \ \ \ \ / / / / \ \ \ \ |
306 | | * / / / / \---------------------------------------b---------------------------------------/ \ \ \ \ Temporal Layer 1 |
307 | | * / / / / / \ \ \ \ \ |
308 | | * I---------------------------------------------------------------------------------------------------------------------------------------------------------------------------b Temporal Layer 0 |
309 | | * |
310 | | * Display Order: |
311 | | * 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 |
312 | | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 |
313 | | * |
314 | | * Coding Order: |
315 | | * 0 6 5 7 4 9 8 1 3 1 1 1 1 1 1 1 2 2 2 2 1 2 2 2 1 2 2 2 2 3 3 3 1 |
316 | | * 0 3 2 4 1 6 5 7 1 0 2 9 4 3 5 8 8 7 9 6 1 0 2 |
317 | | * |
318 | | **********************************************************************************************************************************************************************************************************************/ |
319 | | static PredictionStructureEntry six_level_hierarchical_pred_struct[] = { |
320 | | { |
321 | | 0, // GOP Index 0 - Temporal Layer |
322 | | 0 // GOP Index 0 - Decode Order |
323 | | }, |
324 | | { |
325 | | 5, // GOP Index 1 - Temporal Layer |
326 | | 5 // GOP Index 1 - Decode Order |
327 | | }, |
328 | | { |
329 | | 4, // GOP Index 2 - Temporal Layer |
330 | | 4 // GOP Index 2 - Decode Order |
331 | | }, |
332 | | { |
333 | | 5, // GOP Index 3 - Temporal Layer |
334 | | 6 // GOP Index 3 - Decode Order |
335 | | }, |
336 | | { |
337 | | 3, // GOP Index 4 - Temporal Layer |
338 | | 3 // GOP Index 4 - Decode Order |
339 | | }, |
340 | | { |
341 | | 5, // GOP Index 5 - Temporal Layer |
342 | | 8 // GOP Index 5 - Decode Order |
343 | | }, |
344 | | { |
345 | | 4, // GOP Index 6 - Temporal Layer |
346 | | 7 // GOP Index 6 - Decode Order |
347 | | }, |
348 | | { |
349 | | 5, // GOP Index 7 - Temporal Layer |
350 | | 9 // GOP Index 7 - Decode Order |
351 | | }, |
352 | | { |
353 | | 2, // GOP Index 8 - Temporal Layer |
354 | | 2 // GOP Index 8 - Decode Order |
355 | | }, |
356 | | { |
357 | | 5, // GOP Index 9 - Temporal Layer |
358 | | 12 // GOP Index 9 - Decode Order |
359 | | }, |
360 | | { |
361 | | 4, // GOP Index 10 - Temporal Layer |
362 | | 11 // GOP Index 10 - Decode Order |
363 | | }, |
364 | | { |
365 | | 5, // GOP Index 11 - Temporal Layer |
366 | | 13 // GOP Index 11 - Decode Order |
367 | | }, |
368 | | { |
369 | | 3, // GOP Index 12 - Temporal Layer |
370 | | 10 // GOP Index 12 - Decode Order |
371 | | }, |
372 | | { |
373 | | 5, // GOP Index 13 - Temporal Layer |
374 | | 15 // GOP Index 13 - Decode Order |
375 | | }, |
376 | | { |
377 | | 4, // GOP Index 14 - Temporal Layer |
378 | | 14 // GOP Index 14 - Decode Order |
379 | | }, |
380 | | { |
381 | | 5, // GOP Index 15 - Temporal Layer |
382 | | 16 // GOP Index 15 - Decode Order |
383 | | }, |
384 | | { |
385 | | 1, // GOP Index 16 - Temporal Layer |
386 | | 1 // GOP Index 16 - Decode Order |
387 | | }, |
388 | | { |
389 | | 5, // GOP Index 17 - Temporal Layer |
390 | | 20 // GOP Index 17 - Decode Order |
391 | | }, |
392 | | { |
393 | | 4, // GOP Index 18 - Temporal Layer |
394 | | 19 // GOP Index 18 - Decode Order |
395 | | }, |
396 | | { |
397 | | 5, // GOP Index 19 - Temporal Layer |
398 | | 21 // GOP Index 19 - Decode Order |
399 | | }, |
400 | | { |
401 | | 3, // GOP Index 20 - Temporal Layer |
402 | | 18 // GOP Index 20 - Decode Order |
403 | | }, |
404 | | { |
405 | | 5, // GOP Index 21 - Temporal Layer |
406 | | 23 // GOP Index 21 - Decode Order |
407 | | }, |
408 | | { |
409 | | 4, // GOP Index 22 - Temporal Layer |
410 | | 22 // GOP Index 22 - Decode Order |
411 | | }, |
412 | | { |
413 | | 5, // GOP Index 23 - Temporal Layer |
414 | | 24 // GOP Index 23 - Decode Order |
415 | | }, |
416 | | { |
417 | | 2, // GOP Index 24 - Temporal Layer |
418 | | 17 // GOP Index 24 - Decode Order |
419 | | }, |
420 | | { |
421 | | 5, // GOP Index 25 - Temporal Layer |
422 | | 27 // GOP Index 25 - Decode Order |
423 | | }, |
424 | | { |
425 | | 4, // GOP Index 26 - Temporal Layer |
426 | | 26 // GOP Index 26 - Decode Order |
427 | | }, |
428 | | { |
429 | | 5, // GOP Index 27 - Temporal Layer |
430 | | 28 // GOP Index 27 - Decode Order |
431 | | }, |
432 | | { |
433 | | 3, // GOP Index 28 - Temporal Layer |
434 | | 25 // GOP Index 28 - Decode Order |
435 | | }, |
436 | | { |
437 | | 5, // GOP Index 29 - Temporal Layer |
438 | | 30 // GOP Index 29 - Decode Order |
439 | | }, |
440 | | { |
441 | | 4, // GOP Index 30 - Temporal Layer |
442 | | 29 // GOP Index 30 - Decode Order |
443 | | }, |
444 | | { |
445 | | 5, // GOP Index 31 - Temporal Layer |
446 | | 31 // GOP Index 31 - Decode Order |
447 | | } |
448 | | }; |
449 | | // clang-format on |
450 | | |
451 | | /************************************************ |
452 | | * Prediction Structure Config |
453 | | * Contains a collection of basic control data |
454 | | * for the basic prediction structure. |
455 | | ************************************************/ |
456 | | typedef struct PredictionStructureConfig { |
457 | | uint32_t entry_count; |
458 | | PredictionStructureEntry* entry_array; |
459 | | } PredictionStructureConfig; |
460 | | |
461 | | /************************************************ |
462 | | * Prediction Structure Config Array |
463 | | ************************************************/ |
464 | | static const PredictionStructureConfig g_prediction_structure_config_array[] = { |
465 | | {1, flat_pred_struct}, |
466 | | {2, two_level_hierarchical_pred_struct}, |
467 | | {4, three_level_hierarchical_pred_struct}, |
468 | | {8, four_level_hierarchical_pred_struct}, |
469 | | {16, five_level_hierarchical_pred_struct}, |
470 | | {32, six_level_hierarchical_pred_struct}, |
471 | | {0, (PredictionStructureEntry*)NULL} // Terminating Code, must always come last! |
472 | | }; |
473 | | |
474 | | /************************************************ |
475 | | * Get Prediction Structure |
476 | | ************************************************/ |
477 | | PredictionStructure* svt_aom_get_prediction_structure(PredictionStructureGroup* pred_struct_group_ptr, |
478 | 474 | PredStructure pred_struct, uint32_t levels_of_hierarchy) { |
479 | | // Determine the Index value |
480 | 474 | uint32_t pred_struct_index = PRED_STRUCT_INDEX(levels_of_hierarchy, pred_struct); |
481 | | |
482 | 474 | return pred_struct_group_ptr->prediction_structure_ptr_array[pred_struct_index]; |
483 | 474 | } |
484 | | |
485 | 8.53k | static void prediction_structure_dctor(EbPtr p) { |
486 | 8.53k | PredictionStructure* obj = (PredictionStructure*)p; |
487 | 8.53k | if (obj->pred_struct_entry_ptr_array) { |
488 | 8.53k | EB_FREE_2D(obj->pred_struct_entry_ptr_array); |
489 | 8.53k | } |
490 | 8.53k | } |
491 | | |
492 | | /******************************************************************************************** |
493 | | * Prediction Structure Ctor |
494 | | * |
495 | | * GOP Type: |
496 | | * For Low Delay P, eliminate Ref List 0 |
497 | | * Fow Low Delay b, copy Ref List 0 into Ref List 1 |
498 | | * For Random Access, leave config as is |
499 | | * |
500 | | * number_of_references: |
501 | | * Clip the Ref Lists |
502 | | * |
503 | | * Summary: |
504 | | * |
505 | | * The Pred Struct Ctor constructs the Reference Lists, Dependent Lists, and RPS for each |
506 | | * valid prediction structure position. The full prediction structure is composed of four |
507 | | * sections: |
508 | | * a. Leading Pictures |
509 | | * b. Initialization Pictures |
510 | | * c. Steady-state Pictures |
511 | | * d. Trailing Pictures |
512 | | * |
513 | | * by definition, the Prediction Structure Config describes the Steady-state Picture |
514 | | * Set. From the PS Config, the other sections are determined by following a simple |
515 | | * set of construction rules. These rules are: |
516 | | * -Leading Pictures use only List 1 of the Steady-state for forward-prediction |
517 | | * -Init Pictures don't violate CRA mechanics |
518 | | * -Steady-state Pictures come directly from the PS Config |
519 | | * -Following pictures use only List 0 of the Steady-state for rear-prediction |
520 | | * |
521 | | * In general terms, Leading and Trailing pictures are useful when trying to reduce |
522 | | * the number of base-layer pictures in the presense of scene changes. Trailing |
523 | | * pictures are also useful for terminating sequences. Init pictures are needed |
524 | | * when using multiple references that expand outside of a Prediction Structure. |
525 | | * Steady-state pictures are the normal use cases. |
526 | | * |
527 | | * Leading and Trailing Pictures are not applicable to Low Delay prediction structures. |
528 | | * |
529 | | * Below are a set of example PS diagrams |
530 | | * |
531 | | * Low-delay P, Flat, 2 reference: |
532 | | * |
533 | | * I---P---P |
534 | | * |
535 | | * Display Order 0 1 2 |
536 | | * |
537 | | * Sections: |
538 | | * Let PredStructSize = N |
539 | | * Leading Pictures: [null] Size: 0 |
540 | | * Init Pictures: [0-1] Size: Ceil(MaxReference, N) - N + 1 |
541 | | * Stead-state Pictures: [2] Size: N |
542 | | * Trailing Pictures: [null] Size: 0 |
543 | | * ------------------------------------------ |
544 | | * Total Size: Ceil(MaxReference, N) + 1 |
545 | | * |
546 | | * Low-delay b, 3-level, 2 references: |
547 | | * |
548 | | * b b b b |
549 | | * / / / / |
550 | | * / b / b |
551 | | * / / / / |
552 | | * I---------b-----------b |
553 | | * |
554 | | * Display Order 0 1 2 3 4 5 6 7 8 |
555 | | * |
556 | | * Sections: |
557 | | * Let PredStructSize = N |
558 | | * Leading Pictures: [null] Size: 0 |
559 | | * Init Pictures: [1-4] Size: Ceil(MaxReference, N) - N + 1 |
560 | | * Stead-state Pictures: [5-8] Size: N |
561 | | * Trailing Pictures: [null] Size: 0 |
562 | | * ------------------------------------------ |
563 | | * Total Size: Ceil(MaxReference, N) + 1 |
564 | | * |
565 | | * Random Access, 3-level structure with 3 references: |
566 | | * |
567 | | * p p b b b b b b p p |
568 | | * \ \ / \ / \ / \ / \ / \ / \ / / |
569 | | * P \ / b \ / b \ / b \ / P |
570 | | * \ \ / / \ \ / / \ \ / / \ \ / / |
571 | | * ----I-----------b-----------b-----------b---- |
572 | | * Display Order: 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 |
573 | | * 0 1 2 3 4 5 6 7 8 |
574 | | * |
575 | | * Decode Order: 2 1 3 0 6 5 7 4 1 9 1 8 1 1 1 1 1 1 1 |
576 | | * 0 1 4 3 5 2 6 7 8 |
577 | | * |
578 | | * Sections: |
579 | | * Let PredStructSize = N |
580 | | * Leading Pictures: [0-2] Size: N - 1 |
581 | | * Init Pictures: [3-11] Size: Ceil(MaxReference, N) - N + 1 |
582 | | * Steady-state Pictures: [12-15] Size: N |
583 | | * Trailing Pictures: [16-18] Size: N - 1 |
584 | | * ------------------------------------------ |
585 | | * Total Size: 2*N + Ceil(MaxReference, N) - 1 |
586 | | * |
587 | | * Encoding Order: |
588 | | * -------->----------->----------->-----------|-------> |
589 | | * | | |
590 | | * |----<------| |
591 | | * |
592 | | * |
593 | | * Timeline: |
594 | | * |
595 | | * The timeline is a tool that is used to determine for how long a |
596 | | * picture should be preserved for future reference. The concept of |
597 | | * future reference is equivalently defined as dependence. The RPS |
598 | | * mechanism works by signaling for each picture in the DPB whether |
599 | | * it is used for direct reference, kept for future reference, or |
600 | | * discarded. The timeline merely provides a means of determing |
601 | | * the reference picture states at each prediction structure position. |
602 | | * Its also important to note that all signaling should be done relative |
603 | | * to decode order, not display order. Display order is irrelevant except |
604 | | * for signaling the POC. |
605 | | * |
606 | | * Timeline Example: 3-Level Hierarchical with Leading and Trailing Pictures, 3 References |
607 | | * |
608 | | * p p b b b b b b p p Temporal Layer 2 |
609 | | * \ \ / \ / \ / \ / \ / \ / \ / / |
610 | | * P \ / b \ / b \ / b \ / P Temporal Layer 1 |
611 | | * \ \ / / \ \ / / \ \ / / \ \ / / |
612 | | * ----I-----------b-----------b-----------b---- Temporal Layer 0 |
613 | | * |
614 | | * Decode Order: 2 1 3 0 6 5 7 4 1 9 1 8 1 1 1 1 1 1 1 |
615 | | * 0 1 4 3 5 2 6 7 8 |
616 | | * |
617 | | * Display Order: 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 |
618 | | * 0 1 2 3 4 5 6 7 8 |
619 | | * X ---> |
620 | | * |
621 | | * 1 1 1 1 1 1 1 1 1 DECODE ORDER |
622 | | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 |
623 | | * |
624 | | * |---------------------------------------------------------- |
625 | | * | |
626 | | * Y D 0 | \ x---x-x-x-x---x-x-x---x-x-x |
627 | | * | E 1 | \ x |
628 | | * | C 2 | \ |
629 | | * | O 3 | \ |
630 | | * v D 4 | \ x---x-x-x-x---x-x-x---x-x-x |
631 | | * E 5 | \ x-x |
632 | | * 6 | \ |
633 | | * O 7 | \ |
634 | | * R 8 | \ x---x-x-x-x---x-x-x |
635 | | * D 9 | \ x-x |
636 | | * E 10 | \ |
637 | | * R 11 | \ |
638 | | * 12 | \ x---x-x-x-x |
639 | | * 13 | \ x-x |
640 | | * 14 | \ |
641 | | * 15 | \ |
642 | | * 16 | \ |
643 | | * 17 | \ x |
644 | | * 18 | \ |
645 | | * |
646 | | * Interpreting the timeline: |
647 | | * |
648 | | * The most important detail to keep in mind is that all signaling |
649 | | * is done in Decode Order space. The symbols mean the following: |
650 | | * 'x' directly referenced picture |
651 | | * '-' picture kept for future reference |
652 | | * ' ' not referenced, inferred discard |
653 | | * '\' eqivalent to ' ', deliminiter that nothing can be to the left of |
654 | | * |
655 | | * The basic steps for constructing the timeline are to increment through |
656 | | * each position in the prediction structure (Y-direction on the timeline) |
657 | | * and mark the appropriate state: directly referenced, kept for future reference, |
658 | | * or discarded. As shown, base-layer pictures are referenced much more |
659 | | * frequently than by the other layers. |
660 | | * |
661 | | * The RPS is constructed by looking at each 'x' position in the timeline and |
662 | | * signaling each 'y' reference as depicted in the timeline. DPB analysis is |
663 | | * fairly straigtforward - the total number of directly-referenced and |
664 | | * kept-for-future-reference pictures should not exceed the DPB size. |
665 | | * |
666 | | * The RPS Ctor code follows these construction steps. |
667 | | ******************************************************************************************/ |
668 | | static EbErrorType prediction_structure_ctor(PredictionStructure* pred_struct, |
669 | | const PredictionStructureConfig* pred_struct_cfg, |
670 | 8.53k | const PredStructure pred_type) { |
671 | 8.53k | pred_struct->dctor = prediction_structure_dctor; |
672 | | |
673 | 8.53k | pred_struct->pred_type = pred_type; |
674 | | |
675 | | // Set total Entry Count |
676 | 8.53k | pred_struct->pred_struct_entry_count = pred_struct_cfg->entry_count; |
677 | | |
678 | | // Set the Section Indices |
679 | 8.53k | pred_struct->init_pic_index = 0; |
680 | | |
681 | | // Allocate the entry array |
682 | 8.53k | EB_CALLOC_2D(pred_struct->pred_struct_entry_ptr_array, pred_struct->pred_struct_entry_count, 1); |
683 | | |
684 | | //---------------------------------------- |
685 | | // Construct Steady-state Pictures |
686 | | // -Copy directly from the Config |
687 | | //---------------------------------------- |
688 | 98.1k | for (unsigned int entry_idx = 0; entry_idx < pred_struct->pred_struct_entry_count; ++entry_idx) { |
689 | 89.5k | PredictionStructureEntry* cfg_entry = &pred_struct_cfg->entry_array[entry_idx]; |
690 | 89.5k | PredictionStructureEntry* pred_entry = pred_struct->pred_struct_entry_ptr_array[entry_idx]; |
691 | | |
692 | | // Set the Temporal Layer Index |
693 | 89.5k | pred_entry->temporal_layer_index = cfg_entry->temporal_layer_index; |
694 | | |
695 | | // Set the Decode Order |
696 | 89.5k | pred_entry->decode_order = (pred_type == RANDOM_ACCESS) ? cfg_entry->decode_order : entry_idx; |
697 | 89.5k | } |
698 | | |
699 | 8.53k | return EB_ErrorNone; |
700 | 8.53k | } |
701 | | |
702 | 474 | static void prediction_structure_group_dctor(EbPtr p) { |
703 | 474 | PredictionStructureGroup* obj = (PredictionStructureGroup*)p; |
704 | 474 | EB_DELETE_PTR_ARRAY(obj->prediction_structure_ptr_array, obj->prediction_structure_count); |
705 | 474 | } |
706 | | |
707 | | /************************************************* |
708 | | * Prediction Structure Group Ctor |
709 | | * |
710 | | * Summary: Converts the Prediction Structure Config |
711 | | * into the usable Prediction Structure with RPS and |
712 | | * Dependent List control. |
713 | | * |
714 | | * From each config, several prediction structures |
715 | | * are created. These include: |
716 | | * -Variable Number of References |
717 | | * # [1 - 4] |
718 | | * -Temporal Layers |
719 | | * # [1 - 6] |
720 | | * -GOP Type |
721 | | * # Low Delay P |
722 | | * # Low Delay b |
723 | | * # Random Access |
724 | | * |
725 | | *************************************************/ |
726 | 474 | EbErrorType svt_aom_prediction_structure_group_ctor(PredictionStructureGroup* pred_struct_group_ptr) { |
727 | 474 | pred_struct_group_ptr->dctor = prediction_structure_group_dctor; |
728 | | |
729 | 474 | pred_struct_group_ptr->prediction_structure_count = MAX_TEMPORAL_LAYERS * PRED_TOTAL_COUNT; |
730 | 474 | EB_ALLOC_PTR_ARRAY(pred_struct_group_ptr->prediction_structure_ptr_array, |
731 | 474 | pred_struct_group_ptr->prediction_structure_count); |
732 | 3.31k | for (uint32_t hierarchical_levels = 0; hierarchical_levels < MAX_TEMPORAL_LAYERS; hierarchical_levels++) { |
733 | 11.3k | for (PredStructure pred_type = 0; pred_type < PRED_TOTAL_COUNT; ++pred_type) { |
734 | 8.53k | uint32_t pred_struct_index = PRED_STRUCT_INDEX(hierarchical_levels, pred_type); |
735 | | |
736 | 8.53k | EB_NEW(pred_struct_group_ptr->prediction_structure_ptr_array[pred_struct_index], |
737 | 8.53k | prediction_structure_ctor, |
738 | 8.53k | &g_prediction_structure_config_array[hierarchical_levels], |
739 | 8.53k | pred_type); |
740 | 8.53k | } |
741 | 2.84k | } |
742 | 474 | return EB_ErrorNone; |
743 | 474 | } |