../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
468 / 514
91.1%
Branches:
363 / 398
91.2%
Functions:
8 / 8
100.0%

libavcodec/h264_cavlc.c
Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
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 * H.264 / AVC / MPEG-4 part10 cavlc bitstream decoding.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #define CABAC(h) 0
29 #define UNCHECKED_BITSTREAM_READER 1
30
31 #include "h264dec.h"
32 #include "h264_mvpred.h"
33 #include "h264data.h"
34 #include "golomb.h"
35 #include "mpegutils.h"
36 #include "libavutil/avassert.h"
37
38
39 static const uint8_t golomb_to_inter_cbp_gray[16]={
40 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
41 };
42
43 static const uint8_t golomb_to_intra4x4_cbp_gray[16]={
44 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
45 };
46
47 static const uint8_t chroma_dc_coeff_token_len[4*5]={
48 2, 0, 0, 0,
49 6, 1, 0, 0,
50 6, 6, 3, 0,
51 6, 7, 7, 6,
52 6, 8, 8, 7,
53 };
54
55 static const uint8_t chroma_dc_coeff_token_bits[4*5]={
56 1, 0, 0, 0,
57 7, 1, 0, 0,
58 4, 6, 1, 0,
59 3, 3, 2, 5,
60 2, 3, 2, 0,
61 };
62
63 static const uint8_t chroma422_dc_coeff_token_len[4*9]={
64 1, 0, 0, 0,
65 7, 2, 0, 0,
66 7, 7, 3, 0,
67 9, 7, 7, 5,
68 9, 9, 7, 6,
69 10, 10, 9, 7,
70 11, 11, 10, 7,
71 12, 12, 11, 10,
72 13, 12, 12, 11,
73 };
74
75 static const uint8_t chroma422_dc_coeff_token_bits[4*9]={
76 1, 0, 0, 0,
77 15, 1, 0, 0,
78 14, 13, 1, 0,
79 7, 12, 11, 1,
80 6, 5, 10, 1,
81 7, 6, 4, 9,
82 7, 6, 5, 8,
83 7, 6, 5, 4,
84 7, 5, 4, 4,
85 };
86
87 static const uint8_t coeff_token_len[4][4*17]={
88 {
89 1, 0, 0, 0,
90 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
91 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
92 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
93 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
94 },
95 {
96 2, 0, 0, 0,
97 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
98 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
99 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
100 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
101 },
102 {
103 4, 0, 0, 0,
104 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
105 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
106 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
107 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
108 },
109 {
110 6, 0, 0, 0,
111 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
112 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
113 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
115 }
116 };
117
118 static const uint8_t coeff_token_bits[4][4*17]={
119 {
120 1, 0, 0, 0,
121 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
122 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
123 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
124 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
125 },
126 {
127 3, 0, 0, 0,
128 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
129 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
130 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
131 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
132 },
133 {
134 15, 0, 0, 0,
135 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
136 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
137 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
138 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
139 },
140 {
141 3, 0, 0, 0,
142 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
143 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
144 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
145 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
146 }
147 };
148
149 static const uint8_t total_zeros_len[16][16]= {
150 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
151 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
152 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
153 {5,3,4,4,3,3,3,4,3,4,5,5,5},
154 {4,4,4,3,3,3,3,3,4,5,4,5},
155 {6,5,3,3,3,3,3,3,4,3,6},
156 {6,5,3,3,3,2,3,4,3,6},
157 {6,4,5,3,2,2,3,3,6},
158 {6,6,4,2,2,3,2,5},
159 {5,5,3,2,2,2,4},
160 {4,4,3,3,1,3},
161 {4,4,2,1,3},
162 {3,3,1,2},
163 {2,2,1},
164 {1,1},
165 };
166
167 static const uint8_t total_zeros_bits[16][16]= {
168 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
169 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
170 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
171 {3,7,5,4,6,5,4,3,3,2,2,1,0},
172 {5,4,3,7,6,5,4,3,2,1,1,0},
173 {1,1,7,6,5,4,3,2,1,1,0},
174 {1,1,5,4,3,3,2,1,1,0},
175 {1,1,1,3,3,2,2,1,0},
176 {1,0,1,3,2,1,1,1},
177 {1,0,1,3,2,1,1},
178 {0,1,1,2,1,3},
179 {0,1,1,1,1},
180 {0,1,1,1},
181 {0,1,1},
182 {0,1},
183 };
184
185 static const uint8_t chroma_dc_total_zeros_len[3][4]= {
186 { 1, 2, 3, 3,},
187 { 1, 2, 2, 0,},
188 { 1, 1, 0, 0,},
189 };
190
191 static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
192 { 1, 1, 1, 0,},
193 { 1, 1, 0, 0,},
194 { 1, 0, 0, 0,},
195 };
196
197 static const uint8_t chroma422_dc_total_zeros_len[7][8]= {
198 { 1, 3, 3, 4, 4, 4, 5, 5 },
199 { 3, 2, 3, 3, 3, 3, 3 },
200 { 3, 3, 2, 2, 3, 3 },
201 { 3, 2, 2, 2, 3 },
202 { 2, 2, 2, 2 },
203 { 2, 2, 1 },
204 { 1, 1 },
205 };
206
207 static const uint8_t chroma422_dc_total_zeros_bits[7][8]= {
208 { 1, 2, 3, 2, 3, 1, 1, 0 },
209 { 0, 1, 1, 4, 5, 6, 7 },
210 { 0, 1, 1, 2, 6, 7 },
211 { 6, 0, 1, 2, 7 },
212 { 0, 1, 2, 3 },
213 { 0, 1, 1 },
214 { 0, 1 },
215 };
216
217 static const uint8_t run_len[7][16]={
218 {1,1},
219 {1,2,2},
220 {2,2,2,2},
221 {2,2,2,3,3},
222 {2,2,3,3,3,3},
223 {2,3,3,3,3,3,3},
224 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
225 };
226
227 static const uint8_t run_bits[7][16]={
228 {1,0},
229 {1,1,0},
230 {3,2,1,0},
231 {3,2,1,1,0},
232 {3,2,3,2,1,0},
233 {3,0,1,3,2,5,4},
234 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
235 };
236
237 #define LEVEL_TAB_BITS 8
238 static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
239
240 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
241 #define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
242 #define COEFF_TOKEN_VLC_BITS 8
243 #define TOTAL_ZEROS_VLC_BITS 9
244 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
245 #define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
246 #define RUN_VLC_BITS 3
247 #define RUN7_VLC_BITS 6
248
249 /// 17 pointers to only four different VLCs
250 static const VLCElem *coeff_token_vlc[17];
251
252 static VLCElem chroma_dc_coeff_token_vlc_table[256];
253
254 static VLCElem chroma422_dc_coeff_token_vlc_table[1 << CHROMA422_DC_COEFF_TOKEN_VLC_BITS];
255
256 static const VLCElem *total_zeros_vlc[15+1];
257
258 static const VLCElem *chroma_dc_total_zeros_vlc[3+1];
259
260 static const VLCElem *chroma422_dc_total_zeros_vlc[7+1];
261
262 static const VLCElem *run_vlc[6+1];
263
264 // The other pointers to VLCElem point into this array.
265 static VLCElem run7_vlc_table[96 + (6 << RUN_VLC_BITS)
266 + (15 << TOTAL_ZEROS_VLC_BITS)
267 + (3 << CHROMA_DC_TOTAL_ZEROS_VLC_BITS)
268 + (7 << CHROMA422_DC_TOTAL_ZEROS_VLC_BITS)
269 + (520 + 332 + 280 + 256) /* coeff token */];
270
271 /**
272 * Get the predicted number of non-zero coefficients.
273 * @param n block index
274 */
275 43729416 static inline int pred_non_zero_count(const H264Context *h, const H264SliceContext *sl, int n)
276 {
277 43729416 const int index8= scan8[n];
278 43729416 const int left = sl->non_zero_count_cache[index8 - 1];
279 43729416 const int top = sl->non_zero_count_cache[index8 - 8];
280 43729416 int i= left + top;
281
282
2/2
✓ Branch 2 → 3 taken 42024263 times.
✓ Branch 2 → 4 taken 1705153 times.
43729416 if(i<64) i= (i+1)>>1;
283
284 ff_tlog(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
285
286 43729416 return i&31;
287 }
288
289 391 static av_cold void init_cavlc_level_tab(void){
290 int suffix_length;
291 unsigned int i;
292
293
2/2
✓ Branch 12 → 3 taken 2737 times.
✓ Branch 12 → 13 taken 391 times.
3128 for(suffix_length=0; suffix_length<7; suffix_length++){
294
2/2
✓ Branch 10 → 4 taken 700672 times.
✓ Branch 10 → 11 taken 2737 times.
703409 for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
295 700672 int prefix= LEVEL_TAB_BITS - av_log2(2*i);
296
297
2/2
✓ Branch 4 → 5 taken 651015 times.
✓ Branch 4 → 6 taken 49657 times.
700672 if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
298 651015 int level_code = (prefix << suffix_length) +
299 651015 (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
300 651015 int mask = -(level_code&1);
301 651015 level_code = (((2 + level_code) >> 1) ^ mask) - mask;
302 651015 cavlc_level_tab[suffix_length][i][0]= level_code;
303 651015 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
304
2/2
✓ Branch 6 → 7 taken 46920 times.
✓ Branch 6 → 8 taken 2737 times.
49657 }else if(prefix + 1 <= LEVEL_TAB_BITS){
305 46920 cavlc_level_tab[suffix_length][i][0]= prefix+100;
306 46920 cavlc_level_tab[suffix_length][i][1]= prefix + 1;
307 }else{
308 2737 cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100;
309 2737 cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS;
310 }
311 }
312 }
313 391 }
314
315 391 av_cold void ff_h264_decode_init_vlc(void)
316 {
317 const VLCElem *coeff_token_vlc_original[4];
318 391 VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
319
320 391 VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,
321 CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4 * 5,
322 &chroma_dc_coeff_token_len [0], 1, 1,
323 &chroma_dc_coeff_token_bits[0], 1, 1, 0);
324
325 391 VLC_INIT_STATIC_TABLE(chroma422_dc_coeff_token_vlc_table,
326 CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4 * 9,
327 &chroma422_dc_coeff_token_len [0], 1, 1,
328 &chroma422_dc_coeff_token_bits[0], 1, 1, 0);
329
330 391 ff_vlc_init_tables(&state, RUN7_VLC_BITS, 16,
331 &run_len [6][0], 1, 1,
332 &run_bits[6][0], 1, 1, 0);
333
334
2/2
✓ Branch 8 → 6 taken 2346 times.
✓ Branch 8 → 9 taken 391 times.
2737 for (int i = 0; i < 6; i++) {
335 2346 run_vlc[i + 1] = ff_vlc_init_tables(&state, RUN_VLC_BITS, 7,
336 2346 &run_len [i][0], 1, 1,
337 2346 &run_bits[i][0], 1, 1, 0);
338 }
339
340
2/2
✓ Branch 12 → 10 taken 1564 times.
✓ Branch 12 → 13 taken 391 times.
1955 for (int i = 0; i < 4; i++) {
341 1564 coeff_token_vlc_original[i] =
342 1564 ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
343 1564 &coeff_token_len [i][0], 1, 1,
344 1564 &coeff_token_bits[i][0], 1, 1, 0);
345 }
346
2/2
✓ Branch 15 → 14 taken 6647 times.
✓ Branch 15 → 16 taken 391 times.
7038 for (int i = 0; i < FF_ARRAY_ELEMS(coeff_token_vlc); i++) {
347 static const uint8_t coeff_token_table_index[17] = {
348 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3
349 };
350 6647 coeff_token_vlc[i] = coeff_token_vlc_original[coeff_token_table_index[i]];
351 }
352
353
2/2
✓ Branch 19 → 17 taken 1173 times.
✓ Branch 19 → 20 taken 391 times.
1564 for (int i = 0; i < 3; i++) {
354 1173 chroma_dc_total_zeros_vlc[i + 1] =
355 1173 ff_vlc_init_tables(&state, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
356 1173 &chroma_dc_total_zeros_len [i][0], 1, 1,
357 1173 &chroma_dc_total_zeros_bits[i][0], 1, 1, 0);
358 }
359
360
2/2
✓ Branch 23 → 21 taken 2737 times.
✓ Branch 23 → 24 taken 391 times.
3128 for (int i = 0; i < 7; i++) {
361 2737 chroma422_dc_total_zeros_vlc[i + 1] =
362 2737 ff_vlc_init_tables(&state, CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
363 2737 &chroma422_dc_total_zeros_len [i][0], 1, 1,
364 2737 &chroma422_dc_total_zeros_bits[i][0], 1, 1, 0);
365 }
366
367
2/2
✓ Branch 27 → 25 taken 5865 times.
✓ Branch 27 → 28 taken 391 times.
6256 for (int i = 0; i < 15; i++) {
368 5865 total_zeros_vlc[i + 1] =
369 5865 ff_vlc_init_tables(&state, TOTAL_ZEROS_VLC_BITS, 16,
370 5865 &total_zeros_len [i][0], 1, 1,
371 5865 &total_zeros_bits[i][0], 1, 1, 0);
372 }
373 /*
374 * This is a one time safety check to make sure that
375 * the vlc table sizes were initialized correctly.
376 */
377 av_assert1(state.size == 0);
378
379 391 init_cavlc_level_tab();
380 391 }
381
382 721652 static inline int get_level_prefix(GetBitContext *gb){
383 unsigned int buf;
384 int log;
385
386 721652 OPEN_READER(re, gb);
387 721652 UPDATE_CACHE(re, gb);
388 721652 buf=GET_CACHE(re, gb);
389
390 721652 log= 32 - av_log2(buf);
391
392 721652 LAST_SKIP_BITS(re, gb, log);
393 721652 CLOSE_READER(re, gb);
394
395 721652 return log-1;
396 }
397
398 /**
399 * Decode a residual block.
400 * @param n block index
401 * @param scantable scantable
402 * @param max_coeff number of coefficients in the block
403 * @return <0 if an error occurred
404 */
405 47085218 static int decode_residual(const H264Context *h, H264SliceContext *sl,
406 GetBitContext *gb, int16_t *block, int n,
407 const uint8_t *scantable, const uint32_t *qmul,
408 int max_coeff)
409 {
410 int level[16];
411 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
412
413 //FIXME put trailing_onex into the context
414
415
2/2
✓ Branch 2 → 3 taken 3355802 times.
✓ Branch 2 → 6 taken 43729416 times.
47085218 if(max_coeff <= 8){
416
2/2
✓ Branch 3 → 4 taken 2776744 times.
✓ Branch 3 → 5 taken 579058 times.
3355802 if (max_coeff == 4)
417 2776744 coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc_table,
418 CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
419 else
420 579058 coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc_table,
421 CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
422 }else{
423
2/2
✓ Branch 6 → 7 taken 305005 times.
✓ Branch 6 → 8 taken 43424411 times.
44034421 total_coeff = pred_non_zero_count(h, sl, n >= LUMA_DC_BLOCK_INDEX ?
424 305005 (n - LUMA_DC_BLOCK_INDEX) * 16 : n);
425 43729416 coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
426 COEFF_TOKEN_VLC_BITS, 2);
427 }
428 47085218 total_coeff = coeff_token >> 2;
429 47085218 sl->non_zero_count_cache[scan8[n]] = total_coeff;
430
431 //FIXME set last_non_zero?
432
433
2/2
✓ Branch 11 → 12 taken 16430010 times.
✓ Branch 11 → 13 taken 30655208 times.
47085218 if(total_coeff==0)
434 16430010 return 0;
435
2/2
✓ Branch 13 → 14 taken 9 times.
✓ Branch 13 → 16 taken 30655199 times.
30655208 if(total_coeff > (unsigned)max_coeff) {
436 9 av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", sl->mb_x, sl->mb_y, total_coeff);
437 9 return -1;
438 }
439
440 30655199 trailing_ones= coeff_token&3;
441 ff_tlog(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
442 av_assert2(total_coeff<=16);
443
444 30655199 i = show_bits(gb, 3);
445 30655199 skip_bits(gb, trailing_ones);
446 30655199 level[0] = 1-((i&4)>>1);
447 30655199 level[1] = 1-((i&2) );
448 30655199 level[2] = 1-((i&1)<<1);
449
450
2/2
✓ Branch 18 → 19 taken 13873910 times.
✓ Branch 18 → 70 taken 16781289 times.
30655199 if(trailing_ones<total_coeff) {
451 int mask, prefix;
452 13873910 int suffix_length = total_coeff > 10 & trailing_ones < 3;
453 13873910 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
454 13873910 int level_code= cavlc_level_tab[suffix_length][bitsi][0];
455
456 13873910 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
457
2/2
✓ Branch 21 → 22 taken 320750 times.
✓ Branch 21 → 46 taken 13553160 times.
13873910 if(level_code >= 100){
458 320750 prefix= level_code - 100;
459
2/2
✓ Branch 22 → 23 taken 316595 times.
✓ Branch 22 → 25 taken 4155 times.
320750 if(prefix == LEVEL_TAB_BITS)
460 316595 prefix += get_level_prefix(gb);
461
462 //first coefficient has suffix_length equal to 0 or 1
463
2/2
✓ Branch 25 → 26 taken 194136 times.
✓ Branch 25 → 30 taken 126614 times.
320750 if(prefix<14){ //FIXME try to build a large unified VLC table for all this
464
2/2
✓ Branch 26 → 27 taken 13191 times.
✓ Branch 26 → 29 taken 180945 times.
194136 if(suffix_length)
465 13191 level_code= (prefix<<1) + get_bits1(gb); //part
466 else
467 180945 level_code= prefix; //part
468
2/2
✓ Branch 30 → 31 taken 59384 times.
✓ Branch 30 → 36 taken 67230 times.
126614 }else if(prefix==14){
469
2/2
✓ Branch 31 → 32 taken 536 times.
✓ Branch 31 → 34 taken 58848 times.
59384 if(suffix_length)
470 536 level_code= (prefix<<1) + get_bits1(gb); //part
471 else
472 58848 level_code= prefix + get_bits(gb, 4); //part
473 }else{
474 67230 level_code= 30;
475
2/2
✓ Branch 36 → 37 taken 24 times.
✓ Branch 36 → 41 taken 67206 times.
67230 if(prefix>=16){
476
1/2
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 40 taken 24 times.
24 if(prefix > 25+3){
477 ✗ av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
478 ✗ return -1;
479 }
480 24 level_code += (1<<(prefix-3))-4096;
481 }
482 67230 level_code += get_bits(gb, prefix-3); //part
483 }
484
485
2/2
✓ Branch 43 → 44 taken 247187 times.
✓ Branch 43 → 45 taken 73563 times.
320750 if(trailing_ones < 3) level_code += 2;
486
487 320750 suffix_length = 2;
488 320750 mask= -(level_code&1);
489 320750 level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;
490 }else{
491 13553160 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
492
493
2/2
✓ Branch 46 → 47 taken 765595 times.
✓ Branch 46 → 48 taken 12787565 times.
13553160 suffix_length = 1 + (level_code + 3U > 6U);
494 13553160 level[trailing_ones]= level_code;
495 }
496
497 //remaining coefficients have suffix_length > 0
498
2/2
✓ Branch 69 → 51 taken 39453369 times.
✓ Branch 69 → 70 taken 13873910 times.
53327279 for(i=trailing_ones+1;i<total_coeff;i++) {
499 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
500 39453369 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
501 39453369 level_code= cavlc_level_tab[suffix_length][bitsi][0];
502
503 39453369 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
504
2/2
✓ Branch 53 → 54 taken 816944 times.
✓ Branch 53 → 68 taken 38636425 times.
39453369 if(level_code >= 100){
505 816944 prefix= level_code - 100;
506
2/2
✓ Branch 54 → 55 taken 405057 times.
✓ Branch 54 → 57 taken 411887 times.
816944 if(prefix == LEVEL_TAB_BITS){
507 405057 prefix += get_level_prefix(gb);
508 }
509
2/2
✓ Branch 57 → 58 taken 750314 times.
✓ Branch 57 → 60 taken 66630 times.
816944 if(prefix<15){
510 750314 level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
511 }else{
512 66630 level_code = 15<<suffix_length;
513
2/2
✓ Branch 60 → 61 taken 4 times.
✓ Branch 60 → 65 taken 66626 times.
66630 if (prefix>=16) {
514
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 64 taken 4 times.
4 if(prefix > 25+3){
515 ✗ av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n");
516 ✗ return AVERROR_INVALIDDATA;
517 }
518 4 level_code += (1<<(prefix-3))-4096;
519 }
520 66630 level_code += get_bits(gb, prefix-3);
521 }
522 816944 mask= -(level_code&1);
523 816944 level_code= (((2+level_code)>>1) ^ mask) - mask;
524 }
525 39453369 level[i]= level_code;
526 39453369 suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];
527 }
528 }
529
530
2/2
✓ Branch 70 → 71 taken 307097 times.
✓ Branch 70 → 72 taken 30348102 times.
30655199 if(total_coeff == max_coeff)
531 307097 zeros_left=0;
532 else{
533
2/2
✓ Branch 72 → 73 taken 2009097 times.
✓ Branch 72 → 76 taken 28339005 times.
30348102 if (max_coeff <= 8) {
534
2/2
✓ Branch 73 → 74 taken 1551715 times.
✓ Branch 73 → 75 taken 457382 times.
2009097 if (max_coeff == 4)
535 1551715 zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff],
536 CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
537 else
538 457382 zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff],
539 CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);
540 } else {
541 28339005 zeros_left = get_vlc2(gb, total_zeros_vlc[total_coeff],
542 TOTAL_ZEROS_VLC_BITS, 1);
543 }
544 }
545
546 #define STORE_BLOCK(type) \
547 scantable += zeros_left + total_coeff - 1; \
548 if(n >= LUMA_DC_BLOCK_INDEX){ \
549 ((type*)block)[*scantable] = level[0]; \
550 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
551 if(zeros_left < 7) \
552 run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
553 else \
554 run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
555 zeros_left -= run_before; \
556 scantable -= 1 + run_before; \
557 ((type*)block)[*scantable]= level[i]; \
558 } \
559 for(;i<total_coeff;i++) { \
560 scantable--; \
561 ((type*)block)[*scantable]= level[i]; \
562 } \
563 }else{ \
564 ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
565 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
566 if(zeros_left < 7) \
567 run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
568 else \
569 run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
570 zeros_left -= run_before; \
571 scantable -= 1 + run_before; \
572 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
573 } \
574 for(;i<total_coeff;i++) { \
575 scantable--; \
576 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
577 } \
578 }
579
580
2/2
✓ Branch 77 → 78 taken 10462176 times.
✓ Branch 77 → 99 taken 20193023 times.
30655199 if (h->pixel_shift) {
581
18/18
✓ Branch 78 → 79 taken 839279 times.
✓ Branch 78 → 89 taken 9622897 times.
✓ Branch 80 → 81 taken 775402 times.
✓ Branch 80 → 82 taken 16974 times.
✓ Branch 84 → 85 taken 1075317 times.
✓ Branch 84 → 86 taken 556338 times.
✓ Branch 85 → 80 taken 792376 times.
✓ Branch 85 → 86 taken 282941 times.
✓ Branch 88 → 87 taken 675595 times.
✓ Branch 88 → 120 taken 839279 times.
✓ Branch 90 → 91 taken 13892379 times.
✓ Branch 90 → 92 taken 2124206 times.
✓ Branch 94 → 95 taken 19265710 times.
✓ Branch 94 → 96 taken 6373772 times.
✓ Branch 95 → 90 taken 16016585 times.
✓ Branch 95 → 96 taken 3249125 times.
✓ Branch 98 → 97 taken 9617414 times.
✓ Branch 98 → 120 taken 9622897 times.
37564146 STORE_BLOCK(int32_t)
582 } else {
583
18/18
✓ Branch 99 → 100 taken 1560326 times.
✓ Branch 99 → 110 taken 18632697 times.
✓ Branch 101 → 102 taken 693307 times.
✓ Branch 101 → 103 taken 21258 times.
✓ Branch 105 → 106 taken 1161139 times.
✓ Branch 105 → 107 taken 1113752 times.
✓ Branch 106 → 101 taken 714565 times.
✓ Branch 106 → 107 taken 446574 times.
✓ Branch 109 → 108 taken 1118942 times.
✓ Branch 109 → 120 taken 1560326 times.
✓ Branch 111 → 112 taken 27568232 times.
✓ Branch 111 → 113 taken 4179899 times.
✓ Branch 115 → 116 taken 36081287 times.
✓ Branch 115 → 117 taken 14299541 times.
✓ Branch 116 → 111 taken 31748131 times.
✓ Branch 116 → 117 taken 4333156 times.
✓ Branch 119 → 118 taken 12139433 times.
✓ Branch 119 → 120 taken 18632697 times.
65914094 STORE_BLOCK(int16_t)
584 }
585
586
2/2
✓ Branch 120 → 121 taken 6 times.
✓ Branch 120 → 123 taken 30655193 times.
30655199 if(zeros_left<0){
587 6 av_log(h->avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", sl->mb_x, sl->mb_y);
588 6 return -1;
589 }
590
591 30655193 return 0;
592 }
593
594 static av_always_inline
595 3046973 int decode_luma_residual(const H264Context *h, H264SliceContext *sl,
596 GetBitContext *gb, const uint8_t *scan,
597 const uint8_t *scan8x8, int pixel_shift,
598 int mb_type, int cbp, int p)
599 {
600 int i4x4, i8x8;
601
1/2
✓ Branch 2 → 3 taken 3046973 times.
✗ Branch 2 → 4 not taken.
3046973 int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
602
2/2
✓ Branch 5 → 6 taken 305005 times.
✓ Branch 5 → 26 taken 2741968 times.
3046973 if(IS_INTRA16x16(mb_type)){
603 305005 AV_ZERO128(sl->mb_luma_dc[p]+0);
604 305005 AV_ZERO128(sl->mb_luma_dc[p]+8);
605 305005 AV_ZERO128(sl->mb_luma_dc[p]+16);
606 305005 AV_ZERO128(sl->mb_luma_dc[p]+24);
607
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 305005 times.
305005 if (decode_residual(h, sl, gb, sl->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX + p, scan, NULL, 16) < 0) {
608 ✗ return -1; //FIXME continue if partitioned and other return -1 too
609 }
610
611 av_assert2((cbp&15) == 0 || (cbp&15) == 15);
612
613
2/2
✓ Branch 13 → 14 taken 108630 times.
✓ Branch 13 → 24 taken 196375 times.
305005 if(cbp&15){
614
2/2
✓ Branch 22 → 15 taken 434516 times.
✓ Branch 22 → 23 taken 108628 times.
543144 for(i8x8=0; i8x8<4; i8x8++){
615
2/2
✓ Branch 20 → 16 taken 1738062 times.
✓ Branch 20 → 21 taken 434514 times.
2172576 for(i4x4=0; i4x4<4; i4x4++){
616 1738062 const int index= i4x4 + 4*i8x8 + p*16;
617
2/2
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 1738060 times.
1738062 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift),
618 1738062 index, scan + 1, h->ps.pps->dequant4_coeff[p][qscale], 15) < 0 ){
619 2 return -1;
620 }
621 }
622 }
623 108628 return 0xf;
624 }else{
625 196375 fill_rectangle(&sl->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1);
626 196375 return 0;
627 }
628 }else{
629
2/2
✓ Branch 26 → 27 taken 1178272 times.
✓ Branch 26 → 28 taken 1563696 times.
2741968 int cqm = (IS_INTRA( mb_type ) ? 0:3)+p;
630 /* For CAVLC 4:4:4, we need to keep track of the luma 8x8 CBP for deblocking nnz purposes. */
631 2741968 int new_cbp = 0;
632
2/2
✓ Branch 47 → 30 taken 10967860 times.
✓ Branch 47 → 48 taken 2741961 times.
13709821 for(i8x8=0; i8x8<4; i8x8++){
633
2/2
✓ Branch 30 → 31 taken 7950319 times.
✓ Branch 30 → 45 taken 3017541 times.
10967860 if(cbp & (1<<i8x8)){
634
2/2
✓ Branch 31 → 32 taken 2320623 times.
✓ Branch 31 → 39 taken 5629696 times.
7950319 if(IS_8x8DCT(mb_type)){
635 2320623 int16_t *buf = &sl->mb[64*i8x8+256*p << pixel_shift];
636 uint8_t *nnz;
637
2/2
✓ Branch 37 → 33 taken 9282492 times.
✓ Branch 37 → 38 taken 2320623 times.
11603115 for(i4x4=0; i4x4<4; i4x4++){
638 9282492 const int index= i4x4 + 4*i8x8 + p*16;
639
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 9282492 times.
9282492 if( decode_residual(h, sl, gb, buf, index, scan8x8+16*i4x4,
640 9282492 h->ps.pps->dequant8_coeff[cqm][qscale], 16) < 0 )
641 ✗ return -1;
642 }
643 2320623 nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
644 2320623 nnz[0] += nnz[1] + nnz[8] + nnz[9];
645 2320623 new_cbp |= !!nnz[0] << i8x8;
646 }else{
647
2/2
✓ Branch 44 → 40 taken 22518779 times.
✓ Branch 44 → 46 taken 5629689 times.
28148468 for(i4x4=0; i4x4<4; i4x4++){
648 22518779 const int index= i4x4 + 4*i8x8 + p*16;
649
2/2
✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 43 taken 22518772 times.
22518779 if( decode_residual(h, sl, gb, sl->mb + (16*index << pixel_shift), index,
650 22518779 scan, h->ps.pps->dequant4_coeff[cqm][qscale], 16) < 0 ){
651 7 return -1;
652 }
653 22518772 new_cbp |= sl->non_zero_count_cache[scan8[index]] << i8x8;
654 }
655 }
656 }else{
657 3017541 uint8_t * const nnz = &sl->non_zero_count_cache[scan8[4 * i8x8 + p * 16]];
658 3017541 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
659 }
660 }
661 2741961 return new_cbp;
662 }
663 }
664
665 /* Residual is category 3 (intra) or 4 (inter), so it comes from partition B
666 * or C. NULL if that partition was not received. */
667 3064419 static GetBitContext *mb_residual_gb(const H264Context *h, H264SliceContext *sl,
668 unsigned mb_type)
669 {
670 3064419 int intra = IS_INTRA(mb_type);
671
672
2/2
✓ Branch 2 → 3 taken 3059621 times.
✓ Branch 2 → 4 taken 4798 times.
3064419 if (!sl->data_partitioning)
673 3059621 return &sl->gb;
674
3/4
✓ Branch 4 → 5 taken 2194 times.
✓ Branch 4 → 6 taken 2604 times.
✓ Branch 7 → 8 taken 4798 times.
✗ Branch 7 → 12 not taken.
4798 if (intra ? sl->dpb_available : sl->dpc_available)
675
2/2
✓ Branch 8 → 9 taken 2194 times.
✓ Branch 8 → 10 taken 2604 times.
4798 return intra ? &sl->gb_dpb : &sl->gb_dpc;
676
677
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ av_log(h->avctx, AV_LOG_ERROR, "Missing slice data partition %c\n",
678 intra ? 'B' : 'C');
679 ✗ return NULL;
680 }
681
682 4963024 int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl)
683 {
684 int mb_xy;
685 int partition_count;
686 unsigned int mb_type, cbp;
687 4963024 int dct8x8_allowed = h->ps.pps->transform_8x8_mode;
688
4/4
✓ Branch 2 → 3 taken 389328 times.
✓ Branch 2 → 4 taken 4573696 times.
✓ Branch 3 → 4 taken 346560 times.
✓ Branch 3 → 5 taken 42768 times.
4963024 const int decode_chroma = h->ps.sps->chroma_format_idc == 1 || h->ps.sps->chroma_format_idc == 2;
689 4963024 const int pixel_shift = h->pixel_shift;
690
691 4963024 mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;
692
693 ff_tlog(h->avctx, "pic:%d mb:%d/%d\n", h->poc.frame_num, sl->mb_x, sl->mb_y);
694 4963024 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
695 down the code */
696
2/2
✓ Branch 6 → 7 taken 3856080 times.
✓ Branch 6 → 21 taken 1106944 times.
4963024 if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
697
2/2
✓ Branch 7 → 8 taken 2687745 times.
✓ Branch 7 → 13 taken 1168335 times.
3856080 if (sl->mb_skip_run == -1) {
698 2687745 unsigned mb_skip_run = get_ue_golomb_long(&sl->gb);
699
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 2687745 times.
2687745 if (mb_skip_run > h->mb_num) {
700 ✗ av_log(h->avctx, AV_LOG_ERROR, "mb_skip_run %d is invalid\n", mb_skip_run);
701 ✗ return AVERROR_INVALIDDATA;
702 }
703 2687745 sl->mb_skip_run = mb_skip_run;
704 }
705
706
2/2
✓ Branch 13 → 14 taken 1172111 times.
✓ Branch 13 → 21 taken 2683969 times.
3856080 if (sl->mb_skip_run--) {
707
4/4
✓ Branch 14 → 15 taken 11109 times.
✓ Branch 14 → 19 taken 1161002 times.
✓ Branch 15 → 16 taken 5515 times.
✓ Branch 15 → 19 taken 5594 times.
1172111 if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {
708
2/2
✓ Branch 16 → 17 taken 2894 times.
✓ Branch 16 → 19 taken 2621 times.
5515 if (sl->mb_skip_run == 0)
709 2894 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
710 }
711 1172111 decode_mb_skip(h, sl);
712 1172111 return 0;
713 }
714 }
715
2/2
✓ Branch 21 → 22 taken 497835 times.
✓ Branch 21 → 25 taken 3293078 times.
3790913 if (FRAME_MBAFF(h)) {
716
2/2
✓ Branch 22 → 23 taken 248957 times.
✓ Branch 22 → 25 taken 248878 times.
497835 if ((sl->mb_y & 1) == 0)
717 248957 sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb);
718 }
719
720 3790913 sl->prev_mb_skipped = 0;
721
722 3790913 mb_type= get_ue_golomb(&sl->gb);
723
2/2
✓ Branch 26 → 27 taken 909135 times.
✓ Branch 26 → 30 taken 2881778 times.
3790913 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
724
2/2
✓ Branch 27 → 28 taken 768088 times.
✓ Branch 27 → 29 taken 141047 times.
909135 if(mb_type < 23){
725 768088 partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;
726 768088 mb_type = ff_h264_b_mb_type_info[mb_type].type;
727 }else{
728 141047 mb_type -= 23;
729 141047 goto decode_intra_mb;
730 }
731
2/2
✓ Branch 30 → 31 taken 1774834 times.
✓ Branch 30 → 34 taken 1106944 times.
2881778 } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {
732
2/2
✓ Branch 31 → 32 taken 1496091 times.
✓ Branch 31 → 33 taken 278743 times.
1774834 if(mb_type < 5){
733 1496091 partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;
734 1496091 mb_type = ff_h264_p_mb_type_info[mb_type].type;
735 }else{
736 278743 mb_type -= 5;
737 278743 goto decode_intra_mb;
738 }
739 }else{
740 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_I);
741
1/4
✓ Branch 34 → 35 taken 1106944 times.
✗ Branch 34 → 36 not taken.
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
1106944 if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)
742 ✗ mb_type--;
743 1106944 decode_intra_mb:
744
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 43 taken 1526734 times.
1526734 if(mb_type > 25){
745 ✗ av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y);
746 ✗ return -1;
747 }
748 1526734 partition_count=0;
749 1526734 cbp = ff_h264_i_mb_type_info[mb_type].cbp;
750 1526734 sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;
751 1526734 mb_type = ff_h264_i_mb_type_info[mb_type].type;
752 }
753
754
2/2
✓ Branch 44 → 45 taken 981328 times.
✓ Branch 44 → 46 taken 2809585 times.
3790913 if (MB_FIELD(sl))
755 981328 mb_type |= MB_TYPE_INTERLACED;
756
757 3790913 h->slice_table[mb_xy] = sl->slice_num;
758
759
2/2
✓ Branch 46 → 47 taken 17446 times.
✓ Branch 46 → 57 taken 3773467 times.
3790913 if(IS_INTRA_PCM(mb_type)){
760 17446 const int mb_size = ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] *
761 17446 h->ps.sps->bit_depth_luma;
762 17446 GetBitContext *gb = mb_residual_gb(h, sl, mb_type); // samples are category 3
763
764
1/2
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 taken 17446 times.
17446 if (!gb)
765 ✗ return AVERROR_INVALIDDATA;
766
767 // We assume these blocks are very rare so we do not optimize it.
768 17446 sl->intra_pcm_ptr = align_get_bits(gb);
769
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 55 taken 17446 times.
17446 if (get_bits_left(gb) < mb_size) {
770 ✗ av_log(h->avctx, AV_LOG_ERROR, "Not enough data for an intra PCM block.\n");
771 ✗ return AVERROR_INVALIDDATA;
772 }
773 17446 skip_bits_long(gb, mb_size);
774
775 // In deblocking, the quantizer is 0
776 17446 h->cur_pic.qscale_table[mb_xy] = 0;
777 // All coeffs are present
778 17446 memset(h->non_zero_count[mb_xy], 16, 48);
779
780 17446 h->cur_pic.mb_type[mb_xy] = mb_type;
781 17446 return 0;
782 }
783
784 3773467 fill_decode_neighbors(h, sl, mb_type);
785 3773467 fill_decode_caches(h, sl, mb_type);
786
787 //mb_pred
788
2/2
✓ Branch 59 → 60 taken 1509288 times.
✓ Branch 59 → 90 taken 2264179 times.
3773467 if(IS_INTRA(mb_type)){
789 int pred_mode;
790 // init_top_left_availability(h);
791
2/2
✓ Branch 60 → 61 taken 1204283 times.
✓ Branch 60 → 80 taken 305005 times.
1509288 if(IS_INTRA4x4(mb_type)){
792 int i;
793 1204283 int di = 1;
794
4/4
✓ Branch 61 → 62 taken 855937 times.
✓ Branch 61 → 65 taken 348346 times.
✓ Branch 63 → 64 taken 541711 times.
✓ Branch 63 → 65 taken 314226 times.
1204283 if(dct8x8_allowed && get_bits1(&sl->gb)){
795 541711 mb_type |= MB_TYPE_8x8DCT;
796 541711 di = 4;
797 }
798
799 // fill_intra4x4_pred_table(h);
800
2/2
✓ Branch 75 → 66 taken 12767996 times.
✓ Branch 75 → 76 taken 1204283 times.
13972279 for(i=0; i<16; i+=di){
801 12767996 int mode = pred_intra_mode(h, sl, i);
802
803
2/2
✓ Branch 68 → 69 taken 6809950 times.
✓ Branch 68 → 71 taken 5958046 times.
12767996 if(!get_bits1(&sl->gb)){
804 6809950 const int rem_mode= get_bits(&sl->gb, 3);
805 6809950 mode = rem_mode + (rem_mode >= mode);
806 }
807
808
2/2
✓ Branch 71 → 72 taken 2166844 times.
✓ Branch 71 → 73 taken 10601152 times.
12767996 if(di==4)
809 2166844 fill_rectangle(&sl->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1);
810 else
811 10601152 sl->intra4x4_pred_mode_cache[scan8[i]] = mode;
812 }
813 1204283 write_back_intra_pred_mode(h, sl);
814
1/2
✗ Branch 78 → 79 not taken.
✓ Branch 78 → 83 taken 1204283 times.
1204283 if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,
815 1204283 sl->top_samples_available, sl->left_samples_available) < 0)
816 ✗ return -1;
817 }else{
818 610010 sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
819 305005 sl->left_samples_available, sl->intra16x16_pred_mode, 0);
820
1/2
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 305005 times.
305005 if (sl->intra16x16_pred_mode < 0)
821 ✗ return -1;
822 }
823
2/2
✓ Branch 83 → 84 taken 1482159 times.
✓ Branch 83 → 89 taken 27129 times.
1509288 if(decode_chroma){
824 1482159 pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,
825 1482159 sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1);
826
1/2
✗ Branch 86 → 87 not taken.
✓ Branch 86 → 88 taken 1482159 times.
1482159 if(pred_mode < 0)
827 ✗ return -1;
828 1482159 sl->chroma_pred_mode = pred_mode;
829 } else {
830 27129 sl->chroma_pred_mode = DC_128_PRED8x8;
831 }
832
2/2
✓ Branch 90 → 91 taken 519573 times.
✓ Branch 90 → 161 taken 1744606 times.
2264179 }else if(partition_count==4){
833 int i, j, sub_partition_count[4], list, ref[2][4];
834
835
2/2
✓ Branch 91 → 92 taken 178782 times.
✓ Branch 91 → 102 taken 340791 times.
519573 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
836
2/2
✓ Branch 98 → 93 taken 715128 times.
✓ Branch 98 → 99 taken 178782 times.
893910 for(i=0; i<4; i++){
837 715128 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
838
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 97 taken 715128 times.
715128 if(sl->sub_mb_type[i] >=13){
839 ✗ av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);
840 ✗ return -1;
841 }
842 715128 sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
843 715128 sl->sub_mb_type[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;
844 }
845
2/2
✓ Branch 99 → 100 taken 56302 times.
✓ Branch 99 → 109 taken 122480 times.
178782 if( IS_DIRECT(sl->sub_mb_type[0]|sl->sub_mb_type[1]|sl->sub_mb_type[2]|sl->sub_mb_type[3])) {
846 56302 ff_h264_pred_direct_motion(h, sl, &mb_type);
847 56302 sl->ref_cache[0][scan8[4]] =
848 56302 sl->ref_cache[1][scan8[4]] =
849 56302 sl->ref_cache[0][scan8[12]] =
850 56302 sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
851 }
852 }else{
853 av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ?
854
2/2
✓ Branch 108 → 103 taken 1363164 times.
✓ Branch 108 → 109 taken 340791 times.
1703955 for(i=0; i<4; i++){
855 1363164 sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb);
856
1/2
✗ Branch 104 → 105 not taken.
✓ Branch 104 → 107 taken 1363164 times.
1363164 if(sl->sub_mb_type[i] >=4){
857 ✗ av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y);
858 ✗ return -1;
859 }
860 1363164 sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;
861 1363164 sl->sub_mb_type[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;
862 }
863 }
864
865
2/2
✓ Branch 131 → 110 taken 698355 times.
✓ Branch 131 → 132 taken 519573 times.
1217928 for (list = 0; list < sl->list_count; list++) {
866
2/2
✓ Branch 110 → 111 taken 574146 times.
✓ Branch 110 → 112 taken 124209 times.
698355 int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(sl);
867
2/2
✓ Branch 129 → 114 taken 2793420 times.
✓ Branch 129 → 130 taken 698355 times.
3491775 for(i=0; i<4; i++){
868
2/2
✓ Branch 114 → 115 taken 233328 times.
✓ Branch 114 → 116 taken 2560092 times.
2793420 if(IS_DIRECT(sl->sub_mb_type[i])) continue;
869
2/2
✓ Branch 116 → 117 taken 2231632 times.
✓ Branch 116 → 127 taken 328460 times.
2560092 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
870 unsigned int tmp;
871
2/2
✓ Branch 117 → 118 taken 786991 times.
✓ Branch 117 → 119 taken 1444641 times.
2231632 if(ref_count == 1){
872 786991 tmp= 0;
873
2/2
✓ Branch 119 → 120 taken 454532 times.
✓ Branch 119 → 122 taken 990109 times.
1444641 }else if(ref_count == 2){
874 454532 tmp= get_bits1(&sl->gb)^1;
875 }else{
876 990109 tmp= get_ue_golomb_31(&sl->gb);
877
1/2
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 126 taken 990109 times.
990109 if(tmp>=ref_count){
878 ✗ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
879 ✗ return -1;
880 }
881 }
882 2231632 ref[list][i]= tmp;
883 }else{
884 //FIXME
885 328460 ref[list][i] = -1;
886 }
887 }
888 }
889
890
2/2
✓ Branch 132 → 133 taken 51527 times.
✓ Branch 132 → 134 taken 468046 times.
519573 if(dct8x8_allowed)
891 51527 dct8x8_allowed = get_dct8x8_allowed(h, sl);
892
893
2/2
✓ Branch 158 → 135 taken 698355 times.
✓ Branch 158 → 159 taken 519573 times.
1217928 for (list = 0; list < sl->list_count; list++) {
894
2/2
✓ Branch 156 → 136 taken 2793420 times.
✓ Branch 156 → 157 taken 698355 times.
3491775 for(i=0; i<4; i++){
895
2/2
✓ Branch 136 → 137 taken 233328 times.
✓ Branch 136 → 138 taken 2560092 times.
2793420 if(IS_DIRECT(sl->sub_mb_type[i])) {
896 233328 sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ];
897 233328 continue;
898 }
899 2560092 sl->ref_cache[list][ scan8[4*i] ]=sl->ref_cache[list][ scan8[4*i]+1 ]=
900 2560092 sl->ref_cache[list][ scan8[4*i]+8 ]=sl->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
901
902
2/2
✓ Branch 138 → 139 taken 2231632 times.
✓ Branch 138 → 154 taken 328460 times.
2560092 if(IS_DIR(sl->sub_mb_type[i], 0, list)){
903 2231632 const int sub_mb_type= sl->sub_mb_type[i];
904
2/2
✓ Branch 139 → 140 taken 1684756 times.
✓ Branch 139 → 141 taken 546876 times.
2231632 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
905
2/2
✓ Branch 153 → 143 taken 3695452 times.
✓ Branch 153 → 155 taken 2231632 times.
5927084 for(j=0; j<sub_partition_count[i]; j++){
906 int mx, my;
907 3695452 const int index= 4*i + block_width*j;
908 3695452 int16_t (* mv_cache)[2]= &sl->mv_cache[list][ scan8[index] ];
909 3695452 pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);
910 3695452 mx += (unsigned)get_se_golomb(&sl->gb);
911 3695452 my += (unsigned)get_se_golomb(&sl->gb);
912 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
913
914
2/2
✓ Branch 146 → 147 taken 1172332 times.
✓ Branch 146 → 148 taken 2523120 times.
3695452 if(IS_SUB_8X8(sub_mb_type)){
915 1172332 mv_cache[ 1 ][0]=
916 1172332 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
917 1172332 mv_cache[ 1 ][1]=
918 1172332 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
919
2/2
✓ Branch 148 → 149 taken 1024848 times.
✓ Branch 148 → 150 taken 1498272 times.
2523120 }else if(IS_SUB_8X4(sub_mb_type)){
920 1024848 mv_cache[ 1 ][0]= mx;
921 1024848 mv_cache[ 1 ][1]= my;
922
2/2
✓ Branch 150 → 151 taken 689232 times.
✓ Branch 150 → 152 taken 809040 times.
1498272 }else if(IS_SUB_4X8(sub_mb_type)){
923 689232 mv_cache[ 8 ][0]= mx;
924 689232 mv_cache[ 8 ][1]= my;
925 }
926 3695452 mv_cache[ 0 ][0]= mx;
927 3695452 mv_cache[ 0 ][1]= my;
928 }
929 }else{
930 328460 uint32_t *p= (uint32_t *)&sl->mv_cache[list][ scan8[4*i] ][0];
931 328460 p[0] = p[1]=
932 328460 p[8] = p[9]= 0;
933 }
934 }
935 }
936
2/2
✓ Branch 161 → 162 taken 139281 times.
✓ Branch 161 → 164 taken 1605325 times.
1744606 }else if(IS_DIRECT(mb_type)){
937 139281 ff_h264_pred_direct_motion(h, sl, &mb_type);
938 139281 dct8x8_allowed &= h->ps.sps->direct_8x8_inference_flag;
939 }else{
940 int list, mx, my, i;
941 //FIXME we should set ref_idx_l? to 0 if we use that later ...
942
2/2
✓ Branch 164 → 165 taken 1092432 times.
✓ Branch 164 → 188 taken 512893 times.
1605325 if(IS_16X16(mb_type)){
943
2/2
✓ Branch 178 → 166 taken 1362016 times.
✓ Branch 178 → 179 taken 1092432 times.
2454448 for (list = 0; list < sl->list_count; list++) {
944 unsigned int val;
945
2/2
✓ Branch 166 → 167 taken 1149861 times.
✓ Branch 166 → 177 taken 212155 times.
1362016 if (IS_DIR(mb_type, 0, list)) {
946 1149861 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
947
2/2
✓ Branch 167 → 168 taken 649109 times.
✓ Branch 167 → 169 taken 500752 times.
1149861 if (rc == 1) {
948 649109 val = 0;
949
2/2
✓ Branch 169 → 170 taken 135596 times.
✓ Branch 169 → 172 taken 365156 times.
500752 } else if (rc == 2) {
950 135596 val = get_bits1(&sl->gb)^1;
951 } else {
952 365156 val = get_ue_golomb_31(&sl->gb);
953
1/2
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 176 taken 365156 times.
365156 if (val >= rc) {
954 ✗ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
955 ✗ return -1;
956 }
957 }
958 1149861 fill_rectangle(&sl->ref_cache[list][scan8[0]], 4, 4, 8, val, 1);
959 }
960 }
961
2/2
✓ Branch 187 → 180 taken 1362016 times.
✓ Branch 187 → 251 taken 1092432 times.
2454448 for (list = 0; list < sl->list_count; list++) {
962
2/2
✓ Branch 180 → 181 taken 1149861 times.
✓ Branch 180 → 186 taken 212155 times.
1362016 if(IS_DIR(mb_type, 0, list)){
963 1149861 pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);
964 1149861 mx += (unsigned)get_se_golomb(&sl->gb);
965 1149861 my += (unsigned)get_se_golomb(&sl->gb);
966 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
967
968 1149861 fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
969 }
970 }
971 }
972
2/2
✓ Branch 188 → 189 taken 271583 times.
✓ Branch 188 → 220 taken 241310 times.
512893 else if(IS_16X8(mb_type)){
973
2/2
✓ Branch 206 → 190 taken 371083 times.
✓ Branch 206 → 207 taken 271583 times.
642666 for (list = 0; list < sl->list_count; list++) {
974
2/2
✓ Branch 204 → 191 taken 742166 times.
✓ Branch 204 → 205 taken 371083 times.
1113249 for (i = 0; i < 2; i++) {
975 unsigned int val;
976
2/2
✓ Branch 191 → 192 taken 586310 times.
✓ Branch 191 → 201 taken 155856 times.
742166 if (IS_DIR(mb_type, i, list)) {
977 586310 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
978
2/2
✓ Branch 192 → 193 taken 242913 times.
✓ Branch 192 → 194 taken 343397 times.
586310 if (rc == 1) {
979 242913 val = 0;
980
2/2
✓ Branch 194 → 195 taken 80309 times.
✓ Branch 194 → 197 taken 263088 times.
343397 } else if (rc == 2) {
981 80309 val = get_bits1(&sl->gb)^1;
982 } else {
983 263088 val = get_ue_golomb_31(&sl->gb);
984
1/2
✗ Branch 198 → 199 not taken.
✓ Branch 198 → 202 taken 263088 times.
263088 if (val >= rc) {
985 ✗ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
986 ✗ return -1;
987 }
988 }
989 } else
990 155856 val = LIST_NOT_USED & 0xFF;
991 742166 fill_rectangle(&sl->ref_cache[list][scan8[0] + 16*i], 4, 2, 8, val, 1);
992 }
993 }
994
2/2
✓ Branch 219 → 208 taken 371083 times.
✓ Branch 219 → 251 taken 271583 times.
642666 for (list = 0; list < sl->list_count; list++) {
995
2/2
✓ Branch 217 → 209 taken 742166 times.
✓ Branch 217 → 218 taken 371083 times.
1113249 for(i=0; i<2; i++){
996 unsigned int val;
997
2/2
✓ Branch 209 → 210 taken 586310 times.
✓ Branch 209 → 214 taken 155856 times.
742166 if(IS_DIR(mb_type, i, list)){
998 586310 pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);
999 586310 mx += (unsigned)get_se_golomb(&sl->gb);
1000 586310 my += (unsigned)get_se_golomb(&sl->gb);
1001 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
1002
1003 586310 val= pack16to32(mx,my);
1004 }else
1005 155856 val=0;
1006 742166 fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
1007 }
1008 }
1009 }else{
1010 av_assert2(IS_8X16(mb_type));
1011
2/2
✓ Branch 237 → 221 taken 322251 times.
✓ Branch 237 → 238 taken 241310 times.
563561 for (list = 0; list < sl->list_count; list++) {
1012
2/2
✓ Branch 235 → 222 taken 644502 times.
✓ Branch 235 → 236 taken 322251 times.
966753 for (i = 0; i < 2; i++) {
1013 unsigned int val;
1014
2/2
✓ Branch 222 → 223 taken 516179 times.
✓ Branch 222 → 232 taken 128323 times.
644502 if (IS_DIR(mb_type, i, list)) { //FIXME optimize
1015 516179 unsigned rc = sl->ref_count[list] << MB_MBAFF(sl);
1016
2/2
✓ Branch 223 → 224 taken 214124 times.
✓ Branch 223 → 225 taken 302055 times.
516179 if (rc == 1) {
1017 214124 val = 0;
1018
2/2
✓ Branch 225 → 226 taken 82808 times.
✓ Branch 225 → 228 taken 219247 times.
302055 } else if (rc == 2) {
1019 82808 val = get_bits1(&sl->gb)^1;
1020 } else {
1021 219247 val = get_ue_golomb_31(&sl->gb);
1022
1/2
✗ Branch 229 → 230 not taken.
✓ Branch 229 → 233 taken 219247 times.
219247 if (val >= rc) {
1023 ✗ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
1024 ✗ return -1;
1025 }
1026 }
1027 } else
1028 128323 val = LIST_NOT_USED & 0xFF;
1029 644502 fill_rectangle(&sl->ref_cache[list][scan8[0] + 2*i], 2, 4, 8, val, 1);
1030 }
1031 }
1032
2/2
✓ Branch 250 → 239 taken 322251 times.
✓ Branch 250 → 251 taken 241310 times.
563561 for (list = 0; list < sl->list_count; list++) {
1033
2/2
✓ Branch 248 → 240 taken 644502 times.
✓ Branch 248 → 249 taken 322251 times.
966753 for(i=0; i<2; i++){
1034 unsigned int val;
1035
2/2
✓ Branch 240 → 241 taken 516179 times.
✓ Branch 240 → 245 taken 128323 times.
644502 if(IS_DIR(mb_type, i, list)){
1036 516179 pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
1037 516179 mx += (unsigned)get_se_golomb(&sl->gb);
1038 516179 my += (unsigned)get_se_golomb(&sl->gb);
1039 ff_tlog(h->avctx, "final mv:%d %d\n", mx, my);
1040
1041 516179 val= pack16to32(mx,my);
1042 }else
1043 128323 val=0;
1044 644502 fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);
1045 }
1046 }
1047 }
1048 }
1049
1050
2/2
✓ Branch 253 → 254 taken 2264179 times.
✓ Branch 253 → 255 taken 1509288 times.
3773467 if(IS_INTER(mb_type))
1051 2264179 write_back_motion(h, sl, mb_type);
1052
1053
2/2
✓ Branch 255 → 256 taken 3468462 times.
✓ Branch 255 → 270 taken 305005 times.
3773467 if(!IS_INTRA16x16(mb_type)){
1054 3468462 cbp= get_ue_golomb(&sl->gb);
1055
1056
2/2
✓ Branch 257 → 258 taken 3429112 times.
✓ Branch 257 → 264 taken 39350 times.
3468462 if(decode_chroma){
1057
1/2
✗ Branch 258 → 259 not taken.
✓ Branch 258 → 261 taken 3429112 times.
3429112 if(cbp > 47){
1058 ✗ av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1059 ✗ return -1;
1060 }
1061
2/2
✓ Branch 261 → 262 taken 1180134 times.
✓ Branch 261 → 263 taken 2248978 times.
3429112 if (IS_INTRA4x4(mb_type))
1062 1180134 cbp = ff_h264_golomb_to_intra4x4_cbp[cbp];
1063 else
1064 2248978 cbp = ff_h264_golomb_to_inter_cbp[cbp];
1065 }else{
1066
1/2
✗ Branch 264 → 265 not taken.
✓ Branch 264 → 267 taken 39350 times.
39350 if(cbp > 15){
1067 ✗ av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y);
1068 ✗ return -1;
1069 }
1070
2/2
✓ Branch 267 → 268 taken 24149 times.
✓ Branch 267 → 269 taken 15201 times.
39350 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
1071 15201 else cbp= golomb_to_inter_cbp_gray[cbp];
1072 }
1073 } else {
1074
3/4
✓ Branch 270 → 271 taken 2980 times.
✓ Branch 270 → 274 taken 302025 times.
✗ Branch 271 → 272 not taken.
✓ Branch 271 → 274 taken 2980 times.
305005 if (!decode_chroma && cbp>15) {
1075 ✗ av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n");
1076 ✗ return AVERROR_INVALIDDATA;
1077 }
1078 }
1079
1080
6/6
✓ Branch 274 → 275 taken 1350186 times.
✓ Branch 274 → 279 taken 2423281 times.
✓ Branch 275 → 276 taken 1155963 times.
✓ Branch 275 → 279 taken 194223 times.
✓ Branch 276 → 277 taken 275548 times.
✓ Branch 276 → 279 taken 880415 times.
3773467 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
1081 275548 mb_type |= MB_TYPE_8x8DCT*get_bits1(&sl->gb);
1082 }
1083 3773467 sl->cbp=
1084 3773467 h->cbp_table[mb_xy]= cbp;
1085 3773467 h->cur_pic.mb_type[mb_xy] = mb_type;
1086
1087
4/4
✓ Branch 279 → 280 taken 898234 times.
✓ Branch 279 → 281 taken 2875233 times.
✓ Branch 280 → 281 taken 171740 times.
✓ Branch 280 → 346 taken 726494 times.
6820425 if(cbp || IS_INTRA16x16(mb_type)){
1088 int i4x4, i8x8, chroma_idx;
1089 int dquant;
1090 int ret;
1091 3046973 GetBitContext *gb = mb_residual_gb(h, sl, mb_type);
1092 const uint8_t *scan, *scan8x8;
1093 3046973 const int max_qp = 51 + 6 * (h->ps.sps->bit_depth_luma - 8);
1094
1095
1/2
✗ Branch 282 → 283 not taken.
✓ Branch 282 → 284 taken 3046973 times.
3046973 if (!gb)
1096 ✗ return AVERROR_INVALIDDATA;
1097
1098 3046973 dquant= get_se_golomb(&sl->gb);
1099
1100 3046973 sl->qscale += (unsigned)dquant;
1101
1102
2/2
✓ Branch 285 → 286 taken 8070 times.
✓ Branch 285 → 292 taken 3038903 times.
3046973 if (((unsigned)sl->qscale) > max_qp){
1103
2/2
✓ Branch 286 → 287 taken 3860 times.
✓ Branch 286 → 288 taken 4210 times.
8070 if (sl->qscale < 0) sl->qscale += max_qp + 1;
1104 4210 else sl->qscale -= max_qp+1;
1105
1/2
✗ Branch 289 → 290 not taken.
✓ Branch 289 → 292 taken 8070 times.
8070 if (((unsigned)sl->qscale) > max_qp){
1106 ✗ av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, sl->mb_x, sl->mb_y);
1107 ✗ sl->qscale = max_qp;
1108 ✗ return -1;
1109 }
1110 }
1111
1112 3046973 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);
1113 3046973 sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);
1114
1115
2/2
✓ Branch 294 → 295 taken 824163 times.
✓ Branch 294 → 301 taken 2222810 times.
3046973 if(IS_INTERLACED(mb_type)){
1116
2/2
✓ Branch 295 → 296 taken 824002 times.
✓ Branch 295 → 297 taken 161 times.
824163 scan8x8 = sl->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
1117
2/2
✓ Branch 298 → 299 taken 824002 times.
✓ Branch 298 → 300 taken 161 times.
824163 scan = sl->qscale ? h->field_scan : h->field_scan_q0;
1118 }else{
1119
2/2
✓ Branch 301 → 302 taken 2221921 times.
✓ Branch 301 → 303 taken 889 times.
2222810 scan8x8 = sl->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
1120
2/2
✓ Branch 304 → 305 taken 2221921 times.
✓ Branch 304 → 306 taken 889 times.
2222810 scan = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
1121 }
1122
1123
2/2
✓ Branch 308 → 309 taken 9 times.
✓ Branch 308 → 310 taken 3046964 times.
3046973 if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) {
1124 9 return -1;
1125 }
1126 3046964 h->cbp_table[mb_xy] |= ret << 12;
1127
1/2
✗ Branch 310 → 311 not taken.
✓ Branch 310 → 317 taken 3046964 times.
3046964 if (CHROMA444(h)) {
1128
0/2
✗ Branch 312 → 313 not taken.
✗ Branch 312 → 314 not taken.
✗ if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ) {
1129 ✗ return -1;
1130 }
1131
0/2
✗ Branch 315 → 316 not taken.
✗ Branch 315 → 345 not taken.
✗ if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ) {
1132 ✗ return -1;
1133 }
1134 } else {
1135 3046964 const int num_c8x8 = h->ps.sps->chroma_format_idc;
1136
1137
2/2
✓ Branch 317 → 318 taken 1677901 times.
✓ Branch 317 → 327 taken 1369063 times.
3046964 if(cbp&0x30){
1138
2/2
✓ Branch 326 → 319 taken 3355802 times.
✓ Branch 326 → 327 taken 1677901 times.
5033703 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1139
1/2
✗ Branch 323 → 324 not taken.
✓ Branch 323 → 325 taken 3355802 times.
3355802 if (decode_residual(h, sl, gb, sl->mb + ((256 + 16*16*chroma_idx) << pixel_shift),
1140 CHROMA_DC_BLOCK_INDEX + chroma_idx,
1141
2/2
✓ Branch 319 → 320 taken 579058 times.
✓ Branch 319 → 321 taken 2776744 times.
3355802 CHROMA422(h) ? ff_h264_chroma422_dc_scan : ff_h264_chroma_dc_scan,
1142 NULL, 4 * num_c8x8) < 0) {
1143 ✗ return -1;
1144 }
1145 }
1146
1147
2/2
✓ Branch 327 → 328 taken 1042064 times.
✓ Branch 327 → 343 taken 2004900 times.
3046964 if(cbp&0x20){
1148
2/2
✓ Branch 342 → 329 taken 2084127 times.
✓ Branch 342 → 345 taken 1042058 times.
3126185 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1149
2/2
✓ Branch 329 → 330 taken 1214793 times.
✓ Branch 329 → 331 taken 869334 times.
2084127 const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]];
1150 2084127 int16_t *mb = sl->mb + (16*(16 + 16*chroma_idx) << pixel_shift);
1151
2/2
✓ Branch 340 → 333 taken 2471271 times.
✓ Branch 340 → 341 taken 2084121 times.
4555392 for (i8x8 = 0; i8x8<num_c8x8; i8x8++) {
1152
2/2
✓ Branch 338 → 334 taken 9885078 times.
✓ Branch 338 → 339 taken 2471265 times.
12356343 for (i4x4 = 0; i4x4 < 4; i4x4++) {
1153 9885078 const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;
1154
2/2
✓ Branch 335 → 336 taken 6 times.
✓ Branch 335 → 337 taken 9885072 times.
9885078 if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0)
1155 6 return -1;
1156 9885072 mb += 16 << pixel_shift;
1157 }
1158 }
1159 }
1160 }else{
1161 2004900 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1162 2004900 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1163 }
1164 }
1165 }else{
1166 726494 fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
1167 726494 fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
1168 726494 fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
1169 }
1170 3773452 h->cur_pic.qscale_table[mb_xy] = sl->qscale;
1171 3773452 write_back_non_zero_count(h, sl);
1172
1173 3773452 return 0;
1174 }
1175