FFmpeg
Loading...
Searching...
No Matches
diracdec.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007 Marco Gerards <marco@gnu.org>
3 * Copyright (C) 2009 David Conrad
4 * Copyright (C) 2011 Jordi Ortiz
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/**
24 * @file
25 * Dirac Decoder
26 * @author Marco Gerards <marco@gnu.org>, David Conrad, Jordi Ortiz <nenjordi@gmail.com>
27 */
28
29#include "libavutil/mem.h"
31#include "libavutil/pixdesc.h"
32#include "libavutil/thread.h"
33#include "avcodec.h"
34#include "get_bits.h"
35#include "codec_internal.h"
36#include "decode.h"
37#include "golomb.h"
38#include "dirac_arith.h"
39#include "dirac_vlc.h"
40#include "mpegvideoencdsp.h"
41#include "dirac_dwt.h"
42#include "dirac.h"
43#include "diractab.h"
44#include "diracdsp.h"
45#include "videodsp.h"
46
47#define EDGE_WIDTH 16
48
49/**
50 * The spec limits this to 3 for frame coding, but in practice can be as high as 6
51 */
52#define MAX_REFERENCE_FRAMES 8
53#define MAX_DELAY 5 /* limit for main profile for frame coding (TODO: field coding) */
54#define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1)
55#define MAX_QUANT 255 /* max quant for VC-2 */
56#define MAX_BLOCKSIZE 32 /* maximum xblen/yblen we support */
57
58/**
59 * DiracBlock->ref flags, if set then the block does MC from the given ref
60 */
61#define DIRAC_REF_MASK_REF1 1
62#define DIRAC_REF_MASK_REF2 2
63#define DIRAC_REF_MASK_GLOBAL 4
64
65/**
66 * Value of Picture.reference when Picture is not a reference picture, but
67 * is held for delayed output.
68 */
69#define DELAYED_PIC_REF 4
70
71#define CALC_PADDING(size, depth) \
72 (((size + (1 << depth) - 1) >> depth) << depth)
73
74#define DIVRNDUP(a, b) (((a) + (b) - 1) / (b))
75
76typedef struct {
78 int interpolated[3]; /* 1 if hpel[] is valid */
79 uint8_t *hpel[3][4];
80 uint8_t *hpel_base[3][4];
84
85typedef struct {
86 union {
87 int16_t mv[2][2];
88 int16_t dc[3];
89 } u; /* anonymous unions aren't in C99 :( */
90 uint8_t ref;
92
93typedef struct SubBand {
94 int level;
96 int stride; /* in bytes */
97 int width;
98 int height;
99 int pshift;
100 int quant;
101 uint8_t *ibuf;
103
104 /* for low delay */
105 unsigned length;
106 const uint8_t *coeff_data;
107} SubBand;
108
109typedef struct Plane {
111
112 int width;
113 int height;
114 ptrdiff_t stride;
115
116 /* block length */
117 uint8_t xblen;
118 uint8_t yblen;
119 /* block separation (block n+1 starts after this many pixels in block n) */
120 uint8_t xbsep;
121 uint8_t ybsep;
122 /* amount of overspill on each edge (half of the overlap between blocks) */
123 uint8_t xoffset;
124 uint8_t yoffset;
125
127} Plane;
128
129/* Used by Low Delay and High Quality profiles */
136
137typedef struct DiracContext {
146 int64_t frame_number; /* number of the next frame to display */
150
151 int bit_depth; /* bit depth */
152 int pshift; /* pixel shift = bit_depth > 8 */
153
154 int zero_res; /* zero residue flag */
155 int is_arith; /* whether coeffs use arith or golomb coding */
156 int core_syntax; /* use core syntax only */
157 int low_delay; /* use the low delay syntax */
158 int hq_picture; /* high quality picture, enables low_delay */
159 int ld_picture; /* use low delay picture, turns on low_delay */
160 int dc_prediction; /* has dc prediction */
161 int globalmc_flag; /* use global motion compensation */
162 int num_refs; /* number of reference pictures */
163
164 /* wavelet decoding */
165 unsigned wavelet_depth; /* depth of the IDWT */
166 unsigned wavelet_idx;
167
168 /**
169 * schroedinger older than 1.0.8 doesn't store
170 * quant delta if only one codebook exists in a band
171 */
174
175 unsigned num_x; /* number of horizontal slices */
176 unsigned num_y; /* number of vertical slices */
177
178 uint8_t *thread_buf; /* Per-thread buffer for coefficient storage */
179 int threads_num_buf; /* Current # of buffers allocated */
180 int thread_buf_size; /* Each thread has a buffer this size */
181
184
185 struct {
186 unsigned width;
187 unsigned height;
189
190 struct {
191 AVRational bytes; /* average bytes per slice */
192 uint8_t quant[MAX_DWT_LEVELS][4]; /* [DIRAC_STD] E.1 */
194
195 struct {
196 unsigned prefix_bytes;
197 uint64_t size_scaler;
199
200 struct {
201 int pan_tilt[2]; /* pan/tilt vector */
202 int zrs[2][2]; /* zoom/rotate/shear matrix */
203 int perspective[2]; /* perspective vector */
204 unsigned zrs_exp;
207
208 /* motion compensation */
209 uint8_t mv_precision; /* [DIRAC_STD] REFS_WT_PRECISION */
210 int16_t weight[2]; /* [DIRAC_STD] REF1_WT and REF2_WT */
211 unsigned weight_log2denom; /* [DIRAC_STD] REFS_WT_PRECISION */
212
213 int blwidth; /* number of blocks (horizontally) */
214 int blheight; /* number of blocks (vertically) */
215 int sbwidth; /* number of superblocks (horizontally) */
216 int sbheight; /* number of superblocks (vertically) */
217
218 uint8_t *sbsplit;
220
221 uint8_t *edge_emu_buffer[4];
223
224 uint16_t *mctmp; /* buffer holding the MC data multiplied by OBMC weights */
225 uint8_t *mcscratch;
227
229
230 void (*put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h);
231 void (*avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h);
232 void (*add_obmc)(uint16_t *dst, const uint8_t *src, ptrdiff_t stride, const uint8_t *obmc_weight, int yblen);
235
238
243
251
252/* magic number division by 3 from schroedinger */
253static inline int divide3(int x)
254{
255 return (int)((x+1U)*21845 + 10922) >> 16;
256}
257
258static DiracFrame *remove_frame(DiracFrame *framelist[], unsigned picnum)
259{
260 DiracFrame *remove_pic = NULL;
261 int i, remove_idx = -1;
262
263 for (i = 0; framelist[i]; i++)
264 if (framelist[i]->picture_number == picnum) {
265 remove_pic = framelist[i];
266 remove_idx = i;
267 }
268
269 if (remove_pic)
270 for (i = remove_idx; framelist[i]; i++)
271 framelist[i] = framelist[i+1];
272
273 return remove_pic;
274}
275
276static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame)
277{
278 int i;
279 for (i = 0; i < maxframes; i++)
280 if (!framelist[i]) {
281 framelist[i] = frame;
282 return 0;
283 }
284 return -1;
285}
286
288{
289 int sbwidth = DIVRNDUP(s->seq.width, 4);
290 int sbheight = DIVRNDUP(s->seq.height, 4);
291 int i, w, h, top_padding;
292
293 /* todo: think more about this / use or set Plane here */
294 for (i = 0; i < 3; i++) {
295 int max_xblen = MAX_BLOCKSIZE >> (i ? s->chroma_x_shift : 0);
296 int max_yblen = MAX_BLOCKSIZE >> (i ? s->chroma_y_shift : 0);
297 w = s->seq.width >> (i ? s->chroma_x_shift : 0);
298 h = s->seq.height >> (i ? s->chroma_y_shift : 0);
299
300 /* we allocate the max we support here since num decompositions can
301 * change from frame to frame. Stride is aligned to 16 for SIMD, and
302 * 1<<MAX_DWT_LEVELS top padding to avoid if(y>0) in arith decoding
303 * MAX_BLOCKSIZE padding for MC: blocks can spill up to half of that
304 * on each side */
305 top_padding = FFMAX(1<<MAX_DWT_LEVELS, max_yblen/2);
306 w = FFALIGN(CALC_PADDING(w, MAX_DWT_LEVELS), 8); /* FIXME: Should this be 16 for SSE??? */
307 h = top_padding + CALC_PADDING(h, MAX_DWT_LEVELS) + max_yblen/2;
308
309 s->plane[i].idwt.buf_base = av_calloc(w + max_xblen, h * (2 << s->pshift));
310 s->plane[i].idwt.tmp = av_malloc_array((w+16), 2 << s->pshift);
311 s->plane[i].idwt.buf = s->plane[i].idwt.buf_base + (top_padding*w)*(2 << s->pshift);
312 if (!s->plane[i].idwt.buf_base || !s->plane[i].idwt.tmp)
313 return AVERROR(ENOMEM);
314 }
315
316 /* fixme: allocate using real stride here */
317 s->sbsplit = av_malloc_array(sbwidth, sbheight);
318 s->blmotion = av_malloc_array(sbwidth, sbheight * 16 * sizeof(*s->blmotion));
319
320 if (!s->sbsplit || !s->blmotion)
321 return AVERROR(ENOMEM);
322 return 0;
323}
324
326{
327 int w = s->seq.width;
328 int h = s->seq.height;
329
330 av_assert0(stride >= w);
331 stride += 64;
332
333 if (s->buffer_stride >= stride)
334 return 0;
335 s->buffer_stride = 0;
336
337 av_freep(&s->edge_emu_buffer_base);
338 memset(s->edge_emu_buffer, 0, sizeof(s->edge_emu_buffer));
339 av_freep(&s->mctmp);
340 av_freep(&s->mcscratch);
341
342 s->edge_emu_buffer_base = av_malloc_array(stride, 4 * MAX_BLOCKSIZE);
343
344 s->mctmp = av_malloc_array((stride+MAX_BLOCKSIZE), (h + 5*MAX_BLOCKSIZE) * sizeof(*s->mctmp));
345 s->mcscratch = av_malloc_array(stride, MAX_BLOCKSIZE);
346
347 if (!s->edge_emu_buffer_base || !s->mctmp || !s->mcscratch)
348 return AVERROR(ENOMEM);
349
350 s->buffer_stride = stride;
351 return 0;
352}
353
355{
356 int i, j, k;
357
358 for (i = 0; i < MAX_FRAMES; i++) {
359 if (s->all_frames[i].avframe->data[0]) {
360 av_frame_unref(s->all_frames[i].avframe);
361 memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated));
362 }
363
364 for (j = 0; j < 3; j++)
365 for (k = 1; k < 4; k++)
366 av_freep(&s->all_frames[i].hpel_base[j][k]);
367 }
368
369 memset(s->ref_frames, 0, sizeof(s->ref_frames));
370 memset(s->delay_frames, 0, sizeof(s->delay_frames));
371
372 for (i = 0; i < 3; i++) {
373 av_freep(&s->plane[i].idwt.buf_base);
374 av_freep(&s->plane[i].idwt.tmp);
375 }
376
377 s->buffer_stride = 0;
378 av_freep(&s->sbsplit);
379 av_freep(&s->blmotion);
380 av_freep(&s->edge_emu_buffer_base);
381
382 av_freep(&s->mctmp);
383 av_freep(&s->mcscratch);
384}
385
387
389{
390 DiracContext *s = avctx->priv_data;
391 int i, ret;
392
393 s->avctx = avctx;
394 s->frame_number = -1;
395
396 s->thread_buf = NULL;
397 s->threads_num_buf = -1;
398 s->thread_buf_size = -1;
399
400 ff_diracdsp_init(&s->diracdsp);
401 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
402 ff_videodsp_init(&s->vdsp, 8);
403
404 for (i = 0; i < MAX_FRAMES; i++) {
405 s->all_frames[i].avframe = av_frame_alloc();
406 if (!s->all_frames[i].avframe)
407 return AVERROR(ENOMEM);
408 }
410 if (ret != 0)
411 return AVERROR_UNKNOWN;
412
413 return 0;
414}
415
417{
418 DiracContext *s = avctx->priv_data;
420 s->seen_sequence_header = 0;
421 s->frame_number = -1;
422}
423
425{
426 DiracContext *s = avctx->priv_data;
427 int i;
428
429 // Necessary in case dirac_decode_init() failed
430 if (s->all_frames[MAX_FRAMES - 1].avframe)
432 for (i = 0; i < MAX_FRAMES; i++)
433 av_frame_free(&s->all_frames[i].avframe);
434
435 av_freep(&s->thread_buf);
436 av_freep(&s->slice_params_buf);
437
438 return 0;
439}
440
441static inline int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset)
442{
443 int coeff = dirac_get_se_golomb(gb);
444 const unsigned sign = FFSIGN(coeff);
445 if (coeff)
446 coeff = sign*((sign * coeff * qfactor + qoffset) >> 2);
447 return coeff;
448}
449
450#define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0))
451
452#define UNPACK_ARITH(n, type) \
453 static inline void coeff_unpack_arith_##n(DiracArith *c, int qfactor, int qoffset, \
454 SubBand *b, type *buf, int x, int y) \
455 { \
456 int sign, sign_pred = 0, pred_ctx = CTX_ZPZN_F1; \
457 unsigned coeff; \
458 const int mstride = -(b->stride >> (1+b->pshift)); \
459 if (b->parent) { \
460 const type *pbuf = (type *)b->parent->ibuf; \
461 const int stride = b->parent->stride >> (1+b->parent->pshift); \
462 pred_ctx += !!pbuf[stride * (y>>1) + (x>>1)] << 1; \
463 } \
464 if (b->orientation == subband_hl) \
465 sign_pred = buf[mstride]; \
466 if (x) { \
467 pred_ctx += !(buf[-1] | buf[mstride] | buf[-1 + mstride]); \
468 if (b->orientation == subband_lh) \
469 sign_pred = buf[-1]; \
470 } else { \
471 pred_ctx += !buf[mstride]; \
472 } \
473 coeff = dirac_get_arith_uint(c, pred_ctx, CTX_COEFF_DATA); \
474 if (coeff) { \
475 coeff = (coeff * qfactor + qoffset) >> 2; \
476 sign = dirac_get_arith_bit(c, SIGN_CTX(sign_pred)); \
477 coeff = (coeff ^ -sign) + sign; \
478 } \
479 *buf = coeff; \
480 } \
481
482UNPACK_ARITH(8, int16_t)
484
485/**
486 * Decode the coeffs in the rectangle defined by left, right, top, bottom
487 * [DIRAC_STD] 13.4.3.2 Codeblock unpacking loop. codeblock()
488 */
489static inline int codeblock(const DiracContext *s, SubBand *b,
491 int left, int right, int top, int bottom,
492 int blockcnt_one, int is_arith)
493{
494 int x, y, zero_block;
495 int qoffset, qfactor;
496 uint8_t *buf;
497
498 /* check for any coded coefficients in this codeblock */
499 if (!blockcnt_one) {
500 if (is_arith)
501 zero_block = dirac_get_arith_bit(c, CTX_ZERO_BLOCK);
502 else
503 zero_block = get_bits1(gb);
504
505 if (zero_block)
506 return 0;
507 }
508
509 if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) {
510 int quant;
511 if (is_arith)
512 quant = dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA);
513 else
514 quant = dirac_get_se_golomb(gb);
515 if (quant > INT_MAX - b->quant || b->quant + quant < 0) {
516 av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n");
517 return AVERROR_INVALIDDATA;
518 }
519 b->quant += quant;
520 }
521
522 if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) {
523 av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", b->quant);
524 b->quant = 0;
525 return AVERROR_INVALIDDATA;
526 }
527
528 qfactor = ff_dirac_qscale_tab[b->quant];
529 /* TODO: context pointer? */
530 if (!s->num_refs)
531 qoffset = ff_dirac_qoffset_intra_tab[b->quant] + 2;
532 else
533 qoffset = ff_dirac_qoffset_inter_tab[b->quant] + 2;
534
535 buf = b->ibuf + top * b->stride;
536 if (is_arith) {
537 for (y = top; y < bottom; y++) {
538 if (c->error)
539 return c->error;
540 for (x = left; x < right; x++) {
541 if (b->pshift) {
542 coeff_unpack_arith_10(c, qfactor, qoffset, b, (int32_t*)(buf)+x, x, y);
543 } else {
544 coeff_unpack_arith_8(c, qfactor, qoffset, b, (int16_t*)(buf)+x, x, y);
545 }
546 }
547 buf += b->stride;
548 }
549 } else {
550 for (y = top; y < bottom; y++) {
551 if (get_bits_left(gb) < 1)
552 return AVERROR_INVALIDDATA;
553 for (x = left; x < right; x++) {
554 int val = coeff_unpack_golomb(gb, qfactor, qoffset);
555 if (b->pshift) {
556 AV_WN32(&buf[4*x], val);
557 } else {
558 AV_WN16(&buf[2*x], val);
559 }
560 }
561 buf += b->stride;
562 }
563 }
564 return 0;
565}
566
567/**
568 * Dirac Specification ->
569 * 13.3 intra_dc_prediction(band)
570 */
571#define INTRA_DC_PRED(n, type) \
572 static inline void intra_dc_prediction_##n(SubBand *b) \
573 { \
574 type *buf = (type*)b->ibuf; \
575 int x, y; \
576 \
577 for (x = 1; x < b->width; x++) \
578 buf[x] += buf[x-1]; \
579 buf += (b->stride >> (1+b->pshift)); \
580 \
581 for (y = 1; y < b->height; y++) { \
582 buf[0] += buf[-(b->stride >> (1+b->pshift))]; \
583 \
584 for (x = 1; x < b->width; x++) { \
585 int pred = buf[x - 1] + buf[x - (b->stride >> (1+b->pshift))] + buf[x - (b->stride >> (1+b->pshift))-1]; \
586 buf[x] += divide3(pred); \
587 } \
588 buf += (b->stride >> (1+b->pshift)); \
589 } \
590 } \
591
592INTRA_DC_PRED(8, int16_t)
593INTRA_DC_PRED(10, uint32_t)
594
595/**
596 * Dirac Specification ->
597 * 13.4.2 Non-skipped subbands. subband_coeffs()
598 */
600 SubBand *b, int is_arith)
601{
602 int cb_x, cb_y, left, right, top, bottom;
604 GetBitContext gb;
605 int cb_width = s->codeblock[b->level + (b->orientation != subband_ll)].width;
606 int cb_height = s->codeblock[b->level + (b->orientation != subband_ll)].height;
607 int blockcnt_one = (cb_width + cb_height) == 2;
608 int ret;
609
610 if (!b->length)
611 return 0;
612
613 init_get_bits8(&gb, b->coeff_data, b->length);
614
615 if (is_arith)
616 ff_dirac_init_arith_decoder(&c, &gb, b->length);
617
618 top = 0;
619 for (cb_y = 0; cb_y < cb_height; cb_y++) {
620 bottom = (b->height * (cb_y+1LL)) / cb_height;
621 left = 0;
622 for (cb_x = 0; cb_x < cb_width; cb_x++) {
623 right = (b->width * (cb_x+1LL)) / cb_width;
624 ret = codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith);
625 if (ret < 0)
626 return ret;
627 left = right;
628 }
629 top = bottom;
630 }
631
632 if (b->orientation == subband_ll && s->num_refs == 0) {
633 if (s->pshift) {
634 intra_dc_prediction_10(b);
635 } else {
636 intra_dc_prediction_8(b);
637 }
638 }
639 return 0;
640}
641
642static int decode_subband_arith(AVCodecContext *avctx, void *b)
643{
644 const DiracContext *s = avctx->priv_data;
645 return decode_subband_internal(s, b, 1);
646}
647
648static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
649{
650 const DiracContext *s = avctx->priv_data;
651 SubBand **b = arg;
652 return decode_subband_internal(s, *b, 0);
653}
654
655/**
656 * Dirac Specification ->
657 * [DIRAC_STD] 13.4.1 core_transform_data()
658 */
660{
661 AVCodecContext *avctx = s->avctx;
663 enum dirac_subband orientation;
664 int level, num_bands = 0;
665 int ret[3*MAX_DWT_LEVELS+1];
666 int i;
667 int damaged_count = 0;
668
669 /* Unpack all subbands at all levels. */
670 for (level = 0; level < s->wavelet_depth; level++) {
671 for (orientation = !!level; orientation < 4; orientation++) {
672 SubBand *b = &s->plane[comp].band[level][orientation];
673 bands[num_bands++] = b;
674
675 align_get_bits(&s->gb);
676 /* [DIRAC_STD] 13.4.2 subband() */
677 b->length = get_interleaved_ue_golomb(&s->gb);
678 if (b->length) {
679 b->quant = get_interleaved_ue_golomb(&s->gb);
680 if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) {
681 av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", b->quant);
682 b->quant = 0;
683 return AVERROR_INVALIDDATA;
684 }
685 align_get_bits(&s->gb);
686 b->coeff_data = s->gb.buffer + get_bits_count(&s->gb)/8;
687 if (b->length > FFMAX(get_bits_left(&s->gb)/8, 0)) {
688 b->length = FFMAX(get_bits_left(&s->gb)/8, 0);
689 damaged_count ++;
690 }
691 skip_bits_long(&s->gb, b->length*8);
692 }
693 }
694 /* arithmetic coding has inter-level dependencies, so we can only execute one level at a time */
695 if (s->is_arith)
696 avctx->execute(avctx, decode_subband_arith, &s->plane[comp].band[level][!!level],
697 ret + 3*level + !!level, 4-!!level, sizeof(SubBand));
698 }
699 /* golomb coding has no inter-level dependencies, so we can execute all subbands in parallel */
700 if (!s->is_arith)
701 avctx->execute(avctx, decode_subband_golomb, bands, ret, num_bands, sizeof(SubBand*));
702
703 for (i = 0; i < s->wavelet_depth * 3 + 1; i++) {
704 if (ret[i] < 0)
705 damaged_count++;
706 }
707 if (damaged_count > (s->wavelet_depth * 3 + 1) /2)
708 return AVERROR_INVALIDDATA;
709
710 return 0;
711}
712
713#define PARSE_VALUES(type, x, gb, ebits, buf1, buf2) \
714 type *buf = (type *)buf1; \
715 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
716 if (get_bits_count(gb) >= ebits) \
717 return; \
718 if (buf2) { \
719 buf = (type *)buf2; \
720 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
721 if (get_bits_count(gb) >= ebits) \
722 return; \
723 } \
724
725static void decode_subband(const DiracContext *s, GetBitContext *gb, int quant,
726 int slice_x, int slice_y, int bits_end,
727 const SubBand *b1, const SubBand *b2)
728{
729 int left = b1->width * slice_x / s->num_x;
730 int right = b1->width *(slice_x+1) / s->num_x;
731 int top = b1->height * slice_y / s->num_y;
732 int bottom = b1->height *(slice_y+1) / s->num_y;
733
734 int qfactor, qoffset;
735
736 uint8_t *buf1 = b1->ibuf + top * b1->stride;
737 uint8_t *buf2 = b2 ? b2->ibuf + top * b2->stride: NULL;
738 int x, y;
739
740 if (quant > (DIRAC_MAX_QUANT_INDEX - 1)) {
741 av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", quant);
742 return;
743 }
744 qfactor = ff_dirac_qscale_tab[quant];
745 qoffset = ff_dirac_qoffset_intra_tab[quant] + 2;
746 /* we have to constantly check for overread since the spec explicitly
747 requires this, with the meaning that all remaining coeffs are set to 0 */
748 if (get_bits_count(gb) >= bits_end)
749 return;
750
751 if (s->pshift) {
752 for (y = top; y < bottom; y++) {
753 for (x = left; x < right; x++) {
754 PARSE_VALUES(int32_t, x, gb, bits_end, buf1, buf2);
755 }
756 buf1 += b1->stride;
757 if (buf2)
758 buf2 += b2->stride;
759 }
760 }
761 else {
762 for (y = top; y < bottom; y++) {
763 for (x = left; x < right; x++) {
764 PARSE_VALUES(int16_t, x, gb, bits_end, buf1, buf2);
765 }
766 buf1 += b1->stride;
767 if (buf2)
768 buf2 += b2->stride;
769 }
770 }
771}
772
773/**
774 * Dirac Specification ->
775 * 13.5.2 Slices. slice(sx,sy)
776 */
777static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
778{
779 const DiracContext *s = avctx->priv_data;
780 DiracSlice *slice = arg;
781 GetBitContext *gb = &slice->gb;
782 enum dirac_subband orientation;
783 int level, quant, chroma_bits, chroma_end;
784
785 int quant_base = get_bits(gb, 7); /*[DIRAC_STD] qindex */
786 int length_bits = av_log2(8 * slice->bytes)+1;
787 int luma_bits = get_bits_long(gb, length_bits);
788 int luma_end = get_bits_count(gb) + FFMIN(luma_bits, get_bits_left(gb));
789
790 /* [DIRAC_STD] 13.5.5.2 luma_slice_band */
791 for (level = 0; level < s->wavelet_depth; level++)
792 for (orientation = !!level; orientation < 4; orientation++) {
793 quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0);
794 decode_subband(s, gb, quant, slice->slice_x, slice->slice_y, luma_end,
795 &s->plane[0].band[level][orientation], NULL);
796 }
797
798 /* consume any unused bits from luma */
799 skip_bits_long(gb, get_bits_count(gb) - luma_end);
800
801 chroma_bits = 8*slice->bytes - 7 - length_bits - luma_bits;
802 chroma_end = get_bits_count(gb) + FFMIN(chroma_bits, get_bits_left(gb));
803 /* [DIRAC_STD] 13.5.5.3 chroma_slice_band */
804 for (level = 0; level < s->wavelet_depth; level++)
805 for (orientation = !!level; orientation < 4; orientation++) {
806 quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0);
807 decode_subband(s, gb, quant, slice->slice_x, slice->slice_y, chroma_end,
808 &s->plane[1].band[level][orientation],
809 &s->plane[2].band[level][orientation]);
810 }
811
812 return 0;
813}
814
815typedef struct SliceCoeffs {
816 int left;
817 int top;
818 int tot_h;
819 int tot_v;
820 int tot;
822
823static int subband_coeffs(const DiracContext *s, int x, int y, int p,
825{
826 int level, coef = 0;
827 for (level = 0; level < s->wavelet_depth; level++) {
828 SliceCoeffs *o = &c[level];
829 const SubBand *b = &s->plane[p].band[level][3]; /* orientation doesn't matter */
830 o->top = b->height * y / s->num_y;
831 o->left = b->width * x / s->num_x;
832 o->tot_h = ((b->width * (x + 1)) / s->num_x) - o->left;
833 o->tot_v = ((b->height * (y + 1)) / s->num_y) - o->top;
834 o->tot = o->tot_h*o->tot_v;
835 coef += o->tot * (4 - !!level);
836 }
837 return coef;
838}
839
840/**
841 * VC-2 Specification ->
842 * 13.5.3 hq_slice(sx,sy)
843 */
844static int decode_hq_slice(const DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
845{
846 int i, level, orientation, quant_idx;
847 int qfactor[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4];
848 GetBitContext *gb = &slice->gb;
849 SliceCoeffs coeffs_num[MAX_DWT_LEVELS];
850
851 skip_bits_long(gb, 8*s->highquality.prefix_bytes);
852 quant_idx = get_bits(gb, 8);
853
854 if (quant_idx > DIRAC_MAX_QUANT_INDEX - 1) {
855 av_log(s->avctx, AV_LOG_ERROR, "Invalid quantization index - %i\n", quant_idx);
856 return AVERROR_INVALIDDATA;
857 }
858
859 /* Slice quantization (slice_quantizers() in the specs) */
860 for (level = 0; level < s->wavelet_depth; level++) {
861 for (orientation = !!level; orientation < 4; orientation++) {
862 const int quant = FFMAX(quant_idx - s->lowdelay.quant[level][orientation], 0);
863 qfactor[level][orientation] = ff_dirac_qscale_tab[quant];
864 qoffset[level][orientation] = ff_dirac_qoffset_intra_tab[quant] + 2;
865 }
866 }
867
868 /* Luma + 2 Chroma planes */
869 for (i = 0; i < 3; i++) {
870 int coef_num, coef_par, off = 0;
871 int64_t length = s->highquality.size_scaler*get_bits(gb, 8);
872 int64_t bits_end = get_bits_count(gb) + 8*length;
873 const uint8_t *addr = align_get_bits(gb);
874
875 if (length*8 > get_bits_left(gb)) {
876 av_log(s->avctx, AV_LOG_ERROR, "end too far away\n");
877 return AVERROR_INVALIDDATA;
878 }
879
880 coef_num = subband_coeffs(s, slice->slice_x, slice->slice_y, i, coeffs_num);
881
882 if (s->pshift)
883 coef_par = ff_dirac_golomb_read_32bit(addr, length,
884 tmp_buf, coef_num);
885 else
886 coef_par = ff_dirac_golomb_read_16bit(addr, length,
887 tmp_buf, coef_num);
888
889 if (coef_num > coef_par) {
890 const int start_b = coef_par * (1 << (s->pshift + 1));
891 const int end_b = coef_num * (1 << (s->pshift + 1));
892 memset(&tmp_buf[start_b], 0, end_b - start_b);
893 }
894
895 for (level = 0; level < s->wavelet_depth; level++) {
896 const SliceCoeffs *c = &coeffs_num[level];
897 for (orientation = !!level; orientation < 4; orientation++) {
898 const SubBand *b1 = &s->plane[i].band[level][orientation];
899 uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (s->pshift + 1));
900
901 /* Change to c->tot_h <= 4 for AVX2 dequantization */
902 const int qfunc = s->pshift + 2*(c->tot_h <= 2);
903 s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf, b1->stride,
904 qfactor[level][orientation],
905 qoffset[level][orientation],
906 c->tot_v, c->tot_h);
907
908 off += c->tot << (s->pshift + 1);
909 }
910 }
911
912 skip_bits_long(gb, bits_end - get_bits_count(gb));
913 }
914
915 return 0;
916}
917
918static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
919{
920 int i;
921 const DiracContext *s = avctx->priv_data;
922 DiracSlice *slices = ((DiracSlice *)arg) + s->num_x*jobnr;
923 uint8_t *thread_buf = &s->thread_buf[s->thread_buf_size*threadnr];
924 for (i = 0; i < s->num_x; i++)
925 decode_hq_slice(s, &slices[i], thread_buf);
926 return 0;
927}
928
929/**
930 * Dirac Specification ->
931 * 13.5.1 low_delay_transform_data()
932 */
934{
935 AVCodecContext *avctx = s->avctx;
936 int slice_x, slice_y, bufsize;
937 int64_t coef_buf_size, bytes = 0;
938 const uint8_t *buf;
939 DiracSlice *slices;
941 int slice_num = 0;
942
943 if (s->slice_params_num_buf != (s->num_x * s->num_y)) {
944 s->slice_params_buf = av_realloc_f(s->slice_params_buf, s->num_x * s->num_y, sizeof(DiracSlice));
945 if (!s->slice_params_buf) {
946 av_log(s->avctx, AV_LOG_ERROR, "slice params buffer allocation failure\n");
947 s->slice_params_num_buf = 0;
948 return AVERROR(ENOMEM);
949 }
950 s->slice_params_num_buf = s->num_x * s->num_y;
951 }
952 slices = s->slice_params_buf;
953
954 /* 8 becacuse that's how much the golomb reader could overread junk data
955 * from another plane/slice at most, and 512 because SIMD */
956 coef_buf_size = subband_coeffs(s, s->num_x - 1, s->num_y - 1, 0, tmp) + 8;
957 coef_buf_size = (coef_buf_size << (1 + s->pshift)) + 512;
958
959 if (s->threads_num_buf != avctx->thread_count ||
960 s->thread_buf_size != coef_buf_size) {
961 uint8_t *thread_buf = av_realloc_array(s->thread_buf, avctx->thread_count,
962 coef_buf_size);
963 if (!thread_buf) {
964 av_log(s->avctx, AV_LOG_ERROR, "thread buffer allocation failure\n");
965 return AVERROR(ENOMEM);
966 }
967 s->thread_buf = thread_buf;
968 s->threads_num_buf = avctx->thread_count;
969 s->thread_buf_size = coef_buf_size;
970 }
971
972 align_get_bits(&s->gb);
973 /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */
974 buf = s->gb.buffer + get_bits_count(&s->gb)/8;
975 bufsize = get_bits_left(&s->gb);
976
977 if (s->hq_picture) {
978 int i;
979
980 for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) {
981 for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) {
982 bytes = s->highquality.prefix_bytes + 1;
983 for (i = 0; i < 3; i++) {
984 if (bytes <= bufsize/8)
985 bytes += buf[bytes] * s->highquality.size_scaler + 1;
986 }
987 if (bytes >= INT_MAX || bytes*8 > bufsize) {
988 av_log(s->avctx, AV_LOG_ERROR, "too many bytes\n");
989 return AVERROR_INVALIDDATA;
990 }
991
992 slices[slice_num].bytes = bytes;
993 slices[slice_num].slice_x = slice_x;
994 slices[slice_num].slice_y = slice_y;
995 init_get_bits(&slices[slice_num].gb, buf, bufsize);
996 slice_num++;
997
998 buf += bytes;
999 if (bufsize/8 >= bytes)
1000 bufsize -= bytes*8;
1001 else
1002 bufsize = 0;
1003 }
1004 }
1005
1006 if (s->num_x*s->num_y != slice_num) {
1007 av_log(s->avctx, AV_LOG_ERROR, "too few slices\n");
1008 return AVERROR_INVALIDDATA;
1009 }
1010
1011 avctx->execute2(avctx, decode_hq_slice_row, slices, NULL, s->num_y);
1012 } else {
1013 for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) {
1014 for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) {
1015 bytes = (slice_num+1) * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den
1016 - slice_num * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den;
1017 if (bytes >= INT_MAX || bytes*8 > bufsize) {
1018 av_log(s->avctx, AV_LOG_ERROR, "too many bytes\n");
1019 return AVERROR_INVALIDDATA;
1020 }
1021 slices[slice_num].bytes = bytes;
1022 slices[slice_num].slice_x = slice_x;
1023 slices[slice_num].slice_y = slice_y;
1024 init_get_bits(&slices[slice_num].gb, buf, bufsize);
1025 slice_num++;
1026
1027 buf += bytes;
1028 if (bufsize/8 >= bytes)
1029 bufsize -= bytes*8;
1030 else
1031 bufsize = 0;
1032 }
1033 }
1034 avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num,
1035 sizeof(DiracSlice)); /* [DIRAC_STD] 13.5.2 Slices */
1036 }
1037
1038 if (s->dc_prediction) {
1039 if (s->pshift) {
1040 intra_dc_prediction_10(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */
1041 intra_dc_prediction_10(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */
1042 intra_dc_prediction_10(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */
1043 } else {
1044 intra_dc_prediction_8(&s->plane[0].band[0][0]);
1045 intra_dc_prediction_8(&s->plane[1].band[0][0]);
1046 intra_dc_prediction_8(&s->plane[2].band[0][0]);
1047 }
1048 }
1049
1050 return 0;
1051}
1052
1054{
1055 int i, w, h, level, orientation;
1056
1057 for (i = 0; i < 3; i++) {
1058 Plane *p = &s->plane[i];
1059
1060 p->width = s->seq.width >> (i ? s->chroma_x_shift : 0);
1061 p->height = s->seq.height >> (i ? s->chroma_y_shift : 0);
1062 p->idwt.width = w = CALC_PADDING(p->width , s->wavelet_depth);
1063 p->idwt.height = h = CALC_PADDING(p->height, s->wavelet_depth);
1064 p->idwt.stride = FFALIGN(p->idwt.width, 8) << (1 + s->pshift);
1065
1066 for (level = s->wavelet_depth-1; level >= 0; level--) {
1067 w = w>>1;
1068 h = h>>1;
1069 for (orientation = !!level; orientation < 4; orientation++) {
1070 SubBand *b = &p->band[level][orientation];
1071
1072 b->pshift = s->pshift;
1073 b->ibuf = p->idwt.buf;
1074 b->level = level;
1075 b->stride = p->idwt.stride << (s->wavelet_depth - level);
1076 b->width = w;
1077 b->height = h;
1078 b->orientation = orientation;
1079
1080 if (orientation & 1)
1081 b->ibuf += w << (1+b->pshift);
1082 if (orientation > 1)
1083 b->ibuf += (b->stride>>1);
1084
1085 if (level)
1086 b->parent = &p->band[level-1][orientation];
1087 }
1088 }
1089
1090 if (i > 0) {
1091 p->xblen = s->plane[0].xblen >> s->chroma_x_shift;
1092 p->yblen = s->plane[0].yblen >> s->chroma_y_shift;
1093 p->xbsep = s->plane[0].xbsep >> s->chroma_x_shift;
1094 p->ybsep = s->plane[0].ybsep >> s->chroma_y_shift;
1095 }
1096
1097 p->xoffset = (p->xblen - p->xbsep)/2;
1098 p->yoffset = (p->yblen - p->ybsep)/2;
1099 }
1100}
1101
1102/**
1103 * Unpack the motion compensation parameters
1104 * Dirac Specification ->
1105 * 11.2 Picture prediction data. picture_prediction()
1106 */
1108{
1109 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
1110
1111 GetBitContext *gb = &s->gb;
1112 unsigned idx, ref;
1113
1114 align_get_bits(gb);
1115 /* [DIRAC_STD] 11.2.2 Block parameters. block_parameters() */
1116 /* Luma and Chroma are equal. 11.2.3 */
1117 idx = get_interleaved_ue_golomb(gb); /* [DIRAC_STD] index */
1118
1119 if (idx > 4) {
1120 av_log(s->avctx, AV_LOG_ERROR, "Block prediction index too high\n");
1121 return AVERROR_INVALIDDATA;
1122 }
1123
1124 if (idx == 0) {
1125 s->plane[0].xblen = get_interleaved_ue_golomb(gb);
1126 s->plane[0].yblen = get_interleaved_ue_golomb(gb);
1127 s->plane[0].xbsep = get_interleaved_ue_golomb(gb);
1128 s->plane[0].ybsep = get_interleaved_ue_golomb(gb);
1129 } else {
1130 /*[DIRAC_STD] preset_block_params(index). Table 11.1 */
1131 s->plane[0].xblen = default_blen[idx-1];
1132 s->plane[0].yblen = default_blen[idx-1];
1133 s->plane[0].xbsep = 4 * idx;
1134 s->plane[0].ybsep = 4 * idx;
1135 }
1136 /*[DIRAC_STD] 11.2.4 motion_data_dimensions()
1137 Calculated in function dirac_unpack_block_motion_data */
1138
1139 if (s->plane[0].xblen % (1 << s->chroma_x_shift) != 0 ||
1140 s->plane[0].yblen % (1 << s->chroma_y_shift) != 0 ||
1141 !s->plane[0].xblen || !s->plane[0].yblen) {
1142 av_log(s->avctx, AV_LOG_ERROR,
1143 "invalid x/y block length (%d/%d) for x/y chroma shift (%d/%d)\n",
1144 s->plane[0].xblen, s->plane[0].yblen, s->chroma_x_shift, s->chroma_y_shift);
1145 return AVERROR_INVALIDDATA;
1146 }
1147 if (!s->plane[0].xbsep || !s->plane[0].ybsep || s->plane[0].xbsep < s->plane[0].xblen/2 || s->plane[0].ybsep < s->plane[0].yblen/2) {
1148 av_log(s->avctx, AV_LOG_ERROR, "Block separation too small\n");
1149 return AVERROR_INVALIDDATA;
1150 }
1151 if (s->plane[0].xbsep > s->plane[0].xblen || s->plane[0].ybsep > s->plane[0].yblen) {
1152 av_log(s->avctx, AV_LOG_ERROR, "Block separation greater than size\n");
1153 return AVERROR_INVALIDDATA;
1154 }
1155 if (FFMAX(s->plane[0].xblen, s->plane[0].yblen) > MAX_BLOCKSIZE) {
1156 av_log(s->avctx, AV_LOG_ERROR, "Unsupported large block size\n");
1157 return AVERROR_PATCHWELCOME;
1158 }
1159
1160 /*[DIRAC_STD] 11.2.5 Motion vector precision. motion_vector_precision()
1161 Read motion vector precision */
1162 s->mv_precision = get_interleaved_ue_golomb(gb);
1163 if (s->mv_precision > 3) {
1164 av_log(s->avctx, AV_LOG_ERROR, "MV precision finer than eighth-pel\n");
1165 return AVERROR_INVALIDDATA;
1166 }
1167
1168 /*[DIRAC_STD] 11.2.6 Global motion. global_motion()
1169 Read the global motion compensation parameters */
1170 s->globalmc_flag = get_bits1(gb);
1171 if (s->globalmc_flag) {
1172 memset(s->globalmc, 0, sizeof(s->globalmc));
1173 /* [DIRAC_STD] pan_tilt(gparams) */
1174 for (ref = 0; ref < s->num_refs; ref++) {
1175 if (get_bits1(gb)) {
1176 s->globalmc[ref].pan_tilt[0] = dirac_get_se_golomb(gb);
1177 s->globalmc[ref].pan_tilt[1] = dirac_get_se_golomb(gb);
1178 }
1179 /* [DIRAC_STD] zoom_rotate_shear(gparams)
1180 zoom/rotation/shear parameters */
1181 if (get_bits1(gb)) {
1182 s->globalmc[ref].zrs_exp = get_interleaved_ue_golomb(gb);
1183 s->globalmc[ref].zrs[0][0] = dirac_get_se_golomb(gb);
1184 s->globalmc[ref].zrs[0][1] = dirac_get_se_golomb(gb);
1185 s->globalmc[ref].zrs[1][0] = dirac_get_se_golomb(gb);
1186 s->globalmc[ref].zrs[1][1] = dirac_get_se_golomb(gb);
1187 } else {
1188 s->globalmc[ref].zrs[0][0] = 1;
1189 s->globalmc[ref].zrs[1][1] = 1;
1190 }
1191 /* [DIRAC_STD] perspective(gparams) */
1192 if (get_bits1(gb)) {
1193 s->globalmc[ref].perspective_exp = get_interleaved_ue_golomb(gb);
1194 s->globalmc[ref].perspective[0] = dirac_get_se_golomb(gb);
1195 s->globalmc[ref].perspective[1] = dirac_get_se_golomb(gb);
1196 }
1197 if (s->globalmc[ref].perspective_exp + (uint64_t)s->globalmc[ref].zrs_exp > 30) {
1198 return AVERROR_INVALIDDATA;
1199 }
1200
1201 }
1202 }
1203
1204 /*[DIRAC_STD] 11.2.7 Picture prediction mode. prediction_mode()
1205 Picture prediction mode, not currently used. */
1206 if (get_interleaved_ue_golomb(gb)) {
1207 av_log(s->avctx, AV_LOG_ERROR, "Unknown picture prediction mode\n");
1208 return AVERROR_INVALIDDATA;
1209 }
1210
1211 /* [DIRAC_STD] 11.2.8 Reference picture weight. reference_picture_weights()
1212 just data read, weight calculation will be done later on. */
1213 s->weight_log2denom = 1;
1214 s->weight[0] = 1;
1215 s->weight[1] = 1;
1216
1217 if (get_bits1(gb)) {
1218 s->weight_log2denom = get_interleaved_ue_golomb(gb);
1219 if (s->weight_log2denom < 1 || s->weight_log2denom > 8) {
1220 av_log(s->avctx, AV_LOG_ERROR, "weight_log2denom unsupported or invalid\n");
1221 s->weight_log2denom = 1;
1222 return AVERROR_INVALIDDATA;
1223 }
1224 s->weight[0] = dirac_get_se_golomb(gb);
1225 if (s->num_refs == 2)
1226 s->weight[1] = dirac_get_se_golomb(gb);
1227 }
1228 return 0;
1229}
1230
1231/**
1232 * Dirac Specification ->
1233 * 11.3 Wavelet transform data. wavelet_transform()
1234 */
1236{
1237 GetBitContext *gb = &s->gb;
1238 int i, level;
1239 unsigned tmp;
1240
1241#define CHECKEDREAD(dst, cond, errmsg) \
1242 tmp = get_interleaved_ue_golomb(gb); \
1243 if (cond) { \
1244 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1245 return AVERROR_INVALIDDATA; \
1246 }\
1247 dst = tmp;
1248
1249 align_get_bits(gb);
1250
1251 s->zero_res = s->num_refs ? get_bits1(gb) : 0;
1252 if (s->zero_res)
1253 return 0;
1254
1255 /*[DIRAC_STD] 11.3.1 Transform parameters. transform_parameters() */
1256 CHECKEDREAD(s->wavelet_idx, tmp > 6, "wavelet_idx is too big\n")
1257
1258 CHECKEDREAD(s->wavelet_depth, tmp > MAX_DWT_LEVELS || tmp < 1, "invalid number of DWT decompositions\n")
1259
1260 if (!s->low_delay) {
1261 /* Codeblock parameters (core syntax only) */
1262 if (get_bits1(gb)) {
1263 for (i = 0; i <= s->wavelet_depth; i++) {
1264 CHECKEDREAD(s->codeblock[i].width , tmp < 1 || tmp > (s->avctx->width >>s->wavelet_depth-i), "codeblock width invalid\n")
1265 CHECKEDREAD(s->codeblock[i].height, tmp < 1 || tmp > (s->avctx->height>>s->wavelet_depth-i), "codeblock height invalid\n")
1266 }
1267
1268 CHECKEDREAD(s->codeblock_mode, tmp > 1, "unknown codeblock mode\n")
1269 }
1270 else {
1271 for (i = 0; i <= s->wavelet_depth; i++)
1272 s->codeblock[i].width = s->codeblock[i].height = 1;
1273 }
1274 }
1275 else {
1276 s->num_x = get_interleaved_ue_golomb(gb);
1277 s->num_y = get_interleaved_ue_golomb(gb);
1278 if (s->num_x * s->num_y == 0 || s->num_x * (uint64_t)s->num_y > INT_MAX ||
1279 s->num_x * (uint64_t)s->avctx->width > INT_MAX ||
1280 s->num_y * (uint64_t)s->avctx->height > INT_MAX ||
1281 s->num_x > s->avctx->width ||
1282 s->num_y > s->avctx->height
1283 ) {
1284 av_log(s->avctx,AV_LOG_ERROR,"Invalid numx/y\n");
1285 s->num_x = s->num_y = 0;
1286 return AVERROR_INVALIDDATA;
1287 }
1288 if (s->ld_picture) {
1289 s->lowdelay.bytes.num = get_interleaved_ue_golomb(gb);
1290 s->lowdelay.bytes.den = get_interleaved_ue_golomb(gb);
1291 if (s->lowdelay.bytes.den <= 0) {
1292 av_log(s->avctx,AV_LOG_ERROR,"Invalid lowdelay.bytes.den\n");
1293 return AVERROR_INVALIDDATA;
1294 }
1295 } else if (s->hq_picture) {
1296 s->highquality.prefix_bytes = get_interleaved_ue_golomb(gb);
1297 s->highquality.size_scaler = get_interleaved_ue_golomb(gb);
1298 if (s->highquality.prefix_bytes >= INT_MAX / 8) {
1299 av_log(s->avctx,AV_LOG_ERROR,"too many prefix bytes\n");
1300 return AVERROR_INVALIDDATA;
1301 }
1302 }
1303
1304 /* [DIRAC_STD] 11.3.5 Quantisation matrices (low-delay syntax). quant_matrix() */
1305 if (get_bits1(gb)) {
1306 av_log(s->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n");
1307 /* custom quantization matrix */
1308 for (level = 0; level < s->wavelet_depth; level++) {
1309 for (i = !!level; i < 4; i++) {
1310 s->lowdelay.quant[level][i] = get_interleaved_ue_golomb(gb);
1311 }
1312 }
1313 } else {
1314 if (s->wavelet_depth > 4) {
1315 av_log(s->avctx,AV_LOG_ERROR,"Mandatory custom low delay matrix missing for depth %d\n", s->wavelet_depth);
1316 return AVERROR_INVALIDDATA;
1317 }
1318 /* default quantization matrix */
1319 for (level = 0; level < s->wavelet_depth; level++)
1320 for (i = 0; i < 4; i++) {
1321 s->lowdelay.quant[level][i] = ff_dirac_default_qmat[s->wavelet_idx][level][i];
1322 /* haar with no shift differs for different depths */
1323 if (s->wavelet_idx == 3)
1324 s->lowdelay.quant[level][i] += 4*(s->wavelet_depth-1 - level);
1325 }
1326 }
1327 }
1328 return 0;
1329}
1330
1331static inline int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y)
1332{
1333 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1334
1335 if (!(x|y))
1336 return 0;
1337 else if (!y)
1338 return sbsplit[-1];
1339 else if (!x)
1340 return sbsplit[-stride];
1341
1342 return avgsplit[sbsplit[-1] + sbsplit[-stride] + sbsplit[-stride-1]];
1343}
1344
1345static inline int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask)
1346{
1347 int pred;
1348
1349 if (!(x|y))
1350 return 0;
1351 else if (!y)
1352 return block[-1].ref & refmask;
1353 else if (!x)
1354 return block[-stride].ref & refmask;
1355
1356 /* return the majority */
1357 pred = (block[-1].ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].ref & refmask);
1358 return (pred >> 1) & refmask;
1359}
1360
1361static inline void pred_block_dc(DiracBlock *block, int stride, int x, int y)
1362{
1363 int i, n = 0;
1364
1365 memset(block->u.dc, 0, sizeof(block->u.dc));
1366
1367 if (x && !(block[-1].ref & 3)) {
1368 for (i = 0; i < 3; i++)
1369 block->u.dc[i] += block[-1].u.dc[i];
1370 n++;
1371 }
1372
1373 if (y && !(block[-stride].ref & 3)) {
1374 for (i = 0; i < 3; i++)
1375 block->u.dc[i] += block[-stride].u.dc[i];
1376 n++;
1377 }
1378
1379 if (x && y && !(block[-1-stride].ref & 3)) {
1380 for (i = 0; i < 3; i++)
1381 block->u.dc[i] += block[-1-stride].u.dc[i];
1382 n++;
1383 }
1384
1385 if (n == 2) {
1386 for (i = 0; i < 3; i++)
1387 block->u.dc[i] = (block->u.dc[i]+1)>>1;
1388 } else if (n == 3) {
1389 for (i = 0; i < 3; i++)
1390 block->u.dc[i] = divide3(block->u.dc[i]);
1391 }
1392}
1393
1394static inline void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
1395{
1396 int16_t *pred[3];
1397 int refmask = ref+1;
1398 int mask = refmask | DIRAC_REF_MASK_GLOBAL; /* exclude gmc blocks */
1399 int n = 0;
1400
1401 if (x && (block[-1].ref & mask) == refmask)
1402 pred[n++] = block[-1].u.mv[ref];
1403
1404 if (y && (block[-stride].ref & mask) == refmask)
1405 pred[n++] = block[-stride].u.mv[ref];
1406
1407 if (x && y && (block[-stride-1].ref & mask) == refmask)
1408 pred[n++] = block[-stride-1].u.mv[ref];
1409
1410 switch (n) {
1411 case 0:
1412 block->u.mv[ref][0] = 0;
1413 block->u.mv[ref][1] = 0;
1414 break;
1415 case 1:
1416 block->u.mv[ref][0] = pred[0][0];
1417 block->u.mv[ref][1] = pred[0][1];
1418 break;
1419 case 2:
1420 block->u.mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1;
1421 block->u.mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1;
1422 break;
1423 case 3:
1424 block->u.mv[ref][0] = mid_pred(pred[0][0], pred[1][0], pred[2][0]);
1425 block->u.mv[ref][1] = mid_pred(pred[0][1], pred[1][1], pred[2][1]);
1426 break;
1427 }
1428}
1429
1430static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref)
1431{
1432 int ez = s->globalmc[ref].zrs_exp;
1433 int ep = s->globalmc[ref].perspective_exp;
1434 int (*A)[2] = s->globalmc[ref].zrs;
1435 int *b = s->globalmc[ref].pan_tilt;
1436 int *c = s->globalmc[ref].perspective;
1437
1438 int64_t m = (1<<ep) - (c[0]*(int64_t)x + c[1]*(int64_t)y);
1439 int64_t mx = m * (uint64_t)((A[0][0] * (int64_t)x + A[0][1]*(int64_t)y) + (1LL<<ez) * b[0]);
1440 int64_t my = m * (uint64_t)((A[1][0] * (int64_t)x + A[1][1]*(int64_t)y) + (1LL<<ez) * b[1]);
1441
1442 block->u.mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1443 block->u.mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
1444}
1445
1447 int stride, int x, int y)
1448{
1449 int i;
1450
1453
1454 if (s->num_refs == 2) {
1456 block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF2) << 1;
1457 }
1458
1459 if (!block->ref) {
1460 pred_block_dc(block, stride, x, y);
1461 for (i = 0; i < 3; i++)
1462 block->u.dc[i] += (unsigned)dirac_get_arith_int(arith+1+i, CTX_DC_F1, CTX_DC_DATA);
1463 return;
1464 }
1465
1466 if (s->globalmc_flag) {
1468 block->ref ^= dirac_get_arith_bit(arith, CTX_GLOBAL_BLOCK) << 2;
1469 }
1470
1471 for (i = 0; i < s->num_refs; i++)
1472 if (block->ref & (i+1)) {
1473 if (block->ref & DIRAC_REF_MASK_GLOBAL) {
1474 global_mv(s, block, x, y, i);
1475 } else {
1476 pred_mv(block, stride, x, y, i);
1477 block->u.mv[i][0] += (unsigned)dirac_get_arith_int(arith + 4 + 2 * i, CTX_MV_F1, CTX_MV_DATA);
1478 block->u.mv[i][1] += (unsigned)dirac_get_arith_int(arith + 5 + 2 * i, CTX_MV_F1, CTX_MV_DATA);
1479 }
1480 }
1481}
1482
1483/**
1484 * Copies the current block to the other blocks covered by the current superblock split mode
1485 */
1487{
1488 int x, y;
1489 DiracBlock *dst = block;
1490
1491 for (x = 1; x < size; x++)
1492 dst[x] = *block;
1493
1494 for (y = 1; y < size; y++) {
1495 dst += stride;
1496 for (x = 0; x < size; x++)
1497 dst[x] = *block;
1498 }
1499}
1500
1501/**
1502 * Dirac Specification ->
1503 * 12. Block motion data syntax
1504 */
1506{
1507 GetBitContext *gb = &s->gb;
1508 uint8_t *sbsplit = s->sbsplit;
1509 int i, x, y, q, p;
1510 DiracArith arith[8];
1511
1512 align_get_bits(gb);
1513
1514 /* [DIRAC_STD] 11.2.4 and 12.2.1 Number of blocks and superblocks */
1515 s->sbwidth = DIVRNDUP(s->seq.width, 4*s->plane[0].xbsep);
1516 s->sbheight = DIVRNDUP(s->seq.height, 4*s->plane[0].ybsep);
1517 s->blwidth = 4 * s->sbwidth;
1518 s->blheight = 4 * s->sbheight;
1519
1520 /* [DIRAC_STD] 12.3.1 Superblock splitting modes. superblock_split_modes()
1521 decode superblock split modes */
1522 ff_dirac_init_arith_decoder(arith, gb, get_interleaved_ue_golomb(gb)); /* get_interleaved_ue_golomb(gb) is the length */
1523 for (y = 0; y < s->sbheight; y++) {
1524 for (x = 0; x < s->sbwidth; x++) {
1525 unsigned int split = dirac_get_arith_uint(arith, CTX_SB_F1, CTX_SB_DATA);
1526 if (split > 2)
1527 return AVERROR_INVALIDDATA;
1528 sbsplit[x] = (split + pred_sbsplit(sbsplit+x, s->sbwidth, x, y)) % 3;
1529 }
1530 sbsplit += s->sbwidth;
1531 }
1532
1533 /* setup arith decoding */
1535 for (i = 0; i < s->num_refs; i++) {
1538 }
1539 for (i = 0; i < 3; i++)
1541
1542 for (y = 0; y < s->sbheight; y++)
1543 for (x = 0; x < s->sbwidth; x++) {
1544 int blkcnt = 1 << s->sbsplit[y * s->sbwidth + x];
1545 int step = 4 >> s->sbsplit[y * s->sbwidth + x];
1546
1547 for (q = 0; q < blkcnt; q++)
1548 for (p = 0; p < blkcnt; p++) {
1549 int bx = 4 * x + p*step;
1550 int by = 4 * y + q*step;
1551 DiracBlock *block = &s->blmotion[by*s->blwidth + bx];
1552 decode_block_params(s, arith, block, s->blwidth, bx, by);
1553 propagate_block_data(block, s->blwidth, step);
1554 }
1555 }
1556
1557 for (i = 0; i < 4 + 2*s->num_refs; i++) {
1558 if (arith[i].error)
1559 return arith[i].error;
1560 }
1561
1562 return 0;
1563}
1564
1565static int weight(int i, int blen, int offset)
1566{
1567#define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1568 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1569
1570 if (i < 2*offset)
1571 return ROLLOFF(i);
1572 else if (i > blen-1 - 2*offset)
1573 return ROLLOFF(blen-1 - i);
1574 return 8;
1575}
1576
1577static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride,
1578 int left, int right, int wy)
1579{
1580 int x;
1581 for (x = 0; left && x < p->xblen >> 1; x++)
1582 obmc_weight[x] = wy*8;
1583 for (; x < p->xblen >> right; x++)
1584 obmc_weight[x] = wy*weight(x, p->xblen, p->xoffset);
1585 for (; x < p->xblen; x++)
1586 obmc_weight[x] = wy*8;
1587 for (; x < stride; x++)
1588 obmc_weight[x] = 0;
1589}
1590
1591static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride,
1592 int left, int right, int top, int bottom)
1593{
1594 int y;
1595 for (y = 0; top && y < p->yblen >> 1; y++) {
1596 init_obmc_weight_row(p, obmc_weight, stride, left, right, 8);
1597 obmc_weight += stride;
1598 }
1599 for (; y < p->yblen >> bottom; y++) {
1600 int wy = weight(y, p->yblen, p->yoffset);
1601 init_obmc_weight_row(p, obmc_weight, stride, left, right, wy);
1602 obmc_weight += stride;
1603 }
1604 for (; y < p->yblen; y++) {
1605 init_obmc_weight_row(p, obmc_weight, stride, left, right, 8);
1606 obmc_weight += stride;
1607 }
1608}
1609
1610static void init_obmc_weights(DiracContext *s, Plane *p, int by)
1611{
1612 int top = !by;
1613 int bottom = by == s->blheight-1;
1614
1615 /* don't bother re-initing for rows 2 to blheight-2, the weights don't change */
1616 if (top || bottom || by == 1) {
1617 init_obmc_weight(p, s->obmc_weight[0], MAX_BLOCKSIZE, 1, 0, top, bottom);
1618 init_obmc_weight(p, s->obmc_weight[1], MAX_BLOCKSIZE, 0, 0, top, bottom);
1619 init_obmc_weight(p, s->obmc_weight[2], MAX_BLOCKSIZE, 0, 1, top, bottom);
1620 }
1621}
1622
1623static const uint8_t epel_weights[4][4][4] = {
1624 {{ 16, 0, 0, 0 },
1625 { 12, 4, 0, 0 },
1626 { 8, 8, 0, 0 },
1627 { 4, 12, 0, 0 }},
1628 {{ 12, 0, 4, 0 },
1629 { 9, 3, 3, 1 },
1630 { 6, 6, 2, 2 },
1631 { 3, 9, 1, 3 }},
1632 {{ 8, 0, 8, 0 },
1633 { 6, 2, 6, 2 },
1634 { 4, 4, 4, 4 },
1635 { 2, 6, 2, 6 }},
1636 {{ 4, 0, 12, 0 },
1637 { 3, 1, 9, 3 },
1638 { 2, 2, 6, 6 },
1639 { 1, 3, 3, 9 }}
1640};
1641
1642/**
1643 * For block x,y, determine which of the hpel planes to do bilinear
1644 * interpolation from and set src[] to the location in each hpel plane
1645 * to MC from.
1646 *
1647 * @return the index of the put_dirac_pixels_tab function to use
1648 * 0 for 1 plane (fpel,hpel), 1 for 2 planes (qpel), 2 for 4 planes (qpel), and 3 for epel
1649 */
1650static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5],
1651 int x, int y, int ref, int plane)
1652{
1653 Plane *p = &s->plane[plane];
1654 uint8_t **ref_hpel = s->ref_pics[ref]->hpel[plane];
1655 int motion_x = block->u.mv[ref][0];
1656 int motion_y = block->u.mv[ref][1];
1657 int mx, my, i, epel, nplanes = 0;
1658
1659 if (plane) {
1660 motion_x >>= s->chroma_x_shift;
1661 motion_y >>= s->chroma_y_shift;
1662 }
1663
1664 mx = motion_x & ~(-1U << s->mv_precision);
1665 my = motion_y & ~(-1U << s->mv_precision);
1666 motion_x >>= s->mv_precision;
1667 motion_y >>= s->mv_precision;
1668 /* normalize subpel coordinates to epel */
1669 /* TODO: template this function? */
1670 mx <<= 3 - s->mv_precision;
1671 my <<= 3 - s->mv_precision;
1672
1673 x += motion_x;
1674 y += motion_y;
1675 epel = (mx|my)&1;
1676
1677 /* hpel position */
1678 if (!((mx|my)&3)) {
1679 nplanes = 1;
1680 src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->stride + x;
1681 } else {
1682 /* qpel or epel */
1683 nplanes = 4;
1684 for (i = 0; i < 4; i++)
1685 src[i] = ref_hpel[i] + y*p->stride + x;
1686
1687 /* if we're interpolating in the right/bottom halves, adjust the planes as needed
1688 we increment x/y because the edge changes for half of the pixels */
1689 if (mx > 4) {
1690 src[0] += 1;
1691 src[2] += 1;
1692 x++;
1693 }
1694 if (my > 4) {
1695 src[0] += p->stride;
1696 src[1] += p->stride;
1697 y++;
1698 }
1699
1700 /* hpel planes are:
1701 [0]: F [1]: H
1702 [2]: V [3]: C */
1703 if (!epel) {
1704 /* check if we really only need 2 planes since either mx or my is
1705 a hpel position. (epel weights of 0 handle this there) */
1706 if (!(mx&3)) {
1707 /* mx == 0: average [0] and [2]
1708 mx == 4: average [1] and [3] */
1709 src[!mx] = src[2 + !!mx];
1710 nplanes = 2;
1711 } else if (!(my&3)) {
1712 src[0] = src[(my>>1) ];
1713 src[1] = src[(my>>1)+1];
1714 nplanes = 2;
1715 }
1716 } else {
1717 /* adjust the ordering if needed so the weights work */
1718 if (mx > 4) {
1719 FFSWAP(const uint8_t *, src[0], src[1]);
1720 FFSWAP(const uint8_t *, src[2], src[3]);
1721 }
1722 if (my > 4) {
1723 FFSWAP(const uint8_t *, src[0], src[2]);
1724 FFSWAP(const uint8_t *, src[1], src[3]);
1725 }
1726 src[4] = epel_weights[my&3][mx&3];
1727 }
1728 }
1729
1730 /* fixme: v/h _edge_pos */
1731 if (x + p->xblen > p->width +EDGE_WIDTH/2 ||
1732 y + p->yblen > p->height+EDGE_WIDTH/2 ||
1733 x < 0 || y < 0) {
1734 for (i = 0; i < nplanes; i++) {
1735 s->vdsp.emulated_edge_mc(s->edge_emu_buffer[i], src[i],
1736 p->stride, p->stride,
1737 p->xblen, p->yblen, x, y,
1738 p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2);
1739 src[i] = s->edge_emu_buffer[i];
1740 }
1741 }
1742 return (nplanes>>1) + epel;
1743}
1744
1745static void add_dc(uint16_t *dst, int dc, int stride,
1746 uint8_t *obmc_weight, int xblen, int yblen)
1747{
1748 int x, y;
1749 dc += 128;
1750
1751 for (y = 0; y < yblen; y++) {
1752 for (x = 0; x < xblen; x += 2) {
1753 dst[x ] += dc * obmc_weight[x ];
1754 dst[x+1] += dc * obmc_weight[x+1];
1755 }
1756 dst += stride;
1757 obmc_weight += MAX_BLOCKSIZE;
1758 }
1759}
1760
1762 uint16_t *mctmp, uint8_t *obmc_weight,
1763 int plane, int dstx, int dsty)
1764{
1765 Plane *p = &s->plane[plane];
1766 const uint8_t *src[5];
1767 int idx;
1768
1769 switch (block->ref&3) {
1770 case 0: /* DC */
1771 add_dc(mctmp, block->u.dc[plane], p->stride, obmc_weight, p->xblen, p->yblen);
1772 return;
1773 case 1:
1774 case 2:
1775 idx = mc_subpel(s, block, src, dstx, dsty, (block->ref&3)-1, plane);
1776 s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen);
1777 if (s->weight_func)
1778 s->weight_func(s->mcscratch, p->stride, s->weight_log2denom,
1779 s->weight[0] + s->weight[1], p->yblen);
1780 break;
1781 case 3:
1782 idx = mc_subpel(s, block, src, dstx, dsty, 0, plane);
1783 s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen);
1784 idx = mc_subpel(s, block, src, dstx, dsty, 1, plane);
1785 if (s->biweight_func) {
1786 /* fixme: +32 is a quick hack */
1787 s->put_pixels_tab[idx](s->mcscratch + 32, src, p->stride, p->yblen);
1788 s->biweight_func(s->mcscratch, s->mcscratch+32, p->stride, s->weight_log2denom,
1789 s->weight[0], s->weight[1], p->yblen);
1790 } else
1791 s->avg_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen);
1792 break;
1793 }
1794 s->add_obmc(mctmp, s->mcscratch, p->stride, obmc_weight, p->yblen);
1795}
1796
1797static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty)
1798{
1799 Plane *p = &s->plane[plane];
1800 int x, dstx = p->xbsep - p->xoffset;
1801
1802 block_mc(s, block, mctmp, s->obmc_weight[0], plane, -p->xoffset, dsty);
1803 mctmp += p->xbsep;
1804
1805 for (x = 1; x < s->blwidth-1; x++) {
1806 block_mc(s, block+x, mctmp, s->obmc_weight[1], plane, dstx, dsty);
1807 dstx += p->xbsep;
1808 mctmp += p->xbsep;
1809 }
1810 block_mc(s, block+x, mctmp, s->obmc_weight[2], plane, dstx, dsty);
1811}
1812
1813static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen)
1814{
1815 int idx = 0;
1816 if (xblen > 8)
1817 idx = 1;
1818 if (xblen > 16)
1819 idx = 2;
1820
1821 memcpy(s->put_pixels_tab, s->diracdsp.put_dirac_pixels_tab[idx], sizeof(s->put_pixels_tab));
1822 memcpy(s->avg_pixels_tab, s->diracdsp.avg_dirac_pixels_tab[idx], sizeof(s->avg_pixels_tab));
1823 s->add_obmc = s->diracdsp.add_dirac_obmc[idx];
1824 if (s->weight_log2denom > 1 || s->weight[0] != 1 || s->weight[1] != 1) {
1825 s->weight_func = s->diracdsp.weight_dirac_pixels_tab[idx];
1826 s->biweight_func = s->diracdsp.biweight_dirac_pixels_tab[idx];
1827 } else {
1828 s->weight_func = NULL;
1829 s->biweight_func = NULL;
1830 }
1831}
1832
1833static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height)
1834{
1835 /* chroma allocates an edge of 8 when subsampled
1836 which for 4:2:2 means an h edge of 16 and v edge of 8
1837 just use 8 for everything for the moment */
1838 int i, edge = EDGE_WIDTH/2;
1839
1840 ref->hpel[plane][0] = ref->avframe->data[plane];
1841 s->mpvencdsp.draw_edges(ref->hpel[plane][0], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); /* EDGE_TOP | EDGE_BOTTOM values just copied to make it build, this needs to be ensured */
1842
1843 /* no need for hpel if we only have fpel vectors */
1844 if (!s->mv_precision)
1845 return 0;
1846
1847 for (i = 1; i < 4; i++) {
1848 if (!ref->hpel_base[plane][i])
1849 ref->hpel_base[plane][i] = av_malloc((height+2*edge) * ref->avframe->linesize[plane] + 32);
1850 if (!ref->hpel_base[plane][i]) {
1851 return AVERROR(ENOMEM);
1852 }
1853 /* we need to be 16-byte aligned even for chroma */
1854 ref->hpel[plane][i] = ref->hpel_base[plane][i] + edge*ref->avframe->linesize[plane] + 16;
1855 }
1856
1857 if (!ref->interpolated[plane]) {
1858 s->diracdsp.dirac_hpel_filter(ref->hpel[plane][1], ref->hpel[plane][2],
1859 ref->hpel[plane][3], ref->hpel[plane][0],
1860 ref->avframe->linesize[plane], width, height);
1861 s->mpvencdsp.draw_edges(ref->hpel[plane][1], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1862 s->mpvencdsp.draw_edges(ref->hpel[plane][2], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1863 s->mpvencdsp.draw_edges(ref->hpel[plane][3], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1864 }
1865 ref->interpolated[plane] = 1;
1866
1867 return 0;
1868}
1869
1870/**
1871 * Dirac Specification ->
1872 * 13.0 Transform data syntax. transform_data()
1873 */
1875{
1876 DWTContext d;
1877 int y, i, comp, dsty;
1878 int ret;
1879
1880 if (s->low_delay) {
1881 /* [DIRAC_STD] 13.5.1 low_delay_transform_data() */
1882 if (!s->hq_picture) {
1883 for (comp = 0; comp < 3; comp++) {
1884 Plane *p = &s->plane[comp];
1885 memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height);
1886 }
1887 }
1888 if (!s->zero_res) {
1889 if ((ret = decode_lowdelay(s)) < 0)
1890 return ret;
1891 }
1892 }
1893
1894 for (comp = 0; comp < 3; comp++) {
1895 Plane *p = &s->plane[comp];
1896 uint8_t *frame = s->current_picture->avframe->data[comp];
1897
1898 /* FIXME: small resolutions */
1899 for (i = 0; i < 4; i++)
1900 s->edge_emu_buffer[i] = s->edge_emu_buffer_base + i*s->buffer_stride*MAX_BLOCKSIZE;
1901
1902 if (!s->zero_res && !s->low_delay)
1903 {
1904 memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height);
1905 ret = decode_component(s, comp); /* [DIRAC_STD] 13.4.1 core_transform_data() */
1906 if (ret < 0)
1907 return ret;
1908 }
1909 ret = ff_spatial_idwt_init(&d, &p->idwt, s->wavelet_idx+2,
1910 s->wavelet_depth, s->bit_depth);
1911 if (ret < 0)
1912 return ret;
1913
1914 if (!s->num_refs) { /* intra */
1915 for (y = 0; y < p->height; y += 16) {
1916 int idx = (s->bit_depth - 8) >> 1;
1917 ff_spatial_idwt_slice2(&d, y+16); /* decode */
1918 s->diracdsp.put_signed_rect_clamped[idx](frame + y*p->stride,
1919 p->stride,
1920 p->idwt.buf + y*p->idwt.stride,
1921 p->idwt.stride, p->width, 16);
1922 }
1923 } else { /* inter */
1924 int rowheight = p->ybsep*p->stride;
1925
1926 select_dsp_funcs(s, p->width, p->height, p->xblen, p->yblen);
1927
1928 for (i = 0; i < s->num_refs; i++) {
1929 ret = interpolate_refplane(s, s->ref_pics[i], comp, p->width, p->height);
1930 if (ret < 0)
1931 return ret;
1932 }
1933
1934 memset(s->mctmp, 0, 4*p->yoffset*p->stride);
1935
1936 dsty = -p->yoffset;
1937 for (y = 0; y < s->blheight; y++) {
1938 int h = 0,
1939 start = FFMAX(dsty, 0);
1940 uint16_t *mctmp = s->mctmp + y*rowheight;
1941 DiracBlock *blocks = s->blmotion + y*s->blwidth;
1942
1943 init_obmc_weights(s, p, y);
1944
1945 if (y == s->blheight-1 || start+p->ybsep > p->height)
1946 h = p->height - start;
1947 else
1948 h = p->ybsep - (start - dsty);
1949 if (h <= 0)
1950 break;
1951
1952 memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight);
1953 mc_row(s, blocks, mctmp, comp, dsty);
1954
1955 mctmp += (start - dsty)*p->stride + p->xoffset;
1956 ff_spatial_idwt_slice2(&d, start + h); /* decode */
1957 /* NOTE: add_rect_clamped hasn't been templated hence the shifts.
1958 * idwt.stride is passed as pixels, not in bytes as in the rest of the decoder */
1959 s->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride,
1960 (int16_t*)(p->idwt.buf) + start*(p->idwt.stride >> 1), (p->idwt.stride >> 1), p->width, h);
1961
1962 dsty += p->ybsep;
1963 }
1964 }
1965 }
1966
1967
1968 return 0;
1969}
1970
1972{
1973 int ret, i;
1974 int chroma_x_shift, chroma_y_shift;
1975 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_x_shift,
1976 &chroma_y_shift);
1977 if (ret < 0)
1978 return ret;
1979
1980 f->width = avctx->width + 2 * EDGE_WIDTH;
1981 f->height = avctx->height + 2 * EDGE_WIDTH + 2;
1982 ret = ff_get_buffer(avctx, f, flags);
1983 if (ret < 0)
1984 return ret;
1985
1986 for (i = 0; f->data[i]; i++) {
1987 int offset = (EDGE_WIDTH >> (i && i<3 ? chroma_y_shift : 0)) *
1988 f->linesize[i] + 32;
1989 f->data[i] += offset;
1990 }
1991 f->width = avctx->width;
1992 f->height = avctx->height;
1993
1994 return 0;
1995}
1996
1997/**
1998 * Dirac Specification ->
1999 * 11.1.1 Picture Header. picture_header()
2000 */
2002{
2003 unsigned retire, picnum;
2004 int i, j, ret;
2005 int64_t refdist, refnum;
2006 GetBitContext *gb = &s->gb;
2007
2008 /* [DIRAC_STD] 11.1.1 Picture Header. picture_header() PICTURE_NUM */
2009 picnum = s->current_picture->picture_number = get_bits_long(gb, 32);
2010
2011
2012 av_log(s->avctx,AV_LOG_DEBUG,"PICTURE_NUM: %d\n",picnum);
2013
2014 /* if this is the first keyframe after a sequence header, start our
2015 reordering from here */
2016 if (s->frame_number < 0)
2017 s->frame_number = picnum;
2018
2019 s->ref_pics[0] = s->ref_pics[1] = NULL;
2020 for (i = 0; i < s->num_refs; i++) {
2021 refnum = (picnum + dirac_get_se_golomb(gb)) & 0xFFFFFFFF;
2022 refdist = INT64_MAX;
2023
2024 /* find the closest reference to the one we want */
2025 /* Jordi: this is needed if the referenced picture hasn't yet arrived */
2026 for (j = 0; j < MAX_REFERENCE_FRAMES && refdist; j++)
2027 if (s->ref_frames[j]
2028 && FFABS(s->ref_frames[j]->picture_number - refnum) < refdist) {
2029 s->ref_pics[i] = s->ref_frames[j];
2030 refdist = FFABS(s->ref_frames[j]->picture_number - refnum);
2031 }
2032
2033 if (!s->ref_pics[i] || refdist)
2034 av_log(s->avctx, AV_LOG_DEBUG, "Reference not found\n");
2035
2036 /* if there were no references at all, allocate one */
2037 if (!s->ref_pics[i])
2038 for (j = 0; j < MAX_FRAMES; j++)
2039 if (!s->all_frames[j].avframe->data[0]) {
2040 s->ref_pics[i] = &s->all_frames[j];
2041 ret = get_buffer_with_edge(s->avctx, s->ref_pics[i]->avframe, AV_GET_BUFFER_FLAG_REF);
2042 if (ret < 0)
2043 return ret;
2044 break;
2045 }
2046
2047 if (!s->ref_pics[i]) {
2048 av_log(s->avctx, AV_LOG_ERROR, "Reference could not be allocated\n");
2049 return AVERROR_INVALIDDATA;
2050 }
2051
2052 }
2053
2054 /* retire the reference frames that are not used anymore */
2055 if (s->current_picture->reference) {
2056 retire = (picnum + dirac_get_se_golomb(gb)) & 0xFFFFFFFF;
2057 if (retire != picnum) {
2058 DiracFrame *retire_pic = remove_frame(s->ref_frames, retire);
2059
2060 if (retire_pic)
2061 retire_pic->reference &= DELAYED_PIC_REF;
2062 else
2063 av_log(s->avctx, AV_LOG_DEBUG, "Frame to retire not found\n");
2064 }
2065
2066 /* if reference array is full, remove the oldest as per the spec */
2067 while (add_frame(s->ref_frames, MAX_REFERENCE_FRAMES, s->current_picture)) {
2068 av_log(s->avctx, AV_LOG_ERROR, "Reference frame overflow\n");
2069 remove_frame(s->ref_frames, s->ref_frames[0]->picture_number)->reference &= DELAYED_PIC_REF;
2070 }
2071 }
2072
2073 if (s->num_refs) {
2074 ret = dirac_unpack_prediction_parameters(s); /* [DIRAC_STD] 11.2 Picture Prediction Data. picture_prediction() */
2075 if (ret < 0)
2076 return ret;
2077 ret = dirac_unpack_block_motion_data(s); /* [DIRAC_STD] 12. Block motion data syntax */
2078 if (ret < 0)
2079 return ret;
2080 }
2081 ret = dirac_unpack_idwt_params(s); /* [DIRAC_STD] 11.3 Wavelet transform data */
2082 if (ret < 0)
2083 return ret;
2084
2085 init_planes(s);
2086 return 0;
2087}
2088
2089static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
2090{
2091 DiracFrame *out = s->delay_frames[0];
2092 int i, out_idx = 0;
2093 int ret;
2094
2095 /* find frame with lowest picture number */
2096 for (i = 1; s->delay_frames[i]; i++)
2097 if (s->delay_frames[i]->picture_number < out->picture_number) {
2098 out = s->delay_frames[i];
2099 out_idx = i;
2100 }
2101
2102 for (i = out_idx; s->delay_frames[i]; i++)
2103 s->delay_frames[i] = s->delay_frames[i+1];
2104
2105 if (out) {
2106 out->reference ^= DELAYED_PIC_REF;
2107 if((ret = av_frame_ref(picture, out->avframe)) < 0)
2108 return ret;
2109 *got_frame = 1;
2110 }
2111
2112 return 0;
2113}
2114
2115/**
2116 * Dirac Specification ->
2117 * 9.6 Parse Info Header Syntax. parse_info()
2118 * 4 byte start code + byte parse code + 4 byte size + 4 byte previous size
2119 */
2120#define DATA_UNIT_HEADER_SIZE 13
2121
2122/* [DIRAC_STD] dirac_decode_data_unit makes reference to the while defined in 9.3
2123 inside the function parse_sequence() */
2124static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size)
2125{
2126 DiracContext *s = avctx->priv_data;
2127 DiracFrame *pic = NULL;
2128 AVDiracSeqHeader *dsh;
2129 int ret, i;
2130 uint8_t parse_code;
2131 unsigned tmp;
2132
2134 return AVERROR_INVALIDDATA;
2135
2136 parse_code = buf[4];
2137
2138 ret = init_get_bits8(&s->gb, &buf[13], size - DATA_UNIT_HEADER_SIZE);
2139 if (ret < 0)
2140 return ret;
2141
2142 if (parse_code == DIRAC_PCODE_SEQ_HEADER) {
2143 if (s->seen_sequence_header)
2144 return 0;
2145
2146 /* [DIRAC_STD] 10. Sequence header */
2148 if (ret < 0) {
2149 av_log(avctx, AV_LOG_ERROR, "error parsing sequence header");
2150 return ret;
2151 }
2152
2154 ret = AVERROR(ERANGE);
2155 if (ret >= 0)
2156 ret = ff_set_dimensions(avctx, dsh->width, dsh->height);
2157 if (ret < 0) {
2158 av_freep(&dsh);
2159 return ret;
2160 }
2161
2162 ff_set_sar(avctx, dsh->sample_aspect_ratio);
2163 avctx->pix_fmt = dsh->pix_fmt;
2164 avctx->color_range = dsh->color_range;
2165 avctx->color_trc = dsh->color_trc;
2166 avctx->color_primaries = dsh->color_primaries;
2167 avctx->colorspace = dsh->colorspace;
2168 avctx->profile = dsh->profile;
2169 avctx->level = dsh->level;
2170 avctx->framerate = dsh->framerate;
2171 s->bit_depth = dsh->bit_depth;
2172 s->version.major = dsh->version.major;
2173 s->version.minor = dsh->version.minor;
2174 s->seq = *dsh;
2175 av_freep(&dsh);
2176
2177 s->pshift = s->bit_depth > 8;
2178
2180 &s->chroma_x_shift,
2181 &s->chroma_y_shift);
2182 if (ret < 0)
2183 return ret;
2184
2186 if (ret < 0)
2187 return ret;
2188
2189 s->seen_sequence_header = 1;
2190 } else if (parse_code == DIRAC_PCODE_END_SEQ) { /* [DIRAC_STD] End of Sequence */
2192 s->seen_sequence_header = 0;
2193 } else if (parse_code == DIRAC_PCODE_AUX) {
2194 if (buf[13] == 1) { /* encoder implementation/version */
2195 int ver[3];
2196 /* versions older than 1.0.8 don't store quant delta for
2197 subbands with only one codeblock */
2198 if (sscanf(buf+14, "Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
2199 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
2200 s->old_delta_quant = 1;
2201 }
2202 } else if (parse_code & 0x8) { /* picture data unit */
2203 if (!s->seen_sequence_header) {
2204 av_log(avctx, AV_LOG_DEBUG, "Dropping frame without sequence header\n");
2205 return AVERROR_INVALIDDATA;
2206 }
2207
2208 /* find an unused frame */
2209 for (i = 0; i < MAX_FRAMES; i++)
2210 if (s->all_frames[i].avframe->data[0] == NULL)
2211 pic = &s->all_frames[i];
2212 if (!pic) {
2213 av_log(avctx, AV_LOG_ERROR, "framelist full\n");
2214 return AVERROR_INVALIDDATA;
2215 }
2216
2217 av_frame_unref(pic->avframe);
2218
2219 /* [DIRAC_STD] Defined in 9.6.1 ... */
2220 tmp = parse_code & 0x03; /* [DIRAC_STD] num_refs() */
2221 if (tmp > 2) {
2222 av_log(avctx, AV_LOG_ERROR, "num_refs of 3\n");
2223 return AVERROR_INVALIDDATA;
2224 }
2225 s->num_refs = tmp;
2226 s->is_arith = (parse_code & 0x48) == 0x08; /* [DIRAC_STD] using_ac() */
2227 s->low_delay = (parse_code & 0x88) == 0x88; /* [DIRAC_STD] is_low_delay() */
2228 s->core_syntax = (parse_code & 0x88) == 0x08; /* [DIRAC_STD] is_core_syntax() */
2229 s->ld_picture = (parse_code & 0xF8) == 0xC8; /* [DIRAC_STD] is_ld_picture() */
2230 s->hq_picture = (parse_code & 0xF8) == 0xE8; /* [DIRAC_STD] is_hq_picture() */
2231 s->dc_prediction = (parse_code & 0x28) == 0x08; /* [DIRAC_STD] using_dc_prediction() */
2232 pic->reference = (parse_code & 0x0C) == 0x0C; /* [DIRAC_STD] is_reference() */
2233 if (s->num_refs == 0) /* [DIRAC_STD] is_intra() */
2235 else
2237 pic->avframe->pict_type = s->num_refs + 1; /* Definition of AVPictureType in avutil.h */
2238
2239 /* VC-2 Low Delay has a different parse code than the Dirac Low Delay */
2240 if (s->version.minor == 2 && parse_code == 0x88)
2241 s->ld_picture = 1;
2242
2243 if (s->low_delay && !(s->ld_picture || s->hq_picture) ) {
2244 av_log(avctx, AV_LOG_ERROR, "Invalid low delay flag\n");
2245 return AVERROR_INVALIDDATA;
2246 }
2247
2248 if ((ret = get_buffer_with_edge(avctx, pic->avframe, (parse_code & 0x0C) == 0x0C ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
2249 return ret;
2250 s->current_picture = pic;
2251 s->plane[0].stride = pic->avframe->linesize[0];
2252 s->plane[1].stride = pic->avframe->linesize[1];
2253 s->plane[2].stride = pic->avframe->linesize[2];
2254
2255 if (alloc_buffers(s, FFMAX3(FFABS(s->plane[0].stride), FFABS(s->plane[1].stride), FFABS(s->plane[2].stride))) < 0)
2256 return AVERROR(ENOMEM);
2257
2258 /* [DIRAC_STD] 11.1 Picture parse. picture_parse() */
2260 if (ret < 0)
2261 return ret;
2262
2263 /* [DIRAC_STD] 13.0 Transform data syntax. transform_data() */
2265 if (ret < 0)
2266 return ret;
2267 }
2268 return 0;
2269}
2270
2271static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture,
2272 int *got_frame, AVPacket *pkt)
2273{
2274 DiracContext *s = avctx->priv_data;
2275 const uint8_t *buf = pkt->data;
2276 int buf_size = pkt->size;
2277 int i, buf_idx = 0;
2278 int ret;
2279 unsigned data_unit_size;
2280
2281 /* release unused frames */
2282 for (i = 0; i < MAX_FRAMES; i++)
2283 if (s->all_frames[i].avframe->data[0] && !s->all_frames[i].reference) {
2284 av_frame_unref(s->all_frames[i].avframe);
2285 memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated));
2286 }
2287
2288 s->current_picture = NULL;
2289 *got_frame = 0;
2290
2291 /* end of stream, so flush delayed pics */
2292 if (buf_size == 0)
2293 return get_delayed_pic(s, picture, got_frame);
2294
2295 for (;;) {
2296 /*[DIRAC_STD] Here starts the code from parse_info() defined in 9.6
2297 [DIRAC_STD] PARSE_INFO_PREFIX = "BBCD" as defined in ISO/IEC 646
2298 BBCD start code search */
2299 for (; buf_idx + DATA_UNIT_HEADER_SIZE < buf_size; buf_idx++) {
2300 if (buf[buf_idx ] == 'B' && buf[buf_idx+1] == 'B' &&
2301 buf[buf_idx+2] == 'C' && buf[buf_idx+3] == 'D')
2302 break;
2303 }
2304 /* BBCD found or end of data */
2305 if (buf_idx + DATA_UNIT_HEADER_SIZE >= buf_size)
2306 break;
2307
2308 data_unit_size = AV_RB32(buf+buf_idx+5);
2309 if (data_unit_size > buf_size - buf_idx || !data_unit_size) {
2310 if(data_unit_size > buf_size - buf_idx)
2311 av_log(s->avctx, AV_LOG_ERROR,
2312 "Data unit with size %d is larger than input buffer, discarding\n",
2313 data_unit_size);
2314 buf_idx += 4;
2315 continue;
2316 }
2317 /* [DIRAC_STD] dirac_decode_data_unit makes reference to the while defined in 9.3 inside the function parse_sequence() */
2318 ret = dirac_decode_data_unit(avctx, buf+buf_idx, data_unit_size);
2319 if (ret < 0)
2320 {
2321 av_log(s->avctx, AV_LOG_ERROR,"Error in dirac_decode_data_unit\n");
2322 return ret;
2323 }
2324 buf_idx += data_unit_size;
2325 }
2326
2327 if (!s->current_picture)
2328 return buf_size;
2329
2330 if (s->current_picture->picture_number > s->frame_number) {
2331 DiracFrame *delayed_frame = remove_frame(s->delay_frames, s->frame_number);
2332
2333 s->current_picture->reference |= DELAYED_PIC_REF;
2334
2335 if (add_frame(s->delay_frames, MAX_DELAY, s->current_picture)) {
2336 unsigned min_num = s->delay_frames[0]->picture_number;
2337 /* Too many delayed frames, so we display the frame with the lowest pts */
2338 av_log(avctx, AV_LOG_ERROR, "Delay frame overflow\n");
2339
2340 for (i = 1; s->delay_frames[i]; i++)
2341 if (s->delay_frames[i]->picture_number < min_num)
2342 min_num = s->delay_frames[i]->picture_number;
2343
2344 delayed_frame = remove_frame(s->delay_frames, min_num);
2345 add_frame(s->delay_frames, MAX_DELAY, s->current_picture);
2346 }
2347
2348 if (delayed_frame) {
2349 delayed_frame->reference ^= DELAYED_PIC_REF;
2350 if((ret = av_frame_ref(picture, delayed_frame->avframe)) < 0)
2351 return ret;
2352 s->frame_number = delayed_frame->picture_number + 1LL;
2353 *got_frame = 1;
2354 }
2355 } else if (s->current_picture->picture_number == s->frame_number) {
2356 /* The right frame at the right time :-) */
2357 if((ret = av_frame_ref(picture, s->current_picture->avframe)) < 0)
2358 return ret;
2359 s->frame_number = s->current_picture->picture_number + 1LL;
2360 *got_frame = 1;
2361 }
2362
2363 return buf_idx;
2364}
2365
2367 .p.name = "dirac",
2368 CODEC_LONG_NAME("BBC Dirac VC-2"),
2369 .p.type = AVMEDIA_TYPE_VIDEO,
2370 .p.id = AV_CODEC_ID_DIRAC,
2371 .priv_data_size = sizeof(DiracContext),
2376 .flush = dirac_decode_flush,
2377 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
2378};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition dsp.h:67
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition dsp.h:67
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static char * split(char *message, char delim)
static const float bands[]
const FFCodec ff_dirac_decoder
Definition diracdec.c:2366
static FILE * out
#define A(x)
Definition vpx_arith.h:28
int32_t
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#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 FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define FFSIGN(a)
Definition common.h:75
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
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:1814
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition utils.c:106
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
static AVPacket * pkt
static AVFrame * frame
Interface to Dirac Decoder/Encoder.
@ DIRAC_PCODE_AUX
Definition dirac.h:64
@ DIRAC_PCODE_END_SEQ
Definition dirac.h:63
@ DIRAC_PCODE_SEQ_HEADER
Definition dirac.h:62
#define MAX_DWT_LEVELS
The spec limits the number of wavelet decompositions to 4 for both level 1 (VC-2) and 128 (long-gop d...
Definition dirac.h:49
void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
Definition dirac_arith.c:96
av_cold void ff_dirac_init_arith_tables(void)
Definition dirac_arith.c:86
Arithmetic decoder for Dirac.
#define CTX_GLOBAL_BLOCK
Definition dirac_arith.h:70
#define CTX_PMODE_REF2
Definition dirac_arith.h:69
static int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_ctx)
#define CTX_MV_F1
Definition dirac_arith.h:71
#define CTX_SB_DATA
Definition dirac_arith.h:67
#define CTX_MV_DATA
Definition dirac_arith.h:72
#define CTX_PMODE_REF1
Definition dirac_arith.h:68
@ CTX_ZERO_BLOCK
Definition dirac_arith.h:55
static int dirac_get_arith_bit(DiracArith *c, int ctx)
#define CTX_DC_F1
Definition dirac_arith.h:73
static int dirac_get_arith_int(DiracArith *c, int follow_ctx, int data_ctx)
#define CTX_DC_DATA
Definition dirac_arith.h:74
#define CTX_SB_F1
Definition dirac_arith.h:66
void ff_spatial_idwt_slice2(DWTContext *d, int y)
Definition dirac_dwt.c:69
int ff_spatial_idwt_init(DWTContext *d, DWTPlane *p, enum dwt_type type, int decomposition_count, int bit_depth)
Definition dirac_dwt.c:36
int ff_dirac_golomb_read_32bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
Definition dirac_vlc.c:1115
int ff_dirac_golomb_read_16bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
Definition dirac_vlc.c:1095
void(* dirac_biweight_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int log2_denom, int weightd, int weights, int h)
Definition diracdsp.h:28
void(* dirac_weight_func)(uint8_t *block, ptrdiff_t stride, int log2_denom, int weight, int h)
Definition diracdsp.h:27
const int32_t ff_dirac_qoffset_intra_tab[120]
Definition diractab.c:53
const int ff_dirac_qoffset_inter_tab[122]
Definition diractab.c:72
const int32_t ff_dirac_qscale_tab[116]
Definition diractab.c:34
const uint8_t ff_dirac_default_qmat[7][4][4]
Definition diractab.c:24
#define DIRAC_MAX_QUANT_INDEX
Definition diractab.h:41
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
int ret
Definition ffplay.c:391
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition get_bits.h:424
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 int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static const uint8_t * align_get_bits(GetBitContext *s)
Definition get_bits.h:560
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition get_bits.h:517
exp golomb vlc stuff
static int dirac_get_se_golomb(GetBitContext *gb)
Definition golomb.h:359
static unsigned get_interleaved_ue_golomb(GetBitContext *gb)
Definition golomb.h:143
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#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
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
@ AV_CODEC_ID_DIRAC
Definition codec_id.h:166
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#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:694
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:281
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:318
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
for(k=2;k<=8;++k)
if(svq3)
#define b
Definition input.c:43
#define av_log2
Definition intmath.h:84
#define AV_WN32(p, v)
#define AV_RB32(p)
#define AV_WN16(p, v)
unsigned offset
Definition libaomenc.c:763
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh, const uint8_t *buf, size_t buf_size, void *log_ctx)
Parse a Dirac sequence header.
Definition dirac.c:404
static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
Definition diracdec.c:918
#define DATA_UNIT_HEADER_SIZE
Dirac Specification -> 9.6 Parse Info Header Syntax.
Definition diracdec.c:2120
static av_cold void dirac_decode_flush(AVCodecContext *avctx)
Definition diracdec.c:416
#define CALC_PADDING(size, depth)
Definition diracdec.c:71
static void pred_block_dc(DiracBlock *block, int stride, int x, int y)
Definition diracdec.c:1361
static int dirac_unpack_block_motion_data(DiracContext *s)
Dirac Specification ->
Definition diracdec.c:1505
static int subband_coeffs(const DiracContext *s, int x, int y, int p, SliceCoeffs c[MAX_DWT_LEVELS])
Definition diracdec.c:823
#define CHECKEDREAD(dst, cond, errmsg)
#define MAX_DELAY
Definition diracdec.c:53
static void init_planes(DiracContext *s)
Definition diracdec.c:1053
#define MAX_REFERENCE_FRAMES
The spec limits this to 3 for frame coding, but in practice can be as high as 6.
Definition diracdec.c:52
static int decode_component(DiracContext *s, int comp)
Dirac Specification -> [DIRAC_STD] 13.4.1 core_transform_data()
Definition diracdec.c:659
static int dirac_unpack_prediction_parameters(DiracContext *s)
Unpack the motion compensation parameters Dirac Specification -> 11.2 Picture prediction data.
Definition diracdec.c:1107
static int dirac_decode_picture_header(DiracContext *s)
Dirac Specification -> 11.1.1 Picture Header.
Definition diracdec.c:2001
static const uint8_t epel_weights[4][4][4]
Definition diracdec.c:1623
#define ROLLOFF(i)
static void decode_subband(const DiracContext *s, GetBitContext *gb, int quant, int slice_x, int slice_y, int bits_end, const SubBand *b1, const SubBand *b2)
Definition diracdec.c:725
static int decode_subband_arith(AVCodecContext *avctx, void *b)
Definition diracdec.c:642
static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
Definition diracdec.c:648
static int alloc_sequence_buffers(DiracContext *s)
Definition diracdec.c:287
static DiracFrame * remove_frame(DiracFrame *framelist[], unsigned picnum)
Definition diracdec.c:258
static av_cold void free_sequence_buffers(DiracContext *s)
Definition diracdec.c:354
#define MAX_FRAMES
Definition diracdec.c:54
static av_cold int dirac_decode_init(AVCodecContext *avctx)
Definition diracdec.c:388
static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int top, int bottom)
Definition diracdec.c:1591
static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock *block, int stride, int x, int y)
Definition diracdec.c:1446
#define DIRAC_REF_MASK_REF2
Definition diracdec.c:62
#define DIRAC_REF_MASK_GLOBAL
Definition diracdec.c:63
#define EDGE_WIDTH
Definition diracdec.c:47
static int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask)
Definition diracdec.c:1345
static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
Dirac Specification -> 13.5.2 Slices.
Definition diracdec.c:777
static void add_dc(uint16_t *dst, int dc, int stride, uint8_t *obmc_weight, int xblen, int yblen)
Definition diracdec.c:1745
static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height)
Definition diracdec.c:1833
static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int wy)
Definition diracdec.c:1577
static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size)
Definition diracdec.c:2124
static int dirac_decode_frame_internal(DiracContext *s)
Dirac Specification -> 13.0 Transform data syntax.
Definition diracdec.c:1874
static int alloc_buffers(DiracContext *s, int stride)
Definition diracdec.c:325
static av_always_inline int decode_subband_internal(const DiracContext *s, SubBand *b, int is_arith)
Dirac Specification -> 13.4.2 Non-skipped subbands.
Definition diracdec.c:599
#define PARSE_VALUES(type, x, gb, ebits, buf1, buf2)
Definition diracdec.c:713
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
Definition diracdec.c:1394
static int divide3(int x)
Definition diracdec.c:253
static void block_mc(DiracContext *s, DiracBlock *block, uint16_t *mctmp, uint8_t *obmc_weight, int plane, int dstx, int dsty)
Definition diracdec.c:1761
static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
Definition diracdec.c:2089
#define DIVRNDUP(a, b)
Definition diracdec.c:74
static int codeblock(const DiracContext *s, SubBand *b, GetBitContext *gb, DiracArith *c, int left, int right, int top, int bottom, int blockcnt_one, int is_arith)
Decode the coeffs in the rectangle defined by left, right, top, bottom [DIRAC_STD] 13....
Definition diracdec.c:489
static int decode_lowdelay(DiracContext *s)
Dirac Specification -> 13.5.1 low_delay_transform_data()
Definition diracdec.c:933
static void propagate_block_data(DiracBlock *block, int stride, int size)
Copies the current block to the other blocks covered by the current superblock split mode.
Definition diracdec.c:1486
static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5], int x, int y, int ref, int plane)
For block x,y, determine which of the hpel planes to do bilinear interpolation from and set src[] to ...
Definition diracdec.c:1650
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output.
Definition diracdec.c:69
static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty)
Definition diracdec.c:1797
static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame)
Definition diracdec.c:276
static void init_obmc_weights(DiracContext *s, Plane *p, int by)
Definition diracdec.c:1610
#define UNPACK_ARITH(n, type)
Definition diracdec.c:452
static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref)
Definition diracdec.c:1430
#define INTRA_DC_PRED(n, type)
Dirac Specification -> 13.3 intra_dc_prediction(band)
Definition diracdec.c:571
static int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y)
Definition diracdec.c:1331
static int decode_hq_slice(const DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
VC-2 Specification -> 13.5.3 hq_slice(sx,sy)
Definition diracdec.c:844
static int dirac_unpack_idwt_params(DiracContext *s)
Dirac Specification -> 11.3 Wavelet transform data.
Definition diracdec.c:1235
static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *pkt)
Definition diracdec.c:2271
dirac_subband
Definition diracdec.c:244
@ subband_hl
Definition diracdec.c:246
@ subband_ll
Definition diracdec.c:245
@ subband_hh
Definition diracdec.c:248
@ subband_nb
Definition diracdec.c:249
@ subband_lh
Definition diracdec.c:247
static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen)
Definition diracdec.c:1813
static int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset)
Definition diracdec.c:441
#define DIRAC_REF_MASK_REF1
DiracBlock->ref flags, if set then the block does MC from the given ref.
Definition diracdec.c:61
static AVOnce dirac_arith_init
Definition diracdec.c:386
#define MAX_BLOCKSIZE
Definition diracdec.c:56
static int get_buffer_with_edge(AVCodecContext *avctx, AVFrame *f, int flags)
Definition diracdec.c:1971
static av_cold int dirac_decode_end(AVCodecContext *avctx)
Definition diracdec.c:424
av_cold void ff_diracdsp_init(DiracDSPContext *c)
Definition diracdsp.c:226
const char * arg
Definition jacosubdec.c:66
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition videodsp.c:39
#define av_always_inline
Definition attributes.h:72
#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
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMAX3(a, b, c)
Definition macros.h:48
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
#define mid_pred
Definition mathops.h:115
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define EDGE_BOTTOM
#define EDGE_TOP
#define av_malloc(s)
Definition ops_static.c:52
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition pixdesc.c:3512
const h264_weight_func weight
static const float pred[4]
Definition siprdata.h:259
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition avcodec.h:1797
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:685
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
AVRational framerate
Definition avcodec.h:563
int level
Encoding level descriptor.
Definition avcodec.h:1656
int profile
profile
Definition avcodec.h:1646
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
Definition avcodec.h:1619
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1589
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition avcodec.h:1638
void * priv_data
Definition avcodec.h:470
DiracVersionInfo version
Definition dirac.h:116
enum AVColorPrimaries color_primaries
Definition dirac.h:112
unsigned height
Definition dirac.h:87
enum AVColorRange color_range
Definition dirac.h:111
AVRational sample_aspect_ratio
Definition dirac.h:108
unsigned width
Definition dirac.h:86
enum AVColorSpace colorspace
Definition dirac.h:114
enum AVColorTransferCharacteristic color_trc
Definition dirac.h:113
enum AVPixelFormat pix_fmt
Definition dirac.h:110
AVRational framerate
Definition dirac.h:107
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition frame.h:723
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:524
enum AVPictureType pict_type
Picture type of the frame.
Definition frame.h:571
This structure stores compressed data.
Definition packet.h:587
Rational number (pair of numerator and denominator).
Definition rational.h:58
int16_t dc[3]
Definition diracdec.c:88
uint8_t ref
Definition diracdec.c:90
int16_t mv[2][2]
Definition diracdec.c:87
AVRational bytes
Definition diracdec.c:191
AVCodecContext * avctx
Definition diracdec.c:138
int buffer_stride
Definition diracdec.c:226
MpegvideoEncDSPContext mpvencdsp
Definition diracdec.c:139
unsigned width
Definition diracdec.c:186
unsigned wavelet_depth
Definition diracdec.c:165
unsigned prefix_bytes
Definition diracdec.c:196
struct DiracContext::@147166022327170112176317016052126250043074320045 highquality
DiracFrame * delay_frames[MAX_DELAY+1]
Definition diracdec.c:240
DiracFrame * ref_pics[2]
Definition diracdec.c:237
dirac_biweight_func biweight_func
Definition diracdec.c:234
int64_t frame_number
Definition diracdec.c:146
unsigned codeblock_mode
Definition diracdec.c:173
uint8_t * sbsplit
Definition diracdec.c:218
int threads_num_buf
Definition diracdec.c:179
int slice_params_num_buf
Definition diracdec.c:183
int zrs[2][2]
Definition diracdec.c:202
int seen_sequence_header
Definition diracdec.c:145
uint8_t obmc_weight[3][MAX_BLOCKSIZE *MAX_BLOCKSIZE]
Definition diracdec.c:228
unsigned perspective_exp
Definition diracdec.c:205
uint8_t * edge_emu_buffer[4]
Definition diracdec.c:221
uint8_t quant[MAX_DWT_LEVELS][4]
Definition diracdec.c:192
unsigned num_x
Definition diracdec.c:175
DiracBlock * blmotion
Definition diracdec.c:219
GetBitContext gb
Definition diracdec.c:143
uint16_t * mctmp
Definition diracdec.c:224
uint8_t * mcscratch
Definition diracdec.c:225
unsigned height
Definition diracdec.c:187
DiracFrame * ref_frames[MAX_REFERENCE_FRAMES+1]
Definition diracdec.c:239
uint8_t * edge_emu_buffer_base
Definition diracdec.c:222
int dc_prediction
Definition diracdec.c:160
unsigned weight_log2denom
Definition diracdec.c:211
DiracFrame * current_picture
Definition diracdec.c:236
int perspective[2]
Definition diracdec.c:203
dirac_weight_func weight_func
Definition diracdec.c:233
DiracSlice * slice_params_buf
Definition diracdec.c:182
uint8_t * thread_buf
Definition diracdec.c:178
DiracDSPContext diracdsp
Definition diracdec.c:141
int pan_tilt[2]
Definition diracdec.c:201
unsigned old_delta_quant
schroedinger older than 1.0.8 doesn't store quant delta if only one codebook exists in a band
Definition diracdec.c:172
DiracVersionInfo version
Definition diracdec.c:142
VideoDSPContext vdsp
Definition diracdec.c:140
unsigned zrs_exp
Definition diracdec.c:204
uint8_t mv_precision
Definition diracdec.c:209
int core_syntax
Definition diracdec.c:156
uint64_t size_scaler
Definition diracdec.c:197
int globalmc_flag
Definition diracdec.c:161
int thread_buf_size
Definition diracdec.c:180
int chroma_y_shift
Definition diracdec.c:149
AVDiracSeqHeader seq
Definition diracdec.c:144
DiracFrame all_frames[MAX_FRAMES]
Definition diracdec.c:241
void(* avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h)
Definition diracdec.c:231
int chroma_x_shift
Definition diracdec.c:148
void(* put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h)
Definition diracdec.c:230
void(* add_obmc)(uint16_t *dst, const uint8_t *src, ptrdiff_t stride, const uint8_t *obmc_weight, int yblen)
Definition diracdec.c:232
Plane plane[3]
Definition diracdec.c:147
unsigned num_y
Definition diracdec.c:176
int16_t weight[2]
Definition diracdec.c:210
unsigned wavelet_idx
Definition diracdec.c:166
struct DiracContext::@326161170100263300254156105370361300176302314315 globalmc[2]
struct DiracContext::@263155311377021006273053315211030157311361241365 lowdelay
unsigned picture_number
Definition diracdec.c:82
uint8_t * hpel[3][4]
Definition diracdec.c:79
AVFrame * avframe
Definition diracdec.c:77
uint8_t * hpel_base[3][4]
Definition diracdec.c:80
int interpolated[3]
Definition diracdec.c:78
int reference
Definition diracdec.c:81
int slice_x
Definition diracdec.c:132
int slice_y
Definition diracdec.c:133
GetBitContext gb
Definition diracdec.c:131
Definition cfhd.h:125
uint8_t yoffset
Definition diracdec.c:124
SubBand band[DWT_LEVELS_3D][4]
Definition cfhd.h:138
uint8_t yblen
Definition diracdec.c:118
ptrdiff_t stride
Definition cfhd.h:128
int width
Definition cfhd.h:126
DWTPlane idwt
Definition diracdec.c:110
uint8_t ybsep
Definition diracdec.c:121
int height
Definition cfhd.h:127
uint8_t xbsep
Definition diracdec.c:120
uint8_t xoffset
Definition diracdec.c:123
uint8_t xblen
Definition diracdec.c:117
unsigned length
Definition diracdec.c:105
int pshift
Definition diracdec.c:99
struct SubBand * parent
Definition diracdec.c:102
const uint8_t * coeff_data
Definition diracdec.c:106
int quant
Definition diracdec.c:100
int orientation
Definition diracdec.c:95
ptrdiff_t stride
Definition cfhd.h:117
int level
Definition diracdec.c:94
int width
Definition cfhd.h:119
uint8_t * ibuf
Definition diracdec.c:101
int height
Definition cfhd.h:121
Definition format.c:917
uint8_t level
Definition svq3.c:208
#define stride
#define av_malloc_array(a, b)
#define av_realloc_f(p, o, n)
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
int size
static double b1(void *priv, double x, double y)
Definition vf_xfade.c:2041
static double b2(void *priv, double x, double y)
Definition vf_xfade.c:2042
Core video DSP helper functions.
static const uint8_t quant[64]
Definition vmixdec.c:71
static double c[64]