FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cavsdec.c
Date: 2022-07-07 01:21:54
Exec Total Coverage
Lines: 446 566 78.8%
Branches: 261 366 71.3%

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