FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/svq3.c
Date: 2022-01-16 20:33:26
Exec Total Coverage
Lines: 680 827 82.2%
Branches: 437 563 77.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2003 The FFmpeg Project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /*
22 * How to use this decoder:
23 * SVQ3 data is transported within Apple Quicktime files. Quicktime files
24 * have stsd atoms to describe media trak properties. A stsd atom for a
25 * video trak contains 1 or more ImageDescription atoms. These atoms begin
26 * with the 4-byte length of the atom followed by the codec fourcc. Some
27 * decoders need information in this atom to operate correctly. Such
28 * is the case with SVQ3. In order to get the best use out of this decoder,
29 * the calling app must make the SVQ3 ImageDescription atom available
30 * via the AVCodecContext's extradata[_size] field:
31 *
32 * AVCodecContext.extradata = pointer to ImageDescription, first characters
33 * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
34 * AVCodecContext.extradata_size = size of ImageDescription atom memory
35 * buffer (which will be the same as the ImageDescription atom size field
36 * from the QT file, minus 4 bytes since the length is missing)
37 *
38 * You will know you have these parameters passed correctly when the decoder
39 * correctly decodes this file:
40 * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
41 */
42
43 #include <inttypes.h>
44
45 #include "libavutil/attributes.h"
46 #include "libavutil/crc.h"
47 #include "libavutil/mem_internal.h"
48
49 #include "internal.h"
50 #include "avcodec.h"
51 #include "mpegutils.h"
52 #include "h264dec.h"
53 #include "h264data.h"
54 #include "golomb.h"
55 #include "hpeldsp.h"
56 #include "mathops.h"
57 #include "rectangle.h"
58 #include "tpeldsp.h"
59
60 #if CONFIG_ZLIB
61 #include <zlib.h>
62 #endif
63
64 #include "svq1.h"
65
66 /**
67 * @file
68 * svq3 decoder.
69 */
70
71 typedef struct SVQ3Frame {
72 AVFrame *f;
73
74 int16_t (*motion_val_buf[2])[2];
75 int16_t (*motion_val[2])[2];
76
77 uint32_t *mb_type_buf, *mb_type;
78 } SVQ3Frame;
79
80 typedef struct SVQ3Context {
81 AVCodecContext *avctx;
82
83 H264DSPContext h264dsp;
84 H264PredContext hpc;
85 HpelDSPContext hdsp;
86 TpelDSPContext tdsp;
87 VideoDSPContext vdsp;
88
89 SVQ3Frame *cur_pic;
90 SVQ3Frame *next_pic;
91 SVQ3Frame *last_pic;
92 GetBitContext gb;
93 GetBitContext gb_slice;
94 uint8_t *slice_buf;
95 unsigned slice_buf_size;
96 int halfpel_flag;
97 int thirdpel_flag;
98 int has_watermark;
99 uint32_t watermark_key;
100 int adaptive_quant;
101 int h_edge_pos;
102 int v_edge_pos;
103 int last_frame_output;
104 int slice_num;
105 int qscale;
106 int cbp;
107 int frame_num;
108 int frame_num_offset;
109 int prev_frame_num_offset;
110 int prev_frame_num;
111
112 enum AVPictureType pict_type;
113 enum AVPictureType slice_type;
114 int low_delay;
115
116 int mb_x, mb_y;
117 int mb_xy;
118 int mb_width, mb_height;
119 int mb_stride, mb_num;
120 int b_stride;
121
122 uint32_t *mb2br_xy;
123
124 int chroma_pred_mode;
125 int intra16x16_pred_mode;
126
127 int8_t intra4x4_pred_mode_cache[5 * 8];
128 int8_t (*intra4x4_pred_mode);
129
130 unsigned int top_samples_available;
131 unsigned int left_samples_available;
132
133 uint8_t *edge_emu_buffer;
134
135 DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
136 DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
137 DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2];
138 DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2];
139 DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
140 uint32_t dequant4_coeff[QP_MAX_NUM + 1][16];
141 int block_offset[2 * (16 * 3)];
142 SVQ3Frame frames[3];
143 } SVQ3Context;
144
145 #define FULLPEL_MODE 1
146 #define HALFPEL_MODE 2
147 #define THIRDPEL_MODE 3
148 #define PREDICT_MODE 4
149
150 /* dual scan (from some older H.264 draft)
151 * o-->o-->o o
152 * | /|
153 * o o o / o
154 * | / | |/ |
155 * o o o o
156 * /
157 * o-->o-->o-->o
158 */
159 static const uint8_t svq3_scan[16] = {
160 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
161 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
162 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
163 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
164 };
165
166 static const uint8_t luma_dc_zigzag_scan[16] = {
167 0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
168 3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
169 1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
170 3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
171 };
172
173 static const uint8_t svq3_pred_0[25][2] = {
174 { 0, 0 },
175 { 1, 0 }, { 0, 1 },
176 { 0, 2 }, { 1, 1 }, { 2, 0 },
177 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
178 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
179 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
180 { 2, 4 }, { 3, 3 }, { 4, 2 },
181 { 4, 3 }, { 3, 4 },
182 { 4, 4 }
183 };
184
185 static const int8_t svq3_pred_1[6][6][5] = {
186 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
187 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
188 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
189 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
190 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
191 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
192 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
193 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
194 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
195 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
196 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
197 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
198 };
199
200 static const struct {
201 uint8_t run;
202 uint8_t level;
203 } svq3_dct_tables[2][16] = {
204 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
205 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
206 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
207 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
208 };
209
210 static const uint32_t svq3_dequant_coeff[32] = {
211 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
212 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
213 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
214 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
215 };
216
217 2537 static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
218 {
219 2537 const unsigned qmul = svq3_dequant_coeff[qp];
220 #define stride 16
221 int i;
222 int temp[16];
223 static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };
224
225
2/2
✓ Branch 0 taken 10148 times.
✓ Branch 1 taken 2537 times.
12685 for (i = 0; i < 4; i++) {
226 10148 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
227 10148 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
228 10148 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
229 10148 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
230
231 10148 temp[4 * i + 0] = z0 + z3;
232 10148 temp[4 * i + 1] = z1 + z2;
233 10148 temp[4 * i + 2] = z1 - z2;
234 10148 temp[4 * i + 3] = z0 - z3;
235 }
236
237
2/2
✓ Branch 0 taken 10148 times.
✓ Branch 1 taken 2537 times.
12685 for (i = 0; i < 4; i++) {
238 10148 const int offset = x_offset[i];
239 10148 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
240 10148 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
241 10148 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
242 10148 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
243
244 10148 output[stride * 0 + offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
245 10148 output[stride * 2 + offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
246 10148 output[stride * 8 + offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
247 10148 output[stride * 10 + offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
248 }
249 2537 }
250 #undef stride
251
252 4012263 static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
253 int stride, int qp, int dc)
254 {
255 4012263 const int qmul = svq3_dequant_coeff[qp];
256 int i;
257
258
2/2
✓ Branch 0 taken 998567 times.
✓ Branch 1 taken 3013696 times.
4012263 if (dc) {
259
2/2
✓ Branch 0 taken 26094 times.
✓ Branch 1 taken 972473 times.
998567 dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
260 972473 : qmul * (block[0] >> 3) / 2);
261 998567 block[0] = 0;
262 }
263
264
2/2
✓ Branch 0 taken 16049052 times.
✓ Branch 1 taken 4012263 times.
20061315 for (i = 0; i < 4; i++) {
265 16049052 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
266 16049052 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
267 16049052 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
268 16049052 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
269
270 16049052 block[0 + 4 * i] = z0 + z3;
271 16049052 block[1 + 4 * i] = z1 + z2;
272 16049052 block[2 + 4 * i] = z1 - z2;
273 16049052 block[3 + 4 * i] = z0 - z3;
274 }
275
276
2/2
✓ Branch 0 taken 16049052 times.
✓ Branch 1 taken 4012263 times.
20061315 for (i = 0; i < 4; i++) {
277 16049052 const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
278 16049052 const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
279 16049052 const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
280 16049052 const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
281 16049052 const int rr = (dc + 0x80000u);
282
283 16049052 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
284 16049052 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
285 16049052 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
286 16049052 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
287 }
288
289 4012263 memset(block, 0, 16 * sizeof(int16_t));
290 4012263 }
291
292 3880617 static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
293 int index, const int type)
294 {
295 static const uint8_t *const scan_patterns[4] = {
296 luma_dc_zigzag_scan, ff_zigzag_scan, svq3_scan, ff_h264_chroma_dc_scan
297 };
298
299 int run, level, sign, limit;
300 unsigned vlc;
301 3880617 const int intra = 3 * type >> 2;
302 3880617 const uint8_t *const scan = scan_patterns[type];
303
304
2/2
✓ Branch 0 taken 4440525 times.
✓ Branch 1 taken 559908 times.
5000433 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
305
2/2
✓ Branch 1 taken 5376506 times.
✓ Branch 2 taken 4440525 times.
9817031 for (; (vlc = get_interleaved_ue_golomb(gb)) != 0; index++) {
306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5376506 times.
5376506 if ((int32_t)vlc < 0)
307 return -1;
308
309
2/2
✓ Branch 0 taken 2636157 times.
✓ Branch 1 taken 2740349 times.
5376506 sign = (vlc & 1) ? 0 : -1;
310 5376506 vlc = vlc + 1 >> 1;
311
312
2/2
✓ Branch 0 taken 249567 times.
✓ Branch 1 taken 5126939 times.
5376506 if (type == 3) {
313
2/2
✓ Branch 0 taken 168966 times.
✓ Branch 1 taken 80601 times.
249567 if (vlc < 3) {
314 168966 run = 0;
315 168966 level = vlc;
316
2/2
✓ Branch 0 taken 34195 times.
✓ Branch 1 taken 46406 times.
80601 } else if (vlc < 4) {
317 34195 run = 1;
318 34195 level = 1;
319 } else {
320 46406 run = vlc & 0x3;
321 46406 level = (vlc + 9 >> 2) - run;
322 }
323 } else {
324
2/2
✓ Branch 0 taken 5034539 times.
✓ Branch 1 taken 92400 times.
5126939 if (vlc < 16U) {
325 5034539 run = svq3_dct_tables[intra][vlc].run;
326 5034539 level = svq3_dct_tables[intra][vlc].level;
327
2/2
✓ Branch 0 taken 8622 times.
✓ Branch 1 taken 83778 times.
92400 } else if (intra) {
328 8622 run = vlc & 0x7;
329
6/6
✓ Branch 0 taken 5363 times.
✓ Branch 1 taken 3259 times.
✓ Branch 2 taken 3384 times.
✓ Branch 3 taken 1979 times.
✓ Branch 4 taken 3276 times.
✓ Branch 5 taken 108 times.
8622 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
330 } else {
331 83778 run = vlc & 0xF;
332
6/6
✓ Branch 0 taken 51409 times.
✓ Branch 1 taken 32369 times.
✓ Branch 2 taken 21765 times.
✓ Branch 3 taken 29644 times.
✓ Branch 4 taken 18682 times.
✓ Branch 5 taken 3083 times.
83778 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
333 }
334 }
335
336
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5376506 times.
5376506 if ((index += run) >= limit)
338 return -1;
339
340 5376506 block[scan[index]] = (level ^ sign) - sign;
341 }
342
343
2/2
✓ Branch 0 taken 3320709 times.
✓ Branch 1 taken 1119816 times.
4440525 if (type != 2) {
344 3320709 break;
345 }
346 }
347
348 3880617 return 0;
349 }
350
351 static av_always_inline int
352 556200 svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C,
353 int i, int list, int part_width)
354 {
355 556200 const int topright_ref = s->ref_cache[list][i - 8 + part_width];
356
357
2/2
✓ Branch 0 taken 474763 times.
✓ Branch 1 taken 81437 times.
556200 if (topright_ref != PART_NOT_AVAILABLE) {
358 474763 *C = s->mv_cache[list][i - 8 + part_width];
359 474763 return topright_ref;
360 } else {
361 81437 *C = s->mv_cache[list][i - 8 - 1];
362 81437 return s->ref_cache[list][i - 8 - 1];
363 }
364 }
365
366 /**
367 * Get the predicted MV.
368 * @param n the block index
369 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
370 * @param mx the x component of the predicted motion vector
371 * @param my the y component of the predicted motion vector
372 */
373 556200 static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n,
374 int part_width, int list,
375 int ref, int *const mx, int *const my)
376 {
377 556200 const int index8 = scan8[n];
378 556200 const int top_ref = s->ref_cache[list][index8 - 8];
379 556200 const int left_ref = s->ref_cache[list][index8 - 1];
380 556200 const int16_t *const A = s->mv_cache[list][index8 - 1];
381 556200 const int16_t *const B = s->mv_cache[list][index8 - 8];
382 const int16_t *C;
383 int diagonal_ref, match_count;
384
385 /* mv_cache
386 * B . . A T T T T
387 * U . . L . . , .
388 * U . . L . . . .
389 * U . . L . . , .
390 * . . . L . . . .
391 */
392
393 556200 diagonal_ref = svq3_fetch_diagonal_mv(s, &C, index8, list, part_width);
394 556200 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
395
2/2
✓ Branch 0 taken 532412 times.
✓ Branch 1 taken 23788 times.
556200 if (match_count > 1) { //most common
396 532412 *mx = mid_pred(A[0], B[0], C[0]);
397 532412 *my = mid_pred(A[1], B[1], C[1]);
398
1/2
✓ Branch 0 taken 23788 times.
✗ Branch 1 not taken.
23788 } else if (match_count == 1) {
399
1/2
✓ Branch 0 taken 23788 times.
✗ Branch 1 not taken.
23788 if (left_ref == ref) {
400 23788 *mx = A[0];
401 23788 *my = A[1];
402 } else if (top_ref == ref) {
403 *mx = B[0];
404 *my = B[1];
405 } else {
406 *mx = C[0];
407 *my = C[1];
408 }
409 } else {
410 if (top_ref == PART_NOT_AVAILABLE &&
411 diagonal_ref == PART_NOT_AVAILABLE &&
412 left_ref != PART_NOT_AVAILABLE) {
413 *mx = A[0];
414 *my = A[1];
415 } else {
416 *mx = mid_pred(A[0], B[0], C[0]);
417 *my = mid_pred(A[1], B[1], C[1]);
418 }
419 }
420 556200 }
421
422 911088 static inline void svq3_mc_dir_part(SVQ3Context *s,
423 int x, int y, int width, int height,
424 int mx, int my, int dxy,
425 int thirdpel, int dir, int avg)
426 {
427
2/2
✓ Branch 0 taken 909957 times.
✓ Branch 1 taken 1131 times.
911088 const SVQ3Frame *pic = (dir == 0) ? s->last_pic : s->next_pic;
428 uint8_t *src, *dest;
429 911088 int i, emu = 0;
430 911088 int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
431 911088 int linesize = s->cur_pic->f->linesize[0];
432 911088 int uvlinesize = s->cur_pic->f->linesize[1];
433
434 911088 mx += x;
435 911088 my += y;
436
437
6/6
✓ Branch 0 taken 904879 times.
✓ Branch 1 taken 6209 times.
✓ Branch 2 taken 873095 times.
✓ Branch 3 taken 31784 times.
✓ Branch 4 taken 869995 times.
✓ Branch 5 taken 3100 times.
911088 if (mx < 0 || mx >= s->h_edge_pos - width - 1 ||
438
2/2
✓ Branch 0 taken 47554 times.
✓ Branch 1 taken 822441 times.
869995 my < 0 || my >= s->v_edge_pos - height - 1) {
439 88647 emu = 1;
440 88647 mx = av_clip(mx, -16, s->h_edge_pos - width + 15);
441 88647 my = av_clip(my, -16, s->v_edge_pos - height + 15);
442 }
443
444 /* form component predictions */
445 911088 dest = s->cur_pic->f->data[0] + x + y * linesize;
446 911088 src = pic->f->data[0] + mx + my * linesize;
447
448
2/2
✓ Branch 0 taken 88647 times.
✓ Branch 1 taken 822441 times.
911088 if (emu) {
449 88647 s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
450 linesize, linesize,
451 width + 1, height + 1,
452 mx, my, s->h_edge_pos, s->v_edge_pos);
453 88647 src = s->edge_emu_buffer;
454 }
455
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 910906 times.
911088 if (thirdpel)
456 (avg ? s->tdsp.avg_tpel_pixels_tab
457
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 169 times.
182 : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, linesize,
458 width, height);
459 else
460 (avg ? s->hdsp.avg_pixels_tab
461
2/2
✓ Branch 0 taken 1068 times.
✓ Branch 1 taken 909838 times.
910906 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, linesize,
462 height);
463
464
1/2
✓ Branch 0 taken 911088 times.
✗ Branch 1 not taken.
911088 if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
465 911088 mx = mx + (mx < (int) x) >> 1;
466 911088 my = my + (my < (int) y) >> 1;
467 911088 width = width >> 1;
468 911088 height = height >> 1;
469 911088 blocksize++;
470
471
2/2
✓ Branch 0 taken 1822176 times.
✓ Branch 1 taken 911088 times.
2733264 for (i = 1; i < 3; i++) {
472 1822176 dest = s->cur_pic->f->data[i] + (x >> 1) + (y >> 1) * uvlinesize;
473 1822176 src = pic->f->data[i] + mx + my * uvlinesize;
474
475
2/2
✓ Branch 0 taken 177294 times.
✓ Branch 1 taken 1644882 times.
1822176 if (emu) {
476 177294 s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
477 uvlinesize, uvlinesize,
478 width + 1, height + 1,
479 177294 mx, my, (s->h_edge_pos >> 1),
480 177294 s->v_edge_pos >> 1);
481 177294 src = s->edge_emu_buffer;
482 }
483
2/2
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 1821812 times.
1822176 if (thirdpel)
484 (avg ? s->tdsp.avg_tpel_pixels_tab
485
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 338 times.
364 : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src,
486 uvlinesize,
487 width, height);
488 else
489 (avg ? s->hdsp.avg_pixels_tab
490
2/2
✓ Branch 0 taken 2136 times.
✓ Branch 1 taken 1819676 times.
1821812 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
491 uvlinesize,
492 height);
493 }
494 }
495 911088 }
496
497 438655 static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
498 int dir, int avg)
499 {
500 int i, j, k, mx, my, dx, dy, x, y;
501
2/2
✓ Branch 0 taken 438633 times.
✓ Branch 1 taken 22 times.
438655 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
502 438655 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
503
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 437869 times.
438655 const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0;
504 438655 const int h_edge_pos = 6 * (s->h_edge_pos - part_width) - extra_width;
505 438655 const int v_edge_pos = 6 * (s->v_edge_pos - part_height) - extra_width;
506
507
2/2
✓ Branch 0 taken 478138 times.
✓ Branch 1 taken 438655 times.
916793 for (i = 0; i < 16; i += part_height)
508
2/2
✓ Branch 0 taken 557238 times.
✓ Branch 1 taken 478138 times.
1035376 for (j = 0; j < 16; j += part_width) {
509 557238 const int b_xy = (4 * s->mb_x + (j >> 2)) +
510 557238 (4 * s->mb_y + (i >> 2)) * s->b_stride;
511 int dxy;
512 557238 x = 16 * s->mb_x + j;
513 557238 y = 16 * s->mb_y + i;
514 557238 k = (j >> 2 & 1) + (i >> 1 & 2) +
515 557238 (j >> 1 & 4) + (i & 8);
516
517
2/2
✓ Branch 0 taken 556200 times.
✓ Branch 1 taken 1038 times.
557238 if (mode != PREDICT_MODE) {
518 556200 svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);
519 } else {
520 1038 mx = s->next_pic->motion_val[0][b_xy][0] * 2;
521 1038 my = s->next_pic->motion_val[0][b_xy][1] * 2;
522
523
2/2
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 519 times.
1038 if (dir == 0) {
524 519 mx = mx * s->frame_num_offset /
525 519 s->prev_frame_num_offset + 1 >> 1;
526 519 my = my * s->frame_num_offset /
527 519 s->prev_frame_num_offset + 1 >> 1;
528 } else {
529 519 mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /
530 519 s->prev_frame_num_offset + 1 >> 1;
531 519 my = my * (s->frame_num_offset - s->prev_frame_num_offset) /
532 519 s->prev_frame_num_offset + 1 >> 1;
533 }
534 }
535
536 /* clip motion vector prediction to frame border */
537 557238 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
538 557238 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
539
540 /* get (optional) motion vector differential */
541
2/2
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 556200 times.
557238 if (mode == PREDICT_MODE) {
542 1038 dx = dy = 0;
543 } else {
544 556200 dy = get_interleaved_se_golomb(&s->gb_slice);
545 556200 dx = get_interleaved_se_golomb(&s->gb_slice);
546
547
2/4
✓ Branch 0 taken 556200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 556200 times.
556200 if (dx != (int16_t)dx || dy != (int16_t)dy) {
548 av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
549 return -1;
550 }
551 }
552
553 /* compute motion vector */
554
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 557056 times.
557238 if (mode == THIRDPEL_MODE) {
555 int fx, fy;
556 182 mx = (mx + 1 >> 1) + dx;
557 182 my = (my + 1 >> 1) + dy;
558 182 fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
559 182 fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
560 182 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
561
562 182 svq3_mc_dir_part(s, x, y, part_width, part_height,
563 fx, fy, dxy, 1, dir, avg);
564 182 mx += mx;
565 182 my += my;
566
4/4
✓ Branch 0 taken 282038 times.
✓ Branch 1 taken 275018 times.
✓ Branch 2 taken 1038 times.
✓ Branch 3 taken 281000 times.
557056 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
567 276056 mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
568 276056 my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
569 276056 dxy = (mx & 1) + 2 * (my & 1);
570
571 276056 svq3_mc_dir_part(s, x, y, part_width, part_height,
572 mx >> 1, my >> 1, dxy, 0, dir, avg);
573 276056 mx *= 3;
574 276056 my *= 3;
575 } else {
576 281000 mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
577 281000 my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
578
579 281000 svq3_mc_dir_part(s, x, y, part_width, part_height,
580 mx, my, 0, 0, dir, avg);
581 281000 mx *= 6;
582 281000 my *= 6;
583 }
584
585 /* update mv_cache */
586
2/2
✓ Branch 0 taken 556200 times.
✓ Branch 1 taken 1038 times.
557238 if (mode != PREDICT_MODE) {
587 556200 int32_t mv = pack16to32(mx, my);
588
589
4/4
✓ Branch 0 taken 157550 times.
✓ Branch 1 taken 398650 times.
✓ Branch 2 taken 78775 times.
✓ Branch 3 taken 78775 times.
556200 if (part_height == 8 && i < 8) {
590 78775 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);
591
592
4/4
✓ Branch 0 taken 78696 times.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 39348 times.
✓ Branch 3 taken 39348 times.
78775 if (part_width == 8 && j < 8)
593 39348 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
594 }
595
4/4
✓ Branch 0 taken 157616 times.
✓ Branch 1 taken 398584 times.
✓ Branch 2 taken 78808 times.
✓ Branch 3 taken 78808 times.
556200 if (part_width == 8 && j < 8)
596 78808 AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);
597
4/4
✓ Branch 0 taken 556064 times.
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 556016 times.
556200 if (part_width == 4 || part_height == 4)
598 184 AV_WN32A(s->mv_cache[dir][scan8[k]], mv);
599 }
600
601 /* write back motion vectors */
602 557238 fill_rectangle(s->cur_pic->motion_val[dir][b_xy],
603 part_width >> 2, part_height >> 2, s->b_stride,
604 pack16to32(mx, my), 4);
605 }
606
607 438655 return 0;
608 }
609
610 488398 static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s,
611 int mb_type, const int *block_offset,
612 int linesize, uint8_t *dest_y)
613 {
614 int i;
615
2/2
✓ Branch 0 taken 440385 times.
✓ Branch 1 taken 48013 times.
488398 if (!IS_INTRA4x4(mb_type)) {
616
2/2
✓ Branch 0 taken 7046160 times.
✓ Branch 1 taken 440385 times.
7486545 for (i = 0; i < 16; i++)
617
4/4
✓ Branch 0 taken 4588656 times.
✓ Branch 1 taken 2457504 times.
✓ Branch 2 taken 22222 times.
✓ Branch 3 taken 4566434 times.
7046160 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
618 2479726 uint8_t *const ptr = dest_y + block_offset[i];
619 2479726 svq3_add_idct_c(ptr, s->mb + i * 16, linesize,
620 2479726 s->qscale, IS_INTRA(mb_type) ? 1 : 0);
621 }
622 }
623 488398 }
624
625 50550 static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s,
626 int mb_type,
627 const int *block_offset,
628 int linesize,
629 uint8_t *dest_y)
630 {
631 int i;
632 50550 int qscale = s->qscale;
633
634
2/2
✓ Branch 0 taken 48013 times.
✓ Branch 1 taken 2537 times.
50550 if (IS_INTRA4x4(mb_type)) {
635
2/2
✓ Branch 0 taken 768208 times.
✓ Branch 1 taken 48013 times.
816221 for (i = 0; i < 16; i++) {
636 768208 uint8_t *const ptr = dest_y + block_offset[i];
637 768208 const int dir = s->intra4x4_pred_mode_cache[scan8[i]];
638
639 uint8_t *topright;
640 int nnz;
641
3/4
✓ Branch 0 taken 715259 times.
✓ Branch 1 taken 52949 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 715259 times.
768208 if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
642 av_assert2(s->mb_y || linesize <= block_offset[i]);
643 52949 topright = ptr + 4 - linesize;
644 } else
645 715259 topright = NULL;
646
647 768208 s->hpc.pred4x4[dir](ptr, topright, linesize);
648 768208 nnz = s->non_zero_count_cache[scan8[i]];
649
2/2
✓ Branch 0 taken 560064 times.
✓ Branch 1 taken 208144 times.
768208 if (nnz) {
650 560064 svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);
651 }
652 }
653 } else {
654 2537 s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);
655 2537 svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);
656 }
657 50550 }
658
659 488398 static void hl_decode_mb(SVQ3Context *s)
660 {
661 488398 const int mb_x = s->mb_x;
662 488398 const int mb_y = s->mb_y;
663 488398 const int mb_xy = s->mb_xy;
664 488398 const int mb_type = s->cur_pic->mb_type[mb_xy];
665 uint8_t *dest_y, *dest_cb, *dest_cr;
666 int linesize, uvlinesize;
667 int i, j;
668 488398 const int *block_offset = &s->block_offset[0];
669 488398 const int block_h = 16 >> 1;
670
671 488398 linesize = s->cur_pic->f->linesize[0];
672 488398 uvlinesize = s->cur_pic->f->linesize[1];
673
674 488398 dest_y = s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
675 488398 dest_cb = s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
676 488398 dest_cr = s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
677
678 488398 s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
679 488398 s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
680
681
2/2
✓ Branch 0 taken 50550 times.
✓ Branch 1 taken 437848 times.
488398 if (IS_INTRA(mb_type)) {
682 50550 s->hpc.pred8x8[s->chroma_pred_mode](dest_cb, uvlinesize);
683 50550 s->hpc.pred8x8[s->chroma_pred_mode](dest_cr, uvlinesize);
684
685 50550 hl_decode_mb_predict_luma(s, mb_type, block_offset, linesize, dest_y);
686 }
687
688 488398 hl_decode_mb_idct_luma(s, mb_type, block_offset, linesize, dest_y);
689
690
2/2
✓ Branch 0 taken 159176 times.
✓ Branch 1 taken 329222 times.
488398 if (s->cbp & 0x30) {
691 159176 uint8_t *dest[2] = { dest_cb, dest_cr };
692 159176 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 1,
693 159176 s->dequant4_coeff[4][0]);
694 159176 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 2,
695 159176 s->dequant4_coeff[4][0]);
696
2/2
✓ Branch 0 taken 318352 times.
✓ Branch 1 taken 159176 times.
477528 for (j = 1; j < 3; j++) {
697
2/2
✓ Branch 0 taken 1273408 times.
✓ Branch 1 taken 318352 times.
1591760 for (i = j * 16; i < j * 16 + 4; i++)
698
4/4
✓ Branch 0 taken 731248 times.
✓ Branch 1 taken 542160 times.
✓ Branch 2 taken 430313 times.
✓ Branch 3 taken 300935 times.
1273408 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
699 972473 uint8_t *const ptr = dest[j - 1] + block_offset[i];
700 972473 svq3_add_idct_c(ptr, s->mb + i * 16,
701 972473 uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
702 }
703 }
704 }
705 488398 }
706
707 842100 static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
708 {
709 int i, j, k, m, dir, mode;
710 842100 int cbp = 0;
711 uint32_t vlc;
712 int8_t *top, *left;
713 842100 const int mb_xy = s->mb_xy;
714 842100 const int b_xy = 4 * s->mb_x + 4 * s->mb_y * s->b_stride;
715
716
2/2
✓ Branch 0 taken 56140 times.
✓ Branch 1 taken 785960 times.
842100 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
717
2/2
✓ Branch 0 taken 42120 times.
✓ Branch 1 taken 799980 times.
842100 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
718
719
2/2
✓ Branch 0 taken 353762 times.
✓ Branch 1 taken 488338 times.
842100 if (mb_type == 0) { /* SKIP */
720
2/2
✓ Branch 0 taken 874 times.
✓ Branch 1 taken 352888 times.
353762 if (s->pict_type == AV_PICTURE_TYPE_P ||
721
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 393 times.
874 s->next_pic->mb_type[mb_xy] == -1) {
722 353369 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
723 0, 0, 0, 0, 0, 0);
724
725
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 352888 times.
353369 if (s->pict_type == AV_PICTURE_TYPE_B)
726 481 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
727 0, 0, 0, 0, 1, 1);
728
729 353369 mb_type = MB_TYPE_SKIP;
730 } else {
731 393 mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
732
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
733 return -1;
734
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
735 return -1;
736
737 393 mb_type = MB_TYPE_16x16;
738 }
739
2/2
✓ Branch 0 taken 437788 times.
✓ Branch 1 taken 50550 times.
488338 } else if (mb_type < 8) { /* INTER */
740
4/4
✓ Branch 0 taken 833 times.
✓ Branch 1 taken 436955 times.
✓ Branch 3 taken 129 times.
✓ Branch 4 taken 704 times.
437788 if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
741 129 mode = THIRDPEL_MODE;
742
1/2
✓ Branch 0 taken 437659 times.
✗ Branch 1 not taken.
437659 else if (s->halfpel_flag &&
743
2/2
✓ Branch 1 taken 196960 times.
✓ Branch 2 taken 240699 times.
437659 s->thirdpel_flag == !get_bits1(&s->gb_slice))
744 196960 mode = HALFPEL_MODE;
745 else
746 240699 mode = FULLPEL_MODE;
747
748 /* fill caches */
749 /* note ref_cache should contain here:
750 * ????????
751 * ???11111
752 * N??11111
753 * N??11111
754 * N??11111
755 */
756
757
2/2
✓ Branch 0 taken 437972 times.
✓ Branch 1 taken 184 times.
438156 for (m = 0; m < 2; m++) {
758
3/4
✓ Branch 0 taken 421231 times.
✓ Branch 1 taken 16741 times.
✓ Branch 2 taken 421231 times.
✗ Branch 3 not taken.
437972 if (s->mb_x > 0 && s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6] != -1) {
759
2/2
✓ Branch 0 taken 1684924 times.
✓ Branch 1 taken 421231 times.
2106155 for (i = 0; i < 4; i++)
760 1684924 AV_COPY32(s->mv_cache[m][scan8[0] - 1 + i * 8],
761 s->cur_pic->motion_val[m][b_xy - 1 + i * s->b_stride]);
762 } else {
763
2/2
✓ Branch 0 taken 66964 times.
✓ Branch 1 taken 16741 times.
83705 for (i = 0; i < 4; i++)
764 66964 AV_ZERO32(s->mv_cache[m][scan8[0] - 1 + i * 8]);
765 }
766
2/2
✓ Branch 0 taken 415083 times.
✓ Branch 1 taken 22889 times.
437972 if (s->mb_y > 0) {
767 415083 memcpy(s->mv_cache[m][scan8[0] - 1 * 8],
768 415083 s->cur_pic->motion_val[m][b_xy - s->b_stride],
769 4 * 2 * sizeof(int16_t));
770 415083 memset(&s->ref_cache[m][scan8[0] - 1 * 8],
771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415083 times.
415083 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
772
773
2/2
✓ Branch 0 taken 396855 times.
✓ Branch 1 taken 18228 times.
415083 if (s->mb_x < s->mb_width - 1) {
774 396855 AV_COPY32(s->mv_cache[m][scan8[0] + 4 - 1 * 8],
775 s->cur_pic->motion_val[m][b_xy - s->b_stride + 4]);
776 396855 s->ref_cache[m][scan8[0] + 4 - 1 * 8] =
777
1/2
✓ Branch 0 taken 396855 times.
✗ Branch 1 not taken.
396855 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 396855 times.
396855 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
779 } else
780 18228 s->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
781
2/2
✓ Branch 0 taken 399258 times.
✓ Branch 1 taken 15825 times.
415083 if (s->mb_x > 0) {
782 399258 AV_COPY32(s->mv_cache[m][scan8[0] - 1 - 1 * 8],
783 s->cur_pic->motion_val[m][b_xy - s->b_stride - 1]);
784 399258 s->ref_cache[m][scan8[0] - 1 - 1 * 8] =
785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399258 times.
399258 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
786 } else
787 15825 s->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
788 } else
789 22889 memset(&s->ref_cache[m][scan8[0] - 1 * 8 - 1],
790 PART_NOT_AVAILABLE, 8);
791
792
2/2
✓ Branch 0 taken 437604 times.
✓ Branch 1 taken 368 times.
437972 if (s->pict_type != AV_PICTURE_TYPE_B)
793 437604 break;
794 }
795
796 /* decode motion vector(s) and form prediction(s) */
797
2/2
✓ Branch 0 taken 437604 times.
✓ Branch 1 taken 184 times.
437788 if (s->pict_type == AV_PICTURE_TYPE_P) {
798
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 437604 times.
437604 if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
799 return -1;
800 } else { /* AV_PICTURE_TYPE_B */
801
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 50 times.
184 if (mb_type != 2) {
802
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
134 if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
803 return -1;
804 } else {
805
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 50 times.
250 for (i = 0; i < 4; i++)
806 200 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
807 0, 4 * 2 * sizeof(int16_t));
808 }
809
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 53 times.
184 if (mb_type != 1) {
810
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
131 if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
811 return -1;
812 } else {
813
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 53 times.
265 for (i = 0; i < 4; i++)
814 212 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
815 0, 4 * 2 * sizeof(int16_t));
816 }
817 }
818
819 437788 mb_type = MB_TYPE_16x16;
820
3/4
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 48013 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2537 times.
50550 } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
821 48013 int8_t *i4x4 = s->intra4x4_pred_mode + s->mb2br_xy[s->mb_xy];
822 48013 int8_t *i4x4_cache = s->intra4x4_pred_mode_cache;
823
824 48013 memset(s->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
825
826
1/2
✓ Branch 0 taken 48013 times.
✗ Branch 1 not taken.
48013 if (mb_type == 8) {
827
2/2
✓ Branch 0 taken 44014 times.
✓ Branch 1 taken 3999 times.
48013 if (s->mb_x > 0) {
828
2/2
✓ Branch 0 taken 176056 times.
✓ Branch 1 taken 44014 times.
220070 for (i = 0; i < 4; i++)
829 176056 s->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6 - i];
830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44014 times.
44014 if (s->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
831 s->left_samples_available = 0x5F5F;
832 }
833
2/2
✓ Branch 0 taken 45104 times.
✓ Branch 1 taken 2909 times.
48013 if (s->mb_y > 0) {
834 45104 s->intra4x4_pred_mode_cache[4 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 0];
835 45104 s->intra4x4_pred_mode_cache[5 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 1];
836 45104 s->intra4x4_pred_mode_cache[6 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 2];
837 45104 s->intra4x4_pred_mode_cache[7 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 3];
838
839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45104 times.
45104 if (s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
840 s->top_samples_available = 0x33FF;
841 }
842
843 /* decode prediction codes for luma blocks */
844
2/2
✓ Branch 0 taken 384104 times.
✓ Branch 1 taken 48013 times.
432117 for (i = 0; i < 16; i += 2) {
845 384104 vlc = get_interleaved_ue_golomb(&s->gb_slice);
846
847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 384104 times.
384104 if (vlc >= 25U) {
848 av_log(s->avctx, AV_LOG_ERROR,
849 "luma prediction:%"PRIu32"\n", vlc);
850 return -1;
851 }
852
853 384104 left = &s->intra4x4_pred_mode_cache[scan8[i] - 1];
854 384104 top = &s->intra4x4_pred_mode_cache[scan8[i] - 8];
855
856 384104 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
857 384104 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
858
859
2/4
✓ Branch 0 taken 384104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 384104 times.
384104 if (left[1] == -1 || left[2] == -1) {
860 av_log(s->avctx, AV_LOG_ERROR, "weird prediction\n");
861 return -1;
862 }
863 }
864 } else { /* mb_type == 33, DC_128_PRED block type */
865 for (i = 0; i < 4; i++)
866 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
867 }
868
869 48013 AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
870 48013 i4x4[4] = i4x4_cache[7 + 8 * 3];
871 48013 i4x4[5] = i4x4_cache[7 + 8 * 2];
872 48013 i4x4[6] = i4x4_cache[7 + 8 * 1];
873
874
1/2
✓ Branch 0 taken 48013 times.
✗ Branch 1 not taken.
48013 if (mb_type == 8) {
875 48013 ff_h264_check_intra4x4_pred_mode(s->intra4x4_pred_mode_cache,
876 48013 s->avctx, s->top_samples_available,
877 48013 s->left_samples_available);
878
879
2/2
✓ Branch 0 taken 2909 times.
✓ Branch 1 taken 45104 times.
48013 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
880
2/2
✓ Branch 0 taken 3999 times.
✓ Branch 1 taken 44014 times.
48013 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
881 } else {
882 for (i = 0; i < 4; i++)
883 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
884
885 s->top_samples_available = 0x33FF;
886 s->left_samples_available = 0x5F5F;
887 }
888
889 48013 mb_type = MB_TYPE_INTRA4x4;
890 } else { /* INTRA16x16 */
891 2537 dir = ff_h264_i_mb_type_info[mb_type - 8].pred_mode;
892 2537 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
893
894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2537 times.
2537 if ((s->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
895 2537 s->left_samples_available, dir, 0)) < 0) {
896 av_log(s->avctx, AV_LOG_ERROR, "ff_h264_check_intra_pred_mode < 0\n");
897 return s->intra16x16_pred_mode;
898 }
899
900 2537 cbp = ff_h264_i_mb_type_info[mb_type - 8].cbp;
901 2537 mb_type = MB_TYPE_INTRA16x16;
902 }
903
904
4/4
✓ Branch 0 taken 403919 times.
✓ Branch 1 taken 438181 times.
✓ Branch 2 taken 384749 times.
✓ Branch 3 taken 19170 times.
842100 if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
905
2/2
✓ Branch 0 taken 1538996 times.
✓ Branch 1 taken 384749 times.
1923745 for (i = 0; i < 4; i++)
906 1538996 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
907 0, 4 * 2 * sizeof(int16_t));
908
2/2
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 384246 times.
384749 if (s->pict_type == AV_PICTURE_TYPE_B) {
909
2/2
✓ Branch 0 taken 2012 times.
✓ Branch 1 taken 503 times.
2515 for (i = 0; i < 4; i++)
910 2012 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
911 0, 4 * 2 * sizeof(int16_t));
912 }
913 }
914
2/2
✓ Branch 0 taken 794087 times.
✓ Branch 1 taken 48013 times.
842100 if (!IS_INTRA4x4(mb_type)) {
915 794087 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy], DC_PRED, 8);
916 }
917
4/4
✓ Branch 0 taken 353369 times.
✓ Branch 1 taken 488731 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 352888 times.
842100 if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
918 489212 memset(s->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
919 }
920
921
2/2
✓ Branch 0 taken 839563 times.
✓ Branch 1 taken 2537 times.
842100 if (!IS_INTRA16x16(mb_type) &&
922
4/4
✓ Branch 0 taken 353369 times.
✓ Branch 1 taken 486194 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 352888 times.
839563 (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
923
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 486675 times.
486675 if ((vlc = get_interleaved_ue_golomb(&s->gb_slice)) >= 48U){
924 av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
925 return -1;
926 }
927
928 486675 cbp = IS_INTRA(mb_type) ? ff_h264_golomb_to_intra4x4_cbp[vlc]
929
2/2
✓ Branch 0 taken 48013 times.
✓ Branch 1 taken 438662 times.
486675 : ff_h264_golomb_to_inter_cbp[vlc];
930 }
931
2/2
✓ Branch 0 taken 839563 times.
✓ Branch 1 taken 2537 times.
842100 if (IS_INTRA16x16(mb_type) ||
932
6/6
✓ Branch 0 taken 822603 times.
✓ Branch 1 taken 16960 times.
✓ Branch 2 taken 2424 times.
✓ Branch 3 taken 820179 times.
✓ Branch 4 taken 696 times.
✓ Branch 5 taken 1728 times.
839563 (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
933 3233 s->qscale += get_interleaved_se_golomb(&s->gb_slice);
934
935
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3233 times.
3233 if (s->qscale > 31u) {
936 av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
937 return -1;
938 }
939 }
940
2/2
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 839563 times.
842100 if (IS_INTRA16x16(mb_type)) {
941 2537 AV_ZERO128(s->mb_luma_dc[0] + 0);
942 2537 AV_ZERO128(s->mb_luma_dc[0] + 8);
943
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2537 times.
2537 if (svq3_decode_block(&s->gb_slice, s->mb_luma_dc[0], 0, 1)) {
944 av_log(s->avctx, AV_LOG_ERROR,
945 "error while decoding intra luma dc\n");
946 return -1;
947 }
948 }
949
950
2/2
✓ Branch 0 taken 333418 times.
✓ Branch 1 taken 508682 times.
842100 if (cbp) {
951 333418 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
952
4/4
✓ Branch 0 taken 333352 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 40540 times.
✓ Branch 3 taken 292812 times.
333418 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
953
954
2/2
✓ Branch 0 taken 1333672 times.
✓ Branch 1 taken 333418 times.
1667090 for (i = 0; i < 4; i++)
955
2/2
✓ Branch 0 taken 754392 times.
✓ Branch 1 taken 579280 times.
1333672 if ((cbp & (1 << i))) {
956
2/2
✓ Branch 0 taken 3017568 times.
✓ Branch 1 taken 754392 times.
3771960 for (j = 0; j < 4; j++) {
957 3021440 k = index ? (1 * (j & 1) + 2 * (i & 1) +
958 3872 2 * (j & 2) + 4 * (i & 2))
959
2/2
✓ Branch 0 taken 3872 times.
✓ Branch 1 taken 3013696 times.
3017568 : (4 * i + j);
960 3017568 s->non_zero_count_cache[scan8[k]] = 1;
961
962
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3017568 times.
3017568 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
963 av_log(s->avctx, AV_LOG_ERROR,
964 "error while decoding block\n");
965 return -1;
966 }
967 }
968 }
969
970
2/2
✓ Branch 0 taken 159176 times.
✓ Branch 1 taken 174242 times.
333418 if ((cbp & 0x30)) {
971
2/2
✓ Branch 0 taken 318352 times.
✓ Branch 1 taken 159176 times.
477528 for (i = 1; i < 3; ++i)
972
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 318352 times.
318352 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
973 av_log(s->avctx, AV_LOG_ERROR,
974 "error while decoding chroma dc block\n");
975 return -1;
976 }
977
978
2/2
✓ Branch 0 taken 67770 times.
✓ Branch 1 taken 91406 times.
159176 if ((cbp & 0x20)) {
979
2/2
✓ Branch 0 taken 135540 times.
✓ Branch 1 taken 67770 times.
203310 for (i = 1; i < 3; i++) {
980
2/2
✓ Branch 0 taken 542160 times.
✓ Branch 1 taken 135540 times.
677700 for (j = 0; j < 4; j++) {
981 542160 k = 16 * i + j;
982 542160 s->non_zero_count_cache[scan8[k]] = 1;
983
984
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 542160 times.
542160 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
985 av_log(s->avctx, AV_LOG_ERROR,
986 "error while decoding chroma ac block\n");
987 return -1;
988 }
989 }
990 }
991 }
992 }
993 }
994
995 842100 s->cbp = cbp;
996 842100 s->cur_pic->mb_type[mb_xy] = mb_type;
997
998
2/2
✓ Branch 0 taken 50550 times.
✓ Branch 1 taken 791550 times.
842100 if (IS_INTRA(mb_type))
999 50550 s->chroma_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
1000 50550 s->left_samples_available, DC_PRED8x8, 1);
1001
1002 842100 return 0;
1003 }
1004
1005 2808 static int svq3_decode_slice_header(AVCodecContext *avctx)
1006 {
1007 2808 SVQ3Context *s = avctx->priv_data;
1008 2808 const int mb_xy = s->mb_xy;
1009 int i, header;
1010 unsigned slice_id;
1011
1012 2808 header = get_bits(&s->gb, 8);
1013
1014
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2808 times.
2808 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
1015 /* TODO: what? */
1016 av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
1017 return -1;
1018 } else {
1019 int slice_bits, slice_bytes, slice_length;
1020 2808 int length = header >> 5 & 3;
1021
1022 2808 slice_length = show_bits(&s->gb, 8 * length);
1023 2808 slice_bits = slice_length * 8;
1024 2808 slice_bytes = slice_length + length - 1;
1025
1026 2808 skip_bits(&s->gb, 8);
1027
1028 2808 av_fast_padded_malloc(&s->slice_buf, &s->slice_buf_size, slice_bytes);
1029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (!s->slice_buf)
1030 return AVERROR(ENOMEM);
1031
1032
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2808 times.
2808 if (slice_bytes * 8LL > get_bits_left(&s->gb)) {
1033 av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
1034 return AVERROR_INVALIDDATA;
1035 }
1036 2808 memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
1037
1038
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2798 times.
2808 if (s->watermark_key) {
1039 10 uint32_t header = AV_RL32(&s->slice_buf[1]);
1040 10 AV_WL32(&s->slice_buf[1], header ^ s->watermark_key);
1041 }
1042 2808 init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
1043
1044
1/2
✓ Branch 0 taken 2808 times.
✗ Branch 1 not taken.
2808 if (length > 0) {
1045 2808 memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
1046 }
1047 2808 skip_bits_long(&s->gb, slice_bytes * 8);
1048 }
1049
1050
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2808 times.
2808 if ((slice_id = get_interleaved_ue_golomb(&s->gb_slice)) >= 3) {
1051 av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
1052 return -1;
1053 }
1054
1055 2808 s->slice_type = ff_h264_golomb_to_pict_type[slice_id];
1056
1057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if ((header & 0x9F) == 2) {
1058 i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
1059 get_bits(&s->gb_slice, i);
1060
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2808 times.
2808 } else if (get_bits1(&s->gb_slice)) {
1061 avpriv_report_missing_feature(s->avctx, "Media key encryption");
1062 return AVERROR_PATCHWELCOME;
1063 }
1064
1065 2808 s->slice_num = get_bits(&s->gb_slice, 8);
1066 2808 s->qscale = get_bits(&s->gb_slice, 5);
1067 2808 s->adaptive_quant = get_bits1(&s->gb_slice);
1068
1069 /* unknown fields */
1070 2808 skip_bits1(&s->gb_slice);
1071
1072
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2798 times.
2808 if (s->has_watermark)
1073 10 skip_bits1(&s->gb_slice);
1074
1075 2808 skip_bits1(&s->gb_slice);
1076 2808 skip_bits(&s->gb_slice, 2);
1077
1078
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2808 times.
2808 if (skip_1stop_8data_bits(&s->gb_slice) < 0)
1079 return AVERROR_INVALIDDATA;
1080
1081 /* reset intra predictors and invalidate motion vector references */
1082
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (s->mb_x > 0) {
1083 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,
1084 -1, 4 * sizeof(int8_t));
1085 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],
1086 -1, 8 * sizeof(int8_t) * s->mb_x);
1087 }
1088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (s->mb_y > 0) {
1089 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],
1090 -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
1091
1092 if (s->mb_x > 0)
1093 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
1094 }
1095
1096 2808 return 0;
1097 }
1098
1099 8 static void init_dequant4_coeff_table(SVQ3Context *s)
1100 {
1101 int q, x;
1102 8 const int max_qp = 51;
1103
1104
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 8 times.
424 for (q = 0; q < max_qp + 1; q++) {
1105 416 int shift = ff_h264_quant_div6[q] + 2;
1106 416 int idx = ff_h264_quant_rem6[q];
1107
2/2
✓ Branch 0 taken 6656 times.
✓ Branch 1 taken 416 times.
7072 for (x = 0; x < 16; x++)
1108 6656 s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
1109 6656 ((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] * 16) << shift;
1110 }
1111 8 }
1112
1113 8 static av_cold int svq3_decode_init(AVCodecContext *avctx)
1114 {
1115 8 SVQ3Context *s = avctx->priv_data;
1116 int m, x, y;
1117 unsigned char *extradata;
1118 unsigned char *extradata_end;
1119 unsigned int size;
1120 8 int marker_found = 0;
1121 int ret;
1122
1123 8 s->cur_pic = &s->frames[0];
1124 8 s->last_pic = &s->frames[1];
1125 8 s->next_pic = &s->frames[2];
1126
1127 8 s->cur_pic->f = av_frame_alloc();
1128 8 s->last_pic->f = av_frame_alloc();
1129 8 s->next_pic->f = av_frame_alloc();
1130
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 if (!s->cur_pic->f || !s->last_pic->f || !s->next_pic->f)
1131 return AVERROR(ENOMEM);
1132
1133 8 ff_h264dsp_init(&s->h264dsp, 8, 1);
1134 8 ff_h264_pred_init(&s->hpc, AV_CODEC_ID_SVQ3, 8, 1);
1135 8 ff_videodsp_init(&s->vdsp, 8);
1136
1137
1138 8 avctx->bits_per_raw_sample = 8;
1139
1140 8 ff_hpeldsp_init(&s->hdsp, avctx->flags);
1141 8 ff_tpeldsp_init(&s->tdsp);
1142
1143 8 avctx->pix_fmt = AV_PIX_FMT_YUVJ420P;
1144 8 avctx->color_range = AVCOL_RANGE_JPEG;
1145
1146 8 s->avctx = avctx;
1147 8 s->halfpel_flag = 1;
1148 8 s->thirdpel_flag = 1;
1149 8 s->has_watermark = 0;
1150
1151 /* prowl for the "SEQH" marker in the extradata */
1152 8 extradata = (unsigned char *)avctx->extradata;
1153 8 extradata_end = avctx->extradata + avctx->extradata_size;
1154
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (extradata) {
1155
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 for (m = 0; m + 8 < avctx->extradata_size; m++) {
1156
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
72 if (!memcmp(extradata, "SEQH", 4)) {
1157 8 marker_found = 1;
1158 8 break;
1159 }
1160 64 extradata++;
1161 }
1162 }
1163
1164 /* if a match was found, parse the extra data */
1165
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (marker_found) {
1166 GetBitContext gb;
1167 int frame_size_code;
1168 int unk0, unk1, unk2, unk3, unk4;
1169 int w,h;
1170
1171 8 size = AV_RB32(&extradata[4]);
1172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (size > extradata_end - extradata - 8)
1173 return AVERROR_INVALIDDATA;
1174 8 init_get_bits(&gb, extradata + 8, size * 8);
1175
1176 /* 'frame size code' and optional 'width, height' */
1177 8 frame_size_code = get_bits(&gb, 3);
1178
2/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
8 switch (frame_size_code) {
1179 case 0:
1180 w = 160;
1181 h = 120;
1182 break;
1183 case 1:
1184 w = 128;
1185 h = 96;
1186 break;
1187 case 2:
1188 w = 176;
1189 h = 144;
1190 break;
1191 case 3:
1192 w = 352;
1193 h = 288;
1194 break;
1195 case 4:
1196 w = 704;
1197 h = 576;
1198 break;
1199 case 5:
1200 w = 240;
1201 h = 180;
1202 break;
1203 6 case 6:
1204 6 w = 320;
1205 6 h = 240;
1206 6 break;
1207 2 case 7:
1208 2 w = get_bits(&gb, 12);
1209 2 h = get_bits(&gb, 12);
1210 2 break;
1211 }
1212 8 ret = ff_set_dimensions(avctx, w, h);
1213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
1214 return ret;
1215
1216 8 s->halfpel_flag = get_bits1(&gb);
1217 8 s->thirdpel_flag = get_bits1(&gb);
1218
1219 /* unknown fields */
1220 8 unk0 = get_bits1(&gb);
1221 8 unk1 = get_bits1(&gb);
1222 8 unk2 = get_bits1(&gb);
1223 8 unk3 = get_bits1(&gb);
1224
1225 8 s->low_delay = get_bits1(&gb);
1226
1227 /* unknown field */
1228 8 unk4 = get_bits1(&gb);
1229
1230 8 av_log(avctx, AV_LOG_DEBUG, "Unknown fields %d %d %d %d %d\n",
1231 unk0, unk1, unk2, unk3, unk4);
1232
1233
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (skip_1stop_8data_bits(&gb) < 0)
1234 return AVERROR_INVALIDDATA;
1235
1236 8 s->has_watermark = get_bits1(&gb);
1237 8 avctx->has_b_frames = !s->low_delay;
1238
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (s->has_watermark) {
1239 #if CONFIG_ZLIB
1240 2 unsigned watermark_width = get_interleaved_ue_golomb(&gb);
1241 2 unsigned watermark_height = get_interleaved_ue_golomb(&gb);
1242 2 int u1 = get_interleaved_ue_golomb(&gb);
1243 2 int u2 = get_bits(&gb, 8);
1244 2 int u3 = get_bits(&gb, 2);
1245 2 int u4 = get_interleaved_ue_golomb(&gb);
1246 2 unsigned long buf_len = watermark_width *
1247 2 watermark_height * 4;
1248 2 int offset = get_bits_count(&gb) + 7 >> 3;
1249 uint8_t *buf;
1250
1251
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (watermark_height <= 0 ||
1252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
1253 return AVERROR_INVALIDDATA;
1254
1255 2 buf = av_malloc(buf_len);
1256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!buf)
1257 return AVERROR(ENOMEM);
1258
1259 2 av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
1260 watermark_width, watermark_height);
1261 2 av_log(avctx, AV_LOG_DEBUG,
1262 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1263 u1, u2, u3, u4, offset);
1264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (uncompress(buf, &buf_len, extradata + 8 + offset,
1265 2 size - offset) != Z_OK) {
1266 av_log(avctx, AV_LOG_ERROR,
1267 "could not uncompress watermark logo\n");
1268 av_free(buf);
1269 return -1;
1270 }
1271 2 s->watermark_key = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0, buf, buf_len));
1272
1273 2 s->watermark_key = s->watermark_key << 16 | s->watermark_key;
1274 2 av_log(avctx, AV_LOG_DEBUG,
1275 "watermark key %#"PRIx32"\n", s->watermark_key);
1276 2 av_free(buf);
1277 #else
1278 av_log(avctx, AV_LOG_ERROR,
1279 "this svq3 file contains watermark which need zlib support compiled in\n");
1280 return AVERROR(ENOSYS);
1281 #endif
1282 }
1283 }
1284
1285 8 s->mb_width = (avctx->width + 15) / 16;
1286 8 s->mb_height = (avctx->height + 15) / 16;
1287 8 s->mb_stride = s->mb_width + 1;
1288 8 s->mb_num = s->mb_width * s->mb_height;
1289 8 s->b_stride = 4 * s->mb_width;
1290 8 s->h_edge_pos = s->mb_width * 16;
1291 8 s->v_edge_pos = s->mb_height * 16;
1292
1293 8 s->intra4x4_pred_mode = av_mallocz(s->mb_stride * 2 * 8);
1294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->intra4x4_pred_mode)
1295 return AVERROR(ENOMEM);
1296
1297 8 s->mb2br_xy = av_mallocz(s->mb_stride * (s->mb_height + 1) *
1298 sizeof(*s->mb2br_xy));
1299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->mb2br_xy)
1300 return AVERROR(ENOMEM);
1301
1302
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 for (y = 0; y < s->mb_height; y++)
1303
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 120 times.
2460 for (x = 0; x < s->mb_width; x++) {
1304 2340 const int mb_xy = x + y * s->mb_stride;
1305
1306 2340 s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 * s->mb_stride));
1307 }
1308
1309 8 init_dequant4_coeff_table(s);
1310
1311 8 return 0;
1312 }
1313
1314 24 static void free_picture(SVQ3Frame *pic)
1315 {
1316 int i;
1317
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (i = 0; i < 2; i++) {
1318 48 av_freep(&pic->motion_val_buf[i]);
1319 }
1320 24 av_freep(&pic->mb_type_buf);
1321
1322 24 av_frame_unref(pic->f);
1323 24 }
1324
1325 2808 static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
1326 {
1327 2808 SVQ3Context *s = avctx->priv_data;
1328 2808 const int big_mb_num = s->mb_stride * (s->mb_height + 1) + 1;
1329 2808 const int b4_stride = s->mb_width * 4 + 1;
1330 2808 const int b4_array_size = b4_stride * s->mb_height * 4;
1331 int ret;
1332
1333
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2796 times.
2808 if (!pic->motion_val_buf[0]) {
1334 int i;
1335
1336 12 pic->mb_type_buf = av_calloc(big_mb_num + s->mb_stride, sizeof(uint32_t));
1337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (!pic->mb_type_buf)
1338 return AVERROR(ENOMEM);
1339 12 pic->mb_type = pic->mb_type_buf + 2 * s->mb_stride + 1;
1340
1341
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for (i = 0; i < 2; i++) {
1342 24 pic->motion_val_buf[i] = av_calloc(b4_array_size + 4, 2 * sizeof(int16_t));
1343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (!pic->motion_val_buf[i]) {
1344 ret = AVERROR(ENOMEM);
1345 goto fail;
1346 }
1347
1348 24 pic->motion_val[i] = pic->motion_val_buf[i] + 4;
1349 }
1350 }
1351
1352 2808 ret = ff_get_buffer(avctx, pic->f,
1353 2808 (s->pict_type != AV_PICTURE_TYPE_B) ?
1354 AV_GET_BUFFER_FLAG_REF : 0);
1355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (ret < 0)
1356 goto fail;
1357
1358
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2804 times.
2808 if (!s->edge_emu_buffer) {
1359 4 s->edge_emu_buffer = av_calloc(pic->f->linesize[0], 17);
1360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!s->edge_emu_buffer)
1361 return AVERROR(ENOMEM);
1362 }
1363
1364 2808 return 0;
1365 fail:
1366 free_picture(pic);
1367 return ret;
1368 }
1369
1370 2815 static int svq3_decode_frame(AVCodecContext *avctx, void *data,
1371 int *got_frame, AVPacket *avpkt)
1372 {
1373 2815 SVQ3Context *s = avctx->priv_data;
1374 2815 int buf_size = avpkt->size;
1375 int left;
1376 int ret, m, i;
1377
1378 /* special case for last picture */
1379
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2808 times.
2815 if (buf_size == 0) {
1380
4/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 3 times.
7 if (s->next_pic->f->data[0] && !s->low_delay && !s->last_frame_output) {
1381 4 ret = av_frame_ref(data, s->next_pic->f);
1382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
1383 return ret;
1384 4 s->last_frame_output = 1;
1385 4 *got_frame = 1;
1386 }
1387 7 return 0;
1388 }
1389
1390 2808 s->mb_x = s->mb_y = s->mb_xy = 0;
1391
1392 2808 ret = init_get_bits8(&s->gb, avpkt->data, avpkt->size);
1393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (ret < 0)
1394 return ret;
1395
1396
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2808 times.
2808 if (svq3_decode_slice_header(avctx))
1397 return -1;
1398
1399 2808 s->pict_type = s->slice_type;
1400
1401
2/2
✓ Branch 0 taken 2804 times.
✓ Branch 1 taken 4 times.
2808 if (s->pict_type != AV_PICTURE_TYPE_B)
1402 2804 FFSWAP(SVQ3Frame*, s->next_pic, s->last_pic);
1403
1404 2808 av_frame_unref(s->cur_pic->f);
1405
1406 /* for skipping the frame */
1407 2808 s->cur_pic->f->pict_type = s->pict_type;
1408 2808 s->cur_pic->f->key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
1409
1410 2808 ret = get_buffer(avctx, s->cur_pic);
1411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (ret < 0)
1412 return ret;
1413
1414
2/2
✓ Branch 0 taken 44928 times.
✓ Branch 1 taken 2808 times.
47736 for (i = 0; i < 16; i++) {
1415 44928 s->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1416 44928 s->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1417 }
1418
2/2
✓ Branch 0 taken 44928 times.
✓ Branch 1 taken 2808 times.
47736 for (i = 0; i < 16; i++) {
1419 44928 s->block_offset[16 + i] =
1420 44928 s->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1421 44928 s->block_offset[48 + 16 + i] =
1422 44928 s->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1423 }
1424
1425
2/2
✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 64 times.
2808 if (s->pict_type != AV_PICTURE_TYPE_I) {
1426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2744 times.
2744 if (!s->last_pic->f->data[0]) {
1427 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1428 av_frame_unref(s->last_pic->f);
1429 ret = get_buffer(avctx, s->last_pic);
1430 if (ret < 0)
1431 return ret;
1432 memset(s->last_pic->f->data[0], 0, avctx->height * s->last_pic->f->linesize[0]);
1433 memset(s->last_pic->f->data[1], 0x80, (avctx->height / 2) *
1434 s->last_pic->f->linesize[1]);
1435 memset(s->last_pic->f->data[2], 0x80, (avctx->height / 2) *
1436 s->last_pic->f->linesize[2]);
1437 }
1438
1439
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2740 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2744 if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
1440 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1441 av_frame_unref(s->next_pic->f);
1442 ret = get_buffer(avctx, s->next_pic);
1443 if (ret < 0)
1444 return ret;
1445 memset(s->next_pic->f->data[0], 0, avctx->height * s->next_pic->f->linesize[0]);
1446 memset(s->next_pic->f->data[1], 0x80, (avctx->height / 2) *
1447 s->next_pic->f->linesize[1]);
1448 memset(s->next_pic->f->data[2], 0x80, (avctx->height / 2) *
1449 s->next_pic->f->linesize[2]);
1450 }
1451 }
1452
1453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (avctx->debug & FF_DEBUG_PICT_INFO)
1454 av_log(s->avctx, AV_LOG_DEBUG,
1455 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1456 av_get_picture_type_char(s->pict_type),
1457 s->halfpel_flag, s->thirdpel_flag,
1458 s->adaptive_quant, s->qscale, s->slice_num);
1459
1460
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2808 if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
1461
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2808 avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
1462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 avctx->skip_frame >= AVDISCARD_ALL)
1463 return 0;
1464
1465
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2804 times.
2808 if (s->pict_type == AV_PICTURE_TYPE_B) {
1466 4 s->frame_num_offset = s->slice_num - s->prev_frame_num;
1467
1468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (s->frame_num_offset < 0)
1469 s->frame_num_offset += 256;
1470
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (s->frame_num_offset == 0 ||
1471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 s->frame_num_offset >= s->prev_frame_num_offset) {
1472 av_log(s->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
1473 return -1;
1474 }
1475 } else {
1476 2804 s->prev_frame_num = s->frame_num;
1477 2804 s->frame_num = s->slice_num;
1478 2804 s->prev_frame_num_offset = s->frame_num - s->prev_frame_num;
1479
1480
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2794 times.
2804 if (s->prev_frame_num_offset < 0)
1481 10 s->prev_frame_num_offset += 256;
1482 }
1483
1484
2/2
✓ Branch 0 taken 5616 times.
✓ Branch 1 taken 2808 times.
8424 for (m = 0; m < 2; m++) {
1485 int i;
1486
2/2
✓ Branch 0 taken 22464 times.
✓ Branch 1 taken 5616 times.
28080 for (i = 0; i < 4; i++) {
1487 int j;
1488
2/2
✓ Branch 0 taken 112320 times.
✓ Branch 1 taken 22464 times.
134784 for (j = -1; j < 4; j++)
1489 112320 s->ref_cache[m][scan8[0] + 8 * i + j] = 1;
1490
2/2
✓ Branch 0 taken 16848 times.
✓ Branch 1 taken 5616 times.
22464 if (i < 3)
1491 16848 s->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
1492 }
1493 }
1494
1495
2/2
✓ Branch 0 taken 42120 times.
✓ Branch 1 taken 2808 times.
44928 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
1496
2/2
✓ Branch 0 taken 842100 times.
✓ Branch 1 taken 42120 times.
884220 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
1497 unsigned mb_type;
1498 842100 s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
1499
1500
2/2
✓ Branch 1 taken 3847 times.
✓ Branch 2 taken 838253 times.
842100 if ((get_bits_left(&s->gb_slice)) <= 7) {
1501
2/4
✓ Branch 1 taken 3847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3847 times.
7694 if (((get_bits_count(&s->gb_slice) & 7) == 0 ||
1502 3847 show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
1503
1504 if (svq3_decode_slice_header(avctx))
1505 return -1;
1506 }
1507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3847 times.
3847 if (s->slice_type != s->pict_type) {
1508 avpriv_request_sample(avctx, "non constant slice type");
1509 }
1510 /* TODO: support s->mb_skip_run */
1511 }
1512
1513 842100 mb_type = get_interleaved_ue_golomb(&s->gb_slice);
1514
1515
2/2
✓ Branch 0 taken 19170 times.
✓ Branch 1 taken 822930 times.
842100 if (s->pict_type == AV_PICTURE_TYPE_I)
1516 19170 mb_type += 8;
1517
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 821850 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1058 times.
822930 else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
1518 22 mb_type += 4;
1519
2/4
✓ Branch 0 taken 842100 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 842100 times.
842100 if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
1520 av_log(s->avctx, AV_LOG_ERROR,
1521 "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
1522 return -1;
1523 }
1524
1525
4/4
✓ Branch 0 taken 353762 times.
✓ Branch 1 taken 488338 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 353702 times.
842100 if (mb_type != 0 || s->cbp)
1526 488398 hl_decode_mb(s);
1527
1528
3/4
✓ Branch 0 taken 841020 times.
✓ Branch 1 taken 1080 times.
✓ Branch 2 taken 841020 times.
✗ Branch 3 not taken.
842100 if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
1529 841020 s->cur_pic->mb_type[s->mb_x + s->mb_y * s->mb_stride] =
1530
4/4
✓ Branch 0 taken 821850 times.
✓ Branch 1 taken 19170 times.
✓ Branch 2 taken 790492 times.
✓ Branch 3 taken 31358 times.
841020 (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
1531 }
1532
1533 42120 ff_draw_horiz_band(avctx, s->cur_pic->f,
1534 42060 s->last_pic->f->data[0] ? s->last_pic->f : NULL,
1535
2/2
✓ Branch 0 taken 42060 times.
✓ Branch 1 taken 60 times.
42120 16 * s->mb_y, 16, PICT_FRAME, 0,
1536 s->low_delay);
1537 }
1538
1539 2808 left = buf_size*8 - get_bits_count(&s->gb_slice);
1540
1541
2/4
✓ Branch 0 taken 2808 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2808 times.
2808 if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
1542 av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left);
1543 //av_hex_dump(stderr, buf+buf_size-8, 8);
1544 }
1545
1546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (left < 0) {
1547 av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left);
1548 return -1;
1549 }
1550
1551
3/4
✓ Branch 0 taken 2804 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2804 times.
2808 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
1552 4 ret = av_frame_ref(data, s->cur_pic->f);
1553
2/2
✓ Branch 0 taken 2800 times.
✓ Branch 1 taken 4 times.
2804 else if (s->last_pic->f->data[0])
1554 2800 ret = av_frame_ref(data, s->last_pic->f);
1555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
2808 if (ret < 0)
1556 return ret;
1557
1558 /* Do not output the last pic after seeking. */
1559
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2804 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2808 if (s->last_pic->f->data[0] || s->low_delay)
1560 2804 *got_frame = 1;
1561
1562
2/2
✓ Branch 0 taken 2804 times.
✓ Branch 1 taken 4 times.
2808 if (s->pict_type != AV_PICTURE_TYPE_B) {
1563 2804 FFSWAP(SVQ3Frame*, s->cur_pic, s->next_pic);
1564 } else {
1565 4 av_frame_unref(s->cur_pic->f);
1566 }
1567
1568 2808 return buf_size;
1569 }
1570
1571 8 static av_cold int svq3_decode_end(AVCodecContext *avctx)
1572 {
1573 8 SVQ3Context *s = avctx->priv_data;
1574
1575
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (int i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) {
1576 24 free_picture(&s->frames[i]);
1577 24 av_frame_free(&s->frames[i].f);
1578 }
1579 8 av_freep(&s->slice_buf);
1580 8 av_freep(&s->intra4x4_pred_mode);
1581 8 av_freep(&s->edge_emu_buffer);
1582 8 av_freep(&s->mb2br_xy);
1583
1584 8 return 0;
1585 }
1586
1587 const AVCodec ff_svq3_decoder = {
1588 .name = "svq3",
1589 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
1590 .type = AVMEDIA_TYPE_VIDEO,
1591 .id = AV_CODEC_ID_SVQ3,
1592 .priv_data_size = sizeof(SVQ3Context),
1593 .init = svq3_decode_init,
1594 .close = svq3_decode_end,
1595 .decode = svq3_decode_frame,
1596 .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND |
1597 AV_CODEC_CAP_DR1 |
1598 AV_CODEC_CAP_DELAY,
1599 .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P,
1600 AV_PIX_FMT_NONE},
1601 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1602 };
1603