FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/svq3.c
Date: 2025-07-28 20:30:09
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 4017149 static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
259 int stride, int qp, int dc)
260 {
261 4017149 const int qmul = svq3_dequant_coeff[qp];
262 int i;
263
264
2/2
✓ Branch 0 taken 999789 times.
✓ Branch 1 taken 3017360 times.
4017149 if (dc) {
265
2/2
✓ Branch 0 taken 26094 times.
✓ Branch 1 taken 973695 times.
999789 dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
266 973695 : qmul * (block[0] >> 3) / 2);
267 999789 block[0] = 0;
268 }
269
270
2/2
✓ Branch 0 taken 16068596 times.
✓ Branch 1 taken 4017149 times.
20085745 for (i = 0; i < 4; i++) {
271 16068596 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
272 16068596 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
273 16068596 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
274 16068596 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
275
276 16068596 block[0 + 4 * i] = z0 + z3;
277 16068596 block[1 + 4 * i] = z1 + z2;
278 16068596 block[2 + 4 * i] = z1 - z2;
279 16068596 block[3 + 4 * i] = z0 - z3;
280 }
281
282
2/2
✓ Branch 0 taken 16068596 times.
✓ Branch 1 taken 4017149 times.
20085745 for (i = 0; i < 4; i++) {
283 16068596 const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
284 16068596 const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
285 16068596 const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
286 16068596 const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
287 16068596 const int rr = (dc + 0x80000u);
288
289 16068596 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
290 16068596 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
291 16068596 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
292 16068596 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
293 }
294
295 4017149 memset(block, 0, 16 * sizeof(int16_t));
296 4017149 }
297
298 3885381 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 3885381 const int intra = 3 * type >> 2;
308 3885381 const uint8_t *const scan = scan_patterns[type];
309
310
2/2
✓ Branch 0 taken 4445853 times.
✓ Branch 1 taken 560472 times.
5006325 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
311
2/2
✓ Branch 1 taken 5383846 times.
✓ Branch 2 taken 4445853 times.
9829699 for (; (vlc = get_interleaved_ue_golomb(gb)) != 0; index++) {
312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5383846 times.
5383846 if ((int32_t)vlc < 0)
313 return -1;
314
315
2/2
✓ Branch 0 taken 2639412 times.
✓ Branch 1 taken 2744434 times.
5383846 sign = (vlc & 1) ? 0 : -1;
316 5383846 vlc = vlc + 1 >> 1;
317
318
2/2
✓ Branch 0 taken 249899 times.
✓ Branch 1 taken 5133947 times.
5383846 if (type == 3) {
319
2/2
✓ Branch 0 taken 169166 times.
✓ Branch 1 taken 80733 times.
249899 if (vlc < 3) {
320 169166 run = 0;
321 169166 level = vlc;
322
2/2
✓ Branch 0 taken 34238 times.
✓ Branch 1 taken 46495 times.
80733 } else if (vlc < 4) {
323 34238 run = 1;
324 34238 level = 1;
325 } else {
326 46495 run = vlc & 0x3;
327 46495 level = (vlc + 9 >> 2) - run;
328 }
329 } else {
330
2/2
✓ Branch 0 taken 5041382 times.
✓ Branch 1 taken 92565 times.
5133947 if (vlc < 16U) {
331 5041382 run = svq3_dct_tables[intra][vlc].run;
332 5041382 level = svq3_dct_tables[intra][vlc].level;
333
2/2
✓ Branch 0 taken 8627 times.
✓ Branch 1 taken 83938 times.
92565 } else if (intra) {
334 8627 run = vlc & 0x7;
335
6/6
✓ Branch 0 taken 5366 times.
✓ Branch 1 taken 3261 times.
✓ Branch 2 taken 3386 times.
✓ Branch 3 taken 1980 times.
✓ Branch 4 taken 3278 times.
✓ Branch 5 taken 108 times.
8627 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
336 } else {
337 83938 run = vlc & 0xF;
338
6/6
✓ Branch 0 taken 51500 times.
✓ Branch 1 taken 32438 times.
✓ Branch 2 taken 21798 times.
✓ Branch 3 taken 29702 times.
✓ Branch 4 taken 18712 times.
✓ Branch 5 taken 3086 times.
83938 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 5383846 times.
5383846 if ((index += run) >= limit)
344 return -1;
345
346 5383846 block[scan[index]] = (level ^ sign) - sign;
347 }
348
349
2/2
✓ Branch 0 taken 3324909 times.
✓ Branch 1 taken 1120944 times.
4445853 if (type != 2) {
350 3324909 break;
351 }
352 }
353
354 3885381 return 0;
355 }
356
357 static av_always_inline int
358 556808 svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C,
359 int i, int list, int part_width)
360 {
361 556808 const int topright_ref = s->ref_cache[list][i - 8 + part_width];
362
363
2/2
✓ Branch 0 taken 475267 times.
✓ Branch 1 taken 81541 times.
556808 if (topright_ref != PART_NOT_AVAILABLE) {
364 475267 *C = s->mv_cache[list][i - 8 + part_width];
365 475267 return topright_ref;
366 } else {
367 81541 *C = s->mv_cache[list][i - 8 - 1];
368 81541 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 556808 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 556808 const int index8 = scan8[n];
384 556808 const int top_ref = s->ref_cache[list][index8 - 8];
385 556808 const int left_ref = s->ref_cache[list][index8 - 1];
386 556808 const int16_t *const A = s->mv_cache[list][index8 - 1];
387 556808 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 556808 diagonal_ref = svq3_fetch_diagonal_mv(s, &C, index8, list, part_width);
400 556808 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
401
2/2
✓ Branch 0 taken 533003 times.
✓ Branch 1 taken 23805 times.
556808 if (match_count > 1) { //most common
402 533003 *mx = mid_pred(A[0], B[0], C[0]);
403 533003 *my = mid_pred(A[1], B[1], C[1]);
404
1/2
✓ Branch 0 taken 23805 times.
✗ Branch 1 not taken.
23805 } else if (match_count == 1) {
405
1/2
✓ Branch 0 taken 23805 times.
✗ Branch 1 not taken.
23805 if (left_ref == ref) {
406 23805 *mx = A[0];
407 23805 *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 556808 }
427
428 911840 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 910709 times.
✓ Branch 1 taken 1131 times.
911840 const SVQ3Frame *pic = (dir == 0) ? s->last_pic : s->next_pic;
434 uint8_t *src, *dest;
435 911840 int i, emu = 0;
436 911840 int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
437 911840 int linesize = s->cur_pic->f->linesize[0];
438 911840 int uvlinesize = s->cur_pic->f->linesize[1];
439
440 911840 mx += x;
441 911840 my += y;
442
443
6/6
✓ Branch 0 taken 905629 times.
✓ Branch 1 taken 6211 times.
✓ Branch 2 taken 873824 times.
✓ Branch 3 taken 31805 times.
✓ Branch 4 taken 870724 times.
✓ Branch 5 taken 3100 times.
911840 if (mx < 0 || mx >= s->h_edge_pos - width - 1 ||
444
2/2
✓ Branch 0 taken 47592 times.
✓ Branch 1 taken 823132 times.
870724 my < 0 || my >= s->v_edge_pos - height - 1) {
445 88708 emu = 1;
446 88708 mx = av_clip(mx, -16, s->h_edge_pos - width + 15);
447 88708 my = av_clip(my, -16, s->v_edge_pos - height + 15);
448 }
449
450 /* form component predictions */
451 911840 dest = s->cur_pic->f->data[0] + x + y * linesize;
452 911840 src = pic->f->data[0] + mx + my * linesize;
453
454
2/2
✓ Branch 0 taken 88708 times.
✓ Branch 1 taken 823132 times.
911840 if (emu) {
455 88708 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 88708 src = s->edge_emu_buffer;
460 }
461
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 911658 times.
911840 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 910590 times.
911658 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, linesize,
468 height);
469
470
1/2
✓ Branch 0 taken 911840 times.
✗ Branch 1 not taken.
911840 if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
471 911840 mx = mx + (mx < (int) x) >> 1;
472 911840 my = my + (my < (int) y) >> 1;
473 911840 width = width >> 1;
474 911840 height = height >> 1;
475 911840 blocksize++;
476
477
2/2
✓ Branch 0 taken 1823680 times.
✓ Branch 1 taken 911840 times.
2735520 for (i = 1; i < 3; i++) {
478 1823680 dest = s->cur_pic->f->data[i] + (x >> 1) + (y >> 1) * uvlinesize;
479 1823680 src = pic->f->data[i] + mx + my * uvlinesize;
480
481
2/2
✓ Branch 0 taken 177416 times.
✓ Branch 1 taken 1646264 times.
1823680 if (emu) {
482 177416 s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
483 uvlinesize, uvlinesize,
484 width + 1, height + 1,
485 177416 mx, my, (s->h_edge_pos >> 1),
486 177416 s->v_edge_pos >> 1);
487 177416 src = s->edge_emu_buffer;
488 }
489
2/2
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 1823316 times.
1823680 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 1821180 times.
1823316 : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
497 uvlinesize,
498 height);
499 }
500 }
501 911840 }
502
503 439074 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
2/2
✓ Branch 0 taken 439052 times.
✓ Branch 1 taken 22 times.
439074 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
508 439074 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
509
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 438288 times.
439074 const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0;
510 439074 const int h_edge_pos = 6 * (s->h_edge_pos - part_width) - extra_width;
511 439074 const int v_edge_pos = 6 * (s->v_edge_pos - part_height) - extra_width;
512
513
2/2
✓ Branch 0 taken 478620 times.
✓ Branch 1 taken 439074 times.
917694 for (i = 0; i < 16; i += part_height)
514
2/2
✓ Branch 0 taken 557846 times.
✓ Branch 1 taken 478620 times.
1036466 for (j = 0; j < 16; j += part_width) {
515 557846 const int b_xy = (4 * s->mb_x + (j >> 2)) +
516 557846 (4 * s->mb_y + (i >> 2)) * s->b_stride;
517 int dxy;
518 557846 x = 16 * s->mb_x + j;
519 557846 y = 16 * s->mb_y + i;
520 557846 k = (j >> 2 & 1) + (i >> 1 & 2) +
521 557846 (j >> 1 & 4) + (i & 8);
522
523
2/2
✓ Branch 0 taken 556808 times.
✓ Branch 1 taken 1038 times.
557846 if (mode != PREDICT_MODE) {
524 556808 svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);
525 } else {
526 1038 mx = s->next_pic->motion_val[0][b_xy][0] * 2;
527 1038 my = s->next_pic->motion_val[0][b_xy][1] * 2;
528
529
2/2
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 519 times.
1038 if (dir == 0) {
530 519 mx = mx * s->frame_num_offset /
531 519 s->prev_frame_num_offset + 1 >> 1;
532 519 my = my * s->frame_num_offset /
533 519 s->prev_frame_num_offset + 1 >> 1;
534 } else {
535 519 mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /
536 519 s->prev_frame_num_offset + 1 >> 1;
537 519 my = my * (s->frame_num_offset - s->prev_frame_num_offset) /
538 519 s->prev_frame_num_offset + 1 >> 1;
539 }
540 }
541
542 /* clip motion vector prediction to frame border */
543 557846 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
544 557846 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
545
546 /* get (optional) motion vector differential */
547
2/2
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 556808 times.
557846 if (mode == PREDICT_MODE) {
548 1038 dx = dy = 0;
549 } else {
550 556808 dy = get_interleaved_se_golomb(&s->gb_slice);
551 556808 dx = get_interleaved_se_golomb(&s->gb_slice);
552
553
2/4
✓ Branch 0 taken 556808 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 556808 times.
556808 if (dx != (int16_t)dx || dy != (int16_t)dy) {
554 av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
555 return -1;
556 }
557 }
558
559 /* compute motion vector */
560
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 557664 times.
557846 if (mode == THIRDPEL_MODE) {
561 int fx, fy;
562 182 mx = (mx + 1 >> 1) + dx;
563 182 my = (my + 1 >> 1) + dy;
564 182 fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
565 182 fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
566 182 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
567
568 182 svq3_mc_dir_part(s, x, y, part_width, part_height,
569 fx, fy, dxy, 1, dir, avg);
570 182 mx += mx;
571 182 my += my;
572
4/4
✓ Branch 0 taken 282368 times.
✓ Branch 1 taken 275296 times.
✓ Branch 2 taken 1038 times.
✓ Branch 3 taken 281330 times.
557664 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
573 276334 mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
574 276334 my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
575 276334 dxy = (mx & 1) + 2 * (my & 1);
576
577 276334 svq3_mc_dir_part(s, x, y, part_width, part_height,
578 mx >> 1, my >> 1, dxy, 0, dir, avg);
579 276334 mx *= 3;
580 276334 my *= 3;
581 } else {
582 281330 mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
583 281330 my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
584
585 281330 svq3_mc_dir_part(s, x, y, part_width, part_height,
586 mx, my, 0, 0, dir, avg);
587 281330 mx *= 6;
588 281330 my *= 6;
589 }
590
591 /* update mv_cache */
592
2/2
✓ Branch 0 taken 556808 times.
✓ Branch 1 taken 1038 times.
557846 if (mode != PREDICT_MODE) {
593 556808 int32_t mv = pack16to32(mx, my);
594
595
4/4
✓ Branch 0 taken 157802 times.
✓ Branch 1 taken 399006 times.
✓ Branch 2 taken 78901 times.
✓ Branch 3 taken 78901 times.
556808 if (part_height == 8 && i < 8) {
596 78901 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);
597
598
4/4
✓ Branch 0 taken 78822 times.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 39411 times.
✓ Branch 3 taken 39411 times.
78901 if (part_width == 8 && j < 8)
599 39411 AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
600 }
601
4/4
✓ Branch 0 taken 157868 times.
✓ Branch 1 taken 398940 times.
✓ Branch 2 taken 78934 times.
✓ Branch 3 taken 78934 times.
556808 if (part_width == 8 && j < 8)
602 78934 AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);
603
4/4
✓ Branch 0 taken 556672 times.
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 556624 times.
556808 if (part_width == 4 || part_height == 4)
604 184 AV_WN32A(s->mv_cache[dir][scan8[k]], mv);
605 }
606
607 /* write back motion vectors */
608 557846 fill_rectangle(s->cur_pic->motion_val[dir][b_xy],
609 part_width >> 2, part_height >> 2, s->b_stride,
610 pack16to32(mx, my), 4);
611 }
612
613 439074 return 0;
614 }
615
616 488854 static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s,
617 int mb_type, const int *block_offset,
618 int linesize, uint8_t *dest_y)
619 {
620 int i;
621
2/2
✓ Branch 0 taken 440804 times.
✓ Branch 1 taken 48050 times.
488854 if (!IS_INTRA4x4(mb_type)) {
622
2/2
✓ Branch 0 taken 7052864 times.
✓ Branch 1 taken 440804 times.
7493668 for (i = 0; i < 16; i++)
623
4/4
✓ Branch 0 taken 4592260 times.
✓ Branch 1 taken 2460604 times.
✓ Branch 2 taken 22222 times.
✓ Branch 3 taken 4570038 times.
7052864 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
624 2482826 uint8_t *const ptr = dest_y + block_offset[i];
625 2482826 svq3_add_idct_c(ptr, s->mb + i * 16, linesize,
626 2482826 s->qscale, IS_INTRA(mb_type) ? 1 : 0);
627 }
628 }
629 488854 }
630
631 50587 static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s,
632 int mb_type,
633 const int *block_offset,
634 int linesize,
635 uint8_t *dest_y)
636 {
637 int i;
638 50587 int qscale = s->qscale;
639
640
2/2
✓ Branch 0 taken 48050 times.
✓ Branch 1 taken 2537 times.
50587 if (IS_INTRA4x4(mb_type)) {
641
2/2
✓ Branch 0 taken 768800 times.
✓ Branch 1 taken 48050 times.
816850 for (i = 0; i < 16; i++) {
642 768800 uint8_t *const ptr = dest_y + block_offset[i];
643 768800 const int dir = s->intra4x4_pred_mode_cache[scan8[i]];
644
645 uint8_t *topright;
646 int nnz;
647
3/4
✓ Branch 0 taken 715809 times.
✓ Branch 1 taken 52991 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 715809 times.
768800 if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
648 av_assert2(s->mb_y || linesize <= block_offset[i]);
649 52991 topright = ptr + 4 - linesize;
650 } else
651 715809 topright = NULL;
652
653 768800 s->hpc.pred4x4[dir](ptr, topright, linesize);
654 768800 nnz = s->non_zero_count_cache[scan8[i]];
655
2/2
✓ Branch 0 taken 560628 times.
✓ Branch 1 taken 208172 times.
768800 if (nnz) {
656 560628 svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);
657 }
658 }
659 } else {
660 2537 s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);
661 2537 svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);
662 }
663 50587 }
664
665 488854 static void hl_decode_mb(SVQ3Context *s)
666 {
667 488854 const int mb_x = s->mb_x;
668 488854 const int mb_y = s->mb_y;
669 488854 const int mb_xy = s->mb_xy;
670 488854 const int mb_type = s->cur_pic->mb_type[mb_xy];
671 uint8_t *dest_y, *dest_cb, *dest_cr;
672 int linesize, uvlinesize;
673 int i, j;
674 488854 const int *block_offset = &s->block_offset[0];
675 488854 const int block_h = 16 >> 1;
676
677 488854 linesize = s->cur_pic->f->linesize[0];
678 488854 uvlinesize = s->cur_pic->f->linesize[1];
679
680 488854 dest_y = s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
681 488854 dest_cb = s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
682 488854 dest_cr = s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
683
684 488854 s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
685 488854 s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
686
687
2/2
✓ Branch 0 taken 50587 times.
✓ Branch 1 taken 438267 times.
488854 if (IS_INTRA(mb_type)) {
688 50587 s->hpc.pred8x8[s->chroma_pred_mode](dest_cb, uvlinesize);
689 50587 s->hpc.pred8x8[s->chroma_pred_mode](dest_cr, uvlinesize);
690
691 50587 hl_decode_mb_predict_luma(s, mb_type, block_offset, linesize, dest_y);
692 }
693
694 488854 hl_decode_mb_idct_luma(s, mb_type, block_offset, linesize, dest_y);
695
696
2/2
✓ Branch 0 taken 159382 times.
✓ Branch 1 taken 329472 times.
488854 if (s->cbp & 0x30) {
697 159382 uint8_t *dest[2] = { dest_cb, dest_cr };
698 159382 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 1,
699 159382 s->dequant4_coeff[4][0]);
700 159382 s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 2,
701 159382 s->dequant4_coeff[4][0]);
702
2/2
✓ Branch 0 taken 318764 times.
✓ Branch 1 taken 159382 times.
478146 for (j = 1; j < 3; j++) {
703
2/2
✓ Branch 0 taken 1275056 times.
✓ Branch 1 taken 318764 times.
1593820 for (i = j * 16; i < j * 16 + 4; i++)
704
4/4
✓ Branch 0 taken 732208 times.
✓ Branch 1 taken 542848 times.
✓ Branch 2 taken 430847 times.
✓ Branch 3 taken 301361 times.
1275056 if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
705 973695 uint8_t *const ptr = dest[j - 1] + block_offset[i];
706 973695 svq3_add_idct_c(ptr, s->mb + i * 16,
707 973695 uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
708 }
709 }
710 }
711 488854 }
712
713 842700 static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
714 {
715 int i, j, k, m, dir, mode;
716 842700 int cbp = 0;
717 uint32_t vlc;
718 int8_t *top, *left;
719 842700 const int mb_xy = s->mb_xy;
720 842700 const int b_xy = 4 * s->mb_x + 4 * s->mb_y * s->b_stride;
721
722
2/2
✓ Branch 0 taken 56180 times.
✓ Branch 1 taken 786520 times.
842700 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
723
2/2
✓ Branch 0 taken 42150 times.
✓ Branch 1 taken 800550 times.
842700 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
724
725
2/2
✓ Branch 0 taken 353906 times.
✓ Branch 1 taken 488794 times.
842700 if (mb_type == 0) { /* SKIP */
726
2/2
✓ Branch 0 taken 874 times.
✓ Branch 1 taken 353032 times.
353906 if (s->pict_type == AV_PICTURE_TYPE_P ||
727
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 393 times.
874 s->next_pic->mb_type[mb_xy] == -1) {
728 353513 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
729 0, 0, 0, 0, 0, 0);
730
731
2/2
✓ Branch 0 taken 481 times.
✓ Branch 1 taken 353032 times.
353513 if (s->pict_type == AV_PICTURE_TYPE_B)
732 481 svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
733 0, 0, 0, 0, 1, 1);
734
735 353513 mb_type = MB_TYPE_SKIP;
736 } else {
737 393 mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
738
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
739 return -1;
740
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
741 return -1;
742
743 393 mb_type = MB_TYPE_16x16;
744 }
745
2/2
✓ Branch 0 taken 438207 times.
✓ Branch 1 taken 50587 times.
488794 } else if (mb_type < 8) { /* INTER */
746
4/4
✓ Branch 0 taken 833 times.
✓ Branch 1 taken 437374 times.
✓ Branch 3 taken 129 times.
✓ Branch 4 taken 704 times.
438207 if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
747 129 mode = THIRDPEL_MODE;
748
1/2
✓ Branch 0 taken 438078 times.
✗ Branch 1 not taken.
438078 else if (s->halfpel_flag &&
749
2/2
✓ Branch 1 taken 197151 times.
✓ Branch 2 taken 240927 times.
438078 s->thirdpel_flag == !get_bits1(&s->gb_slice))
750 197151 mode = HALFPEL_MODE;
751 else
752 240927 mode = FULLPEL_MODE;
753
754 /* fill caches */
755 /* note ref_cache should contain here:
756 * ????????
757 * ???11111
758 * N??11111
759 * N??11111
760 * N??11111
761 */
762
763
2/2
✓ Branch 0 taken 438391 times.
✓ Branch 1 taken 184 times.
438575 for (m = 0; m < 2; m++) {
764
3/4
✓ Branch 0 taken 421631 times.
✓ Branch 1 taken 16760 times.
✓ Branch 2 taken 421631 times.
✗ Branch 3 not taken.
438391 if (s->mb_x > 0 && s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6] != -1) {
765
2/2
✓ Branch 0 taken 1686524 times.
✓ Branch 1 taken 421631 times.
2108155 for (i = 0; i < 4; i++)
766 1686524 AV_COPY32(s->mv_cache[m][scan8[0] - 1 + i * 8],
767 s->cur_pic->motion_val[m][b_xy - 1 + i * s->b_stride]);
768 } else {
769
2/2
✓ Branch 0 taken 67040 times.
✓ Branch 1 taken 16760 times.
83800 for (i = 0; i < 4; i++)
770 67040 AV_ZERO32(s->mv_cache[m][scan8[0] - 1 + i * 8]);
771 }
772
2/2
✓ Branch 0 taken 415485 times.
✓ Branch 1 taken 22906 times.
438391 if (s->mb_y > 0) {
773 415485 memcpy(s->mv_cache[m][scan8[0] - 1 * 8],
774 415485 s->cur_pic->motion_val[m][b_xy - s->b_stride],
775 4 * 2 * sizeof(int16_t));
776 415485 memset(&s->ref_cache[m][scan8[0] - 1 * 8],
777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415485 times.
415485 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
778
779
2/2
✓ Branch 0 taken 397233 times.
✓ Branch 1 taken 18252 times.
415485 if (s->mb_x < s->mb_width - 1) {
780 397233 AV_COPY32(s->mv_cache[m][scan8[0] + 4 - 1 * 8],
781 s->cur_pic->motion_val[m][b_xy - s->b_stride + 4]);
782 397233 s->ref_cache[m][scan8[0] + 4 - 1 * 8] =
783
1/2
✓ Branch 0 taken 397233 times.
✗ Branch 1 not taken.
397233 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397233 times.
397233 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
785 } else
786 18252 s->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
787
2/2
✓ Branch 0 taken 399643 times.
✓ Branch 1 taken 15842 times.
415485 if (s->mb_x > 0) {
788 399643 AV_COPY32(s->mv_cache[m][scan8[0] - 1 - 1 * 8],
789 s->cur_pic->motion_val[m][b_xy - s->b_stride - 1]);
790 399643 s->ref_cache[m][scan8[0] - 1 - 1 * 8] =
791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399643 times.
399643 (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
792 } else
793 15842 s->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
794 } else
795 22906 memset(&s->ref_cache[m][scan8[0] - 1 * 8 - 1],
796 PART_NOT_AVAILABLE, 8);
797
798
2/2
✓ Branch 0 taken 438023 times.
✓ Branch 1 taken 368 times.
438391 if (s->pict_type != AV_PICTURE_TYPE_B)
799 438023 break;
800 }
801
802 /* decode motion vector(s) and form prediction(s) */
803
2/2
✓ Branch 0 taken 438023 times.
✓ Branch 1 taken 184 times.
438207 if (s->pict_type == AV_PICTURE_TYPE_P) {
804
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 438023 times.
438023 if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
805 return -1;
806 } else { /* AV_PICTURE_TYPE_B */
807
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 50 times.
184 if (mb_type != 2) {
808
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
134 if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
809 return -1;
810 } else {
811
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 50 times.
250 for (i = 0; i < 4; i++)
812 200 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
813 0, 4 * 2 * sizeof(int16_t));
814 }
815
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 53 times.
184 if (mb_type != 1) {
816
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
131 if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
817 return -1;
818 } else {
819
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 53 times.
265 for (i = 0; i < 4; i++)
820 212 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
821 0, 4 * 2 * sizeof(int16_t));
822 }
823 }
824
825 438207 mb_type = MB_TYPE_16x16;
826
3/4
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 48050 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2537 times.
50587 } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
827 48050 int8_t *i4x4 = s->intra4x4_pred_mode + s->mb2br_xy[s->mb_xy];
828 48050 int8_t *i4x4_cache = s->intra4x4_pred_mode_cache;
829
830 48050 memset(s->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
831
832
1/2
✓ Branch 0 taken 48050 times.
✗ Branch 1 not taken.
48050 if (mb_type == 8) {
833
2/2
✓ Branch 0 taken 44048 times.
✓ Branch 1 taken 4002 times.
48050 if (s->mb_x > 0) {
834
2/2
✓ Branch 0 taken 176192 times.
✓ Branch 1 taken 44048 times.
220240 for (i = 0; i < 4; i++)
835 176192 s->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6 - i];
836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44048 times.
44048 if (s->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
837 s->left_samples_available = 0x5F5F;
838 }
839
2/2
✓ Branch 0 taken 45141 times.
✓ Branch 1 taken 2909 times.
48050 if (s->mb_y > 0) {
840 45141 s->intra4x4_pred_mode_cache[4 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 0];
841 45141 s->intra4x4_pred_mode_cache[5 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 1];
842 45141 s->intra4x4_pred_mode_cache[6 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 2];
843 45141 s->intra4x4_pred_mode_cache[7 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 3];
844
845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45141 times.
45141 if (s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
846 s->top_samples_available = 0x33FF;
847 }
848
849 /* decode prediction codes for luma blocks */
850
2/2
✓ Branch 0 taken 384400 times.
✓ Branch 1 taken 48050 times.
432450 for (i = 0; i < 16; i += 2) {
851 384400 vlc = get_interleaved_ue_golomb(&s->gb_slice);
852
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 384400 times.
384400 if (vlc >= 25U) {
854 av_log(s->avctx, AV_LOG_ERROR,
855 "luma prediction:%"PRIu32"\n", vlc);
856 return -1;
857 }
858
859 384400 left = &s->intra4x4_pred_mode_cache[scan8[i] - 1];
860 384400 top = &s->intra4x4_pred_mode_cache[scan8[i] - 8];
861
862 384400 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
863 384400 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
864
865
2/4
✓ Branch 0 taken 384400 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 384400 times.
384400 if (left[1] == -1 || left[2] == -1) {
866 av_log(s->avctx, AV_LOG_ERROR, "weird prediction\n");
867 return -1;
868 }
869 }
870 } else { /* mb_type == 33, DC_128_PRED block type */
871 for (i = 0; i < 4; i++)
872 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
873 }
874
875 48050 AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
876 48050 i4x4[4] = i4x4_cache[7 + 8 * 3];
877 48050 i4x4[5] = i4x4_cache[7 + 8 * 2];
878 48050 i4x4[6] = i4x4_cache[7 + 8 * 1];
879
880
1/2
✓ Branch 0 taken 48050 times.
✗ Branch 1 not taken.
48050 if (mb_type == 8) {
881 48050 ff_h264_check_intra4x4_pred_mode(s->intra4x4_pred_mode_cache,
882 48050 s->avctx, s->top_samples_available,
883 48050 s->left_samples_available);
884
885
2/2
✓ Branch 0 taken 2909 times.
✓ Branch 1 taken 45141 times.
48050 s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
886
2/2
✓ Branch 0 taken 4002 times.
✓ Branch 1 taken 44048 times.
48050 s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
887 } else {
888 for (i = 0; i < 4; i++)
889 memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
890
891 s->top_samples_available = 0x33FF;
892 s->left_samples_available = 0x5F5F;
893 }
894
895 48050 mb_type = MB_TYPE_INTRA4x4;
896 } else { /* INTRA16x16 */
897 2537 dir = ff_h264_i_mb_type_info[mb_type - 8].pred_mode;
898 2537 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
899
900
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,
901 2537 s->left_samples_available, dir, 0)) < 0) {
902 av_log(s->avctx, AV_LOG_ERROR, "ff_h264_check_intra_pred_mode < 0\n");
903 return s->intra16x16_pred_mode;
904 }
905
906 2537 cbp = ff_h264_i_mb_type_info[mb_type - 8].cbp;
907 2537 mb_type = MB_TYPE_INTRA16x16;
908 }
909
910
4/4
✓ Branch 0 taken 404100 times.
✓ Branch 1 taken 438600 times.
✓ Branch 2 taken 384930 times.
✓ Branch 3 taken 19170 times.
842700 if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
911
2/2
✓ Branch 0 taken 1539720 times.
✓ Branch 1 taken 384930 times.
1924650 for (i = 0; i < 4; i++)
912 1539720 memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
913 0, 4 * 2 * sizeof(int16_t));
914
2/2
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 384427 times.
384930 if (s->pict_type == AV_PICTURE_TYPE_B) {
915
2/2
✓ Branch 0 taken 2012 times.
✓ Branch 1 taken 503 times.
2515 for (i = 0; i < 4; i++)
916 2012 memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
917 0, 4 * 2 * sizeof(int16_t));
918 }
919 }
920
2/2
✓ Branch 0 taken 794650 times.
✓ Branch 1 taken 48050 times.
842700 if (!IS_INTRA4x4(mb_type)) {
921 794650 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy], DC_PRED, 8);
922 }
923
4/4
✓ Branch 0 taken 353513 times.
✓ Branch 1 taken 489187 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 353032 times.
842700 if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
924 489668 memset(s->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
925 }
926
927
2/2
✓ Branch 0 taken 840163 times.
✓ Branch 1 taken 2537 times.
842700 if (!IS_INTRA16x16(mb_type) &&
928
4/4
✓ Branch 0 taken 353513 times.
✓ Branch 1 taken 486650 times.
✓ Branch 2 taken 481 times.
✓ Branch 3 taken 353032 times.
840163 (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
929
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 487131 times.
487131 if ((vlc = get_interleaved_ue_golomb(&s->gb_slice)) >= 48U){
930 av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
931 return -1;
932 }
933
934 487131 cbp = IS_INTRA(mb_type) ? ff_h264_golomb_to_intra4x4_cbp[vlc]
935
2/2
✓ Branch 0 taken 48050 times.
✓ Branch 1 taken 439081 times.
487131 : ff_h264_golomb_to_inter_cbp[vlc];
936 }
937
2/2
✓ Branch 0 taken 840163 times.
✓ Branch 1 taken 2537 times.
842700 if (IS_INTRA16x16(mb_type) ||
938
6/6
✓ Branch 0 taken 823203 times.
✓ Branch 1 taken 16960 times.
✓ Branch 2 taken 2424 times.
✓ Branch 3 taken 820779 times.
✓ Branch 4 taken 696 times.
✓ Branch 5 taken 1728 times.
840163 (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
939 3233 s->qscale += get_interleaved_se_golomb(&s->gb_slice);
940
941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3233 times.
3233 if (s->qscale > 31u) {
942 av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
943 return -1;
944 }
945 }
946
2/2
✓ Branch 0 taken 2537 times.
✓ Branch 1 taken 840163 times.
842700 if (IS_INTRA16x16(mb_type)) {
947 2537 AV_ZERO128(s->mb_luma_dc[0] + 0);
948 2537 AV_ZERO128(s->mb_luma_dc[0] + 8);
949
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)) {
950 av_log(s->avctx, AV_LOG_ERROR,
951 "error while decoding intra luma dc\n");
952 return -1;
953 }
954 }
955
956
2/2
✓ Branch 0 taken 333795 times.
✓ Branch 1 taken 508905 times.
842700 if (cbp) {
957 333795 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
958
4/4
✓ Branch 0 taken 333729 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 40577 times.
✓ Branch 3 taken 293152 times.
333795 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
959
960
2/2
✓ Branch 0 taken 1335180 times.
✓ Branch 1 taken 333795 times.
1668975 for (i = 0; i < 4; i++)
961
2/2
✓ Branch 0 taken 755308 times.
✓ Branch 1 taken 579872 times.
1335180 if ((cbp & (1 << i))) {
962
2/2
✓ Branch 0 taken 3021232 times.
✓ Branch 1 taken 755308 times.
3776540 for (j = 0; j < 4; j++) {
963 3025104 k = index ? (1 * (j & 1) + 2 * (i & 1) +
964 3872 2 * (j & 2) + 4 * (i & 2))
965
2/2
✓ Branch 0 taken 3872 times.
✓ Branch 1 taken 3017360 times.
3021232 : (4 * i + j);
966 3021232 s->non_zero_count_cache[scan8[k]] = 1;
967
968
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3021232 times.
3021232 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
969 av_log(s->avctx, AV_LOG_ERROR,
970 "error while decoding block\n");
971 return -1;
972 }
973 }
974 }
975
976
2/2
✓ Branch 0 taken 159382 times.
✓ Branch 1 taken 174413 times.
333795 if ((cbp & 0x30)) {
977
2/2
✓ Branch 0 taken 318764 times.
✓ Branch 1 taken 159382 times.
478146 for (i = 1; i < 3; ++i)
978
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 318764 times.
318764 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
979 av_log(s->avctx, AV_LOG_ERROR,
980 "error while decoding chroma dc block\n");
981 return -1;
982 }
983
984
2/2
✓ Branch 0 taken 67856 times.
✓ Branch 1 taken 91526 times.
159382 if ((cbp & 0x20)) {
985
2/2
✓ Branch 0 taken 135712 times.
✓ Branch 1 taken 67856 times.
203568 for (i = 1; i < 3; i++) {
986
2/2
✓ Branch 0 taken 542848 times.
✓ Branch 1 taken 135712 times.
678560 for (j = 0; j < 4; j++) {
987 542848 k = 16 * i + j;
988 542848 s->non_zero_count_cache[scan8[k]] = 1;
989
990
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 542848 times.
542848 if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
991 av_log(s->avctx, AV_LOG_ERROR,
992 "error while decoding chroma ac block\n");
993 return -1;
994 }
995 }
996 }
997 }
998 }
999 }
1000
1001 842700 s->cbp = cbp;
1002 842700 s->cur_pic->mb_type[mb_xy] = mb_type;
1003
1004
2/2
✓ Branch 0 taken 50587 times.
✓ Branch 1 taken 792113 times.
842700 if (IS_INTRA(mb_type))
1005 50587 s->chroma_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
1006 50587 s->left_samples_available, DC_PRED8x8, 1);
1007
1008 842700 return 0;
1009 }
1010
1011 2810 static int svq3_decode_slice_header(AVCodecContext *avctx)
1012 {
1013 2810 SVQ3Context *s = avctx->priv_data;
1014 2810 const int mb_xy = s->mb_xy;
1015 int i, header;
1016 unsigned slice_id;
1017
1018 2810 header = get_bits(&s->gb, 8);
1019
1020
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2810 times.
2810 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
1021 /* TODO: what? */
1022 av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
1023 return -1;
1024 } else {
1025 int slice_bits, slice_bytes, slice_length;
1026 2810 int length = header >> 5 & 3;
1027
1028 2810 slice_length = show_bits(&s->gb, 8 * length);
1029 2810 slice_bits = slice_length * 8;
1030 2810 slice_bytes = slice_length + length - 1;
1031
1032 2810 skip_bits(&s->gb, 8);
1033
1034 2810 av_fast_padded_malloc(&s->slice_buf, &s->slice_buf_size, slice_bytes);
1035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (!s->slice_buf)
1036 return AVERROR(ENOMEM);
1037
1038
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2810 times.
2810 if (slice_bytes * 8LL > get_bits_left(&s->gb)) {
1039 av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
1040 return AVERROR_INVALIDDATA;
1041 }
1042 2810 memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
1043
1044
1/2
✓ Branch 0 taken 2810 times.
✗ Branch 1 not taken.
2810 if (length > 0) {
1045 2810 memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
1046 }
1047
1048
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2800 times.
2810 if (s->watermark_key) {
1049 10 uint32_t header = AV_RL32(&s->slice_buf[1]);
1050 10 AV_WL32(&s->slice_buf[1], header ^ s->watermark_key);
1051 }
1052 2810 init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
1053
1054 2810 skip_bits_long(&s->gb, slice_bytes * 8);
1055 }
1056
1057
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2810 times.
2810 if ((slice_id = get_interleaved_ue_golomb(&s->gb_slice)) >= 3) {
1058 av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
1059 return -1;
1060 }
1061
1062 2810 s->slice_type = ff_h264_golomb_to_pict_type[slice_id];
1063
1064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if ((header & 0x9F) == 2) {
1065 i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
1066 get_bits(&s->gb_slice, i);
1067
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2810 times.
2810 } else if (get_bits1(&s->gb_slice)) {
1068 avpriv_report_missing_feature(s->avctx, "Media key encryption");
1069 return AVERROR_PATCHWELCOME;
1070 }
1071
1072 2810 s->slice_num = get_bits(&s->gb_slice, 8);
1073 2810 s->qscale = get_bits(&s->gb_slice, 5);
1074 2810 s->adaptive_quant = get_bits1(&s->gb_slice);
1075
1076 /* unknown fields */
1077 2810 skip_bits1(&s->gb_slice);
1078
1079
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2800 times.
2810 if (s->has_watermark)
1080 10 skip_bits1(&s->gb_slice);
1081
1082 2810 skip_bits1(&s->gb_slice);
1083 2810 skip_bits(&s->gb_slice, 2);
1084
1085
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2810 times.
2810 if (skip_1stop_8data_bits(&s->gb_slice) < 0)
1086 return AVERROR_INVALIDDATA;
1087
1088 /* reset intra predictors and invalidate motion vector references */
1089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (s->mb_x > 0) {
1090 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,
1091 -1, 4 * sizeof(int8_t));
1092 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],
1093 -1, 8 * sizeof(int8_t) * s->mb_x);
1094 }
1095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (s->mb_y > 0) {
1096 memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],
1097 -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
1098
1099 if (s->mb_x > 0)
1100 s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
1101 }
1102
1103 2810 return 0;
1104 }
1105
1106 8 static void init_dequant4_coeff_table(SVQ3Context *s)
1107 {
1108 int q, x;
1109 8 const int max_qp = 51;
1110
1111
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 8 times.
424 for (q = 0; q < max_qp + 1; q++) {
1112 416 int shift = ff_h264_quant_div6[q] + 2;
1113 416 int idx = ff_h264_quant_rem6[q];
1114
2/2
✓ Branch 0 taken 6656 times.
✓ Branch 1 taken 416 times.
7072 for (x = 0; x < 16; x++)
1115 6656 s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
1116 6656 ((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] * 16) << shift;
1117 }
1118 8 }
1119
1120 8 static av_cold int svq3_decode_extradata(AVCodecContext *avctx, SVQ3Context *s,
1121 int seqh_offset)
1122 {
1123 8 const uint8_t *extradata = avctx->extradata + seqh_offset;
1124 8 unsigned int size = AV_RB32(extradata + 4);
1125 GetBitContext gb;
1126 int ret;
1127
1128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (size > avctx->extradata_size - seqh_offset - 8)
1129 return AVERROR_INVALIDDATA;
1130 8 extradata += 8;
1131 8 init_get_bits(&gb, extradata, size * 8);
1132
1133 /* 'frame size code' and optional 'width, height' */
1134 8 int frame_size_code = get_bits(&gb, 3);
1135 int w, h;
1136
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) {
1137 case 0:
1138 w = 160;
1139 h = 120;
1140 break;
1141 case 1:
1142 w = 128;
1143 h = 96;
1144 break;
1145 case 2:
1146 w = 176;
1147 h = 144;
1148 break;
1149 case 3:
1150 w = 352;
1151 h = 288;
1152 break;
1153 case 4:
1154 w = 704;
1155 h = 576;
1156 break;
1157 case 5:
1158 w = 240;
1159 h = 180;
1160 break;
1161 6 case 6:
1162 6 w = 320;
1163 6 h = 240;
1164 6 break;
1165 2 case 7:
1166 2 w = get_bits(&gb, 12);
1167 2 h = get_bits(&gb, 12);
1168 2 break;
1169 }
1170 8 ret = ff_set_dimensions(avctx, w, h);
1171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
1172 return ret;
1173
1174 8 s->halfpel_flag = get_bits1(&gb);
1175 8 s->thirdpel_flag = get_bits1(&gb);
1176
1177 /* unknown fields */
1178 8 int unk0 = get_bits1(&gb);
1179 8 int unk1 = get_bits1(&gb);
1180 8 int unk2 = get_bits1(&gb);
1181 8 int unk3 = get_bits1(&gb);
1182
1183 8 s->low_delay = get_bits1(&gb);
1184 8 avctx->has_b_frames = !s->low_delay;
1185
1186 /* unknown field */
1187 8 int unk4 = get_bits1(&gb);
1188
1189 8 av_log(avctx, AV_LOG_DEBUG, "Unknown fields %d %d %d %d %d\n",
1190 unk0, unk1, unk2, unk3, unk4);
1191
1192
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (skip_1stop_8data_bits(&gb) < 0)
1193 return AVERROR_INVALIDDATA;
1194
1195 8 s->has_watermark = get_bits1(&gb);
1196
1197
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if (!s->has_watermark)
1198 6 return 0;
1199
1200 #if CONFIG_ZLIB
1201 2 unsigned watermark_width = get_interleaved_ue_golomb(&gb);
1202 2 unsigned watermark_height = get_interleaved_ue_golomb(&gb);
1203 2 int u1 = get_interleaved_ue_golomb(&gb);
1204 2 int u2 = get_bits(&gb, 8);
1205 2 int u3 = get_bits(&gb, 2);
1206 2 int u4 = get_interleaved_ue_golomb(&gb);
1207 2 unsigned long buf_len = watermark_width *
1208 2 watermark_height * 4;
1209 2 int offset = get_bits_count(&gb) + 7 >> 3;
1210
1211
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 ||
1212 2 get_bits_left(&gb) <= 0 ||
1213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
1214 return AVERROR_INVALIDDATA;
1215
1216 2 av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
1217 watermark_width, watermark_height);
1218 2 av_log(avctx, AV_LOG_DEBUG,
1219 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1220 u1, u2, u3, u4, offset);
1221
1222 2 uint8_t *buf = av_malloc(buf_len);
1223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!buf)
1224 return AVERROR(ENOMEM);
1225
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (uncompress(buf, &buf_len, extradata + offset,
1227 2 size - offset) != Z_OK) {
1228 av_log(avctx, AV_LOG_ERROR,
1229 "could not uncompress watermark logo\n");
1230 av_free(buf);
1231 return AVERROR_EXTERNAL;
1232 }
1233 2 s->watermark_key = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0, buf, buf_len));
1234
1235 2 s->watermark_key = s->watermark_key << 16 | s->watermark_key;
1236 2 av_log(avctx, AV_LOG_DEBUG,
1237 "watermark key %#"PRIx32"\n", s->watermark_key);
1238 2 av_free(buf);
1239
1240 2 return 0;
1241 #else
1242 av_log(avctx, AV_LOG_ERROR,
1243 "this svq3 file contains watermark which need zlib support compiled in\n");
1244 return AVERROR(ENOSYS);
1245 #endif
1246 }
1247
1248 8 static av_cold int svq3_decode_init(AVCodecContext *avctx)
1249 {
1250 8 SVQ3Context *s = avctx->priv_data;
1251 int m, x, y;
1252 unsigned char *extradata;
1253 int ret;
1254
1255 8 s->cur_pic = &s->frames[0];
1256 8 s->last_pic = &s->frames[1];
1257 8 s->next_pic = &s->frames[2];
1258
1259 8 s->cur_pic->f = av_frame_alloc();
1260 8 s->last_pic->f = av_frame_alloc();
1261 8 s->next_pic->f = av_frame_alloc();
1262
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)
1263 return AVERROR(ENOMEM);
1264
1265 8 ff_h264dsp_init(&s->h264dsp, 8, 1);
1266 8 ff_h264_pred_init(&s->hpc, AV_CODEC_ID_SVQ3, 8, 1);
1267 8 ff_videodsp_init(&s->vdsp, 8);
1268
1269
1270 8 avctx->bits_per_raw_sample = 8;
1271
1272 8 ff_hpeldsp_init(&s->hdsp, avctx->flags);
1273 8 ff_tpeldsp_init(&s->tdsp);
1274
1275 8 avctx->pix_fmt = AV_PIX_FMT_YUVJ420P;
1276 8 avctx->color_range = AVCOL_RANGE_JPEG;
1277
1278 8 s->avctx = avctx;
1279 8 s->halfpel_flag = 1;
1280 8 s->thirdpel_flag = 1;
1281 8 s->has_watermark = 0;
1282
1283 /* prowl for the "SEQH" marker in the extradata */
1284 8 extradata = (unsigned char *)avctx->extradata;
1285
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (extradata) {
1286
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 for (m = 0; m + 8 < avctx->extradata_size; m++) {
1287
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
72 if (!memcmp(extradata, "SEQH", 4)) {
1288 /* if a match was found, parse the extra data */
1289 8 ret = svq3_decode_extradata(avctx, s, m);
1290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
1291 return ret;
1292 8 break;
1293 }
1294 64 extradata++;
1295 }
1296 }
1297
1298 8 s->mb_width = (avctx->width + 15) / 16;
1299 8 s->mb_height = (avctx->height + 15) / 16;
1300 8 s->mb_stride = s->mb_width + 1;
1301 8 s->mb_num = s->mb_width * s->mb_height;
1302 8 s->b_stride = 4 * s->mb_width;
1303 8 s->h_edge_pos = s->mb_width * 16;
1304 8 s->v_edge_pos = s->mb_height * 16;
1305
1306 8 const unsigned big_mb_num = s->mb_stride * (s->mb_height + 2) + 1;
1307
1308 8 s->mb_type_buf = av_calloc(big_mb_num, NUM_PICS * sizeof(*s->mb_type_buf));
1309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->mb_type_buf)
1310 return AVERROR(ENOMEM);
1311 8 uint32_t *mb_type_buf = s->mb_type_buf + 2 * s->mb_stride + 1;
1312
1313 8 const unsigned b4_stride = s->mb_width * 4 + 1;
1314 8 const unsigned b4_array_size = b4_stride * s->mb_height * 4;
1315 8 const unsigned motion_val_buf_size = b4_array_size + 4;
1316
1317 8 s->motion_val_buf = av_calloc(motion_val_buf_size,
1318 NUM_PICS * 2 * sizeof(*s->motion_val_buf));
1319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->motion_val_buf)
1320 return AVERROR(ENOMEM);
1321 8 int16_t (*motion_val_buf)[2] = s->motion_val_buf + 4;
1322
1323
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (size_t i = 0; i < NUM_PICS; ++i) {
1324 24 SVQ3Frame *const pic = &s->frames[i];
1325
1326 24 pic->mb_type = mb_type_buf;
1327 24 mb_type_buf += big_mb_num;
1328
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) {
1329 48 pic->motion_val[j] = motion_val_buf;
1330 48 motion_val_buf += motion_val_buf_size;
1331 }
1332 }
1333
1334 8 s->intra4x4_pred_mode = av_mallocz(s->mb_stride * 2 * 8);
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->intra4x4_pred_mode)
1336 return AVERROR(ENOMEM);
1337
1338 8 s->mb2br_xy = av_mallocz(s->mb_stride * (s->mb_height + 1) *
1339 sizeof(*s->mb2br_xy));
1340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->mb2br_xy)
1341 return AVERROR(ENOMEM);
1342
1343
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 for (y = 0; y < s->mb_height; y++)
1344
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 120 times.
2460 for (x = 0; x < s->mb_width; x++) {
1345 2340 const int mb_xy = x + y * s->mb_stride;
1346
1347 2340 s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 * s->mb_stride));
1348 }
1349
1350 8 init_dequant4_coeff_table(s);
1351
1352 8 return 0;
1353 }
1354
1355 2810 static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
1356 {
1357 2810 SVQ3Context *s = avctx->priv_data;
1358 2810 int ret = ff_get_buffer(avctx, pic->f,
1359 2810 (s->pict_type != AV_PICTURE_TYPE_B) ?
1360 AV_GET_BUFFER_FLAG_REF : 0);
1361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (ret < 0)
1362 return ret;
1363
1364
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2806 times.
2810 if (!s->edge_emu_buffer) {
1365 4 s->edge_emu_buffer = av_calloc(pic->f->linesize[0], 17);
1366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!s->edge_emu_buffer)
1367 return AVERROR(ENOMEM);
1368 }
1369
1370 2810 return 0;
1371 }
1372
1373 static av_cold int alloc_dummy_frame(AVCodecContext *avctx, SVQ3Frame *pic)
1374 {
1375 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1376 av_frame_unref(pic->f);
1377 int ret = get_buffer(avctx, pic);
1378 if (ret < 0)
1379 return ret;
1380
1381 memset(pic->f->data[0], 0, avctx->height * pic->f->linesize[0]);
1382 memset(pic->f->data[1], 0x80, (avctx->height / 2) *
1383 pic->f->linesize[1]);
1384 memset(pic->f->data[2], 0x80, (avctx->height / 2) *
1385 pic->f->linesize[2]);
1386
1387 return 0;
1388 }
1389
1390 2816 static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1391 int *got_frame, AVPacket *avpkt)
1392 {
1393 2816 SVQ3Context *s = avctx->priv_data;
1394 2816 int buf_size = avpkt->size;
1395 int left;
1396 int ret, m, i;
1397
1398 /* special case for last picture */
1399
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2810 times.
2816 if (buf_size == 0) {
1400
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) {
1401 3 av_frame_move_ref(rframe, s->next_pic->f);
1402 3 *got_frame = 1;
1403 }
1404 6 return 0;
1405 }
1406
1407 2810 s->mb_x = s->mb_y = s->mb_xy = 0;
1408
1409 2810 ret = init_get_bits8(&s->gb, avpkt->data, avpkt->size);
1410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (ret < 0)
1411 return ret;
1412
1413 2810 ret = svq3_decode_slice_header(avctx);
1414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (ret < 0)
1415 return ret;
1416
1417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (avpkt->size < s->mb_width * s->mb_height / 8)
1418 return AVERROR_INVALIDDATA;
1419
1420 2810 s->pict_type = s->slice_type;
1421
1422
2/2
✓ Branch 0 taken 2806 times.
✓ Branch 1 taken 4 times.
2810 if (s->pict_type != AV_PICTURE_TYPE_B)
1423 2806 FFSWAP(SVQ3Frame*, s->next_pic, s->last_pic);
1424
1425 2810 av_frame_unref(s->cur_pic->f);
1426
1427 /* for skipping the frame */
1428 2810 s->cur_pic->f->pict_type = s->pict_type;
1429
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 2746 times.
2810 if (s->pict_type == AV_PICTURE_TYPE_I)
1430 64 s->cur_pic->f->flags |= AV_FRAME_FLAG_KEY;
1431 else
1432 2746 s->cur_pic->f->flags &= ~AV_FRAME_FLAG_KEY;
1433
1434 2810 ret = get_buffer(avctx, s->cur_pic);
1435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (ret < 0)
1436 return ret;
1437
1438
2/2
✓ Branch 0 taken 44960 times.
✓ Branch 1 taken 2810 times.
47770 for (i = 0; i < 16; i++) {
1439 44960 s->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1440 44960 s->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1441 }
1442
2/2
✓ Branch 0 taken 44960 times.
✓ Branch 1 taken 2810 times.
47770 for (i = 0; i < 16; i++) {
1443 44960 s->block_offset[16 + i] =
1444 44960 s->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1445 44960 s->block_offset[48 + 16 + i] =
1446 44960 s->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1447 }
1448
1449
2/2
✓ Branch 0 taken 2746 times.
✓ Branch 1 taken 64 times.
2810 if (s->pict_type != AV_PICTURE_TYPE_I) {
1450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2746 times.
2746 if (!s->last_pic->f->data[0]) {
1451 ret = alloc_dummy_frame(avctx, s->last_pic);
1452 if (ret < 0)
1453 return ret;
1454 }
1455
1456
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2742 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2746 if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
1457 ret = alloc_dummy_frame(avctx, s->next_pic);
1458 if (ret < 0)
1459 return ret;
1460 }
1461 }
1462
1463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (avctx->debug & FF_DEBUG_PICT_INFO)
1464 av_log(s->avctx, AV_LOG_DEBUG,
1465 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1466 av_get_picture_type_char(s->pict_type),
1467 s->halfpel_flag, s->thirdpel_flag,
1468 s->adaptive_quant, s->qscale, s->slice_num);
1469
1470
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2810 if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
1471
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2810 avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
1472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 avctx->skip_frame >= AVDISCARD_ALL)
1473 return 0;
1474
1475
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2806 times.
2810 if (s->pict_type == AV_PICTURE_TYPE_B) {
1476 4 s->frame_num_offset = s->slice_num - s->prev_frame_num;
1477
1478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (s->frame_num_offset < 0)
1479 s->frame_num_offset += 256;
1480
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (s->frame_num_offset == 0 ||
1481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 s->frame_num_offset >= s->prev_frame_num_offset) {
1482 av_log(s->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
1483 return -1;
1484 }
1485 } else {
1486 2806 s->prev_frame_num = s->frame_num;
1487 2806 s->frame_num = s->slice_num;
1488 2806 s->prev_frame_num_offset = s->frame_num - s->prev_frame_num;
1489
1490
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2796 times.
2806 if (s->prev_frame_num_offset < 0)
1491 10 s->prev_frame_num_offset += 256;
1492 }
1493
1494
2/2
✓ Branch 0 taken 5620 times.
✓ Branch 1 taken 2810 times.
8430 for (m = 0; m < 2; m++) {
1495 int i;
1496
2/2
✓ Branch 0 taken 22480 times.
✓ Branch 1 taken 5620 times.
28100 for (i = 0; i < 4; i++) {
1497 int j;
1498
2/2
✓ Branch 0 taken 112400 times.
✓ Branch 1 taken 22480 times.
134880 for (j = -1; j < 4; j++)
1499 112400 s->ref_cache[m][scan8[0] + 8 * i + j] = 1;
1500
2/2
✓ Branch 0 taken 16860 times.
✓ Branch 1 taken 5620 times.
22480 if (i < 3)
1501 16860 s->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
1502 }
1503 }
1504
1505
2/2
✓ Branch 0 taken 42150 times.
✓ Branch 1 taken 2810 times.
44960 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
1506
2/2
✓ Branch 0 taken 842700 times.
✓ Branch 1 taken 42150 times.
884850 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
1507 unsigned mb_type;
1508 842700 s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
1509
1510
2/2
✓ Branch 1 taken 3847 times.
✓ Branch 2 taken 838853 times.
842700 if ((get_bits_left(&s->gb_slice)) <= 7) {
1511
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 ||
1512 3847 show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
1513
1514 ret = svq3_decode_slice_header(avctx);
1515 if (ret < 0)
1516 return ret;
1517 }
1518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3847 times.
3847 if (s->slice_type != s->pict_type) {
1519 avpriv_request_sample(avctx, "non constant slice type");
1520 }
1521 /* TODO: support s->mb_skip_run */
1522 }
1523
1524 842700 mb_type = get_interleaved_ue_golomb(&s->gb_slice);
1525
1526
2/2
✓ Branch 0 taken 19170 times.
✓ Branch 1 taken 823530 times.
842700 if (s->pict_type == AV_PICTURE_TYPE_I)
1527 19170 mb_type += 8;
1528
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 822450 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1058 times.
823530 else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
1529 22 mb_type += 4;
1530
2/4
✓ Branch 0 taken 842700 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 842700 times.
842700 if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
1531 av_log(s->avctx, AV_LOG_ERROR,
1532 "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
1533 return -1;
1534 }
1535
1536
4/4
✓ Branch 0 taken 353906 times.
✓ Branch 1 taken 488794 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 353846 times.
842700 if (mb_type != 0 || s->cbp)
1537 488854 hl_decode_mb(s);
1538
1539
3/4
✓ Branch 0 taken 841620 times.
✓ Branch 1 taken 1080 times.
✓ Branch 2 taken 841620 times.
✗ Branch 3 not taken.
842700 if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
1540 841620 s->cur_pic->mb_type[s->mb_x + s->mb_y * s->mb_stride] =
1541
4/4
✓ Branch 0 taken 822450 times.
✓ Branch 1 taken 19170 times.
✓ Branch 2 taken 791055 times.
✓ Branch 3 taken 31395 times.
841620 (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
1542 }
1543
1544 42150 ff_draw_horiz_band(avctx, s->cur_pic->f,
1545 42090 s->last_pic->f->data[0] ? s->last_pic->f : NULL,
1546
2/2
✓ Branch 0 taken 42090 times.
✓ Branch 1 taken 60 times.
42150 16 * s->mb_y, 16, PICT_FRAME, 0,
1547 s->low_delay);
1548 }
1549
1550 2810 left = buf_size*8 - get_bits_count(&s->gb_slice);
1551
1552
2/4
✓ Branch 0 taken 2810 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2810 times.
2810 if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
1553 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);
1554 //av_hex_dump(stderr, buf+buf_size-8, 8);
1555 }
1556
1557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (left < 0) {
1558 av_log(avctx, AV_LOG_ERROR, "frame num %"PRId64" left %d\n", avctx->frame_num, left);
1559 return -1;
1560 }
1561
1562
3/4
✓ Branch 0 taken 2806 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2806 times.
2810 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
1563 4 ret = av_frame_ref(rframe, s->cur_pic->f);
1564
2/2
✓ Branch 0 taken 2802 times.
✓ Branch 1 taken 4 times.
2806 else if (s->last_pic->f->data[0])
1565 2802 ret = av_frame_ref(rframe, s->last_pic->f);
1566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2810 times.
2810 if (ret < 0)
1567 return ret;
1568
1569 /* Do not output the last pic after seeking. */
1570
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2806 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
2810 if (s->last_pic->f->data[0] || s->low_delay)
1571 2806 *got_frame = 1;
1572
1573
2/2
✓ Branch 0 taken 2806 times.
✓ Branch 1 taken 4 times.
2810 if (s->pict_type != AV_PICTURE_TYPE_B) {
1574 2806 FFSWAP(SVQ3Frame*, s->cur_pic, s->next_pic);
1575 } else {
1576 4 av_frame_unref(s->cur_pic->f);
1577 }
1578
1579 2810 return buf_size;
1580 }
1581
1582 8 static av_cold int svq3_decode_end(AVCodecContext *avctx)
1583 {
1584 8 SVQ3Context *s = avctx->priv_data;
1585
1586
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (int i = 0; i < NUM_PICS; i++)
1587 24 av_frame_free(&s->frames[i].f);
1588 8 av_freep(&s->motion_val_buf);
1589 8 av_freep(&s->mb_type_buf);
1590 8 av_freep(&s->slice_buf);
1591 8 av_freep(&s->intra4x4_pred_mode);
1592 8 av_freep(&s->edge_emu_buffer);
1593 8 av_freep(&s->mb2br_xy);
1594
1595 8 return 0;
1596 }
1597
1598 const FFCodec ff_svq3_decoder = {
1599 .p.name = "svq3",
1600 CODEC_LONG_NAME("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
1601 .p.type = AVMEDIA_TYPE_VIDEO,
1602 .p.id = AV_CODEC_ID_SVQ3,
1603 .priv_data_size = sizeof(SVQ3Context),
1604 .init = svq3_decode_init,
1605 .close = svq3_decode_end,
1606 FF_CODEC_DECODE_CB(svq3_decode_frame),
1607 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND |
1608 AV_CODEC_CAP_DR1 |
1609 AV_CODEC_CAP_DELAY,
1610 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1611 };
1612