FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "avcodec.h"
30 #include "get_bits.h"
31 #include "golomb.h"
32 #include "cavs.h"
33 #include "internal.h"
34 #include "mpeg12data.h"
35 #include "mpegvideo.h"
36 
37 static const uint8_t mv_scan[4] = {
40 };
41 
42 static const uint8_t cbp_tab[64][2] = {
43  { 63, 0 }, { 15, 15 }, { 31, 63 }, { 47, 31 }, { 0, 16 }, { 14, 32 }, { 13, 47 }, { 11, 13 },
44  { 7, 14 }, { 5, 11 }, { 10, 12 }, { 8, 5 }, { 12, 10 }, { 61, 7 }, { 4, 48 }, { 55, 3 },
45  { 1, 2 }, { 2, 8 }, { 59, 4 }, { 3, 1 }, { 62, 61 }, { 9, 55 }, { 6, 59 }, { 29, 62 },
46  { 45, 29 }, { 51, 27 }, { 23, 23 }, { 39, 19 }, { 27, 30 }, { 46, 28 }, { 53, 9 }, { 30, 6 },
47  { 43, 60 }, { 37, 21 }, { 60, 44 }, { 16, 26 }, { 21, 51 }, { 28, 35 }, { 19, 18 }, { 35, 20 },
48  { 42, 24 }, { 26, 53 }, { 44, 17 }, { 32, 37 }, { 58, 39 }, { 24, 45 }, { 20, 58 }, { 17, 43 },
49  { 18, 42 }, { 48, 46 }, { 22, 36 }, { 33, 33 }, { 25, 34 }, { 49, 40 }, { 40, 52 }, { 36, 49 },
50  { 34, 50 }, { 50, 56 }, { 52, 25 }, { 54, 22 }, { 41, 54 }, { 56, 57 }, { 38, 41 }, { 57, 38 }
51 };
52 
53 static const uint8_t scan3x3[4] = { 4, 5, 7, 8 };
54 
55 static const uint8_t cavs_chroma_qp[64] = {
56  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
57  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
58  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 42, 43, 43, 44, 44,
59  45, 45, 46, 46, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51
60 };
61 
62 static const uint8_t dequant_shift[64] = {
63  14, 14, 14, 14, 14, 14, 14, 14,
64  13, 13, 13, 13, 13, 13, 13, 13,
65  13, 12, 12, 12, 12, 12, 12, 12,
66  11, 11, 11, 11, 11, 11, 11, 11,
67  11, 10, 10, 10, 10, 10, 10, 10,
68  10, 9, 9, 9, 9, 9, 9, 9,
69  9, 8, 8, 8, 8, 8, 8, 8,
70  7, 7, 7, 7, 7, 7, 7, 7
71 };
72 
73 static const uint16_t dequant_mul[64] = {
74  32768, 36061, 38968, 42495, 46341, 50535, 55437, 60424,
75  32932, 35734, 38968, 42495, 46177, 50535, 55109, 59933,
76  65535, 35734, 38968, 42577, 46341, 50617, 55027, 60097,
77  32809, 35734, 38968, 42454, 46382, 50576, 55109, 60056,
78  65535, 35734, 38968, 42495, 46320, 50515, 55109, 60076,
79  65535, 35744, 38968, 42495, 46341, 50535, 55099, 60087,
80  65535, 35734, 38973, 42500, 46341, 50535, 55109, 60097,
81  32771, 35734, 38965, 42497, 46341, 50535, 55109, 60099
82 };
83 
84 #define EOB 0, 0, 0
85 
86 static const struct dec_2dvlc intra_dec[7] = {
87  {
88  { //level / run / table_inc
89  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
90  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
91  { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
92  { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 2, 1, 2 }, { -2, 1, 2 },
93  { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
94  { 1, 15, 1 }, { -1, 15, 1 }, { 2, 2, 2 }, { -2, 2, 2 }, { 1, 16, 1 }, { -1, 16, 1 },
95  { 1, 17, 1 }, { -1, 17, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 18, 1 }, { -1, 18, 1 },
96  { 1, 19, 1 }, { -1, 19, 1 }, { 2, 3, 2 }, { -2, 3, 2 }, { 1, 20, 1 }, { -1, 20, 1 },
97  { 1, 21, 1 }, { -1, 21, 1 }, { 2, 4, 2 }, { -2, 4, 2 }, { 1, 22, 1 }, { -1, 22, 1 },
98  { 2, 5, 2 }, { -2, 5, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { EOB }
99  },
100  //level_add
101  { 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 },
102  2, //golomb_order
103  0, //inc_limit
104  23, //max_run
105  },
106  {
107  { //level / run
108  { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 }, { -2, 1, 1 },
109  { 1, 3, 0 }, { -1, 3, 0 }, { EOB }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
110  { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 2, 2, 1 },
111  { -2, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 1, 9, 0 },
112  { -1, 9, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 4, 1, 2 }, { -4, 1, 2 }, { 1, 10, 0 },
113  { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 3, 2, 2 },
114  { -3, 2, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 5, 1, 3 },
115  { -5, 1, 3 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 14, 0 },
116  { -1, 14, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 2, 8, 1 }, { -2, 8, 1 }, { 3, 3, 2 },
117  { -3, 3, 2 }, { 6, 1, 3 }, { -6, 1, 3 }, { 1, 15, 0 }, { -1, 15, 0 }
118  },
119  //level_add
120  { 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 },
121  2, //golomb_order
122  1, //inc_limit
123  15, //max_run
124  },
125  {
126  { //level / run
127  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 },
128  { 3, 1, 1 }, { -3, 1, 1 }, { EOB }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
129  { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
130  { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
131  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 2, 4, 0 },
132  { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
133  { -7, 1, 2 }, { 3, 3, 1 }, { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 },
134  { -1, 8, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 3 }, { -8, 1, 3 }, { 1, 9, 0 },
135  { -1, 9, 0 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 }, { 2, 7, 0 },
136  { -2, 7, 0 }, { 9, 1, 3 }, { -9, 1, 3 }, { 1, 10, 0 }, { -1, 10, 0 }
137  },
138  //level_add
139  { 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 },
140  2, //golomb_order
141  2, //inc_limit
142  10, //max_run
143  },
144  {
145  { //level / run
146  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
147  { 1, 2, 0 }, { -1, 2, 0 }, { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 1 },
148  { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 1 },
149  { -6, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
150  { -1, 4, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
151  { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 5, 2, 1 },
152  { -5, 2, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 10, 1, 2 }, {-10, 1, 2 }, { 3, 3, 0 },
153  { -3, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 11, 1, 3 }, {-11, 1, 3 }, { 6, 2, 1 },
154  { -6, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 5, 0 }, { -2, 5, 0 }, { 3, 4, 0 },
155  { -3, 4, 0 }, { 12, 1, 3 }, {-12, 1, 3 }, { 4, 3, 0 }, { -4, 3, 0 }
156  },
157  //level_add
158  { 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 },
159  2, //golomb_order
160  4, //inc_limit
161  7, //max_run
162  },
163  {
164  { //level / run
165  { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
166  { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
167  { -6, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 1 },
168  { -8, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 10, 1, 1 },
169  {-10, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 2 },
170  {-11, 1, 2 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 13, 1, 2 },
171  {-13, 1, 2 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 },
172  { -2, 3, 0 }, { 14, 1, 2 }, {-14, 1, 2 }, { 6, 2, 0 }, { -6, 2, 0 }, { 15, 1, 2 },
173  {-15, 1, 2 }, { 16, 1, 2 }, {-16, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 5, 0 },
174  { -1, 5, 0 }, { 7, 2, 0 }, { -7, 2, 0 }, { 17, 1, 2 }, {-17, 1, 2 }
175  },
176  //level_add
177  { 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 },
178  2, //golomb_order
179  7, //inc_limit
180  5, //max_run
181  },
182  {
183  { //level / run
184  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
185  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
186  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
187  { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 11, 1, 1 },
188  {-11, 1, 1 }, { 12, 1, 1 }, {-12, 1, 1 }, { 13, 1, 1 }, {-13, 1, 1 }, { 2, 2, 0 },
189  { -2, 2, 0 }, { 14, 1, 1 }, {-14, 1, 1 }, { 15, 1, 1 }, {-15, 1, 1 }, { 3, 2, 0 },
190  { -3, 2, 0 }, { 16, 1, 1 }, {-16, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 17, 1, 1 },
191  {-17, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 18, 1, 1 }, {-18, 1, 1 }, { 5, 2, 0 },
192  { -5, 2, 0 }, { 19, 1, 1 }, {-19, 1, 1 }, { 20, 1, 1 }, {-20, 1, 1 }, { 6, 2, 0 },
193  { -6, 2, 0 }, { 21, 1, 1 }, {-21, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }
194  },
195  //level_add
196  { 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 },
197  2, //golomb_order
198  10, //inc_limit
199  3, //max_run
200  },
201  {
202  { //level / run
203  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
204  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
205  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
206  { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 11, 1, 0 }, {-11, 1, 0 }, { 12, 1, 0 },
207  {-12, 1, 0 }, { 13, 1, 0 }, {-13, 1, 0 }, { 14, 1, 0 }, {-14, 1, 0 }, { 15, 1, 0 },
208  {-15, 1, 0 }, { 16, 1, 0 }, {-16, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 17, 1, 0 },
209  {-17, 1, 0 }, { 18, 1, 0 }, {-18, 1, 0 }, { 19, 1, 0 }, {-19, 1, 0 }, { 20, 1, 0 },
210  {-20, 1, 0 }, { 21, 1, 0 }, {-21, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 22, 1, 0 },
211  {-22, 1, 0 }, { 23, 1, 0 }, {-23, 1, 0 }, { 24, 1, 0 }, {-24, 1, 0 }, { 25, 1, 0 },
212  {-25, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 26, 1, 0 }, {-26, 1, 0 }
213  },
214  //level_add
215  { 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 },
216  2, //golomb_order
217  INT_MAX, //inc_limit
218  2, //max_run
219  }
220 };
221 
222 static const struct dec_2dvlc inter_dec[7] = {
223  {
224  { //level / run
225  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
226  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
227  { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
228  { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 1, 12, 1 }, { -1, 12, 1 },
229  { 1, 13, 1 }, { -1, 13, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 14, 1 }, { -1, 14, 1 },
230  { 1, 15, 1 }, { -1, 15, 1 }, { 1, 16, 1 }, { -1, 16, 1 }, { 1, 17, 1 }, { -1, 17, 1 },
231  { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 }, { 3, 1, 3 }, { -3, 1, 3 },
232  { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 2, 2, 2 }, { -2, 2, 2 },
233  { 1, 22, 1 }, { -1, 22, 1 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
234  { 1, 25, 1 }, { -1, 25, 1 }, { 1, 26, 1 }, { -1, 26, 1 }, { EOB }
235  },
236  //level_add
237  { 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 },
238  3, //golomb_order
239  0, //inc_limit
240  26 //max_run
241  },
242  {
243  { //level / run
244  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 1, 3, 0 },
245  { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
246  { -1, 6, 0 }, { 2, 1, 1 }, { -2, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 },
247  { -1, 8, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 2, 2, 1 },
248  { -2, 2, 1 }, { 1, 11, 0 }, { -1, 11, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 1, 2 },
249  { -3, 1, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 }, { -1, 14, 0 }, { 2, 3, 1 },
250  { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 1, 16, 0 },
251  { -1, 16, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 1, 17, 0 }, { -1, 17, 0 }, { 4, 1, 3 },
252  { -4, 1, 3 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 18, 0 }, { -1, 18, 0 }, { 1, 19, 0 },
253  { -1, 19, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 3, 2, 2 }, { -3, 2, 2 }
254  },
255  //level_add
256  { 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 },
257  2, //golomb_order
258  1, //inc_limit
259  19 //max_run
260  },
261  {
262  { //level / run
263  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 0 },
264  { -2, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 3, 1, 1 },
265  { -3, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
266  { -1, 6, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 1, 2 },
267  { -4, 1, 2 }, { 1, 8, 0 }, { -1, 8, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 4, 0 },
268  { -2, 4, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 5, 1, 2 },
269  { -5, 1, 2 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 6, 0 },
270  { -2, 6, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 3, 1 }, { -3, 3, 1 }, { 6, 1, 2 },
271  { -6, 1, 2 }, { 4, 2, 2 }, { -4, 2, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 7, 0 },
272  { -2, 7, 0 }, { 3, 4, 1 }, { -3, 4, 1 }, { 1, 14, 0 }, { -1, 14, 0 }
273  },
274  //level_add
275  { 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 },
276  2, //golomb_order
277  2, //inc_limit
278  14 //max_run
279  },
280  {
281  { //level / run
282  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
283  { -1, 2, 0 }, { 3, 1, 0 }, { -3, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
284  { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 1 },
285  { -5, 1, 1 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 2, 3, 0 },
286  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 2, 4, 0 },
287  { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
288  { -7, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 5, 0 },
289  { -2, 5, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 4, 0 },
290  { -3, 4, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 1, 10, 0 },
291  { -1, 10, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 4, 3, 1 }, { -4, 3, 1 }
292  },
293  //level_add
294  { 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 },
295  2, //golomb_order
296  3, //inc_limit
297  10 //max_run
298  },
299  {
300  { //level / run
301  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
302  { -3, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 },
303  { -5, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 0 },
304  { -6, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
305  { -1, 4, 0 }, { 8, 1, 1 }, { -8, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
306  { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 5, 2, 0 },
307  { -5, 2, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 10, 1, 2 },
308  {-10, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 11, 1, 2 }, {-11, 1, 2 }, { 1, 7, 0 },
309  { -1, 7, 0 }, { 6, 2, 0 }, { -6, 2, 0 }, { 3, 4, 0 }, { -3, 4, 0 }, { 2, 5, 0 },
310  { -2, 5, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 4, 3, 0 }, { -4, 3, 0 }
311  },
312  //level_add
313  { 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 },
314  2, //golomb_order
315  6, //inc_limit
316  7 //max_run
317  },
318  {
319  { //level / run
320  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
321  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 1, 2, 0 },
322  { -1, 2, 0 }, { 6, 1, 0 }, { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 },
323  { -8, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 1, 3, 0 },
324  { -1, 3, 0 }, { 10, 1, 1 }, { -10, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 1 },
325  { -11, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 1 }, { -12, 1, 1 }, { 1, 4, 0 },
326  { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 13, 1, 1 }, { -13, 1, 1 }, { 5, 2, 0 },
327  { -5, 2, 0 }, { 14, 1, 1 }, { -14, 1, 1 }, { 6, 2, 0 }, { -6, 2, 0 }, { 1, 5, 0 },
328  { -1, 5, 0 }, { 15, 1, 1 }, { -15, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 16, 1, 1 },
329  { -16, 1, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 2, 0 }, { -7, 2, 0 }
330  },
331  //level_add
332  { 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 },
333  2, //golomb_order
334  9, //inc_limit
335  5 //max_run
336  },
337  {
338  { //level / run
339  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
340  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
341  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 8, 1, 0 },
342  { -8, 1, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
343  { -11, 1, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 13, 1, 0 },
344  { -13, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 15, 1, 0 },
345  { -15, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 16, 1, 0 }, { -16, 1, 0 }, { 17, 1, 0 },
346  { -17, 1, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 19, 1, 0 },
347  { -19, 1, 0 }, { 20, 1, 0 }, { -20, 1, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 1, 4, 0 },
348  { -1, 4, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 21, 1, 0 }, { -21, 1, 0 }
349  },
350  //level_add
351  { 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 },
352  2, //golomb_order
353  INT_MAX, //inc_limit
354  4 //max_run
355  }
356 };
357 
358 static const struct dec_2dvlc chroma_dec[5] = {
359  {
360  { //level / run
361  { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
362  { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
363  { 1, 7, 1 }, { -1, 7, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 8, 1 }, { -1, 8, 1 },
364  { 1, 9, 1 }, { -1, 9, 1 }, { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 },
365  { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
366  { 1, 15, 1 }, { -1, 15, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 16, 1 }, { -1, 16, 1 },
367  { 1, 17, 1 }, { -1, 17, 1 }, { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 },
368  { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 1, 22, 1 }, { -1, 22, 1 },
369  { 2, 2, 2 }, { -2, 2, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
370  { 1, 25, 1 }, { -1, 25, 1 }, { 4, 1, 3 }, { -4, 1, 3 }, { EOB }
371  },
372  //level_add
373  { 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 },
374  2, //golomb_order
375  0, //inc_limit
376  25 //max_run
377  },
378  {
379  { //level / run
380  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 },
381  { -2, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
382  { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 1, 7, 0 },
383  { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 2, 1 }, { -2, 2, 1 }, { 1, 9, 0 },
384  { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 4, 1, 2 },
385  { -4, 1, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 },
386  { -1, 14, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 },
387  { -2, 4, 1 }, { 5, 1, 3 }, { -5, 1, 3 }, { 3, 2, 2 }, { -3, 2, 2 }, { 1, 16, 0 },
388  { -1, 16, 0 }, { 1, 17, 0 }, { -1, 17, 0 }, { 1, 18, 0 }, { -1, 18, 0 }, { 2, 5, 1 },
389  { -2, 5, 1 }, { 1, 19, 0 }, { -1, 19, 0 }, { 1, 20, 0 }, { -1, 20, 0 }
390  },
391  //level_add
392  { 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 },
393  0, //golomb_order
394  1, //inc_limit
395  20 //max_run
396  },
397  {
398  { //level / run
399  { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
400  { -1, 2, 0 }, { 3, 1, 1 }, { -3, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 4, 1, 1 },
401  { -4, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
402  { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
403  { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 1, 7, 0 },
404  { -1, 7, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 1, 2 }, { -7, 1, 2 }, { 1, 8, 0 },
405  { -1, 8, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 3, 1 },
406  { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 2 },
407  { -8, 1, 2 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 9, 1, 2 },
408  { -9, 1, 2 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 },
409  },
410  //level_add
411  { 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 },
412  1, //golomb_order
413  2, //inc_limit
414  11 //max_run
415  },
416  {
417  { //level / run
418  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
419  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 5, 1, 1 },
420  { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 1, 3, 0 },
421  { -1, 3, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 8, 1, 1 },
422  { -8, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 9, 1, 1 },
423  { -9, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 10, 1, 1 },
424  {-10, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 2, 4, 0 },
425  { -2, 4, 0 }, { 11, 1, 1 }, {-11, 1, 1 }, { 1, 6, 0 }, { -1, 6, 0 }, { 12, 1, 1 },
426  {-12, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 6, 2, 1 }, { -6, 2, 1 }, { 13, 1, 1 },
427  {-13, 1, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 }, { -1, 8, 0 },
428  },
429  //level_add
430  { 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 },
431  1, //golomb_order
432  4, //inc_limit
433  8 //max_run
434  },
435  {
436  { //level / run
437  { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
438  { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
439  { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 1, 2, 0 },
440  { -1, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
441  { -11, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 13, 1, 0 },
442  { -13, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 1, 3, 0 },
443  { -1, 3, 0 }, { 15, 1, 0 }, { -15, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 16, 1, 0 },
444  { -16, 1, 0 }, { 17, 1, 0 }, { -17, 1, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 },
445  { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 6, 2, 0 },
446  { -6, 2, 0 }, { 19, 1, 0 }, { -19, 1, 0 }, { 1, 5, 0 }, { -1, 5, 0 },
447  },
448  //level_add
449  { 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 },
450  0, //golomb_order
451  INT_MAX, //inc_limit
452  5, //max_run
453  }
454 };
455 
456 #undef EOB
457 
458 /*****************************************************************************
459  *
460  * motion vector prediction
461  *
462  ****************************************************************************/
463 
464 static inline void store_mvs(AVSContext *h)
465 {
466  h->col_mv[h->mbidx * 4 + 0] = h->mv[MV_FWD_X0];
467  h->col_mv[h->mbidx * 4 + 1] = h->mv[MV_FWD_X1];
468  h->col_mv[h->mbidx * 4 + 2] = h->mv[MV_FWD_X2];
469  h->col_mv[h->mbidx * 4 + 3] = h->mv[MV_FWD_X3];
470 }
471 
472 static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
473  cavs_vector *col_mv)
474 {
475  cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
476  int den = h->direct_den[col_mv->ref];
477  int m = col_mv->x >> 31;
478 
479  pmv_fw->dist = h->dist[1];
480  pmv_bw->dist = h->dist[0];
481  pmv_fw->ref = 1;
482  pmv_bw->ref = 0;
483  /* scale the co-located motion vector according to its temporal span */
484  pmv_fw->x = (((den + (den * col_mv->x * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
485  pmv_bw->x = m - (((den + (den * col_mv->x * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
486  m = col_mv->y >> 31;
487  pmv_fw->y = (((den + (den * col_mv->y * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
488  pmv_bw->y = m - (((den + (den * col_mv->y * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
489 }
490 
491 static inline void mv_pred_sym(AVSContext *h, cavs_vector *src,
492  enum cavs_block size)
493 {
494  cavs_vector *dst = src + MV_BWD_OFFS;
495 
496  /* backward mv is the scaled and negated forward mv */
497  dst->x = -((src->x * h->sym_factor + 256) >> 9);
498  dst->y = -((src->y * h->sym_factor + 256) >> 9);
499  dst->ref = 0;
500  dst->dist = h->dist[0];
501  set_mvs(dst, size);
502 }
503 
504 /*****************************************************************************
505  *
506  * residual data decoding
507  *
508  ****************************************************************************/
509 
510 /** kth-order exponential golomb code */
511 static inline int get_ue_code(GetBitContext *gb, int order)
512 {
513  if (order) {
514  int ret = get_ue_golomb(gb) << order;
515  return ret + get_bits(gb, order);
516  }
517  return get_ue_golomb(gb);
518 }
519 
520 static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
521  DCTELEM *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->scantable.permutated;
526 
527  /* inverse scan and dequantization */
528  while (--coeff_num >= 0) {
529  pos += run_buf[coeff_num];
530  if (pos > 63) {
532  "position out of block bounds at pic %d MB(%d,%d)\n",
533  h->cur.poc, h->mbx, h->mby);
534  return -1;
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, int stride)
553 {
554  int i, esc_code, level, mask;
555  unsigned int level_code, run;
556  DCTELEM level_buf[65];
557  uint8_t run_buf[65];
558  DCTELEM *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  return -1;
566  esc_code = get_ue_code(gb, esc_golomb_order);
567  level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
568  while (level > r->inc_limit)
569  r++;
570  mask = -(level_code & 1);
571  level = (level ^ mask) - mask;
572  } else {
573  level = r->rltab[level_code][0];
574  if (!level) //end of block signal
575  break;
576  run = r->rltab[level_code][1];
577  r += r->rltab[level_code][2];
578  }
579  level_buf[i] = level;
580  run_buf[i] = run;
581  }
582  if (dequant(h, level_buf, run_buf, block, dequant_mul[qp],
583  dequant_shift[qp], i))
584  return -1;
585  h->cdsp.cavs_idct8_add(dst, block, stride);
586  h->dsp.clear_block(block);
587  return 0;
588 }
589 
590 
591 static inline void decode_residual_chroma(AVSContext *h)
592 {
593  if (h->cbp & (1 << 4))
594  decode_residual_block(h, &h->gb, chroma_dec, 0,
595  cavs_chroma_qp[h->qp], h->cu, h->c_stride);
596  if (h->cbp & (1 << 5))
597  decode_residual_block(h, &h->gb, chroma_dec, 0,
598  cavs_chroma_qp[h->qp], h->cv, h->c_stride);
599 }
600 
601 static inline int decode_residual_inter(AVSContext *h)
602 {
603  int block;
604 
605  /* get coded block pattern */
606  int cbp = get_ue_golomb(&h->gb);
607  if (cbp > 63U) {
608  av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp\n");
609  return -1;
610  }
611  h->cbp = cbp_tab[cbp][1];
612 
613  /* get quantizer */
614  if (h->cbp && !h->qp_fixed)
615  h->qp = (h->qp + get_se_golomb(&h->gb)) & 63;
616  for (block = 0; block < 4; block++)
617  if (h->cbp & (1 << block))
618  decode_residual_block(h, &h->gb, inter_dec, 0, h->qp,
619  h->cy + h->luma_scan[block], h->l_stride);
621 
622  return 0;
623 }
624 
625 /*****************************************************************************
626  *
627  * macroblock level
628  *
629  ****************************************************************************/
630 
631 static inline void set_mv_intra(AVSContext *h)
632 {
634  set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
636  set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
637  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
638  h->col_type_base[h->mbidx] = I_8X8;
639 }
640 
641 static int decode_mb_i(AVSContext *h, int cbp_code)
642 {
643  GetBitContext *gb = &h->gb;
644  unsigned pred_mode_uv;
645  int block;
646  uint8_t top[18];
647  uint8_t *left = NULL;
648  uint8_t *d;
649 
650  ff_cavs_init_mb(h);
651 
652  /* get intra prediction modes from stream */
653  for (block = 0; block < 4; block++) {
654  int nA, nB, predpred;
655  int pos = scan3x3[block];
656 
657  nA = h->pred_mode_Y[pos - 1];
658  nB = h->pred_mode_Y[pos - 3];
659  predpred = FFMIN(nA, nB);
660  if (predpred == NOT_AVAIL) // if either is not available
661  predpred = INTRA_L_LP;
662  if (!get_bits1(gb)) {
663  int rem_mode = get_bits(gb, 2);
664  predpred = rem_mode + (rem_mode >= predpred);
665  }
666  h->pred_mode_Y[pos] = predpred;
667  }
668  pred_mode_uv = get_ue_golomb(gb);
669  if (pred_mode_uv > 6) {
670  av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
671  return -1;
672  }
673  ff_cavs_modify_mb_i(h, &pred_mode_uv);
674 
675  /* get coded block pattern */
676  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I)
677  cbp_code = get_ue_golomb(gb);
678  if (cbp_code > 63U) {
679  av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
680  return -1;
681  }
682  h->cbp = cbp_tab[cbp_code][0];
683  if (h->cbp && !h->qp_fixed)
684  h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta
685 
686  /* luma intra prediction interleaved with residual decode/transform/add */
687  for (block = 0; block < 4; block++) {
688  d = h->cy + h->luma_scan[block];
689  ff_cavs_load_intra_pred_luma(h, top, &left, block);
691  (d, top, left, h->l_stride);
692  if (h->cbp & (1<<block))
693  decode_residual_block(h, gb, intra_dec, 1, h->qp, d, h->l_stride);
694  }
695 
696  /* chroma intra prediction */
698  h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx * 10],
699  h->left_border_u, h->c_stride);
700  h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx * 10],
701  h->left_border_v, h->c_stride);
702 
704  ff_cavs_filter(h, I_8X8);
705  set_mv_intra(h);
706  return 0;
707 }
708 
709 static inline void set_intra_mode_default(AVSContext *h)
710 {
711  if (h->stream_revision > 0) {
712  h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
713  h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = NOT_AVAIL;
714  } else {
715  h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
716  h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = INTRA_L_LP;
717  }
718 }
719 
720 static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
721 {
722  GetBitContext *gb = &h->gb;
723  int ref[4];
724 
725  ff_cavs_init_mb(h);
726  switch (mb_type) {
727  case P_SKIP:
729  break;
730  case P_16X16:
731  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
733  break;
734  case P_16X8:
735  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
736  ref[2] = h->ref_flag ? 0 : get_bits1(gb);
739  break;
740  case P_8X16:
741  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
742  ref[1] = h->ref_flag ? 0 : get_bits1(gb);
745  break;
746  case P_8X8:
747  ref[0] = h->ref_flag ? 0 : get_bits1(gb);
748  ref[1] = h->ref_flag ? 0 : get_bits1(gb);
749  ref[2] = h->ref_flag ? 0 : get_bits1(gb);
750  ref[3] = h->ref_flag ? 0 : get_bits1(gb);
755  }
756  ff_cavs_inter(h, mb_type);
758  store_mvs(h);
759  if (mb_type != P_SKIP)
761  ff_cavs_filter(h, mb_type);
762  h->col_type_base[h->mbidx] = mb_type;
763 }
764 
765 static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
766 {
767  int block;
768  enum cavs_sub_mb sub_type[4];
769  int flags;
770 
771  ff_cavs_init_mb(h);
772 
773  /* reset all MVs */
775  set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
777  set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
778  switch (mb_type) {
779  case B_SKIP:
780  case B_DIRECT:
781  if (!h->col_type_base[h->mbidx]) {
782  /* intra MB at co-location, do in-plane prediction */
785  } else
786  /* direct prediction from co-located P MB, block-wise */
787  for (block = 0; block < 4; block++)
788  mv_pred_direct(h, &h->mv[mv_scan[block]],
789  &h->col_mv[h->mbidx * 4 + block]);
790  break;
791  case B_FWD_16X16:
793  break;
794  case B_SYM_16X16:
796  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
797  break;
798  case B_BWD_16X16:
800  break;
801  case B_8X8:
802  for (block = 0; block < 4; block++)
803  sub_type[block] = get_bits(&h->gb, 2);
804  for (block = 0; block < 4; block++) {
805  switch (sub_type[block]) {
806  case B_SUB_DIRECT:
807  if (!h->col_type_base[h->mbidx]) {
808  /* intra MB at co-location, do in-plane prediction */
809  ff_cavs_mv(h, mv_scan[block], mv_scan[block] - 3,
810  MV_PRED_BSKIP, BLK_8X8, 1);
811  ff_cavs_mv(h, mv_scan[block] + MV_BWD_OFFS,
812  mv_scan[block] - 3 + MV_BWD_OFFS,
813  MV_PRED_BSKIP, BLK_8X8, 0);
814  } else
815  mv_pred_direct(h, &h->mv[mv_scan[block]],
816  &h->col_mv[h->mbidx * 4 + block]);
817  break;
818  case B_SUB_FWD:
819  ff_cavs_mv(h, mv_scan[block], mv_scan[block] - 3,
820  MV_PRED_MEDIAN, BLK_8X8, 1);
821  break;
822  case B_SUB_SYM:
823  ff_cavs_mv(h, mv_scan[block], mv_scan[block] - 3,
824  MV_PRED_MEDIAN, BLK_8X8, 1);
825  mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
826  break;
827  }
828  }
829  for (block = 0; block < 4; block++) {
830  if (sub_type[block] == B_SUB_BWD)
831  ff_cavs_mv(h, mv_scan[block] + MV_BWD_OFFS,
832  mv_scan[block] + MV_BWD_OFFS - 3,
833  MV_PRED_MEDIAN, BLK_8X8, 0);
834  }
835  break;
836  default:
837  if (mb_type <= B_SYM_16X16) {
838  av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
839  return AVERROR_INVALIDDATA;
840  }
841  av_assert2(mb_type < B_8X8);
842  flags = ff_cavs_partition_flags[mb_type];
843  if (mb_type & 1) { /* 16x8 macroblock types */
844  if (flags & FWD0)
846  if (flags & SYM0)
847  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
848  if (flags & FWD1)
850  if (flags & SYM1)
851  mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
852  if (flags & BWD0)
854  if (flags & BWD1)
856  } else { /* 8x16 macroblock types */
857  if (flags & FWD0)
859  if (flags & SYM0)
860  mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
861  if (flags & FWD1)
863  if (flags & SYM1)
864  mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
865  if (flags & BWD0)
867  if (flags & BWD1)
869  }
870  }
871  ff_cavs_inter(h, mb_type);
873  if (mb_type != B_SKIP)
875  ff_cavs_filter(h, mb_type);
876 
877  return 0;
878 }
879 
880 /*****************************************************************************
881  *
882  * slice level
883  *
884  ****************************************************************************/
885 
886 static inline int decode_slice_header(AVSContext *h, GetBitContext *gb)
887 {
888  if (h->stc > 0xAF)
889  av_log(h->avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
890 
891  if (h->stc >= h->mb_height)
892  return -1;
893 
894  h->mby = h->stc;
895  h->mbidx = h->mby * h->mb_width;
896 
897  /* mark top macroblocks as unavailable */
898  h->flags &= ~(B_AVAIL | C_AVAIL);
899  if ((h->mby == 0) && (!h->qp_fixed)) {
900  h->qp_fixed = get_bits1(gb);
901  h->qp = get_bits(gb, 6);
902  }
903  /* inter frame or second slice can have weighting params */
904  if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
905  (!h->pic_structure && h->mby >= h->mb_width / 2))
906  if (get_bits1(gb)) { //slice_weighting_flag
908  "weighted prediction not yet supported\n");
909  }
910  return 0;
911 }
912 
913 static inline int check_for_slice(AVSContext *h)
914 {
915  GetBitContext *gb = &h->gb;
916  int align;
917 
918  if (h->mbx)
919  return 0;
920  align = (-get_bits_count(gb)) & 7;
921  /* check for stuffing byte */
922  if (!align && (show_bits(gb, 8) == 0x80))
923  align = 8;
924  if ((show_bits_long(gb, 24 + align) & 0xFFFFFF) == 0x000001) {
925  skip_bits_long(gb, 24 + align);
926  h->stc = get_bits(gb, 8);
927  if (h->stc >= h->mb_height)
928  return 0;
929  decode_slice_header(h, gb);
930  return 1;
931  }
932  return 0;
933 }
934 
935 /*****************************************************************************
936  *
937  * frame level
938  *
939  ****************************************************************************/
940 
941 static int decode_pic(AVSContext *h)
942 {
943  int skip_count = -1;
944  int ret;
945  enum cavs_mb mb_type;
946 
947  skip_bits(&h->gb, 16);//bbv_dwlay
948  if (h->stc == PIC_PB_START_CODE) {
949  h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
950  if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
951  av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
952  return -1;
953  }
954  /* make sure we have the reference frames we need */
955  if (!h->DPB[0].f->data[0] ||
956  (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
957  return -1;
958  } else {
960  if (get_bits1(&h->gb))
961  skip_bits(&h->gb, 24);//time_code
962  /* old sample clips were all progressive and no low_delay,
963  bump stream revision if detected otherwise */
964  if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
965  h->stream_revision = 1;
966  /* similarly test top_field_first and repeat_first_field */
967  else if (show_bits(&h->gb, 11) & 3)
968  h->stream_revision = 1;
969  if (h->stream_revision > 0)
970  skip_bits(&h->gb, 1); //marker_bit
971  }
972  /* release last B frame */
973  if (h->cur.f->data[0])
974  h->avctx->release_buffer(h->avctx, h->cur.f);
975 
976  if ((ret = ff_get_buffer(h->avctx, h->cur.f)) < 0)
977  return ret;
978 
979  if (!h->edge_emu_buffer) {
980  int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
981  h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
982  if (!h->edge_emu_buffer)
983  return AVERROR(ENOMEM);
984  }
985 
986  if ((ret = ff_cavs_init_pic(h)) < 0)
987  return ret;
988  h->cur.poc = get_bits(&h->gb, 8) * 2;
989 
990  /* get temporal distances and MV scaling factors */
991  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
992  h->dist[0] = (h->cur.poc - h->DPB[0].poc + 512) % 512;
993  } else {
994  h->dist[0] = (h->DPB[0].poc - h->cur.poc + 512) % 512;
995  }
996  h->dist[1] = (h->cur.poc - h->DPB[1].poc + 512) % 512;
997  h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
998  h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
999  if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {
1000  h->sym_factor = h->dist[0] * h->scale_den[1];
1001  } else {
1002  h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;
1003  h->direct_den[1] = h->dist[1] ? 16384 / h->dist[1] : 0;
1004  }
1005 
1006  if (h->low_delay)
1007  get_ue_golomb(&h->gb); //bbv_check_times
1008  h->progressive = get_bits1(&h->gb);
1009  h->pic_structure = 1;
1010  if (!h->progressive)
1011  h->pic_structure = get_bits1(&h->gb);
1012  if (!h->pic_structure && h->stc == PIC_PB_START_CODE)
1013  skip_bits1(&h->gb); //advanced_pred_mode_disable
1014  skip_bits1(&h->gb); //top_field_first
1015  skip_bits1(&h->gb); //repeat_first_field
1016  h->qp_fixed = get_bits1(&h->gb);
1017  h->qp = get_bits(&h->gb, 6);
1018  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1019  if (!h->progressive && !h->pic_structure)
1020  skip_bits1(&h->gb);//what is this?
1021  skip_bits(&h->gb, 4); //reserved bits
1022  } else {
1023  if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
1024  h->ref_flag = get_bits1(&h->gb);
1025  skip_bits(&h->gb, 4); //reserved bits
1026  h->skip_mode_flag = get_bits1(&h->gb);
1027  }
1028  h->loop_filter_disable = get_bits1(&h->gb);
1029  if (!h->loop_filter_disable && get_bits1(&h->gb)) {
1030  h->alpha_offset = get_se_golomb(&h->gb);
1031  h->beta_offset = get_se_golomb(&h->gb);
1032  } else {
1033  h->alpha_offset = h->beta_offset = 0;
1034  }
1035  if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1036  do {
1037  check_for_slice(h);
1038  decode_mb_i(h, 0);
1039  } while (ff_cavs_next_mb(h));
1040  } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
1041  do {
1042  if (check_for_slice(h))
1043  skip_count = -1;
1044  if (h->skip_mode_flag && (skip_count < 0))
1045  skip_count = get_ue_golomb(&h->gb);
1046  if (h->skip_mode_flag && skip_count--) {
1047  decode_mb_p(h, P_SKIP);
1048  } else {
1049  mb_type = get_ue_golomb(&h->gb) + P_SKIP + h->skip_mode_flag;
1050  if (mb_type > P_8X8)
1051  decode_mb_i(h, mb_type - P_8X8 - 1);
1052  else
1053  decode_mb_p(h, mb_type);
1054  }
1055  } while (ff_cavs_next_mb(h));
1056  } else { /* AV_PICTURE_TYPE_B */
1057  do {
1058  if (check_for_slice(h))
1059  skip_count = -1;
1060  if (h->skip_mode_flag && (skip_count < 0))
1061  skip_count = get_ue_golomb(&h->gb);
1062  if (h->skip_mode_flag && skip_count--) {
1063  decode_mb_b(h, B_SKIP);
1064  } else {
1065  mb_type = get_ue_golomb(&h->gb) + B_SKIP + h->skip_mode_flag;
1066  if (mb_type > B_8X8)
1067  decode_mb_i(h, mb_type - B_8X8 - 1);
1068  else
1069  decode_mb_b(h, mb_type);
1070  }
1071  } while (ff_cavs_next_mb(h));
1072  }
1073  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1074  if (h->DPB[1].f->data[0])
1075  h->avctx->release_buffer(h->avctx, h->DPB[1].f);
1076  FFSWAP(AVSFrame, h->cur, h->DPB[1]);
1077  FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
1078  }
1079  return 0;
1080 }
1081 
1082 /*****************************************************************************
1083  *
1084  * headers and interface
1085  *
1086  ****************************************************************************/
1087 
1089 {
1090  int frame_rate_code;
1091  int width, height;
1092 
1093  h->profile = get_bits(&h->gb, 8);
1094  h->level = get_bits(&h->gb, 8);
1095  skip_bits1(&h->gb); //progressive sequence
1096 
1097  width = get_bits(&h->gb, 14);
1098  height = get_bits(&h->gb, 14);
1099  if ((h->width || h->height) && (h->width != width || h->height != height)) {
1100  av_log_missing_feature(h->avctx, "Width/height changing in CAVS", 0);
1101  return AVERROR_PATCHWELCOME;
1102  }
1103  if (width <= 0 || height <= 0) {
1104  av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
1105  return AVERROR_INVALIDDATA;
1106  }
1107  h->width = width;
1108  h->height = height;
1109 
1110  skip_bits(&h->gb, 2); //chroma format
1111  skip_bits(&h->gb, 3); //sample_precision
1112  h->aspect_ratio = get_bits(&h->gb, 4);
1113  frame_rate_code = get_bits(&h->gb, 4);
1114  skip_bits(&h->gb, 18); //bit_rate_lower
1115  skip_bits1(&h->gb); //marker_bit
1116  skip_bits(&h->gb, 12); //bit_rate_upper
1117  h->low_delay = get_bits1(&h->gb);
1118  h->mb_width = (h->width + 15) >> 4;
1119  h->mb_height = (h->height + 15) >> 4;
1120  h->avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_code].num;
1121  h->avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_code].den;
1122  h->avctx->width = h->width;
1123  h->avctx->height = h->height;
1124  if (!h->top_qp)
1126  return 0;
1127 }
1128 
1129 static void cavs_flush(AVCodecContext * avctx)
1130 {
1131  AVSContext *h = avctx->priv_data;
1132  h->got_keyframe = 0;
1133 }
1134 
1135 static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
1136  AVPacket *avpkt)
1137 {
1138  AVSContext *h = avctx->priv_data;
1139  const uint8_t *buf = avpkt->data;
1140  int buf_size = avpkt->size;
1141  AVFrame *picture = data;
1142  uint32_t stc = -1;
1143  int input_size;
1144  const uint8_t *buf_end;
1145  const uint8_t *buf_ptr;
1146 
1147  if (buf_size == 0) {
1148  if (!h->low_delay && h->DPB[0].f->data[0]) {
1149  *got_frame = 1;
1150  *picture = *h->DPB[0].f;
1151  if (h->cur.f->data[0])
1152  avctx->release_buffer(avctx, h->cur.f);
1153  FFSWAP(AVSFrame, h->cur, h->DPB[0]);
1154  }
1155  return 0;
1156  }
1157 
1158  buf_ptr = buf;
1159  buf_end = buf + buf_size;
1160  for(;;) {
1161  buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &stc);
1162  if ((stc & 0xFFFFFE00) || buf_ptr == buf_end)
1163  return FFMAX(0, buf_ptr - buf);
1164  input_size = (buf_end - buf_ptr) * 8;
1165  switch (stc) {
1166  case CAVS_START_CODE:
1167  init_get_bits(&h->gb, buf_ptr, input_size);
1168  decode_seq_header(h);
1169  break;
1170  case PIC_I_START_CODE:
1171  if (!h->got_keyframe) {
1172  if(h->DPB[0].f->data[0])
1173  avctx->release_buffer(avctx, h->DPB[0].f);
1174  if(h->DPB[1].f->data[0])
1175  avctx->release_buffer(avctx, h->DPB[1].f);
1176  h->got_keyframe = 1;
1177  }
1178  case PIC_PB_START_CODE:
1179  *got_frame = 0;
1180  if (!h->got_keyframe)
1181  break;
1182  if(!h->top_qp)
1183  break;
1184  init_get_bits(&h->gb, buf_ptr, input_size);
1185  h->stc = stc;
1186  if (decode_pic(h))
1187  break;
1188  *got_frame = 1;
1189  if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1190  if (h->DPB[1].f->data[0]) {
1191  *picture = *h->DPB[1].f;
1192  } else {
1193  *got_frame = 0;
1194  }
1195  } else
1196  *picture = *h->cur.f;
1197  break;
1198  case EXT_START_CODE:
1199  //mpeg_decode_extension(avctx, buf_ptr, input_size);
1200  break;
1201  case USER_START_CODE:
1202  //mpeg_decode_user_data(avctx, buf_ptr, input_size);
1203  break;
1204  default:
1205  if (stc <= SLICE_MAX_START_CODE) {
1206  init_get_bits(&h->gb, buf_ptr, input_size);
1207  decode_slice_header(h, &h->gb);
1208  }
1209  break;
1210  }
1211  }
1212 }
1213 
1215  .name = "cavs",
1216  .type = AVMEDIA_TYPE_VIDEO,
1217  .id = AV_CODEC_ID_CAVS,
1218  .priv_data_size = sizeof(AVSContext),
1219  .init = ff_cavs_init,
1220  .close = ff_cavs_end,
1222  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
1223  .flush = cavs_flush,
1224  .long_name = NULL_IF_CONFIG_SMALL("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
1225 };