FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/svq3.c
Date: 2025-10-10 03:51:19
Exec Total Coverage
Lines: 687 830 82.8%
Functions: 18 19 94.7%
Branches: 437 565 77.3%

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.h"
48 #include "libavutil/mem_internal.h"
49
50 #include "codec_internal.h"
51 #include "decode.h"
52 #include "avcodec.h"
53 #include "mpegutils.h"
54 #include "h264data.h"
55 #include "h264dsp.h"
56 #include "h264pred.h"
57 #include "h264_parse.h"
58 #include "golomb.h"
59 #include "hpeldsp.h"
60 #include "mathops.h"
61 #include "rectangle.h"
62 #include "tpeldsp.h"
63 #include "videodsp.h"
64
65 #if CONFIG_ZLIB
66 #include <zlib.h>
67 #endif
68
69 /**
70 * @file
71 * svq3 decoder.
72 */
73
74 #define NUM_PICS 3
75
76 typedef struct SVQ3Frame {
77 AVFrame *f;
78
79 int16_t (*motion_val[2])[2];
80
81 uint32_t *mb_type;
82 } SVQ3Frame;
83
84 typedef struct SVQ3Context {
85 AVCodecContext *avctx;
86
87 H264DSPContext h264dsp;
88 H264PredContext hpc;
89 HpelDSPContext hdsp;
90 TpelDSPContext tdsp;
91 VideoDSPContext vdsp;
92
93 SVQ3Frame *cur_pic;
94 SVQ3Frame *next_pic;
95 SVQ3Frame *last_pic;
96 GetBitContext gb;
97 GetBitContext gb_slice;
98 uint8_t *slice_buf;
99 unsigned slice_buf_size;
100 int halfpel_flag;
101 int thirdpel_flag;
102 int has_watermark;
103 uint32_t watermark_key;
104 int adaptive_quant;
105 int h_edge_pos;
106 int v_edge_pos;
107 int slice_num;
108 int qscale;
109 int cbp;
110 int frame_num;
111 int frame_num_offset;
112 int prev_frame_num_offset;
113 int prev_frame_num;
114
115 enum AVPictureType pict_type;
116 enum AVPictureType slice_type;
117 int low_delay;
118
119 int mb_x, mb_y;
120 int mb_xy;
121 int mb_width, mb_height;
122 int mb_stride, mb_num;
123 int b_stride;
124
125 uint32_t *mb2br_xy;
126
127 int chroma_pred_mode;
128 int intra16x16_pred_mode;
129
130 int8_t intra4x4_pred_mode_cache[5 * 8];
131 int8_t (*intra4x4_pred_mode);
132
133 unsigned int top_samples_available;
134 unsigned int left_samples_available;
135
136 uint8_t *edge_emu_buffer;
137
138 DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
139 DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
140 DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2];
141 DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2];
142 DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
143 uint32_t dequant4_coeff[QP_MAX_NUM + 1][16];
144 int block_offset[2 * (16 * 3)];
145 SVQ3Frame frames[NUM_PICS];
146
147 uint32_t *mb_type_buf;
148 int16_t (*motion_val_buf)[2];
149 } SVQ3Context;
150
151 #define FULLPEL_MODE 1
152 #define HALFPEL_MODE 2
153 #define THIRDPEL_MODE 3
154 #define PREDICT_MODE 4
155
156 /* dual scan (from some older H.264 draft)
157 * o-->o-->o o
158 * | /|
159 * o o o / o
160 * | / | |/ |
161 * o o o o
162 * /
163 * o-->o-->o-->o
164 */
165 static const uint8_t svq3_scan[16] = {
166 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
167 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
168 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
169 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
170 };
171
172 static const uint8_t luma_dc_zigzag_scan[16] = {
173 0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
174 3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
175 1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
176 3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
177 };
178
179 static const uint8_t svq3_pred_0[25][2] = {
180 { 0, 0 },
181 { 1, 0 }, { 0, 1 },
182 { 0, 2 }, { 1, 1 }, { 2, 0 },
183 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
184 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
185 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
186 { 2, 4 }, { 3, 3 }, { 4, 2 },
187 { 4, 3 }, { 3, 4 },
188 { 4, 4 }
189 };
190
191 static const int8_t svq3_pred_1[6][6][5] = {
192 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
193 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
194 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
195 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
196 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
197 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
198 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
199 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
200 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
201 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
202 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
203 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
204 };
205
206 static const struct {
207 uint8_t run;
208 uint8_t level;
209 } svq3_dct_tables[2][16] = {
210 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
211 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
212 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
213 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
214 };
215
216 static const uint32_t svq3_dequant_coeff[32] = {
217 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
218 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
219 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
220 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
221 };
222
223 2537 static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
224 {
225 2537 const unsigned qmul = svq3_dequant_coeff[qp];
226 #define stride 16
227 int i;
228 int temp[16];
229 static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };
230
231
2/2
✓ Branch 0 taken 10148 times.
✓ Branch 1 taken 2537 times.
12685 for (i = 0; i < 4; i++) {
232 10148 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
233 10148 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
234 10148 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
235 10148 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
236
237 10148 temp[4 * i + 0] = z0 + z3;
238 10148 temp[4 * i + 1] = z1 + z2;
239 10148 temp[4 * i + 2] = z1 - z2;
240 10148 temp[4 * i + 3] = z0 - z3;
241 }
242
243
2/2
✓ Branch 0 taken 10148 times.
✓ Branch 1 taken 2537 times.
12685 for (i = 0; i < 4; i++) {
244 10148 const int offset = x_offset[i];
245 10148 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
246 10148 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
247 10148 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
248 10148 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
249
250 10148 output[stride * 0 + offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
251 10148 output[stride * 2 + offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
252 10148 output[stride * 8 + offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
253 10148 output[stride * 10 + offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
254 }
255 2537 }
256 #undef stride
257
258 4021067 static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
259 int stride, int qp, int dc)
260 {
261 4021067 const int qmul = svq3_dequant_coeff[qp];
262 int i;
263
264
2/2
✓ Branch 0 taken 1000611 times.
✓ Branch 1 taken 3020456 times.
4021067 if (dc) {
265
2/2
✓ Branch 0 taken 26094 times.
✓ Branch 1 taken 974517 times.
1000611 dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
266 974517 : qmul * (block[0] >> 3) / 2);
267 1000611 block[0] = 0;
268 }
269
270
2/2
✓ Branch 0 taken 16084268 times.
✓ Branch 1 taken 4021067 times.
20105335 for (i = 0; i < 4; i++) {
271 16084268 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
272 16084268 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
273 16084268 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
274 16084268 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
275
276 16084268 block[0 + 4 * i] = z0 + z3;
277 16084268 block[1 + 4 * i] = z1 + z2;
278 16084268 block[2 + 4 * i] = z1 - z2;
279 16084268 block[3 + 4 * i] = z0 - z3;
280 }
281
282
2/2
✓ Branch 0 taken 16084268 times.
✓ Branch 1 taken 4021067 times.
20105335 for (i = 0; i < 4; i++) {
283 16084268 const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
284 16084268 const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
285 16084268 const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
286 16084268 const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
287 16084268 const int rr = (dc + 0x80000u);
288
289 16084268 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
290 16084268 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
291 16084268 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
292 16084268 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
293 }
294
295 4021067 memset(block, 0, 16 * sizeof(int16_t));
296 4021067 }
297
298 3889227 static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
299 int index, const int type)
300 {
301 static const uint8_t *const scan_patterns[4] = {
302 luma_dc_zigzag_scan, ff_zigzag_scan, svq3_scan, ff_h264_chroma_dc_scan
303 };
304
305 int run, level, sign, limit;
306 unsigned vlc;
307 3889227 const int intra = 3 * type >> 2;
308 3889227 const uint8_t *const scan = scan_patterns[type];
309
310
2/2
✓ Branch 0 taken 4450247 times.
✓ Branch 1 taken 561020 times.
5011267 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
311
2/2
✓ Branch 1 taken 5390348 times.
✓ Branch 2 taken 4450247 times.
9840595 for (; (vlc = get_interleaved_ue_golomb(gb)) != 0; index++) {
312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5390348 times.
5390348 if ((int32_t)vlc < 0)
313 return -1;
314
315
2/2
✓ Branch 0 taken 2642304 times.
✓ Branch 1 taken 2748044 times.
5390348 sign = (vlc & 1) ? 0 : -1;
316 5390348 vlc = vlc + 1 >> 1;
317
318
2/2
✓ Branch 0 taken 250160 times.
✓ Branch 1 taken 5140188 times.
5390348 if (type == 3) {
319
2/2
✓ Branch 0 taken 169337 times.
✓ Branch 1 taken 80823 times.
250160 if (vlc < 3) {
320 169337 run = 0;
321 169337 level = vlc;
322
2/2
✓ Branch 0 taken 34268 times.
✓ Branch 1 taken 46555 times.
80823 } else if (vlc < 4) {
323 34268 run = 1;
324 34268 level = 1;
325 } else {
326 46555 run = vlc & 0x3;
327 46555 level = (vlc + 9 >> 2) - run;
328 }
329 } else {
330
2/2
✓ Branch 0 taken 5047499 times.
✓ Branch 1 taken 92689 times.
5140188 if (vlc < 16U) {
331 5047499 run = svq3_dct_tables[intra][vlc].run;
332 5047499 level = svq3_dct_tables[intra][vlc].level;
333
2/2
✓ Branch 0 taken 8633 times.
✓ Branch 1 taken 84056 times.
92689 } else if (intra) {
334 8633 run = vlc & 0x7;
335
6/6
✓ Branch 0 taken 5371 times.
✓ Branch 1 taken 3262 times.
✓ Branch 2 taken 3390 times.
✓ Branch 3 taken 1981 times.
✓ Branch 4 taken 3282 times.
✓ Branch 5 taken 108 times.
8633 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
336 } else {
337 84056 run = vlc & 0xF;
338
6/6
✓ Branch 0 taken 51569 times.
✓ Branch 1 taken 32487 times.
✓ Branch 2 taken 21823 times.
✓ Branch 3 taken 29746 times.
✓ Branch 4 taken 18737 times.
✓ Branch 5 taken 3086 times.
84056 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
339 }
340 }
341
342
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5390348 times.
5390348 if ((index += run) >= limit)
344 return -1;
345
346 5390348 block[scan[index]] = (level ^ sign) - sign;
347 }
348
349
2/2
✓ Branch 0 taken 3328207 times.
✓ Branch 1 taken 1122040 times.
4450247 if (type != 2) {
350 3328207 break;
351 }
352 }
353
354 3889227 return 0;
355 }
356
357 static av_always_inline int
358 557229 svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C,
359 int i, int list, int part_width)
360 {
361 557229 const int topright_ref = s->ref_cache[list][i - 8 + part_width];
362
363
2/2
✓ Branch 0 taken 475607 times.
✓ Branch 1 taken 81622 times.
557229 if (topright_ref != PART_NOT_AVAILABLE) {
364 475607 *C = s->mv_cache[list][i - 8 + part_width];
365 475607 return topright_ref;
366 } else {
367 81622 *C = s->mv_cache[list][i - 8 - 1];
368 81622 return s->ref_cache[list][i - 8 - 1];
369 }
370 }
371
372 /**
373 * Get the predicted MV.
374 * @param n the block index
375 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
376 * @param mx the x component of the predicted motion vector
377 * @param my the y component of the predicted motion vector
378 */
379 557229 static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n,
380 int part_width, int list,
381 int ref, int *const mx, int *const my)
382 {
383 557229 const int index8 = scan8[n];
384 557229 const int top_ref = s->ref_cache[list][index8 - 8];
385 557229 const int left_ref = s->ref_cache[list][index8 - 1];
386 557229 const int16_t *const A = s->mv_cache[list][index8 - 1];
387 557229 const int16_t *const B = s->mv_cache[list][index8 - 8];
388 const int16_t *C;
389 int diagonal_ref, match_count;
390
391 /* mv_cache
392 * B . . A T T T T
393 * U . . L . . , .
394 * U . . L . . . .
395 * U . . L . . , .
396 * . . . L . . . .
397 */
398
399 557229 diagonal_ref = svq3_fetch_diagonal_mv(s, &C, index8, list, part_width);
400 557229 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
401
2/2
✓ Branch 0 taken 533406 times.
✓ Branch 1 taken 23823 times.
557229 if (match_count > 1) { //most common
402 533406 *mx = mid_pred(A[0], B[0], C[0]);
403 533406 *my = mid_pred(A[1], B[1], C[1]);
404
1/2
✓ Branch 0 taken 23823 times.
✗ Branch 1 not taken.
23823 } else if (match_count == 1) {
405
1/2
✓ Branch 0 taken 23823 times.
✗ Branch 1 not taken.
23823 if (left_ref == ref) {
406 23823 *mx = A[0];
407 23823 *my = A[1];
408 } else if (top_ref == ref) {
409 *mx = B[0];
410 *my = B[1];
411 } else {
412 *mx = C[0];
413 *my = C[1];
414 }
415 } else {
416 if (top_ref == PART_NOT_AVAILABLE &&
417 diagonal_ref == PART_NOT_AVAILABLE &&
418 left_ref != PART_NOT_AVAILABLE) {
419 *mx = A[0];
420 *my = A[1];
421 } else {
422 *mx = mid_pred(A[0], B[0], C[0]);
423 *my = mid_pred(A[1], B[1], C[1]);
424 }
425 }
426 557229 }
427
428 912267 static inline void svq3_mc_dir_part(SVQ3Context *s,
429 int x, int y, int width, int height,
430 int mx, int my, int dxy,
431 int thirdpel, int dir, int avg)
432 {
433
2/2
✓ Branch 0 taken 911136 times.
✓ Branch 1 taken 1131 times.
912267 const SVQ3Frame *pic = (dir == 0) ? s->last_pic : s->next_pic;
434 uint8_t *src, *dest;
435 912267 int i, emu = 0;
436 912267 int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
437 912267 int linesize = s->cur_pic->f->linesize[0];
438 912267 int uvlinesize = s->cur_pic->f->linesize[1];
439
440 912267 mx += x;
441 912267 my += y;
442
443
6/6
✓ Branch 0 taken 906056 times.
✓ Branch 1 taken 6211 times.
✓ Branch 2 taken 874238 times.
✓ Branch 3 taken 31818 times.
✓ Branch 4 taken 871136 times.
✓ Branch 5 taken 3102 times.
912267 if (mx < 0 || mx >= s->h_edge_pos - width - 1 ||
444
2/2
✓ Branch 0 taken 47614 times.
✓ Branch 1 taken 823522 times.
871136 my < 0 || my >= s->v_edge_pos - height - 1) {
445 88745 emu = 1;
446 88745 mx = av_clip(mx, -16, s->h_edge_pos - width + 15);
447 88745 my = av_clip(my, -16, s->v_edge_pos - height + 15);
448 }
449
450 /* form component predictions */
451 912267 dest = s->cur_pic->f->data[0] + x + y * linesize;
452 912267 src = pic->f->data[0] + mx + my * linesize;
453
454
2/2
✓ Branch 0 taken 88745 times.
✓ Branch 1 taken 823522 times.
912267 if (emu) {
455 88745 s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
456 linesize, linesize,
457 width + 1, height + 1,
458 mx, my, s->h_edge_pos, s->v_edge_pos);
459 88745 src = s->edge_emu_buffer;
460 }
461
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 912085 times.
912267 if (thirdpel)
462 (avg ? s->tdsp.avg_tpel_pixels_tab
463
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 169 times.
182 : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, linesize,
464 width, height);
465 else
466 (avg ? s->hdsp.avg_pixels_tab
467
2/2
✓ Branch 0 taken 1068 times.
✓ Branch 1 taken 911017 times.
912085 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, linesize,
468 height);
469
470
1/2
✓ Branch 0 taken 912267 times.
✗ Branch 1 not taken.
912267 if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
471 912267 mx = mx + (mx < (int) x) >> 1;
472 912267 my = my + (my < (int) y) >> 1;
473 912267 width = width >> 1;
474 912267 height = height >> 1;
475 912267 blocksize++;
476
477
2/2
✓ Branch 0 taken 1824534 times.
✓ Branch 1 taken 912267 times.
2736801 for (i = 1; i < 3; i++) {
478 1824534 dest = s->cur_pic->f->data[i] + (x >> 1) + (y >> 1) * uvlinesize;
479 1824534 src = pic->f->data[i] + mx + my * uvlinesize;
480
481
2/2
✓ Branch 0 taken 177490 times.
✓ Branch 1 taken 1647044 times.
1824534 if (emu) {
482 177490 s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
483 uvlinesize, uvlinesize,
484 width + 1, height + 1,
485 177490 mx, my, (s->h_edge_pos >> 1),
486 177490 s->v_edge_pos >> 1);
487 177490 src = s->edge_emu_buffer;
488 }
489
2/2
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 1824170 times.
1824534 if (thirdpel)
490 (avg ? s->tdsp.avg_tpel_pixels_tab
491
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 338 times.
364 : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src,
492 uvlinesize,
493 width, height);
494 else
495 (avg ? s->hdsp.avg_pixels_tab
496
2/2
✓ Branch 0 taken 2136 times.
✓ Branch 1 taken 1822034 times.
1824170 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
497 uvlinesize,
498 height);
499 }
500 }
501 912267 }
502
503 439333 static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
504 int dir, int avg)
505 {
506 int i, j, k, mx, my, dx, dy, x, y;
507 // 0->16x16,1->8x16,2->16x8,3->8x8,4->4x8,5->8x4,6->4x4
508
2/2
✓ Branch 0 taken 439311 times.
✓ Branch 1 taken 22 times.
439333 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
509 439333 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
510
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 438547 times.
439333 const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0;
511 439333 const int h_edge_pos = 6 * (s->h_edge_pos - part_width) - extra_width;
512 439333 const int v_edge_pos = 6 * (s->v_edge_pos - part_height) - extra_width;
513
514
2/2
✓ Branch 0 taken 478933 times.
✓ Branch 1 taken 439333 times.
918266 for (i = 0; i < 16; i += part_height)
515
2/2
✓ Branch 0 taken 558267 times.
✓ Branch 1 taken 478933 times.
1037200 for (j = 0; j < 16; j += part_width) {
516 558267 const int b_xy = (4 * s->mb_x + (j >> 2)) +
517 558267 (4 * s->mb_y + (i >> 2)) * s->b_stride;
518 int dxy;
519 558267 x = 16 * s->mb_x + j;
520 558267 y = 16 * s->mb_y + i;
521 558267 k = (j >> 2 & 1) + (i >> 1 & 2) +
522 558267 (j >> 1 & 4) + (i & 8);
523
524
2/2
✓ Branch 0 taken 557229 times.
✓ Branch 1 taken 1038 times.
558267 if (mode != PREDICT_MODE) {
525 557229 svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);
526 } else {
527 1038 mx = s->next_pic->motion_val[0][b_xy][0] * 2;
528 1038 my = s->next_pic->motion_val[0][b_xy][1] * 2;
529
530
2/2
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 519 times.
1038 if (dir == 0) {
531 519 mx = mx * s->frame_num_offset /
532 519 s->prev_frame_num_offset + 1 >> 1;
533 519 my = my * s->frame_num_offset /
534 519 s->prev_frame_num_offset + 1 >> 1;
535 } else {
536 519 mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /
537 519 s->prev_frame_num_offset + 1 >> 1;
538 519 my = my * (s->frame_num_offset - s->prev_frame_num_offset) /
539 519 s->prev_frame_num_offset + 1 >> 1;
540 }
541 }
542
543 /* clip motion vector prediction to frame border */
544 558267 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
545 558267 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
546
547 /* get (optional) motion vector differential */
548
2/2
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 557229 times.
558267 if (mode == PREDICT_MODE) {
549 1038 dx = dy = 0;
550 } else {
551 557229 dy = get_interleaved_se_golomb(&s->gb_slice);
552 557229 dx = get_interleaved_se_golomb(&s->gb_slice);
553
554
2/4
✓ Branch 0 taken 557229 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 557229 times.
557229 if (dx != (int16_t)dx || dy != (int16_t)dy) {
555 av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
556 return -1;
557 }
558 }
559
560 /* compute motion vector */
561
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 558085 times.
558267 if (mode == THIRDPEL_MODE) {
562 int fx, fy;
563 182 mx = (mx + 1 >> 1) + dx;
564 182 my = (my + 1 >> 1) + dy;
565 182 fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
566 182 fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
567 182 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
568
569 182 svq3_mc_dir_part(s, x, y, part_width, part_height,
570 fx, fy, dxy, 1, dir, avg);
571 182 mx += mx;
572 182 my += my;
573
4/4
✓ Branch 0 taken 282554 times.
✓ Branch 1 taken 275531 times.
✓ Branch 2 taken 1038 times.
✓ Branch 3 taken 281516 times.
558085 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
574 276569 mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
575 276569 my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
576 276569 dxy = (mx & 1) + 2 * (my & 1);
577
578 276569 svq3_mc_dir_part(s, x, y, part_width, part_height,
579 mx >> 1, my >> 1, dxy, 0, dir, avg);
580 276569 mx *= 3;
581 276569 my *= 3;
582 } else {
583 281516 mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
584 281516 my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
585
586 281516 svq3_mc_dir_part(s, x, y, part_width, part_height,
587 mx, my, 0, 0, dir, avg);
588 281516 mx *= 6;
589 281516 my *= 6;
590 }
591
592 /* update mv_cache */
593
2/2
✓ Branch 0 taken 557229 times.
✓ Branch 1 taken 1038 times.
558267 if (mode != PREDICT_MODE) {
594 557229 int32_t mv = pack16to32(mx, my);
595
596
4/4
✓ Branch 0 taken 158018 times.
✓ Branch 1 taken 399211 times.
✓ Branch 2 taken 79009 times.
✓ Branch 3 taken 79009 times.
557229 if (part_height == 8 && i < 8) {
597 79009 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);
598
599
4/4
✓ Branch 0 taken 78930 times.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 39465 times.
✓ Branch 3 taken 39465 times.
79009 if (part_width == 8 && j < 8)
600 39465 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
601 }
602
4/4
✓ Branch 0 taken 158084 times.
✓ Branch 1 taken 399145 times.
✓ Branch 2 taken 79042 times.
✓ Branch 3 taken 79042 times.
557229 if (part_width == 8 && j < 8)
603 79042 AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);
604
4/4
✓ Branch 0 taken 557093 times.
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 557045 times.
557229 if (part_width == 4 || part_height == 4)
605 184 AV_WN32A(s->mv_cache[dir][scan8[k]], mv);
606 }
607
608 /* write back motion vectors */
609 558267 fill_rectangle(s->cur_pic->motion_val[dir][b_xy],
610 part_width >> 2, part_height >> 2, s->b_stride,
611 pack16to32(mx, my), 4);
612 }
613
614 439333 return 0;
615 }
616
617 489148 static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s,
618 int mb_type, const int *block_offset,
619 int linesize, uint8_t *dest_y)
620 {
621 int i;
622
2/2
✓ Branch 0 taken 441063 times.
✓ Branch 1 taken 48085 times.
489148 if (!IS_INTRA4x4(mb_type)) {
623
2/2
✓ Branch 0 taken 7057008 times.
✓ Branch 1 taken 441063 times.
7498071 for (i = 0; i < 16; i++)
624
4/4
✓ Branch 0 taken 4593856 times.
✓ Branch 1 taken 2463152 times.
✓ Branch 2 taken 22222 times.
✓ Branch 3 taken 4571634 times.
7057008 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
625 2485374 uint8_t *const ptr = dest_y + block_offset[i];
626 2485374 svq3_add_idct_c(ptr, s->mb + i * 16, linesize,
627 2485374 s->qscale, IS_INTRA(mb_type) ? 1 : 0);
628 }
629 }
630 489148 }
631
632 50622 static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s,
633 int mb_type,
634 const int *block_offset,
635 int linesize,
636 uint8_t *dest_y)
637 {
638 int i;
639 50622 int qscale = s->qscale;
640
641
2/2
✓ Branch 0 taken 48085 times.
✓ Branch 1 taken 2537 times.
50622 if (IS_INTRA4x4(mb_type)) {
642
2/2
✓ Branch 0 taken 769360 times.
✓ Branch 1 taken 48085 times.
817445 for (i = 0; i < 16; i++) {
643 769360 uint8_t *const ptr = dest_y + block_offset[i];
644 769360 const int dir = s->intra4x4_pred_mode_cache[scan8[i]];
645
646 uint8_t *topright;
647 int nnz;
648
3/4
✓ Branch 0 taken 716328 times.
✓ Branch 1 taken 53032 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 716328 times.
769360 if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
649 av_assert2(s->mb_y || linesize <= block_offset[i]);
650 53032 topright = ptr + 4 - linesize;
651 } else
652 716328 topright = NULL;
653
654 769360 s->hpc.pred4x4[dir](ptr, topright, linesize);
655 769360 nnz = s->non_zero_count_cache[scan8[i]];
656
2/2
✓ Branch 0 taken 561176 times.
✓ Branch 1 taken 208184 times.
769360 if (nnz) {
657 561176 svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);
658 }
659 }
660 } else {
661 2537 s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);
662 2537 svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);
663 }
664 50622 }
665
666 489148 static void hl_decode_mb(SVQ3Context *s)
667 {
668 489148 const int mb_x = s->mb_x;
669 489148 const int mb_y = s->mb_y;
670 489148 const int mb_xy = s->mb_xy;
671 489148 const int mb_type = s->cur_pic->mb_type[mb_xy];
672 uint8_t *dest_y, *dest_cb, *dest_cr;
673 int linesize, uvlinesize;
674 int i, j;
675 489148 const int *block_offset = &s->block_offset[0];
676 489148 const int block_h = 16 >> 1;
677
678 489148 linesize = s->cur_pic->f->linesize[0];
679 489148 uvlinesize = s->cur_pic->f->linesize[1];
680
681 489148 dest_y = s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
682 489148 dest_cb = s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
683 489148 dest_cr = s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
684
685 489148 s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
686 489148 s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
687
688
2/2
✓ Branch 0 taken 50622 times.
✓ Branch 1 taken 438526 times.
489148 if (IS_INTRA(mb_type)) {
689 50622 s->hpc.pred8x8[s->chroma_pred_mode](dest_cb, uvlinesize);
690 50622 s->hpc.pred8x8[s->chroma_pred_mode](dest_cr, uvlinesize);
691
692 50622 hl_decode_mb_predict_luma(s, mb_type, block_offset, linesize, dest_y);
693 }
694
695 489148 hl_decode_mb_idct_luma(s, mb_type, block_offset, linesize, dest_y);
696
697
2/2
✓ Branch 0 taken 159521 times.
✓ Branch 1 taken 329627 times.
489148 if (s->cbp & 0x30) {
698 159521 uint8_t *dest[2] = { dest_cb, dest_cr };
699 159521 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 1,
700 159521 s->dequant4_coeff[4][0]);
701 159521 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 2,
702 159521 s->dequant4_coeff[4][0]);
703
2/2
✓ Branch 0 taken 319042 times.
✓ Branch 1 taken 159521 times.
478563 for (j = 1; j < 3; j++) {
704
2/2
✓ Branch 0 taken 1276168 times.
✓ Branch 1 taken 319042 times.
1595210 for (i = j * 16; i < j * 16 + 4; i++)
705
4/4
✓ Branch 0 taken 732848 times.
✓ Branch 1 taken 543320 times.
✓ Branch 2 taken 431197 times.
✓ Branch 3 taken 301651 times.
1276168 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
706 974517 uint8_t *const ptr = dest[j - 1] + block_offset[i];
707 974517 svq3_add_idct_c(ptr, s->mb + i * 16,
708 974517 uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
709 }
710 }
711 }
712 489148 }
713
714 843000 static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
715 {
716 int i, j, k, m, dir, mode;
717 843000 int cbp = 0;
718 uint32_t vlc;
719 int8_t *top, *left;
720 843000 const int mb_xy = s->mb_xy;
721 843000 const int b_xy = 4 * s->mb_x + 4 * s->mb_y * s->b_stride;
722
723
2/2
✓ Branch 0 taken 56200 times.
✓ Branch 1 taken 786800 times.
843000 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
724
2/2
✓ Branch 0 taken 42165 times.
✓ Branch 1 taken 800835 times.
843000 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
725
726
2/2
✓ Branch 0 taken 353912 times.
✓ Branch 1 taken 489088 times.
843000 if (mb_type == 0) { /* SKIP */
727
2/2
✓ Branch 0 taken 874 times.
✓ Branch 1 taken 353038 times.
353912 if (s->pict_type == AV_PICTURE_TYPE_P ||
728
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 393 times.
874 s->next_pic->mb_type[mb_xy] == -1) {
729 353519 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
730 0, 0, 0, 0, 0, 0);
731
732
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 353038 times.
353519 if (s->pict_type == AV_PICTURE_TYPE_B)
733 481 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
734 0, 0, 0, 0, 1, 1);
735
736 353519 mb_type = MB_TYPE_SKIP;
737 } else {
738 393 mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
739
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
740 return -1;
741
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
742 return -1;
743
744 393 mb_type = MB_TYPE_16x16;
745 }
746
2/2
✓ Branch 0 taken 438466 times.
✓ Branch 1 taken 50622 times.
489088 } else if (mb_type < 8) { /* INTER */
747
4/4
✓ Branch 0 taken 833 times.
✓ Branch 1 taken 437633 times.
✓ Branch 3 taken 129 times.
✓ Branch 4 taken 704 times.
438466 if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
748 129 mode = THIRDPEL_MODE;
749
1/2
✓ Branch 0 taken 438337 times.
✗ Branch 1 not taken.
438337 else if (s->halfpel_flag &&
750
2/2
✓ Branch 1 taken 197275 times.
✓ Branch 2 taken 241062 times.
438337 s->thirdpel_flag == !get_bits1(&s->gb_slice))
751 197275 mode = HALFPEL_MODE;
752 else
753 241062 mode = FULLPEL_MODE;
754
755 /* fill caches */
756 /* note ref_cache should contain here:
757 * ????????
758 * ???11111
759 * N??11111
760 * N??11111
761 * N??11111
762 */
763
764
2/2
✓ Branch 0 taken 438650 times.
✓ Branch 1 taken 184 times.
438834 for (m = 0; m < 2; m++) {
765
3/4
✓ Branch 0 taken 421880 times.
✓ Branch 1 taken 16770 times.
✓ Branch 2 taken 421880 times.
✗ Branch 3 not taken.
438650 if (s->mb_x > 0 && s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6] != -1) {
766
2/2
✓ Branch 0 taken 1687520 times.
✓ Branch 1 taken 421880 times.
2109400 for (i = 0; i < 4; i++)
767 1687520 AV_COPY32(s->mv_cache[m][scan8[0] - 1 + i * 8],
768 s->cur_pic->motion_val[m][b_xy - 1 + i * s->b_stride]);
769 } else {
770
2/2
✓ Branch 0 taken 67080 times.
✓ Branch 1 taken 16770 times.
83850 for (i = 0; i < 4; i++)
771 67080 AV_ZERO32(s->mv_cache[m][scan8[0] - 1 + i * 8]);
772 }
773
2/2
✓ Branch 0 taken 415726 times.
✓ Branch 1 taken 22924 times.
438650 if (s->mb_y > 0) {
774 415726 memcpy(s->mv_cache[m][scan8[0] - 1 * 8],
775 415726 s->cur_pic->motion_val[m][b_xy - s->b_stride],
776 4 * 2 * sizeof(int16_t));
777 415726 memset(&s->ref_cache[m][scan8[0] - 1 * 8],
778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415726 times.
415726 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
779
780
2/2
✓ Branch 0 taken 397465 times.
✓ Branch 1 taken 18261 times.
415726 if (s->mb_x < s->mb_width - 1) {
781 397465 AV_COPY32(s->mv_cache[m][scan8[0] + 4 - 1 * 8],
782 s->cur_pic->motion_val[m][b_xy - s->b_stride + 4]);
783 397465 s->ref_cache[m][scan8[0] + 4 - 1 * 8] =
784
1/2
✓ Branch 0 taken 397465 times.
✗ Branch 1 not taken.
397465 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397465 times.
397465 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
786 } else
787 18261 s->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
788
2/2
✓ Branch 0 taken 399874 times.
✓ Branch 1 taken 15852 times.
415726 if (s->mb_x > 0) {
789 399874 AV_COPY32(s->mv_cache[m][scan8[0] - 1 - 1 * 8],
790 s->cur_pic->motion_val[m][b_xy - s->b_stride - 1]);
791 399874 s->ref_cache[m][scan8[0] - 1 - 1 * 8] =
792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399874 times.
399874 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
793 } else
794 15852 s->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
795 } else
796 22924 memset(&s->ref_cache[m][scan8[0] - 1 * 8 - 1],
797 PART_NOT_AVAILABLE, 8);
798
799
2/2
✓ Branch 0 taken 438282 times.
✓ Branch 1 taken 368 times.
438650 if (s->pict_type != AV_PICTURE_TYPE_B)
800 438282 break;
801 }
802
803 /* decode motion vector(s) and form prediction(s) */
804
2/2
✓ Branch 0 taken 438282 times.
✓ Branch 1 taken 184 times.
438466 if (s->pict_type == AV_PICTURE_TYPE_P) {
805
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 438282 times.
438282 if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
806 return -1;
807 } else { /* AV_PICTURE_TYPE_B */
808
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 50 times.
184 if (mb_type != 2) {
809
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
134 if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
810 return -1;
811 } else {
812
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 50 times.
250 for (i = 0; i < 4; i++)
813 200 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
814 0, 4 * 2 * sizeof(int16_t));
815 }
816
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 53 times.
184 if (mb_type != 1) {
817
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
131 if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
818 return -1;
819 } else {
820
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 53 times.
265 for (i = 0; i < 4; i++)
821 212 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
822 0, 4 * 2 * sizeof(int16_t));
823 }
824 }
825
826 438466 mb_type = MB_TYPE_16x16;
827
3/4
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 48085 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2537 times.
50622 } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
828 48085 int8_t *i4x4 = s->intra4x4_pred_mode + s->mb2br_xy[s->mb_xy];
829 48085 int8_t *i4x4_cache = s->intra4x4_pred_mode_cache;
830
831 48085 memset(s->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
832
833
1/2
✓ Branch 0 taken 48085 times.
✗ Branch 1 not taken.
48085 if (mb_type == 8) {
834
2/2
✓ Branch 0 taken 44080 times.
✓ Branch 1 taken 4005 times.
48085 if (s->mb_x > 0) {
835
2/2
✓ Branch 0 taken 176320 times.
✓ Branch 1 taken 44080 times.
220400 for (i = 0; i < 4; i++)
836 176320 s->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6 - i];
837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44080 times.
44080 if (s->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
838 s->left_samples_available = 0x5F5F;
839 }
840
2/2
✓ Branch 0 taken 45176 times.
✓ Branch 1 taken 2909 times.
48085 if (s->mb_y > 0) {
841 45176 s->intra4x4_pred_mode_cache[4 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 0];
842 45176 s->intra4x4_pred_mode_cache[5 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 1];
843 45176 s->intra4x4_pred_mode_cache[6 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 2];
844 45176 s->intra4x4_pred_mode_cache[7 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 3];
845
846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45176 times.
45176 if (s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
847 s->top_samples_available = 0x33FF;
848 }
849
850 /* decode prediction codes for luma blocks */
851
2/2
✓ Branch 0 taken 384680 times.
✓ Branch 1 taken 48085 times.
432765 for (i = 0; i < 16; i += 2) {
852 384680 vlc = get_interleaved_ue_golomb(&s->gb_slice);
853
854
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 384680 times.
384680 if (vlc >= 25U) {
855 av_log(s->avctx, AV_LOG_ERROR,
856 "luma prediction:%"PRIu32"\n", vlc);
857 return -1;
858 }
859
860 384680 left = &s->intra4x4_pred_mode_cache[scan8[i] - 1];
861 384680 top = &s->intra4x4_pred_mode_cache[scan8[i] - 8];
862
863 384680 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
864 384680 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
865
866
2/4
✓ Branch 0 taken 384680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 384680 times.
384680 if (left[1] == -1 || left[2] == -1) {
867 av_log(s->avctx, AV_LOG_ERROR, "weird prediction\n");
868 return -1;
869 }
870 }
871 } else { /* mb_type == 33, DC_128_PRED block type */
872 for (i = 0; i < 4; i++)
873 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
874 }
875
876 48085 AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
877 48085 i4x4[4] = i4x4_cache[7 + 8 * 3];
878 48085 i4x4[5] = i4x4_cache[7 + 8 * 2];
879 48085 i4x4[6] = i4x4_cache[7 + 8 * 1];
880
881
1/2
✓ Branch 0 taken 48085 times.
✗ Branch 1 not taken.
48085 if (mb_type == 8) {
882 48085 ff_h264_check_intra4x4_pred_mode(s->intra4x4_pred_mode_cache,
883 48085 s->avctx, s->top_samples_available,
884 48085 s->left_samples_available);
885
886
2/2
✓ Branch 0 taken 2909 times.
✓ Branch 1 taken 45176 times.
48085 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
887
2/2
✓ Branch 0 taken 4005 times.
✓ Branch 1 taken 44080 times.
48085 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
888 } else {
889 for (i = 0; i < 4; i++)
890 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
891
892 s->top_samples_available = 0x33FF;
893 s->left_samples_available = 0x5F5F;
894 }
895
896 48085 mb_type = MB_TYPE_INTRA4x4;
897 } else { /* INTRA16x16 */
898 2537 dir = ff_h264_i_mb_type_info[mb_type - 8].pred_mode;
899 2537 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
900
901
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,
902 2537 s->left_samples_available, dir, 0)) < 0) {
903 av_log(s->avctx, AV_LOG_ERROR, "ff_h264_check_intra_pred_mode < 0\n");
904 return s->intra16x16_pred_mode;
905 }
906
907 2537 cbp = ff_h264_i_mb_type_info[mb_type - 8].cbp;
908 2537 mb_type = MB_TYPE_INTRA16x16;
909 }
910
911
4/4
✓ Branch 0 taken 404141 times.
✓ Branch 1 taken 438859 times.
✓ Branch 2 taken 384971 times.
✓ Branch 3 taken 19170 times.
843000 if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
912
2/2
✓ Branch 0 taken 1539884 times.
✓ Branch 1 taken 384971 times.
1924855 for (i = 0; i < 4; i++)
913 1539884 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
914 0, 4 * 2 * sizeof(int16_t));
915
2/2
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 384468 times.
384971 if (s->pict_type == AV_PICTURE_TYPE_B) {
916
2/2
✓ Branch 0 taken 2012 times.
✓ Branch 1 taken 503 times.
2515 for (i = 0; i < 4; i++)
917 2012 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
918 0, 4 * 2 * sizeof(int16_t));
919 }
920 }
921
2/2
✓ Branch 0 taken 794915 times.
✓ Branch 1 taken 48085 times.
843000 if (!IS_INTRA4x4(mb_type)) {
922 794915 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy], DC_PRED, 8);
923 }
924
4/4
✓ Branch 0 taken 353519 times.
✓ Branch 1 taken 489481 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 353038 times.
843000 if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
925 489962 memset(s->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
926 }
927
928
2/2
✓ Branch 0 taken 840463 times.
✓ Branch 1 taken 2537 times.
843000 if (!IS_INTRA16x16(mb_type) &&
929
4/4
✓ Branch 0 taken 353519 times.
✓ Branch 1 taken 486944 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 353038 times.
840463 (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
930
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 487425 times.
487425 if ((vlc = get_interleaved_ue_golomb(&s->gb_slice)) >= 48U){
931 av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
932 return -1;
933 }
934
935 487425 cbp = IS_INTRA(mb_type) ? ff_h264_golomb_to_intra4x4_cbp[vlc]
936
2/2
✓ Branch 0 taken 48085 times.
✓ Branch 1 taken 439340 times.
487425 : ff_h264_golomb_to_inter_cbp[vlc];
937 }
938
2/2
✓ Branch 0 taken 840463 times.
✓ Branch 1 taken 2537 times.
843000 if (IS_INTRA16x16(mb_type) ||
939
6/6
✓ Branch 0 taken 823503 times.
✓ Branch 1 taken 16960 times.
✓ Branch 2 taken 2424 times.
✓ Branch 3 taken 821079 times.
✓ Branch 4 taken 696 times.
✓ Branch 5 taken 1728 times.
840463 (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
940 3233 s->qscale += get_interleaved_se_golomb(&s->gb_slice);
941
942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3233 times.
3233 if (s->qscale > 31u) {
943 av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
944 return -1;
945 }
946 }
947
2/2
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 840463 times.
843000 if (IS_INTRA16x16(mb_type)) {
948 2537 AV_ZERO128(s->mb_luma_dc[0] + 0);
949 2537 AV_ZERO128(s->mb_luma_dc[0] + 8);
950
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)) {
951 av_log(s->avctx, AV_LOG_ERROR,
952 "error while decoding intra luma dc\n");
953 return -1;
954 }
955 }
956
957
2/2
✓ Branch 0 taken 334040 times.
✓ Branch 1 taken 508960 times.
843000 if (cbp) {
958 334040 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
959
4/4
✓ Branch 0 taken 333974 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 40612 times.
✓ Branch 3 taken 293362 times.
334040 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
960
961
2/2
✓ Branch 0 taken 1336160 times.
✓ Branch 1 taken 334040 times.
1670200 for (i = 0; i < 4; i++)
962
2/2
✓ Branch 0 taken 756082 times.
✓ Branch 1 taken 580078 times.
1336160 if ((cbp & (1 << i))) {
963
2/2
✓ Branch 0 taken 3024328 times.
✓ Branch 1 taken 756082 times.
3780410 for (j = 0; j < 4; j++) {
964 3028200 k = index ? (1 * (j & 1) + 2 * (i & 1) +
965 3872 2 * (j & 2) + 4 * (i & 2))
966
2/2
✓ Branch 0 taken 3872 times.
✓ Branch 1 taken 3020456 times.
3024328 : (4 * i + j);
967 3024328 s->non_zero_count_cache[scan8[k]] = 1;
968
969
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3024328 times.
3024328 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
970 av_log(s->avctx, AV_LOG_ERROR,
971 "error while decoding block\n");
972 return -1;
973 }
974 }
975 }
976
977
2/2
✓ Branch 0 taken 159521 times.
✓ Branch 1 taken 174519 times.
334040 if ((cbp & 0x30)) {
978
2/2
✓ Branch 0 taken 319042 times.
✓ Branch 1 taken 159521 times.
478563 for (i = 1; i < 3; ++i)
979
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 319042 times.
319042 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
980 av_log(s->avctx, AV_LOG_ERROR,
981 "error while decoding chroma dc block\n");
982 return -1;
983 }
984
985
2/2
✓ Branch 0 taken 67915 times.
✓ Branch 1 taken 91606 times.
159521 if ((cbp & 0x20)) {
986
2/2
✓ Branch 0 taken 135830 times.
✓ Branch 1 taken 67915 times.
203745 for (i = 1; i < 3; i++) {
987
2/2
✓ Branch 0 taken 543320 times.
✓ Branch 1 taken 135830 times.
679150 for (j = 0; j < 4; j++) {
988 543320 k = 16 * i + j;
989 543320 s->non_zero_count_cache[scan8[k]] = 1;
990
991
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 543320 times.
543320 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
992 av_log(s->avctx, AV_LOG_ERROR,
993 "error while decoding chroma ac block\n");
994 return -1;
995 }
996 }
997 }
998 }
999 }
1000 }
1001
1002 843000 s->cbp = cbp;
1003 843000 s->cur_pic->mb_type[mb_xy] = mb_type;
1004
1005
2/2
✓ Branch 0 taken 50622 times.
✓ Branch 1 taken 792378 times.
843000 if (IS_INTRA(mb_type))
1006 50622 s->chroma_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
1007 50622 s->left_samples_available, DC_PRED8x8, 1);
1008
1009 843000 return 0;
1010 }
1011
1012 2811 static int svq3_decode_slice_header(AVCodecContext *avctx)
1013 {
1014 2811 SVQ3Context *s = avctx->priv_data;
1015 2811 const int mb_xy = s->mb_xy;
1016 int i, header;
1017 unsigned slice_id;
1018
1019 2811 header = get_bits(&s->gb, 8);
1020
1021
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2811 times.
2811 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
1022 /* TODO: what? */
1023 av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
1024 return -1;
1025 } else {
1026 int slice_bits, slice_bytes, slice_length;
1027 2811 int length = header >> 5 & 3;
1028
1029 2811 slice_length = show_bits(&s->gb, 8 * length);
1030 2811 slice_bits = slice_length * 8;
1031 2811 slice_bytes = slice_length + length - 1;
1032
1033 2811 skip_bits(&s->gb, 8);
1034
1035 2811 av_fast_padded_malloc(&s->slice_buf, &s->slice_buf_size, slice_bytes);
1036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (!s->slice_buf)
1037 return AVERROR(ENOMEM);
1038
1039
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2811 times.
2811 if (slice_bytes * 8LL > get_bits_left(&s->gb)) {
1040 av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
1041 return AVERROR_INVALIDDATA;
1042 }
1043 2811 memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
1044
1045
1/2
✓ Branch 0 taken 2811 times.
✗ Branch 1 not taken.
2811 if (length > 0) {
1046 2811 memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
1047 }
1048
1049
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2801 times.
2811 if (s->watermark_key) {
1050 10 uint32_t header = AV_RL32(&s->slice_buf[1]);
1051 10 AV_WL32(&s->slice_buf[1], header ^ s->watermark_key);
1052 }
1053 2811 init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
1054
1055 2811 skip_bits_long(&s->gb, slice_bytes * 8);
1056 }
1057
1058
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2811 times.
2811 if ((slice_id = get_interleaved_ue_golomb(&s->gb_slice)) >= 3) {
1059 av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
1060 return -1;
1061 }
1062
1063 2811 s->slice_type = ff_h264_golomb_to_pict_type[slice_id];
1064
1065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if ((header & 0x9F) == 2) {
1066 i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
1067 get_bits(&s->gb_slice, i);
1068
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2811 times.
2811 } else if (get_bits1(&s->gb_slice)) {
1069 avpriv_report_missing_feature(s->avctx, "Media key encryption");
1070 return AVERROR_PATCHWELCOME;
1071 }
1072
1073 2811 s->slice_num = get_bits(&s->gb_slice, 8);
1074 2811 s->qscale = get_bits(&s->gb_slice, 5);
1075 2811 s->adaptive_quant = get_bits1(&s->gb_slice);
1076
1077 /* unknown fields */
1078 2811 skip_bits1(&s->gb_slice);
1079
1080
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2801 times.
2811 if (s->has_watermark)
1081 10 skip_bits1(&s->gb_slice);
1082
1083 2811 skip_bits1(&s->gb_slice);
1084 2811 skip_bits(&s->gb_slice, 2);
1085
1086
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2811 times.
2811 if (skip_1stop_8data_bits(&s->gb_slice) < 0)
1087 return AVERROR_INVALIDDATA;
1088
1089 /* reset intra predictors and invalidate motion vector references */
1090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (s->mb_x > 0) {
1091 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,
1092 -1, 4 * sizeof(int8_t));
1093 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],
1094 -1, 8 * sizeof(int8_t) * s->mb_x);
1095 }
1096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (s->mb_y > 0) {
1097 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],
1098 -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
1099
1100 if (s->mb_x > 0)
1101 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
1102 }
1103
1104 2811 return 0;
1105 }
1106
1107 8 static void init_dequant4_coeff_table(SVQ3Context *s)
1108 {
1109 int q, x;
1110 8 const int max_qp = 51;
1111
1112
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 8 times.
424 for (q = 0; q < max_qp + 1; q++) {
1113 416 int shift = ff_h264_quant_div6[q] + 2;
1114 416 int idx = ff_h264_quant_rem6[q];
1115
2/2
✓ Branch 0 taken 6656 times.
✓ Branch 1 taken 416 times.
7072 for (x = 0; x < 16; x++)
1116 6656 s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
1117 6656 ((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] * 16) << shift;
1118 }
1119 8 }
1120
1121 8 static av_cold int svq3_decode_extradata(AVCodecContext *avctx, SVQ3Context *s,
1122 int seqh_offset)
1123 {
1124 8 const uint8_t *extradata = avctx->extradata + seqh_offset;
1125 8 unsigned int size = AV_RB32(extradata + 4);
1126 GetBitContext gb;
1127 int ret;
1128
1129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (size > avctx->extradata_size - seqh_offset - 8)
1130 return AVERROR_INVALIDDATA;
1131 8 extradata += 8;
1132 8 init_get_bits(&gb, extradata, size * 8);
1133
1134 /* 'frame size code' and optional 'width, height' */
1135 8 int frame_size_code = get_bits(&gb, 3);
1136 int w, h;
1137
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) {
1138 case 0:
1139 w = 160;
1140 h = 120;
1141 break;
1142 case 1:
1143 w = 128;
1144 h = 96;
1145 break;
1146 case 2:
1147 w = 176;
1148 h = 144;
1149 break;
1150 case 3:
1151 w = 352;
1152 h = 288;
1153 break;
1154 case 4:
1155 w = 704;
1156 h = 576;
1157 break;
1158 case 5:
1159 w = 240;
1160 h = 180;
1161 break;
1162 6 case 6:
1163 6 w = 320;
1164 6 h = 240;
1165 6 break;
1166 2 case 7:
1167 2 w = get_bits(&gb, 12);
1168 2 h = get_bits(&gb, 12);
1169 2 break;
1170 }
1171 8 ret = ff_set_dimensions(avctx, w, h);
1172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
1173 return ret;
1174
1175 8 s->halfpel_flag = get_bits1(&gb);
1176 8 s->thirdpel_flag = get_bits1(&gb);
1177
1178 /* unknown fields */
1179 8 int unk0 = get_bits1(&gb);
1180 8 int unk1 = get_bits1(&gb);
1181 8 int unk2 = get_bits1(&gb);
1182 8 int unk3 = get_bits1(&gb);
1183
1184 8 s->low_delay = get_bits1(&gb);
1185 8 avctx->has_b_frames = !s->low_delay;
1186
1187 /* unknown field */
1188 8 int unk4 = get_bits1(&gb);
1189
1190 8 av_log(avctx, AV_LOG_DEBUG, "Unknown fields %d %d %d %d %d\n",
1191 unk0, unk1, unk2, unk3, unk4);
1192
1193
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (skip_1stop_8data_bits(&gb) < 0)
1194 return AVERROR_INVALIDDATA;
1195
1196 8 s->has_watermark = get_bits1(&gb);
1197
1198
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if (!s->has_watermark)
1199 6 return 0;
1200
1201 #if CONFIG_ZLIB
1202 2 unsigned watermark_width = get_interleaved_ue_golomb(&gb);
1203 2 unsigned watermark_height = get_interleaved_ue_golomb(&gb);
1204 2 int u1 = get_interleaved_ue_golomb(&gb);
1205 2 int u2 = get_bits(&gb, 8);
1206 2 int u3 = get_bits(&gb, 2);
1207 2 int u4 = get_interleaved_ue_golomb(&gb);
1208 2 unsigned long buf_len = watermark_width *
1209 2 watermark_height * 4;
1210 2 int offset = get_bits_count(&gb) + 7 >> 3;
1211
1212
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 if (watermark_height <= 0 ||
1213 2 get_bits_left(&gb) <= 0 ||
1214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
1215 return AVERROR_INVALIDDATA;
1216
1217 2 av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
1218 watermark_width, watermark_height);
1219 2 av_log(avctx, AV_LOG_DEBUG,
1220 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1221 u1, u2, u3, u4, offset);
1222
1223 2 uint8_t *buf = av_malloc(buf_len);
1224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!buf)
1225 return AVERROR(ENOMEM);
1226
1227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (uncompress(buf, &buf_len, extradata + offset,
1228 2 size - offset) != Z_OK) {
1229 av_log(avctx, AV_LOG_ERROR,
1230 "could not uncompress watermark logo\n");
1231 av_free(buf);
1232 return AVERROR_EXTERNAL;
1233 }
1234 2 s->watermark_key = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0, buf, buf_len));
1235
1236 2 s->watermark_key = s->watermark_key << 16 | s->watermark_key;
1237 2 av_log(avctx, AV_LOG_DEBUG,
1238 "watermark key %#"PRIx32"\n", s->watermark_key);
1239 2 av_free(buf);
1240
1241 2 return 0;
1242 #else
1243 av_log(avctx, AV_LOG_ERROR,
1244 "this svq3 file contains watermark which need zlib support compiled in\n");
1245 return AVERROR(ENOSYS);
1246 #endif
1247 }
1248
1249 8 static av_cold int svq3_decode_init(AVCodecContext *avctx)
1250 {
1251 8 SVQ3Context *s = avctx->priv_data;
1252 int m, x, y;
1253 unsigned char *extradata;
1254 int ret;
1255
1256 8 s->cur_pic = &s->frames[0];
1257 8 s->last_pic = &s->frames[1];
1258 8 s->next_pic = &s->frames[2];
1259
1260 8 s->cur_pic->f = av_frame_alloc();
1261 8 s->last_pic->f = av_frame_alloc();
1262 8 s->next_pic->f = av_frame_alloc();
1263
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)
1264 return AVERROR(ENOMEM);
1265
1266 8 ff_h264dsp_init(&s->h264dsp, 8, 1);
1267 8 ff_h264_pred_init(&s->hpc, AV_CODEC_ID_SVQ3, 8, 1);
1268 8 ff_videodsp_init(&s->vdsp, 8);
1269
1270
1271 8 avctx->bits_per_raw_sample = 8;
1272
1273 8 ff_hpeldsp_init(&s->hdsp, avctx->flags);
1274 8 ff_tpeldsp_init(&s->tdsp);
1275
1276 8 avctx->pix_fmt = AV_PIX_FMT_YUVJ420P;
1277 8 avctx->color_range = AVCOL_RANGE_JPEG;
1278
1279 8 s->avctx = avctx;
1280 8 s->halfpel_flag = 1;
1281 8 s->thirdpel_flag = 1;
1282 8 s->has_watermark = 0;
1283
1284 /* prowl for the "SEQH" marker in the extradata */
1285 8 extradata = (unsigned char *)avctx->extradata;
1286
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (extradata) {
1287
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 for (m = 0; m + 8 < avctx->extradata_size; m++) {
1288
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
72 if (!memcmp(extradata, "SEQH", 4)) {
1289 /* if a match was found, parse the extra data */
1290 8 ret = svq3_decode_extradata(avctx, s, m);
1291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
1292 return ret;
1293 8 break;
1294 }
1295 64 extradata++;
1296 }
1297 }
1298
1299 8 s->mb_width = (avctx->width + 15) / 16;
1300 8 s->mb_height = (avctx->height + 15) / 16;
1301 8 s->mb_stride = s->mb_width + 1;
1302 8 s->mb_num = s->mb_width * s->mb_height;
1303 8 s->b_stride = 4 * s->mb_width;
1304 8 s->h_edge_pos = s->mb_width * 16;
1305 8 s->v_edge_pos = s->mb_height * 16;
1306
1307 8 const unsigned big_mb_num = s->mb_stride * (s->mb_height + 2) + 1;
1308
1309 8 s->mb_type_buf = av_calloc(big_mb_num, NUM_PICS * sizeof(*s->mb_type_buf));
1310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->mb_type_buf)
1311 return AVERROR(ENOMEM);
1312 8 uint32_t *mb_type_buf = s->mb_type_buf + 2 * s->mb_stride + 1;
1313
1314 8 const unsigned b4_stride = s->mb_width * 4 + 1;
1315 8 const unsigned b4_array_size = b4_stride * s->mb_height * 4;
1316 8 const unsigned motion_val_buf_size = b4_array_size + 4;
1317
1318 8 s->motion_val_buf = av_calloc(motion_val_buf_size,
1319 NUM_PICS * 2 * sizeof(*s->motion_val_buf));
1320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->motion_val_buf)
1321 return AVERROR(ENOMEM);
1322 8 int16_t (*motion_val_buf)[2] = s->motion_val_buf + 4;
1323
1324
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (size_t i = 0; i < NUM_PICS; ++i) {
1325 24 SVQ3Frame *const pic = &s->frames[i];
1326
1327 24 pic->mb_type = mb_type_buf;
1328 24 mb_type_buf += big_mb_num;
1329
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (size_t j = 0; j < FF_ARRAY_ELEMS(pic->motion_val); ++j) {
1330 48 pic->motion_val[j] = motion_val_buf;
1331 48 motion_val_buf += motion_val_buf_size;
1332 }
1333 }
1334
1335 8 s->intra4x4_pred_mode = av_mallocz(s->mb_stride * 2 * 8);
1336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->intra4x4_pred_mode)
1337 return AVERROR(ENOMEM);
1338
1339 8 s->mb2br_xy = av_mallocz(s->mb_stride * (s->mb_height + 1) *
1340 sizeof(*s->mb2br_xy));
1341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->mb2br_xy)
1342 return AVERROR(ENOMEM);
1343
1344
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 for (y = 0; y < s->mb_height; y++)
1345
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 120 times.
2460 for (x = 0; x < s->mb_width; x++) {
1346 2340 const int mb_xy = x + y * s->mb_stride;
1347
1348 2340 s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 * s->mb_stride));
1349 }
1350
1351 8 init_dequant4_coeff_table(s);
1352
1353 8 return 0;
1354 }
1355
1356 2811 static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
1357 {
1358 2811 SVQ3Context *s = avctx->priv_data;
1359 2811 int ret = ff_get_buffer(avctx, pic->f,
1360 2811 (s->pict_type != AV_PICTURE_TYPE_B) ?
1361 AV_GET_BUFFER_FLAG_REF : 0);
1362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (ret < 0)
1363 return ret;
1364
1365
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2807 times.
2811 if (!s->edge_emu_buffer) {
1366 4 s->edge_emu_buffer = av_calloc(pic->f->linesize[0], 17);
1367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!s->edge_emu_buffer)
1368 return AVERROR(ENOMEM);
1369 }
1370
1371 2811 return 0;
1372 }
1373
1374 static av_cold int alloc_dummy_frame(AVCodecContext *avctx, SVQ3Frame *pic)
1375 {
1376 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1377 av_frame_unref(pic->f);
1378 int ret = get_buffer(avctx, pic);
1379 if (ret < 0)
1380 return ret;
1381
1382 memset(pic->f->data[0], 0, avctx->height * pic->f->linesize[0]);
1383 memset(pic->f->data[1], 0x80, (avctx->height / 2) *
1384 pic->f->linesize[1]);
1385 memset(pic->f->data[2], 0x80, (avctx->height / 2) *
1386 pic->f->linesize[2]);
1387
1388 return 0;
1389 }
1390
1391 2817 static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1392 int *got_frame, AVPacket *avpkt)
1393 {
1394 2817 SVQ3Context *s = avctx->priv_data;
1395 2817 int buf_size = avpkt->size;
1396 int left;
1397 int ret, m, i;
1398
1399 /* special case for last picture */
1400
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2811 times.
2817 if (buf_size == 0) {
1401
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 if (s->next_pic->f->data[0] && !s->low_delay) {
1402 3 av_frame_move_ref(rframe, s->next_pic->f);
1403 3 *got_frame = 1;
1404 }
1405 6 return 0;
1406 }
1407
1408 2811 s->mb_x = s->mb_y = s->mb_xy = 0;
1409
1410 2811 ret = init_get_bits8(&s->gb, avpkt->data, avpkt->size);
1411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (ret < 0)
1412 return ret;
1413
1414 2811 ret = svq3_decode_slice_header(avctx);
1415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (ret < 0)
1416 return ret;
1417
1418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (avpkt->size < s->mb_width * s->mb_height / 8)
1419 return AVERROR_INVALIDDATA;
1420
1421 2811 s->pict_type = s->slice_type;
1422
1423
2/2
✓ Branch 0 taken 2807 times.
✓ Branch 1 taken 4 times.
2811 if (s->pict_type != AV_PICTURE_TYPE_B)
1424 2807 FFSWAP(SVQ3Frame*, s->next_pic, s->last_pic);
1425
1426 2811 av_frame_unref(s->cur_pic->f);
1427
1428 /* for skipping the frame */
1429 2811 s->cur_pic->f->pict_type = s->pict_type;
1430
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 2747 times.
2811 if (s->pict_type == AV_PICTURE_TYPE_I)
1431 64 s->cur_pic->f->flags |= AV_FRAME_FLAG_KEY;
1432 else
1433 2747 s->cur_pic->f->flags &= ~AV_FRAME_FLAG_KEY;
1434
1435 2811 ret = get_buffer(avctx, s->cur_pic);
1436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (ret < 0)
1437 return ret;
1438
1439
2/2
✓ Branch 0 taken 44976 times.
✓ Branch 1 taken 2811 times.
47787 for (i = 0; i < 16; i++) {
1440 44976 s->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1441 44976 s->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1442 }
1443
2/2
✓ Branch 0 taken 44976 times.
✓ Branch 1 taken 2811 times.
47787 for (i = 0; i < 16; i++) {
1444 44976 s->block_offset[16 + i] =
1445 44976 s->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1446 44976 s->block_offset[48 + 16 + i] =
1447 44976 s->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1448 }
1449
1450
2/2
✓ Branch 0 taken 2747 times.
✓ Branch 1 taken 64 times.
2811 if (s->pict_type != AV_PICTURE_TYPE_I) {
1451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2747 times.
2747 if (!s->last_pic->f->data[0]) {
1452 ret = alloc_dummy_frame(avctx, s->last_pic);
1453 if (ret < 0)
1454 return ret;
1455 }
1456
1457
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2743 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2747 if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
1458 ret = alloc_dummy_frame(avctx, s->next_pic);
1459 if (ret < 0)
1460 return ret;
1461 }
1462 }
1463
1464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (avctx->debug & FF_DEBUG_PICT_INFO)
1465 av_log(s->avctx, AV_LOG_DEBUG,
1466 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1467 av_get_picture_type_char(s->pict_type),
1468 s->halfpel_flag, s->thirdpel_flag,
1469 s->adaptive_quant, s->qscale, s->slice_num);
1470
1471
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2811 if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
1472
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2811 avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
1473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 avctx->skip_frame >= AVDISCARD_ALL)
1474 return 0;
1475
1476
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2807 times.
2811 if (s->pict_type == AV_PICTURE_TYPE_B) {
1477 4 s->frame_num_offset = s->slice_num - s->prev_frame_num;
1478
1479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (s->frame_num_offset < 0)
1480 s->frame_num_offset += 256;
1481
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (s->frame_num_offset == 0 ||
1482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 s->frame_num_offset >= s->prev_frame_num_offset) {
1483 av_log(s->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
1484 return -1;
1485 }
1486 } else {
1487 2807 s->prev_frame_num = s->frame_num;
1488 2807 s->frame_num = s->slice_num;
1489 2807 s->prev_frame_num_offset = s->frame_num - s->prev_frame_num;
1490
1491
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2797 times.
2807 if (s->prev_frame_num_offset < 0)
1492 10 s->prev_frame_num_offset += 256;
1493 }
1494
1495
2/2
✓ Branch 0 taken 5622 times.
✓ Branch 1 taken 2811 times.
8433 for (m = 0; m < 2; m++) {
1496 int i;
1497
2/2
✓ Branch 0 taken 22488 times.
✓ Branch 1 taken 5622 times.
28110 for (i = 0; i < 4; i++) {
1498 int j;
1499
2/2
✓ Branch 0 taken 112440 times.
✓ Branch 1 taken 22488 times.
134928 for (j = -1; j < 4; j++)
1500 112440 s->ref_cache[m][scan8[0] + 8 * i + j] = 1;
1501
2/2
✓ Branch 0 taken 16866 times.
✓ Branch 1 taken 5622 times.
22488 if (i < 3)
1502 16866 s->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
1503 }
1504 }
1505
1506
2/2
✓ Branch 0 taken 42165 times.
✓ Branch 1 taken 2811 times.
44976 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
1507
2/2
✓ Branch 0 taken 843000 times.
✓ Branch 1 taken 42165 times.
885165 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
1508 unsigned mb_type;
1509 843000 s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
1510
1511
2/2
✓ Branch 1 taken 3847 times.
✓ Branch 2 taken 839153 times.
843000 if ((get_bits_left(&s->gb_slice)) <= 7) {
1512
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 ||
1513 3847 show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
1514
1515 ret = svq3_decode_slice_header(avctx);
1516 if (ret < 0)
1517 return ret;
1518 }
1519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3847 times.
3847 if (s->slice_type != s->pict_type) {
1520 avpriv_request_sample(avctx, "non constant slice type");
1521 }
1522 /* TODO: support s->mb_skip_run */
1523 }
1524
1525 843000 mb_type = get_interleaved_ue_golomb(&s->gb_slice);
1526
1527
2/2
✓ Branch 0 taken 19170 times.
✓ Branch 1 taken 823830 times.
843000 if (s->pict_type == AV_PICTURE_TYPE_I)
1528 19170 mb_type += 8;
1529
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 822750 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1058 times.
823830 else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
1530 22 mb_type += 4;
1531
2/4
✓ Branch 0 taken 843000 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 843000 times.
843000 if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
1532 av_log(s->avctx, AV_LOG_ERROR,
1533 "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
1534 return -1;
1535 }
1536
1537
4/4
✓ Branch 0 taken 353912 times.
✓ Branch 1 taken 489088 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 353852 times.
843000 if (mb_type != 0 || s->cbp)
1538 489148 hl_decode_mb(s);
1539
1540
3/4
✓ Branch 0 taken 841920 times.
✓ Branch 1 taken 1080 times.
✓ Branch 2 taken 841920 times.
✗ Branch 3 not taken.
843000 if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
1541 841920 s->cur_pic->mb_type[s->mb_x + s->mb_y * s->mb_stride] =
1542
4/4
✓ Branch 0 taken 822750 times.
✓ Branch 1 taken 19170 times.
✓ Branch 2 taken 791320 times.
✓ Branch 3 taken 31430 times.
841920 (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
1543 }
1544
1545 42165 ff_draw_horiz_band(avctx, s->cur_pic->f,
1546 42105 s->last_pic->f->data[0] ? s->last_pic->f : NULL,
1547
2/2
✓ Branch 0 taken 42105 times.
✓ Branch 1 taken 60 times.
42165 16 * s->mb_y, 16, PICT_FRAME, 0,
1548 s->low_delay);
1549 }
1550
1551 2811 left = buf_size*8 - get_bits_count(&s->gb_slice);
1552
1553
2/4
✓ Branch 0 taken 2811 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2811 times.
2811 if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
1554 av_log(avctx, AV_LOG_INFO, "frame num %"PRId64" incomplete pic x %d y %d left %d\n", avctx->frame_num, s->mb_y, s->mb_x, left);
1555 //av_hex_dump(stderr, buf+buf_size-8, 8);
1556 }
1557
1558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (left < 0) {
1559 av_log(avctx, AV_LOG_ERROR, "frame num %"PRId64" left %d\n", avctx->frame_num, left);
1560 return -1;
1561 }
1562
1563
3/4
✓ Branch 0 taken 2807 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2807 times.
2811 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
1564 4 ret = av_frame_ref(rframe, s->cur_pic->f);
1565
2/2
✓ Branch 0 taken 2803 times.
✓ Branch 1 taken 4 times.
2807 else if (s->last_pic->f->data[0])
1566 2803 ret = av_frame_ref(rframe, s->last_pic->f);
1567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2811 times.
2811 if (ret < 0)
1568 return ret;
1569
1570 /* Do not output the last pic after seeking. */
1571
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2807 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2811 if (s->last_pic->f->data[0] || s->low_delay)
1572 2807 *got_frame = 1;
1573
1574
2/2
✓ Branch 0 taken 2807 times.
✓ Branch 1 taken 4 times.
2811 if (s->pict_type != AV_PICTURE_TYPE_B) {
1575 2807 FFSWAP(SVQ3Frame*, s->cur_pic, s->next_pic);
1576 } else {
1577 4 av_frame_unref(s->cur_pic->f);
1578 }
1579
1580 2811 return buf_size;
1581 }
1582
1583 8 static av_cold int svq3_decode_end(AVCodecContext *avctx)
1584 {
1585 8 SVQ3Context *s = avctx->priv_data;
1586
1587
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (int i = 0; i < NUM_PICS; i++)
1588 24 av_frame_free(&s->frames[i].f);
1589 8 av_freep(&s->motion_val_buf);
1590 8 av_freep(&s->mb_type_buf);
1591 8 av_freep(&s->slice_buf);
1592 8 av_freep(&s->intra4x4_pred_mode);
1593 8 av_freep(&s->edge_emu_buffer);
1594 8 av_freep(&s->mb2br_xy);
1595
1596 8 return 0;
1597 }
1598
1599 const FFCodec ff_svq3_decoder = {
1600 .p.name = "svq3",
1601 CODEC_LONG_NAME("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
1602 .p.type = AVMEDIA_TYPE_VIDEO,
1603 .p.id = AV_CODEC_ID_SVQ3,
1604 .priv_data_size = sizeof(SVQ3Context),
1605 .init = svq3_decode_init,
1606 .close = svq3_decode_end,
1607 FF_CODEC_DECODE_CB(svq3_decode_frame),
1608 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND |
1609 AV_CODEC_CAP_DR1 |
1610 AV_CODEC_CAP_DELAY,
1611 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1612 };
1613