FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/svq3.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 680 827 82.2%
Branches: 437 563 77.6%

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