FFmpeg
Loading...
Searching...
No Matches
cavsdec.c
Go to the documentation of this file.
1/*
2 * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
3 * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder
25 * @author Stefan Gehrer <stefan.gehrer@gmx.de>
26 *
27 * Clause, table and figure numbers refer to GY/T 257.1-2012.
28 */
29
31#include "libavutil/avassert.h"
32#include "libavutil/intmath.h"
33#include "libavutil/mem.h"
34#include "avcodec.h"
35#include "get_bits.h"
36#include "golomb.h"
37#include "cavs.h"
38#include "codec_internal.h"
39#include "profiles.h"
40#include "decode.h"
41#include "mathops.h"
42#include "mpeg12data.h"
43#include "put_bits.h"
44#include "startcode.h"
45
46static const uint8_t mv_scan[4] = {
49};
50
51static const uint8_t cbp_tab[64][2] = {
52 { 63, 0 }, { 15, 15 }, { 31, 63 }, { 47, 31 }, { 0, 16 }, { 14, 32 }, { 13, 47 }, { 11, 13 },
53 { 7, 14 }, { 5, 11 }, { 10, 12 }, { 8, 5 }, { 12, 10 }, { 61, 7 }, { 4, 48 }, { 55, 3 },
54 { 1, 2 }, { 2, 8 }, { 59, 4 }, { 3, 1 }, { 62, 61 }, { 9, 55 }, { 6, 59 }, { 29, 62 },
55 { 45, 29 }, { 51, 27 }, { 23, 23 }, { 39, 19 }, { 27, 30 }, { 46, 28 }, { 53, 9 }, { 30, 6 },
56 { 43, 60 }, { 37, 21 }, { 60, 44 }, { 16, 26 }, { 21, 51 }, { 28, 35 }, { 19, 18 }, { 35, 20 },
57 { 42, 24 }, { 26, 53 }, { 44, 17 }, { 32, 37 }, { 58, 39 }, { 24, 45 }, { 20, 58 }, { 17, 43 },
58 { 18, 42 }, { 48, 46 }, { 22, 36 }, { 33, 33 }, { 25, 34 }, { 49, 40 }, { 40, 52 }, { 36, 49 },
59 { 34, 50 }, { 50, 56 }, { 52, 25 }, { 54, 22 }, { 41, 54 }, { 56, 57 }, { 38, 41 }, { 57, 38 }
60};
61
62static const uint8_t scan3x3[4] = { 4, 5, 7, 8 };
63
64static const uint8_t dequant_shift[64] = {
65 14, 14, 14, 14, 14, 14, 14, 14,
66 13, 13, 13, 13, 13, 13, 13, 13,
67 13, 12, 12, 12, 12, 12, 12, 12,
68 11, 11, 11, 11, 11, 11, 11, 11,
69 11, 10, 10, 10, 10, 10, 10, 10,
70 10, 9, 9, 9, 9, 9, 9, 9,
71 9, 8, 8, 8, 8, 8, 8, 8,
72 7, 7, 7, 7, 7, 7, 7, 7
73};
74
75static const uint16_t dequant_mul[64] = {
76 32768, 36061, 38968, 42495, 46341, 50535, 55437, 60424,
77 32932, 35734, 38968, 42495, 46177, 50535, 55109, 59933,
78 65535, 35734, 38968, 42577, 46341, 50617, 55027, 60097,
79 32809, 35734, 38968, 42454, 46382, 50576, 55109, 60056,
80 65535, 35734, 38968, 42495, 46320, 50515, 55109, 60076,
81 65535, 35744, 38968, 42495, 46341, 50535, 55099, 60087,
82 65535, 35734, 38973, 42500, 46341, 50535, 55109, 60097,
83 32771, 35734, 38965, 42497, 46341, 50535, 55109, 60099
84};
85
86#define EOB 0, 0, 0
87
88static const struct dec_2dvlc intra_dec[7] = {
89 {
90 { //level / run / table_inc
91 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
92 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
93 { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
94 { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 2, 1, 2 }, { -2, 1, 2 },
95 { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
96 { 1, 15, 1 }, { -1, 15, 1 }, { 2, 2, 2 }, { -2, 2, 2 }, { 1, 16, 1 }, { -1, 16, 1 },
97 { 1, 17, 1 }, { -1, 17, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 18, 1 }, { -1, 18, 1 },
98 { 1, 19, 1 }, { -1, 19, 1 }, { 2, 3, 2 }, { -2, 3, 2 }, { 1, 20, 1 }, { -1, 20, 1 },
99 { 1, 21, 1 }, { -1, 21, 1 }, { 2, 4, 2 }, { -2, 4, 2 }, { 1, 22, 1 }, { -1, 22, 1 },
100 { 2, 5, 2 }, { -2, 5, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { EOB }
101 },
102 //level_add
103 { 0, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1 },
104 2, //golomb_order
105 0, //inc_limit
106 23, //max_run
107 },
108 {
109 { //level / run
110 { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 }, { -2, 1, 1 },
111 { 1, 3, 0 }, { -1, 3, 0 }, { EOB }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
112 { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 2, 2, 1 },
113 { -2, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 1, 9, 0 },
114 { -1, 9, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 4, 1, 2 }, { -4, 1, 2 }, { 1, 10, 0 },
115 { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 3, 2, 2 },
116 { -3, 2, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 5, 1, 3 },
117 { -5, 1, 3 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 14, 0 },
118 { -1, 14, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 2, 8, 1 }, { -2, 8, 1 }, { 3, 3, 2 },
119 { -3, 3, 2 }, { 6, 1, 3 }, { -6, 1, 3 }, { 1, 15, 0 }, { -1, 15, 0 }
120 },
121 //level_add
122 { 0, 7, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
123 2, //golomb_order
124 1, //inc_limit
125 15, //max_run
126 },
127 {
128 { //level / run
129 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 },
130 { 3, 1, 1 }, { -3, 1, 1 }, { EOB }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
131 { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
132 { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
133 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 2, 4, 0 },
134 { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
135 { -7, 1, 2 }, { 3, 3, 1 }, { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 },
136 { -1, 8, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 3 }, { -8, 1, 3 }, { 1, 9, 0 },
137 { -1, 9, 0 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 }, { 2, 7, 0 },
138 { -2, 7, 0 }, { 9, 1, 3 }, { -9, 1, 3 }, { 1, 10, 0 }, { -1, 10, 0 }
139 },
140 //level_add
141 { 0, 10, 6, 4, 4, 3, 3, 3, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
142 2, //golomb_order
143 2, //inc_limit
144 10, //max_run
145 },
146 {
147 { //level / run
148 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
149 { 1, 2, 0 }, { -1, 2, 0 }, { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 1 },
150 { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 1 },
151 { -6, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
152 { -1, 4, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
153 { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 5, 2, 1 },
154 { -5, 2, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 10, 1, 2 }, {-10, 1, 2 }, { 3, 3, 0 },
155 { -3, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 11, 1, 3 }, {-11, 1, 3 }, { 6, 2, 1 },
156 { -6, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 5, 0 }, { -2, 5, 0 }, { 3, 4, 0 },
157 { -3, 4, 0 }, { 12, 1, 3 }, {-12, 1, 3 }, { 4, 3, 0 }, { -4, 3, 0 }
158 },
159 //level_add
160 { 0, 13, 7, 5, 4, 3, 2, 2, -1, -1, -1 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
161 2, //golomb_order
162 4, //inc_limit
163 7, //max_run
164 },
165 {
166 { //level / run
167 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
168 { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
169 { -6, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 1 },
170 { -8, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 10, 1, 1 },
171 {-10, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 2 },
172 {-11, 1, 2 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 13, 1, 2 },
173 {-13, 1, 2 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 },
174 { -2, 3, 0 }, { 14, 1, 2 }, {-14, 1, 2 }, { 6, 2, 0 }, { -6, 2, 0 }, { 15, 1, 2 },
175 {-15, 1, 2 }, { 16, 1, 2 }, {-16, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 5, 0 },
176 { -1, 5, 0 }, { 7, 2, 0 }, { -7, 2, 0 }, { 17, 1, 2 }, {-17, 1, 2 }
177 },
178 //level_add
179 { 0,18, 8, 4, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
180 2, //golomb_order
181 7, //inc_limit
182 5, //max_run
183 },
184 {
185 { //level / run
186 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
187 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
188 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
189 { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 11, 1, 1 },
190 {-11, 1, 1 }, { 12, 1, 1 }, {-12, 1, 1 }, { 13, 1, 1 }, {-13, 1, 1 }, { 2, 2, 0 },
191 { -2, 2, 0 }, { 14, 1, 1 }, {-14, 1, 1 }, { 15, 1, 1 }, {-15, 1, 1 }, { 3, 2, 0 },
192 { -3, 2, 0 }, { 16, 1, 1 }, {-16, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 17, 1, 1 },
193 {-17, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 18, 1, 1 }, {-18, 1, 1 }, { 5, 2, 0 },
194 { -5, 2, 0 }, { 19, 1, 1 }, {-19, 1, 1 }, { 20, 1, 1 }, {-20, 1, 1 }, { 6, 2, 0 },
195 { -6, 2, 0 }, { 21, 1, 1 }, {-21, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }
196 },
197 //level_add
198 { 0, 22, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
199 2, //golomb_order
200 10, //inc_limit
201 3, //max_run
202 },
203 {
204 { //level / run
205 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
206 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
207 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
208 { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 11, 1, 0 }, {-11, 1, 0 }, { 12, 1, 0 },
209 {-12, 1, 0 }, { 13, 1, 0 }, {-13, 1, 0 }, { 14, 1, 0 }, {-14, 1, 0 }, { 15, 1, 0 },
210 {-15, 1, 0 }, { 16, 1, 0 }, {-16, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 17, 1, 0 },
211 {-17, 1, 0 }, { 18, 1, 0 }, {-18, 1, 0 }, { 19, 1, 0 }, {-19, 1, 0 }, { 20, 1, 0 },
212 {-20, 1, 0 }, { 21, 1, 0 }, {-21, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 22, 1, 0 },
213 {-22, 1, 0 }, { 23, 1, 0 }, {-23, 1, 0 }, { 24, 1, 0 }, {-24, 1, 0 }, { 25, 1, 0 },
214 {-25, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 26, 1, 0 }, {-26, 1, 0 }
215 },
216 //level_add
217 { 0, 27, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
218 2, //golomb_order
219 INT_MAX, //inc_limit
220 2, //max_run
221 }
222};
223
224static const struct dec_2dvlc inter_dec[7] = {
225 {
226 { //level / run
227 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
228 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
229 { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
230 { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 1, 12, 1 }, { -1, 12, 1 },
231 { 1, 13, 1 }, { -1, 13, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 14, 1 }, { -1, 14, 1 },
232 { 1, 15, 1 }, { -1, 15, 1 }, { 1, 16, 1 }, { -1, 16, 1 }, { 1, 17, 1 }, { -1, 17, 1 },
233 { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 }, { 3, 1, 3 }, { -3, 1, 3 },
234 { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 2, 2, 2 }, { -2, 2, 2 },
235 { 1, 22, 1 }, { -1, 22, 1 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
236 { 1, 25, 1 }, { -1, 25, 1 }, { 1, 26, 1 }, { -1, 26, 1 }, { EOB }
237 },
238 //level_add
239 { 0, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
240 3, //golomb_order
241 0, //inc_limit
242 26 //max_run
243 },
244 {
245 { //level / run
246 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 1, 3, 0 },
247 { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
248 { -1, 6, 0 }, { 2, 1, 1 }, { -2, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 },
249 { -1, 8, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 2, 2, 1 },
250 { -2, 2, 1 }, { 1, 11, 0 }, { -1, 11, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 1, 2 },
251 { -3, 1, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 }, { -1, 14, 0 }, { 2, 3, 1 },
252 { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 1, 16, 0 },
253 { -1, 16, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 1, 17, 0 }, { -1, 17, 0 }, { 4, 1, 3 },
254 { -4, 1, 3 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 18, 0 }, { -1, 18, 0 }, { 1, 19, 0 },
255 { -1, 19, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 3, 2, 2 }, { -3, 2, 2 }
256 },
257 //level_add
258 { 0, 5, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1 },
259 2, //golomb_order
260 1, //inc_limit
261 19 //max_run
262 },
263 {
264 { //level / run
265 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 0 },
266 { -2, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 3, 1, 1 },
267 { -3, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
268 { -1, 6, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 1, 2 },
269 { -4, 1, 2 }, { 1, 8, 0 }, { -1, 8, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 4, 0 },
270 { -2, 4, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 5, 1, 2 },
271 { -5, 1, 2 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 6, 0 },
272 { -2, 6, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 3, 1 }, { -3, 3, 1 }, { 6, 1, 2 },
273 { -6, 1, 2 }, { 4, 2, 2 }, { -4, 2, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 7, 0 },
274 { -2, 7, 0 }, { 3, 4, 1 }, { -3, 4, 1 }, { 1, 14, 0 }, { -1, 14, 0 }
275 },
276 //level_add
277 { 0, 7, 5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
278 2, //golomb_order
279 2, //inc_limit
280 14 //max_run
281 },
282 {
283 { //level / run
284 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
285 { -1, 2, 0 }, { 3, 1, 0 }, { -3, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
286 { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 1 },
287 { -5, 1, 1 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 2, 3, 0 },
288 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 2, 4, 0 },
289 { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
290 { -7, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 5, 0 },
291 { -2, 5, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 4, 0 },
292 { -3, 4, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 1, 10, 0 },
293 { -1, 10, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 4, 3, 1 }, { -4, 3, 1 }
294 },
295 //level_add
296 { 0,10, 6, 5, 4, 3, 3, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
297 2, //golomb_order
298 3, //inc_limit
299 10 //max_run
300 },
301 {
302 { //level / run
303 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
304 { -3, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 },
305 { -5, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 0 },
306 { -6, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
307 { -1, 4, 0 }, { 8, 1, 1 }, { -8, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
308 { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 5, 2, 0 },
309 { -5, 2, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 10, 1, 2 },
310 {-10, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 11, 1, 2 }, {-11, 1, 2 }, { 1, 7, 0 },
311 { -1, 7, 0 }, { 6, 2, 0 }, { -6, 2, 0 }, { 3, 4, 0 }, { -3, 4, 0 }, { 2, 5, 0 },
312 { -2, 5, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 4, 3, 0 }, { -4, 3, 0 }
313 },
314 //level_add
315 { 0, 13, 7, 5, 4, 3, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
316 2, //golomb_order
317 6, //inc_limit
318 7 //max_run
319 },
320 {
321 { //level / run
322 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
323 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 1, 2, 0 },
324 { -1, 2, 0 }, { 6, 1, 0 }, { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 },
325 { -8, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 1, 3, 0 },
326 { -1, 3, 0 }, { 10, 1, 1 }, { -10, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 1 },
327 { -11, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 1 }, { -12, 1, 1 }, { 1, 4, 0 },
328 { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 13, 1, 1 }, { -13, 1, 1 }, { 5, 2, 0 },
329 { -5, 2, 0 }, { 14, 1, 1 }, { -14, 1, 1 }, { 6, 2, 0 }, { -6, 2, 0 }, { 1, 5, 0 },
330 { -1, 5, 0 }, { 15, 1, 1 }, { -15, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 16, 1, 1 },
331 { -16, 1, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 2, 0 }, { -7, 2, 0 }
332 },
333 //level_add
334 { 0, 17, 8, 4, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
335 2, //golomb_order
336 9, //inc_limit
337 5 //max_run
338 },
339 {
340 { //level / run
341 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
342 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
343 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 8, 1, 0 },
344 { -8, 1, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
345 { -11, 1, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 13, 1, 0 },
346 { -13, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 15, 1, 0 },
347 { -15, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 16, 1, 0 }, { -16, 1, 0 }, { 17, 1, 0 },
348 { -17, 1, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 19, 1, 0 },
349 { -19, 1, 0 }, { 20, 1, 0 }, { -20, 1, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 1, 4, 0 },
350 { -1, 4, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 21, 1, 0 }, { -21, 1, 0 }
351 },
352 //level_add
353 { 0, 22, 6, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
354 2, //golomb_order
355 INT_MAX, //inc_limit
356 4 //max_run
357 }
358};
359
360static const struct dec_2dvlc chroma_dec[5] = {
361 {
362 { //level / run
363 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
364 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
365 { 1, 7, 1 }, { -1, 7, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 8, 1 }, { -1, 8, 1 },
366 { 1, 9, 1 }, { -1, 9, 1 }, { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 },
367 { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
368 { 1, 15, 1 }, { -1, 15, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 16, 1 }, { -1, 16, 1 },
369 { 1, 17, 1 }, { -1, 17, 1 }, { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 },
370 { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 1, 22, 1 }, { -1, 22, 1 },
371 { 2, 2, 2 }, { -2, 2, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
372 { 1, 25, 1 }, { -1, 25, 1 }, { 4, 1, 3 }, { -4, 1, 3 }, { EOB }
373 },
374 //level_add
375 { 0, 5, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 },
376 2, //golomb_order
377 0, //inc_limit
378 25 //max_run
379 },
380 {
381 { //level / run
382 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 },
383 { -2, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
384 { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 1, 7, 0 },
385 { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 2, 1 }, { -2, 2, 1 }, { 1, 9, 0 },
386 { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 4, 1, 2 },
387 { -4, 1, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 },
388 { -1, 14, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 },
389 { -2, 4, 1 }, { 5, 1, 3 }, { -5, 1, 3 }, { 3, 2, 2 }, { -3, 2, 2 }, { 1, 16, 0 },
390 { -1, 16, 0 }, { 1, 17, 0 }, { -1, 17, 0 }, { 1, 18, 0 }, { -1, 18, 0 }, { 2, 5, 1 },
391 { -2, 5, 1 }, { 1, 19, 0 }, { -1, 19, 0 }, { 1, 20, 0 }, { -1, 20, 0 }
392 },
393 //level_add
394 { 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1 },
395 0, //golomb_order
396 1, //inc_limit
397 20 //max_run
398 },
399 {
400 { //level / run
401 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
402 { -1, 2, 0 }, { 3, 1, 1 }, { -3, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 4, 1, 1 },
403 { -4, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
404 { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
405 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 1, 7, 0 },
406 { -1, 7, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 1, 2 }, { -7, 1, 2 }, { 1, 8, 0 },
407 { -1, 8, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 3, 1 },
408 { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 2 },
409 { -8, 1, 2 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 9, 1, 2 },
410 { -9, 1, 2 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 },
411 },
412 //level_add
413 { 0,10, 6, 4, 4, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
414 1, //golomb_order
415 2, //inc_limit
416 11 //max_run
417 },
418 {
419 { //level / run
420 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
421 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 5, 1, 1 },
422 { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 1, 3, 0 },
423 { -1, 3, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 8, 1, 1 },
424 { -8, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 9, 1, 1 },
425 { -9, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 10, 1, 1 },
426 {-10, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 2, 4, 0 },
427 { -2, 4, 0 }, { 11, 1, 1 }, {-11, 1, 1 }, { 1, 6, 0 }, { -1, 6, 0 }, { 12, 1, 1 },
428 {-12, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 6, 2, 1 }, { -6, 2, 1 }, { 13, 1, 1 },
429 {-13, 1, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 }, { -1, 8, 0 },
430 },
431 //level_add
432 { 0, 14, 7, 4, 3, 3, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
433 1, //golomb_order
434 4, //inc_limit
435 8 //max_run
436 },
437 {
438 { //level / run
439 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
440 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
441 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 1, 2, 0 },
442 { -1, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
443 { -11, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 13, 1, 0 },
444 { -13, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 1, 3, 0 },
445 { -1, 3, 0 }, { 15, 1, 0 }, { -15, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 16, 1, 0 },
446 { -16, 1, 0 }, { 17, 1, 0 }, { -17, 1, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 },
447 { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 6, 2, 0 },
448 { -6, 2, 0 }, { 19, 1, 0 }, { -19, 1, 0 }, { 1, 5, 0 }, { -1, 5, 0 },
449 },
450 //level_add
451 { 0, 20, 7, 3, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
452 0, //golomb_order
453 INT_MAX, //inc_limit
454 5, //max_run
455 }
456};
457
458#undef EOB
459
460/*****************************************************************************
461 *
462 * motion vector prediction
463 *
464 ****************************************************************************/
465
466static inline void store_mvs(AVSContext *h)
467{
468 h->col_mv[h->mbidx * 4 + 0] = h->mv[MV_FWD_X0];
469 h->col_mv[h->mbidx * 4 + 1] = h->mv[MV_FWD_X1];
470 h->col_mv[h->mbidx * 4 + 2] = h->mv[MV_FWD_X2];
471 h->col_mv[h->mbidx * 4 + 3] = h->mv[MV_FWD_X3];
472}
473
474/**
475 * Scale one component of the co-located motion vector, den being
476 * 16384 / BlockDistanceRef (clause 9.9.1 b) 3)). The intermediate
477 * products stay unsigned, they can overflow an int.
478 */
479static inline int scale_direct(unsigned den, int mv, int dist)
480{
481 int m = FF_SIGNBIT(mv);
482
483 return (((den + (den * mv * dist ^ m) - m - 1) >> 14) ^ m) - m;
484}
485
486/**
487 * The parity of a field is the parity of its distance index: a first
488 * coded field has an even one, a second field an odd one (clause 9.4.6.1).
489 */
490static inline int field_parity(AVSContext *h, int distance_index)
491{
492 return (distance_index & 1) ^ !h->top_field_first;
493}
494
495/**
496 * Direct mode: scale the co-located motion vector by its own
497 * BlockDistance, carried in the mv cache (clause 9.9.1 b)). Annex B
498 * fixes PictureStructure over a sequence, so the frame and field
499 * conversion of step 2 cannot arise.
500 */
501static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
502 cavs_vector *col_mv)
503{
504 cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
505 unsigned den = h->direct_den[col_mv->dist];
506 int delta_fw = 0, delta_bw = 0;
507 int mv_ref_y = col_mv->y;
508
509 pmv_fw->ref = h->ref_base[0];
510 pmv_bw->ref = h->ref_base[1];
511 if (!h->pic_structure) {
512 /* reference field selection of 9.9.1 b) 1): an enhanced second
513 * field references index 0 in both directions, its co-located
514 * block being in the first field of the backward reference */
515 int enh = h->b_field_enhanced;
516 int di_col = h->DPB[0].poc + (enh ? 0 : h->field);
517 int di_ref = (di_col - col_mv->dist) & 511;
518 int di_fw0 = (h->DPB[1].poc + 1) & 511;
519
520 if (!enh || !h->field)
521 pmv_fw->ref += di_ref != di_fw0;
522 if (!enh)
523 pmv_bw->ref += h->field;
524 if (enh) {
525 /* the field parity offsets of 9.9.1 b) 3) */
526 int par_cur = h->field ^ !h->top_field_first;
527 int par_bw = h->ref[pmv_bw->ref].parity;
528
529 mv_ref_y += 2 * (field_parity(h, di_ref) - par_bw);
530 delta_fw = 2 * (h->ref[pmv_fw->ref].parity - par_cur);
531 delta_bw = 2 * (par_bw - par_cur);
532 }
533 }
534 pmv_fw->dist = h->dist[pmv_fw->ref];
535 pmv_bw->dist = h->dist[pmv_bw->ref];
536 pmv_fw->ref_idx = pmv_bw->ref_idx = 0; /* derived (clause 9.4.5) */
537 /* scale the co-located motion vector according to its temporal span */
538 pmv_fw->x = scale_direct(den, col_mv->x, pmv_fw->dist);
539 pmv_bw->x = -scale_direct(den, col_mv->x, pmv_bw->dist);
540 pmv_fw->y = scale_direct(den, mv_ref_y, pmv_fw->dist) - delta_fw;
541 pmv_bw->y = -scale_direct(den, mv_ref_y, pmv_bw->dist) - delta_bw;
542}
543
544/**
545 * Symmetric mode: derive the backward mv from the forward one, scaled by
546 * the block's own pair of distances (clause 9.9.1 c)).
547 */
548static inline void mv_pred_sym(AVSContext *h, cavs_vector *src,
549 enum cavs_block size)
550{
552 int factor;
553
554 if (h->pic_structure)
555 dst->ref = h->ref_base[1];
556 else
557 dst->ref = h->ref_base[1] + 1 - (src->ref - h->ref_base[0]);
558 dst->dist = h->dist[dst->ref];
559 dst->ref_idx = 0; /* derived, not read (clause 9.4.5) */
560 factor = dst->dist * h->scale_den[src->ref];
561 /* backward mv is the scaled and negated forward mv */
562 dst->x = -((src->x * factor + 256) >> 9);
563 dst->y = -((src->y * factor + 256) >> 9);
564 set_mvs(dst, size);
565}
566
567/*****************************************************************************
568 *
569 * residual data decoding
570 *
571 ****************************************************************************/
572
573/** kth-order exponential golomb code */
574static inline int get_ue_code(GetBitContext *gb, int order)
575{
576 unsigned ret = get_ue_golomb(gb);
577 if (ret >= ((1U<<31)>>order)) {
578 av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too large\n");
579 return AVERROR_INVALIDDATA;
580 }
581 if (order) {
582 return (ret<<order) + get_bits(gb, order);
583 }
584 return ret;
585}
586
587static inline int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf,
588 int16_t *dst, int mul, int shift, int coeff_num)
589{
590 int round = 1 << (shift - 1);
591 int pos = -1;
592 const uint8_t *scantab = h->scantable;
593
594 /* inverse scan and dequantization */
595 while (--coeff_num >= 0) {
596 pos += run_buf[coeff_num];
597 if (pos > 63) {
598 av_log(h->avctx, AV_LOG_ERROR,
599 "position out of block bounds at pic %d MB(%d,%d)\n",
600 h->cur.poc, h->mbx, h->mby);
601 return AVERROR_INVALIDDATA;
602 }
603 dst[scantab[pos]] = (level_buf[coeff_num] * mul + round) >> shift;
604 }
605 return 0;
606}
607
608/**
609 * decode coefficients from one 8x8 block, dequantize, inverse transform
610 * and add them to sample block
611 * @param r pointer to 2D VLC table
612 * @param esc_golomb_order escape codes are k-golomb with this order k
613 * @param qp quantizer
614 * @param dst location of sample block
615 * @param stride line stride in frame buffer
616 */
618 const struct dec_2dvlc *r, int esc_golomb_order,
619 int qp, uint8_t *dst, ptrdiff_t stride)
620{
621 int i, esc_code, level, mask, ret;
622 unsigned int level_code, run;
623 int16_t level_buf[65];
624 uint8_t run_buf[65];
625 int16_t *block = h->block;
626
627 for (i = 0; i < 65; i++) {
628 level_code = get_ue_code(gb, r->golomb_order);
629 if (level_code >= ESCAPE_CODE) {
630 run = ((level_code - ESCAPE_CODE) >> 1) + 1;
631 if(run > 64) {
632 av_log(h->avctx, AV_LOG_ERROR, "run %d is too large\n", run);
633 return AVERROR_INVALIDDATA;
634 }
635 esc_code = get_ue_code(gb, esc_golomb_order);
636 if (esc_code < 0 || esc_code > 32767) {
637 av_log(h->avctx, AV_LOG_ERROR, "esc_code invalid\n");
638 return AVERROR_INVALIDDATA;
639 }
640
641 level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
642 while (level > r->inc_limit)
643 r++;
644 mask = -(level_code & 1);
645 level = (level ^ mask) - mask;
646 } else {
647 level = r->rltab[level_code][0];
648 if (!level) //end of block signal
649 break;
650 run = r->rltab[level_code][1];
651 r += r->rltab[level_code][2];
652 }
653 level_buf[i] = level;
654 run_buf[i] = run;
655 }
656 ret = dequant(h, level_buf, run_buf, block, dequant_mul[qp],
657 dequant_shift[qp], i);
658 if (ret >= 0)
659 h->cdsp.cavs_idct8_add(dst, block, stride);
660 /* dequant() can write before it fails, so always clear the block */
661 h->bdsp.clear_block(block);
662 return ret;
663}
664
665
666/*****************************************************************************
667 *
668 * advanced entropy coding (AEC), clause 8.4
669 *
670 ****************************************************************************/
671
672/* Table 51: start index of each ae(v) element's context models */
673#define AEC_MB_SKIP_RUN 0
674#define AEC_MB_TYPE 4
675#define AEC_MB_PART_TYPE 19
676#define AEC_INTRA_LUMA_PRED_MODE 22
677#define AEC_INTRA_CHROMA_PRED_MODE 26
678#define AEC_MB_REFERENCE_INDEX 30
679#define AEC_MV_DIFF_X 36
680#define AEC_MV_DIFF_Y 42
681#define AEC_CBP 48
682#define AEC_MB_QP_DELTA 54
683#define AEC_COEFF_FRAME_LUMA 58
684#define AEC_COEFF_FRAME_CHROMA 124
685#define AEC_COEFF_FIELD_LUMA 190
686#define AEC_COEFF_FIELD_CHROMA 256
687
688/* a conforming block's quantized coefficients span -2^(n+3)..2^(n+3)-1
689 * with n the sample precision, 8 for both profiles (clause 9.6.2) */
690#define CAVS_MAX_ABS_LEVEL 2048
691
692/* one trans_coefficient set: 14 + 32 + 20 models, coeffRun from index 46 */
693#define AEC_COEFF_NUM_CTX 66
694#define AEC_COEFF_RUN 46
695#define AEC_COEFF_RUN_NUM_CTX 20
696
697/** Table 52, priIdx as a function of lMax, which saturates at 5. */
698static const uint8_t cavs_aec_pri_idx[6] = { 0, 1, 2, 3, 3, 4 };
699
700/** Decode mb_skip_run, table 44 unary (8.4.4.2 a)). @return SkipMbCount */
702{
703 int v = 0;
704
705 while (!ff_cavs_aec_decode_decision(&h->aec,
706 AEC_MB_SKIP_RUN + FFMIN(v, 3))) {
707 if (++v > h->mb_width * h->mb_height) {
708 av_log(h->avctx, AV_LOG_ERROR, "mb_skip_run out of range\n");
709 return AVERROR_INVALIDDATA;
710 }
711 }
712 return v;
713}
714
715/** Decode mb_type, table 44 unary mapped by tables 54 and 55 (9.4.2 a) 2)) */
717{
718 int v = 0;
719
720 while (!ff_cavs_aec_decode_decision(&h->aec, AEC_MB_TYPE + FFMIN(v, 4))) {
721 if (++v > 5 - h->skip_mode_flag) {
722 av_log(h->avctx, AV_LOG_ERROR, "mb_type out of range\n");
723 return AVERROR_INVALIDDATA;
724 }
725 }
726 return v ? v - 1 + h->skip_mode_flag : 5;
727}
728
729/** Decode mb_type in a B picture (table 45, 8.4.4.2 b)); see table 56. */
731{
732 int a = (h->flags & A_AVAIL) && h->left_mb_type != B_SKIP &&
733 h->left_mb_type != B_DIRECT;
734 int b = (h->flags & B_AVAIL) && h->top_mb_type[h->mbx] != B_SKIP &&
735 h->top_mb_type[h->mbx] != B_DIRECT;
736 int v;
737
738 if (!ff_cavs_aec_decode_decision(&h->aec, AEC_MB_TYPE + 5 + a + b))
739 return h->skip_mode_flag;
740 for (v = 1;
741 !ff_cavs_aec_decode_decision(&h->aec, AEC_MB_TYPE + 7 + FFMIN(v, 7));
742 v++) {
743 if (v >= 24 - h->skip_mode_flag) {
744 av_log(h->avctx, AV_LOG_ERROR, "mb_type out of range\n");
745 return AVERROR_INVALIDDATA;
746 }
747 }
748 return v + h->skip_mode_flag;
749}
750
751/**
752 * Decode mb_part_type (tables 46 and 57, 8.4.4.2 c)).
753 * @return MbPartType, 0 to 3
754 */
756{
758 int b1 = ff_cavs_aec_decode_decision(&h->aec,
759 AEC_MB_PART_TYPE + (b0 ? 2 : 1));
760
761 return (b0 << 1) | b1;
762}
763
764/** Decode mb_reference_index, table 44 unary (8.4.3 j), 8.4.4.2 f)). */
765static int aec_ref_index(AVSContext *h, int ctx_inc, int max)
766{
768 AEC_MB_REFERENCE_INDEX + ctx_inc))
769 return 0;
770 if (h->cur.f->pict_type == AV_PICTURE_TYPE_B)
771 return 1;
773 return 1;
774 for (int v = 2; v <= max; v++)
776 return v;
777 av_log(h->avctx, AV_LOG_ERROR, "mb_reference_index out of range\n");
778 return AVERROR_INVALIDDATA;
779}
780
781/**
782 * Decode one mv_diff_x or mv_diff_y (table 49, 8.4.4.2 g)); mvda is the
783 * magnitude of the same component of the left block's mv_diff.
784 */
785static int aec_mv_diff(AVSContext *h, int base, int mvda, int *diff)
786{
787 int v;
788
790 base + (mvda < 2 ? 0 :
791 mvda < 16 ? 1 : 2))) {
792 *diff = 0; /* mvdSign is not coded for mvdAbs 0 */
793 return 0;
794 }
795 if (!ff_cavs_aec_decode_decision(&h->aec, base + 3)) {
796 v = 1;
797 } else if (!ff_cavs_aec_decode_decision(&h->aec, base + 4)) {
798 v = 2;
799 } else {
800 int even = ff_cavs_aec_decode_decision(&h->aec, base + 5);
801 int k = 0;
802
803 while (!ff_cavs_aec_decode_bypass(&h->aec)) {
804 if (++k > 11) {
805 av_log(h->avctx, AV_LOG_ERROR, "mv_diff out of range\n");
806 return AVERROR_INVALIDDATA;
807 }
808 }
809 v = (1 << k) - 1;
810 while (k--)
811 v += ff_cavs_aec_decode_bypass(&h->aec) << k;
812 v = 3 + 2 * v + even;
813 }
814 if (ff_cavs_aec_decode_bypass(&h->aec)) /* mvdSign */
815 v = -v;
816 if (v < -4096 || v > 4095) {
817 av_log(h->avctx, AV_LOG_ERROR, "mv_diff %d out of range\n", v);
818 return AVERROR_INVALIDDATA;
819 }
820 *diff = v;
821 return 0;
822}
823
824/**
825 * Decode a motion vector's mv_diff pair into the cache that
826 * ff_cavs_mv() reads and the next block takes its mvda from.
827 */
828static int aec_mv(AVSContext *h, enum cavs_mv_loc nP)
829{
830 for (int i = 0; i < 2; i++) {
832 int diff;
833 int ret = aec_mv_diff(h, base, FFABS(h->mvd[nP - 1][i]), &diff);
834
835 if (ret < 0)
836 return ret;
837 h->mvd[nP][i] = diff;
838 }
839 return 0;
840}
841
842/**
843 * Decode intra_luma_pred_mode (table 47) and derive IntraLumaPredMode
844 * from predIntraPredMode per clause 9.4.4.2 a).
845 */
847{
848 int v = 0;
849
850 while (v < 4 &&
852 v++;
853
854 if (v == 0)
855 return pred;
856 if (v == 4) /* 4 stands for 0 (9.4.4.2 a) 2)) */
857 v = 0;
858 return v < pred ? v : v + 1;
859}
860
861/**
862 * Decode intra_chroma_pred_mode (table 48, 8.4.4.2 e)).
863 * @return IntraChromaPredMode, 0 to 3 (table 60)
864 */
866{
867 /* a and b of 8.4.4.2 e); non-intra neighbours hold INTRA_C_LP */
868 const int a = (h->flags & A_AVAIL) &&
869 h->left_c_pred_mode != INTRA_C_LP;
870 const int b = (h->flags & B_AVAIL) &&
871 h->top_c_pred_mode[h->mbx] != INTRA_C_LP;
872 int v;
873
876 v = 0;
877 else if (!ff_cavs_aec_decode_decision(&h->aec,
879 v = 1;
880 else
881 v = 2 + ff_cavs_aec_decode_decision(&h->aec,
883
884 h->left_c_pred_mode = v;
885 h->top_c_pred_mode[h->mbx] = v;
886 return v;
887}
888
889/**
890 * Decode cbp (table 50, 8.4.4.2 h), clause 9.4.7).
891 * @return MbCBP, a six bit mask over the block order numbers
892 */
893static int aec_cbp(AVSContext *h)
894{
895 const int left = (h->flags & A_AVAIL) ? ~h->left_cbp : 0;
896 const int top = (h->flags & B_AVAIL) ? ~h->top_cbp[h->mbx] : 0;
897 int cbp = 0;
898 int a, b;
899
900 a = (left >> 1) & 1; /* left macroblock, block 1 */
901 b = (top >> 2) & 1; /* above macroblock, block 2 */
902 cbp |= ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + a + 2 * b) << 0;
903
904 a = ~cbp & 1; /* this macroblock, block 0 */
905 b = (top >> 3) & 1; /* above macroblock, block 3 */
906 cbp |= ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + a + 2 * b) << 1;
907
908 a = (left >> 3) & 1; /* left macroblock, block 3 */
909 b = ~cbp & 1; /* this macroblock, block 0 */
910 cbp |= ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + a + 2 * b) << 2;
911
912 a = (~cbp >> 2) & 1; /* this macroblock, block 2 */
913 b = (~cbp >> 1) & 1; /* this macroblock, block 1 */
914 cbp |= ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + a + 2 * b) << 3;
915
916 if (ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + 4)) {
917 if (ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + 5))
918 cbp |= 3 << 4;
919 else
920 cbp |= 1 << (4 + ff_cavs_aec_decode_decision(&h->aec, AEC_CBP + 5));
921 }
922
923 h->left_cbp = cbp;
924 h->top_cbp[h->mbx] = cbp;
925 return cbp;
926}
927
928/**
929 * Decode mb_qp_delta (table 44 unary, 8.4.4.2 i)) and map the code
930 * number to the signed delta of clause 9.4.8.
931 */
933{
934 int ctx = AEC_MB_QP_DELTA + (h->prev_delta_qp != 0);
935 int v = 0;
936
937 while (!ff_cavs_aec_decode_decision(&h->aec, ctx)) {
938 v++;
939 ctx = AEC_MB_QP_DELTA + (v == 1 ? 2 : 3);
940 if (v > 64) {
941 av_log(h->avctx, AV_LOG_ERROR, "mb_qp_delta out of range\n");
942 return AVERROR_INVALIDDATA;
943 }
944 }
945
946 if (v)
947 v = (v & 1) ? (v + 1) / 2 : -((v + 1) / 2);
948 if (v < -32 || v > 31) {
949 av_log(h->avctx, AV_LOG_ERROR, "mb_qp_delta out of range\n");
950 return AVERROR_INVALIDDATA;
951 }
952 *delta = v;
953 return 0;
954}
955
956/**
957 * Decode the trans_coefficient pairs of one 8x8 block (8.4.4.2 j) and k)).
958 * @param chroma selects the chroma half of the context sets of table 51
959 */
961 uint8_t *dst, ptrdiff_t stride)
962{
963 int16_t level_buf[65];
964 uint8_t run_buf[65];
965 int16_t *block = h->block;
966 int lmax = 0, pos = 0, i, base, ret;
967
968 if (h->pic_structure)
970 else
972
973 for (i = 0; i < 65; i++) {
974 const int pri = cavs_aec_pri_idx[FFMIN(lmax, 5)];
976 pri * 3 - (pri != 0));
977 int ctx_run = ff_cavs_aec_ctx_idx(base + AEC_COEFF_RUN,
978 AEC_COEFF_RUN_NUM_CTX, pri * 4);
979 int abs_level, run_val;
980
981 if (ctx_lvl < 0 || ctx_run < 0)
982 return FFMIN(ctx_lvl, ctx_run);
983 if (get_bits_left(&h->gb) <= 0)
984 return AVERROR_INVALIDDATA;
985
986 /* coeffLevel, table 44 unary; secIdx as in IEEE 1857-2023 table 36,
987 * whose lMax == 0 column has no secIdx 2 */
988 if (!lmax) {
989 abs_level = 0;
990 if (!ff_cavs_aec_decode_decision(&h->aec, ctx_lvl)) {
991 do {
992 abs_level++;
993 if (abs_level >= CAVS_MAX_ABS_LEVEL) {
994 av_log(h->avctx, AV_LOG_ERROR, "AbsLevel too large\n");
995 return AVERROR_INVALIDDATA;
996 }
997 } while (!ff_cavs_aec_decode_decision(&h->aec, ctx_lvl + 1));
998 }
999 abs_level++; /* clause 9.5.2 a) */
1000 } else {
1002 14 + (pos >> 1));
1003 if (ctx_w < 0)
1004 return ctx_w;
1005 if (ff_cavs_aec_decode_decision_w(&h->aec, ctx_lvl, ctx_w))
1006 break; /* AbsLevel 0, end of block */
1007 abs_level = 1;
1008 if (!ff_cavs_aec_decode_decision(&h->aec, ctx_lvl + 1)) {
1009 do {
1010 abs_level++;
1011 if (abs_level > CAVS_MAX_ABS_LEVEL) {
1012 av_log(h->avctx, AV_LOG_ERROR, "AbsLevel too large\n");
1013 return AVERROR_INVALIDDATA;
1014 }
1015 } while (!ff_cavs_aec_decode_decision(&h->aec, ctx_lvl + 2));
1016 }
1017 }
1018
1019 if (ff_cavs_aec_decode_bypass(&h->aec))
1020 level_buf[i] = -abs_level;
1021 else
1022 level_buf[i] = abs_level;
1023 if (level_buf[i] < -CAVS_MAX_ABS_LEVEL ||
1024 level_buf[i] >= CAVS_MAX_ABS_LEVEL) {
1025 av_log(h->avctx, AV_LOG_ERROR,
1026 "coefficient level out of range\n");
1027 return AVERROR_INVALIDDATA;
1028 }
1029
1030 ctx_run += abs_level > 1 ? 2 : 0;
1031 run_val = 0;
1032 if (!ff_cavs_aec_decode_decision(&h->aec, ctx_run)) {
1033 do {
1034 run_val++;
1035 if (run_val > 64) {
1036 av_log(h->avctx, AV_LOG_ERROR, "RunVal too large\n");
1037 return AVERROR_INVALIDDATA;
1038 }
1039 } while (!ff_cavs_aec_decode_decision(&h->aec, ctx_run + 1));
1040 }
1041 run_buf[i] = run_val + 1; /* scan positions consumed, 9.5.3 b) */
1042
1043 /* lMax is updated with this coefficient before the next pair */
1044 lmax = FFMAX(lmax, abs_level);
1045 pos = FFMIN(pos + run_val + 1, 63);
1046 }
1047
1048 ret = dequant(h, level_buf, run_buf, block, dequant_mul[qp],
1049 dequant_shift[qp], i);
1050 if (ret >= 0)
1051 h->cdsp.cavs_idct8_add(dst, block, stride);
1052 h->bdsp.clear_block(block);
1053 return ret;
1054}
1055
1056
1057/**
1058 * Tell whether the byte aligned 00 00 01 at @p offset is a start code: in a
1059 * de-emulated payload it may be a coincidence (annex A).
1060 */
1062{
1063 int lo = 0, hi = h->nb_stc_offset;
1064
1065 if (h->gb.buffer != h->deemulated_buf)
1066 return 1;
1067 /* stc_offset[] is sorted; a crafted payload can hold one every 4 bytes */
1068 while (lo < hi) {
1069 int mid = lo + (hi - lo) / 2;
1070
1071 if (h->stc_offset[mid] == offset)
1072 return 1;
1073 if (h->stc_offset[mid] < offset)
1074 lo = mid + 1;
1075 else
1076 hi = mid;
1077 }
1078 return 0;
1079}
1080
1081/**
1082 * Position the reader on the start code that ends an AEC slice: the first
1083 * one at or after the slice's own payload. The reader position is not
1084 * reliable: the arithmetic decoder's look ahead has run past it.
1085 */
1087{
1088 GetBitContext *gb = &h->gb;
1089 const uint8_t *buf = gb->buffer;
1090 int size = gb->size_in_bits >> 3;
1091 int i = h->aec_start;
1092
1093 /* release gb; check_for_slice() waits for this */
1094 h->aec.gb = NULL;
1095
1096 for (; i + 2 < size; i++)
1097 if (!buf[i] && !buf[i + 1] && buf[i + 2] == 1 &&
1099 break;
1100 if (init_get_bits8(gb, buf, size) >= 0)
1101 skip_bits_long(gb, i * 8);
1102}
1103
1104/**
1105 * Read mb_qp_delta when the macroblock has coefficients and the picture's qp
1106 * is not fixed, and keep PreviousDeltaQP for the AEC contexts (clause 9.4.8).
1107 */
1109{
1110 int delta = 0;
1111
1112 if (h->cbp && !h->qp_fixed) {
1113 if (h->aec_enable) {
1114 int ret = aec_mb_qp_delta(h, &delta);
1115 if (ret < 0)
1116 return ret;
1117 } else {
1118 delta = get_se_golomb(&h->gb);
1119 }
1120 h->qp = (h->qp + (unsigned)delta) & 63;
1121 }
1122 h->prev_delta_qp = delta;
1123 return 0;
1124}
1125
1126/** Decode one 8x8 block's residual with the picture's entropy coder. */
1127static int decode_residual(AVSContext *h, const struct dec_2dvlc *r,
1128 int esc_golomb_order, int chroma, int qp,
1129 uint8_t *dst, ptrdiff_t stride)
1130{
1131 if (h->aec_enable)
1133 return decode_residual_block(h, &h->gb, r, esc_golomb_order, qp, dst,
1134 stride);
1135}
1136
1138{
1139 const int qp = ff_cavs_chroma_qp[h->qp];
1140 int ret;
1141
1142 if (h->cbp & (1 << 4)) {
1143 ret = decode_residual(h, chroma_dec, 0, 1, qp, h->cu, h->c_stride);
1144 if (ret < 0)
1145 return ret;
1146 }
1147 if (h->cbp & (1 << 5)) {
1148 ret = decode_residual(h, chroma_dec, 0, 1, qp, h->cv, h->c_stride);
1149 if (ret < 0)
1150 return ret;
1151 }
1152 return 0;
1153}
1154
1156{
1157 int block, ret;
1158
1159 if (h->aec_enable) {
1160 h->cbp = aec_cbp(h);
1161 } else {
1162 /* get coded block pattern */
1163 int cbp = get_ue_golomb(&h->gb);
1164 if (cbp > 63U) {
1165 av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
1166 return AVERROR_INVALIDDATA;
1167 }
1168 h->cbp = cbp_tab[cbp][1];
1169 }
1171 if (ret < 0)
1172 return ret;
1173 for (block = 0; block < 4; block++)
1174 if (h->cbp & (1 << block)) {
1175 ret = decode_residual(h, inter_dec, 0, 0, h->qp,
1176 h->cy + h->luma_scan[block], h->l_stride);
1177 if (ret < 0)
1178 return ret;
1179 }
1180
1181 return decode_residual_chroma(h);
1182}
1183
1184/*****************************************************************************
1185 *
1186 * macroblock level
1187 *
1188 ****************************************************************************/
1189
1190static inline void set_mv_intra(AVSContext *h)
1191{
1192 h->mv[MV_FWD_X0] = CAVS_INTRA_MV;
1193 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
1194 h->mv[MV_BWD_X0] = CAVS_INTRA_MV;
1195 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
1196 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
1197 h->col_type_base[h->mbidx] = I_8X8;
1198}
1199
1200static int decode_mb_i(AVSContext *h, int cbp_code)
1201{
1202 GetBitContext *gb = &h->gb;
1203 unsigned pred_mode_uv;
1204 int block;
1205 uint8_t top[18];
1206 uint8_t *left = NULL;
1207 uint8_t *d;
1208 int ret;
1209
1211 h->left_mb_type = I_8X8;
1212 h->top_mb_type[h->mbx] = I_8X8;
1213
1214 /* get intra prediction modes from stream */
1215 for (block = 0; block < 4; block++) {
1216 int nA, nB, predpred;
1217 int pos = scan3x3[block];
1218
1219 nA = h->pred_mode_Y[pos - 1];
1220 nB = h->pred_mode_Y[pos - 3];
1221 predpred = FFMIN(nA, nB);
1222 if (predpred == NOT_AVAIL) // if either is not available
1223 predpred = INTRA_L_LP;
1224 if (h->aec_enable) {
1225 predpred = aec_intra_luma_pred_mode(h, predpred);
1226 } else if (!get_bits1(gb)) {
1227 int rem_mode = get_bits(gb, 2);
1228 predpred = rem_mode + (rem_mode >= predpred);
1229 }
1230 h->pred_mode_Y[pos] = predpred;
1231 }
1232 if (h->aec_enable) {
1233 pred_mode_uv = aec_intra_chroma_pred_mode(h);
1234 } else {
1235 pred_mode_uv = get_ue_golomb_31(gb);
1236 if (pred_mode_uv > 6) {
1237 av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
1238 return AVERROR_INVALIDDATA;
1239 }
1240 }
1241 ff_cavs_modify_mb_i(h, &pred_mode_uv);
1242
1243 /* get coded block pattern */
1244 if (h->aec_enable) {
1245 /* under AEC an intra MB codes cbp too (table 26, clause 9.4.7) */
1246 h->cbp = aec_cbp(h);
1247 } else {
1248 /* an I picture's second field codes cbp in mb_type (9.4.2 a) 2)) */
1249 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I && !h->field)
1250 cbp_code = get_ue_golomb(gb);
1251 if (cbp_code > 63U) {
1252 av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
1253 return AVERROR_INVALIDDATA;
1254 }
1255 h->cbp = cbp_tab[cbp_code][0];
1256 }
1258 if (ret < 0)
1259 return ret;
1260
1261 /* luma intra prediction interleaved with residual decode/transform/add */
1262 for (block = 0; block < 4; block++) {
1263 d = h->cy + h->luma_scan[block];
1265 h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
1266 (d, top, left, h->l_stride);
1267 if (h->cbp & (1<<block)) {
1268 ret = decode_residual(h, intra_dec, 1, 0, h->qp, d, h->l_stride);
1269 if (ret < 0)
1270 return ret;
1271 }
1272 }
1273
1274 /* chroma intra prediction */
1276 h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx * 10],
1277 h->left_border_u, h->c_stride);
1278 h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx * 10],
1279 h->left_border_v, h->c_stride);
1280
1282 if (ret < 0)
1283 return ret;
1285 set_mv_intra(h);
1286 return 0;
1287}
1288
1290{
1291 if (h->stream_revision > 0) {
1292 h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
1293 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = NOT_AVAIL;
1294 } else {
1295 h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
1296 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = INTRA_L_LP;
1297 }
1298}
1299
1300/**
1301 * Read one mb_reference_index and turn it into a reference list index
1302 * (table 26, clauses 7.2.5 and 9.4.5). Table 26 misprints the presence
1303 * predicate's brackets; GB/T 20090.2-2013 table 27 and IEEE 1857-2023
1304 * clause 7.1.5 both print it as implemented here.
1305 */
1307{
1308 const int base = h->ref_base[list];
1309 /* NumberOfReference of one direction, clause 9.4.5 figures 15 to 20 */
1310 const int max = !h->pic_structure &&
1311 h->cur.f->pict_type == AV_PICTURE_TYPE_P ? 3 : 1;
1312 int idx = 0;
1313
1314 if (!h->ref_flag &&
1315 (h->cur.f->pict_type == AV_PICTURE_TYPE_P ||
1316 (h->cur.f->pict_type == AV_PICTURE_TYPE_B && !h->pic_structure))) {
1317 if (h->aec_enable) {
1318 /* a and b of 8.4.4.2 f); unavailable, intra and derived
1319 * neighbours carry index 0 */
1320 int a = h->mv[nP - 1].ref_idx > 0;
1321 int b = h->mv[nP - 4].ref_idx > 0;
1322
1323 idx = aec_ref_index(h, a + 2 * b, max);
1324 if (idx < 0)
1325 return idx;
1326 } else {
1327 idx = get_bits(&h->gb, max > 1 ? 2 : 1);
1328 }
1329 }
1330 h->mv[nP].ref = base + idx;
1331 h->mv[nP].ref_idx = idx;
1332 return base + idx;
1333}
1334
1335/**
1336 * Decode one motion vector: under AEC its mv_diff must be read before
1337 * ff_cavs_mv() overwrites the cache its context comes from.
1338 */
1339static int decode_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
1340 enum cavs_mv_pred mode, enum cavs_block size, int ref)
1341{
1342 if (h->aec_enable && mode < MV_PRED_PSKIP) {
1343 int ret = aec_mv(h, nP);
1344 if (ret < 0)
1345 return ret;
1346 }
1347 ff_cavs_mv(h, nP, nC, mode, size, ref);
1348 return 0;
1349}
1350
1351/* what the AEC contexts of later macroblocks read about this one (8.4.4.2) */
1352static void set_inter_mb_ctx(AVSContext *h, enum cavs_mb mb_type, int skip)
1353{
1354 h->left_mb_type = mb_type;
1355 h->top_mb_type[h->mbx] = mb_type;
1356 h->left_c_pred_mode = INTRA_C_LP;
1357 h->top_c_pred_mode[h->mbx] = INTRA_C_LP;
1358 if (skip) {
1359 h->left_cbp = 0;
1360 h->top_cbp[h->mbx] = 0;
1361 h->prev_delta_qp = 0;
1362 }
1363}
1364
1365#define MV(nP, nC, mode, size, ref) \
1366 do { \
1367 ret = decode_mv(h, nP, nC, mode, size, ref); \
1368 if (ret < 0) \
1369 return ret; \
1370 } while (0)
1371
1372#define REF(dst, list, nP) \
1373 do { \
1374 ret = decode_ref_index(h, list, nP); \
1375 if (ret < 0) \
1376 return ret; \
1377 dst = ret; \
1378 } while (0)
1379
1380static int decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
1381{
1382 int ref[4];
1383 int ret;
1384
1386 set_inter_mb_ctx(h, mb_type, mb_type == P_SKIP);
1387 switch (mb_type) {
1388 case P_SKIP:
1389 MV(MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, h->ref_base[0]);
1390 break;
1391 case P_16X16:
1392 REF(ref[0], 0, MV_FWD_X0);
1394 break;
1395 case P_16X8:
1396 REF(ref[0], 0, MV_FWD_X0);
1397 REF(ref[2], 0, MV_FWD_X2);
1400 break;
1401 case P_8X16:
1402 REF(ref[0], 0, MV_FWD_X0);
1403 REF(ref[1], 0, MV_FWD_X1);
1406 break;
1407 case P_8X8:
1408 REF(ref[0], 0, MV_FWD_X0);
1409 REF(ref[1], 0, MV_FWD_X1);
1410 REF(ref[2], 0, MV_FWD_X2);
1411 REF(ref[3], 0, MV_FWD_X3);
1416 break;
1417 default:
1418 av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in P frame\n",
1419 mb_type);
1420 return AVERROR_INVALIDDATA;
1421 }
1422 ff_cavs_inter(h, mb_type);
1424 store_mvs(h);
1425 if (mb_type != P_SKIP) {
1427 if (ret < 0)
1428 return ret;
1429 }
1430 ff_cavs_filter(h, mb_type);
1431 h->col_type_base[h->mbidx] = mb_type;
1432 return 0;
1433}
1434
1435static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
1436{
1437 int block;
1438 enum cavs_sub_mb sub_type[4];
1439 int flags;
1440 int ref[2][4];
1441 int ret;
1442 /* the co-located macroblock of an enhanced second field is the one at
1443 * the same position in the first field (clause 9.9.1 b) 1)) */
1444 int col = h->mbidx - (h->b_field_enhanced && h->field ?
1445 h->mb_width * h->mb_height / 2 : 0);
1446
1448 set_inter_mb_ctx(h, mb_type, mb_type == B_SKIP);
1449
1450 /* reset all MVs */
1451 h->mv[MV_FWD_X0] = CAVS_DIR_MV;
1452 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
1453 h->mv[MV_BWD_X0] = CAVS_DIR_MV;
1454 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
1455 switch (mb_type) {
1456 case B_SKIP:
1457 case B_DIRECT:
1458 if (!h->col_type_base[col]) {
1459 /* intra MB at co-location: in-plane prediction (9.9.1 b) 1)) */
1461 h->ref_base[0]);
1463 h->ref_base[1]);
1464 } else
1465 /* direct prediction from co-located P MB, block-wise */
1466 for (block = 0; block < 4; block++)
1467 mv_pred_direct(h, &h->mv[mv_scan[block]],
1468 &h->col_mv[col * 4 + block]);
1469 break;
1470 case B_FWD_16X16:
1471 REF(ref[0][0], 0, MV_FWD_X0);
1473 break;
1474 case B_SYM_16X16:
1475 REF(ref[0][0], 0, MV_FWD_X0);
1478 break;
1479 case B_BWD_16X16:
1480 REF(ref[1][0], 1, MV_BWD_X0);
1482 break;
1483 case B_8X8:
1484#define TMP_UNUSED_INX 7
1485 flags = 0;
1486 for (block = 0; block < 4; block++) {
1487 if (h->aec_enable)
1488 sub_type[block] = aec_mb_part_type(h);
1489 else
1490 sub_type[block] = get_bits(&h->gb, 2);
1491 }
1492 /* all forward reference indices come first (table 26) */
1493 for (block = 0; block < 4; block++)
1494 if (sub_type[block] == B_SUB_FWD || sub_type[block] == B_SUB_SYM)
1495 REF(ref[0][block], 0, mv_scan[block]);
1496 for (block = 0; block < 4; block++)
1497 if (sub_type[block] == B_SUB_BWD)
1498 REF(ref[1][block], 1, mv_scan[block] + MV_BWD_OFFS);
1499 for (block = 0; block < 4; block++) {
1500 switch (sub_type[block]) {
1501 case B_SUB_DIRECT:
1502 if (!h->col_type_base[col]) {
1503 /* intra MB at co-location, do in-plane prediction */
1504 if(flags==0) {
1505 // if col-MB is a Intra MB, current Block size is 16x16.
1506 // AVS standard section 9.9.1
1507 if(block>0){
1508 h->mv[TMP_UNUSED_INX ] = h->mv[MV_FWD_X0 ];
1510 }
1512 MV_PRED_BSKIP, BLK_8X8, h->ref_base[0]);
1515 MV_PRED_BSKIP, BLK_8X8, h->ref_base[1]);
1516 if(block>0) {
1517 flags = mv_scan[block];
1518 h->mv[flags ] = h->mv[MV_FWD_X0 ];
1519 h->mv[flags + MV_BWD_OFFS] = h->mv[MV_FWD_X0 + MV_BWD_OFFS];
1520 h->mv[MV_FWD_X0 ] = h->mv[TMP_UNUSED_INX ];
1522 } else
1523 flags = MV_FWD_X0;
1524 } else {
1525 h->mv[mv_scan[block] ] = h->mv[flags ];
1526 h->mv[mv_scan[block] + MV_BWD_OFFS] = h->mv[flags + MV_BWD_OFFS];
1527 }
1528 } else
1529 mv_pred_direct(h, &h->mv[mv_scan[block]],
1530 &h->col_mv[col * 4 + block]);
1531 break;
1532 case B_SUB_FWD:
1533 MV(mv_scan[block], mv_scan[block] - 3,
1535 break;
1536 case B_SUB_SYM:
1537 MV(mv_scan[block], mv_scan[block] - 3,
1539 mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
1540 break;
1541 }
1542 }
1543#undef TMP_UNUSED_INX
1544 for (block = 0; block < 4; block++) {
1545 if (sub_type[block] == B_SUB_BWD)
1547 mv_scan[block] + MV_BWD_OFFS - 3,
1549 }
1550 break;
1551 default:
1552 if (mb_type <= B_SYM_16X16) {
1553 av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
1554 return AVERROR_INVALIDDATA;
1555 }
1556 av_assert2(mb_type < B_8X8);
1557 flags = ff_cavs_partition_flags[mb_type];
1558 if (mb_type & 1) { /* 16x8 macroblock types */
1559 if (flags & FWD0)
1560 REF(ref[0][0], 0, MV_FWD_X0);
1561 if (flags & FWD1)
1562 REF(ref[0][2], 0, MV_FWD_X2);
1563 if (flags & BWD0)
1564 REF(ref[1][0], 1, MV_BWD_X0);
1565 if (flags & BWD1)
1566 REF(ref[1][2], 1, MV_BWD_X2);
1567 if (flags & FWD0)
1569 if (flags & SYM0)
1570 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
1571 if (flags & FWD1)
1573 if (flags & SYM1)
1574 mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
1575 if (flags & BWD0)
1577 if (flags & BWD1)
1579 } else { /* 8x16 macroblock types */
1580 if (flags & FWD0)
1581 REF(ref[0][0], 0, MV_FWD_X0);
1582 if (flags & FWD1)
1583 REF(ref[0][1], 0, MV_FWD_X1);
1584 if (flags & BWD0)
1585 REF(ref[1][0], 1, MV_BWD_X0);
1586 if (flags & BWD1)
1587 REF(ref[1][1], 1, MV_BWD_X1);
1588 if (flags & FWD0)
1590 if (flags & SYM0)
1591 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
1592 if (flags & FWD1)
1594 if (flags & SYM1)
1595 mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
1596 if (flags & BWD0)
1598 if (flags & BWD1)
1600 }
1601 }
1602 ff_cavs_inter(h, mb_type);
1604 if (mb_type != B_SKIP) {
1606 if (ret < 0)
1607 return ret;
1608 }
1609 ff_cavs_filter(h, mb_type);
1610
1611 return 0;
1612}
1613
1614#undef MV
1615#undef REF
1616
1617/**
1618 * Decode one macroblock of a P or B coded macroblock layer, table 25.
1619 * @param skip_count what is left of the current mb_skip_run, or -1 when the
1620 * next macroblock position starts a new one
1621 */
1622static int decode_mb_pb_layer(AVSContext *h, int *skip_count)
1623{
1624 const int b = h->cur.f->pict_type == AV_PICTURE_TYPE_B;
1625 const enum cavs_mb skip = b ? B_SKIP : P_SKIP;
1626 const enum cavs_mb last = b ? B_8X8 : P_8X8;
1627 enum cavs_mb mb_type;
1628 int skipped, ret;
1629
1630 if (h->skip_mode_flag && *skip_count < 0) {
1631 if (h->aec_enable) {
1632 *skip_count = aec_mb_skip_run(h);
1633 } else {
1634 if (get_bits_left(&h->gb) < 1)
1635 return AVERROR_INVALIDDATA;
1636 *skip_count = get_ue_golomb(&h->gb);
1637 }
1638 if (*skip_count < 0)
1639 return AVERROR_INVALIDDATA;
1640 }
1641 skipped = h->skip_mode_flag && (*skip_count)--;
1642 if (skipped) {
1643 mb_type = skip;
1644 } else if (h->aec_enable) {
1646 if (ret < 0)
1647 return ret;
1648 mb_type = ret + skip;
1649 } else {
1650 if (get_bits_left(&h->gb) < 1)
1651 return AVERROR_INVALIDDATA;
1652 mb_type = get_ue_golomb(&h->gb) + skip + h->skip_mode_flag;
1653 }
1654 if (mb_type > last)
1655 ret = decode_mb_i(h, mb_type - last - 1);
1656 else
1657 ret = b ? decode_mb_b(h, mb_type) : decode_mb_p(h, mb_type);
1658 if (ret < 0)
1659 return ret;
1660 /* the stuffing bit follows a coded MB and the last one of a skip run */
1661 if (h->aec_enable && (!skipped || !*skip_count) &&
1664 return 0;
1665}
1666
1667/*****************************************************************************
1668 *
1669 * slice level
1670 *
1671 ****************************************************************************/
1672
1674{
1675 int mby = h->stc;
1676
1677 /* over 2800 lines MbRow carries high bits here (clause 7.2.4) */
1678 if (h->height > 2800)
1679 mby += get_bits(gb, 3) << 7; //slice_vertical_position_extension
1680
1681 if (mby >= h->mb_height) {
1682 av_log(h->avctx, AV_LOG_ERROR, "MbRow %d is too large\n", mby);
1683 return AVERROR_INVALIDDATA;
1684 }
1685
1686 h->mby = mby;
1687 h->mbidx = h->mby * h->mb_width;
1688 /* the second field's first slice jumps to MbHeight / 2 (clause 3.24) */
1690
1691 /* mark top macroblocks as unavailable */
1692 h->flags &= ~(B_AVAIL | C_AVAIL);
1693 if (!h->pic_qp_fixed) {
1694 h->qp_fixed = get_bits1(gb);
1695 h->qp = get_bits(gb, 6);
1696 }
1697 /* inter frame or second slice can have weighting params */
1698 if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
1699 (!h->pic_structure && h->mbidx >= h->mb_width * h->mb_height / 2))
1700 if (get_bits1(gb)) { //slice_weighting_flag
1701 avpriv_request_sample(h->avctx, "Weighted prediction");
1702 return AVERROR_PATCHWELCOME;
1703 }
1704 return 0;
1705}
1706
1707static inline int check_for_slice(AVSContext *h)
1708{
1709 GetBitContext *gb = &h->gb;
1710 int align;
1711 int ret;
1712
1713 if (h->mbx)
1714 return 0;
1715 /* an AEC slice ends with its stuffing bit, not at a start code (7.2.4) */
1716 if (h->aec_enable && h->aec.gb)
1717 return 0;
1718 align = (-get_bits_count(gb)) & 7;
1719 /* check for stuffing byte */
1720 if (!align && (show_bits(gb, 8) == 0x80))
1721 align = 8;
1722 if ((show_bits_long(gb, 24 + align) & 0xFFFFFF) == 0x000001) {
1724 int stc;
1725
1726 if (!is_start_code_offset(h, (get_bits_count(gb) + align) >> 3))
1727 return 0;
1728 peek = *gb;
1729 skip_bits_long(&peek, 24 + align);
1730 stc = get_bits(&peek, 8);
1731 /* any other unit ends the picture's data; leave it to the caller */
1732 if (stc > (SLICE_MAX_START_CODE & 0xFF)) {
1733 h->pic_data_end = 1;
1734 return 0;
1735 }
1736 *gb = peek;
1737 h->stc = stc;
1738 ret = decode_slice_header(h, gb);
1739 if (ret < 0)
1740 return ret;
1741 if (h->aec_enable) {
1742 /* aec_byte_alignment_bit padding, then 8.4.1 */
1743 align_get_bits(gb);
1744 h->aec_start = get_bits_count(gb) >> 3;
1745 ff_cavs_aec_init(&h->aec, gb);
1746 h->prev_delta_qp = 0; /* reset with PreviousQP, clause 9.3 */
1747 }
1748 return 1;
1749 }
1750 return 0;
1751}
1752
1753/*****************************************************************************
1754 *
1755 * frame level
1756 *
1757 ****************************************************************************/
1758
1759/**
1760 * Build the reference list and the temporal distances of the current frame
1761 * or field (clause 9.4.5 figures 14 to 20, clause 9.4.6.1).
1762 */
1764{
1765 /* the first coded field is the first displayed one (clause 7.2.3.1),
1766 * and annex B.2 keeps top_field_first constant over the sequence */
1767 const int f1 = !h->top_field_first; /* parity of a first field */
1768 const int f2 = h->top_field_first; /* parity of a second field */
1769 const int b = h->cur.f->pict_type == AV_PICTURE_TYPE_B;
1770 const int poc = h->cur.poc;
1771 const int poc0 = h->DPB[0].poc;
1772 const int poc1 = h->DPB[1].poc;
1773 int nref;
1774
1775#define SET_REF(idx, frame, par, distance) \
1776 do { \
1777 h->ref[idx].f = (frame); \
1778 h->ref[idx].parity = (par); \
1779 h->dist[idx] = (distance) & 511; \
1780 } while (0)
1781
1782 h->ref_base[0] = h->ref_base[1] = 0;
1783
1784 if (h->pic_structure) {
1785 /* figures 15 and 18: whole frames, most recent first */
1786 SET_REF(0, h->DPB[0].f, 0, b ? poc0 - poc : poc - poc0);
1787 for (int i = 1; i < FF_ARRAY_ELEMS(h->ref); i++)
1788 SET_REF(i, h->DPB[1].f, 0, poc - poc1);
1789 /* figure 18: a B frame codes no reference index */
1790 h->ref_base[0] = b;
1791 nref = 1;
1792 } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1793 /* figure 14: the second field references its own first field */
1794 for (int i = 0; i < FF_ARRAY_ELEMS(h->ref); i++)
1795 SET_REF(i, h->cur.f, f1, 1);
1796 nref = 1;
1797 } else if (!b) {
1798 if (!h->field) {
1799 /* figure 16: the four fields of the two previous frames */
1800 SET_REF(0, h->DPB[0].f, f2, poc - poc0 - 1);
1801 SET_REF(1, h->DPB[0].f, f1, poc - poc0);
1802 SET_REF(2, h->DPB[1].f, f2, poc - poc1 - 1);
1803 SET_REF(3, h->DPB[1].f, f1, poc - poc1);
1804 } else {
1805 /* figure 17: this picture's first field, then the three before */
1806 SET_REF(0, h->cur.f, f1, 1);
1807 SET_REF(1, h->DPB[0].f, f2, poc - poc0);
1808 SET_REF(2, h->DPB[0].f, f1, poc - poc0 + 1);
1809 SET_REF(3, h->DPB[1].f, f2, poc - poc1);
1810 }
1811 nref = 4;
1812 } else {
1813 /* figures 19 and 20: two backward and two forward fields */
1814 SET_REF(0, h->DPB[0].f, f1, poc0 - poc - h->field);
1815 SET_REF(1, h->DPB[0].f, f2, poc0 + 1 - poc - h->field);
1816 SET_REF(2, h->DPB[1].f, f2, poc + h->field - poc1 - 1);
1817 SET_REF(3, h->DPB[1].f, f1, poc + h->field - poc1);
1818 h->ref_base[0] = 2;
1819 nref = 2;
1820 }
1821#undef SET_REF
1822
1823 for (int i = 0; i < FF_ARRAY_ELEMS(h->ref); i++)
1824 h->scale_den[i] = h->dist[i] ? 512 / h->dist[i] : 0;
1825
1826 for (int i = 0; b && i < nref; i++) {
1827 int fw = h->ref_base[0] + i;
1828 int bw = h->pic_structure ? h->ref_base[1]
1829 : h->ref_base[1] + 1 - i;
1830 int factor = h->dist[bw] * h->scale_den[fw];
1831
1832 if (factor > 32768) {
1833 av_log(h->avctx, AV_LOG_ERROR,
1834 "symmetric scaling factor %d too large\n", factor);
1835 return AVERROR_INVALIDDATA;
1836 }
1837 }
1838 return 0;
1839}
1840
1842{
1843 int ret;
1844 int field;
1845 int skip_count = -1;
1846 int pb_field_enhanced_flag = 0;
1847
1848 if (!h->top_qp) {
1849 av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
1850 return AVERROR_INVALIDDATA;
1851 }
1852
1853 av_frame_unref(h->cur.f);
1854
1855 skip_bits(&h->gb, 16);//bbv_delay
1856 if (h->profile == AV_PROFILE_CAVS_BROADCASTING)
1857 skip_bits(&h->gb, 8); //marker_bit, bbv_delay_extension (tables 21, 22)
1858 if (h->stc == PIC_PB_START_CODE) {
1859 h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
1860 if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
1861 av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
1862 return AVERROR_INVALIDDATA;
1863 }
1864 /* make sure we have the reference frames we need */
1865 if (!h->DPB[0].f->data[0] ||
1866 (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
1867 return AVERROR_INVALIDDATA;
1868 } else {
1869 h->cur.f->pict_type = AV_PICTURE_TYPE_I;
1870 if (get_bits1(&h->gb))
1871 skip_bits(&h->gb, 24);//time_code
1872 /* a Broadcasting stream always has the marker bit (table 21); old
1873 JiZhun sample clips were all progressive and no low_delay, bump
1874 stream revision if detected otherwise */
1875 if (h->profile == AV_PROFILE_CAVS_BROADCASTING)
1876 h->stream_revision = 1;
1877 else if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
1878 h->stream_revision = 1;
1879 /* similarly test top_field_first and repeat_first_field */
1880 else if (show_bits(&h->gb, 11) & 3)
1881 h->stream_revision = 1;
1882 if (h->stream_revision > 0)
1883 skip_bits(&h->gb, 1); //marker_bit
1884 }
1885
1886 if (get_bits_left(&h->gb) < 23)
1887 return AVERROR_INVALIDDATA;
1888
1889 ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
1891 if (ret < 0)
1892 return ret;
1893
1894 if (!h->edge_emu_buffer) {
1895 int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
1896 h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
1897 if (!h->edge_emu_buffer)
1898 return AVERROR(ENOMEM);
1899 }
1900
1901 /* picture_distance; DistanceIndex is twice it (clause 9.4.6.1) */
1902 h->cur.poc = get_bits(&h->gb, 8) * 2;
1903
1904 if (h->low_delay)
1905 get_ue_golomb(&h->gb); //bbv_check_times
1906 h->progressive = get_bits1(&h->gb);
1907 h->pic_structure = 1;
1908 if (!h->progressive)
1909 h->pic_structure = get_bits1(&h->gb);
1910 /* clause 7.2.3: a progressive sequence has frame pictures only; its odd
1911 * MbHeight would also let a field picture write past coded_height */
1912 if (!h->pic_structure && h->progressive_seq) {
1913 av_log(h->avctx, AV_LOG_ERROR,
1914 "field picture in a progressive sequence\n");
1915 return AVERROR_INVALIDDATA;
1916 }
1917 /* a field coded picture uses inverse block scan method 2 (9.5.3 c)) */
1918 h->scantable = h->pic_structure ? h->permutated_scantable
1919 : h->permutated_scantable_field;
1920 if (!h->pic_structure && h->stc == PIC_PB_START_CODE)
1921 skip_bits1(&h->gb); //advanced_pred_mode_disable
1922 h->top_field_first = get_bits1(&h->gb);
1923 skip_bits1(&h->gb); //repeat_first_field
1924 h->pic_qp_fixed =
1925 h->qp_fixed = get_bits1(&h->gb);
1926 h->qp = get_bits(&h->gb, 6);
1927 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1928 /* only a field coded intra picture has skip_mode_flag (table 21) */
1929 h->skip_mode_flag = 0;
1930 if (!h->progressive && !h->pic_structure)
1931 h->skip_mode_flag = get_bits1(&h->gb);
1932 skip_bits(&h->gb, 4); //reserved bits
1933 } else {
1934 if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
1935 h->ref_flag = get_bits1(&h->gb);
1936 else
1937 /* 1 for a frame coded B picture (clause 7.2.3.2) */
1938 h->ref_flag = 1;
1939 /* no_forward_reference_flag, pb_field_enhanced_flag, r(2); table 22.
1940 * JiZhun has reserved bits here and must ignore them (clause 5.4) */
1941 skip_bits1(&h->gb);
1942 pb_field_enhanced_flag = get_bits1(&h->gb) &&
1943 h->profile == AV_PROFILE_CAVS_BROADCASTING;
1944 skip_bits(&h->gb, 2);
1945 h->skip_mode_flag = get_bits1(&h->gb);
1946 }
1947 h->loop_filter_disable = get_bits1(&h->gb);
1948 if (!h->loop_filter_disable && get_bits1(&h->gb)) {
1949 h->alpha_offset = get_se_golomb(&h->gb);
1950 h->beta_offset = get_se_golomb(&h->gb);
1951 if ( h->alpha_offset < -64 || h->alpha_offset > 64
1952 || h-> beta_offset < -64 || h-> beta_offset > 64) {
1953 h->alpha_offset = h->beta_offset = 0;
1954 return AVERROR_INVALIDDATA;
1955 }
1956 } else {
1957 h->alpha_offset = h->beta_offset = 0;
1958 }
1959
1960 /* AWQ parameters and aec_enable end the header (tables 21, 22) */
1961 h->aec_enable = 0;
1962 if (h->profile == AV_PROFILE_CAVS_BROADCASTING) {
1963 if (get_bits1(&h->gb)) { //weighting_quant_flag
1964 avpriv_request_sample(h->avctx, "Adaptive weighted quantization");
1965 return AVERROR_PATCHWELCOME;
1966 }
1967 h->aec_enable = get_bits1(&h->gb);
1968 }
1969
1970 /* in a frame picture the field derivations reduce to the frame ones
1971 * (9.9.1 b) 3)); PFieldSkip of 9.9.1 a) 1) is not implemented */
1972 h->b_field_enhanced = pb_field_enhanced_flag && !h->pic_structure &&
1973 h->cur.f->pict_type == AV_PICTURE_TYPE_B;
1974 if (pb_field_enhanced_flag && !h->pic_structure &&
1975 h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
1976 avpriv_request_sample(h->avctx, "Enhanced field coded P picture");
1977 return AVERROR_PATCHWELCOME;
1978 }
1979
1980 if (!h->progressive) {
1981 h->cur.f->flags |= AV_FRAME_FLAG_INTERLACED;
1982 if (h->top_field_first)
1983 h->cur.f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
1984 }
1985
1986 /* needs picture_structure, so only after the whole header */
1987 if ((ret = ff_cavs_init_pic(h)) < 0)
1988 return ret;
1989 if ((ret = set_ref_list(h)) < 0)
1990 return ret;
1991
1992 field = h->field;
1993 ret = 0;
1994 h->aec.gb = NULL; /* started by the first slice header */
1995 h->pic_data_end = 0;
1996 do {
1998 if (ret < 0)
1999 break;
2000 if (ret)
2001 skip_count = -1;
2002 if (h->aec_enable && !h->aec.gb) {
2003 av_log(h->avctx, AV_LOG_ERROR,
2004 "AEC picture without a slice header\n");
2006 break;
2007 }
2008 /* past the picture's data, only a pending skip run can code MBs */
2009 if (h->pic_data_end && !(h->skip_mode_flag && skip_count > 0)) {
2010 av_log(h->avctx, AV_LOG_ERROR, "picture data ended before MB %d\n",
2011 h->mbidx);
2013 break;
2014 }
2015 if (h->field != field) {
2016 field = h->field;
2017 if ((ret = set_ref_list(h)) < 0)
2018 break;
2019 }
2020 if (h->cur.f->pict_type != AV_PICTURE_TYPE_I || h->field) {
2021 /* an intra picture's second field is inter coded (9.4.2 a) 2)) */
2022 ret = decode_mb_pb_layer(h, &skip_count);
2023 } else {
2024 ret = decode_mb_i(h, 0);
2025 /* aec_mb_stuffing_bit is 1 on the slice's last MB (7.2.4) */
2026 if (ret >= 0 && h->aec_enable &&
2029 }
2030 if (ret < 0)
2031 break;
2032 } while (ff_cavs_next_mb(h));
2033 if (ret >= 0 && h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
2034 av_frame_unref(h->DPB[1].f);
2035 FFSWAP(AVSFrame, h->cur, h->DPB[1]);
2036 FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
2037 }
2038 return ret;
2039}
2040
2041/*****************************************************************************
2042 *
2043 * headers and interface
2044 *
2045 ****************************************************************************/
2046
2048{
2049 int frame_rate_code;
2050 int profile, level, aspect_ratio;
2051 int width, height;
2052 int mb_width, mb_height;
2053 int progressive_seq, low_delay;
2054 int chroma_format, sample_precision;
2055 int ret;
2056
2057 profile = get_bits(&h->gb, 8);
2058 /* the sequence header is the same for both profiles (table 14) */
2061 avpriv_report_missing_feature(h->avctx, "Profile %#x", profile);
2062 return AVERROR_PATCHWELCOME;
2063 }
2064 level = get_bits(&h->gb, 8);
2065 progressive_seq = get_bits1(&h->gb);
2066
2067 width = get_bits(&h->gb, 14);
2068 height = get_bits(&h->gb, 14);
2069 if ((h->width || h->height) && (h->width != width || h->height != height)) {
2071 "Width/height changing in CAVS");
2072 return AVERROR_PATCHWELCOME;
2073 }
2074 if (width <= 0 || height <= 0) {
2075 av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
2076 return AVERROR_INVALIDDATA;
2077 }
2078 chroma_format = get_bits(&h->gb, 2);
2079 sample_precision = get_bits(&h->gb, 3);
2080 /* the Broadcasting macroblock layer is written for 8 bit 4:2:0 */
2082 if (sample_precision != 1) {
2083 av_log(h->avctx, AV_LOG_ERROR,
2084 "sample_precision %d is not 8 bit\n", sample_precision);
2085 return AVERROR_INVALIDDATA;
2086 }
2087 if (chroma_format == 2) {
2088 avpriv_request_sample(h->avctx, "4:2:2 chroma");
2089 return AVERROR_PATCHWELCOME;
2090 }
2091 if (chroma_format != 1) {
2092 av_log(h->avctx, AV_LOG_ERROR,
2093 "chroma_format %d is reserved\n", chroma_format);
2094 return AVERROR_INVALIDDATA;
2095 }
2096 }
2097 aspect_ratio = get_bits(&h->gb, 4);
2098 frame_rate_code = get_bits(&h->gb, 4);
2099 if (frame_rate_code == 0 || frame_rate_code > 13) {
2100 av_log(h->avctx, AV_LOG_WARNING,
2101 "frame_rate_code %d is invalid\n", frame_rate_code);
2102 frame_rate_code = 1;
2103 }
2104
2105 skip_bits(&h->gb, 18); //bit_rate_lower
2106 skip_bits1(&h->gb); //marker_bit
2107 skip_bits(&h->gb, 12); //bit_rate_upper
2108 low_delay = get_bits1(&h->gb);
2109
2110 mb_width = (width + 15) >> 4;
2111 /* interlaced: an even number of MB rows (clause 7.2.2) */
2112 mb_height = progressive_seq ? (height + 15) >> 4
2113 : ((height + 31) >> 5) * 2;
2114 /* the grid sizes the arrays of ff_cavs_init_top_lines(), allocated once */
2115 if (h->top_qp && (mb_width != h->mb_width || mb_height != h->mb_height)) {
2116 avpriv_report_missing_feature(h->avctx, "Macroblock grid changing");
2117 return AVERROR_PATCHWELCOME;
2118 }
2119
2120 /* horizontal_size and vertical_size are only the displayed part */
2121 ret = ff_set_dimensions(h->avctx, mb_width * 16, mb_height * 16);
2122 if (ret < 0)
2123 return ret;
2124 h->avctx->width = width;
2125 h->avctx->height = height;
2126
2127 /* commit last: a rejected header must leave the decoder as it was */
2128 h->profile = profile;
2129 h->level = level;
2130 h->aspect_ratio = aspect_ratio;
2131 h->width = width;
2132 h->height = height;
2133 h->mb_width = mb_width;
2134 h->mb_height = mb_height;
2135 h->low_delay = low_delay;
2136 h->avctx->profile = profile;
2137 h->progressive_seq = progressive_seq;
2138 h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];
2139 if (!h->top_qp)
2140 return ff_cavs_init_top_lines(h);
2141 return 0;
2142}
2143
2144/** annex A applies to picture headers and slices, not to other units */
2145static int annex_a_applies(int stc)
2146{
2147 return stc <= (SLICE_MAX_START_CODE & 0xFF) ||
2148 stc == (PIC_I_START_CODE & 0xFF) ||
2149 stc == (PIC_PB_START_CODE & 0xFF);
2150}
2151
2152/**
2153 * Copy one region of a picture payload, removing the annex A pseudo start
2154 * codes; the clause 5.8.2.4 stuffing is rewritten to keep the next start
2155 * code aligned. With pb NULL they are only counted.
2156 * @return the number of pseudo start codes found
2157 */
2158static int deemulate_region(PutBitContext *pb, const uint8_t *buf, int size,
2159 int deemulated)
2160{
2161 int found = 0;
2162 int stuffing = -1;
2163 int i;
2164
2165 if (!deemulated) {
2166 for (i = 0; i < size; i++)
2167 if (pb)
2168 put_bits(pb, 8, buf[i]);
2169 return 0;
2170 }
2171
2172 /* the stuffing bit is the last set bit of the region */
2173 for (i = size; i > 0 && !buf[i - 1]; i--)
2174 ;
2175 if (i > 0) {
2176 stuffing = i - 1;
2177 size = stuffing;
2178 }
2179
2180 for (i = 0; i < size; i++) {
2181 if (i + 2 < size && !buf[i] && !buf[i + 1] && buf[i + 2] == 2) {
2182 /* drop the two low bits of the 02 */
2183 if (pb) {
2184 put_bits(pb, 16, 0);
2185 put_bits(pb, 6, 0);
2186 }
2187 found++;
2188 i += 2;
2189 } else if (pb) {
2190 put_bits(pb, 8, buf[i]);
2191 }
2192 }
2193
2194 if (pb) {
2195 if (stuffing >= 0) {
2196 int n = ff_ctz(buf[stuffing]) + 1;
2197 if (n < 8)
2198 put_bits(pb, 8 - n, buf[stuffing] >> n);
2199 put_bits(pb, 1, 1); //stuffing_bit
2200 }
2201 align_put_bits(pb); /* stuffing_bit until byte aligned */
2202 }
2203 return found;
2204}
2205
2206/**
2207 * Walk the payload region by region, removing the annex A pseudo start
2208 * codes; on the writing pass, record every start code prefix offset in
2209 * h->stc_offset.
2210 * @return the number of pseudo start codes found
2211 */
2213 const uint8_t *buf, int size)
2214{
2215 int deemulated = 1; /* buf starts inside a picture header */
2216 int found = 0;
2217 int pos = 0;
2218
2219 while (pos < size) {
2220 int end;
2221
2222 for (end = pos; end + 2 < size; end++) {
2223 /* nothing can start at end, end + 1 or end + 2 (annex A) */
2224 if (buf[end + 2] > 1) {
2225 end += 2;
2226 continue;
2227 }
2228 if (!buf[end] && !buf[end + 1] && buf[end + 2] == 1)
2229 break;
2230 }
2231 if (end + 2 >= size)
2232 end = size;
2233
2234 found += deemulate_region(pb, buf + pos, end - pos, deemulated);
2235 if (end == size)
2236 break;
2237
2238 if (pb) {
2239 h->stc_offset[h->nb_stc_offset++] = put_bits_count(pb) >> 3;
2240 put_bits(pb, 24, 1); /* start code prefix */
2241 }
2242 pos = end + 3;
2243 if (pos < size) {
2244 if (pb)
2245 put_bits(pb, 8, buf[pos]);
2246 deemulated = annex_a_applies(buf[pos]);
2247 pos++;
2248 }
2249 }
2250 return found;
2251}
2252
2253/**
2254 * Remove the annex A pseudo start codes from a payload: a byte forming
2255 * 00 00 02 with the two before it loses its two least significant bits. buf
2256 * runs from just after a picture start code to the packet end.
2257 * @return the size of h->deemulated_buf, 0 if buf needs no copy, or < 0
2258 */
2259static int remove_pseudo_start_codes(AVSContext *h, const uint8_t *buf,
2260 int size)
2261{
2262 PutBitContext pb;
2263
2264 if (size <= 0 || size > INT_MAX / 8 ||
2265 !deemulate_picture(h, NULL, buf, size))
2266 return 0;
2267
2268 av_fast_padded_malloc(&h->deemulated_buf, &h->deemulated_buf_size, size);
2269 if (!h->deemulated_buf)
2270 return AVERROR(ENOMEM);
2271
2272 av_fast_malloc(&h->stc_offset, &h->stc_offset_size,
2273 (size / 3 + 1) * sizeof(*h->stc_offset));
2274 if (!h->stc_offset)
2275 return AVERROR(ENOMEM);
2276 h->nb_stc_offset = 0;
2277
2278 init_put_bits(&pb, h->deemulated_buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
2279 deemulate_picture(h, &pb, buf, size);
2280 flush_put_bits(&pb);
2282 /* de-emulation shrinks, so restore the padding the reader over-reads */
2283 memset(h->deemulated_buf + put_bytes_output(&pb), 0,
2285 return put_bytes_output(&pb);
2286}
2287
2289{
2290 AVSContext *h = avctx->priv_data;
2291 h->got_keyframe = 0;
2292}
2293
2294static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
2295 int *got_frame, AVPacket *avpkt)
2296{
2297 AVSContext *h = avctx->priv_data;
2298 const uint8_t *buf = avpkt->data;
2299 int buf_size = avpkt->size;
2300 uint32_t stc = -1;
2301 int input_size, ret;
2302 const uint8_t *buf_end;
2303 const uint8_t *buf_ptr;
2304 int frame_start = 0;
2305
2306 if (buf_size == 0) {
2307 if (!h->low_delay && h->DPB[0].f->data[0]) {
2308 *got_frame = 1;
2309 av_frame_move_ref(rframe, h->DPB[0].f);
2310 }
2311 return 0;
2312 }
2313
2314 h->stc = 0;
2315
2316 buf_ptr = buf;
2317 buf_end = buf + buf_size;
2318 for(;;) {
2319 buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
2320 if ((stc & 0xFFFFFE00) || buf_ptr == buf_end) {
2321 if (!h->stc)
2322 av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n");
2323 return FFMAX(0, buf_ptr - buf);
2324 }
2325 input_size = buf_end - buf_ptr;
2326 if ((ret = init_get_bits8(&h->gb, buf_ptr, input_size)) < 0)
2327 return ret;
2328 switch (stc) {
2329 case CAVS_START_CODE:
2331 if (ret < 0)
2332 return ret;
2333 break;
2334 case PIC_I_START_CODE:
2335 if (!h->got_keyframe) {
2336 av_frame_unref(h->DPB[0].f);
2337 av_frame_unref(h->DPB[1].f);
2338 h->got_keyframe = 1;
2339 }
2341 case PIC_PB_START_CODE:
2342 if (frame_start > 1)
2343 return AVERROR_INVALIDDATA;
2344 frame_start ++;
2345 if (*got_frame)
2346 av_frame_unref(rframe);
2347 *got_frame = 0;
2348 if (!h->got_keyframe)
2349 break;
2350 /* annex A, normative for decoders */
2351 ret = remove_pseudo_start_codes(h, buf_ptr, input_size);
2352 if (ret < 0)
2353 return ret;
2354 if (ret > 0 &&
2355 (ret = init_get_bits8(&h->gb, h->deemulated_buf, ret)) < 0)
2356 return ret;
2357 h->stc = stc;
2358 ret = decode_pic(h);
2359 if (ret < 0)
2360 return ret;
2361 *got_frame = 1;
2362 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
2363 if (h->DPB[!h->low_delay].f->data[0]) {
2364 if ((ret = av_frame_ref(rframe, h->DPB[!h->low_delay].f)) < 0)
2365 return ret;
2366 } else {
2367 *got_frame = 0;
2368 }
2369 } else {
2370 av_frame_move_ref(rframe, h->cur.f);
2371 }
2372 break;
2373 case EXT_START_CODE:
2374 //mpeg_decode_extension(avctx, buf_ptr, input_size);
2375 break;
2376 case USER_START_CODE:
2377 //mpeg_decode_user_data(avctx, buf_ptr, input_size);
2378 break;
2379 default:
2380 /* slice start codes are consumed by check_for_slice() */
2381 break;
2382 }
2383 }
2384}
2385
2387 .p.name = "cavs",
2388 CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2/P16)"),
2389 .p.type = AVMEDIA_TYPE_VIDEO,
2390 .p.id = AV_CODEC_ID_CAVS,
2391 .priv_data_size = sizeof(AVSContext),
2392 .init = ff_cavs_init,
2393 .close = ff_cavs_end,
2395 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
2396 .flush = cavs_flush,
2398 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
2399};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
const FFCodec ff_cavs_decoder
Definition cavsdec.c:2386
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static uint32_t BS_FUNC peek(BSCTX *bc, unsigned int n)
Return n bits from the buffer but do not change the buffer state.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
int ff_cavs_init_pic(AVSContext *h)
Definition cavs.c:789
void ff_cavs_set_mb_row(AVSContext *h)
Point the macroblock sample pointers at macroblock row h->mby, addressed inside the macroblock's own ...
Definition cavs.c:673
int ff_cavs_next_mb(AVSContext *h)
save predictors for later macroblocks and increase macroblock address
Definition cavs.c:742
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
Definition cavs.c:246
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block)
Definition cavs.c:195
av_cold int ff_cavs_end(AVCodecContext *avctx)
Definition cavs.c:915
void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, enum cavs_mv_pred mode, enum cavs_block size, int ref)
Definition cavs.c:594
av_cold int ff_cavs_init(AVCodecContext *avctx)
Definition cavs.c:867
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type)
Definition cavs.c:513
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
Definition cavs.c:373
int ff_cavs_init_top_lines(AVSContext *h)
some predictions require data from the top-neighbouring macroblock.
Definition cavs.c:826
void ff_cavs_init_mb(AVSContext *h)
initialise predictors for motion vectors and intra prediction
Definition cavs.c:696
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
in-loop deblocking filter for a single macroblock
Definition cavs.c:119
#define C_AVAIL
Definition cavs.h:50
#define BWD1
Definition cavs.h:61
#define SYM1
Definition cavs.h:63
#define MV_BWD_OFFS
Definition cavs.h:67
#define USER_START_CODE
Definition cavs.h:43
cavs_sub_mb
Definition cavs.h:85
@ B_SUB_SYM
Definition cavs.h:89
@ B_SUB_DIRECT
Definition cavs.h:86
@ B_SUB_FWD
Definition cavs.h:87
@ B_SUB_BWD
Definition cavs.h:88
#define PIC_I_START_CODE
Definition cavs.h:45
#define SYM0
Definition cavs.h:62
cavs_mv_pred
Definition cavs.h:113
@ MV_PRED_MEDIAN
Definition cavs.h:114
@ MV_PRED_TOP
Definition cavs.h:116
@ MV_PRED_BSKIP
Definition cavs.h:119
@ MV_PRED_PSKIP
Definition cavs.h:118
@ MV_PRED_LEFT
Definition cavs.h:115
@ MV_PRED_TOPRIGHT
Definition cavs.h:117
const uint8_t ff_cavs_chroma_qp[64]
Definition cavsdata.c:57
#define EXT_START_CODE
Definition cavs.h:42
#define SLICE_MAX_START_CODE
Definition cavs.h:41
#define CAVS_INTRA_MV
mark block as "no prediction from this direction" e.g.
Definition cavs.h:314
cavs_mb
Definition cavs.h:70
@ B_FWD_16X16
Definition cavs.h:79
@ P_SKIP
Definition cavs.h:72
@ P_8X16
Definition cavs.h:75
@ I_8X8
Definition cavs.h:71
@ B_8X8
Definition cavs.h:82
@ P_16X8
Definition cavs.h:74
@ B_DIRECT
Definition cavs.h:78
@ B_SKIP
Definition cavs.h:77
@ B_BWD_16X16
Definition cavs.h:80
@ P_8X8
Definition cavs.h:76
@ P_16X16
Definition cavs.h:73
@ B_SYM_16X16
Definition cavs.h:81
#define FWD0
Definition cavs.h:58
@ INTRA_L_LP
Definition cavs.h:95
static void set_mvs(cavs_vector *mv, enum cavs_block size)
Definition cavs.h:316
cavs_mv_loc
Definition cavs.h:129
@ MV_FWD_C2
Definition cavs.h:133
@ MV_BWD_X1
Definition cavs.h:146
@ MV_FWD_X3
Definition cavs.h:139
@ MV_BWD_A1
Definition cavs.h:144
@ MV_FWD_X1
Definition cavs.h:136
@ MV_BWD_B3
Definition cavs.h:142
@ MV_FWD_X0
Definition cavs.h:135
@ MV_BWD_X2
Definition cavs.h:148
@ MV_FWD_B3
Definition cavs.h:132
@ MV_FWD_X2
Definition cavs.h:138
@ MV_FWD_A1
Definition cavs.h:134
@ MV_BWD_X0
Definition cavs.h:145
@ MV_BWD_C2
Definition cavs.h:143
@ INTRA_C_LP
Definition cavs.h:104
cavs_block
Definition cavs.h:122
@ BLK_16X8
Definition cavs.h:124
@ BLK_16X16
Definition cavs.h:123
@ BLK_8X8
Definition cavs.h:126
@ BLK_8X16
Definition cavs.h:125
#define BWD0
Definition cavs.h:60
#define FWD1
Definition cavs.h:59
const uint8_t ff_cavs_partition_flags[30]
Definition cavsdata.c:24
#define A_AVAIL
Definition cavs.h:48
#define B_AVAIL
Definition cavs.h:49
#define CAVS_DIR_MV
mark block as using intra prediction
Definition cavs.h:311
#define PIC_PB_START_CODE
Definition cavs.h:46
#define CAVS_START_CODE
Definition cavs.h:44
#define NOT_AVAIL
Definition cavs.h:52
#define ESCAPE_CODE
Definition cavs.h:56
void ff_cavs_aec_init(CAVSAECContext *aec, GetBitContext *gb)
Reset all contexts and start the decoder on byte aligned gb (8.4.1).
Definition cavs_aec.c:36
static int ff_cavs_aec_decode_decision_w(CAVSAECContext *aec, int ctx_idx, int ctx_idx_w)
Decode a bin with two weighted context models (8.4.4.3.2).
Definition cavs_aec.h:172
static int ff_cavs_aec_decode_decision(CAVSAECContext *aec, int ctx_idx)
Decode a bin with one context model (8.4.4.3.2).
Definition cavs_aec.h:157
static int ff_cavs_aec_ctx_idx(int start, int span, int inc)
Table 51 start index + ctxIdxInc, or AVERROR_INVALIDDATA/AVERROR_BUG.
Definition cavs_aec.h:43
static int ff_cavs_aec_decode_stuffing_bit(CAVSAECContext *aec)
Decode aec_mb_stuffing_bit, fixed lgPmps (8.4.4.3.4).
Definition cavs_aec.h:209
static int ff_cavs_aec_decode_bypass(CAVSAECContext *aec)
Decode a bypass bin, fixed lgPmps (8.4.4.3.3).
Definition cavs_aec.h:203
static const struct dec_2dvlc intra_dec[7]
Definition cavsdec.c:88
#define AEC_COEFF_FIELD_LUMA
Definition cavsdec.c:685
static int scale_direct(unsigned den, int mv, int dist)
Scale one component of the co-located motion vector, den being 16384 / BlockDistanceRef (clause 9....
Definition cavsdec.c:479
static av_cold void cavs_flush(AVCodecContext *avctx)
Definition cavsdec.c:2288
static int aec_mb_qp_delta(AVSContext *h, int *delta)
Decode mb_qp_delta (table 44 unary, 8.4.4.2 i)) and map the code number to the signed delta of clause...
Definition cavsdec.c:932
#define REF(dst, list, nP)
Definition cavsdec.c:1372
static const struct dec_2dvlc inter_dec[7]
Definition cavsdec.c:224
static int set_ref_list(AVSContext *h)
Build the reference list and the temporal distances of the current frame or field (clause 9....
Definition cavsdec.c:1763
static int aec_cbp(AVSContext *h)
Decode cbp (table 50, 8.4.4.2 h), clause 9.4.7).
Definition cavsdec.c:893
static int decode_seq_header(AVSContext *h)
Definition cavsdec.c:2047
static int decode_slice_header(AVSContext *h, GetBitContext *gb)
Definition cavsdec.c:1673
static int deemulate_region(PutBitContext *pb, const uint8_t *buf, int size, int deemulated)
Copy one region of a picture payload, removing the annex A pseudo start codes; the clause 5....
Definition cavsdec.c:2158
#define SET_REF(idx, frame, par, distance)
static void set_intra_mode_default(AVSContext *h)
Definition cavsdec.c:1289
static int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf, int16_t *dst, int mul, int shift, int coeff_num)
Definition cavsdec.c:587
#define MV(nP, nC, mode, size, ref)
Definition cavsdec.c:1365
#define AEC_INTRA_CHROMA_PRED_MODE
Definition cavsdec.c:677
#define CAVS_MAX_ABS_LEVEL
Definition cavsdec.c:690
#define AEC_MB_TYPE
Definition cavsdec.c:674
#define AEC_MV_DIFF_Y
Definition cavsdec.c:680
#define AEC_MV_DIFF_X
Definition cavsdec.c:679
static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
Definition cavsdec.c:1435
static const struct dec_2dvlc chroma_dec[5]
Definition cavsdec.c:360
static int decode_mb_i(AVSContext *h, int cbp_code)
Definition cavsdec.c:1200
static int decode_residual(AVSContext *h, const struct dec_2dvlc *r, int esc_golomb_order, int chroma, int qp, uint8_t *dst, ptrdiff_t stride)
Decode one 8x8 block's residual with the picture's entropy coder.
Definition cavsdec.c:1127
#define AEC_MB_PART_TYPE
Definition cavsdec.c:675
static int field_parity(AVSContext *h, int distance_index)
The parity of a field is the parity of its distance index: a first coded field has an even one,...
Definition cavsdec.c:490
static int aec_ref_index(AVSContext *h, int ctx_inc, int max)
Decode mb_reference_index, table 44 unary (8.4.3 j), 8.4.4.2 f)).
Definition cavsdec.c:765
static int aec_mb_type_p(AVSContext *h)
Decode mb_type, table 44 unary mapped by tables 54 and 55 (9.4.2 a) 2))
Definition cavsdec.c:716
static int aec_mb_type_b(AVSContext *h)
Decode mb_type in a B picture (table 45, 8.4.4.2 b)); see table 56.
Definition cavsdec.c:730
static int aec_intra_luma_pred_mode(AVSContext *h, int pred)
Decode intra_luma_pred_mode (table 47) and derive IntraLumaPredMode from predIntraPredMode per clause...
Definition cavsdec.c:846
static int decode_mb_pb_layer(AVSContext *h, int *skip_count)
Decode one macroblock of a P or B coded macroblock layer, table 25.
Definition cavsdec.c:1622
#define AEC_MB_QP_DELTA
Definition cavsdec.c:682
#define AEC_COEFF_FIELD_CHROMA
Definition cavsdec.c:686
static int decode_mb_qp_delta(AVSContext *h)
Read mb_qp_delta when the macroblock has coefficients and the picture's qp is not fixed,...
Definition cavsdec.c:1108
#define AEC_MB_REFERENCE_INDEX
Definition cavsdec.c:678
static const uint16_t dequant_mul[64]
Definition cavsdec.c:75
static int decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
Definition cavsdec.c:1380
static void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw, cavs_vector *col_mv)
Direct mode: scale the co-located motion vector by its own BlockDistance, carried in the mv cache (cl...
Definition cavsdec.c:501
static int aec_mv_diff(AVSContext *h, int base, int mvda, int *diff)
Decode one mv_diff_x or mv_diff_y (table 49, 8.4.4.2 g)); mvda is the magnitude of the same component...
Definition cavsdec.c:785
static int decode_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, enum cavs_mv_pred mode, enum cavs_block size, int ref)
Decode one motion vector: under AEC its mv_diff must be read before ff_cavs_mv() overwrites the cache...
Definition cavsdec.c:1339
static const uint8_t cavs_aec_pri_idx[6]
Table 52, priIdx as a function of lMax, which saturates at 5.
Definition cavsdec.c:698
#define EOB
Definition cavsdec.c:86
#define AEC_COEFF_RUN_NUM_CTX
Definition cavsdec.c:695
static int get_ue_code(GetBitContext *gb, int order)
kth-order exponential golomb code
Definition cavsdec.c:574
static int decode_residual_chroma(AVSContext *h)
Definition cavsdec.c:1137
static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition cavsdec.c:2294
#define AEC_COEFF_FRAME_CHROMA
Definition cavsdec.c:684
static const uint8_t scan3x3[4]
Definition cavsdec.c:62
static int decode_residual_block(AVSContext *h, GetBitContext *gb, const struct dec_2dvlc *r, int esc_golomb_order, int qp, uint8_t *dst, ptrdiff_t stride)
decode coefficients from one 8x8 block, dequantize, inverse transform and add them to sample block
Definition cavsdec.c:617
static int decode_residual_block_aec(AVSContext *h, int chroma, int qp, uint8_t *dst, ptrdiff_t stride)
Decode the trans_coefficient pairs of one 8x8 block (8.4.4.2 j) and k)).
Definition cavsdec.c:960
static int aec_intra_chroma_pred_mode(AVSContext *h)
Decode intra_chroma_pred_mode (table 48, 8.4.4.2 e)).
Definition cavsdec.c:865
static int remove_pseudo_start_codes(AVSContext *h, const uint8_t *buf, int size)
Remove the annex A pseudo start codes from a payload: a byte forming 00 00 02 with the two before it ...
Definition cavsdec.c:2259
static int is_start_code_offset(AVSContext *h, int offset)
Tell whether the byte aligned 00 00 01 at offset is a start code: in a de-emulated payload it may be ...
Definition cavsdec.c:1061
#define AEC_MB_SKIP_RUN
Definition cavsdec.c:673
#define AEC_COEFF_RUN
Definition cavsdec.c:694
static const uint8_t cbp_tab[64][2]
Definition cavsdec.c:51
static void aec_end_of_slice(AVSContext *h)
Position the reader on the start code that ends an AEC slice: the first one at or after the slice's o...
Definition cavsdec.c:1086
static int deemulate_picture(AVSContext *h, PutBitContext *pb, const uint8_t *buf, int size)
Walk the payload region by region, removing the annex A pseudo start codes; on the writing pass,...
Definition cavsdec.c:2212
static const uint8_t mv_scan[4]
Definition cavsdec.c:46
static void set_inter_mb_ctx(AVSContext *h, enum cavs_mb mb_type, int skip)
Definition cavsdec.c:1352
static void mv_pred_sym(AVSContext *h, cavs_vector *src, enum cavs_block size)
Symmetric mode: derive the backward mv from the forward one, scaled by the block's own pair of distan...
Definition cavsdec.c:548
static int decode_residual_inter(AVSContext *h)
Definition cavsdec.c:1155
static int aec_mb_skip_run(AVSContext *h)
Decode mb_skip_run, table 44 unary (8.4.4.2 a)).
Definition cavsdec.c:701
#define AEC_INTRA_LUMA_PRED_MODE
Definition cavsdec.c:676
static void store_mvs(AVSContext *h)
Definition cavsdec.c:466
static int check_for_slice(AVSContext *h)
Definition cavsdec.c:1707
static int annex_a_applies(int stc)
annex A applies to picture headers and slices, not to other units
Definition cavsdec.c:2145
#define TMP_UNUSED_INX
static int decode_ref_index(AVSContext *h, int list, enum cavs_mv_loc nP)
Read one mb_reference_index and turn it into a reference list index (table 26, clauses 7....
Definition cavsdec.c:1306
static void set_mv_intra(AVSContext *h)
Definition cavsdec.c:1190
#define AEC_CBP
Definition cavsdec.c:681
static int aec_mb_part_type(AVSContext *h)
Decode mb_part_type (tables 46 and 57, 8.4.4.2 c)).
Definition cavsdec.c:755
static const uint8_t dequant_shift[64]
Definition cavsdec.c:64
static int decode_pic(AVSContext *h)
Definition cavsdec.c:1841
#define AEC_COEFF_NUM_CTX
Definition cavsdec.c:693
#define AEC_COEFF_FRAME_LUMA
Definition cavsdec.c:683
static int aec_mv(AVSContext *h, enum cavs_mv_loc nP)
Decode a motion vector's mv_diff pair into the cache that ff_cavs_mv() reads and the next block takes...
Definition cavsdec.c:828
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
#define max(a, b)
static int16_t block[64]
Definition dct.c:125
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1814
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
#define AV_PROFILE_CAVS_BROADCASTING
Definition defs.h:223
#define AV_PROFILE_CAVS_JIZHUN
Definition defs.h:222
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
int ret
Definition ffplay.c:391
static ListView * list
Definition ffplay.c:377
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition get_bits.h:498
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static const uint8_t * align_get_bits(GetBitContext *s)
Definition get_bits.h:560
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition get_bits.h:373
exp golomb vlc stuff
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition golomb.h:239
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition golomb.h:120
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition golomb.h:53
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition avcodec.h:415
@ AV_CODEC_ID_CAVS
Definition codec_id.h:137
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition utils.c:53
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:702
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition frame.h:707
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition frame.c:526
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:281
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define ff_ctz
Definition intmath.h:105
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition mem.c:661
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
int a
#define r
Definition input.c:42
#define b
Definition input.c:43
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
unsigned offset
Definition libaomenc.c:763
static const int8_t mv[256][2]
Definition 4xm.c:81
static int shift(int a, int b)
Definition bonk.c:261
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
static const int factor[16]
Definition vf_pp7.c:98
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const uint16_t mask[17]
Definition lzw.c:38
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
#define FF_SIGNBIT(x)
Definition mathops.h:132
Memory handling functions.
MPEG-1/2 tables.
const AVRational ff_mpeg12_frame_rate_tab[]
static void frame_start(MPVMainEncContext *const m)
int profile
Definition mxfenc.c:2300
const AVProfile ff_cavs_profiles[]
Definition profiles.c:70
bitstream writer API
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition put_bits.h:62
static int put_bits_count(PutBitContext *s)
Definition put_bits.h:90
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition put_bits.h:153
static int put_bytes_output(const PutBitContext *s)
Definition put_bits.h:99
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition put_bits.h:445
static int even(int64_t layout)
Definition rematrix.c:93
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
Definition siprdata.h:259
unsigned int pos
Definition spdifenc.c:431
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
main external API structure.
Definition avcodec.h:443
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This structure stores compressed data.
Definition packet.h:587
int size
Definition packet.h:611
uint8_t * data
Definition packet.h:610
const uint8_t * buffer
Definition get_bits.h:110
int16_t x
Definition cavs.h:153
int16_t y
Definition cavs.h:154
int16_t dist
Definition cavs.h:155
int16_t ref_idx
mb_reference_index of the block, 0 when it codes none (clause 9.4.5); ref above is where the referenc...
Definition cavs.h:161
int16_t ref
Definition cavs.h:156
Definition swscale.c:82
uint8_t run
Definition svq3.c:207
uint8_t level
Definition svq3.c:208
#define stride
#define av_mallocz(s)
#define avpriv_request_sample(...)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
int size
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
static double b1(void *priv, double x, double y)
Definition vf_xfade.c:2041
static double b0(void *priv, double x, double y)
Definition vf_xfade.c:2040
float delta
uint8_t base
Definition vp3data.h:128