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