FFmpeg coverage


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