FFmpeg
cavsdec.c
Go to the documentation of this file.
1 /*
2  * Chinese AVS video (AVS1-P2, JiZhun profile) 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, JiZhun profile) decoder
25  * @author Stefan Gehrer <stefan.gehrer@gmx.de>
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/emms.h"
30 #include "avcodec.h"
31 #include "get_bits.h"
32 #include "golomb.h"
33 #include "cavs.h"
34 #include "codec_internal.h"
35 #include "decode.h"
36 #include "mathops.h"
37 #include "mpeg12data.h"
38 #include "startcode.h"
39 
40 static const uint8_t mv_scan[4] = {
43 };
44 
45 static const uint8_t cbp_tab[64][2] = {
46  { 63, 0 }, { 15, 15 }, { 31, 63 }, { 47, 31 }, { 0, 16 }, { 14, 32 }, { 13, 47 }, { 11, 13 },
47  { 7, 14 }, { 5, 11 }, { 10, 12 }, { 8, 5 }, { 12, 10 }, { 61, 7 }, { 4, 48 }, { 55, 3 },
48  { 1, 2 }, { 2, 8 }, { 59, 4 }, { 3, 1 }, { 62, 61 }, { 9, 55 }, { 6, 59 }, { 29, 62 },
49  { 45, 29 }, { 51, 27 }, { 23, 23 }, { 39, 19 }, { 27, 30 }, { 46, 28 }, { 53, 9 }, { 30, 6 },
50  { 43, 60 }, { 37, 21 }, { 60, 44 }, { 16, 26 }, { 21, 51 }, { 28, 35 }, { 19, 18 }, { 35, 20 },
51  { 42, 24 }, { 26, 53 }, { 44, 17 }, { 32, 37 }, { 58, 39 }, { 24, 45 }, { 20, 58 }, { 17, 43 },
52  { 18, 42 }, { 48, 46 }, { 22, 36 }, { 33, 33 }, { 25, 34 }, { 49, 40 }, { 40, 52 }, { 36, 49 },
53  { 34, 50 }, { 50, 56 }, { 52, 25 }, { 54, 22 }, { 41, 54 }, { 56, 57 }, { 38, 41 }, { 57, 38 }
54 };
55 
56 static const uint8_t scan3x3[4] = { 4, 5, 7, 8 };
57 
58 static const uint8_t dequant_shift[64] = {
59  14, 14, 14, 14, 14, 14, 14, 14,
60  13, 13, 13, 13, 13, 13, 13, 13,
61  13, 12, 12, 12, 12, 12, 12, 12,
62  11, 11, 11, 11, 11, 11, 11, 11,
63  11, 10, 10, 10, 10, 10, 10, 10,
64  10, 9, 9, 9, 9, 9, 9, 9,
65  9, 8, 8, 8, 8, 8, 8, 8,
66  7, 7, 7, 7, 7, 7, 7, 7
67 };
68 
69 static const uint16_t dequant_mul[64] = {
70  32768, 36061, 38968, 42495, 46341, 50535, 55437, 60424,
71  32932, 35734, 38968, 42495, 46177, 50535, 55109, 59933,
72  65535, 35734, 38968, 42577, 46341, 50617, 55027, 60097,
73  32809, 35734, 38968, 42454, 46382, 50576, 55109, 60056,
74  65535, 35734, 38968, 42495, 46320, 50515, 55109, 60076,
75  65535, 35744, 38968, 42495, 46341, 50535, 55099, 60087,
76  65535, 35734, 38973, 42500, 46341, 50535, 55109, 60097,
77  32771, 35734, 38965, 42497, 46341, 50535, 55109, 60099
78 };
79 
80 #define EOB 0, 0, 0
81 
82 static const struct dec_2dvlc intra_dec[7] = {
83  {
84  { //level / run / table_inc
85  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
86  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
87  { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
88  { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 2, 1, 2 }, { -2, 1, 2 },
89  { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
90  { 1, 15, 1 }, { -1, 15, 1 }, { 2, 2, 2 }, { -2, 2, 2 }, { 1, 16, 1 }, { -1, 16, 1 },
91  { 1, 17, 1 }, { -1, 17, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 18, 1 }, { -1, 18, 1 },
92  { 1, 19, 1 }, { -1, 19, 1 }, { 2, 3, 2 }, { -2, 3, 2 }, { 1, 20, 1 }, { -1, 20, 1 },
93  { 1, 21, 1 }, { -1, 21, 1 }, { 2, 4, 2 }, { -2, 4, 2 }, { 1, 22, 1 }, { -1, 22, 1 },
94  { 2, 5, 2 }, { -2, 5, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { EOB }
95  },
96  //level_add
97  { 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 },
98  2, //golomb_order
99  0, //inc_limit
100  23, //max_run
101  },
102  {
103  { //level / run
104  { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 }, { -2, 1, 1 },
105  { 1, 3, 0 }, { -1, 3, 0 }, { EOB }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
106  { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 2, 2, 1 },
107  { -2, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 1, 9, 0 },
108  { -1, 9, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 4, 1, 2 }, { -4, 1, 2 }, { 1, 10, 0 },
109  { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 3, 2, 2 },
110  { -3, 2, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 5, 1, 3 },
111  { -5, 1, 3 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 14, 0 },
112  { -1, 14, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 2, 8, 1 }, { -2, 8, 1 }, { 3, 3, 2 },
113  { -3, 3, 2 }, { 6, 1, 3 }, { -6, 1, 3 }, { 1, 15, 0 }, { -1, 15, 0 }
114  },
115  //level_add
116  { 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 },
117  2, //golomb_order
118  1, //inc_limit
119  15, //max_run
120  },
121  {
122  { //level / run
123  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 },
124  { 3, 1, 1 }, { -3, 1, 1 }, { EOB }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
125  { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
126  { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
127  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 2, 4, 0 },
128  { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
129  { -7, 1, 2 }, { 3, 3, 1 }, { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 },
130  { -1, 8, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 3 }, { -8, 1, 3 }, { 1, 9, 0 },
131  { -1, 9, 0 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 }, { 2, 7, 0 },
132  { -2, 7, 0 }, { 9, 1, 3 }, { -9, 1, 3 }, { 1, 10, 0 }, { -1, 10, 0 }
133  },
134  //level_add
135  { 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 },
136  2, //golomb_order
137  2, //inc_limit
138  10, //max_run
139  },
140  {
141  { //level / run
142  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
143  { 1, 2, 0 }, { -1, 2, 0 }, { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 1 },
144  { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 1 },
145  { -6, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
146  { -1, 4, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
147  { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 5, 2, 1 },
148  { -5, 2, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 10, 1, 2 }, {-10, 1, 2 }, { 3, 3, 0 },
149  { -3, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 11, 1, 3 }, {-11, 1, 3 }, { 6, 2, 1 },
150  { -6, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 5, 0 }, { -2, 5, 0 }, { 3, 4, 0 },
151  { -3, 4, 0 }, { 12, 1, 3 }, {-12, 1, 3 }, { 4, 3, 0 }, { -4, 3, 0 }
152  },
153  //level_add
154  { 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 },
155  2, //golomb_order
156  4, //inc_limit
157  7, //max_run
158  },
159  {
160  { //level / run
161  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
162  { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
163  { -6, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 1 },
164  { -8, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 10, 1, 1 },
165  {-10, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 2 },
166  {-11, 1, 2 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 13, 1, 2 },
167  {-13, 1, 2 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 },
168  { -2, 3, 0 }, { 14, 1, 2 }, {-14, 1, 2 }, { 6, 2, 0 }, { -6, 2, 0 }, { 15, 1, 2 },
169  {-15, 1, 2 }, { 16, 1, 2 }, {-16, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 5, 0 },
170  { -1, 5, 0 }, { 7, 2, 0 }, { -7, 2, 0 }, { 17, 1, 2 }, {-17, 1, 2 }
171  },
172  //level_add
173  { 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 },
174  2, //golomb_order
175  7, //inc_limit
176  5, //max_run
177  },
178  {
179  { //level / run
180  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
181  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
182  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
183  { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 11, 1, 1 },
184  {-11, 1, 1 }, { 12, 1, 1 }, {-12, 1, 1 }, { 13, 1, 1 }, {-13, 1, 1 }, { 2, 2, 0 },
185  { -2, 2, 0 }, { 14, 1, 1 }, {-14, 1, 1 }, { 15, 1, 1 }, {-15, 1, 1 }, { 3, 2, 0 },
186  { -3, 2, 0 }, { 16, 1, 1 }, {-16, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 17, 1, 1 },
187  {-17, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 18, 1, 1 }, {-18, 1, 1 }, { 5, 2, 0 },
188  { -5, 2, 0 }, { 19, 1, 1 }, {-19, 1, 1 }, { 20, 1, 1 }, {-20, 1, 1 }, { 6, 2, 0 },
189  { -6, 2, 0 }, { 21, 1, 1 }, {-21, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }
190  },
191  //level_add
192  { 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 },
193  2, //golomb_order
194  10, //inc_limit
195  3, //max_run
196  },
197  {
198  { //level / run
199  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
200  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
201  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
202  { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 11, 1, 0 }, {-11, 1, 0 }, { 12, 1, 0 },
203  {-12, 1, 0 }, { 13, 1, 0 }, {-13, 1, 0 }, { 14, 1, 0 }, {-14, 1, 0 }, { 15, 1, 0 },
204  {-15, 1, 0 }, { 16, 1, 0 }, {-16, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 17, 1, 0 },
205  {-17, 1, 0 }, { 18, 1, 0 }, {-18, 1, 0 }, { 19, 1, 0 }, {-19, 1, 0 }, { 20, 1, 0 },
206  {-20, 1, 0 }, { 21, 1, 0 }, {-21, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 22, 1, 0 },
207  {-22, 1, 0 }, { 23, 1, 0 }, {-23, 1, 0 }, { 24, 1, 0 }, {-24, 1, 0 }, { 25, 1, 0 },
208  {-25, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 26, 1, 0 }, {-26, 1, 0 }
209  },
210  //level_add
211  { 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 },
212  2, //golomb_order
213  INT_MAX, //inc_limit
214  2, //max_run
215  }
216 };
217 
218 static const struct dec_2dvlc inter_dec[7] = {
219  {
220  { //level / run
221  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
222  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
223  { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
224  { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 1, 12, 1 }, { -1, 12, 1 },
225  { 1, 13, 1 }, { -1, 13, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 14, 1 }, { -1, 14, 1 },
226  { 1, 15, 1 }, { -1, 15, 1 }, { 1, 16, 1 }, { -1, 16, 1 }, { 1, 17, 1 }, { -1, 17, 1 },
227  { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 }, { 3, 1, 3 }, { -3, 1, 3 },
228  { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 2, 2, 2 }, { -2, 2, 2 },
229  { 1, 22, 1 }, { -1, 22, 1 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
230  { 1, 25, 1 }, { -1, 25, 1 }, { 1, 26, 1 }, { -1, 26, 1 }, { EOB }
231  },
232  //level_add
233  { 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 },
234  3, //golomb_order
235  0, //inc_limit
236  26 //max_run
237  },
238  {
239  { //level / run
240  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 1, 3, 0 },
241  { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
242  { -1, 6, 0 }, { 2, 1, 1 }, { -2, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 },
243  { -1, 8, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 2, 2, 1 },
244  { -2, 2, 1 }, { 1, 11, 0 }, { -1, 11, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 1, 2 },
245  { -3, 1, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 }, { -1, 14, 0 }, { 2, 3, 1 },
246  { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 1, 16, 0 },
247  { -1, 16, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 1, 17, 0 }, { -1, 17, 0 }, { 4, 1, 3 },
248  { -4, 1, 3 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 18, 0 }, { -1, 18, 0 }, { 1, 19, 0 },
249  { -1, 19, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 3, 2, 2 }, { -3, 2, 2 }
250  },
251  //level_add
252  { 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 },
253  2, //golomb_order
254  1, //inc_limit
255  19 //max_run
256  },
257  {
258  { //level / run
259  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 0 },
260  { -2, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 3, 1, 1 },
261  { -3, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
262  { -1, 6, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 1, 2 },
263  { -4, 1, 2 }, { 1, 8, 0 }, { -1, 8, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 4, 0 },
264  { -2, 4, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 5, 1, 2 },
265  { -5, 1, 2 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 6, 0 },
266  { -2, 6, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 3, 1 }, { -3, 3, 1 }, { 6, 1, 2 },
267  { -6, 1, 2 }, { 4, 2, 2 }, { -4, 2, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 7, 0 },
268  { -2, 7, 0 }, { 3, 4, 1 }, { -3, 4, 1 }, { 1, 14, 0 }, { -1, 14, 0 }
269  },
270  //level_add
271  { 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 },
272  2, //golomb_order
273  2, //inc_limit
274  14 //max_run
275  },
276  {
277  { //level / run
278  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
279  { -1, 2, 0 }, { 3, 1, 0 }, { -3, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
280  { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 1 },
281  { -5, 1, 1 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 2, 3, 0 },
282  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 2, 4, 0 },
283  { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
284  { -7, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 5, 0 },
285  { -2, 5, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 4, 0 },
286  { -3, 4, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 1, 10, 0 },
287  { -1, 10, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 4, 3, 1 }, { -4, 3, 1 }
288  },
289  //level_add
290  { 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 },
291  2, //golomb_order
292  3, //inc_limit
293  10 //max_run
294  },
295  {
296  { //level / run
297  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
298  { -3, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 },
299  { -5, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 0 },
300  { -6, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
301  { -1, 4, 0 }, { 8, 1, 1 }, { -8, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
302  { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 5, 2, 0 },
303  { -5, 2, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 10, 1, 2 },
304  {-10, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 11, 1, 2 }, {-11, 1, 2 }, { 1, 7, 0 },
305  { -1, 7, 0 }, { 6, 2, 0 }, { -6, 2, 0 }, { 3, 4, 0 }, { -3, 4, 0 }, { 2, 5, 0 },
306  { -2, 5, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 4, 3, 0 }, { -4, 3, 0 }
307  },
308  //level_add
309  { 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 },
310  2, //golomb_order
311  6, //inc_limit
312  7 //max_run
313  },
314  {
315  { //level / run
316  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
317  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 1, 2, 0 },
318  { -1, 2, 0 }, { 6, 1, 0 }, { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 },
319  { -8, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 1, 3, 0 },
320  { -1, 3, 0 }, { 10, 1, 1 }, { -10, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 1 },
321  { -11, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 1 }, { -12, 1, 1 }, { 1, 4, 0 },
322  { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 13, 1, 1 }, { -13, 1, 1 }, { 5, 2, 0 },
323  { -5, 2, 0 }, { 14, 1, 1 }, { -14, 1, 1 }, { 6, 2, 0 }, { -6, 2, 0 }, { 1, 5, 0 },
324  { -1, 5, 0 }, { 15, 1, 1 }, { -15, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 16, 1, 1 },
325  { -16, 1, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 2, 0 }, { -7, 2, 0 }
326  },
327  //level_add
328  { 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 },
329  2, //golomb_order
330  9, //inc_limit
331  5 //max_run
332  },
333  {
334  { //level / run
335  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
336  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
337  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 8, 1, 0 },
338  { -8, 1, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
339  { -11, 1, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 13, 1, 0 },
340  { -13, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 15, 1, 0 },
341  { -15, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 16, 1, 0 }, { -16, 1, 0 }, { 17, 1, 0 },
342  { -17, 1, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 19, 1, 0 },
343  { -19, 1, 0 }, { 20, 1, 0 }, { -20, 1, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 1, 4, 0 },
344  { -1, 4, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 21, 1, 0 }, { -21, 1, 0 }
345  },
346  //level_add
347  { 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 },
348  2, //golomb_order
349  INT_MAX, //inc_limit
350  4 //max_run
351  }
352 };
353 
354 static const struct dec_2dvlc chroma_dec[5] = {
355  {
356  { //level / run
357  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
358  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
359  { 1, 7, 1 }, { -1, 7, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 8, 1 }, { -1, 8, 1 },
360  { 1, 9, 1 }, { -1, 9, 1 }, { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 },
361  { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
362  { 1, 15, 1 }, { -1, 15, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 16, 1 }, { -1, 16, 1 },
363  { 1, 17, 1 }, { -1, 17, 1 }, { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 },
364  { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 1, 22, 1 }, { -1, 22, 1 },
365  { 2, 2, 2 }, { -2, 2, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
366  { 1, 25, 1 }, { -1, 25, 1 }, { 4, 1, 3 }, { -4, 1, 3 }, { EOB }
367  },
368  //level_add
369  { 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 },
370  2, //golomb_order
371  0, //inc_limit
372  25 //max_run
373  },
374  {
375  { //level / run
376  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 },
377  { -2, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
378  { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 1, 7, 0 },
379  { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 2, 1 }, { -2, 2, 1 }, { 1, 9, 0 },
380  { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 4, 1, 2 },
381  { -4, 1, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 },
382  { -1, 14, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 },
383  { -2, 4, 1 }, { 5, 1, 3 }, { -5, 1, 3 }, { 3, 2, 2 }, { -3, 2, 2 }, { 1, 16, 0 },
384  { -1, 16, 0 }, { 1, 17, 0 }, { -1, 17, 0 }, { 1, 18, 0 }, { -1, 18, 0 }, { 2, 5, 1 },
385  { -2, 5, 1 }, { 1, 19, 0 }, { -1, 19, 0 }, { 1, 20, 0 }, { -1, 20, 0 }
386  },
387  //level_add
388  { 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 },
389  0, //golomb_order
390  1, //inc_limit
391  20 //max_run
392  },
393  {
394  { //level / run
395  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
396  { -1, 2, 0 }, { 3, 1, 1 }, { -3, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 4, 1, 1 },
397  { -4, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
398  { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
399  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 1, 7, 0 },
400  { -1, 7, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 1, 2 }, { -7, 1, 2 }, { 1, 8, 0 },
401  { -1, 8, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 3, 1 },
402  { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 2 },
403  { -8, 1, 2 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 9, 1, 2 },
404  { -9, 1, 2 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 },
405  },
406  //level_add
407  { 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 },
408  1, //golomb_order
409  2, //inc_limit
410  11 //max_run
411  },
412  {
413  { //level / run
414  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
415  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 5, 1, 1 },
416  { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 1, 3, 0 },
417  { -1, 3, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 8, 1, 1 },
418  { -8, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 9, 1, 1 },
419  { -9, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 10, 1, 1 },
420  {-10, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 2, 4, 0 },
421  { -2, 4, 0 }, { 11, 1, 1 }, {-11, 1, 1 }, { 1, 6, 0 }, { -1, 6, 0 }, { 12, 1, 1 },
422  {-12, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 6, 2, 1 }, { -6, 2, 1 }, { 13, 1, 1 },
423  {-13, 1, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 }, { -1, 8, 0 },
424  },
425  //level_add
426  { 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 },
427  1, //golomb_order
428  4, //inc_limit
429  8 //max_run
430  },
431  {
432  { //level / run
433  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
434  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
435  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 1, 2, 0 },
436  { -1, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
437  { -11, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 13, 1, 0 },
438  { -13, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 1, 3, 0 },
439  { -1, 3, 0 }, { 15, 1, 0 }, { -15, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 16, 1, 0 },
440  { -16, 1, 0 }, { 17, 1, 0 }, { -17, 1, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 },
441  { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 6, 2, 0 },
442  { -6, 2, 0 }, { 19, 1, 0 }, { -19, 1, 0 }, { 1, 5, 0 }, { -1, 5, 0 },
443  },
444  //level_add
445  { 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 },
446  0, //golomb_order
447  INT_MAX, //inc_limit
448  5, //max_run
449  }
450 };
451 
452 #undef EOB
453 
454 /*****************************************************************************
455  *
456  * motion vector prediction
457  *
458  ****************************************************************************/
459 
460 static inline void store_mvs(AVSContext *h)
461 {
462  h->col_mv[h->mbidx * 4 + 0] = h->mv[MV_FWD_X0];
463  h->col_mv[h->mbidx * 4 + 1] = h->mv[MV_FWD_X1];
464  h->col_mv[h->mbidx * 4 + 2] = h->mv[MV_FWD_X2];
465  h->col_mv[h->mbidx * 4 + 3] = h->mv[MV_FWD_X3];
466 }
467 
468 static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
469  cavs_vector *col_mv)
470 {
471  cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
472  unsigned den = h->direct_den[col_mv->ref];
473  int m = FF_SIGNBIT(col_mv->x);
474 
475  pmv_fw->dist = h->dist[1];
476  pmv_bw->dist = h->dist[0];
477  pmv_fw->ref = 1;
478  pmv_bw->ref = 0;
479  /* scale the co-located motion vector according to its temporal span */
480  pmv_fw->x = (((den + (den * col_mv->x * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
481  pmv_bw->x = m - (((den + (den * col_mv->x * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
482  m = FF_SIGNBIT(col_mv->y);
483  pmv_fw->y = (((den + (den * col_mv->y * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
484  pmv_bw->y = m - (((den + (den * col_mv->y * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
485 }
486 
487 static inline void mv_pred_sym(AVSContext *h, cavs_vector *src,
488  enum cavs_block size)
489 {
490  cavs_vector *dst = src + MV_BWD_OFFS;
491 
492  /* backward mv is the scaled and negated forward mv */
493  dst->x = -((src->x * h->sym_factor + 256) >> 9);
494  dst->y = -((src->y * h->sym_factor + 256) >> 9);
495  dst->ref = 0;
496  dst->dist = h->dist[0];
497  set_mvs(dst, size);
498 }
499 
500 /*****************************************************************************
501  *
502  * residual data decoding
503  *
504  ****************************************************************************/
505 
506 /** kth-order exponential golomb code */
507 static inline int get_ue_code(GetBitContext *gb, int order)
508 {
509  unsigned ret = get_ue_golomb(gb);
510  if (ret >= ((1U<<31)>>order)) {
511  av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too large\n");
512  return AVERROR_INVALIDDATA;
513  }
514  if (order) {
515  return (ret<<order) + get_bits(gb, order);
516  }
517  return ret;
518 }
519 
520 static inline int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf,
521  int16_t *dst, int mul, int shift, int coeff_num)
522 {
523  int round = 1 << (shift - 1);
524  int pos = -1;
525  const uint8_t *scantab = h->permutated_scantable;
526 
527  /* inverse scan and dequantization */
528  while (--coeff_num >= 0) {
529  pos += run_buf[coeff_num];
530  if (pos > 63) {
531  av_log(h->avctx, AV_LOG_ERROR,
532  "position out of block bounds at pic %d MB(%d,%d)\n",
533  h->cur.poc, h->mbx, h->mby);
534  return AVERROR_INVALIDDATA;
535  }
536  dst[scantab[pos]] = (level_buf[coeff_num] * mul + round) >> shift;
537  }
538  return 0;
539 }
540 
541 /**
542  * decode coefficients from one 8x8 block, dequantize, inverse transform
543  * and add them to sample block
544  * @param r pointer to 2D VLC table
545  * @param esc_golomb_order escape codes are k-golomb with this order k
546  * @param qp quantizer
547  * @param dst location of sample block
548  * @param stride line stride in frame buffer
549  */
551  const struct dec_2dvlc *r, int esc_golomb_order,
552  int qp, uint8_t *dst, ptrdiff_t stride)
553 {
554  int i, esc_code, level, mask, ret;
555  unsigned int level_code, run;
556  int16_t level_buf[65];
557  uint8_t run_buf[65];
558  int16_t *block = h->block;
559 
560  for (i = 0; i < 65; i++) {
561  level_code = get_ue_code(gb, r->golomb_order);
562  if (level_code >= ESCAPE_CODE) {
563  run = ((level_code - ESCAPE_CODE) >> 1) + 1;
564  if(run > 64) {
565  av_log(h->avctx, AV_LOG_ERROR, "run %d is too large\n", run);
566  return AVERROR_INVALIDDATA;
567  }
568  esc_code = get_ue_code(gb, esc_golomb_order);
569  if (esc_code < 0 || esc_code > 32767) {
570  av_log(h->avctx, AV_LOG_ERROR, "esc_code invalid\n");
571  return AVERROR_INVALIDDATA;
572  }
573 
574  level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
575  while (level > r->inc_limit)
576  r++;
577  mask = -(level_code & 1);
578  level = (level ^ mask) - mask;
579  } else {
580  level = r->rltab[level_code][0];
581  if (!level) //end of block signal
582  break;
583  run = r->rltab[level_code][1];
584  r += r->rltab[level_code][2];
585  }
586  level_buf[i] = level;
587  run_buf[i] = run;
588  }
589  if ((ret = dequant(h, level_buf, run_buf, block, dequant_mul[qp],
590  dequant_shift[qp], i)) < 0)
591  return ret;
592  h->cdsp.cavs_idct8_add(dst, block, stride);
593  h->bdsp.clear_block(block);
594  return 0;
595 }
596 
597 
599 {
600  if (h->cbp & (1 << 4)) {
601  int ret = decode_residual_block(h, &h->gb, chroma_dec, 0,
602  ff_cavs_chroma_qp[h->qp], h->cu, h->c_stride);
603  if (ret < 0)
604  return ret;
605  }
606  if (h->cbp & (1 << 5)) {
607  int ret = decode_residual_block(h, &h->gb, chroma_dec, 0,
608  ff_cavs_chroma_qp[h->qp], h->cv, h->c_stride);
609  if (ret < 0)
610  return ret;
611  }
612  return 0;
613 }
614 
615 static inline int decode_residual_inter(AVSContext *h)
616 {
617  int block;
618 
619  /* get coded block pattern */
620  int cbp = get_ue_golomb(&h->gb);
621  if (cbp > 63U) {
622  av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
623  return AVERROR_INVALIDDATA;
624  }
625  h->cbp = cbp_tab[cbp][1];
626 
627  /* get quantizer */
628  if (h->cbp && !h->qp_fixed)
629  h->qp = (h->qp + (unsigned)get_se_golomb(&h->gb)) & 63;
630  for (block = 0; block < 4; block++)
631  if (h->cbp & (1 << block))
632  decode_residual_block(h, &h->gb, inter_dec, 0, h->qp,
633  h->cy + h->luma_scan[block], h->l_stride);
635 
636  return 0;
637 }
638 
639 /*****************************************************************************
640  *
641  * macroblock level
642  *
643  ****************************************************************************/
644 
645 static inline void set_mv_intra(AVSContext *h)
646 {
648  set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
650  set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
651  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
652  h->col_type_base[h->mbidx] = I_8X8;
653 }
654 
655 static int decode_mb_i(AVSContext *h, int cbp_code)
656 {
657  GetBitContext *gb = &h->gb;
658  unsigned pred_mode_uv;
659  int block;
660  uint8_t top[18];
661  uint8_t *left = NULL;
662  uint8_t *d;
663  int ret;
664 
666 
667  /* get intra prediction modes from stream */
668  for (block = 0; block < 4; block++) {
669  int nA, nB, predpred;
670  int pos = scan3x3[block];
671 
672  nA = h->pred_mode_Y[pos - 1];
673  nB = h->pred_mode_Y[pos - 3];
674  predpred = FFMIN(nA, nB);
675  if (predpred == NOT_AVAIL) // if either is not available
676  predpred = INTRA_L_LP;
677  if (!get_bits1(gb)) {
678  int rem_mode = get_bits(gb, 2);
679  predpred = rem_mode + (rem_mode >= predpred);
680  }
681  h->pred_mode_Y[pos] = predpred;
682  }
683  pred_mode_uv = get_ue_golomb_31(gb);
684  if (pred_mode_uv > 6) {
685  av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
686  return AVERROR_INVALIDDATA;
687  }
688  ff_cavs_modify_mb_i(h, &pred_mode_uv);
689 
690  /* get coded block pattern */
691  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I)
692  cbp_code = get_ue_golomb(gb);
693  if (cbp_code > 63U) {
694  av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
695  return AVERROR_INVALIDDATA;
696  }
697  h->cbp = cbp_tab[cbp_code][0];
698  if (h->cbp && !h->qp_fixed)
699  h->qp = (h->qp + (unsigned)get_se_golomb(gb)) & 63; //qp_delta
700 
701  /* luma intra prediction interleaved with residual decode/transform/add */
702  for (block = 0; block < 4; block++) {
703  d = h->cy + h->luma_scan[block];
705  h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
706  (d, top, left, h->l_stride);
707  if (h->cbp & (1<<block)) {
708  ret = decode_residual_block(h, gb, intra_dec, 1, h->qp, d, h->l_stride);
709  if (ret < 0)
710  return ret;
711  }
712  }
713 
714  /* chroma intra prediction */
716  h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx * 10],
717  h->left_border_u, h->c_stride);
718  h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx * 10],
719  h->left_border_v, h->c_stride);
720 
722  if (ret < 0)
723  return ret;
725  set_mv_intra(h);
726  return 0;
727 }
728 
729 static inline void set_intra_mode_default(AVSContext *h)
730 {
731  if (h->stream_revision > 0) {
732  h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
733  h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = NOT_AVAIL;
734  } else {
735  h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
736  h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = INTRA_L_LP;
737  }
738 }
739 
740 static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
741 {
742  GetBitContext *gb = &h->gb;
743  int ref[4];
744 
746  switch (mb_type) {
747  case P_SKIP:
749  break;
750  case P_16X16:
751  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
753  break;
754  case P_16X8:
755  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
756  ref[2] = h->ref_flag ? 0 : get_bits1(gb);
759  break;
760  case P_8X16:
761  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
762  ref[1] = h->ref_flag ? 0 : get_bits1(gb);
765  break;
766  case P_8X8:
767  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
768  ref[1] = h->ref_flag ? 0 : get_bits1(gb);
769  ref[2] = h->ref_flag ? 0 : get_bits1(gb);
770  ref[3] = h->ref_flag ? 0 : get_bits1(gb);
775  }
776  ff_cavs_inter(h, mb_type);
778  store_mvs(h);
779  if (mb_type != P_SKIP)
781  ff_cavs_filter(h, mb_type);
782  h->col_type_base[h->mbidx] = mb_type;
783 }
784 
785 static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
786 {
787  int block;
788  enum cavs_sub_mb sub_type[4];
789  int flags;
790 
792 
793  /* reset all MVs */
794  h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
795  set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
796  h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
797  set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
798  switch (mb_type) {
799  case B_SKIP:
800  case B_DIRECT:
801  if (!h->col_type_base[h->mbidx]) {
802  /* intra MB at co-location, do in-plane prediction */
805  } else
806  /* direct prediction from co-located P MB, block-wise */
807  for (block = 0; block < 4; block++)
808  mv_pred_direct(h, &h->mv[mv_scan[block]],
809  &h->col_mv[h->mbidx * 4 + block]);
810  break;
811  case B_FWD_16X16:
813  break;
814  case B_SYM_16X16:
816  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
817  break;
818  case B_BWD_16X16:
820  break;
821  case B_8X8:
822 #define TMP_UNUSED_INX 7
823  flags = 0;
824  for (block = 0; block < 4; block++)
825  sub_type[block] = get_bits(&h->gb, 2);
826  for (block = 0; block < 4; block++) {
827  switch (sub_type[block]) {
828  case B_SUB_DIRECT:
829  if (!h->col_type_base[h->mbidx]) {
830  /* intra MB at co-location, do in-plane prediction */
831  if(flags==0) {
832  // if col-MB is a Intra MB, current Block size is 16x16.
833  // AVS standard section 9.9.1
834  if(block>0){
835  h->mv[TMP_UNUSED_INX ] = h->mv[MV_FWD_X0 ];
837  }
839  MV_PRED_BSKIP, BLK_8X8, 1);
842  MV_PRED_BSKIP, BLK_8X8, 0);
843  if(block>0) {
844  flags = mv_scan[block];
845  h->mv[flags ] = h->mv[MV_FWD_X0 ];
846  h->mv[flags + MV_BWD_OFFS] = h->mv[MV_FWD_X0 + MV_BWD_OFFS];
847  h->mv[MV_FWD_X0 ] = h->mv[TMP_UNUSED_INX ];
849  } else
850  flags = MV_FWD_X0;
851  } else {
852  h->mv[mv_scan[block] ] = h->mv[flags ];
853  h->mv[mv_scan[block] + MV_BWD_OFFS] = h->mv[flags + MV_BWD_OFFS];
854  }
855  } else
856  mv_pred_direct(h, &h->mv[mv_scan[block]],
857  &h->col_mv[h->mbidx * 4 + block]);
858  break;
859  case B_SUB_FWD:
861  MV_PRED_MEDIAN, BLK_8X8, 1);
862  break;
863  case B_SUB_SYM:
865  MV_PRED_MEDIAN, BLK_8X8, 1);
866  mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
867  break;
868  }
869  }
870 #undef TMP_UNUSED_INX
871  for (block = 0; block < 4; block++) {
872  if (sub_type[block] == B_SUB_BWD)
874  mv_scan[block] + MV_BWD_OFFS - 3,
875  MV_PRED_MEDIAN, BLK_8X8, 0);
876  }
877  break;
878  default:
879  if (mb_type <= B_SYM_16X16) {
880  av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
881  return AVERROR_INVALIDDATA;
882  }
883  av_assert2(mb_type < B_8X8);
884  flags = ff_cavs_partition_flags[mb_type];
885  if (mb_type & 1) { /* 16x8 macroblock types */
886  if (flags & FWD0)
888  if (flags & SYM0)
889  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
890  if (flags & FWD1)
892  if (flags & SYM1)
893  mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
894  if (flags & BWD0)
896  if (flags & BWD1)
898  } else { /* 8x16 macroblock types */
899  if (flags & FWD0)
901  if (flags & SYM0)
902  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
903  if (flags & FWD1)
905  if (flags & SYM1)
906  mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
907  if (flags & BWD0)
909  if (flags & BWD1)
911  }
912  }
913  ff_cavs_inter(h, mb_type);
915  if (mb_type != B_SKIP)
917  ff_cavs_filter(h, mb_type);
918 
919  return 0;
920 }
921 
922 /*****************************************************************************
923  *
924  * slice level
925  *
926  ****************************************************************************/
927 
929 {
930  if (h->stc > 0xAF)
931  av_log(h->avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
932 
933  if (h->stc >= h->mb_height) {
934  av_log(h->avctx, AV_LOG_ERROR, "stc 0x%02x is too large\n", h->stc);
935  return AVERROR_INVALIDDATA;
936  }
937 
938  h->mby = h->stc;
939  h->mbidx = h->mby * h->mb_width;
940 
941  /* mark top macroblocks as unavailable */
942  h->flags &= ~(B_AVAIL | C_AVAIL);
943  if (!h->pic_qp_fixed) {
944  h->qp_fixed = get_bits1(gb);
945  h->qp = get_bits(gb, 6);
946  }
947  /* inter frame or second slice can have weighting params */
948  if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
949  (!h->pic_structure && h->mby >= h->mb_width / 2))
950  if (get_bits1(gb)) { //slice_weighting_flag
951  av_log(h->avctx, AV_LOG_ERROR,
952  "weighted prediction not yet supported\n");
953  }
954  return 0;
955 }
956 
957 static inline int check_for_slice(AVSContext *h)
958 {
959  GetBitContext *gb = &h->gb;
960  int align;
961 
962  if (h->mbx)
963  return 0;
964  align = (-get_bits_count(gb)) & 7;
965  /* check for stuffing byte */
966  if (!align && (show_bits(gb, 8) == 0x80))
967  align = 8;
968  if ((show_bits_long(gb, 24 + align) & 0xFFFFFF) == 0x000001) {
969  skip_bits_long(gb, 24 + align);
970  h->stc = get_bits(gb, 8);
971  if (h->stc >= h->mb_height)
972  return 0;
973  decode_slice_header(h, gb);
974  return 1;
975  }
976  return 0;
977 }
978 
979 /*****************************************************************************
980  *
981  * frame level
982  *
983  ****************************************************************************/
984 
985 static int decode_pic(AVSContext *h)
986 {
987  int ret;
988  int skip_count = -1;
989  enum cavs_mb mb_type;
990 
991  if (!h->top_qp) {
992  av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
993  return AVERROR_INVALIDDATA;
994  }
995 
996  av_frame_unref(h->cur.f);
997 
998  skip_bits(&h->gb, 16);//bbv_dwlay
999  if (h->stc == PIC_PB_START_CODE) {
1000  h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
1001  if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
1002  av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
1003  return AVERROR_INVALIDDATA;
1004  }
1005  /* make sure we have the reference frames we need */
1006  if (!h->DPB[0].f->data[0] ||
1007  (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
1008  return AVERROR_INVALIDDATA;
1009  } else {
1010  h->cur.f->pict_type = AV_PICTURE_TYPE_I;
1011  if (get_bits1(&h->gb))
1012  skip_bits(&h->gb, 24);//time_code
1013  /* old sample clips were all progressive and no low_delay,
1014  bump stream revision if detected otherwise */
1015  if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
1016  h->stream_revision = 1;
1017  /* similarly test top_field_first and repeat_first_field */
1018  else if (show_bits(&h->gb, 11) & 3)
1019  h->stream_revision = 1;
1020  if (h->stream_revision > 0)
1021  skip_bits(&h->gb, 1); //marker_bit
1022  }
1023 
1024  if (get_bits_left(&h->gb) < 23)
1025  return AVERROR_INVALIDDATA;
1026 
1027  ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
1029  if (ret < 0)
1030  return ret;
1031 
1032  if (!h->edge_emu_buffer) {
1033  int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
1034  h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
1035  if (!h->edge_emu_buffer)
1036  return AVERROR(ENOMEM);
1037  }
1038 
1039  if ((ret = ff_cavs_init_pic(h)) < 0)
1040  return ret;
1041  h->cur.poc = get_bits(&h->gb, 8) * 2;
1042 
1043  /* get temporal distances and MV scaling factors */
1044  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1045  h->dist[0] = (h->cur.poc - h->DPB[0].poc) & 511;
1046  } else {
1047  h->dist[0] = (h->DPB[0].poc - h->cur.poc) & 511;
1048  }
1049  h->dist[1] = (h->cur.poc - h->DPB[1].poc) & 511;
1050  h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
1051  h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
1052  if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {
1053  h->sym_factor = h->dist[0] * h->scale_den[1];
1054  if (FFABS(h->sym_factor) > 32768) {
1055  av_log(h->avctx, AV_LOG_ERROR, "sym_factor %d too large\n", h->sym_factor);
1056  return AVERROR_INVALIDDATA;
1057  }
1058  } else {
1059  h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;
1060  h->direct_den[1] = h->dist[1] ? 16384 / h->dist[1] : 0;
1061  }
1062 
1063  if (h->low_delay)
1064  get_ue_golomb(&h->gb); //bbv_check_times
1065  h->progressive = get_bits1(&h->gb);
1066  h->pic_structure = 1;
1067  if (!h->progressive)
1068  h->pic_structure = get_bits1(&h->gb);
1069  if (!h->pic_structure && h->stc == PIC_PB_START_CODE)
1070  skip_bits1(&h->gb); //advanced_pred_mode_disable
1071  skip_bits1(&h->gb); //top_field_first
1072  skip_bits1(&h->gb); //repeat_first_field
1073  h->pic_qp_fixed =
1074  h->qp_fixed = get_bits1(&h->gb);
1075  h->qp = get_bits(&h->gb, 6);
1076  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1077  if (!h->progressive && !h->pic_structure)
1078  skip_bits1(&h->gb);//what is this?
1079  skip_bits(&h->gb, 4); //reserved bits
1080  } else {
1081  if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
1082  h->ref_flag = get_bits1(&h->gb);
1083  skip_bits(&h->gb, 4); //reserved bits
1084  h->skip_mode_flag = get_bits1(&h->gb);
1085  }
1086  h->loop_filter_disable = get_bits1(&h->gb);
1087  if (!h->loop_filter_disable && get_bits1(&h->gb)) {
1088  h->alpha_offset = get_se_golomb(&h->gb);
1089  h->beta_offset = get_se_golomb(&h->gb);
1090  if ( h->alpha_offset < -64 || h->alpha_offset > 64
1091  || h-> beta_offset < -64 || h-> beta_offset > 64) {
1092  h->alpha_offset = h->beta_offset = 0;
1093  return AVERROR_INVALIDDATA;
1094  }
1095  } else {
1096  h->alpha_offset = h->beta_offset = 0;
1097  }
1098 
1099  ret = 0;
1100  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1101  do {
1102  check_for_slice(h);
1103  ret = decode_mb_i(h, 0);
1104  if (ret < 0)
1105  break;
1106  } while (ff_cavs_next_mb(h));
1107  } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
1108  do {
1109  if (check_for_slice(h))
1110  skip_count = -1;
1111  if (h->skip_mode_flag && (skip_count < 0)) {
1112  if (get_bits_left(&h->gb) < 1) {
1114  break;
1115  }
1116  skip_count = get_ue_golomb(&h->gb);
1117  }
1118  if (h->skip_mode_flag && skip_count--) {
1119  decode_mb_p(h, P_SKIP);
1120  } else {
1121  if (get_bits_left(&h->gb) < 1) {
1123  break;
1124  }
1125  mb_type = get_ue_golomb(&h->gb) + P_SKIP + h->skip_mode_flag;
1126  if (mb_type > P_8X8)
1127  ret = decode_mb_i(h, mb_type - P_8X8 - 1);
1128  else
1129  decode_mb_p(h, mb_type);
1130  }
1131  if (ret < 0)
1132  break;
1133  } while (ff_cavs_next_mb(h));
1134  } else { /* AV_PICTURE_TYPE_B */
1135  do {
1136  if (check_for_slice(h))
1137  skip_count = -1;
1138  if (h->skip_mode_flag && (skip_count < 0)) {
1139  if (get_bits_left(&h->gb) < 1) {
1141  break;
1142  }
1143  skip_count = get_ue_golomb(&h->gb);
1144  }
1145  if (h->skip_mode_flag && skip_count--) {
1146  ret = decode_mb_b(h, B_SKIP);
1147  } else {
1148  if (get_bits_left(&h->gb) < 1) {
1150  break;
1151  }
1152  mb_type = get_ue_golomb(&h->gb) + B_SKIP + h->skip_mode_flag;
1153  if (mb_type > B_8X8)
1154  ret = decode_mb_i(h, mb_type - B_8X8 - 1);
1155  else
1156  ret = decode_mb_b(h, mb_type);
1157  }
1158  if (ret < 0)
1159  break;
1160  } while (ff_cavs_next_mb(h));
1161  }
1162  emms_c();
1163  if (ret >= 0 && h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1164  av_frame_unref(h->DPB[1].f);
1165  FFSWAP(AVSFrame, h->cur, h->DPB[1]);
1166  FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
1167  }
1168  return ret;
1169 }
1170 
1171 /*****************************************************************************
1172  *
1173  * headers and interface
1174  *
1175  ****************************************************************************/
1176 
1178 {
1179  int frame_rate_code;
1180  int width, height;
1181  int ret;
1182 
1183  h->profile = get_bits(&h->gb, 8);
1184  if (h->profile != 0x20) {
1186  "only supprt JiZhun profile");
1187  return AVERROR_PATCHWELCOME;
1188  }
1189  h->level = get_bits(&h->gb, 8);
1190  skip_bits1(&h->gb); //progressive sequence
1191 
1192  width = get_bits(&h->gb, 14);
1193  height = get_bits(&h->gb, 14);
1194  if ((h->width || h->height) && (h->width != width || h->height != height)) {
1196  "Width/height changing in CAVS");
1197  return AVERROR_PATCHWELCOME;
1198  }
1199  if (width <= 0 || height <= 0) {
1200  av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
1201  return AVERROR_INVALIDDATA;
1202  }
1203  skip_bits(&h->gb, 2); //chroma format
1204  skip_bits(&h->gb, 3); //sample_precision
1205  h->aspect_ratio = get_bits(&h->gb, 4);
1206  frame_rate_code = get_bits(&h->gb, 4);
1207  if (frame_rate_code == 0 || frame_rate_code > 13) {
1208  av_log(h->avctx, AV_LOG_WARNING,
1209  "frame_rate_code %d is invalid\n", frame_rate_code);
1210  frame_rate_code = 1;
1211  }
1212 
1213  skip_bits(&h->gb, 18); //bit_rate_lower
1214  skip_bits1(&h->gb); //marker_bit
1215  skip_bits(&h->gb, 12); //bit_rate_upper
1216  h->low_delay = get_bits1(&h->gb);
1217 
1218  ret = ff_set_dimensions(h->avctx, width, height);
1219  if (ret < 0)
1220  return ret;
1221 
1222  h->width = width;
1223  h->height = height;
1224  h->mb_width = (h->width + 15) >> 4;
1225  h->mb_height = (h->height + 15) >> 4;
1226  h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];
1227  if (!h->top_qp)
1228  return ff_cavs_init_top_lines(h);
1229  return 0;
1230 }
1231 
1232 static void cavs_flush(AVCodecContext * avctx)
1233 {
1234  AVSContext *h = avctx->priv_data;
1235  h->got_keyframe = 0;
1236 }
1237 
1238 static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1239  int *got_frame, AVPacket *avpkt)
1240 {
1241  AVSContext *h = avctx->priv_data;
1242  const uint8_t *buf = avpkt->data;
1243  int buf_size = avpkt->size;
1244  uint32_t stc = -1;
1245  int input_size, ret;
1246  const uint8_t *buf_end;
1247  const uint8_t *buf_ptr;
1248  int frame_start = 0;
1249 
1250  if (buf_size == 0) {
1251  if (!h->low_delay && h->DPB[0].f->data[0]) {
1252  *got_frame = 1;
1253  av_frame_move_ref(rframe, h->DPB[0].f);
1254  }
1255  return 0;
1256  }
1257 
1258  h->stc = 0;
1259 
1260  buf_ptr = buf;
1261  buf_end = buf + buf_size;
1262  for(;;) {
1263  buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
1264  if ((stc & 0xFFFFFE00) || buf_ptr == buf_end) {
1265  if (!h->stc)
1266  av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n");
1267  return FFMAX(0, buf_ptr - buf);
1268  }
1269  input_size = (buf_end - buf_ptr) * 8;
1270  switch (stc) {
1271  case CAVS_START_CODE:
1272  init_get_bits(&h->gb, buf_ptr, input_size);
1274  break;
1275  case PIC_I_START_CODE:
1276  if (!h->got_keyframe) {
1277  av_frame_unref(h->DPB[0].f);
1278  av_frame_unref(h->DPB[1].f);
1279  h->got_keyframe = 1;
1280  }
1281  case PIC_PB_START_CODE:
1282  if (frame_start > 1)
1283  return AVERROR_INVALIDDATA;
1284  frame_start ++;
1285  if (*got_frame)
1286  av_frame_unref(rframe);
1287  *got_frame = 0;
1288  if (!h->got_keyframe)
1289  break;
1290  init_get_bits(&h->gb, buf_ptr, input_size);
1291  h->stc = stc;
1292  if (decode_pic(h))
1293  break;
1294  *got_frame = 1;
1295  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1296  if (h->DPB[!h->low_delay].f->data[0]) {
1297  if ((ret = av_frame_ref(rframe, h->DPB[!h->low_delay].f)) < 0)
1298  return ret;
1299  } else {
1300  *got_frame = 0;
1301  }
1302  } else {
1303  av_frame_move_ref(rframe, h->cur.f);
1304  }
1305  break;
1306  case EXT_START_CODE:
1307  //mpeg_decode_extension(avctx, buf_ptr, input_size);
1308  break;
1309  case USER_START_CODE:
1310  //mpeg_decode_user_data(avctx, buf_ptr, input_size);
1311  break;
1312  default:
1313  if (stc <= SLICE_MAX_START_CODE) {
1314  init_get_bits(&h->gb, buf_ptr, input_size);
1315  decode_slice_header(h, &h->gb);
1316  }
1317  break;
1318  }
1319  }
1320 }
1321 
1323  .p.name = "cavs",
1324  CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
1325  .p.type = AVMEDIA_TYPE_VIDEO,
1326  .p.id = AV_CODEC_ID_CAVS,
1327  .priv_data_size = sizeof(AVSContext),
1328  .init = ff_cavs_init,
1329  .close = ff_cavs_end,
1331  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1332  .flush = cavs_flush,
1333  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1334 };
BLK_16X16
@ BLK_16X16
Definition: cavs.h:120
cavs_mb
cavs_mb
Definition: cavs.h:67
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
level
uint8_t level
Definition: svq3.c:204
MV_PRED_PSKIP
@ MV_PRED_PSKIP
Definition: cavs.h:115
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:495
ff_cavs_partition_flags
const uint8_t ff_cavs_partition_flags[30]
Definition: cavsdata.c:24
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_cavs_chroma_qp
const uint8_t ff_cavs_chroma_qp[64]
Definition: cavsdata.c:57
MV_BWD_C2
@ MV_BWD_C2
Definition: cavs.h:140
SYM1
#define SYM1
Definition: cavs.h:60
chroma_dec
static const struct dec_2dvlc chroma_dec[5]
Definition: cavsdec.c:354
MV_BWD_X0
@ MV_BWD_X0
Definition: cavs.h:142
EXT_START_CODE
#define EXT_START_CODE
Definition: cavs.h:39
SLICE_MAX_START_CODE
#define SLICE_MAX_START_CODE
Definition: cavs.h:38
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
MV_FWD_X0
@ MV_FWD_X0
Definition: cavs.h:132
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
FWD0
#define FWD0
Definition: cavs.h:55
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
AVPacket::data
uint8_t * data
Definition: packet.h:522
B_SUB_FWD
@ B_SUB_FWD
Definition: cavs.h:84
FFCodec
Definition: codec_internal.h:127
ff_cavs_init
av_cold int ff_cavs_init(AVCodecContext *avctx)
Definition: cavs.c:792
scan3x3
static const uint8_t scan3x3[4]
Definition: cavsdec.c:56
BLK_8X8
@ BLK_8X8
Definition: cavs.h:123
ff_cavs_dir_mv
const cavs_vector ff_cavs_dir_mv
mark block as "no prediction from this direction" e.g.
Definition: cavsdata.c:66
cavs_block
cavs_block
Definition: cavs.h:119
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_cavs_modify_mb_i
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
Definition: cavs.c:361
decode_residual_chroma
static int decode_residual_chroma(AVSContext *h)
Definition: cavsdec.c:598
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
ff_cavs_load_intra_pred_chroma
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
Definition: cavs.c:234
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
ff_cavs_init_pic
int ff_cavs_init_pic(AVSContext *h)
Definition: cavs.c:721
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
golomb.h
exp golomb vlc stuff
set_mvs
static void set_mvs(cavs_vector *mv, enum cavs_block size)
Definition: cavs.h:255
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
ff_cavs_intra_mv
const cavs_vector ff_cavs_intra_mv
mark block as using intra prediction
Definition: cavsdata.c:69
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
cavs_vector::x
int16_t x
Definition: cavs.h:150
GetBitContext
Definition: get_bits.h:108
MV_BWD_A1
@ MV_BWD_A1
Definition: cavs.h:141
dequant
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:520
cavs_vector::dist
int16_t dist
Definition: cavs.h:152
P_16X8
@ P_16X8
Definition: cavs.h:71
B_AVAIL
#define B_AVAIL
Definition: cavs.h:46
avassert.h
EOB
#define EOB
Definition: cavsdec.c:80
frame_start
static int frame_start(MpegEncContext *s)
Definition: mpegvideo_enc.c:1710
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
I_8X8
@ I_8X8
Definition: cavs.h:68
mask
static const uint16_t mask[17]
Definition: lzw.c:38
mv_scan
static const uint8_t mv_scan[4]
Definition: cavsdec.c:40
emms_c
#define emms_c()
Definition: emms.h:63
MV_BWD_X1
@ MV_BWD_X1
Definition: cavs.h:143
width
#define width
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
MV_BWD_X2
@ MV_BWD_X2
Definition: cavs.h:145
BWD0
#define BWD0
Definition: cavs.h:57
ff_cavs_init_top_lines
int ff_cavs_init_top_lines(AVSContext *h)
some predictions require data from the top-neighbouring macroblock.
Definition: cavs.c:757
MV_PRED_BSKIP
@ MV_PRED_BSKIP
Definition: cavs.h:116
BLK_16X8
@ BLK_16X8
Definition: cavs.h:121
decode_seq_header
static int decode_seq_header(AVSContext *h)
Definition: cavsdec.c:1177
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:425
cavs_flush
static void cavs_flush(AVCodecContext *avctx)
Definition: cavsdec.c:1232
decode_slice_header
static int decode_slice_header(AVSContext *h, GetBitContext *gb)
Definition: cavsdec.c:928
decode_mb_p
static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
Definition: cavsdec.c:740
decode.h
get_bits.h
set_mv_intra
static void set_mv_intra(AVSContext *h)
Definition: cavsdec.c:645
decode_residual_block
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:550
MV_PRED_TOPRIGHT
@ MV_PRED_TOPRIGHT
Definition: cavs.h:114
PIC_PB_START_CODE
#define PIC_PB_START_CODE
Definition: cavs.h:43
MV_FWD_B3
@ MV_FWD_B3
Definition: cavs.h:129
MV_BWD_OFFS
#define MV_BWD_OFFS
Definition: cavs.h:64
get_se_golomb
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:239
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
B_SUB_BWD
@ B_SUB_BWD
Definition: cavs.h:85
dequant_mul
static const uint16_t dequant_mul[64]
Definition: cavsdec.c:69
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
check_for_slice
static int check_for_slice(AVSContext *h)
Definition: cavsdec.c:957
INTRA_L_LP
@ INTRA_L_LP
Definition: cavs.h:92
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
run
uint8_t run
Definition: svq3.c:203
TMP_UNUSED_INX
#define TMP_UNUSED_INX
P_16X16
@ P_16X16
Definition: cavs.h:70
mv_pred_direct
static void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw, cavs_vector *col_mv)
Definition: cavsdec.c:468
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
mathops.h
PIC_I_START_CODE
#define PIC_I_START_CODE
Definition: cavs.h:42
avpriv_find_start_code
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
CAVS_START_CODE
#define CAVS_START_CODE
Definition: cavs.h:41
decode_pic
static int decode_pic(AVSContext *h)
Definition: cavsdec.c:985
FF_SIGNBIT
#define FF_SIGNBIT(x)
Definition: mathops.h:130
ff_cavs_mv
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:573
startcode.h
B_SYM_16X16
@ B_SYM_16X16
Definition: cavs.h:78
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
av_frame_ref
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:354
codec_internal.h
shift
static int shift(int a, int b)
Definition: bonk.c:262
cbp_tab
static const uint8_t cbp_tab[64][2]
Definition: cavsdec.c:45
store_mvs
static void store_mvs(AVSContext *h)
Definition: cavsdec.c:460
MV_FWD_A1
@ MV_FWD_A1
Definition: cavs.h:131
size
int size
Definition: twinvq_data.h:10344
MV_PRED_MEDIAN
@ MV_PRED_MEDIAN
Definition: cavs.h:111
BWD1
#define BWD1
Definition: cavs.h:58
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
USER_START_CODE
#define USER_START_CODE
Definition: cavs.h:40
ff_cavs_end
av_cold int ff_cavs_end(AVCodecContext *avctx)
Definition: cavs.c:835
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
C_AVAIL
#define C_AVAIL
Definition: cavs.h:47
height
#define height
P_8X8
@ P_8X8
Definition: cavs.h:73
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
intra_dec
static const struct dec_2dvlc intra_dec[7]
Definition: cavsdec.c:82
BLK_8X16
@ BLK_8X16
Definition: cavs.h:122
emms.h
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
MV_FWD_X3
@ MV_FWD_X3
Definition: cavs.h:136
ff_cavs_load_intra_pred_luma
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block)
Definition: cavs.c:183
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
decode_mb_b
static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
Definition: cavsdec.c:785
get_ue_code
static int get_ue_code(GetBitContext *gb, int order)
kth-order exponential golomb code
Definition: cavsdec.c:507
AV_CODEC_ID_CAVS
@ AV_CODEC_ID_CAVS
Definition: codec_id.h:139
MV_PRED_TOP
@ MV_PRED_TOP
Definition: cavs.h:113
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:603
cavs_vector::y
int16_t y
Definition: cavs.h:151
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:576
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
MV_FWD_X2
@ MV_FWD_X2
Definition: cavs.h:135
MV_FWD_C2
@ MV_FWD_C2
Definition: cavs.h:130
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
ff_cavs_init_mb
void ff_cavs_init_mb(AVSContext *h)
initialise predictors for motion vectors and intra prediction
Definition: cavs.c:635
ff_mpeg12_frame_rate_tab
const AVRational ff_mpeg12_frame_rate_tab[]
Definition: mpeg12framerate.c:24
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
dec_2dvlc
Definition: cavs.h:156
B_SKIP
@ B_SKIP
Definition: cavs.h:74
pos
unsigned int pos
Definition: spdifenc.c:413
B_FWD_16X16
@ B_FWD_16X16
Definition: cavs.h:76
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
U
#define U(x)
Definition: vpx_arith.h:37
mpeg12data.h
ff_cavs_inter
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type)
Definition: cavs.c:492
AVCodecContext
main external API structure.
Definition: avcodec.h:445
cavs_sub_mb
cavs_sub_mb
Definition: cavs.h:82
get_ue_golomb_31
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition: golomb.h:120
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:281
B_BWD_16X16
@ B_BWD_16X16
Definition: cavs.h:77
B_SUB_SYM
@ B_SUB_SYM
Definition: cavs.h:86
ff_cavs_decoder
const FFCodec ff_cavs_decoder
Definition: cavsdec.c:1322
cavs_decode_frame
static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition: cavsdec.c:1238
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
AV_CODEC_CAP_DELAY
#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:76
decode_mb_i
static int decode_mb_i(AVSContext *h, int cbp_code)
Definition: cavsdec.c:655
cavs_vector
Definition: cavs.h:149
AVSContext
Definition: cavs.h:169
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
cavs_vector::ref
int16_t ref
Definition: cavs.h:153
mv_pred_sym
static void mv_pred_sym(AVSContext *h, cavs_vector *src, enum cavs_block size)
Definition: cavsdec.c:487
ff_cavs_next_mb
int ff_cavs_next_mb(AVSContext *h)
save predictors for later macroblocks and increase macroblock address
Definition: cavs.c:676
B_8X8
@ B_8X8
Definition: cavs.h:79
decode_residual_inter
static int decode_residual_inter(AVSContext *h)
Definition: cavsdec.c:615
ESCAPE_CODE
#define ESCAPE_CODE
Definition: cavs.h:53
MV_BWD_B3
@ MV_BWD_B3
Definition: cavs.h:139
P_8X16
@ P_8X16
Definition: cavs.h:72
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
set_intra_mode_default
static void set_intra_mode_default(AVSContext *h)
Definition: cavsdec.c:729
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
MV_PRED_LEFT
@ MV_PRED_LEFT
Definition: cavs.h:112
d
d
Definition: ffmpeg_filter.c:409
B_SUB_DIRECT
@ B_SUB_DIRECT
Definition: cavs.h:83
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
cavs.h
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
inter_dec
static const struct dec_2dvlc inter_dec[7]
Definition: cavsdec.c:218
ff_cavs_filter
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
in-loop deblocking filter for a single macroblock
Definition: cavs.c:107
MV_FWD_X1
@ MV_FWD_X1
Definition: cavs.h:133
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2038
FWD1
#define FWD1
Definition: cavs.h:56
dequant_shift
static const uint8_t dequant_shift[64]
Definition: cavsdec.c:58
B_DIRECT
@ B_DIRECT
Definition: cavs.h:75
AVSFrame
Definition: cavs.h:164
SYM0
#define SYM0
Definition: cavs.h:59
NOT_AVAIL
#define NOT_AVAIL
Definition: cavs.h:49
P_SKIP
@ P_SKIP
Definition: cavs.h:69