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