FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/svq3.c
Date: 2024-04-23 06:12:56
Exec Total Coverage
Lines: 682 829 82.3%
Functions: 18 18 100.0%
Branches: 439 565 77.7%

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