FFmpeg
Loading...
Searching...
No Matches
mv30.c
Go to the documentation of this file.
1/*
2 * MidiVid MV30 decoder
3 *
4 * Copyright (c) 2020 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <stddef.h>
24#include <string.h>
25
27#include "libavutil/mem.h"
28#include "libavutil/thread.h"
29
30#include "avcodec.h"
31#include "bytestream.h"
32#include "codec_internal.h"
33#include "copy_block.h"
34#include "decode.h"
35#include "mathops.h"
36#include "blockdsp.h"
37#include "get_bits.h"
38#include "aandcttab.h"
39
40#define CBP_VLC_BITS 9
41
42typedef struct MV30Context {
44
50
51 int block[6][64];
52 int16_t *mvectors;
53 unsigned int mvectors_size;
54 int16_t *coeffs;
55 unsigned int coeffs_size;
56
57 int16_t intraq_tab[2][64];
58 int16_t interq_tab[2][64];
59
63
65
66static const uint8_t luma_tab[] = {
67 12, 12, 15, 19, 25, 34, 40, 48,
68 12, 12, 18, 22, 27, 44, 47, 46,
69 17, 18, 21, 26, 35, 46, 52, 47,
70 18, 20, 24, 28, 40, 61, 59, 51,
71 20, 24, 32, 43, 50, 72, 72, 63,
72 25, 31, 42, 48, 58, 72, 81, 75,
73 38, 46, 54, 61, 71, 84, 88, 85,
74 50, 61, 65, 68, 79, 78, 86, 91,
75};
76
77static const uint8_t chroma_tab[] = {
78 12, 16, 24, 47, 99, 99, 99, 99,
79 16, 21, 26, 66, 99, 99, 99, 99,
80 24, 26, 56, 99, 99, 99, 99, 99,
81 47, 66, 99, 99, 99, 99, 99, 99,
82 99, 99, 99, 99, 99, 99, 99, 99,
83 99, 99, 99, 99, 99, 99, 99, 99,
84 99, 99, 99, 99, 99, 99, 99, 99,
85 99, 99, 99, 99, 99, 99, 99, 99,
86};
87
88static const uint8_t zigzag[] = {
89 0, 1, 8, 9, 16, 2, 3, 10,
90 17, 24, 32, 25, 18, 11, 4, 5,
91 12, 19, 26, 33, 40, 48, 41, 34,
92 27, 20, 13, 6, 7, 14, 21, 28,
93 35, 42, 49, 56, 57, 50, 43, 36,
94 29, 22, 15, 23, 30, 37, 44, 51,
95 58, 59, 52, 45, 38, 31, 39, 46,
96 53, 60, 61, 54, 47, 55, 62, 63,
97};
98
99static void get_qtable(int16_t *table, int quant, const uint8_t *quant_tab)
100{
101 int factor = quant < 50 ? 5000 / FFMAX(quant, 1) : 200 - FFMIN(quant, 100) * 2;
102
103 for (int i = 0; i < 64; i++) {
104 table[i] = av_clip((quant_tab[i] * factor + 0x32) / 100, 1, 0x7fff);
105 table[i] = ((int)ff_aanscales[i] * (int)table[i] + 0x800) >> 12;
106 }
107}
108
109static inline void idct_1d(unsigned *blk, int step)
110{
111 const unsigned t0 = blk[0 * step] + blk[4 * step];
112 const unsigned t1 = blk[0 * step] - blk[4 * step];
113 const unsigned t2 = blk[2 * step] + blk[6 * step];
114 const unsigned t3 = ((int)((blk[2 * step] - blk[6 * step]) * 362U) >> 8) - t2;
115 const unsigned t4 = t0 + t2;
116 const unsigned t5 = t0 - t2;
117 const unsigned t6 = t1 + t3;
118 const unsigned t7 = t1 - t3;
119 const unsigned t8 = blk[5 * step] + blk[3 * step];
120 const unsigned t9 = blk[5 * step] - blk[3 * step];
121 const unsigned tA = blk[1 * step] + blk[7 * step];
122 const unsigned tB = blk[1 * step] - blk[7 * step];
123 const unsigned tC = t8 + tA;
124 const unsigned tD = (int)((tB + t9) * 473U) >> 8;
125 const unsigned tE = (((int)(t9 * -669U) >> 8) - tC) + tD;
126 const unsigned tF = ((int)((tA - t8) * 362U) >> 8) - tE;
127 const unsigned t10 = (((int)(tB * 277U) >> 8) - tD) + tF;
128
129 blk[0 * step] = t4 + tC;
130 blk[1 * step] = t6 + tE;
131 blk[2 * step] = t7 + tF;
132 blk[3 * step] = t5 - t10;
133 blk[4 * step] = t5 + t10;
134 blk[5 * step] = t7 - tF;
135 blk[6 * step] = t6 - tE;
136 blk[7 * step] = t4 - tC;
137}
138
139static void idct_put(uint8_t *dst, int stride, int *block)
140{
141 for (int i = 0; i < 8; i++) {
142 if ((block[0x08 + i] |
143 block[0x10 + i] |
144 block[0x18 + i] |
145 block[0x20 + i] |
146 block[0x28 + i] |
147 block[0x30 + i] |
148 block[0x38 + i]) == 0) {
149 block[0x08 + i] = block[i];
150 block[0x10 + i] = block[i];
151 block[0x18 + i] = block[i];
152 block[0x20 + i] = block[i];
153 block[0x28 + i] = block[i];
154 block[0x30 + i] = block[i];
155 block[0x38 + i] = block[i];
156 } else {
157 idct_1d(block + i, 8);
158 }
159 }
160
161 for (int i = 0; i < 8; i++) {
162 idct_1d(block, 1);
163 for (int j = 0; j < 8; j++)
164 dst[j] = av_clip_uint8((block[j] >> 5) + 128);
165 block += 8;
166 dst += stride;
167 }
168}
169
170static void idct_add(uint8_t *dst, int stride,
171 const uint8_t *src, int in_linesize, int *block)
172{
173 for (int i = 0; i < 8; i++) {
174 if ((block[0x08 + i] |
175 block[0x10 + i] |
176 block[0x18 + i] |
177 block[0x20 + i] |
178 block[0x28 + i] |
179 block[0x30 + i] |
180 block[0x38 + i]) == 0) {
181 block[0x08 + i] = block[i];
182 block[0x10 + i] = block[i];
183 block[0x18 + i] = block[i];
184 block[0x20 + i] = block[i];
185 block[0x28 + i] = block[i];
186 block[0x30 + i] = block[i];
187 block[0x38 + i] = block[i];
188 } else {
189 idct_1d(block + i, 8);
190 }
191 }
192
193 for (int i = 0; i < 8; i++) {
194 idct_1d(block, 1);
195 for (int j = 0; j < 8; j++)
196 dst[j] = av_clip_uint8((block[j] >> 5) + src[j]);
197 block += 8;
198 dst += stride;
199 src += in_linesize;
200 }
201}
202
203static inline void idct2_1d(int *blk, int step)
204{
205 const unsigned int t0 = blk[0 * step];
206 const unsigned int t1 = blk[1 * step];
207 const unsigned int t2 = (int)(t1 * 473U) >> 8;
208 const unsigned int t3 = t2 - t1;
209 const unsigned int t4 = ((int)(t1 * 362U) >> 8) - t3;
210 const unsigned int t5 = (((int)(t1 * 277U) >> 8) - t2) + t4;
211
212 blk[0 * step] = t1 + t0;
213 blk[1 * step] = t0 + t3;
214 blk[2 * step] = t4 + t0;
215 blk[3 * step] = t0 - t5;
216 blk[4 * step] = t5 + t0;
217 blk[5 * step] = t0 - t4;
218 blk[6 * step] = t0 - t3;
219 blk[7 * step] = t0 - t1;
220}
221
222static void idct2_put(uint8_t *dst, int stride, int *block)
223{
224 for (int i = 0; i < 2; i++) {
225 if ((block[0x08 + i]) == 0) {
226 block[0x08 + i] = block[i];
227 block[0x10 + i] = block[i];
228 block[0x18 + i] = block[i];
229 block[0x20 + i] = block[i];
230 block[0x28 + i] = block[i];
231 block[0x30 + i] = block[i];
232 block[0x38 + i] = block[i];
233 } else {
234 idct2_1d(block + i, 8);
235 }
236 }
237
238 for (int i = 0; i < 8; i++) {
239 if (block[1] == 0) {
240 for (int j = 0; j < 8; j++)
241 dst[j] = av_clip_uint8((block[0] >> 5) + 128);
242 } else {
243 idct2_1d(block, 1);
244 for (int j = 0; j < 8; j++)
245 dst[j] = av_clip_uint8((block[j] >> 5) + 128);
246 }
247 block += 8;
248 dst += stride;
249 }
250}
251
252static void idct2_add(uint8_t *dst, int stride,
253 const uint8_t *src, int in_linesize,
254 int *block)
255{
256 for (int i = 0; i < 2; i++) {
257 if ((block[0x08 + i]) == 0) {
258 block[0x08 + i] = block[i];
259 block[0x10 + i] = block[i];
260 block[0x18 + i] = block[i];
261 block[0x20 + i] = block[i];
262 block[0x28 + i] = block[i];
263 block[0x30 + i] = block[i];
264 block[0x38 + i] = block[i];
265 } else {
266 idct2_1d(block + i, 8);
267 }
268 }
269
270 for (int i = 0; i < 8; i++) {
271 if (block[1] == 0) {
272 for (int j = 0; j < 8; j++)
273 dst[j] = av_clip_uint8((block[0] >> 5) + src[j]);
274 } else {
275 idct2_1d(block, 1);
276 for (int j = 0; j < 8; j++)
277 dst[j] = av_clip_uint8((block[j] >> 5) + src[j]);
278 }
279 block += 8;
280 dst += stride;
281 src += in_linesize;
282 }
283}
284
285static void update_inter_block(uint8_t *dst, int stride,
286 const uint8_t *src, int in_linesize,
287 int block)
288{
289 for (int i = 0; i < 8; i++) {
290 for (int j = 0; j < 8; j++)
291 dst[j] = av_clip_uint8(block + src[j]);
292 dst += stride;
293 src += in_linesize;
294 }
295}
296
298 GetByteContext *gbyte, int16_t *qtab,
299 int *block, int *pfill,
300 uint8_t *dst, int linesize)
301{
302 MV30Context *s = avctx->priv_data;
303 int fill;
304
305 switch (mode) {
306 case 0:
307 s->bdsp.fill_block_tab[1](dst, 128, linesize, 8);
308 break;
309 case 1:
310 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
311 pfill[0] += fill;
312 block[0] = ((int)((unsigned)pfill[0] * qtab[0]) >> 5) + 128;
313 s->bdsp.fill_block_tab[1](dst, block[0], linesize, 8);
314 break;
315 case 2:
316 memset(block, 0, sizeof(*block) * 64);
317 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
318 pfill[0] += fill;
319 block[0] = (unsigned)pfill[0] * qtab[0];
320 block[1] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[1];
321 block[8] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[8];
322 block[9] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[9];
323 idct2_put(dst, linesize, block);
324 break;
325 case 3:
326 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
327 pfill[0] += fill;
328 block[0] = (unsigned)pfill[0] * qtab[0];
329 for (int i = 1; i < 64; i++)
330 block[zigzag[i]] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[zigzag[i]];
331 idct_put(dst, linesize, block);
332 break;
333 }
334
335 return 0;
336}
337
339 GetByteContext *gbyte, int16_t *qtab,
340 int *block, int *pfill,
341 uint8_t *dst, int linesize,
342 const uint8_t *src, int in_linesize)
343{
344 int fill;
345
346 switch (mode) {
347 case 0:
348 copy_block8(dst, src, linesize, in_linesize, 8);
349 break;
350 case 1:
351 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
352 pfill[0] += fill;
353 block[0] = (int)((unsigned)pfill[0] * qtab[0]) >> 5;
354 update_inter_block(dst, linesize, src, in_linesize, block[0]);
355 break;
356 case 2:
357 memset(block, 0, sizeof(*block) * 64);
358 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
359 pfill[0] += fill;
360 block[0] = (unsigned)pfill[0] * qtab[0];
361 block[1] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[1];
362 block[8] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[8];
363 block[9] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[9];
364 idct2_add(dst, linesize, src, in_linesize, block);
365 break;
366 case 3:
367 fill = sign_extend(bytestream2_get_ne16(gbyte), 16);
368 pfill[0] += fill;
369 block[0] = (unsigned)pfill[0] * qtab[0];
370 for (int i = 1; i < 64; i++)
371 block[zigzag[i]] = sign_extend(bytestream2_get_ne16(gbyte), 16) * qtab[zigzag[i]];
372 idct_add(dst, linesize, src, in_linesize, block);
373 break;
374 }
375
376 return 0;
377}
378
379static int decode_coeffs(GetBitContext *gb, int16_t *coeffs, int nb_codes)
380{
381 memset(coeffs, 0, nb_codes * sizeof(*coeffs));
382
383 for (int i = 0; i < nb_codes;) {
384 int value = get_vlc2(gb, cbp_tab, CBP_VLC_BITS, 1);
385
386 if (value > 0) {
387 int x = get_bits(gb, value);
388
389 if (x < (1 << value) / 2) {
390 x = (1 << (value - 1)) + (x & ((1 << value) - 1 >> 1));
391 } else {
392 x = -(1 << (value - 1)) - (x & ((1 << value) - 1 >> 1));
393 }
394 coeffs[i++] = x;
395 } else {
396 int flag = get_bits1(gb);
397
398 i += get_bits(gb, 3 + flag * 3) + 1 + flag * 8;
399 }
400 }
401
402 return 0;
403}
404
406{
407 MV30Context *s = avctx->priv_data;
408 GetBitContext mgb;
409 uint8_t *dst[6];
410 int linesize[6];
411 int ret;
412
413 mgb = *gb;
414 if (get_bits_left(gb) < s->mode_size * 8)
415 return AVERROR_INVALIDDATA;
416
417 skip_bits_long(gb, s->mode_size * 8);
418
419 linesize[0] = frame->linesize[0];
420 linesize[1] = frame->linesize[0];
421 linesize[2] = frame->linesize[0];
422 linesize[3] = frame->linesize[0];
423 linesize[4] = frame->linesize[1];
424 linesize[5] = frame->linesize[2];
425
426 for (int y = 0; y < avctx->height; y += 16) {
427 GetByteContext gbyte;
428 int pfill[3][1] = { {0} };
429 int nb_codes = get_bits(gb, 16);
430
431 av_fast_padded_malloc(&s->coeffs, &s->coeffs_size, nb_codes * sizeof(*s->coeffs));
432 if (!s->coeffs)
433 return AVERROR(ENOMEM);
434 ret = decode_coeffs(gb, s->coeffs, nb_codes);
435 if (ret < 0)
436 return ret;
437
438 bytestream2_init(&gbyte, (uint8_t *)s->coeffs, nb_codes * sizeof(*s->coeffs));
439
440 for (int x = 0; x < avctx->width; x += 16) {
441 dst[0] = frame->data[0] + linesize[0] * y + x;
442 dst[1] = frame->data[0] + linesize[0] * y + x + 8;
443 dst[2] = frame->data[0] + linesize[0] * (y + 8) + x;
444 dst[3] = frame->data[0] + linesize[0] * (y + 8) + x + 8;
445 dst[4] = frame->data[1] + linesize[4] * (y >> 1) + (x >> 1);
446 dst[5] = frame->data[2] + linesize[5] * (y >> 1) + (x >> 1);
447
448 for (int b = 0; b < 6; b++) {
449 int mode = get_bits_le(&mgb, 2);
450
451 ret = decode_intra_block(avctx, mode, &gbyte, s->intraq_tab[b >= 4],
452 s->block[b],
453 pfill[(b >= 4) + (b >= 5)],
454 dst[b], linesize[b]);
455 if (ret < 0)
456 return ret;
457 }
458 }
459 }
460
461 return 0;
462}
463
465 AVFrame *frame, AVFrame *prev)
466{
467 MV30Context *s = avctx->priv_data;
469 GetBitContext mgb;
471 const int mask_size = ((avctx->height >> 4) * (avctx->width >> 4) * 2 + 7) / 8;
472 uint8_t *dst[6], *src[6];
473 int in_linesize[6];
474 int linesize[6];
475 int ret, cnt = 0;
476 int flags = 0;
477
478 in_linesize[0] = prev->linesize[0];
479 in_linesize[1] = prev->linesize[0];
480 in_linesize[2] = prev->linesize[0];
481 in_linesize[3] = prev->linesize[0];
482 in_linesize[4] = prev->linesize[1];
483 in_linesize[5] = prev->linesize[2];
484
485 linesize[0] = frame->linesize[0];
486 linesize[1] = frame->linesize[0];
487 linesize[2] = frame->linesize[0];
488 linesize[3] = frame->linesize[0];
489 linesize[4] = frame->linesize[1];
490 linesize[5] = frame->linesize[2];
491
492 av_fast_padded_malloc(&s->mvectors, &s->mvectors_size, 2 * s->nb_mvectors * sizeof(*s->mvectors));
493 if (!s->mvectors) {
494 ret = AVERROR(ENOMEM);
495 goto fail;
496 }
497
498 mask = *gb;
499 skip_bits_long(gb, mask_size * 8);
500 mgb = *gb;
501 skip_bits_long(gb, s->mode_size * 8);
502
503 ret = decode_coeffs(gb, s->mvectors, 2 * s->nb_mvectors);
504 if (ret < 0)
505 goto fail;
506
507 bytestream2_init(&mv, (uint8_t *)s->mvectors, 2 * s->nb_mvectors * sizeof(*s->mvectors));
508
509 for (int y = 0; y < avctx->height; y += 16) {
510 GetByteContext gbyte;
511 int pfill[3][1] = { {0} };
512 int nb_codes = get_bits(gb, 16);
513
514 skip_bits(gb, 8);
515 if (get_bits_left(gb) < 0) {
517 goto fail;
518 }
519
520 av_fast_padded_malloc(&s->coeffs, &s->coeffs_size, nb_codes * sizeof(*s->coeffs));
521 if (!s->coeffs) {
522 ret = AVERROR(ENOMEM);
523 goto fail;
524 }
525
526 ret = decode_coeffs(gb, s->coeffs, nb_codes);
527 if (ret < 0)
528 goto fail;
529
530 bytestream2_init(&gbyte, (uint8_t *)s->coeffs, nb_codes * sizeof(*s->coeffs));
531
532 for (int x = 0; x < avctx->width; x += 16) {
533 if (cnt >= 4)
534 cnt = 0;
535 if (cnt == 0) {
536 if (get_bits_left(&mask) < 8) {
538 goto fail;
539 }
540 flags = get_bits(&mask, 8);
541 }
542
543 dst[0] = frame->data[0] + linesize[0] * y + x;
544 dst[1] = frame->data[0] + linesize[0] * y + x + 8;
545 dst[2] = frame->data[0] + linesize[0] * (y + 8) + x;
546 dst[3] = frame->data[0] + linesize[0] * (y + 8) + x + 8;
547 dst[4] = frame->data[1] + linesize[4] * (y >> 1) + (x >> 1);
548 dst[5] = frame->data[2] + linesize[5] * (y >> 1) + (x >> 1);
549
550 if ((flags >> (cnt)) & 1) {
551 int mv_x = sign_extend(bytestream2_get_ne16(&mv), 16);
552 int mv_y = sign_extend(bytestream2_get_ne16(&mv), 16);
553
554 int px = x + mv_x;
555 int py = y + mv_y;
556
557 if (px < 0 || px > FFALIGN(avctx->width , 16) - 16 ||
558 py < 0 || py > FFALIGN(avctx->height, 16) - 16)
559 return AVERROR_INVALIDDATA;
560
561 src[0] = prev->data[0] + in_linesize[0] * py + px;
562 src[1] = prev->data[0] + in_linesize[0] * py + px + 8;
563 src[2] = prev->data[0] + in_linesize[0] * (py + 8) + px;
564 src[3] = prev->data[0] + in_linesize[0] * (py + 8) + px + 8;
565 src[4] = prev->data[1] + in_linesize[4] * (py >> 1) + (px >> 1);
566 src[5] = prev->data[2] + in_linesize[5] * (py >> 1) + (px >> 1);
567
568 if ((flags >> (cnt + 4)) & 1) {
569 for (int b = 0; b < 6; b++)
570 copy_block8(dst[b], src[b], linesize[b], in_linesize[b], 8);
571 } else {
572 for (int b = 0; b < 6; b++) {
573 int mode = get_bits_le(&mgb, 2);
574
575 ret = decode_inter_block(avctx, mode, &gbyte, s->interq_tab[b >= 4],
576 s->block[b],
577 pfill[(b >= 4) + (b >= 5)],
578 dst[b], linesize[b],
579 src[b], in_linesize[b]);
580 if (ret < 0)
581 goto fail;
582 }
583 }
584 } else {
585 for (int b = 0; b < 6; b++) {
586 int mode = get_bits_le(&mgb, 2);
587
588 ret = decode_intra_block(avctx, mode, &gbyte, s->intraq_tab[b >= 4],
589 s->block[b],
590 pfill[(b >= 4) + (b >= 5)],
591 dst[b], linesize[b]);
592 if (ret < 0)
593 goto fail;
594 }
595 }
596
597 cnt++;
598 }
599 }
600
601fail:
602 return ret;
603}
604
606 int *got_frame, AVPacket *avpkt)
607{
608 MV30Context *s = avctx->priv_data;
609 GetBitContext *gb = &s->gb;
610 int ret;
611
612 if ((ret = init_get_bits8(gb, avpkt->data, avpkt->size)) < 0)
613 return ret;
614
615 if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
616 return ret;
617
618 s->intra_quant = get_bits(gb, 8);
619 s->inter_quant = s->intra_quant + get_sbits(gb, 8);
620 s->is_inter = get_bits_le(gb, 16);
621 s->mode_size = get_bits_le(gb, 16);
622 if (s->is_inter)
623 s->nb_mvectors = get_bits_le(gb, 16);
624
625 get_qtable(s->intraq_tab[0], s->intra_quant, luma_tab);
626 get_qtable(s->intraq_tab[1], s->intra_quant, chroma_tab);
627
628 if (s->is_inter == 0) {
629 frame->flags |= AV_FRAME_FLAG_KEY;
630 ret = decode_intra(avctx, gb, frame);
631 if (ret < 0)
632 return ret;
633 } else {
634 get_qtable(s->interq_tab[0], s->inter_quant, luma_tab);
635 get_qtable(s->interq_tab[1], s->inter_quant, chroma_tab);
636
637 if (!s->prev_frame->data[0]) {
638 av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
639 return AVERROR_INVALIDDATA;
640 }
641
642 frame->flags &= ~AV_FRAME_FLAG_KEY;
643 ret = decode_inter(avctx, gb, frame, s->prev_frame);
644 if (ret < 0)
645 return ret;
646 }
647
648 if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
649 return ret;
650
651 *got_frame = 1;
652
653 return avpkt->size;
654}
655
656static const uint8_t cbp_bits[] = {
657 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9, 9,
658};
659
666
668{
669 MV30Context *s = avctx->priv_data;
670 static AVOnce init_static_once = AV_ONCE_INIT;
671
674
675 ff_blockdsp_init(&s->bdsp);
676
677 s->prev_frame = av_frame_alloc();
678 if (!s->prev_frame)
679 return AVERROR(ENOMEM);
680
681 ff_thread_once(&init_static_once, init_static_data);
682
683 return 0;
684}
685
687{
688 MV30Context *s = avctx->priv_data;
689
690 av_frame_unref(s->prev_frame);
691}
692
694{
695 MV30Context *s = avctx->priv_data;
696
697 av_frame_free(&s->prev_frame);
698 av_freep(&s->coeffs);
699 s->coeffs_size = 0;
700 av_freep(&s->mvectors);
701 s->mvectors_size = 0;
702
703 return 0;
704}
705
707 .p.name = "mv30",
708 CODEC_LONG_NAME("MidiVid 3.0"),
709 .p.type = AVMEDIA_TYPE_VIDEO,
710 .p.id = AV_CODEC_ID_MV30,
711 .priv_data_size = sizeof(MV30Context),
712 .init = decode_init,
715 .flush = decode_flush,
716 .p.capabilities = AV_CODEC_CAP_DR1,
717 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
718};
const uint16_t ff_aanscales[64]
Definition aandcttab.c:26
AAN (Arai, Agui and Nakajima) (I)DCT tables.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static av_cold void decode_flush(AVCodecContext *avctx)
Definition agm.c:1253
const FFCodec ff_mv30_decoder
Definition mv30.c:706
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
Libavcodec external API header.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
#define bytestream2_get_ne16
Definition bytestream.h:119
static const uint8_t cbp_tab[64][2]
Definition cavsdec.c:46
#define flag(name)
Definition cbs_h264.c:60
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_clip
Definition common.h:100
#define av_clip_uint8
Definition common.h:106
static void copy_block8(uint8_t *dst, const uint8_t *src, ptrdiff_t dstStride, ptrdiff_t srcStride, int h)
Definition copy_block.h:47
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
double value
Definition eval.c:102
bitstream reader API header.
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition get_bits.h:358
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition get_bits.h:645
static int get_sbits(GetBitContext *s, int n)
Definition get_bits.h:322
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define fail
Definition test.h:479
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition avcodec.h:415
@ AV_CODEC_ID_MV30
Definition codec_id.h:296
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition utils.c:53
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:687
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
Definition frame.c:376
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define b
Definition input.c:43
static const int8_t mv[256][2]
Definition 4xm.c:81
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
static av_cold int decode_close(AVCodecContext *avctx)
Definition aacdec.c:1220
av_cold void ff_blockdsp_init(BlockDSPContext *c)
Definition blockdsp.c:58
static const int factor[16]
Definition vf_pp7.c:98
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
#define AVOnce
Definition thread.h:202
static int ff_thread_once(char *control, void(*routine)(void))
Definition thread.h:205
#define AV_ONCE_INIT
Definition thread.h:203
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
static av_const int sign_extend(int val, unsigned bits)
Definition mathops.h:135
Memory handling functions.
static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame)
Definition mv30.c:405
static av_cold void decode_flush(AVCodecContext *avctx)
Definition mv30.c:686
static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame, AVFrame *prev)
Definition mv30.c:464
static void get_qtable(int16_t *table, int quant, const uint8_t *quant_tab)
Definition mv30.c:99
static void idct2_1d(int *blk, int step)
Definition mv30.c:203
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition mv30.c:605
static av_cold int decode_close(AVCodecContext *avctx)
Definition mv30.c:693
static const uint8_t cbp_bits[]
Definition mv30.c:656
static void idct_add(uint8_t *dst, int stride, const uint8_t *src, int in_linesize, int *block)
Definition mv30.c:170
static av_cold int decode_init(AVCodecContext *avctx)
Definition mv30.c:667
static av_cold void init_static_data(void)
Definition mv30.c:660
static void idct_put(uint8_t *dst, int stride, int *block)
Definition mv30.c:139
static const uint8_t luma_tab[]
Definition mv30.c:66
static const uint8_t zigzag[]
Definition mv30.c:88
static int decode_intra_block(AVCodecContext *avctx, int mode, GetByteContext *gbyte, int16_t *qtab, int *block, int *pfill, uint8_t *dst, int linesize)
Definition mv30.c:297
static void update_inter_block(uint8_t *dst, int stride, const uint8_t *src, int in_linesize, int block)
Definition mv30.c:285
static int decode_coeffs(GetBitContext *gb, int16_t *coeffs, int nb_codes)
Definition mv30.c:379
static void idct_1d(unsigned *blk, int step)
Definition mv30.c:109
static void idct2_put(uint8_t *dst, int stride, int *block)
Definition mv30.c:222
static void idct2_add(uint8_t *dst, int stride, const uint8_t *src, int in_linesize, int *block)
Definition mv30.c:252
static int decode_inter_block(AVCodecContext *avctx, int mode, GetByteContext *gbyte, int16_t *qtab, int *block, int *pfill, uint8_t *dst, int linesize, const uint8_t *src, int in_linesize)
Definition mv30.c:338
static const uint8_t chroma_tab[]
Definition mv30.c:77
#define CBP_VLC_BITS
Definition mv30.c:40
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
static const uint16_t table[]
Definition prosumer.c:203
#define blk(i)
Definition sha.c:55
#define FF_ARRAY_ELEMS(a)
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
GetBitContext gb
Definition mv30.c:43
int is_inter
Definition mv30.c:47
unsigned int mvectors_size
Definition mv30.c:53
BlockDSPContext bdsp
Definition mv30.c:60
int16_t * mvectors
Definition mv30.c:52
AVFrame * prev_frame
Definition mv30.c:61
unsigned int coeffs_size
Definition mv30.c:55
int nb_mvectors
Definition mv30.c:49
int mode_size
Definition mv30.c:48
int block[6][64]
Definition mv30.c:51
int16_t interq_tab[2][64]
Definition mv30.c:58
int16_t intraq_tab[2][64]
Definition mv30.c:57
int inter_quant
Definition mv30.c:46
int16_t * coeffs
Definition mv30.c:54
int intra_quant
Definition mv30.c:45
Definition vlc.h:32
Definition swscale.c:71
#define stride
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
Definition vlc.h:288
static const uint8_t quant[64]
Definition vmixdec.c:71