FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utvideodec.c
Go to the documentation of this file.
1 /*
2  * Ut Video decoder
3  * Copyright (c) 2011 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  * Ut Video decoder
25  */
26 
27 #include <inttypes.h>
28 #include <stdlib.h>
29 
30 #define UNCHECKED_BITSTREAM_READER 1
31 
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/pixdesc.h"
34 #include "avcodec.h"
35 #include "bswapdsp.h"
36 #include "bytestream.h"
37 #include "get_bits.h"
38 #include "internal.h"
39 #include "thread.h"
40 #include "utvideo.h"
41 
42 static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
43 {
44  int i;
45  HuffEntry he[1024];
46  int last;
47  uint32_t codes[1024];
48  uint8_t bits[1024];
49  uint16_t syms[1024];
50  uint32_t code;
51 
52  *fsym = -1;
53  for (i = 0; i < 1024; i++) {
54  he[i].sym = i;
55  he[i].len = *src++;
56  }
57  qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len);
58 
59  if (!he[0].len) {
60  *fsym = he[0].sym;
61  return 0;
62  }
63 
64  last = 1023;
65  while (he[last].len == 255 && last)
66  last--;
67 
68  if (he[last].len > 32) {
69  return -1;
70  }
71 
72  code = 1;
73  for (i = last; i >= 0; i--) {
74  codes[i] = code >> (32 - he[i].len);
75  bits[i] = he[i].len;
76  syms[i] = he[i].sym;
77  code += 0x80000000u >> (he[i].len - 1);
78  }
79 #define VLC_BITS 11
80  return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
81  bits, sizeof(*bits), sizeof(*bits),
82  codes, sizeof(*codes), sizeof(*codes),
83  syms, sizeof(*syms), sizeof(*syms), 0);
84 }
85 
86 static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
87 {
88  int i;
89  HuffEntry he[256];
90  int last;
91  uint32_t codes[256];
92  uint8_t bits[256];
93  uint8_t syms[256];
94  uint32_t code;
95 
96  *fsym = -1;
97  for (i = 0; i < 256; i++) {
98  he[i].sym = i;
99  he[i].len = *src++;
100  }
101  qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
102 
103  if (!he[0].len) {
104  *fsym = he[0].sym;
105  return 0;
106  }
107 
108  last = 255;
109  while (he[last].len == 255 && last)
110  last--;
111 
112  if (he[last].len > 32)
113  return -1;
114 
115  code = 1;
116  for (i = last; i >= 0; i--) {
117  codes[i] = code >> (32 - he[i].len);
118  bits[i] = he[i].len;
119  syms[i] = he[i].sym;
120  code += 0x80000000u >> (he[i].len - 1);
121  }
122 
123  return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
124  bits, sizeof(*bits), sizeof(*bits),
125  codes, sizeof(*codes), sizeof(*codes),
126  syms, sizeof(*syms), sizeof(*syms), 0);
127 }
128 
129 static int decode_plane10(UtvideoContext *c, int plane_no,
130  uint16_t *dst, ptrdiff_t stride,
131  int width, int height,
132  const uint8_t *src, const uint8_t *huff,
133  int use_pred)
134 {
135  int i, j, slice, pix, ret;
136  int sstart, send;
137  VLC vlc;
138  GetBitContext gb;
139  int prev, fsym;
140 
141  if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) {
142  av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
143  return ret;
144  }
145  if (fsym >= 0) { // build_huff reported a symbol to fill slices with
146  send = 0;
147  for (slice = 0; slice < c->slices; slice++) {
148  uint16_t *dest;
149 
150  sstart = send;
151  send = (height * (slice + 1) / c->slices);
152  dest = dst + sstart * stride;
153 
154  prev = 0x200;
155  for (j = sstart; j < send; j++) {
156  for (i = 0; i < width; i++) {
157  pix = fsym;
158  if (use_pred) {
159  prev += pix;
160  prev &= 0x3FF;
161  pix = prev;
162  }
163  dest[i] = pix;
164  }
165  dest += stride;
166  }
167  }
168  return 0;
169  }
170 
171  send = 0;
172  for (slice = 0; slice < c->slices; slice++) {
173  uint16_t *dest;
174  int slice_data_start, slice_data_end, slice_size;
175 
176  sstart = send;
177  send = (height * (slice + 1) / c->slices);
178  dest = dst + sstart * stride;
179 
180  // slice offset and size validation was done earlier
181  slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
182  slice_data_end = AV_RL32(src + slice * 4);
183  slice_size = slice_data_end - slice_data_start;
184 
185  if (!slice_size) {
186  av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
187  "yet a slice has a length of zero.\n");
188  goto fail;
189  }
190 
191  memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
192  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
193  (uint32_t *)(src + slice_data_start + c->slices * 4),
194  (slice_data_end - slice_data_start + 3) >> 2);
195  init_get_bits(&gb, c->slice_bits, slice_size * 8);
196 
197  prev = 0x200;
198  for (j = sstart; j < send; j++) {
199  for (i = 0; i < width; i++) {
200  pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
201  if (pix < 0) {
202  av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
203  goto fail;
204  }
205  if (use_pred) {
206  prev += pix;
207  prev &= 0x3FF;
208  pix = prev;
209  }
210  dest[i] = pix;
211  }
212  dest += stride;
213  if (get_bits_left(&gb) < 0) {
215  "Slice decoding ran out of bits\n");
216  goto fail;
217  }
218  }
219  if (get_bits_left(&gb) > 32)
221  "%d bits left after decoding slice\n", get_bits_left(&gb));
222  }
223 
224  ff_free_vlc(&vlc);
225 
226  return 0;
227 fail:
228  ff_free_vlc(&vlc);
229  return AVERROR_INVALIDDATA;
230 }
231 
232 static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
233 {
234  const int is_luma = (pix_fmt == AV_PIX_FMT_YUV420P) && !plane_no;
235 
236  if (interlaced)
237  return ~(1 + 2 * is_luma);
238 
239  return ~is_luma;
240 }
241 
242 static int decode_plane(UtvideoContext *c, int plane_no,
243  uint8_t *dst, ptrdiff_t stride,
244  int width, int height,
245  const uint8_t *src, int use_pred)
246 {
247  int i, j, slice, pix;
248  int sstart, send;
249  VLC vlc;
250  GetBitContext gb;
251  int ret, prev, fsym;
252  const int cmask = compute_cmask(plane_no, c->interlaced, c->avctx->pix_fmt);
253 
254  if (c->pack) {
255  send = 0;
256  for (slice = 0; slice < c->slices; slice++) {
257  GetBitContext cbit, pbit;
258  uint8_t *dest, *p;
259 
260  ret = init_get_bits8(&cbit, c->control_stream[plane_no][slice], c->control_stream_size[plane_no][slice]);
261  if (ret < 0)
262  return ret;
263 
264  ret = init_get_bits8(&pbit, c->packed_stream[plane_no][slice], c->packed_stream_size[plane_no][slice]);
265  if (ret < 0)
266  return ret;
267 
268  sstart = send;
269  send = (height * (slice + 1) / c->slices) & cmask;
270  dest = dst + sstart * stride;
271 
272  if (3 * ((dst + send * stride - dest + 7)/8) > get_bits_left(&cbit))
273  return AVERROR_INVALIDDATA;
274 
275  for (p = dest; p < dst + send * stride; p += 8) {
276  int bits = get_bits_le(&cbit, 3);
277 
278  if (bits == 0) {
279  *(uint64_t *) p = 0;
280  } else {
281  uint32_t sub = 0x80 >> (8 - (bits + 1)), add;
282  int k;
283 
284  if ((bits + 1) * 8 > get_bits_left(&pbit))
285  return AVERROR_INVALIDDATA;
286 
287  for (k = 0; k < 8; k++) {
288 
289  p[k] = get_bits_le(&pbit, bits + 1);
290  add = (~p[k] & sub) << (8 - bits);
291  p[k] -= sub;
292  p[k] += add;
293  }
294  }
295  }
296  }
297 
298  return 0;
299  }
300 
301  if (build_huff(src, &vlc, &fsym)) {
302  av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
303  return AVERROR_INVALIDDATA;
304  }
305  if (fsym >= 0) { // build_huff reported a symbol to fill slices with
306  send = 0;
307  for (slice = 0; slice < c->slices; slice++) {
308  uint8_t *dest;
309 
310  sstart = send;
311  send = (height * (slice + 1) / c->slices) & cmask;
312  dest = dst + sstart * stride;
313 
314  prev = 0x80;
315  for (j = sstart; j < send; j++) {
316  for (i = 0; i < width; i++) {
317  pix = fsym;
318  if (use_pred) {
319  prev += pix;
320  pix = prev;
321  }
322  dest[i] = pix;
323  }
324  dest += stride;
325  }
326  }
327  return 0;
328  }
329 
330  src += 256;
331 
332  send = 0;
333  for (slice = 0; slice < c->slices; slice++) {
334  uint8_t *dest;
335  int slice_data_start, slice_data_end, slice_size;
336 
337  sstart = send;
338  send = (height * (slice + 1) / c->slices) & cmask;
339  dest = dst + sstart * stride;
340 
341  // slice offset and size validation was done earlier
342  slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
343  slice_data_end = AV_RL32(src + slice * 4);
344  slice_size = slice_data_end - slice_data_start;
345 
346  if (!slice_size) {
347  av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
348  "yet a slice has a length of zero.\n");
349  goto fail;
350  }
351 
352  memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
353  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
354  (uint32_t *)(src + slice_data_start + c->slices * 4),
355  (slice_data_end - slice_data_start + 3) >> 2);
356  init_get_bits(&gb, c->slice_bits, slice_size * 8);
357 
358  prev = 0x80;
359  for (j = sstart; j < send; j++) {
360  for (i = 0; i < width; i++) {
361  pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
362  if (pix < 0) {
363  av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
364  goto fail;
365  }
366  if (use_pred) {
367  prev += pix;
368  pix = prev;
369  }
370  dest[i] = pix;
371  }
372  if (get_bits_left(&gb) < 0) {
374  "Slice decoding ran out of bits\n");
375  goto fail;
376  }
377  dest += stride;
378  }
379  if (get_bits_left(&gb) > 32)
381  "%d bits left after decoding slice\n", get_bits_left(&gb));
382  }
383 
384  ff_free_vlc(&vlc);
385 
386  return 0;
387 fail:
388  ff_free_vlc(&vlc);
389  return AVERROR_INVALIDDATA;
390 }
391 
392 #undef A
393 #undef B
394 #undef C
395 
397  int width, int height, int slices, int rmode)
398 {
399  int i, j, slice;
400  int A, B, C;
401  uint8_t *bsrc;
402  int slice_start, slice_height;
403  const int cmask = ~rmode;
404 
405  for (slice = 0; slice < slices; slice++) {
406  slice_start = ((slice * height) / slices) & cmask;
407  slice_height = ((((slice + 1) * height) / slices) & cmask) -
408  slice_start;
409 
410  if (!slice_height)
411  continue;
412  bsrc = src + slice_start * stride;
413 
414  // first line - left neighbour prediction
415  bsrc[0] += 0x80;
416  c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
417  bsrc += stride;
418  if (slice_height <= 1)
419  continue;
420  // second line - first element has top prediction, the rest uses median
421  C = bsrc[-stride];
422  bsrc[0] += C;
423  A = bsrc[0];
424  for (i = 1; i < FFMIN(width, 16); i++) { /* scalar loop (DSP need align 16) */
425  B = bsrc[i - stride];
426  bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
427  C = B;
428  A = bsrc[i];
429  }
430  if (width > 16)
431  c->llviddsp.add_median_pred(bsrc + 16, bsrc - stride + 16,
432  bsrc + 16, width - 16, &A, &B);
433 
434  bsrc += stride;
435  // the rest of lines use continuous median prediction
436  for (j = 2; j < slice_height; j++) {
437  c->llviddsp.add_median_pred(bsrc, bsrc - stride,
438  bsrc, width, &A, &B);
439  bsrc += stride;
440  }
441  }
442 }
443 
444 /* UtVideo interlaced mode treats every two lines as a single one,
445  * so restoring function should take care of possible padding between
446  * two parts of the same "line".
447  */
449  int width, int height, int slices, int rmode)
450 {
451  int i, j, slice;
452  int A, B, C;
453  uint8_t *bsrc;
454  int slice_start, slice_height;
455  const int cmask = ~(rmode ? 3 : 1);
456  const ptrdiff_t stride2 = stride << 1;
457 
458  for (slice = 0; slice < slices; slice++) {
459  slice_start = ((slice * height) / slices) & cmask;
460  slice_height = ((((slice + 1) * height) / slices) & cmask) -
461  slice_start;
462  slice_height >>= 1;
463  if (!slice_height)
464  continue;
465 
466  bsrc = src + slice_start * stride;
467 
468  // first line - left neighbour prediction
469  bsrc[0] += 0x80;
470  A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
471  c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
472  bsrc += stride2;
473  if (slice_height <= 1)
474  continue;
475  // second line - first element has top prediction, the rest uses median
476  C = bsrc[-stride2];
477  bsrc[0] += C;
478  A = bsrc[0];
479  for (i = 1; i < FFMIN(width, 16); i++) { /* scalar loop (DSP need align 16) */
480  B = bsrc[i - stride2];
481  bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
482  C = B;
483  A = bsrc[i];
484  }
485  if (width > 16)
486  c->llviddsp.add_median_pred(bsrc + 16, bsrc - stride2 + 16,
487  bsrc + 16, width - 16, &A, &B);
488 
489  c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
490  bsrc + stride, width, &A, &B);
491  bsrc += stride2;
492  // the rest of lines use continuous median prediction
493  for (j = 2; j < slice_height; j++) {
494  c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
495  bsrc, width, &A, &B);
496  c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
497  bsrc + stride, width, &A, &B);
498  bsrc += stride2;
499  }
500  }
501 }
502 
504  int width, int height, int slices, int rmode)
505 {
506  int i, j, slice;
507  int A, B, C;
508  uint8_t *bsrc;
509  int slice_start, slice_height;
510  const int cmask = ~rmode;
511  int min_width = FFMIN(width, 32);
512 
513  for (slice = 0; slice < slices; slice++) {
514  slice_start = ((slice * height) / slices) & cmask;
515  slice_height = ((((slice + 1) * height) / slices) & cmask) -
516  slice_start;
517 
518  if (!slice_height)
519  continue;
520  bsrc = src + slice_start * stride;
521 
522  // first line - left neighbour prediction
523  bsrc[0] += 0x80;
524  c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
525  bsrc += stride;
526  if (slice_height <= 1)
527  continue;
528  for (j = 1; j < slice_height; j++) {
529  // second line - first element has top prediction, the rest uses gradient
530  bsrc[0] = (bsrc[0] + bsrc[-stride]) & 0xFF;
531  for (i = 1; i < min_width; i++) { /* dsp need align 32 */
532  A = bsrc[i - stride];
533  B = bsrc[i - (stride + 1)];
534  C = bsrc[i - 1];
535  bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
536  }
537  if (width > 32)
538  c->llviddsp.add_gradient_pred(bsrc + 32, stride, width - 32);
539  bsrc += stride;
540  }
541  }
542 }
543 
545  int width, int height, int slices, int rmode)
546 {
547  int i, j, slice;
548  int A, B, C;
549  uint8_t *bsrc;
550  int slice_start, slice_height;
551  const int cmask = ~(rmode ? 3 : 1);
552  const ptrdiff_t stride2 = stride << 1;
553  int min_width = FFMIN(width, 32);
554 
555  for (slice = 0; slice < slices; slice++) {
556  slice_start = ((slice * height) / slices) & cmask;
557  slice_height = ((((slice + 1) * height) / slices) & cmask) -
558  slice_start;
559  slice_height >>= 1;
560  if (!slice_height)
561  continue;
562 
563  bsrc = src + slice_start * stride;
564 
565  // first line - left neighbour prediction
566  bsrc[0] += 0x80;
567  A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
568  c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
569  bsrc += stride2;
570  if (slice_height <= 1)
571  continue;
572  for (j = 1; j < slice_height; j++) {
573  // second line - first element has top prediction, the rest uses gradient
574  bsrc[0] = (bsrc[0] + bsrc[-stride2]) & 0xFF;
575  for (i = 1; i < min_width; i++) { /* dsp need align 32 */
576  A = bsrc[i - stride2];
577  B = bsrc[i - (stride2 + 1)];
578  C = bsrc[i - 1];
579  bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
580  }
581  if (width > 32)
582  c->llviddsp.add_gradient_pred(bsrc + 32, stride2, width - 32);
583 
584  A = bsrc[-stride];
585  B = bsrc[-(1 + stride + stride - width)];
586  C = bsrc[width - 1];
587  bsrc[stride] = (A - B + C + bsrc[stride]) & 0xFF;
588  for (i = 1; i < width; i++) {
589  A = bsrc[i - stride];
590  B = bsrc[i - (1 + stride)];
591  C = bsrc[i - 1 + stride];
592  bsrc[i + stride] = (A - B + C + bsrc[i + stride]) & 0xFF;
593  }
594  bsrc += stride2;
595  }
596  }
597 }
598 
599 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
600  AVPacket *avpkt)
601 {
602  const uint8_t *buf = avpkt->data;
603  int buf_size = avpkt->size;
604  UtvideoContext *c = avctx->priv_data;
605  int i, j;
606  const uint8_t *plane_start[5];
607  int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
608  int ret;
609  GetByteContext gb;
610  ThreadFrame frame = { .f = data };
611 
612  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
613  return ret;
614 
615  /* parse plane structure to get frame flags and validate slice offsets */
616  bytestream2_init(&gb, buf, buf_size);
617 
618  if (c->pack) {
619  const uint8_t *packed_stream;
620  const uint8_t *control_stream;
621  GetByteContext pb;
622  uint32_t nb_cbs;
623  int left;
624 
625  c->frame_info = PRED_GRADIENT << 8;
626 
627  if (bytestream2_get_byte(&gb) != 1)
628  return AVERROR_INVALIDDATA;
629  bytestream2_skip(&gb, 3);
630  c->offset = bytestream2_get_le32(&gb);
631 
632  if (buf_size <= c->offset + 8LL)
633  return AVERROR_INVALIDDATA;
634 
635  bytestream2_init(&pb, buf + 8 + c->offset, buf_size - 8 - c->offset);
636 
637  nb_cbs = bytestream2_get_le32(&pb);
638  if (nb_cbs > c->offset)
639  return AVERROR_INVALIDDATA;
640 
641  packed_stream = buf + 8;
642  control_stream = packed_stream + (c->offset - nb_cbs);
643  left = control_stream - packed_stream;
644 
645  for (i = 0; i < c->planes; i++) {
646  for (j = 0; j < c->slices; j++) {
647  c->packed_stream[i][j] = packed_stream;
648  c->packed_stream_size[i][j] = bytestream2_get_le32(&pb);
649  if (c->packed_stream_size[i][j] > left)
650  return AVERROR_INVALIDDATA;
651  left -= c->packed_stream_size[i][j];
652  packed_stream += c->packed_stream_size[i][j];
653  }
654  }
655 
656  left = buf + buf_size - control_stream;
657 
658  for (i = 0; i < c->planes; i++) {
659  for (j = 0; j < c->slices; j++) {
660  c->control_stream[i][j] = control_stream;
661  c->control_stream_size[i][j] = bytestream2_get_le32(&pb);
662  if (c->control_stream_size[i][j] > left)
663  return AVERROR_INVALIDDATA;
664  left -= c->control_stream_size[i][j];
665  control_stream += c->control_stream_size[i][j];
666  }
667  }
668  } else if (c->pro) {
670  av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
671  return AVERROR_INVALIDDATA;
672  }
673  c->frame_info = bytestream2_get_le32u(&gb);
674  c->slices = ((c->frame_info >> 16) & 0xff) + 1;
675  for (i = 0; i < c->planes; i++) {
676  plane_start[i] = gb.buffer;
677  if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
678  av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
679  return AVERROR_INVALIDDATA;
680  }
681  slice_start = 0;
682  slice_end = 0;
683  for (j = 0; j < c->slices; j++) {
684  slice_end = bytestream2_get_le32u(&gb);
685  if (slice_end < 0 || slice_end < slice_start ||
686  bytestream2_get_bytes_left(&gb) < slice_end + 1024LL) {
687  av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
688  return AVERROR_INVALIDDATA;
689  }
690  slice_size = slice_end - slice_start;
691  slice_start = slice_end;
692  max_slice_size = FFMAX(max_slice_size, slice_size);
693  }
694  plane_size = slice_end;
695  bytestream2_skipu(&gb, plane_size);
696  bytestream2_skipu(&gb, 1024);
697  }
698  plane_start[c->planes] = gb.buffer;
699  } else {
700  for (i = 0; i < c->planes; i++) {
701  plane_start[i] = gb.buffer;
702  if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
703  av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
704  return AVERROR_INVALIDDATA;
705  }
706  bytestream2_skipu(&gb, 256);
707  slice_start = 0;
708  slice_end = 0;
709  for (j = 0; j < c->slices; j++) {
710  slice_end = bytestream2_get_le32u(&gb);
711  if (slice_end < 0 || slice_end < slice_start ||
712  bytestream2_get_bytes_left(&gb) < slice_end) {
713  av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
714  return AVERROR_INVALIDDATA;
715  }
716  slice_size = slice_end - slice_start;
717  slice_start = slice_end;
718  max_slice_size = FFMAX(max_slice_size, slice_size);
719  }
720  plane_size = slice_end;
721  bytestream2_skipu(&gb, plane_size);
722  }
723  plane_start[c->planes] = gb.buffer;
725  av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
726  return AVERROR_INVALIDDATA;
727  }
728  c->frame_info = bytestream2_get_le32u(&gb);
729  }
730  av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
731  c->frame_info);
732 
733  c->frame_pred = (c->frame_info >> 8) & 3;
734 
735  max_slice_size += 4*avctx->width;
736 
737  if (!c->pack) {
739  max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
740 
741  if (!c->slice_bits) {
742  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
743  return AVERROR(ENOMEM);
744  }
745  }
746 
747  switch (c->avctx->pix_fmt) {
748  case AV_PIX_FMT_GBRP:
749  case AV_PIX_FMT_GBRAP:
750  for (i = 0; i < c->planes; i++) {
751  ret = decode_plane(c, i, frame.f->data[i],
752  frame.f->linesize[i], avctx->width,
753  avctx->height, plane_start[i],
754  c->frame_pred == PRED_LEFT);
755  if (ret)
756  return ret;
757  if (c->frame_pred == PRED_MEDIAN) {
758  if (!c->interlaced) {
759  restore_median_planar(c, frame.f->data[i],
760  frame.f->linesize[i], avctx->width,
761  avctx->height, c->slices, 0);
762  } else {
763  restore_median_planar_il(c, frame.f->data[i],
764  frame.f->linesize[i],
765  avctx->width, avctx->height, c->slices,
766  0);
767  }
768  } else if (c->frame_pred == PRED_GRADIENT) {
769  if (!c->interlaced) {
770  restore_gradient_planar(c, frame.f->data[i],
771  frame.f->linesize[i], avctx->width,
772  avctx->height, c->slices, 0);
773  } else {
774  restore_gradient_planar_il(c, frame.f->data[i],
775  frame.f->linesize[i],
776  avctx->width, avctx->height, c->slices,
777  0);
778  }
779  }
780  }
781  c->utdsp.restore_rgb_planes(frame.f->data[2], frame.f->data[0], frame.f->data[1],
782  frame.f->linesize[2], frame.f->linesize[0], frame.f->linesize[1],
783  avctx->width, avctx->height);
784  break;
785  case AV_PIX_FMT_GBRAP10:
786  case AV_PIX_FMT_GBRP10:
787  for (i = 0; i < c->planes; i++) {
788  ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i],
789  frame.f->linesize[i] / 2, avctx->width,
790  avctx->height, plane_start[i],
791  plane_start[i + 1] - 1024,
792  c->frame_pred == PRED_LEFT);
793  if (ret)
794  return ret;
795  }
796  c->utdsp.restore_rgb_planes10((uint16_t *)frame.f->data[2], (uint16_t *)frame.f->data[0], (uint16_t *)frame.f->data[1],
797  frame.f->linesize[2] / 2, frame.f->linesize[0] / 2, frame.f->linesize[1] / 2,
798  avctx->width, avctx->height);
799  break;
800  case AV_PIX_FMT_YUV420P:
801  for (i = 0; i < 3; i++) {
802  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
803  avctx->width >> !!i, avctx->height >> !!i,
804  plane_start[i], c->frame_pred == PRED_LEFT);
805  if (ret)
806  return ret;
807  if (c->frame_pred == PRED_MEDIAN) {
808  if (!c->interlaced) {
809  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
810  avctx->width >> !!i, avctx->height >> !!i,
811  c->slices, !i);
812  } else {
813  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
814  avctx->width >> !!i,
815  avctx->height >> !!i,
816  c->slices, !i);
817  }
818  } else if (c->frame_pred == PRED_GRADIENT) {
819  if (!c->interlaced) {
820  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
821  avctx->width >> !!i, avctx->height >> !!i,
822  c->slices, !i);
823  } else {
824  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
825  avctx->width >> !!i,
826  avctx->height >> !!i,
827  c->slices, !i);
828  }
829  }
830  }
831  break;
832  case AV_PIX_FMT_YUV422P:
833  for (i = 0; i < 3; i++) {
834  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
835  avctx->width >> !!i, avctx->height,
836  plane_start[i], c->frame_pred == PRED_LEFT);
837  if (ret)
838  return ret;
839  if (c->frame_pred == PRED_MEDIAN) {
840  if (!c->interlaced) {
841  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
842  avctx->width >> !!i, avctx->height,
843  c->slices, 0);
844  } else {
845  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
846  avctx->width >> !!i, avctx->height,
847  c->slices, 0);
848  }
849  } else if (c->frame_pred == PRED_GRADIENT) {
850  if (!c->interlaced) {
851  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
852  avctx->width >> !!i, avctx->height,
853  c->slices, 0);
854  } else {
855  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
856  avctx->width >> !!i, avctx->height,
857  c->slices, 0);
858  }
859  }
860  }
861  break;
862  case AV_PIX_FMT_YUV444P:
863  for (i = 0; i < 3; i++) {
864  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
865  avctx->width, avctx->height,
866  plane_start[i], c->frame_pred == PRED_LEFT);
867  if (ret)
868  return ret;
869  if (c->frame_pred == PRED_MEDIAN) {
870  if (!c->interlaced) {
871  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
872  avctx->width, avctx->height,
873  c->slices, 0);
874  } else {
875  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
876  avctx->width, avctx->height,
877  c->slices, 0);
878  }
879  } else if (c->frame_pred == PRED_GRADIENT) {
880  if (!c->interlaced) {
881  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
882  avctx->width, avctx->height,
883  c->slices, 0);
884  } else {
885  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
886  avctx->width, avctx->height,
887  c->slices, 0);
888  }
889  }
890  }
891  break;
893  for (i = 0; i < 3; i++) {
894  ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], frame.f->linesize[i] / 2,
895  avctx->width >> !!i, avctx->height,
896  plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
897  if (ret)
898  return ret;
899  }
900  break;
901  }
902 
903  frame.f->key_frame = 1;
904  frame.f->pict_type = AV_PICTURE_TYPE_I;
905  frame.f->interlaced_frame = !!c->interlaced;
906 
907  *got_frame = 1;
908 
909  /* always report that the buffer was completely consumed */
910  return buf_size;
911 }
912 
914 {
915  UtvideoContext * const c = avctx->priv_data;
916  int h_shift, v_shift;
917 
918  c->avctx = avctx;
919 
921  ff_bswapdsp_init(&c->bdsp);
923 
924  c->slice_bits_size = 0;
925 
926  switch (avctx->codec_tag) {
927  case MKTAG('U', 'L', 'R', 'G'):
928  c->planes = 3;
929  avctx->pix_fmt = AV_PIX_FMT_GBRP;
930  break;
931  case MKTAG('U', 'L', 'R', 'A'):
932  c->planes = 4;
933  avctx->pix_fmt = AV_PIX_FMT_GBRAP;
934  break;
935  case MKTAG('U', 'L', 'Y', '0'):
936  c->planes = 3;
937  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
938  avctx->colorspace = AVCOL_SPC_BT470BG;
939  break;
940  case MKTAG('U', 'L', 'Y', '2'):
941  c->planes = 3;
942  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
943  avctx->colorspace = AVCOL_SPC_BT470BG;
944  break;
945  case MKTAG('U', 'L', 'Y', '4'):
946  c->planes = 3;
947  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
948  avctx->colorspace = AVCOL_SPC_BT470BG;
949  break;
950  case MKTAG('U', 'Q', 'Y', '2'):
951  c->planes = 3;
952  c->pro = 1;
953  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
954  break;
955  case MKTAG('U', 'Q', 'R', 'G'):
956  c->planes = 3;
957  c->pro = 1;
958  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
959  break;
960  case MKTAG('U', 'Q', 'R', 'A'):
961  c->planes = 4;
962  c->pro = 1;
963  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
964  break;
965  case MKTAG('U', 'L', 'H', '0'):
966  c->planes = 3;
967  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
968  avctx->colorspace = AVCOL_SPC_BT709;
969  break;
970  case MKTAG('U', 'L', 'H', '2'):
971  c->planes = 3;
972  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
973  avctx->colorspace = AVCOL_SPC_BT709;
974  break;
975  case MKTAG('U', 'L', 'H', '4'):
976  c->planes = 3;
977  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
978  avctx->colorspace = AVCOL_SPC_BT709;
979  break;
980  case MKTAG('U', 'M', 'Y', '2'):
981  c->planes = 3;
982  c->pack = 1;
983  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
984  avctx->colorspace = AVCOL_SPC_BT470BG;
985  break;
986  case MKTAG('U', 'M', 'H', '2'):
987  c->planes = 3;
988  c->pack = 1;
989  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
990  avctx->colorspace = AVCOL_SPC_BT709;
991  break;
992  case MKTAG('U', 'M', 'Y', '4'):
993  c->planes = 3;
994  c->pack = 1;
995  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
996  avctx->colorspace = AVCOL_SPC_BT470BG;
997  break;
998  case MKTAG('U', 'M', 'H', '4'):
999  c->planes = 3;
1000  c->pack = 1;
1001  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
1002  avctx->colorspace = AVCOL_SPC_BT709;
1003  break;
1004  case MKTAG('U', 'M', 'R', 'G'):
1005  c->planes = 3;
1006  c->pack = 1;
1007  avctx->pix_fmt = AV_PIX_FMT_GBRP;
1008  break;
1009  case MKTAG('U', 'M', 'R', 'A'):
1010  c->planes = 4;
1011  c->pack = 1;
1012  avctx->pix_fmt = AV_PIX_FMT_GBRAP;
1013  break;
1014  default:
1015  av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
1016  avctx->codec_tag);
1017  return AVERROR_INVALIDDATA;
1018  }
1019 
1020  av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &h_shift, &v_shift);
1021  if ((avctx->width & ((1<<h_shift)-1)) ||
1022  (avctx->height & ((1<<v_shift)-1))) {
1023  avpriv_request_sample(avctx, "Odd dimensions");
1024  return AVERROR_PATCHWELCOME;
1025  }
1026 
1027  if (c->pack && avctx->extradata_size >= 16) {
1028  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1029  avctx->extradata[3], avctx->extradata[2],
1030  avctx->extradata[1], avctx->extradata[0]);
1031  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1032  AV_RB32(avctx->extradata + 4));
1033  c->compression = avctx->extradata[8];
1034  if (c->compression != 2)
1035  avpriv_request_sample(avctx, "Unknown compression type");
1036  c->slices = avctx->extradata[9] + 1;
1037  } else if (!c->pro && avctx->extradata_size >= 16) {
1038  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1039  avctx->extradata[3], avctx->extradata[2],
1040  avctx->extradata[1], avctx->extradata[0]);
1041  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1042  AV_RB32(avctx->extradata + 4));
1043  c->frame_info_size = AV_RL32(avctx->extradata + 8);
1044  c->flags = AV_RL32(avctx->extradata + 12);
1045 
1046  if (c->frame_info_size != 4)
1047  avpriv_request_sample(avctx, "Frame info not 4 bytes");
1048  av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
1049  c->slices = (c->flags >> 24) + 1;
1050  c->compression = c->flags & 1;
1051  c->interlaced = c->flags & 0x800;
1052  } else if (c->pro && avctx->extradata_size == 8) {
1053  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1054  avctx->extradata[3], avctx->extradata[2],
1055  avctx->extradata[1], avctx->extradata[0]);
1056  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1057  AV_RB32(avctx->extradata + 4));
1058  c->interlaced = 0;
1059  c->frame_info_size = 4;
1060  } else {
1061  av_log(avctx, AV_LOG_ERROR,
1062  "Insufficient extradata size %d, should be at least 16\n",
1063  avctx->extradata_size);
1064  return AVERROR_INVALIDDATA;
1065  }
1066 
1067  return 0;
1068 }
1069 
1071 {
1072  UtvideoContext * const c = avctx->priv_data;
1073 
1074  av_freep(&c->slice_bits);
1075 
1076  return 0;
1077 }
1078 
1080  .name = "utvideo",
1081  .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
1082  .type = AVMEDIA_TYPE_VIDEO,
1083  .id = AV_CODEC_ID_UTVIDEO,
1084  .priv_data_size = sizeof(UtvideoContext),
1085  .init = decode_init,
1086  .close = decode_end,
1087  .decode = decode_frame,
1088  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1089  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1090 };
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.h:25
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:475
static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:448
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static enum AVPixelFormat pix_fmt
int ff_ut10_huff_cmp_len(const void *a, const void *b)
Definition: utvideo.c:43
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define C
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:388
uint32_t flags
Definition: utvideo.h:75
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVFrame * f
Definition: thread.h:35
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
void(* restore_rgb_planes)(uint8_t *src_r, uint8_t *src_g, uint8_t *src_b, ptrdiff_t linesize_r, ptrdiff_t linesize_g, ptrdiff_t linesize_b, int width, int height)
Definition: utvideodsp.h:28
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:479
int slice_bits_size
Definition: utvideo.h:86
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:268
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
int size
Definition: avcodec.h:1431
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:384
static av_cold int decode_end(AVCodecContext *avctx)
Definition: utvideodec.c:1070
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1727
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
#define src
Definition: vp8dsp.c:254
AVCodec.
Definition: avcodec.h:3408
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
int interlaced
Definition: utvideo.h:79
av_cold void ff_utvideodsp_init(UTVideoDSPContext *c)
Definition: utvideodsp.c:75
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#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
uint8_t
#define av_cold
Definition: attributes.h:82
static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:503
static void restore_gradient_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:544
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1618
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:344
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:87
uint32_t frame_info
Definition: utvideo.h:75
static AVFrame * frame
#define height
uint8_t * data
Definition: avcodec.h:1430
const uint8_t * buffer
Definition: bytestream.h:34
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:170
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:365
static int decode_plane10(UtvideoContext *c, int plane_no, uint16_t *dst, ptrdiff_t stride, int width, int height, const uint8_t *src, const uint8_t *huff, int use_pred)
Definition: utvideodec.c:129
#define A(x)
Definition: vp56_arith.h:28
#define av_log(a,...)
static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
Definition: utvideodec.c:86
BswapDSPContext bdsp
Definition: utvideo.h:71
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:596
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static av_cold int decode_init(AVCodecContext *avctx)
Definition: utvideodec.c:913
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
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:2391
#define B
Definition: huffyuvdsp.h:32
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
AVCodecContext * avctx
Definition: utvideo.h:69
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
uint16_t width
Definition: gdv.c:47
const char * name
Name of the codec implementation.
Definition: avcodec.h:3415
uint32_t frame_info_size
Definition: utvideo.h:75
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:116
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1015
Definition: vlc.h:26
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:488
static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:396
int compression
Definition: utvideo.h:78
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:301
#define FFMIN(a, b)
Definition: common.h:96
static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
Definition: utvideodec.c:232
uint8_t interlaced
Definition: mxfenc.c:1949
int width
picture width / height.
Definition: avcodec.h:1690
size_t control_stream_size[4][256]
Definition: utvideo.h:91
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:563
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: utvideodec.c:599
Common Ut Video header.
int frame_pred
Definition: utvideo.h:80
uint8_t len
Definition: magicyuv.c:49
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:249
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:464
uint32_t offset
Definition: utvideo.h:75
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
Definition: avcodec.h:1518
const uint8_t * control_stream[4][256]
Definition: utvideo.h:90
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1543
void * buf
Definition: avisynth_c.h:690
#define VLC_BITS
int extradata_size
Definition: avcodec.h:1619
void ff_llviddsp_init(LLVidDSPContext *c)
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2141
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:433
#define mid_pred
Definition: mathops.h:97
static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
Definition: utvideodec.c:42
void(* restore_rgb_planes10)(uint16_t *src_r, uint16_t *src_g, uint16_t *src_b, ptrdiff_t linesize_r, ptrdiff_t linesize_g, ptrdiff_t linesize_b, int width, int height)
Definition: utvideodsp.h:31
uint8_t * slice_bits
Definition: utvideo.h:85
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition: get_bits.h:289
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:369
static int decode_plane(UtvideoContext *c, int plane_no, uint8_t *dst, ptrdiff_t stride, int width, int height, const uint8_t *src, int use_pred)
Definition: utvideodec.c:242
int ff_ut_huff_cmp_len(const void *a, const void *b)
Definition: utvideo.c:37
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
LLVidDSPContext llviddsp
Definition: utvideo.h:72
void(* add_gradient_pred)(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
common internal api header.
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
static double c[64]
uint16_t sym
Definition: magicyuv.c:48
size_t packed_stream_size[4][256]
Definition: utvideo.h:89
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:773
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2029
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
void * priv_data
Definition: avcodec.h:1545
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
int len
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:296
UTVideoDSPContext utdsp
Definition: utvideo.h:70
#define av_freep(p)
const uint8_t * packed_stream[4][256]
Definition: utvideo.h:88
#define stride
#define MKTAG(a, b, c, d)
Definition: common.h:366
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
AVCodec ff_utvideo_decoder
Definition: utvideodec.c:1079
This structure stores compressed data.
Definition: avcodec.h:1407
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:354
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)