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 first start code prefix at or after @p offset,
1083 * or near the end of the buffer when there is none.
1084 * @return 1 if a start code prefix was found
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 = offset;
1092
1093 for (; i + 2 < size; i++)
1094 if (!buf[i] && !buf[i + 1] && buf[i + 2] == 1 &&
1096 break;
1097 if (init_get_bits8(gb, buf, size) >= 0)
1098 skip_bits_long(gb, i * 8);
1099 return i + 2 < size;
1100}
1101
1102/**
1103 * Position the reader on the start code that ends an AEC slice: the first
1104 * one at or after the slice's own payload. The reader position is not
1105 * reliable: the arithmetic decoder's look ahead has run past it.
1106 */
1108{
1109 /* release gb; check_for_slice() waits for this */
1110 h->aec.gb = NULL;
1111
1112 seek_to_start_code(h, h->aec_start);
1113}
1114
1115/**
1116 * Read mb_qp_delta when the macroblock has coefficients and the picture's qp
1117 * is not fixed, and keep PreviousDeltaQP for the AEC contexts (clause 9.4.8).
1118 */
1120{
1121 int delta = 0;
1122
1123 if (h->cbp && !h->qp_fixed) {
1124 if (h->aec_enable) {
1125 int ret = aec_mb_qp_delta(h, &delta);
1126 if (ret < 0)
1127 return ret;
1128 } else {
1129 delta = get_se_golomb(&h->gb);
1130 }
1131 h->qp = (h->qp + (unsigned)delta) & 63;
1132 }
1133 h->prev_delta_qp = delta;
1134 return 0;
1135}
1136
1137/** Decode one 8x8 block's residual with the picture's entropy coder. */
1138static int decode_residual(AVSContext *h, const struct dec_2dvlc *r,
1139 int esc_golomb_order, int chroma, int qp,
1140 uint8_t *dst, ptrdiff_t stride)
1141{
1142 if (h->aec_enable)
1144 return decode_residual_block(h, &h->gb, r, esc_golomb_order, qp, dst,
1145 stride);
1146}
1147
1149{
1150 const int qp = ff_cavs_chroma_qp[h->qp];
1151 int ret;
1152
1153 if (h->cbp & (1 << 4)) {
1154 ret = decode_residual(h, chroma_dec, 0, 1, qp, h->cu, h->c_stride);
1155 if (ret < 0)
1156 return ret;
1157 }
1158 if (h->cbp & (1 << 5)) {
1159 ret = decode_residual(h, chroma_dec, 0, 1, qp, h->cv, h->c_stride);
1160 if (ret < 0)
1161 return ret;
1162 }
1163 return 0;
1164}
1165
1167{
1168 int block, ret;
1169
1170 if (h->aec_enable) {
1171 h->cbp = aec_cbp(h);
1172 } else {
1173 /* get coded block pattern */
1174 int cbp = get_ue_golomb(&h->gb);
1175 if (cbp > 63U) {
1176 av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
1177 return AVERROR_INVALIDDATA;
1178 }
1179 h->cbp = cbp_tab[cbp][1];
1180 }
1182 if (ret < 0)
1183 return ret;
1184 for (block = 0; block < 4; block++)
1185 if (h->cbp & (1 << block)) {
1186 ret = decode_residual(h, inter_dec, 0, 0, h->qp,
1187 h->cy + h->luma_scan[block], h->l_stride);
1188 if (ret < 0)
1189 return ret;
1190 }
1191
1192 return decode_residual_chroma(h);
1193}
1194
1195/*****************************************************************************
1196 *
1197 * macroblock level
1198 *
1199 ****************************************************************************/
1200
1201static inline void set_mv_intra(AVSContext *h)
1202{
1203 h->mv[MV_FWD_X0] = CAVS_INTRA_MV;
1204 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
1205 h->mv[MV_BWD_X0] = CAVS_INTRA_MV;
1206 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
1207 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
1208 h->col_type_base[h->mbidx] = I_8X8;
1209}
1210
1211static int decode_mb_i(AVSContext *h, int cbp_code)
1212{
1213 GetBitContext *gb = &h->gb;
1214 unsigned pred_mode_uv;
1215 int block;
1216 uint8_t top[18];
1217 uint8_t *left = NULL;
1218 uint8_t *d;
1219 int ret;
1220
1222 h->left_mb_type = I_8X8;
1223 h->top_mb_type[h->mbx] = I_8X8;
1224
1225 /* get intra prediction modes from stream */
1226 for (block = 0; block < 4; block++) {
1227 int nA, nB, predpred;
1228 int pos = scan3x3[block];
1229
1230 nA = h->pred_mode_Y[pos - 1];
1231 nB = h->pred_mode_Y[pos - 3];
1232 predpred = FFMIN(nA, nB);
1233 if (predpred == NOT_AVAIL) // if either is not available
1234 predpred = INTRA_L_LP;
1235 if (h->aec_enable) {
1236 predpred = aec_intra_luma_pred_mode(h, predpred);
1237 } else if (!get_bits1(gb)) {
1238 int rem_mode = get_bits(gb, 2);
1239 predpred = rem_mode + (rem_mode >= predpred);
1240 }
1241 h->pred_mode_Y[pos] = predpred;
1242 }
1243 if (h->aec_enable) {
1244 pred_mode_uv = aec_intra_chroma_pred_mode(h);
1245 } else {
1246 pred_mode_uv = get_ue_golomb_31(gb);
1247 if (pred_mode_uv > 6) {
1248 av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
1249 return AVERROR_INVALIDDATA;
1250 }
1251 }
1252 ff_cavs_modify_mb_i(h, &pred_mode_uv);
1253
1254 /* get coded block pattern */
1255 if (h->aec_enable) {
1256 /* under AEC an intra MB codes cbp too (table 26, clause 9.4.7) */
1257 h->cbp = aec_cbp(h);
1258 } else {
1259 /* an I picture's second field codes cbp in mb_type (9.4.2 a) 2)) */
1260 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I && !h->field)
1261 cbp_code = get_ue_golomb(gb);
1262 if (cbp_code > 63U) {
1263 av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
1264 return AVERROR_INVALIDDATA;
1265 }
1266 h->cbp = cbp_tab[cbp_code][0];
1267 }
1269 if (ret < 0)
1270 return ret;
1271
1272 /* luma intra prediction interleaved with residual decode/transform/add */
1273 for (block = 0; block < 4; block++) {
1274 d = h->cy + h->luma_scan[block];
1276 h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
1277 (d, top, left, h->l_stride);
1278 if (h->cbp & (1<<block)) {
1279 ret = decode_residual(h, intra_dec, 1, 0, h->qp, d, h->l_stride);
1280 if (ret < 0)
1281 return ret;
1282 }
1283 }
1284
1285 /* chroma intra prediction */
1287 h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx * 10],
1288 h->left_border_u, h->c_stride);
1289 h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx * 10],
1290 h->left_border_v, h->c_stride);
1291
1293 if (ret < 0)
1294 return ret;
1296 set_mv_intra(h);
1297 return 0;
1298}
1299
1301{
1302 if (h->stream_revision > 0) {
1303 h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
1304 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = NOT_AVAIL;
1305 } else {
1306 h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
1307 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = INTRA_L_LP;
1308 }
1309}
1310
1311/**
1312 * Read one mb_reference_index and turn it into a reference list index
1313 * (table 26, clauses 7.2.5 and 9.4.5). Table 26 misprints the presence
1314 * predicate's brackets; GB/T 20090.2-2013 table 27 and IEEE 1857-2023
1315 * clause 7.1.5 both print it as implemented here.
1316 */
1318{
1319 const int base = h->ref_base[list];
1320 /* NumberOfReference of one direction, clause 9.4.5 figures 15 to 20 */
1321 const int max = !h->pic_structure &&
1322 h->cur.f->pict_type == AV_PICTURE_TYPE_P ? 3 : 1;
1323 int idx = 0;
1324
1325 if (!h->ref_flag &&
1326 (h->cur.f->pict_type == AV_PICTURE_TYPE_P ||
1327 (h->cur.f->pict_type == AV_PICTURE_TYPE_B && !h->pic_structure))) {
1328 if (h->aec_enable) {
1329 /* a and b of 8.4.4.2 f); unavailable, intra and derived
1330 * neighbours carry index 0 */
1331 int a = h->mv[nP - 1].ref_idx > 0;
1332 int b = h->mv[nP - 4].ref_idx > 0;
1333
1334 idx = aec_ref_index(h, a + 2 * b, max);
1335 if (idx < 0)
1336 return idx;
1337 } else {
1338 idx = get_bits(&h->gb, max > 1 ? 2 : 1);
1339 }
1340 }
1341 h->mv[nP].ref = base + idx;
1342 h->mv[nP].ref_idx = idx;
1343 return base + idx;
1344}
1345
1346/**
1347 * Decode one motion vector: under AEC its mv_diff must be read before
1348 * ff_cavs_mv() overwrites the cache its context comes from.
1349 */
1350static int decode_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
1351 enum cavs_mv_pred mode, enum cavs_block size, int ref)
1352{
1353 if (h->aec_enable && mode < MV_PRED_PSKIP) {
1354 int ret = aec_mv(h, nP);
1355 if (ret < 0)
1356 return ret;
1357 }
1358 ff_cavs_mv(h, nP, nC, mode, size, ref);
1359 return 0;
1360}
1361
1362/* what the AEC contexts of later macroblocks read about this one (8.4.4.2) */
1363static void set_inter_mb_ctx(AVSContext *h, enum cavs_mb mb_type, int skip)
1364{
1365 h->left_mb_type = mb_type;
1366 h->top_mb_type[h->mbx] = mb_type;
1367 h->left_c_pred_mode = INTRA_C_LP;
1368 h->top_c_pred_mode[h->mbx] = INTRA_C_LP;
1369 if (skip) {
1370 h->left_cbp = 0;
1371 h->top_cbp[h->mbx] = 0;
1372 h->prev_delta_qp = 0;
1373 }
1374}
1375
1376#define MV(nP, nC, mode, size, ref) \
1377 do { \
1378 ret = decode_mv(h, nP, nC, mode, size, ref); \
1379 if (ret < 0) \
1380 return ret; \
1381 } while (0)
1382
1383#define REF(dst, list, nP) \
1384 do { \
1385 ret = decode_ref_index(h, list, nP); \
1386 if (ret < 0) \
1387 return ret; \
1388 dst = ret; \
1389 } while (0)
1390
1391static int decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
1392{
1393 int ref[4];
1394 int ret;
1395
1397 set_inter_mb_ctx(h, mb_type, mb_type == P_SKIP);
1398 switch (mb_type) {
1399 case P_SKIP:
1400 /* PFieldSkip predicts from the reference marked 1, the same
1401 * parity field of the previous frame (9.9.1 a) 1))
1402 */
1404 h->ref_base[0] + h->p_field_skip);
1405 break;
1406 case P_16X16:
1407 REF(ref[0], 0, MV_FWD_X0);
1409 break;
1410 case P_16X8:
1411 REF(ref[0], 0, MV_FWD_X0);
1412 REF(ref[2], 0, MV_FWD_X2);
1415 break;
1416 case P_8X16:
1417 REF(ref[0], 0, MV_FWD_X0);
1418 REF(ref[1], 0, MV_FWD_X1);
1421 break;
1422 case P_8X8:
1423 REF(ref[0], 0, MV_FWD_X0);
1424 REF(ref[1], 0, MV_FWD_X1);
1425 REF(ref[2], 0, MV_FWD_X2);
1426 REF(ref[3], 0, MV_FWD_X3);
1431 break;
1432 default:
1433 av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in P frame\n",
1434 mb_type);
1435 return AVERROR_INVALIDDATA;
1436 }
1437 ff_cavs_inter(h, mb_type);
1439 store_mvs(h);
1440 if (mb_type != P_SKIP) {
1442 if (ret < 0)
1443 return ret;
1444 }
1445 ff_cavs_filter(h, mb_type);
1446 h->col_type_base[h->mbidx] = mb_type;
1447 return 0;
1448}
1449
1450static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
1451{
1452 int block;
1453 enum cavs_sub_mb sub_type[4];
1454 int flags;
1455 int ref[2][4];
1456 int ret;
1457 /* the co-located macroblock of an enhanced second field is the one at
1458 * the same position in the first field (clause 9.9.1 b) 1)) */
1459 int col = h->mbidx - (h->b_field_enhanced && h->field ?
1460 h->mb_width * h->mb_height / 2 : 0);
1461
1463 set_inter_mb_ctx(h, mb_type, mb_type == B_SKIP);
1464
1465 /* reset all MVs */
1466 h->mv[MV_FWD_X0] = CAVS_DIR_MV;
1467 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
1468 h->mv[MV_BWD_X0] = CAVS_DIR_MV;
1469 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
1470 switch (mb_type) {
1471 case B_SKIP:
1472 case B_DIRECT:
1473 if (!h->col_type_base[col]) {
1474 /* intra MB at co-location: in-plane prediction (9.9.1 b) 1)) */
1476 h->ref_base[0]);
1478 h->ref_base[1]);
1479 } else
1480 /* direct prediction from co-located P MB, block-wise */
1481 for (block = 0; block < 4; block++)
1482 mv_pred_direct(h, &h->mv[mv_scan[block]],
1483 &h->col_mv[col * 4 + block]);
1484 break;
1485 case B_FWD_16X16:
1486 REF(ref[0][0], 0, MV_FWD_X0);
1488 break;
1489 case B_SYM_16X16:
1490 REF(ref[0][0], 0, MV_FWD_X0);
1493 break;
1494 case B_BWD_16X16:
1495 REF(ref[1][0], 1, MV_BWD_X0);
1497 break;
1498 case B_8X8:
1499#define TMP_UNUSED_INX 7
1500 flags = 0;
1501 for (block = 0; block < 4; block++) {
1502 if (h->aec_enable)
1503 sub_type[block] = aec_mb_part_type(h);
1504 else
1505 sub_type[block] = get_bits(&h->gb, 2);
1506 }
1507 /* all forward reference indices come first (table 26) */
1508 for (block = 0; block < 4; block++)
1509 if (sub_type[block] == B_SUB_FWD || sub_type[block] == B_SUB_SYM)
1510 REF(ref[0][block], 0, mv_scan[block]);
1511 for (block = 0; block < 4; block++)
1512 if (sub_type[block] == B_SUB_BWD)
1513 REF(ref[1][block], 1, mv_scan[block] + MV_BWD_OFFS);
1514 for (block = 0; block < 4; block++) {
1515 switch (sub_type[block]) {
1516 case B_SUB_DIRECT:
1517 if (!h->col_type_base[col]) {
1518 /* intra MB at co-location, do in-plane prediction */
1519 if(flags==0) {
1520 // if col-MB is a Intra MB, current Block size is 16x16.
1521 // AVS standard section 9.9.1
1522 if(block>0){
1523 h->mv[TMP_UNUSED_INX ] = h->mv[MV_FWD_X0 ];
1525 }
1527 MV_PRED_BSKIP, BLK_8X8, h->ref_base[0]);
1530 MV_PRED_BSKIP, BLK_8X8, h->ref_base[1]);
1531 if(block>0) {
1532 flags = mv_scan[block];
1533 h->mv[flags ] = h->mv[MV_FWD_X0 ];
1534 h->mv[flags + MV_BWD_OFFS] = h->mv[MV_FWD_X0 + MV_BWD_OFFS];
1535 h->mv[MV_FWD_X0 ] = h->mv[TMP_UNUSED_INX ];
1537 } else
1538 flags = MV_FWD_X0;
1539 } else {
1540 h->mv[mv_scan[block] ] = h->mv[flags ];
1541 h->mv[mv_scan[block] + MV_BWD_OFFS] = h->mv[flags + MV_BWD_OFFS];
1542 }
1543 } else
1544 mv_pred_direct(h, &h->mv[mv_scan[block]],
1545 &h->col_mv[col * 4 + block]);
1546 break;
1547 case B_SUB_FWD:
1548 MV(mv_scan[block], mv_scan[block] - 3,
1550 break;
1551 case B_SUB_SYM:
1552 MV(mv_scan[block], mv_scan[block] - 3,
1554 mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
1555 break;
1556 }
1557 }
1558#undef TMP_UNUSED_INX
1559 for (block = 0; block < 4; block++) {
1560 if (sub_type[block] == B_SUB_BWD)
1562 mv_scan[block] + MV_BWD_OFFS - 3,
1564 }
1565 break;
1566 default:
1567 if (mb_type <= B_SYM_16X16) {
1568 av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
1569 return AVERROR_INVALIDDATA;
1570 }
1571 av_assert2(mb_type < B_8X8);
1572 flags = ff_cavs_partition_flags[mb_type];
1573 if (mb_type & 1) { /* 16x8 macroblock types */
1574 if (flags & FWD0)
1575 REF(ref[0][0], 0, MV_FWD_X0);
1576 if (flags & FWD1)
1577 REF(ref[0][2], 0, MV_FWD_X2);
1578 if (flags & BWD0)
1579 REF(ref[1][0], 1, MV_BWD_X0);
1580 if (flags & BWD1)
1581 REF(ref[1][2], 1, MV_BWD_X2);
1582 if (flags & FWD0)
1584 if (flags & SYM0)
1585 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
1586 if (flags & FWD1)
1588 if (flags & SYM1)
1589 mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
1590 if (flags & BWD0)
1592 if (flags & BWD1)
1594 } else { /* 8x16 macroblock types */
1595 if (flags & FWD0)
1596 REF(ref[0][0], 0, MV_FWD_X0);
1597 if (flags & FWD1)
1598 REF(ref[0][1], 0, MV_FWD_X1);
1599 if (flags & BWD0)
1600 REF(ref[1][0], 1, MV_BWD_X0);
1601 if (flags & BWD1)
1602 REF(ref[1][1], 1, MV_BWD_X1);
1603 if (flags & FWD0)
1605 if (flags & SYM0)
1606 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
1607 if (flags & FWD1)
1609 if (flags & SYM1)
1610 mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
1611 if (flags & BWD0)
1613 if (flags & BWD1)
1615 }
1616 }
1617 ff_cavs_inter(h, mb_type);
1619 if (mb_type != B_SKIP) {
1621 if (ret < 0)
1622 return ret;
1623 }
1624 ff_cavs_filter(h, mb_type);
1625
1626 return 0;
1627}
1628
1629#undef MV
1630#undef REF
1631
1632/**
1633 * Decode one macroblock of a P or B coded macroblock layer, table 25.
1634 * @param skip_count what is left of the current mb_skip_run, or -1 when the
1635 * next macroblock position starts a new one
1636 */
1637static int decode_mb_pb_layer(AVSContext *h, int *skip_count)
1638{
1639 const int b = h->cur.f->pict_type == AV_PICTURE_TYPE_B;
1640 const enum cavs_mb skip = b ? B_SKIP : P_SKIP;
1641 const enum cavs_mb last = b ? B_8X8 : P_8X8;
1642 enum cavs_mb mb_type;
1643 int skipped, ret;
1644
1645 if (h->skip_mode_flag && *skip_count < 0) {
1646 if (h->aec_enable) {
1647 *skip_count = aec_mb_skip_run(h);
1648 } else {
1649 if (get_bits_left(&h->gb) < 1)
1650 return AVERROR_INVALIDDATA;
1651 *skip_count = get_ue_golomb(&h->gb);
1652 }
1653 if (*skip_count < 0)
1654 return AVERROR_INVALIDDATA;
1655 }
1656 skipped = h->skip_mode_flag && (*skip_count)--;
1657 if (skipped) {
1658 mb_type = skip;
1659 } else if (h->aec_enable) {
1661 if (ret < 0)
1662 return ret;
1663 mb_type = ret + skip;
1664 } else {
1665 if (get_bits_left(&h->gb) < 1)
1666 return AVERROR_INVALIDDATA;
1667 mb_type = get_ue_golomb(&h->gb) + skip + h->skip_mode_flag;
1668 }
1669 if (mb_type > last)
1670 ret = decode_mb_i(h, mb_type - last - 1);
1671 else
1672 ret = b ? decode_mb_b(h, mb_type) : decode_mb_p(h, mb_type);
1673 if (ret < 0)
1674 return ret;
1675 /* the stuffing bit follows a coded MB and the last one of a skip run */
1676 if (h->aec_enable && (!skipped || !*skip_count) &&
1679 return 0;
1680}
1681
1682/*****************************************************************************
1683 *
1684 * slice level
1685 *
1686 ****************************************************************************/
1687
1689{
1690 int mby = h->stc;
1691
1692 /* over 2800 lines MbRow carries high bits here (clause 7.2.4) */
1693 if (h->height > 2800)
1694 mby += get_bits(gb, 3) << 7; //slice_vertical_position_extension
1695
1696 if (mby >= h->mb_height) {
1697 av_log(h->avctx, AV_LOG_ERROR, "MbRow %d is too large\n", mby);
1698 return AVERROR_INVALIDDATA;
1699 }
1700
1701 h->mby = mby;
1702 h->mbidx = h->mby * h->mb_width;
1703 /* the second field's first slice jumps to MbHeight / 2 (clause 3.24) */
1705
1706 /* mark top macroblocks as unavailable */
1707 h->flags &= ~(B_AVAIL | C_AVAIL);
1708 if (!h->pic_qp_fixed) {
1709 h->qp_fixed = get_bits1(gb);
1710 h->qp = get_bits(gb, 6);
1711 }
1712 /* inter frame or second slice can have weighting params */
1713 if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
1714 (!h->pic_structure && h->mbidx >= h->mb_width * h->mb_height / 2))
1715 if (get_bits1(gb)) { //slice_weighting_flag
1716 avpriv_request_sample(h->avctx, "Weighted prediction");
1717 return AVERROR_PATCHWELCOME;
1718 }
1719 return 0;
1720}
1721
1722static inline int check_for_slice(AVSContext *h)
1723{
1724 GetBitContext *gb = &h->gb;
1725 int align;
1726 int ret;
1727
1728 if (h->mbx)
1729 return 0;
1730 /* an AEC slice ends with its stuffing bit, not at a start code (7.2.4) */
1731 if (h->aec_enable && h->aec.gb)
1732 return 0;
1733 for (;;) {
1735 int stc;
1736
1737 align = (-get_bits_count(gb)) & 7;
1738 /* check for stuffing byte */
1739 if (!align && (show_bits(gb, 8) == 0x80))
1740 align = 8;
1741 if ((show_bits_long(gb, 24 + align) & 0xFFFFFF) != 0x000001)
1742 return 0;
1743 if (!is_start_code_offset(h, (get_bits_count(gb) + align) >> 3))
1744 return 0;
1745 peek = *gb;
1746 skip_bits_long(&peek, 24 + align);
1747 stc = get_bits(&peek, 8);
1748 if (stc > (SLICE_MAX_START_CODE & 0xFF)) {
1749 /* video_sequence() places extension_and_user_data(1) between
1750 * the picture header and picture_data() (table 13)
1751 */
1752 if (stc != (USER_START_CODE & 0xFF) &&
1753 stc != (EXT_START_CODE & 0xFF)) {
1754 /* any other unit ends the picture's data; leave it to the
1755 * caller */
1756 h->pic_data_end = 1;
1757 return 0;
1758 }
1759 if (!seek_to_start_code(h, get_bits_count(&peek) >> 3)) {
1760 h->pic_data_end = 1;
1761 return 0;
1762 }
1763 continue;
1764 }
1765 *gb = peek;
1766 h->stc = stc;
1767 ret = decode_slice_header(h, gb);
1768 if (ret < 0)
1769 return ret;
1770 if (h->aec_enable) {
1771 /* aec_byte_alignment_bit padding, then 8.4.1 */
1772 align_get_bits(gb);
1773 h->aec_start = get_bits_count(gb) >> 3;
1774 ff_cavs_aec_init(&h->aec, gb);
1775 h->prev_delta_qp = 0; /* reset with PreviousQP, clause 9.3 */
1776 }
1777 return 1;
1778 }
1779}
1780
1781/*****************************************************************************
1782 *
1783 * frame level
1784 *
1785 ****************************************************************************/
1786
1787/**
1788 * Build the reference list and the temporal distances of the current frame
1789 * or field (clause 9.4.5 figures 14 to 20, clause 9.4.6.1).
1790 */
1792{
1793 /* the first coded field is the first displayed one (clause 7.2.3.1),
1794 * and annex B.2 keeps top_field_first constant over the sequence */
1795 const int f1 = !h->top_field_first; /* parity of a first field */
1796 const int f2 = h->top_field_first; /* parity of a second field */
1797 const int b = h->cur.f->pict_type == AV_PICTURE_TYPE_B;
1798 const int poc = h->cur.poc;
1799 const int poc0 = h->DPB[0].poc;
1800 const int poc1 = h->DPB[1].poc;
1801 int nref;
1802
1803#define SET_REF(idx, frame, par, distance) \
1804 do { \
1805 h->ref[idx].f = (frame); \
1806 h->ref[idx].parity = (par); \
1807 h->dist[idx] = (distance) & 511; \
1808 } while (0)
1809
1810 h->ref_base[0] = h->ref_base[1] = 0;
1811
1812 if (h->pic_structure) {
1813 /* figures 15 and 18: whole frames, most recent first */
1814 SET_REF(0, h->DPB[0].f, 0, b ? poc0 - poc : poc - poc0);
1815 for (int i = 1; i < FF_ARRAY_ELEMS(h->ref); i++)
1816 SET_REF(i, h->DPB[1].f, 0, poc - poc1);
1817 /* figure 18: a B frame codes no reference index */
1818 h->ref_base[0] = b;
1819 nref = 1;
1820 } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1821 /* figure 14: the second field references its own first field */
1822 for (int i = 0; i < FF_ARRAY_ELEMS(h->ref); i++)
1823 SET_REF(i, h->cur.f, f1, 1);
1824 nref = 1;
1825 } else if (!b) {
1826 if (!h->field) {
1827 /* figure 16: the four fields of the two previous frames */
1828 SET_REF(0, h->DPB[0].f, f2, poc - poc0 - 1);
1829 SET_REF(1, h->DPB[0].f, f1, poc - poc0);
1830 SET_REF(2, h->DPB[1].f, f2, poc - poc1 - 1);
1831 SET_REF(3, h->DPB[1].f, f1, poc - poc1);
1832 } else {
1833 /* figure 17: this picture's first field, then the three before */
1834 SET_REF(0, h->cur.f, f1, 1);
1835 SET_REF(1, h->DPB[0].f, f2, poc - poc0);
1836 SET_REF(2, h->DPB[0].f, f1, poc - poc0 + 1);
1837 SET_REF(3, h->DPB[1].f, f2, poc - poc1);
1838 }
1839 nref = 4;
1840 } else {
1841 /* figures 19 and 20: two backward and two forward fields */
1842 SET_REF(0, h->DPB[0].f, f1, poc0 - poc - h->field);
1843 SET_REF(1, h->DPB[0].f, f2, poc0 + 1 - poc - h->field);
1844 SET_REF(2, h->DPB[1].f, f2, poc + h->field - poc1 - 1);
1845 SET_REF(3, h->DPB[1].f, f1, poc + h->field - poc1);
1846 h->ref_base[0] = 2;
1847 nref = 2;
1848 }
1849#undef SET_REF
1850
1851 for (int i = 0; i < FF_ARRAY_ELEMS(h->ref); i++)
1852 h->scale_den[i] = h->dist[i] ? 512 / h->dist[i] : 0;
1853
1854 for (int i = 0; b && i < nref; i++) {
1855 int fw = h->ref_base[0] + i;
1856 int bw = h->pic_structure ? h->ref_base[1]
1857 : h->ref_base[1] + 1 - i;
1858 int factor = h->dist[bw] * h->scale_den[fw];
1859
1860 if (factor > 32768) {
1861 av_log(h->avctx, AV_LOG_ERROR,
1862 "symmetric scaling factor %d too large\n", factor);
1863 return AVERROR_INVALIDDATA;
1864 }
1865 }
1866 return 0;
1867}
1868
1870{
1871 int ret;
1872 int field;
1873 int skip_count = -1;
1874 int pb_field_enhanced_flag = 0;
1875
1876 if (!h->top_qp) {
1877 av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
1878 return AVERROR_INVALIDDATA;
1879 }
1880
1881 av_frame_unref(h->cur.f);
1882
1883 skip_bits(&h->gb, 16);//bbv_delay
1884 if (h->profile == AV_PROFILE_CAVS_BROADCASTING)
1885 skip_bits(&h->gb, 8); //marker_bit, bbv_delay_extension (tables 21, 22)
1886 if (h->stc == PIC_PB_START_CODE) {
1887 h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
1888 if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
1889 av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
1890 return AVERROR_INVALIDDATA;
1891 }
1892 /* make sure we have the reference frames we need */
1893 if (!h->DPB[0].f->data[0] ||
1894 (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
1895 return AVERROR_INVALIDDATA;
1896 } else {
1897 h->cur.f->pict_type = AV_PICTURE_TYPE_I;
1898 if (get_bits1(&h->gb))
1899 skip_bits(&h->gb, 24);//time_code
1900 /* a Broadcasting stream always has the marker bit (table 21); old
1901 JiZhun sample clips were all progressive and no low_delay, bump
1902 stream revision if detected otherwise */
1903 if (h->profile == AV_PROFILE_CAVS_BROADCASTING)
1904 h->stream_revision = 1;
1905 else if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
1906 h->stream_revision = 1;
1907 /* similarly test top_field_first and repeat_first_field */
1908 else if (show_bits(&h->gb, 11) & 3)
1909 h->stream_revision = 1;
1910 if (h->stream_revision > 0)
1911 skip_bits(&h->gb, 1); //marker_bit
1912 }
1913
1914 if (get_bits_left(&h->gb) < 23)
1915 return AVERROR_INVALIDDATA;
1916
1917 ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
1919 if (ret < 0)
1920 return ret;
1921
1922 if (!h->edge_emu_buffer) {
1923 int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
1924 h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
1925 if (!h->edge_emu_buffer)
1926 return AVERROR(ENOMEM);
1927 }
1928
1929 /* picture_distance; DistanceIndex is twice it (clause 9.4.6.1) */
1930 h->cur.poc = get_bits(&h->gb, 8) * 2;
1931
1932 if (h->low_delay)
1933 get_ue_golomb(&h->gb); //bbv_check_times
1934 h->progressive = get_bits1(&h->gb);
1935 h->pic_structure = 1;
1936 if (!h->progressive)
1937 h->pic_structure = get_bits1(&h->gb);
1938 /* clause 7.2.3: a progressive sequence has frame pictures only; its odd
1939 * MbHeight would also let a field picture write past coded_height */
1940 if (!h->pic_structure && h->progressive_seq) {
1941 av_log(h->avctx, AV_LOG_ERROR,
1942 "field picture in a progressive sequence\n");
1943 return AVERROR_INVALIDDATA;
1944 }
1945 /* a field coded picture uses inverse block scan method 2 (9.5.3 c)) */
1946 h->scantable = h->pic_structure ? h->permutated_scantable
1947 : h->permutated_scantable_field;
1948 if (!h->pic_structure && h->stc == PIC_PB_START_CODE)
1949 skip_bits1(&h->gb); //advanced_pred_mode_disable
1950 h->top_field_first = get_bits1(&h->gb);
1951 skip_bits1(&h->gb); //repeat_first_field
1952 h->pic_qp_fixed =
1953 h->qp_fixed = get_bits1(&h->gb);
1954 h->qp = get_bits(&h->gb, 6);
1955 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1956 /* only a field coded intra picture has skip_mode_flag (table 21) */
1957 h->skip_mode_flag = 0;
1958 if (!h->progressive && !h->pic_structure)
1959 h->skip_mode_flag = get_bits1(&h->gb);
1960 skip_bits(&h->gb, 4); //reserved bits
1961 } else {
1962 if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
1963 h->ref_flag = get_bits1(&h->gb);
1964 else
1965 /* 1 for a frame coded B picture (clause 7.2.3.2) */
1966 h->ref_flag = 1;
1967 /* no_forward_reference_flag, pb_field_enhanced_flag, r(2); table 22.
1968 * JiZhun has reserved bits here and must ignore them (clause 5.4) */
1969 skip_bits1(&h->gb);
1970 pb_field_enhanced_flag = get_bits1(&h->gb) &&
1971 h->profile == AV_PROFILE_CAVS_BROADCASTING;
1972 skip_bits(&h->gb, 2);
1973 h->skip_mode_flag = get_bits1(&h->gb);
1974 }
1975 h->loop_filter_disable = get_bits1(&h->gb);
1976 if (!h->loop_filter_disable && get_bits1(&h->gb)) {
1977 h->alpha_offset = get_se_golomb(&h->gb);
1978 h->beta_offset = get_se_golomb(&h->gb);
1979 if ( h->alpha_offset < -64 || h->alpha_offset > 64
1980 || h-> beta_offset < -64 || h-> beta_offset > 64) {
1981 h->alpha_offset = h->beta_offset = 0;
1982 return AVERROR_INVALIDDATA;
1983 }
1984 } else {
1985 h->alpha_offset = h->beta_offset = 0;
1986 }
1987
1988 /* AWQ parameters and aec_enable end the header (tables 21, 22) */
1989 h->aec_enable = 0;
1990 if (h->profile == AV_PROFILE_CAVS_BROADCASTING) {
1991 if (get_bits1(&h->gb)) { //weighting_quant_flag
1992 avpriv_request_sample(h->avctx, "Adaptive weighted quantization");
1993 return AVERROR_PATCHWELCOME;
1994 }
1995 h->aec_enable = get_bits1(&h->gb);
1996 }
1997
1998 /* in a frame picture the field derivations reduce to the frame ones
1999 * (9.9.1 b) 3)) */
2000 h->b_field_enhanced = pb_field_enhanced_flag && !h->pic_structure &&
2001 h->cur.f->pict_type == AV_PICTURE_TYPE_B;
2002 h->p_field_skip = pb_field_enhanced_flag && !h->pic_structure &&
2003 h->cur.f->pict_type == AV_PICTURE_TYPE_P;
2004
2005 if (!h->progressive) {
2006 h->cur.f->flags |= AV_FRAME_FLAG_INTERLACED;
2007 if (h->top_field_first)
2008 h->cur.f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
2009 }
2010
2011 /* needs picture_structure, so only after the whole header */
2012 if ((ret = ff_cavs_init_pic(h)) < 0)
2013 return ret;
2014 if ((ret = set_ref_list(h)) < 0)
2015 return ret;
2016
2017 field = h->field;
2018 ret = 0;
2019 h->aec.gb = NULL; /* started by the first slice header */
2020 h->pic_data_end = 0;
2021 do {
2023 if (ret < 0)
2024 break;
2025 if (ret)
2026 skip_count = -1;
2027 if (h->aec_enable && !h->aec.gb) {
2028 av_log(h->avctx, AV_LOG_ERROR,
2029 "AEC picture without a slice header\n");
2031 break;
2032 }
2033 /* past the picture's data, only a pending skip run can code MBs */
2034 if (h->pic_data_end && !(h->skip_mode_flag && skip_count > 0)) {
2035 av_log(h->avctx, AV_LOG_ERROR, "picture data ended before MB %d\n",
2036 h->mbidx);
2038 break;
2039 }
2040 if (h->field != field) {
2041 field = h->field;
2042 if ((ret = set_ref_list(h)) < 0)
2043 break;
2044 }
2045 if (h->cur.f->pict_type != AV_PICTURE_TYPE_I || h->field) {
2046 /* an intra picture's second field is inter coded (9.4.2 a) 2)) */
2047 ret = decode_mb_pb_layer(h, &skip_count);
2048 } else {
2049 ret = decode_mb_i(h, 0);
2050 /* aec_mb_stuffing_bit is 1 on the slice's last MB (7.2.4) */
2051 if (ret >= 0 && h->aec_enable &&
2054 }
2055 if (ret < 0)
2056 break;
2057 } while (ff_cavs_next_mb(h));
2058 if (ret >= 0 && h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
2059 av_frame_unref(h->DPB[1].f);
2060 FFSWAP(AVSFrame, h->cur, h->DPB[1]);
2061 FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
2062 }
2063 return ret;
2064}
2065
2066/*****************************************************************************
2067 *
2068 * headers and interface
2069 *
2070 ****************************************************************************/
2071
2073{
2074 int frame_rate_code;
2075 int profile, level, aspect_ratio;
2076 int width, height;
2077 int mb_width, mb_height;
2078 int progressive_seq, low_delay;
2079 int chroma_format, sample_precision;
2080 int ret;
2081
2082 profile = get_bits(&h->gb, 8);
2083 /* the sequence header is the same for both profiles (table 14) */
2086 avpriv_report_missing_feature(h->avctx, "Profile %#x", profile);
2087 return AVERROR_PATCHWELCOME;
2088 }
2089 level = get_bits(&h->gb, 8);
2090 progressive_seq = get_bits1(&h->gb);
2091
2092 width = get_bits(&h->gb, 14);
2093 height = get_bits(&h->gb, 14);
2094 if ((h->width || h->height) && (h->width != width || h->height != height)) {
2096 "Width/height changing in CAVS");
2097 return AVERROR_PATCHWELCOME;
2098 }
2099 if (width <= 0 || height <= 0) {
2100 av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
2101 return AVERROR_INVALIDDATA;
2102 }
2103 chroma_format = get_bits(&h->gb, 2);
2104 sample_precision = get_bits(&h->gb, 3);
2105 /* the Broadcasting macroblock layer is written for 8 bit 4:2:0 */
2107 if (sample_precision != 1) {
2108 av_log(h->avctx, AV_LOG_ERROR,
2109 "sample_precision %d is not 8 bit\n", sample_precision);
2110 return AVERROR_INVALIDDATA;
2111 }
2112 if (chroma_format == 2) {
2113 avpriv_request_sample(h->avctx, "4:2:2 chroma");
2114 return AVERROR_PATCHWELCOME;
2115 }
2116 if (chroma_format != 1) {
2117 av_log(h->avctx, AV_LOG_ERROR,
2118 "chroma_format %d is reserved\n", chroma_format);
2119 return AVERROR_INVALIDDATA;
2120 }
2121 }
2122 aspect_ratio = get_bits(&h->gb, 4);
2123 frame_rate_code = get_bits(&h->gb, 4);
2124 if (frame_rate_code == 0 || frame_rate_code > 13) {
2125 av_log(h->avctx, AV_LOG_WARNING,
2126 "frame_rate_code %d is invalid\n", frame_rate_code);
2127 frame_rate_code = 1;
2128 }
2129
2130 skip_bits(&h->gb, 18); //bit_rate_lower
2131 skip_bits1(&h->gb); //marker_bit
2132 skip_bits(&h->gb, 12); //bit_rate_upper
2133 low_delay = get_bits1(&h->gb);
2134
2135 mb_width = (width + 15) >> 4;
2136 /* interlaced: an even number of MB rows (clause 7.2.2) */
2137 mb_height = progressive_seq ? (height + 15) >> 4
2138 : ((height + 31) >> 5) * 2;
2139 /* the grid sizes the arrays of ff_cavs_init_top_lines(), allocated once */
2140 if (h->top_qp && (mb_width != h->mb_width || mb_height != h->mb_height)) {
2141 avpriv_report_missing_feature(h->avctx, "Macroblock grid changing");
2142 return AVERROR_PATCHWELCOME;
2143 }
2144
2145 /* horizontal_size and vertical_size are only the displayed part */
2146 ret = ff_set_dimensions(h->avctx, mb_width * 16, mb_height * 16);
2147 if (ret < 0)
2148 return ret;
2149 h->avctx->width = width;
2150 h->avctx->height = height;
2151
2152 /* commit last: a rejected header must leave the decoder as it was */
2153 h->profile = profile;
2154 h->level = level;
2155 h->aspect_ratio = aspect_ratio;
2156 h->width = width;
2157 h->height = height;
2158 h->mb_width = mb_width;
2159 h->mb_height = mb_height;
2160 h->low_delay = low_delay;
2161 h->avctx->profile = profile;
2162 h->progressive_seq = progressive_seq;
2163 h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];
2164 if (!h->top_qp)
2165 return ff_cavs_init_top_lines(h);
2166 return 0;
2167}
2168
2169/** annex A applies to picture headers and slices, not to other units */
2170static int annex_a_applies(int stc)
2171{
2172 return stc <= (SLICE_MAX_START_CODE & 0xFF) ||
2173 stc == (PIC_I_START_CODE & 0xFF) ||
2174 stc == (PIC_PB_START_CODE & 0xFF);
2175}
2176
2177/**
2178 * Copy one region of a picture payload, removing the annex A pseudo start
2179 * codes; the clause 5.8.2.4 stuffing is rewritten to keep the next start
2180 * code aligned. With pb NULL they are only counted.
2181 * @return the number of pseudo start codes found
2182 */
2183static int deemulate_region(PutBitContext *pb, const uint8_t *buf, int size,
2184 int deemulated)
2185{
2186 int found = 0;
2187 int stuffing = -1;
2188 int i;
2189
2190 if (!deemulated) {
2191 for (i = 0; i < size; i++)
2192 if (pb)
2193 put_bits(pb, 8, buf[i]);
2194 return 0;
2195 }
2196
2197 /* the stuffing bit is the last set bit of the region */
2198 for (i = size; i > 0 && !buf[i - 1]; i--)
2199 ;
2200 if (i > 0) {
2201 stuffing = i - 1;
2202 size = stuffing;
2203 }
2204
2205 for (i = 0; i < size; i++) {
2206 if (i + 2 < size && !buf[i] && !buf[i + 1] && buf[i + 2] == 2) {
2207 /* drop the two low bits of the 02 */
2208 if (pb) {
2209 put_bits(pb, 16, 0);
2210 put_bits(pb, 6, 0);
2211 }
2212 found++;
2213 i += 2;
2214 } else if (pb) {
2215 put_bits(pb, 8, buf[i]);
2216 }
2217 }
2218
2219 if (pb) {
2220 if (stuffing >= 0) {
2221 int n = ff_ctz(buf[stuffing]) + 1;
2222 if (n < 8)
2223 put_bits(pb, 8 - n, buf[stuffing] >> n);
2224 put_bits(pb, 1, 1); //stuffing_bit
2225 }
2226 align_put_bits(pb); /* stuffing_bit until byte aligned */
2227 }
2228 return found;
2229}
2230
2231/**
2232 * Walk the payload region by region, removing the annex A pseudo start
2233 * codes; on the writing pass, record every start code prefix offset in
2234 * h->stc_offset.
2235 * @return the number of pseudo start codes found
2236 */
2238 const uint8_t *buf, int size)
2239{
2240 int deemulated = 1; /* buf starts inside a picture header */
2241 int found = 0;
2242 int pos = 0;
2243
2244 while (pos < size) {
2245 int end;
2246
2247 for (end = pos; end + 2 < size; end++) {
2248 /* nothing can start at end, end + 1 or end + 2 (annex A) */
2249 if (buf[end + 2] > 1) {
2250 end += 2;
2251 continue;
2252 }
2253 if (!buf[end] && !buf[end + 1] && buf[end + 2] == 1)
2254 break;
2255 }
2256 if (end + 2 >= size)
2257 end = size;
2258
2259 found += deemulate_region(pb, buf + pos, end - pos, deemulated);
2260 if (end == size)
2261 break;
2262
2263 if (pb) {
2264 h->stc_offset[h->nb_stc_offset++] = put_bits_count(pb) >> 3;
2265 put_bits(pb, 24, 1); /* start code prefix */
2266 }
2267 pos = end + 3;
2268 if (pos < size) {
2269 if (pb)
2270 put_bits(pb, 8, buf[pos]);
2271 deemulated = annex_a_applies(buf[pos]);
2272 pos++;
2273 }
2274 }
2275 return found;
2276}
2277
2278/**
2279 * Remove the annex A pseudo start codes from a payload: a byte forming
2280 * 00 00 02 with the two before it loses its two least significant bits. buf
2281 * runs from just after a picture start code to the packet end.
2282 * @return the size of h->deemulated_buf, 0 if buf needs no copy, or < 0
2283 */
2284static int remove_pseudo_start_codes(AVSContext *h, const uint8_t *buf,
2285 int size)
2286{
2287 PutBitContext pb;
2288
2289 if (size <= 0 || size > INT_MAX / 8 ||
2290 !deemulate_picture(h, NULL, buf, size))
2291 return 0;
2292
2293 av_fast_padded_malloc(&h->deemulated_buf, &h->deemulated_buf_size, size);
2294 if (!h->deemulated_buf)
2295 return AVERROR(ENOMEM);
2296
2297 av_fast_malloc(&h->stc_offset, &h->stc_offset_size,
2298 (size / 3 + 1) * sizeof(*h->stc_offset));
2299 if (!h->stc_offset)
2300 return AVERROR(ENOMEM);
2301 h->nb_stc_offset = 0;
2302
2303 init_put_bits(&pb, h->deemulated_buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
2304 deemulate_picture(h, &pb, buf, size);
2305 flush_put_bits(&pb);
2307 /* de-emulation shrinks, so restore the padding the reader over-reads */
2308 memset(h->deemulated_buf + put_bytes_output(&pb), 0,
2310 return put_bytes_output(&pb);
2311}
2312
2314{
2315 AVSContext *h = avctx->priv_data;
2316 h->got_keyframe = 0;
2317}
2318
2319static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
2320 int *got_frame, AVPacket *avpkt)
2321{
2322 AVSContext *h = avctx->priv_data;
2323 const uint8_t *buf = avpkt->data;
2324 int buf_size = avpkt->size;
2325 uint32_t stc = -1;
2326 int input_size, ret;
2327 const uint8_t *buf_end;
2328 const uint8_t *buf_ptr;
2329 int frame_start = 0;
2330
2331 if (buf_size == 0) {
2332 if (!h->low_delay && h->DPB[0].f->data[0]) {
2333 *got_frame = 1;
2334 av_frame_move_ref(rframe, h->DPB[0].f);
2335 }
2336 return 0;
2337 }
2338
2339 h->stc = 0;
2340
2341 buf_ptr = buf;
2342 buf_end = buf + buf_size;
2343 for(;;) {
2344 buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
2345 if ((stc & 0xFFFFFE00) || buf_ptr == buf_end) {
2346 if (!h->stc)
2347 av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n");
2348 return FFMAX(0, buf_ptr - buf);
2349 }
2350 input_size = buf_end - buf_ptr;
2351 if ((ret = init_get_bits8(&h->gb, buf_ptr, input_size)) < 0)
2352 return ret;
2353 switch (stc) {
2354 case CAVS_START_CODE:
2356 if (ret < 0)
2357 return ret;
2358 break;
2359 case PIC_I_START_CODE:
2360 if (!h->got_keyframe) {
2361 av_frame_unref(h->DPB[0].f);
2362 av_frame_unref(h->DPB[1].f);
2363 h->got_keyframe = 1;
2364 }
2366 case PIC_PB_START_CODE:
2367 if (frame_start > 1)
2368 return AVERROR_INVALIDDATA;
2369 frame_start ++;
2370 if (*got_frame)
2371 av_frame_unref(rframe);
2372 *got_frame = 0;
2373 if (!h->got_keyframe)
2374 break;
2375 /* annex A, normative for decoders */
2376 ret = remove_pseudo_start_codes(h, buf_ptr, input_size);
2377 if (ret < 0)
2378 return ret;
2379 if (ret > 0 &&
2380 (ret = init_get_bits8(&h->gb, h->deemulated_buf, ret)) < 0)
2381 return ret;
2382 h->stc = stc;
2383 ret = decode_pic(h);
2384 if (ret < 0)
2385 return ret;
2386 *got_frame = 1;
2387 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
2388 if (h->DPB[!h->low_delay].f->data[0]) {
2389 if ((ret = av_frame_ref(rframe, h->DPB[!h->low_delay].f)) < 0)
2390 return ret;
2391 } else {
2392 *got_frame = 0;
2393 }
2394 } else {
2395 av_frame_move_ref(rframe, h->cur.f);
2396 }
2397 break;
2398 case EXT_START_CODE:
2399 //mpeg_decode_extension(avctx, buf_ptr, input_size);
2400 break;
2401 case USER_START_CODE:
2402 //mpeg_decode_user_data(avctx, buf_ptr, input_size);
2403 break;
2404 default:
2405 /* slice start codes are consumed by check_for_slice() */
2406 break;
2407 }
2408 }
2409}
2410
2412 .p.name = "cavs",
2413 CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2/P16)"),
2414 .p.type = AVMEDIA_TYPE_VIDEO,
2415 .p.id = AV_CODEC_ID_CAVS,
2416 .priv_data_size = sizeof(AVSContext),
2417 .init = ff_cavs_init,
2418 .close = ff_cavs_end,
2420 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
2421 .flush = cavs_flush,
2423 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
2424};
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:2411
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:792
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:676
int ff_cavs_next_mb(AVSContext *h)
save predictors for later macroblocks and increase macroblock address
Definition cavs.c:745
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:918
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:870
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:829
void ff_cavs_init_mb(AVSContext *h)
initialise predictors for motion vectors and intra prediction
Definition cavs.c:699
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:315
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:317
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:312
#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:2313
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:1383
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:1791
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:2072
static int decode_slice_header(AVSContext *h, GetBitContext *gb)
Definition cavsdec.c:1688
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:2183
#define SET_REF(idx, frame, par, distance)
static void set_intra_mode_default(AVSContext *h)
Definition cavsdec.c:1300
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:1376
#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:1450
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:1211
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:1138
#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:1637
#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:1119
#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:1391
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:1350
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:1148
static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition cavsdec.c:2319
#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:2284
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:1107
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:2237
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:1363
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:1166
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:1722
static int annex_a_applies(int stc)
annex A applies to picture headers and slices, not to other units
Definition cavsdec.c:2170
#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:1317
static void set_mv_intra(AVSContext *h)
Definition cavsdec.c:1201
#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:1869
static int seek_to_start_code(AVSContext *h, int offset)
Position the reader on the first start code prefix at or after offset, or near the end of the buffer ...
Definition cavsdec.c:1086
#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:812
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:2404
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:85
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