FFmpeg
clearvideo.c
Go to the documentation of this file.
1 /*
2  * ClearVideo decoder
3  * Copyright (c) 2012-2018 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * ClearVideo decoder
25  */
26 
27 #include "avcodec.h"
28 #include "bytestream.h"
29 #include "get_bits.h"
30 #include "idctdsp.h"
31 #include "internal.h"
32 #include "mathops.h"
33 #include "clearvideodata.h"
34 
35 typedef struct LevelCodes {
36  uint16_t mv_esc;
37  uint16_t bias_esc;
41 } LevelCodes;
42 
43 typedef struct MV {
44  int16_t x, y;
45 } MV;
46 
47 static const MV zero_mv = { 0 };
48 
49 typedef struct MVInfo {
50  int mb_w;
51  int mb_h;
52  int mb_size;
53  int mb_stride;
54  int top;
55  MV *mv;
56 } MVInfo;
57 
58 typedef struct TileInfo {
59  uint16_t flags;
60  int16_t bias;
61  MV mv;
62  struct TileInfo *child[4];
63 } TileInfo;
64 
65 typedef struct CLVContext {
74  int tile_size;
77  LevelCodes ylev[4], ulev[3], vlev[3];
79  DECLARE_ALIGNED(16, int16_t, block)[64];
80  int top_dc[3], left_dc[4];
81 } CLVContext;
82 
83 static inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,
84  int ac_quant)
85 {
86  GetBitContext *gb = &ctx->gb;
87  int idx = 1, last = 0, val, skip;
88 
89  memset(blk, 0, sizeof(*blk) * 64);
90  blk[0] = get_vlc2(gb, ctx->dc_vlc.table, 9, 3);
91  if (blk[0] < 0)
92  return AVERROR_INVALIDDATA;
93  blk[0] -= 63;
94 
95  if (!has_ac)
96  return 0;
97 
98  while (idx < 64 && !last) {
99  val = get_vlc2(gb, ctx->ac_vlc.table, 9, 2);
100  if (val < 0)
101  return AVERROR_INVALIDDATA;
102  if (val != 0x1BFF) {
103  last = val >> 12;
104  skip = (val >> 4) & 0xFF;
105  val &= 0xF;
106  if (get_bits1(gb))
107  val = -val;
108  } else {
109  last = get_bits1(gb);
110  skip = get_bits(gb, 6);
111  val = get_sbits(gb, 8);
112  }
113  if (val) {
114  int aval = FFABS(val), sign = val < 0;
115  val = ac_quant * (2 * aval + 1);
116  if (!(ac_quant & 1))
117  val--;
118  if (sign)
119  val = -val;
120  }
121  idx += skip;
122  if (idx >= 64)
123  return AVERROR_INVALIDDATA;
124  blk[ff_zigzag_direct[idx++]] = val;
125  }
126 
127  return (idx <= 64 && last) ? 0 : -1;
128 }
129 
130 #define DCT_TEMPLATE(blk, step, bias, shift, dshift, OP) \
131  const int t0 = OP(2841 * blk[1 * step] + 565 * blk[7 * step]); \
132  const int t1 = OP( 565 * blk[1 * step] - 2841 * blk[7 * step]); \
133  const int t2 = OP(1609 * blk[5 * step] + 2408 * blk[3 * step]); \
134  const int t3 = OP(2408 * blk[5 * step] - 1609 * blk[3 * step]); \
135  const int t4 = OP(1108 * blk[2 * step] - 2676 * blk[6 * step]); \
136  const int t5 = OP(2676 * blk[2 * step] + 1108 * blk[6 * step]); \
137  const int t6 = ((blk[0 * step] + blk[4 * step]) * (1 << dshift)) + bias; \
138  const int t7 = ((blk[0 * step] - blk[4 * step]) * (1 << dshift)) + bias; \
139  const int t8 = t0 + t2; \
140  const int t9 = t0 - t2; \
141  const int tA = (int)(181U * (t9 + (t1 - t3)) + 0x80) >> 8; \
142  const int tB = (int)(181U * (t9 - (t1 - t3)) + 0x80) >> 8; \
143  const int tC = t1 + t3; \
144  \
145  blk[0 * step] = (t6 + t5 + t8) >> shift; \
146  blk[1 * step] = (t7 + t4 + tA) >> shift; \
147  blk[2 * step] = (t7 - t4 + tB) >> shift; \
148  blk[3 * step] = (t6 - t5 + tC) >> shift; \
149  blk[4 * step] = (t6 - t5 - tC) >> shift; \
150  blk[5 * step] = (t7 - t4 - tB) >> shift; \
151  blk[6 * step] = (t7 + t4 - tA) >> shift; \
152  blk[7 * step] = (t6 + t5 - t8) >> shift; \
153 
154 #define ROP(x) x
155 #define COP(x) (((x) + 4) >> 3)
156 
157 static void clv_dct(int16_t *block)
158 {
159  int i;
160  int16_t *ptr;
161 
162  ptr = block;
163  for (i = 0; i < 8; i++) {
164  DCT_TEMPLATE(ptr, 1, 0x80, 8, 11, ROP);
165  ptr += 8;
166  }
167 
168  ptr = block;
169  for (i = 0; i < 8; i++) {
170  DCT_TEMPLATE(ptr, 8, 0x2000, 14, 8, COP);
171  ptr++;
172  }
173 }
174 
175 static int decode_mb(CLVContext *c, int x, int y)
176 {
177  int i, has_ac[6], off;
178 
179  for (i = 0; i < 6; i++)
180  has_ac[i] = get_bits1(&c->gb);
181 
182  off = x * 16 + y * 16 * c->pic->linesize[0];
183  for (i = 0; i < 4; i++) {
184  if (decode_block(c, c->block, has_ac[i], c->ac_quant) < 0)
185  return AVERROR_INVALIDDATA;
186  if (!x && !(i & 1)) {
187  c->block[0] += c->top_dc[0];
188  c->top_dc[0] = c->block[0];
189  } else {
190  c->block[0] += c->left_dc[(i & 2) >> 1];
191  }
192  c->left_dc[(i & 2) >> 1] = c->block[0];
193  c->block[0] *= c->luma_dc_quant;
194  clv_dct(c->block);
195  if (i == 2)
196  off += c->pic->linesize[0] * 8;
197  c->idsp.put_pixels_clamped(c->block,
198  c->pic->data[0] + off + (i & 1) * 8,
199  c->pic->linesize[0]);
200  }
201 
202  off = x * 8 + y * 8 * c->pic->linesize[1];
203  for (i = 1; i < 3; i++) {
204  if (decode_block(c, c->block, has_ac[i + 3], c->ac_quant) < 0)
205  return AVERROR_INVALIDDATA;
206  if (!x) {
207  c->block[0] += c->top_dc[i];
208  c->top_dc[i] = c->block[0];
209  } else {
210  c->block[0] += c->left_dc[i + 1];
211  }
212  c->left_dc[i + 1] = c->block[0];
213  c->block[0] *= c->chroma_dc_quant;
214  clv_dct(c->block);
215  c->idsp.put_pixels_clamped(c->block, c->pic->data[i] + off,
216  c->pic->linesize[i]);
217  }
218 
219  return 0;
220 }
221 
222 static int copy_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src,
223  int plane, int x, int y, int dx, int dy, int size)
224 {
225  int shift = plane > 0;
226  int sx = x + dx;
227  int sy = y + dy;
228  int sstride, dstride, soff, doff;
229  uint8_t *sbuf, *dbuf;
230  int i;
231 
232  if (x < 0 || sx < 0 || y < 0 || sy < 0 ||
233  x + size > avctx->coded_width >> shift ||
234  y + size > avctx->coded_height >> shift ||
235  sx + size > avctx->coded_width >> shift ||
236  sy + size > avctx->coded_height >> shift)
237  return AVERROR_INVALIDDATA;
238 
239  sstride = src->linesize[plane];
240  dstride = dst->linesize[plane];
241  soff = sx + sy * sstride;
242  sbuf = src->data[plane];
243  doff = x + y * dstride;
244  dbuf = dst->data[plane];
245 
246  for (i = 0; i < size; i++) {
247  uint8_t *dptr = &dbuf[doff];
248  uint8_t *sptr = &sbuf[soff];
249 
250  memcpy(dptr, sptr, size);
251  doff += dstride;
252  soff += sstride;
253  }
254 
255  return 0;
256 }
257 
258 static int copyadd_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src,
259  int plane, int x, int y, int dx, int dy, int size, int bias)
260 {
261  int shift = plane > 0;
262  int sx = x + dx;
263  int sy = y + dy;
264  int sstride = src->linesize[plane];
265  int dstride = dst->linesize[plane];
266  int soff = sx + sy * sstride;
267  uint8_t *sbuf = src->data[plane];
268  int doff = x + y * dstride;
269  uint8_t *dbuf = dst->data[plane];
270  int i, j;
271 
272  if (x < 0 || sx < 0 || y < 0 || sy < 0 ||
273  x + size > avctx->coded_width >> shift ||
274  y + size > avctx->coded_height >> shift ||
275  sx + size > avctx->coded_width >> shift ||
276  sy + size > avctx->coded_height >> shift)
277  return AVERROR_INVALIDDATA;
278 
279  for (j = 0; j < size; j++) {
280  uint8_t *dptr = &dbuf[doff];
281  uint8_t *sptr = &sbuf[soff];
282 
283  for (i = 0; i < size; i++) {
284  int val = sptr[i] + bias;
285 
286  dptr[i] = av_clip_uint8(val);
287  }
288 
289  doff += dstride;
290  soff += sstride;
291  }
292 
293  return 0;
294 }
295 
296 static MV mvi_predict(MVInfo *mvi, int mb_x, int mb_y, MV diff)
297 {
298  MV res, pred_mv;
299  int left_mv, right_mv, top_mv, bot_mv;
300 
301  if (mvi->top) {
302  if (mb_x > 0) {
303  pred_mv = mvi->mv[mvi->mb_stride + mb_x - 1];
304  } else {
305  pred_mv = zero_mv;
306  }
307  } else if ((mb_x == 0) || (mb_x == mvi->mb_w - 1)) {
308  pred_mv = mvi->mv[mb_x];
309  } else {
310  MV A = mvi->mv[mvi->mb_stride + mb_x - 1];
311  MV B = mvi->mv[ mb_x ];
312  MV C = mvi->mv[ mb_x + 1];
313  pred_mv.x = mid_pred(A.x, B.x, C.x);
314  pred_mv.y = mid_pred(A.y, B.y, C.y);
315  }
316 
317  res = pred_mv;
318 
319  left_mv = -((mb_x * mvi->mb_size));
320  right_mv = ((mvi->mb_w - mb_x - 1) * mvi->mb_size);
321  if (res.x < left_mv) {
322  res.x = left_mv;
323  }
324  if (res.x > right_mv) {
325  res.x = right_mv;
326  }
327  top_mv = -((mb_y * mvi->mb_size));
328  bot_mv = ((mvi->mb_h - mb_y - 1) * mvi->mb_size);
329  if (res.y < top_mv) {
330  res.y = top_mv;
331  }
332  if (res.y > bot_mv) {
333  res.y = bot_mv;
334  }
335 
336  mvi->mv[mvi->mb_stride + mb_x].x = res.x + diff.x;
337  mvi->mv[mvi->mb_stride + mb_x].y = res.y + diff.y;
338 
339  return res;
340 }
341 
342 static void mvi_reset(MVInfo *mvi, int mb_w, int mb_h, int mb_size)
343 {
344  mvi->top = 1;
345  mvi->mb_w = mb_w;
346  mvi->mb_h = mb_h;
347  mvi->mb_size = mb_size;
348  mvi->mb_stride = mb_w;
349  memset(mvi->mv, 0, sizeof(MV) * mvi->mb_stride * 2);
350 }
351 
352 static void mvi_update_row(MVInfo *mvi)
353 {
354  int i;
355 
356  mvi->top = 0;
357  for (i = 0 ; i < mvi->mb_stride; i++) {
358  mvi->mv[i] = mvi->mv[mvi->mb_stride + i];
359  }
360 }
361 
363 {
364  TileInfo *ti;
365  int i, flags = 0;
366  int16_t bias = 0;
367  MV mv = { 0 };
368 
369  if (lc[level].flags_cb.table) {
370  flags = get_vlc2(gb, lc[level].flags_cb.table, lc[level].flags_cb.bits, 2);
371  }
372 
373  if (lc[level].mv_cb.table) {
374  uint16_t mv_code = get_vlc2(gb, lc[level].mv_cb.table, lc[level].mv_cb.bits, 3);
375 
376  if (mv_code != lc[level].mv_esc) {
377  mv.x = (int8_t)(mv_code & 0xff);
378  mv.y = (int8_t)(mv_code >> 8);
379  } else {
380  mv.x = get_sbits(gb, 8);
381  mv.y = get_sbits(gb, 8);
382  }
383  }
384 
385  if (lc[level].bias_cb.table) {
386  uint16_t bias_val = get_vlc2(gb, lc[level].bias_cb.table, lc[level].bias_cb.bits, 2);
387 
388  if (bias_val != lc[level].bias_esc) {
389  bias = (int16_t)(bias_val);
390  } else {
391  bias = get_sbits(gb, 16);
392  }
393  }
394 
395  ti = av_calloc(1, sizeof(*ti));
396  if (!ti)
397  return NULL;
398 
399  ti->flags = flags;
400  ti->mv = mv;
401  ti->bias = bias;
402 
403  if (ti->flags) {
404  for (i = 0; i < 4; i++) {
405  if (ti->flags & (1 << i)) {
406  TileInfo *subti = decode_tile_info(gb, lc, level + 1);
407  ti->child[i] = subti;
408  }
409  }
410  }
411 
412  return ti;
413 }
414 
415 static int tile_do_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src,
416  int plane, int x, int y, int dx, int dy, int size, int bias)
417 {
418  int ret;
419 
420  if (!bias) {
421  ret = copy_block(avctx, dst, src, plane, x, y, dx, dy, size);
422  } else {
423  ret = copyadd_block(avctx, dst, src, plane, x, y, dx, dy, size, bias);
424  }
425 
426  return ret;
427 }
428 
429 static int restore_tree(AVCodecContext *avctx, AVFrame *dst, AVFrame *src,
430  int plane, int x, int y, int size,
431  TileInfo *tile, MV root_mv)
432 {
433  int ret;
434  MV mv;
435 
436  mv.x = root_mv.x + tile->mv.x;
437  mv.y = root_mv.y + tile->mv.y;
438 
439  if (!tile->flags) {
440  ret = tile_do_block(avctx, dst, src, plane, x, y, mv.x, mv.y, size, tile->bias);
441  } else {
442  int i, hsize = size >> 1;
443 
444  for (i = 0; i < 4; i++) {
445  int xoff = (i & 2) == 0 ? 0 : hsize;
446  int yoff = (i & 1) == 0 ? 0 : hsize;
447 
448  if (tile->child[i]) {
449  ret = restore_tree(avctx, dst, src, plane, x + xoff, y + yoff, hsize, tile->child[i], root_mv);
450  av_freep(&tile->child[i]);
451  } else {
452  ret = tile_do_block(avctx, dst, src, plane, x + xoff, y + yoff, mv.x, mv.y, hsize, tile->bias);
453  }
454  }
455  }
456 
457  return ret;
458 }
459 
460 static void extend_edges(AVFrame *buf, int tile_size)
461 {
462  int comp, i, j;
463 
464  for (comp = 0; comp < 3; comp++) {
465  int shift = comp > 0;
466  int w = buf->width >> shift;
467  int h = buf->height >> shift;
468  int size = comp == 0 ? tile_size : tile_size >> 1;
469  int stride = buf->linesize[comp];
470  uint8_t *framebuf = buf->data[comp];
471 
472  int right = size - (w & (size - 1));
473  int bottom = size - (h & (size - 1));
474 
475  if ((right == size) && (bottom == size)) {
476  return;
477  }
478  if (right != size) {
479  int off = w;
480  for (j = 0; j < h; j++) {
481  for (i = 0; i < right; i++) {
482  framebuf[off + i] = 0x80;
483  }
484  off += stride;
485  }
486  }
487  if (bottom != size) {
488  int off = h * stride;
489  for (j = 0; j < bottom; j++) {
490  for (i = 0; i < stride; i++) {
491  framebuf[off + i] = 0x80;
492  }
493  off += stride;
494  }
495  }
496  }
497 }
498 
499 static int clv_decode_frame(AVCodecContext *avctx, void *data,
500  int *got_frame, AVPacket *avpkt)
501 {
502  const uint8_t *buf = avpkt->data;
503  int buf_size = avpkt->size;
504  CLVContext *c = avctx->priv_data;
505  GetByteContext gb;
506  uint32_t frame_type;
507  int i, j, ret;
508  int mb_ret = 0;
509 
510  bytestream2_init(&gb, buf, buf_size);
511  if (avctx->codec_tag == MKTAG('C', 'L', 'V', '1')) {
512  int skip = bytestream2_get_byte(&gb);
513  bytestream2_skip(&gb, (skip + 1) * 8);
514  }
515 
516  frame_type = bytestream2_get_byte(&gb);
517 
518  if ((frame_type & 0x7f) == 0x30) {
519  *got_frame = 0;
520  return buf_size;
521  } else if (frame_type & 0x2) {
522  if (buf_size < c->mb_width * c->mb_height) {
523  av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
524  return AVERROR_INVALIDDATA;
525  }
526 
527  if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
528  return ret;
529 
530  c->pic->key_frame = 1;
531  c->pic->pict_type = AV_PICTURE_TYPE_I;
532 
533  bytestream2_get_be32(&gb); // frame size;
534  c->ac_quant = bytestream2_get_byte(&gb);
535  c->luma_dc_quant = 32;
536  c->chroma_dc_quant = 32;
537 
538  if ((ret = init_get_bits8(&c->gb, buf + bytestream2_tell(&gb),
539  buf_size - bytestream2_tell(&gb))) < 0)
540  return ret;
541 
542  for (i = 0; i < 3; i++)
543  c->top_dc[i] = 32;
544  for (i = 0; i < 4; i++)
545  c->left_dc[i] = 32;
546 
547  for (j = 0; j < c->mb_height; j++) {
548  for (i = 0; i < c->mb_width; i++) {
549  ret = decode_mb(c, i, j);
550  if (ret < 0)
551  mb_ret = ret;
552  }
553  }
554  extend_edges(c->pic, c->tile_size);
555  } else {
556  int plane;
557 
558  if (c->pmb_width * c->pmb_height > 8LL*(buf_size - bytestream2_tell(&gb)))
559  return AVERROR_INVALIDDATA;
560 
561  if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
562  return ret;
563 
564  ret = av_frame_copy(c->pic, c->prev);
565  if (ret < 0)
566  return ret;
567 
568  if ((ret = init_get_bits8(&c->gb, buf + bytestream2_tell(&gb),
569  buf_size - bytestream2_tell(&gb))) < 0)
570  return ret;
571 
572  mvi_reset(&c->mvi, c->pmb_width, c->pmb_height, 1 << c->tile_shift);
573 
574  for (j = 0; j < c->pmb_height; j++) {
575  for (i = 0; i < c->pmb_width; i++) {
576  if (get_bits_left(&c->gb) <= 0)
577  return AVERROR_INVALIDDATA;
578  if (get_bits1(&c->gb)) {
579  MV mv = mvi_predict(&c->mvi, i, j, zero_mv);
580 
581  for (plane = 0; plane < 3; plane++) {
582  int16_t x = plane == 0 ? i << c->tile_shift : i << (c->tile_shift - 1);
583  int16_t y = plane == 0 ? j << c->tile_shift : j << (c->tile_shift - 1);
584  int16_t size = plane == 0 ? 1 << c->tile_shift : 1 << (c->tile_shift - 1);
585  int16_t mx = plane == 0 ? mv.x : mv.x / 2;
586  int16_t my = plane == 0 ? mv.y : mv.y / 2;
587 
588  ret = copy_block(avctx, c->pic, c->prev, plane, x, y, mx, my, size);
589  if (ret < 0)
590  mb_ret = ret;
591  }
592  } else {
593  int x = i << c->tile_shift;
594  int y = j << c->tile_shift;
595  int size = 1 << c->tile_shift;
596  TileInfo *tile;
597  MV mv, cmv;
598 
599  tile = decode_tile_info(&c->gb, c->ylev, 0);
600  if (!tile)
601  return AVERROR(ENOMEM);
602  mv = mvi_predict(&c->mvi, i, j, tile->mv);
603  ret = restore_tree(avctx, c->pic, c->prev, 0, x, y, size, tile, mv);
604  if (ret < 0)
605  mb_ret = ret;
606  x = i << (c->tile_shift - 1);
607  y = j << (c->tile_shift - 1);
608  size = 1 << (c->tile_shift - 1);
609  cmv.x = mv.x + tile->mv.x;
610  cmv.y = mv.y + tile->mv.y;
611  cmv.x /= 2;
612  cmv.y /= 2;
613  av_freep(&tile);
614  tile = decode_tile_info(&c->gb, c->ulev, 0);
615  if (!tile)
616  return AVERROR(ENOMEM);
617  ret = restore_tree(avctx, c->pic, c->prev, 1, x, y, size, tile, cmv);
618  if (ret < 0)
619  mb_ret = ret;
620  av_freep(&tile);
621  tile = decode_tile_info(&c->gb, c->vlev, 0);
622  if (!tile)
623  return AVERROR(ENOMEM);
624  ret = restore_tree(avctx, c->pic, c->prev, 2, x, y, size, tile, cmv);
625  if (ret < 0)
626  mb_ret = ret;
627  av_freep(&tile);
628  }
629  }
630  mvi_update_row(&c->mvi);
631  }
632  extend_edges(c->pic, c->tile_size);
633 
634  c->pic->key_frame = 0;
635  c->pic->pict_type = AV_PICTURE_TYPE_P;
636  }
637 
638  if ((ret = av_frame_ref(data, c->pic)) < 0)
639  return ret;
640 
641  FFSWAP(AVFrame *, c->pic, c->prev);
642 
643  *got_frame = 1;
644 
645  if (get_bits_left(&c->gb) < 0)
646  av_log(c->avctx, AV_LOG_WARNING, "overread %d\n", -get_bits_left(&c->gb));
647 
648  return mb_ret < 0 ? mb_ret : buf_size;
649 }
650 
652 {
653  CLVContext *const c = avctx->priv_data;
654  int ret, w, h;
655 
656  if (avctx->extradata_size == 110) {
657  c->tile_size = AV_RL32(&avctx->extradata[94]);
658  } else if (avctx->extradata_size == 150) {
659  c->tile_size = AV_RB32(&avctx->extradata[134]);
660  } else if (!avctx->extradata_size) {
661  c->tile_size = 16;
662  } else {
663  av_log(avctx, AV_LOG_ERROR, "Unsupported extradata size: %d\n", avctx->extradata_size);
664  return AVERROR_INVALIDDATA;
665  }
666 
667  c->tile_shift = av_log2(c->tile_size);
668  if (1U << c->tile_shift != c->tile_size || c->tile_shift < 1 || c->tile_shift > 30) {
669  av_log(avctx, AV_LOG_ERROR, "Tile size: %d, is not power of 2 > 1 and < 2^31\n", c->tile_size);
670  return AVERROR_INVALIDDATA;
671  }
672 
673  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
674  w = avctx->width;
675  h = avctx->height;
676  ret = ff_set_dimensions(avctx, FFALIGN(w, 1 << c->tile_shift), FFALIGN(h, 1 << c->tile_shift));
677  if (ret < 0)
678  return ret;
679  avctx->width = w;
680  avctx->height = h;
681 
682  c->avctx = avctx;
683  c->mb_width = FFALIGN(avctx->width, 16) >> 4;
684  c->mb_height = FFALIGN(avctx->height, 16) >> 4;
685  c->pmb_width = (w + c->tile_size - 1) >> c->tile_shift;
686  c->pmb_height = (h + c->tile_size - 1) >> c->tile_shift;
687  c->pic = av_frame_alloc();
688  c->prev = av_frame_alloc();
689  c->mvi.mv = av_calloc(c->pmb_width * 2, sizeof(*c->mvi.mv));
690  if (!c->pic || !c->prev || !c->mvi.mv)
691  return AVERROR(ENOMEM);
692 
693  ff_idctdsp_init(&c->idsp, avctx);
694  ret = init_vlc(&c->dc_vlc, 9, NUM_DC_CODES,
695  clv_dc_bits, 1, 1,
696  clv_dc_codes, 1, 1, 0);
697  if (ret) {
698  av_log(avctx, AV_LOG_ERROR, "Error initialising DC VLC\n");
699  return ret;
700  }
701  ret = ff_init_vlc_sparse(&c->ac_vlc, 9, NUM_AC_CODES,
702  clv_ac_bits, 1, 1,
703  clv_ac_codes, 1, 1,
704  clv_ac_syms, 2, 2, 0);
705  if (ret) {
706  av_log(avctx, AV_LOG_ERROR, "Error initialising AC VLC\n");
707  return ret;
708  }
709 
710  ret = init_vlc(&c->ylev[0].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsy_0_bits),
711  clv_flagsy_0_bits, 1, 1,
712  clv_flagsy_0_codes, 2, 2, 0);
713  if (ret)
714  return ret;
715 
716  ret = init_vlc(&c->ylev[1].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsy_1_bits),
717  clv_flagsy_1_bits, 1, 1,
718  clv_flagsy_1_codes, 2, 2, 0);
719  if (ret)
720  return ret;
721 
722  ret = init_vlc(&c->ylev[2].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsy_2_bits),
723  clv_flagsy_2_bits, 1, 1,
724  clv_flagsy_2_codes, 2, 2, 0);
725  if (ret)
726  return ret;
727 
728  ret = init_vlc(&c->ulev[0].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsu_0_bits),
729  clv_flagsu_0_bits, 1, 1,
730  clv_flagsu_0_codes, 2, 2, 0);
731  if (ret)
732  return ret;
733 
734  ret = init_vlc(&c->ulev[1].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsu_1_bits),
735  clv_flagsu_1_bits, 1, 1,
736  clv_flagsu_1_codes, 2, 2, 0);
737  if (ret)
738  return ret;
739 
740  ret = init_vlc(&c->vlev[0].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsv_0_bits),
741  clv_flagsv_0_bits, 1, 1,
742  clv_flagsv_0_codes, 2, 2, 0);
743  if (ret)
744  return ret;
745 
746  ret = init_vlc(&c->vlev[1].flags_cb, 9, FF_ARRAY_ELEMS(clv_flagsv_1_bits),
747  clv_flagsv_1_bits, 1, 1,
748  clv_flagsv_1_codes, 2, 2, 0);
749  if (ret)
750  return ret;
751 
752  ret = ff_init_vlc_sparse(&c->ylev[0].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvy_0_bits),
753  clv_mvy_0_bits, 1, 1,
754  clv_mvy_0_codes, 2, 2,
755  clv_mvy_0_syms, 2, 2, 0);
756  if (ret)
757  return ret;
758 
759  ret = ff_init_vlc_sparse(&c->ylev[1].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvy_1_bits),
760  clv_mvy_1_bits, 1, 1,
761  clv_mvy_1_codes, 2, 2,
762  clv_mvy_1_syms, 2, 2, 0);
763  if (ret)
764  return ret;
765 
766  ret = ff_init_vlc_sparse(&c->ylev[2].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvy_2_bits),
767  clv_mvy_2_bits, 1, 1,
768  clv_mvy_2_codes, 2, 2,
769  clv_mvy_2_syms, 2, 2, 0);
770  if (ret)
771  return ret;
772 
773  ret = ff_init_vlc_sparse(&c->ylev[3].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvy_3_bits),
774  clv_mvy_3_bits, 1, 1,
775  clv_mvy_3_codes, 2, 2,
776  clv_mvy_3_syms, 2, 2, 0);
777  if (ret)
778  return ret;
779 
780  ret = ff_init_vlc_sparse(&c->ulev[1].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvu_1_bits),
781  clv_mvu_1_bits, 1, 1,
782  clv_mvu_1_codes, 2, 2,
783  clv_mvu_1_syms, 2, 2, 0);
784  if (ret)
785  return ret;
786 
787  ret = ff_init_vlc_sparse(&c->ulev[2].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvu_2_bits),
788  clv_mvu_2_bits, 1, 1,
789  clv_mvu_2_codes, 2, 2,
790  clv_mvu_2_syms, 2, 2, 0);
791  if (ret)
792  return ret;
793 
794  ret = ff_init_vlc_sparse(&c->vlev[1].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvv_1_bits),
795  clv_mvv_1_bits, 1, 1,
796  clv_mvv_1_codes, 2, 2,
797  clv_mvv_1_syms, 2, 2, 0);
798  if (ret)
799  return ret;
800 
801  ret = ff_init_vlc_sparse(&c->vlev[2].mv_cb, 9, FF_ARRAY_ELEMS(clv_mvv_2_bits),
802  clv_mvv_2_bits, 1, 1,
803  clv_mvv_2_codes, 2, 2,
804  clv_mvv_2_syms, 2, 2, 0);
805  if (ret)
806  return ret;
807 
808  ret = ff_init_vlc_sparse(&c->ylev[1].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasy_1_bits),
809  clv_biasy_1_bits, 1, 1,
810  clv_biasy_1_codes, 2, 2,
811  clv_biasy_1_syms, 2, 2, 0);
812  if (ret)
813  return ret;
814 
815  ret = ff_init_vlc_sparse(&c->ylev[2].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasy_2_bits),
816  clv_biasy_2_bits, 1, 1,
817  clv_biasy_2_codes, 2, 2,
818  clv_biasy_2_syms, 2, 2, 0);
819  if (ret)
820  return ret;
821 
822  ret = ff_init_vlc_sparse(&c->ylev[3].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasy_3_bits),
823  clv_biasy_3_bits, 1, 1,
824  clv_biasy_3_codes, 2, 2,
825  clv_biasy_3_syms, 2, 2, 0);
826  if (ret)
827  return ret;
828 
829  ret = ff_init_vlc_sparse(&c->ulev[1].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasu_1_bits),
830  clv_biasu_1_bits, 1, 1,
831  clv_biasu_1_codes, 2, 2,
832  clv_biasu_1_syms, 2, 2, 0);
833  if (ret)
834  return ret;
835 
836  ret = ff_init_vlc_sparse(&c->ulev[2].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasu_2_bits),
837  clv_biasu_2_bits, 1, 1,
838  clv_biasu_2_codes, 2, 2,
839  clv_biasu_2_syms, 2, 2, 0);
840  if (ret)
841  return ret;
842 
843  ret = ff_init_vlc_sparse(&c->vlev[1].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasv_1_bits),
844  clv_biasv_1_bits, 1, 1,
845  clv_biasv_1_codes, 2, 2,
846  clv_biasv_1_syms, 2, 2, 0);
847  if (ret)
848  return ret;
849 
850  ret = ff_init_vlc_sparse(&c->vlev[2].bias_cb, 9, FF_ARRAY_ELEMS(clv_biasv_2_bits),
851  clv_biasv_2_bits, 1, 1,
852  clv_biasv_2_codes, 2, 2,
853  clv_biasv_2_syms, 2, 2, 0);
854  if (ret)
855  return ret;
856 
857  c->ylev[0].mv_esc = 0x0909;
858  c->ylev[1].mv_esc = 0x0A0A;
859  c->ylev[2].mv_esc = 0x1010;
860  c->ylev[3].mv_esc = 0x1313;
861  c->ulev[1].mv_esc = 0x0808;
862  c->ulev[2].mv_esc = 0x0B0B;
863  c->vlev[1].mv_esc = 0x0808;
864  c->vlev[2].mv_esc = 0x0B0B;
865 
866  c->ylev[1].bias_esc = 0x100;
867  c->ylev[2].bias_esc = 0x100;
868  c->ylev[3].bias_esc = 0x100;
869  c->ulev[1].bias_esc = 0x100;
870  c->ulev[2].bias_esc = 0x100;
871  c->vlev[1].bias_esc = 0x100;
872  c->vlev[2].bias_esc = 0x100;
873 
874  return 0;
875 }
876 
878 {
879  CLVContext *const c = avctx->priv_data;
880  int i;
881 
882  av_frame_free(&c->prev);
883  av_frame_free(&c->pic);
884 
885  av_freep(&c->mvi.mv);
886 
887  ff_free_vlc(&c->dc_vlc);
888  ff_free_vlc(&c->ac_vlc);
889  for (i = 0; i < 4; i++) {
890  ff_free_vlc(&c->ylev[i].mv_cb);
891  ff_free_vlc(&c->ylev[i].flags_cb);
892  ff_free_vlc(&c->ylev[i].bias_cb);
893  }
894  for (i = 0; i < 3; i++) {
895  ff_free_vlc(&c->ulev[i].mv_cb);
896  ff_free_vlc(&c->ulev[i].flags_cb);
897  ff_free_vlc(&c->ulev[i].bias_cb);
898  ff_free_vlc(&c->vlev[i].mv_cb);
899  ff_free_vlc(&c->vlev[i].flags_cb);
900  ff_free_vlc(&c->vlev[i].bias_cb);
901  }
902 
903  return 0;
904 }
905 
907  .name = "clearvideo",
908  .long_name = NULL_IF_CONFIG_SMALL("Iterated Systems ClearVideo"),
909  .type = AVMEDIA_TYPE_VIDEO,
911  .priv_data_size = sizeof(CLVContext),
913  .close = clv_decode_end,
915  .capabilities = AV_CODEC_CAP_DR1,
917 };
clv_mvy_0_codes
static const uint16_t clv_mvy_0_codes[]
Definition: clearvideodata.h:201
AVCodec
AVCodec.
Definition: codec.h:190
stride
int stride
Definition: mace.c:144
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
FF_CODEC_CAP_INIT_THREADSAFE
#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:40
clv_biasy_2_codes
static const uint16_t clv_biasy_2_codes[]
Definition: clearvideodata.h:1662
level
uint8_t level
Definition: svq3.c:210
clv_dc_bits
static const uint8_t clv_dc_bits[NUM_DC_CODES]
Definition: clearvideodata.h:49
CLVContext::dc_vlc
VLC dc_vlc
Definition: clearvideo.c:76
LevelCodes::mv_esc
uint16_t mv_esc
Definition: clearvideo.c:36
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
clv_flagsv_0_bits
static const uint8_t clv_flagsv_0_bits[]
Definition: clearvideodata.h:161
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
clv_biasu_1_codes
static const uint16_t clv_biasu_1_codes[]
Definition: clearvideodata.h:1739
clv_mvy_2_codes
static const uint16_t clv_mvy_2_codes[]
Definition: clearvideodata.h:469
ff_clearvideo_decoder
AVCodec ff_clearvideo_decoder
Definition: clearvideo.c:906
clv_mvu_1_codes
static const uint16_t clv_mvu_1_codes[]
Definition: clearvideodata.h:1174
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:83
GetByteContext
Definition: bytestream.h:33
clv_flagsv_0_codes
static const uint16_t clv_flagsv_0_codes[]
Definition: clearvideodata.h:165
MKTAG
#define MKTAG(a, b, c, d)
Definition: common.h:406
CLVContext::pmb_width
int pmb_width
Definition: clearvideo.c:72
clv_biasy_1_codes
static const uint16_t clv_biasy_1_codes[]
Definition: clearvideodata.h:1626
LevelCodes::mv_cb
VLC mv_cb
Definition: clearvideo.c:39
mv
static const int8_t mv[256][2]
Definition: 4xm.c:77
TileInfo
Definition: clearvideo.c:58
clv_mvu_2_codes
static const uint16_t clv_mvu_2_codes[]
Definition: clearvideodata.h:1269
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
MVInfo::mv
MV * mv
Definition: clearvideo.c:55
copyadd_block
static int copyadd_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src, int plane, int x, int y, int dx, int dy, int size, int bias)
Definition: clearvideo.c:258
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
MV::y
int16_t y
Definition: clearvideo.c:44
AVFrame::width
int width
Definition: frame.h:358
w
uint8_t w
Definition: llviddspenc.c:38
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
MVInfo::mb_w
int mb_w
Definition: clearvideo.c:50
init_vlc
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:38
TileInfo::bias
int16_t bias
Definition: clearvideo.c:60
data
const char data[16]
Definition: mxf.c:91
clv_biasy_3_codes
static const uint16_t clv_biasy_3_codes[]
Definition: clearvideodata.h:1703
clearvideodata.h
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:797
clv_mvu_1_bits
static const uint8_t clv_mvu_1_bits[]
Definition: clearvideodata.h:1156
CLVContext::top_dc
int top_dc[3]
Definition: clearvideo.c:80
CLVContext::mvi
MVInfo mvi
Definition: clearvideo.c:73
clv_flagsu_1_codes
static const uint16_t clv_flagsu_1_codes[]
Definition: clearvideodata.h:156
CLVContext::pic
AVFrame * pic
Definition: clearvideo.c:68
clv_flagsy_0_codes
static const uint16_t clv_flagsy_0_codes[]
Definition: clearvideodata.h:120
clv_decode_init
static av_cold int clv_decode_init(AVCodecContext *avctx)
Definition: clearvideo.c:651
clv_flagsv_1_codes
static const uint16_t clv_flagsv_1_codes[]
Definition: clearvideodata.h:174
clv_ac_codes
static const uint8_t clv_ac_codes[NUM_AC_CODES]
Definition: clearvideodata.h:84
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
MVInfo::top
int top
Definition: clearvideo.c:54
LevelCodes::flags_cb
VLC flags_cb
Definition: clearvideo.c:38
A
#define A(x)
Definition: vp56_arith.h:28
clv_biasy_2_syms
static const uint16_t clv_biasy_2_syms[]
Definition: clearvideodata.h:1678
ROP
#define ROP(x)
Definition: clearvideo.c:154
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
clv_mvv_1_bits
static const uint8_t clv_mvv_1_bits[]
Definition: clearvideodata.h:1387
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
extend_edges
static void extend_edges(AVFrame *buf, int tile_size)
Definition: clearvideo.c:460
decode_mb
static int decode_mb(CLVContext *c, int x, int y)
Definition: clearvideo.c:175
U
#define U(x)
Definition: vp56_arith.h:37
GetBitContext
Definition: get_bits.h:61
clv_mvy_1_bits
static const uint8_t clv_mvy_1_bits[]
Definition: clearvideodata.h:281
clv_mvu_2_syms
static const uint16_t clv_mvu_2_syms[]
Definition: clearvideodata.h:1328
mvi_predict
static MV mvi_predict(MVInfo *mvi, int mb_x, int mb_y, MV diff)
Definition: clearvideo.c:296
clv_biasv_2_syms
static const uint16_t clv_biasv_2_syms[]
Definition: clearvideodata.h:1823
CLVContext::mb_width
int mb_width
Definition: clearvideo.c:71
val
static double val(void *priv, double ch)
Definition: aeval.c:76
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:714
clv_mvu_1_syms
static const uint16_t clv_mvu_1_syms[]
Definition: clearvideodata.h:1206
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
clv_mvv_2_codes
static const uint16_t clv_mvv_2_codes[]
Definition: clearvideodata.h:1500
TileInfo::child
struct TileInfo * child[4]
Definition: clearvideo.c:62
clv_biasv_1_syms
static const uint16_t clv_biasv_1_syms[]
Definition: clearvideodata.h:1799
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:628
CLVContext::vlev
LevelCodes vlev[3]
Definition: clearvideo.c:77
CLVContext::ylev
LevelCodes ylev[4]
Definition: clearvideo.c:77
CLVContext::avctx
AVCodecContext * avctx
Definition: clearvideo.c:66
clv_dct
static void clv_dct(int16_t *block)
Definition: clearvideo.c:157
CLVContext::gb
GetBitContext gb
Definition: clearvideo.c:70
clv_mvy_3_syms
static const uint16_t clv_mvy_3_syms[]
Definition: clearvideodata.h:981
clv_flagsu_0_bits
static const uint8_t clv_flagsu_0_bits[]
Definition: clearvideodata.h:143
LevelCodes::bias_esc
uint16_t bias_esc
Definition: clearvideo.c:37
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:359
ctx
AVFormatContext * ctx
Definition: movenc.c:48
clv_mvy_1_syms
static const uint16_t clv_mvy_1_syms[]
Definition: clearvideodata.h:356
get_bits.h
MV::x
int16_t x
Definition: clearvideo.c:44
CLVContext::left_dc
int left_dc[4]
Definition: clearvideo.c:80
ff_free_vlc
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:359
LevelCodes
Definition: clearvideo.c:35
clv_mvv_1_syms
static const uint16_t clv_mvv_1_syms[]
Definition: clearvideodata.h:1437
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
blk
#define blk(i)
Definition: sha.c:185
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
clv_mvy_0_bits
static const uint8_t clv_mvy_0_bits[]
Definition: clearvideodata.h:179
CLVContext::tile_shift
int tile_shift
Definition: clearvideo.c:75
clv_biasv_2_codes
static const uint16_t clv_biasv_2_codes[]
Definition: clearvideodata.h:1814
clv_flagsu_1_bits
static const uint8_t clv_flagsu_1_bits[]
Definition: clearvideodata.h:152
clv_mvy_3_codes
static const uint16_t clv_mvy_3_codes[]
Definition: clearvideodata.h:806
NULL
#define NULL
Definition: coverity.c:32
clv_biasu_2_codes
static const uint16_t clv_biasu_2_codes[]
Definition: clearvideodata.h:1764
clv_mvv_1_codes
static const uint16_t clv_mvv_1_codes[]
Definition: clearvideodata.h:1405
clv_biasu_1_bits
static const uint8_t clv_biasu_1_bits[]
Definition: clearvideodata.h:1733
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
clv_mvy_2_bits
static const uint8_t clv_mvy_2_bits[]
Definition: clearvideodata.h:405
src
#define src
Definition: vp8dsp.c:254
clv_flagsy_1_codes
static const uint16_t clv_flagsy_1_codes[]
Definition: clearvideodata.h:129
mathops.h
clv_decode_end
static av_cold int clv_decode_end(AVCodecContext *avctx)
Definition: clearvideo.c:877
MVInfo
Definition: clearvideo.c:49
MVInfo::mb_stride
int mb_stride
Definition: clearvideo.c:53
ff_init_vlc_sparse
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:273
mvi_update_row
static void mvi_update_row(MVInfo *mvi)
Definition: clearvideo.c:352
TileInfo::mv
MV mv
Definition: clearvideo.c:61
clv_flagsv_1_bits
static const uint8_t clv_flagsv_1_bits[]
Definition: clearvideodata.h:170
clv_mvu_2_bits
static const uint8_t clv_mvu_2_bits[]
Definition: clearvideodata.h:1238
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
clv_decode_frame
static int clv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: clearvideo.c:499
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
clv_biasu_2_syms
static const uint16_t clv_biasu_2_syms[]
Definition: clearvideodata.h:1774
AVPacket::size
int size
Definition: packet.h:356
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
av_frame_ref
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:444
MVInfo::mb_h
int mb_h
Definition: clearvideo.c:51
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:800
MV
Definition: clearvideo.c:43
restore_tree
static int restore_tree(AVCodecContext *avctx, AVFrame *dst, AVFrame *src, int plane, int x, int y, int size, TileInfo *tile, MV root_mv)
Definition: clearvideo.c:429
size
int size
Definition: twinvq_data.h:11134
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:92
clv_biasy_1_syms
static const uint16_t clv_biasy_1_syms[]
Definition: clearvideodata.h:1639
CLVContext::pmb_height
int pmb_height
Definition: clearvideo.c:72
clv_biasy_1_bits
static const uint8_t clv_biasy_1_bits[]
Definition: clearvideodata.h:1618
copy_block
static int copy_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src, int plane, int x, int y, int dx, int dy, int size)
Definition: clearvideo.c:222
clv_mvv_2_syms
static const uint16_t clv_mvv_2_syms[]
Definition: clearvideodata.h:1559
clv_flagsy_0_bits
static const uint8_t clv_flagsy_0_bits[]
Definition: clearvideodata.h:116
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:112
clv_biasv_1_bits
static const uint8_t clv_biasv_1_bits[]
Definition: clearvideodata.h:1784
clv_flagsy_2_bits
static const uint8_t clv_flagsy_2_bits[]
Definition: clearvideodata.h:134
NUM_AC_CODES
#define NUM_AC_CODES
Definition: clearvideodata.h:28
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
frame_type
frame_type
Definition: jpeg2000_parser.c:31
pred_mv
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
Definition: diracdec.c:1389
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:627
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
clv_mvy_3_bits
static const uint8_t clv_mvy_3_bits[]
Definition: clearvideodata.h:717
clv_biasu_2_bits
static const uint8_t clv_biasu_2_bits[]
Definition: clearvideodata.h:1757
clv_flagsu_0_codes
static const uint16_t clv_flagsu_0_codes[]
Definition: clearvideodata.h:147
clv_ac_bits
static const uint8_t clv_ac_bits[NUM_AC_CODES]
Definition: clearvideodata.h:100
clv_mvv_2_bits
static const uint8_t clv_mvv_2_bits[]
Definition: clearvideodata.h:1469
uint8_t
uint8_t
Definition: audio_convert.c:194
ff_idctdsp_init
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:238
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
TileInfo::flags
uint16_t flags
Definition: clearvideo.c:59
clv_flagsy_2_codes
static const uint16_t clv_flagsy_2_codes[]
Definition: clearvideodata.h:138
AVCodecContext::height
int height
Definition: avcodec.h:699
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
CLVContext::tile_size
int tile_size
Definition: clearvideo.c:74
idctdsp.h
clv_biasy_3_syms
static const uint16_t clv_biasy_3_syms[]
Definition: clearvideodata.h:1718
avcodec.h
ff_zigzag_direct
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
VLC::bits
int bits
Definition: vlc.h:27
mid_pred
#define mid_pred
Definition: mathops.h:97
ff_reget_buffer
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
Definition: decode.c:1961
ret
ret
Definition: filter_design.txt:187
clv_mvy_2_syms
static const uint16_t clv_mvy_2_syms[]
Definition: clearvideodata.h:593
IDCTDSPContext
Definition: idctdsp.h:53
COP
#define COP(x)
Definition: clearvideo.c:155
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:88
CLVContext::luma_dc_quant
int luma_dc_quant
Definition: clearvideo.c:78
LevelCodes::bias_cb
VLC bias_cb
Definition: clearvideo.c:40
B
#define B
Definition: huffyuvdsp.h:32
AVCodecContext
main external API structure.
Definition: avcodec.h:526
AVFrame::height
int height
Definition: frame.h:358
decode_block
static int decode_block(CLVContext *ctx, int16_t *blk, int has_ac, int ac_quant)
Definition: clearvideo.c:83
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
clv_mvy_1_codes
static const uint16_t clv_mvy_1_codes[]
Definition: clearvideodata.h:307
CLVContext::mb_height
int mb_height
Definition: clearvideo.c:71
VLC
Definition: vlc.h:26
DCT_TEMPLATE
#define DCT_TEMPLATE(blk, step, bias, shift, dshift, OP)
Definition: clearvideo.c:130
clv_mvy_0_syms
static const uint16_t clv_mvy_0_syms[]
Definition: clearvideodata.h:241
clv_dc_codes
static const uint8_t clv_dc_codes[NUM_DC_CODES]
Definition: clearvideodata.h:30
clv_biasy_2_bits
static const uint8_t clv_biasy_2_bits[]
Definition: clearvideodata.h:1652
shift
static int shift(int a, int b)
Definition: sonic.c:82
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:714
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
CLVContext::prev
AVFrame * prev
Definition: clearvideo.c:69
clv_biasv_1_codes
static const uint16_t clv_biasv_1_codes[]
Definition: clearvideodata.h:1790
clv_biasy_3_bits
static const uint8_t clv_biasy_3_bits[]
Definition: clearvideodata.h:1694
ff_set_dimensions
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:104
mvi_reset
static void mvi_reset(MVInfo *mvi, int mb_w, int mb_h, int mb_size)
Definition: clearvideo.c:342
decode_tile_info
static TileInfo * decode_tile_info(GetBitContext *gb, LevelCodes *lc, int level)
Definition: clearvideo.c:362
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:551
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
CLVContext::idsp
IDCTDSPContext idsp
Definition: clearvideo.c:67
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
AVPacket
This structure stores compressed data.
Definition: packet.h:332
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
CLVContext::chroma_dc_quant
int chroma_dc_quant
Definition: clearvideo.c:78
NUM_DC_CODES
#define NUM_DC_CODES
Definition: clearvideodata.h:27
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
bytestream.h
clv_biasv_2_bits
static const uint8_t clv_biasv_2_bits[]
Definition: clearvideodata.h:1808
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
CLVContext
Definition: clearvideo.c:65
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
CLVContext::block
int16_t block[64]
Definition: clearvideo.c:79
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
clv_flagsy_1_bits
static const uint8_t clv_flagsy_1_bits[]
Definition: clearvideodata.h:125
h
h
Definition: vp9dsp_template.c:2038
AV_CODEC_ID_CLEARVIDEO
@ AV_CODEC_ID_CLEARVIDEO
Definition: codec_id.h:272
zero_mv
static const MV zero_mv
Definition: clearvideo.c:47
tile_do_block
static int tile_do_block(AVCodecContext *avctx, AVFrame *dst, AVFrame *src, int plane, int x, int y, int dx, int dy, int size, int bias)
Definition: clearvideo.c:415
CLVContext::ac_quant
int ac_quant
Definition: clearvideo.c:78
CLVContext::ulev
LevelCodes ulev[3]
Definition: clearvideo.c:77
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
MVInfo::mb_size
int mb_size
Definition: clearvideo.c:52
CLVContext::ac_vlc
VLC ac_vlc
Definition: clearvideo.c:76
clv_ac_syms
static const uint16_t clv_ac_syms[NUM_AC_CODES]
Definition: clearvideodata.h:68
clv_biasu_1_syms
static const uint16_t clv_biasu_1_syms[]
Definition: clearvideodata.h:1748