FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mss2.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 444 529 83.9%
Functions: 18 19 94.7%
Branches: 252 362 69.6%

Line Branch Exec Source
1 /*
2 * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder
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 * @file
23 * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder
24 */
25
26 #include "libavutil/avassert.h"
27 #include "libavutil/mem.h"
28 #include "codec_internal.h"
29 #include "decode.h"
30 #include "error_resilience.h"
31 #include "mpeg_er.h"
32 #include "mpegvideodec.h"
33 #include "vc1.h"
34 #include "wmv2data.h"
35 #include "mss12.h"
36 #include "mss2dsp.h"
37
38 typedef struct MSS2Context {
39 VC1Context v;
40 int split_position;
41 AVFrame *last_pic;
42 MSS12Context c;
43 MSS2DSPContext dsp;
44 SliceContext sc[2];
45 } MSS2Context;
46
47 3121304 static void arith2_normalise(ArithCoder *c)
48 {
49
2/2
✓ Branch 0 taken 39967 times.
✓ Branch 1 taken 3121304 times.
3161271 while ((c->high >> 15) - (c->low >> 15) < 2) {
50
2/2
✓ Branch 0 taken 8558 times.
✓ Branch 1 taken 31409 times.
39967 if ((c->low ^ c->high) & 0x10000) {
51 8558 c->high ^= 0x8000;
52 8558 c->value ^= 0x8000;
53 8558 c->low ^= 0x8000;
54 }
55 39967 c->high = (uint16_t)c->high << 8 | 0xFF;
56 39967 c->value = (uint16_t)c->value << 8 | bytestream2_get_byte(c->gbc.gB);
57 39967 c->low = (uint16_t)c->low << 8;
58 }
59 3121304 }
60
61
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 166 times.
256 ARITH_GET_BIT(arith2)
62
63 /* L. Stuiver and A. Moffat: "Piecewise Integer Mapping for Arithmetic Coding."
64 * In Proc. 8th Data Compression Conference (DCC '98), pp. 3-12, Mar. 1998 */
65
66 3121048 static int arith2_get_scaled_value(int value, int n, int range)
67 {
68 3121048 int split = (n << 1) - range;
69
70
2/2
✓ Branch 0 taken 1728674 times.
✓ Branch 1 taken 1392374 times.
3121048 if (value > split)
71 1728674 return split + (value - split >> 1);
72 else
73 1392374 return value;
74 }
75
76 3121048 static void arith2_rescale_interval(ArithCoder *c, int range,
77 int low, int high, int n)
78 {
79 3121048 int split = (n << 1) - range;
80
81
2/2
✓ Branch 0 taken 3047148 times.
✓ Branch 1 taken 73900 times.
3121048 if (high > split)
82 3047148 c->high = split + (high - split << 1);
83 else
84 73900 c->high = high;
85
86 3121048 c->high += c->low - 1;
87
88
2/2
✓ Branch 0 taken 29469 times.
✓ Branch 1 taken 3091579 times.
3121048 if (low > split)
89 29469 c->low += split + (low - split << 1);
90 else
91 3091579 c->low += low;
92 3121048 }
93
94 826 static int arith2_get_number(ArithCoder *c, int n)
95 {
96 826 int range = c->high - c->low + 1;
97 826 int scale = av_log2(range) - av_log2(n);
98 int val;
99
100
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 442 times.
826 if (n << scale > range)
101 384 scale--;
102
103 826 n <<= scale;
104
105 826 val = arith2_get_scaled_value(c->value - c->low, n, range) >> scale;
106
107 826 arith2_rescale_interval(c, range, val << scale, (val + 1) << scale, n);
108
109 826 arith2_normalise(c);
110
111 826 return val;
112 }
113
114 3120222 static int arith2_get_prob(ArithCoder *c, int16_t *probs)
115 {
116 3120222 int range = c->high - c->low + 1, n = *probs;
117 3120222 int scale = av_log2(range) - av_log2(n);
118 3120222 int i = 0, val;
119
120
2/2
✓ Branch 0 taken 1632960 times.
✓ Branch 1 taken 1487262 times.
3120222 if (n << scale > range)
121 1632960 scale--;
122
123 3120222 n <<= scale;
124
125 3120222 val = arith2_get_scaled_value(c->value - c->low, n, range) >> scale;
126
2/2
✓ Branch 0 taken 90884 times.
✓ Branch 1 taken 3120222 times.
3211106 while (probs[++i] > val) ;
127
128 3120222 arith2_rescale_interval(c, range,
129 3120222 probs[i] << scale, probs[i - 1] << scale, n);
130
131 3120222 return i;
132 }
133
134 3120222 ARITH_GET_MODEL_SYM(arith2)
135
136 370 static int arith2_get_consumed_bytes(ArithCoder *c)
137 {
138 370 int diff = (c->high >> 16) - (c->low >> 16);
139 370 int bp = bytestream2_tell(c->gbc.gB) - 3 << 3;
140 370 int bits = 1;
141
142
2/2
✓ Branch 0 taken 1474 times.
✓ Branch 1 taken 370 times.
1844 while (!(diff & 0x80)) {
143 1474 bits++;
144 1474 diff <<= 1;
145 }
146
147 370 return (bits + bp + 7 >> 3) + ((c->low >> 16) + 1 == c->high >> 16);
148 }
149
150 185 static void arith2_init(ArithCoder *c, GetByteContext *gB)
151 {
152 185 c->low = 0;
153 185 c->high = 0xFFFFFF;
154 185 c->value = bytestream2_get_be24(gB);
155 185 c->overread = 0;
156 185 c->gbc.gB = gB;
157 185 c->get_model_sym = arith2_get_model_sym;
158 185 c->get_number = arith2_get_number;
159 185 }
160
161 6 static int decode_pal_v2(MSS12Context *ctx, const uint8_t *buf, int buf_size)
162 {
163 int i, ncol;
164 6 uint32_t *pal = ctx->pal + 256 - ctx->free_colours;
165
166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!ctx->free_colours)
167 return 0;
168
169 6 ncol = *buf++;
170
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (ncol > ctx->free_colours || buf_size < 2 + ncol * 3)
171 return AVERROR_INVALIDDATA;
172
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 6 times.
23 for (i = 0; i < ncol; i++)
173 17 *pal++ = AV_RB24(buf + 3 * i);
174
175 6 return 1 + ncol * 3;
176 }
177
178 4 static int decode_555(AVCodecContext *avctx, GetByteContext *gB, uint16_t *dst, ptrdiff_t stride,
179 int keyframe, int w, int h)
180 {
181 4 int last_symbol = 0, repeat = 0, prev_avail = 0;
182
183
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (!keyframe) {
184 int x, y, endx, endy, t;
185
186 #define READ_PAIR(a, b) \
187 a = bytestream2_get_byte(gB) << 4; \
188 t = bytestream2_get_byte(gB); \
189 a |= t >> 4; \
190 b = (t & 0xF) << 8; \
191 b |= bytestream2_get_byte(gB); \
192
193 2 READ_PAIR(x, endx)
194 2 READ_PAIR(y, endy)
195
196
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 if (endx >= w || endy >= h || x > endx || y > endy)
197 return AVERROR_INVALIDDATA;
198 2 dst += x + stride * y;
199 2 w = endx - x + 1;
200 2 h = endy - y + 1;
201
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (y)
202 2 prev_avail = 1;
203 }
204
205 do {
206 146 uint16_t *p = dst;
207 do {
208
2/2
✓ Branch 0 taken 5320 times.
✓ Branch 1 taken 3880 times.
9200 if (repeat-- < 1) {
209 5320 int b = bytestream2_get_byte(gB);
210
2/2
✓ Branch 0 taken 2920 times.
✓ Branch 1 taken 2400 times.
5320 if (b < 128)
211 2920 last_symbol = b << 8 | bytestream2_get_byte(gB);
212
2/2
✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 960 times.
2400 else if (b > 129) {
213 1440 repeat = 0;
214
2/2
✓ Branch 0 taken 398 times.
✓ Branch 1 taken 1440 times.
1838 while (b-- > 130) {
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398 times.
398 if (repeat >= (INT_MAX >> 8) - 1) {
216 av_log(avctx, AV_LOG_ERROR, "repeat overflow\n");
217 return AVERROR_INVALIDDATA;
218 }
219 398 repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
220 }
221
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1430 times.
1440 if (last_symbol == -2) {
222 10 int skip = FFMIN((unsigned)repeat, dst + w - p);
223 10 repeat -= skip;
224 10 p += skip;
225 }
226 } else
227 960 last_symbol = 127 - b;
228 }
229
2/2
✓ Branch 0 taken 4414 times.
✓ Branch 1 taken 4786 times.
9200 if (last_symbol >= 0)
230 4414 *p = last_symbol;
231
3/4
✓ Branch 0 taken 4764 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 4764 times.
✗ Branch 3 not taken.
4786 else if (last_symbol == -1 && prev_avail)
232 4764 *p = *(p - stride);
233
2/2
✓ Branch 0 taken 9054 times.
✓ Branch 1 taken 146 times.
9200 } while (++p < dst + w);
234 146 dst += stride;
235 146 prev_avail = 1;
236
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 4 times.
146 } while (--h);
237
238 4 return 0;
239 }
240
241 6 static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, ptrdiff_t pal_stride,
242 uint8_t *rgb_dst, ptrdiff_t rgb_stride, uint32_t *pal,
243 int keyframe, int kf_slipt, int slice, int w, int h)
244 {
245 6 uint8_t bits[270] = { 0 };
246 uint32_t codes[270];
247 VLC vlc;
248
249 6 int current_length = 0, read_codes = 0, next_code = 0, current_codes = 0;
250 int remaining_codes, surplus_codes, i;
251
252 6 const int alphabet_size = 270 - keyframe;
253
254 6 int last_symbol = 0, repeat = 0, prev_avail = 0;
255
256
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (!keyframe) {
257 int x, y, clipw, cliph;
258
259 3 x = get_bits(gb, 12);
260 3 y = get_bits(gb, 12);
261 3 clipw = get_bits(gb, 12) + 1;
262 3 cliph = get_bits(gb, 12) + 1;
263
264
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (x + clipw > w || y + cliph > h)
265 return AVERROR_INVALIDDATA;
266 3 pal_dst += pal_stride * y + x;
267 3 rgb_dst += rgb_stride * y + x * 3;
268 3 w = clipw;
269 3 h = cliph;
270
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (y)
271 3 prev_avail = 1;
272 } else {
273
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (slice > 0) {
274 1 pal_dst += pal_stride * kf_slipt;
275 1 rgb_dst += rgb_stride * kf_slipt;
276 1 prev_avail = 1;
277 1 h -= kf_slipt;
278 } else
279 2 h = kf_slipt;
280 }
281
282 /* read explicit codes */
283 do {
284
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 78 times.
231 while (current_codes--) {
285 153 int symbol = get_bits(gb, 8);
286
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 101 times.
153 if (symbol >= 204 - keyframe)
287 52 symbol += 14 - keyframe;
288
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 90 times.
101 else if (symbol > 189)
289 11 symbol = get_bits1(gb) + (symbol << 1) - 190;
290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
153 if (bits[symbol])
291 return AVERROR_INVALIDDATA;
292 153 bits[symbol] = current_length;
293 153 codes[symbol] = next_code++;
294 153 read_codes++;
295 }
296 78 current_length++;
297 78 next_code <<= 1;
298 78 remaining_codes = (1 << current_length) - next_code;
299 78 current_codes = get_bits(gb, av_ceil_log2(remaining_codes + 1));
300
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
78 if (current_length > 22 || current_codes > remaining_codes)
301 return AVERROR_INVALIDDATA;
302
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 6 times.
78 } while (current_codes != remaining_codes);
303
304 6 remaining_codes = alphabet_size - read_codes;
305
306 /* determine the minimum length to fit the rest of the alphabet */
307 6 while ((surplus_codes = (2 << current_length) -
308
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 6 times.
19 (next_code << 1) - remaining_codes) < 0) {
309 13 current_length++;
310 13 next_code <<= 1;
311 }
312
313 /* add the rest of the symbols lexicographically */
314
2/2
✓ Branch 0 taken 1617 times.
✓ Branch 1 taken 6 times.
1623 for (i = 0; i < alphabet_size; i++)
315
2/2
✓ Branch 0 taken 1464 times.
✓ Branch 1 taken 153 times.
1617 if (!bits[i]) {
316
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1458 times.
1464 if (surplus_codes-- == 0) {
317 6 current_length++;
318 6 next_code <<= 1;
319 }
320 1464 bits[i] = current_length;
321 1464 codes[i] = next_code++;
322 }
323
324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (next_code != 1 << current_length)
325 return AVERROR_INVALIDDATA;
326
327
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if ((i = vlc_init(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0)) < 0)
328 return i;
329
330 /* frame decode */
331 do {
332 146 uint8_t *pp = pal_dst;
333 146 uint8_t *rp = rgb_dst;
334 do {
335
2/2
✓ Branch 0 taken 1908 times.
✓ Branch 1 taken 7240 times.
9148 if (repeat-- < 1) {
336 1908 int b = get_vlc2(gb, vlc.table, 9, 3);
337
2/2
✓ Branch 0 taken 686 times.
✓ Branch 1 taken 1222 times.
1908 if (b < 256)
338 686 last_symbol = b;
339
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 394 times.
1222 else if (b < 268) {
340 828 b -= 256;
341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 828 times.
828 if (b == 11)
342 b = get_bits(gb, 4) + 10;
343
344
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 744 times.
828 if (!b)
345 84 repeat = 0;
346 else
347 744 repeat = get_bits(gb, b);
348
349 828 repeat += (1 << b) - 1;
350
351
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 796 times.
828 if (last_symbol == -2) {
352 32 int skip = FFMIN(repeat, pal_dst + w - pp);
353 32 repeat -= skip;
354 32 pp += skip;
355 32 rp += skip * 3;
356 }
357 } else
358 394 last_symbol = 267 - b;
359 }
360
2/2
✓ Branch 0 taken 3616 times.
✓ Branch 1 taken 5532 times.
9148 if (last_symbol >= 0) {
361 3616 *pp = last_symbol;
362 3616 AV_WB24(rp, pal[last_symbol]);
363
3/4
✓ Branch 0 taken 5466 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 5466 times.
✗ Branch 3 not taken.
5532 } else if (last_symbol == -1 && prev_avail) {
364 5466 *pp = *(pp - pal_stride);
365 5466 memcpy(rp, rp - rgb_stride, 3);
366 }
367 9148 rp += 3;
368
2/2
✓ Branch 0 taken 9002 times.
✓ Branch 1 taken 146 times.
9148 } while (++pp < pal_dst + w);
369 146 pal_dst += pal_stride;
370 146 rgb_dst += rgb_stride;
371 146 prev_avail = 1;
372
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 6 times.
146 } while (--h);
373
374 6 ff_vlc_free(&vlc);
375 6 return 0;
376 }
377
378 82 static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
379 int x, int y, int w, int h, int wmv9_mask)
380 {
381 82 MSS2Context *ctx = avctx->priv_data;
382 82 MSS12Context *c = &ctx->c;
383 82 VC1Context *v = avctx->priv_data;
384 82 MpegEncContext *s = &v->s;
385 MPVWorkPicture *f;
386 int ret;
387
388 82 ff_mpeg_flush(avctx);
389
390
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
82 if ((ret = init_get_bits8(&s->gb, buf, buf_size)) < 0)
391 return ret;
392
393 82 s->loop_filter = avctx->skip_loop_filter < AVDISCARD_ALL;
394
395
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
82 if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
396 av_log(v->s.avctx, AV_LOG_ERROR, "header error\n");
397 return AVERROR_INVALIDDATA;
398 }
399
400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if (s->pict_type != AV_PICTURE_TYPE_I) {
401 av_log(v->s.avctx, AV_LOG_ERROR, "expected I-frame\n");
402 return AVERROR_INVALIDDATA;
403 }
404
405 82 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
406
407
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
82 if ((ret = ff_mpv_frame_start(s, avctx)) < 0) {
408 av_log(v->s.avctx, AV_LOG_ERROR, "ff_mpv_frame_start error\n");
409 avctx->pix_fmt = AV_PIX_FMT_RGB24;
410 return ret;
411 }
412
413 82 ff_mpeg_er_frame_start(s);
414
415 82 v->end_mb_x = (w + 15) >> 4;
416 82 s->end_mb_y = (h + 15) >> 4;
417
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 28 times.
82 if (v->respic & 1)
418 54 v->end_mb_x = v->end_mb_x + 1 >> 1;
419
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 28 times.
82 if (v->respic & 2)
420 54 s->end_mb_y = s->end_mb_y + 1 >> 1;
421
422 82 ff_vc1_decode_blocks(v);
423
424
3/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
82 if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
425 28 ff_er_frame_end(&s->er, NULL);
426 } else {
427 54 av_log(v->s.avctx, AV_LOG_WARNING,
428 "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
429 v->end_mb_x, s->end_mb_y, s->mb_width, s->mb_height);
430 }
431
432 82 ff_mpv_frame_end(s);
433
434 82 f = &s->cur_pic;
435
436
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 28 times.
82 if (v->respic == 3) {
437 54 ctx->dsp.upsample_plane(f->data[0], f->linesize[0], w, h);
438 54 ctx->dsp.upsample_plane(f->data[1], f->linesize[1], w+1 >> 1, h+1 >> 1);
439 54 ctx->dsp.upsample_plane(f->data[2], f->linesize[2], w+1 >> 1, h+1 >> 1);
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 } else if (v->respic)
441 avpriv_request_sample(v->s.avctx,
442 "Asymmetric WMV9 rectangle subsampling");
443
444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 av_assert0(f->linesize[1] == f->linesize[2]);
445
446
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 2 times.
82 if (wmv9_mask != -1)
447 80 ctx->dsp.mss2_blit_wmv9_masked(c->rgb_pic + y * c->rgb_stride + x * 3,
448 c->rgb_stride, wmv9_mask,
449 80 c->pal_pic + y * c->pal_stride + x,
450 c->pal_stride,
451 80 f->data[0], f->linesize[0],
452 80 f->data[1], f->data[2], f->linesize[1],
453 w, h);
454 else
455 2 ctx->dsp.mss2_blit_wmv9(c->rgb_pic + y * c->rgb_stride + x * 3,
456 c->rgb_stride,
457 2 f->data[0], f->linesize[0],
458 2 f->data[1], f->data[2], f->linesize[1],
459 w, h);
460
461 82 avctx->pix_fmt = AV_PIX_FMT_RGB24;
462
463 82 return 0;
464 }
465
466 struct Rectangle {
467 int coded, x, y, w, h;
468 };
469
470 struct Rectangle2 {
471 int left, right, top, bottom;
472 };
473
474 2 static void calc_draw_region(struct Rectangle2 * draw, const struct Rectangle2 * rect)
475 {
476 #define COMPARE(top, bottom, left, right) \
477 if (rect->top <= draw->top && rect->bottom >= draw->bottom) { \
478 if (rect->left <= draw->left && rect->right >= draw->left) \
479 draw->left = FFMIN(rect->right, draw->right); \
480 \
481 if (rect->right >= draw->right) { \
482 if (rect->left >= draw->left) { \
483 if (rect->left < draw->right) \
484 draw->right = rect->left; \
485 } else { \
486 draw->right = draw->left; \
487 } \
488 } \
489 }
490
491
2/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
2 COMPARE(top, bottom, left, right)
492
5/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
2 COMPARE(left, right, top, bottom)
493 2 }
494
495 static int calc_split_position(int split_position, const struct Rectangle2 * rect, int height)
496 {
497 if (rect->top || rect->bottom != height)
498 split_position = rect->top + split_position * (rect->bottom - rect->top) / height;
499
500 return av_clip(split_position, rect->top + 1, rect->bottom - 1);
501 }
502
503 #define MAX_WMV9_RECTANGLES 20
504 #define ARITH2_PADDING 2
505
506 111 static int mss2_decode_frame(AVCodecContext *avctx, AVFrame *frame,
507 int *got_frame, AVPacket *avpkt)
508 {
509 111 const uint8_t *buf = avpkt->data;
510 111 int buf_size = avpkt->size;
511 111 MSS2Context *ctx = avctx->priv_data;
512 111 MSS12Context *c = &ctx->c;
513 GetBitContext gb;
514 GetByteContext gB;
515 ArithCoder acoder;
516
517 int keyframe, has_wmv9, has_mv, is_rle, is_555, ret;
518
519 struct Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
520 struct Rectangle2 draw;
521 111 int used_rects = 0, i, implicit_rect = 0, wmv9_mask = -1;
522
523
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
111 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
524 return ret;
525
526
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 103 times.
111 if (keyframe = get_bits1(&gb))
527 8 skip_bits(&gb, 7);
528 111 has_wmv9 = get_bits1(&gb);
529
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 8 times.
111 has_mv = keyframe ? 0 : get_bits1(&gb);
530 111 is_rle = get_bits1(&gb);
531
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 103 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
111 is_555 = is_rle && get_bits1(&gb);
532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (c->slice_split > 0)
533 ctx->split_position = c->slice_split;
534
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 105 times.
111 else if (c->slice_split < 0) {
535
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
6 if (get_bits1(&gb)) {
536
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 if (get_bits1(&gb)) {
537
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits1(&gb))
538 ctx->split_position = get_bits(&gb, 16);
539 else
540 1 ctx->split_position = get_bits(&gb, 12);
541 } else
542 1 ctx->split_position = get_bits(&gb, 8) << 4;
543 } else {
544
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (keyframe)
545 3 ctx->split_position = avctx->height / 2;
546 }
547 } else
548 105 ctx->split_position = avctx->height;
549
550
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
111 if (c->slice_split && (ctx->split_position < 1 - is_555 ||
551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 ctx->split_position > avctx->height - 1))
552 return AVERROR_INVALIDDATA;
553
554 111 align_get_bits(&gb);
555 111 buf += get_bits_count(&gb) >> 3;
556 111 buf_size -= get_bits_count(&gb) >> 3;
557
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (buf_size < 1)
559 return AVERROR_INVALIDDATA;
560
561
7/10
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 107 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
111 if (is_555 && (has_wmv9 || has_mv || c->slice_split && ctx->split_position))
562 return AVERROR_INVALIDDATA;
563
564
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 107 times.
111 avctx->pix_fmt = is_555 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24;
565
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 105 times.
111 if (ctx->last_pic->format != avctx->pix_fmt)
566 6 av_frame_unref(ctx->last_pic);
567
568
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 29 times.
111 if (has_wmv9) {
569 82 bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
570 82 arith2_init(&acoder, &gB);
571
572 82 implicit_rect = !arith2_get_bit(&acoder);
573
574
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 82 times.
87 while (arith2_get_bit(&acoder)) {
575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (used_rects == MAX_WMV9_RECTANGLES)
576 return AVERROR_INVALIDDATA;
577 5 r = &wmv9rects[used_rects];
578
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (!used_rects)
579 5 r->x = arith2_get_number(&acoder, avctx->width);
580 else
581 r->x = arith2_get_number(&acoder, avctx->width -
582 wmv9rects[used_rects - 1].x) +
583 wmv9rects[used_rects - 1].x;
584 5 r->y = arith2_get_number(&acoder, avctx->height);
585 5 r->w = arith2_get_number(&acoder, avctx->width - r->x) + 1;
586 5 r->h = arith2_get_number(&acoder, avctx->height - r->y) + 1;
587 5 used_rects++;
588 }
589
590
3/4
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 77 times.
82 if (implicit_rect && used_rects) {
591 av_log(avctx, AV_LOG_ERROR, "implicit_rect && used_rects > 0\n");
592 return AVERROR_INVALIDDATA;
593 }
594
595
2/2
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 5 times.
82 if (implicit_rect) {
596 77 wmv9rects[0].x = 0;
597 77 wmv9rects[0].y = 0;
598 77 wmv9rects[0].w = avctx->width;
599 77 wmv9rects[0].h = avctx->height;
600
601 77 used_rects = 1;
602 }
603
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 82 times.
164 for (i = 0; i < used_rects; i++) {
604
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 77 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
82 if (!implicit_rect && arith2_get_bit(&acoder)) {
605 av_log(avctx, AV_LOG_ERROR, "Unexpected grandchildren\n");
606 return AVERROR_INVALIDDATA;
607 }
608
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if (!i) {
609 82 wmv9_mask = arith2_get_bit(&acoder) - 1;
610
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 2 times.
82 if (!wmv9_mask)
611 80 wmv9_mask = arith2_get_number(&acoder, 256);
612 }
613 82 wmv9rects[i].coded = arith2_get_number(&acoder, 2);
614 }
615
616 82 buf += arith2_get_consumed_bytes(&acoder);
617 82 buf_size -= arith2_get_consumed_bytes(&acoder);
618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if (buf_size < 1)
619 return AVERROR_INVALIDDATA;
620 }
621
622 111 c->mvX = c->mvY = 0;
623
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 103 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2 times.
111 if (keyframe && !is_555) {
624
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if ((i = decode_pal_v2(c, buf, buf_size)) < 0)
625 return AVERROR_INVALIDDATA;
626 6 buf += i;
627 6 buf_size -= i;
628
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 26 times.
105 } else if (has_mv) {
629 79 buf += 4;
630 79 buf_size -= 4;
631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (buf_size < 1)
632 return AVERROR_INVALIDDATA;
633 79 c->mvX = AV_RB16(buf - 4) - avctx->width;
634 79 c->mvY = AV_RB16(buf - 2) - avctx->height;
635 }
636
637
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 69 times.
111 if (c->mvX < 0 || c->mvY < 0) {
638 42 FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic);
639
640
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
42 if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
641 return ret;
642
643
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (ctx->last_pic->data[0]) {
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]);
645 42 c->last_rgb_pic = ctx->last_pic->data[0] +
646 42 ctx->last_pic->linesize[0] * (avctx->height - 1);
647 } else {
648 av_log(avctx, AV_LOG_ERROR, "Missing keyframe\n");
649 return AVERROR_INVALIDDATA;
650 }
651 } else {
652
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
69 if ((ret = ff_reget_buffer(avctx, ctx->last_pic, 0)) < 0)
653 return ret;
654
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
69 if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0)
655 return ret;
656
657 69 c->last_rgb_pic = NULL;
658 }
659 111 c->rgb_pic = frame->data[0] +
660 111 frame->linesize[0] * (avctx->height - 1);
661 111 c->rgb_stride = -frame->linesize[0];
662
663
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 103 times.
111 if (keyframe)
664 8 frame->flags |= AV_FRAME_FLAG_KEY;
665 else
666 103 frame->flags &= ~AV_FRAME_FLAG_KEY;
667
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 103 times.
111 frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
668
669
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 107 times.
111 if (is_555) {
670 4 bytestream2_init(&gB, buf, buf_size);
671
672
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (decode_555(avctx, &gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1,
673 keyframe, avctx->width, avctx->height))
674 return AVERROR_INVALIDDATA;
675
676 4 buf_size -= bytestream2_tell(&gB);
677 } else {
678
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 101 times.
107 if (keyframe) {
679 6 c->corrupted = 0;
680 6 ff_mss12_slicecontext_reset(&ctx->sc[0]);
681
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (c->slice_split)
682 3 ff_mss12_slicecontext_reset(&ctx->sc[1]);
683 }
684
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 103 times.
107 if (is_rle) {
685
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
686 return ret;
687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,
688 4 c->rgb_pic, c->rgb_stride, c->pal, keyframe,
689 ctx->split_position, 0,
690 avctx->width, avctx->height))
691 return ret;
692 4 align_get_bits(&gb);
693
694
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (c->slice_split)
695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,
696 2 c->rgb_pic, c->rgb_stride, c->pal, keyframe,
697 ctx->split_position, 1,
698 avctx->width, avctx->height))
699 return ret;
700
701 4 align_get_bits(&gb);
702 4 buf += get_bits_count(&gb) >> 3;
703 4 buf_size -= get_bits_count(&gb) >> 3;
704
3/4
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 77 times.
✗ Branch 3 not taken.
103 } else if (!implicit_rect || wmv9_mask != -1) {
705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (c->corrupted)
706 return AVERROR_INVALIDDATA;
707 103 bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
708 103 arith2_init(&acoder, &gB);
709 103 c->keyframe = keyframe;
710
711 103 draw.left = 0;
712 103 draw.top = 0;
713 103 draw.right = avctx->width;
714 103 draw.bottom = avctx->height;
715
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 80 times.
103 if (wmv9_mask == -1) {
716
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
25 for (i = 0; i < used_rects; i++) {
717 struct Rectangle2 r;
718 2 r.left = wmv9rects[i].x;
719 2 r.top = wmv9rects[i].y;
720 2 r.right = r.left + wmv9rects[i].w;
721 2 r.bottom = r.top + wmv9rects[i].h;
722 2 calc_draw_region(&draw, &r);
723 }
724 }
725
726
2/4
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103 times.
✗ Branch 3 not taken.
103 if (draw.left >= avctx->width || draw.right > avctx->width ||
727
2/4
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 103 times.
103 draw.top >= avctx->height || draw.bottom > avctx->height)
728 return AVERROR_INVALIDDATA;
729
730
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 101 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
103 if (c->slice_split && draw.bottom - draw.top >= 10) {
731 ctx->split_position = calc_split_position(ctx->split_position, &draw, avctx->height);
732 if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, draw.top,
733 avctx->width,
734 ctx->split_position - draw.top))
735 return AVERROR_INVALIDDATA;
736 buf += arith2_get_consumed_bytes(&acoder);
737 buf_size -= arith2_get_consumed_bytes(&acoder);
738 if (c->slice_split) {
739 if (buf_size < 1)
740 return AVERROR_INVALIDDATA;
741 bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
742 arith2_init(&acoder, &gB);
743 if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,
744 ctx->split_position,
745 avctx->width,
746 draw.bottom - ctx->split_position))
747 return AVERROR_INVALIDDATA;
748 buf += arith2_get_consumed_bytes(&acoder);
749 buf_size -= arith2_get_consumed_bytes(&acoder);
750 }
751 } else {
752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, draw.left, draw.top,
753 103 draw.right - draw.left, draw.bottom - draw.top))
754 return AVERROR_INVALIDDATA;
755
756 103 buf += arith2_get_consumed_bytes(&acoder);
757 103 buf_size -= arith2_get_consumed_bytes(&acoder);
758 }
759 } else
760 memset(c->pal_pic, 0, c->pal_stride * avctx->height);
761 }
762
763
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 29 times.
111 if (has_wmv9) {
764
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 82 times.
164 for (i = 0; i < used_rects; i++) {
765 82 int x = wmv9rects[i].x;
766 82 int y = wmv9rects[i].y;
767 82 int w = wmv9rects[i].w;
768 82 int h = wmv9rects[i].h;
769
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if (wmv9rects[i].coded) {
770 int WMV9codedFrameSize;
771
2/4
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 82 times.
82 if (buf_size < 4 || !(WMV9codedFrameSize = AV_RL24(buf)))
772 return AVERROR_INVALIDDATA;
773
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
82 if (ret = decode_wmv9(avctx, buf + 3, buf_size - 3,
774 x, y, w, h, wmv9_mask))
775 return ret;
776 82 buf += WMV9codedFrameSize + 3;
777 82 buf_size -= WMV9codedFrameSize + 3;
778 } else {
779 uint8_t *dst = c->rgb_pic + y * c->rgb_stride + x * 3;
780 if (wmv9_mask != -1) {
781 ctx->dsp.mss2_gray_fill_masked(dst, c->rgb_stride,
782 wmv9_mask,
783 c->pal_pic + y * c->pal_stride + x,
784 c->pal_stride,
785 w, h);
786 } else {
787 do {
788 memset(dst, 0x80, w * 3);
789 dst += c->rgb_stride;
790 } while (--h);
791 }
792 }
793 }
794 }
795
796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (buf_size)
797 av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\n");
798
799
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 69 times.
111 if (c->mvX < 0 || c->mvY < 0) {
800 42 ret = av_frame_replace(ctx->last_pic, frame);
801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (ret < 0)
802 return ret;
803 }
804
805 111 *got_frame = 1;
806
807 111 return avpkt->size;
808 }
809
810 12 static av_cold int wmv9_init(AVCodecContext *avctx)
811 {
812 12 VC1Context *v = avctx->priv_data;
813 int ret;
814
815 12 v->s.avctx = avctx;
816
817 12 ff_vc1_init_common(v);
818
819 12 v->profile = PROFILE_MAIN;
820
821 12 v->zz_8x4 = ff_wmv2_scantableA;
822 12 v->zz_4x8 = ff_wmv2_scantableB;
823 12 v->res_y411 = 0;
824 12 v->res_sprite = 0;
825
826 12 v->frmrtq_postproc = 7;
827 12 v->bitrtq_postproc = 31;
828
829 12 v->res_x8 = 0;
830 12 v->multires = 0;
831 12 v->res_fasttx = 1;
832
833 12 v->fastuvmc = 0;
834
835 12 v->extended_mv = 0;
836
837 12 v->dquant = 1;
838 12 v->vstransform = 1;
839
840 12 v->res_transtab = 0;
841
842 12 v->overlap = 0;
843
844 12 v->resync_marker = 0;
845 12 v->rangered = 0;
846
847 12 v->s.max_b_frames = avctx->max_b_frames = 0;
848 12 v->quantizer_mode = 0;
849
850 12 v->finterpflag = 0;
851
852 12 v->res_rtm_flag = 1;
853
854 12 ff_vc1_init_transposed_scantables(v);
855
856 12 ret = ff_vc1_decode_init(avctx);
857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (ret < 0)
858 return ret;
859
860 12 return 0;
861 }
862
863 12 static av_cold int mss2_decode_end(AVCodecContext *avctx)
864 {
865 12 MSS2Context *const ctx = avctx->priv_data;
866
867 12 av_frame_free(&ctx->last_pic);
868
869 12 ff_mss12_decode_end(&ctx->c);
870 12 av_freep(&ctx->c.pal_pic);
871 12 av_freep(&ctx->c.last_pal_pic);
872 12 ff_vc1_decode_end(avctx);
873
874 12 return 0;
875 }
876
877 12 static av_cold int mss2_decode_init(AVCodecContext *avctx)
878 {
879 12 MSS2Context * const ctx = avctx->priv_data;
880 12 MSS12Context *c = &ctx->c;
881 int ret;
882 12 c->avctx = avctx;
883
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (ret = ff_mss12_decode_init(c, 1, &ctx->sc[0], &ctx->sc[1]))
884 return ret;
885 12 ctx->last_pic = av_frame_alloc();
886 12 c->pal_stride = c->mask_stride;
887 12 c->pal_pic = av_mallocz(c->pal_stride * avctx->height);
888 12 c->last_pal_pic = av_mallocz(c->pal_stride * avctx->height);
889
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
12 if (!c->pal_pic || !c->last_pal_pic || !ctx->last_pic)
890 return AVERROR(ENOMEM);
891
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (ret = wmv9_init(avctx))
892 return ret;
893 12 ff_mss2dsp_init(&ctx->dsp);
894
895 24 avctx->pix_fmt = c->free_colours == 127 ? AV_PIX_FMT_RGB555
896
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 : AV_PIX_FMT_RGB24;
897
898
899 12 return 0;
900 }
901
902 const FFCodec ff_mss2_decoder = {
903 .p.name = "mss2",
904 CODEC_LONG_NAME("MS Windows Media Video V9 Screen"),
905 .p.type = AVMEDIA_TYPE_VIDEO,
906 .p.id = AV_CODEC_ID_MSS2,
907 .priv_data_size = sizeof(MSS2Context),
908 .init = mss2_decode_init,
909 .close = mss2_decode_end,
910 FF_CODEC_DECODE_CB(mss2_decode_frame),
911 .p.capabilities = AV_CODEC_CAP_DR1,
912 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
913 };
914