FFmpeg
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_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned nb_elems)
44 {
45  int i;
46  uint32_t codes[1024];
47  uint8_t bits[1024];
48  uint16_t codes_count[33] = { 0 };
49 
50  *fsym = -1;
51  for (i = 0; i < nb_elems; i++) {
52  if (src[i] == 0) {
53  *fsym = i;
54  return 0;
55  } else if (src[i] == 255) {
56  bits[i] = 0;
57  } else if (src[i] <= 32) {
58  bits[i] = src[i];
59  } else
60  return AVERROR_INVALIDDATA;
61 
62  codes_count[bits[i]]++;
63  }
64  if (codes_count[0] == nb_elems)
65  return AVERROR_INVALIDDATA;
66 
67  for (unsigned i = 32, nb_codes = 0; i > 0; i--) {
68  uint16_t curr = codes_count[i]; // # of leafs of length i
69  codes_count[i] = nb_codes / 2; // # of non-leaf nodes on level i
70  nb_codes = codes_count[i] + curr; // # of nodes on level i
71  }
72 
73  for (unsigned i = nb_elems; i-- > 0;) {
74  if (!bits[i]) {
75  codes[i] = 0;
76  continue;
77  }
78  codes[i] = codes_count[bits[i]]++;
79  }
80 #define VLC_BITS 11
81  return init_vlc(vlc, VLC_BITS, nb_elems,
82  bits, sizeof(*bits), sizeof(*bits),
83  codes, sizeof(*codes), sizeof(*codes), 0);
84 }
85 
86 static int decode_plane10(UtvideoContext *c, int plane_no,
87  uint16_t *dst, ptrdiff_t stride,
88  int width, int height,
89  const uint8_t *src, const uint8_t *huff,
90  int use_pred)
91 {
92  int i, j, slice, pix, ret;
93  int sstart, send;
94  VLC vlc;
95  GetBitContext gb;
96  int prev, fsym;
97 
98  if ((ret = build_huff(huff, &vlc, &fsym, 1024)) < 0) {
99  av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
100  return ret;
101  }
102  if (fsym >= 0) { // build_huff reported a symbol to fill slices with
103  send = 0;
104  for (slice = 0; slice < c->slices; slice++) {
105  uint16_t *dest;
106 
107  sstart = send;
108  send = (height * (slice + 1) / c->slices);
109  dest = dst + sstart * stride;
110 
111  prev = 0x200;
112  for (j = sstart; j < send; j++) {
113  for (i = 0; i < width; i++) {
114  pix = fsym;
115  if (use_pred) {
116  prev += pix;
117  prev &= 0x3FF;
118  pix = prev;
119  }
120  dest[i] = pix;
121  }
122  dest += stride;
123  }
124  }
125  return 0;
126  }
127 
128  send = 0;
129  for (slice = 0; slice < c->slices; slice++) {
130  uint16_t *dest;
131  int slice_data_start, slice_data_end, slice_size;
132 
133  sstart = send;
134  send = (height * (slice + 1) / c->slices);
135  dest = dst + sstart * stride;
136 
137  // slice offset and size validation was done earlier
138  slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
139  slice_data_end = AV_RL32(src + slice * 4);
140  slice_size = slice_data_end - slice_data_start;
141 
142  if (!slice_size) {
143  av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
144  "yet a slice has a length of zero.\n");
145  goto fail;
146  }
147 
148  memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
149  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
150  (uint32_t *)(src + slice_data_start + c->slices * 4),
151  (slice_data_end - slice_data_start + 3) >> 2);
152  init_get_bits(&gb, c->slice_bits, slice_size * 8);
153 
154  prev = 0x200;
155  for (j = sstart; j < send; j++) {
156  for (i = 0; i < width; i++) {
157  pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
158  if (pix < 0) {
159  av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
160  goto fail;
161  }
162  if (use_pred) {
163  prev += pix;
164  prev &= 0x3FF;
165  pix = prev;
166  }
167  dest[i] = pix;
168  }
169  dest += stride;
170  if (get_bits_left(&gb) < 0) {
172  "Slice decoding ran out of bits\n");
173  goto fail;
174  }
175  }
176  if (get_bits_left(&gb) > 32)
178  "%d bits left after decoding slice\n", get_bits_left(&gb));
179  }
180 
181  ff_free_vlc(&vlc);
182 
183  return 0;
184 fail:
185  ff_free_vlc(&vlc);
186  return AVERROR_INVALIDDATA;
187 }
188 
189 static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
190 {
191  const int is_luma = (pix_fmt == AV_PIX_FMT_YUV420P) && !plane_no;
192 
193  if (interlaced)
194  return ~(1 + 2 * is_luma);
195 
196  return ~is_luma;
197 }
198 
199 static int decode_plane(UtvideoContext *c, int plane_no,
200  uint8_t *dst, ptrdiff_t stride,
201  int width, int height,
202  const uint8_t *src, int use_pred)
203 {
204  int i, j, slice, pix;
205  int sstart, send;
206  VLC vlc;
207  GetBitContext gb;
208  int ret, prev, fsym;
209  const int cmask = compute_cmask(plane_no, c->interlaced, c->avctx->pix_fmt);
210 
211  if (c->pack) {
212  send = 0;
213  for (slice = 0; slice < c->slices; slice++) {
214  GetBitContext cbit, pbit;
215  uint8_t *dest, *p;
216 
217  ret = init_get_bits8_le(&cbit, c->control_stream[plane_no][slice], c->control_stream_size[plane_no][slice]);
218  if (ret < 0)
219  return ret;
220 
221  ret = init_get_bits8_le(&pbit, c->packed_stream[plane_no][slice], c->packed_stream_size[plane_no][slice]);
222  if (ret < 0)
223  return ret;
224 
225  sstart = send;
226  send = (height * (slice + 1) / c->slices) & cmask;
227  dest = dst + sstart * stride;
228 
229  if (3 * ((dst + send * stride - dest + 7)/8) > get_bits_left(&cbit))
230  return AVERROR_INVALIDDATA;
231 
232  for (p = dest; p < dst + send * stride; p += 8) {
233  int bits = get_bits_le(&cbit, 3);
234 
235  if (bits == 0) {
236  *(uint64_t *) p = 0;
237  } else {
238  uint32_t sub = 0x80 >> (8 - (bits + 1)), add;
239  int k;
240 
241  if ((bits + 1) * 8 > get_bits_left(&pbit))
242  return AVERROR_INVALIDDATA;
243 
244  for (k = 0; k < 8; k++) {
245 
246  p[k] = get_bits_le(&pbit, bits + 1);
247  add = (~p[k] & sub) << (8 - bits);
248  p[k] -= sub;
249  p[k] += add;
250  }
251  }
252  }
253  }
254 
255  return 0;
256  }
257 
258  if (build_huff(src, &vlc, &fsym, 256)) {
259  av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
260  return AVERROR_INVALIDDATA;
261  }
262  if (fsym >= 0) { // build_huff reported a symbol to fill slices with
263  send = 0;
264  for (slice = 0; slice < c->slices; slice++) {
265  uint8_t *dest;
266 
267  sstart = send;
268  send = (height * (slice + 1) / c->slices) & cmask;
269  dest = dst + sstart * stride;
270 
271  prev = 0x80;
272  for (j = sstart; j < send; j++) {
273  for (i = 0; i < width; i++) {
274  pix = fsym;
275  if (use_pred) {
276  prev += (unsigned)pix;
277  pix = prev;
278  }
279  dest[i] = pix;
280  }
281  dest += stride;
282  }
283  }
284  return 0;
285  }
286 
287  src += 256;
288 
289  send = 0;
290  for (slice = 0; slice < c->slices; slice++) {
291  uint8_t *dest;
292  int slice_data_start, slice_data_end, slice_size;
293 
294  sstart = send;
295  send = (height * (slice + 1) / c->slices) & cmask;
296  dest = dst + sstart * stride;
297 
298  // slice offset and size validation was done earlier
299  slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
300  slice_data_end = AV_RL32(src + slice * 4);
301  slice_size = slice_data_end - slice_data_start;
302 
303  if (!slice_size) {
304  av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
305  "yet a slice has a length of zero.\n");
306  goto fail;
307  }
308 
309  memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
310  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
311  (uint32_t *)(src + slice_data_start + c->slices * 4),
312  (slice_data_end - slice_data_start + 3) >> 2);
313  init_get_bits(&gb, c->slice_bits, slice_size * 8);
314 
315  prev = 0x80;
316  for (j = sstart; j < send; j++) {
317  for (i = 0; i < width; i++) {
318  pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
319  if (pix < 0) {
320  av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
321  goto fail;
322  }
323  if (use_pred) {
324  prev += pix;
325  pix = prev;
326  }
327  dest[i] = pix;
328  }
329  if (get_bits_left(&gb) < 0) {
331  "Slice decoding ran out of bits\n");
332  goto fail;
333  }
334  dest += stride;
335  }
336  if (get_bits_left(&gb) > 32)
338  "%d bits left after decoding slice\n", get_bits_left(&gb));
339  }
340 
341  ff_free_vlc(&vlc);
342 
343  return 0;
344 fail:
345  ff_free_vlc(&vlc);
346  return AVERROR_INVALIDDATA;
347 }
348 
349 #undef A
350 #undef B
351 #undef C
352 
354  int width, int height, int slices, int rmode)
355 {
356  int i, j, slice;
357  int A, B, C;
358  uint8_t *bsrc;
359  int slice_start, slice_height;
360  const int cmask = ~rmode;
361 
362  for (slice = 0; slice < slices; slice++) {
363  slice_start = ((slice * height) / slices) & cmask;
364  slice_height = ((((slice + 1) * height) / slices) & cmask) -
365  slice_start;
366 
367  if (!slice_height)
368  continue;
369  bsrc = src + slice_start * stride;
370 
371  // first line - left neighbour prediction
372  bsrc[0] += 0x80;
373  c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
374  bsrc += stride;
375  if (slice_height <= 1)
376  continue;
377  // second line - first element has top prediction, the rest uses median
378  C = bsrc[-stride];
379  bsrc[0] += C;
380  A = bsrc[0];
381  for (i = 1; i < FFMIN(width, 16); i++) { /* scalar loop (DSP need align 16) */
382  B = bsrc[i - stride];
383  bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
384  C = B;
385  A = bsrc[i];
386  }
387  if (width > 16)
388  c->llviddsp.add_median_pred(bsrc + 16, bsrc - stride + 16,
389  bsrc + 16, width - 16, &A, &B);
390 
391  bsrc += stride;
392  // the rest of lines use continuous median prediction
393  for (j = 2; j < slice_height; j++) {
394  c->llviddsp.add_median_pred(bsrc, bsrc - stride,
395  bsrc, width, &A, &B);
396  bsrc += stride;
397  }
398  }
399 }
400 
401 /* UtVideo interlaced mode treats every two lines as a single one,
402  * so restoring function should take care of possible padding between
403  * two parts of the same "line".
404  */
406  int width, int height, int slices, int rmode)
407 {
408  int i, j, slice;
409  int A, B, C;
410  uint8_t *bsrc;
411  int slice_start, slice_height;
412  const int cmask = ~(rmode ? 3 : 1);
413  const ptrdiff_t stride2 = stride << 1;
414 
415  for (slice = 0; slice < slices; slice++) {
416  slice_start = ((slice * height) / slices) & cmask;
417  slice_height = ((((slice + 1) * height) / slices) & cmask) -
418  slice_start;
419  slice_height >>= 1;
420  if (!slice_height)
421  continue;
422 
423  bsrc = src + slice_start * stride;
424 
425  // first line - left neighbour prediction
426  bsrc[0] += 0x80;
427  A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
428  c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
429  bsrc += stride2;
430  if (slice_height <= 1)
431  continue;
432  // second line - first element has top prediction, the rest uses median
433  C = bsrc[-stride2];
434  bsrc[0] += C;
435  A = bsrc[0];
436  for (i = 1; i < FFMIN(width, 16); i++) { /* scalar loop (DSP need align 16) */
437  B = bsrc[i - stride2];
438  bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
439  C = B;
440  A = bsrc[i];
441  }
442  if (width > 16)
443  c->llviddsp.add_median_pred(bsrc + 16, bsrc - stride2 + 16,
444  bsrc + 16, width - 16, &A, &B);
445 
446  c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
447  bsrc + stride, width, &A, &B);
448  bsrc += stride2;
449  // the rest of lines use continuous median prediction
450  for (j = 2; j < slice_height; j++) {
451  c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
452  bsrc, width, &A, &B);
453  c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
454  bsrc + stride, width, &A, &B);
455  bsrc += stride2;
456  }
457  }
458 }
459 
461  int width, int height, int slices, int rmode)
462 {
463  int i, j, slice;
464  int A, B, C;
465  uint8_t *bsrc;
466  int slice_start, slice_height;
467  const int cmask = ~rmode;
468  int min_width = FFMIN(width, 32);
469 
470  for (slice = 0; slice < slices; slice++) {
471  slice_start = ((slice * height) / slices) & cmask;
472  slice_height = ((((slice + 1) * height) / slices) & cmask) -
473  slice_start;
474 
475  if (!slice_height)
476  continue;
477  bsrc = src + slice_start * stride;
478 
479  // first line - left neighbour prediction
480  bsrc[0] += 0x80;
481  c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
482  bsrc += stride;
483  if (slice_height <= 1)
484  continue;
485  for (j = 1; j < slice_height; j++) {
486  // second line - first element has top prediction, the rest uses gradient
487  bsrc[0] = (bsrc[0] + bsrc[-stride]) & 0xFF;
488  for (i = 1; i < min_width; i++) { /* dsp need align 32 */
489  A = bsrc[i - stride];
490  B = bsrc[i - (stride + 1)];
491  C = bsrc[i - 1];
492  bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
493  }
494  if (width > 32)
495  c->llviddsp.add_gradient_pred(bsrc + 32, stride, width - 32);
496  bsrc += stride;
497  }
498  }
499 }
500 
502  int width, int height, int slices, int rmode)
503 {
504  int i, j, slice;
505  int A, B, C;
506  uint8_t *bsrc;
507  int slice_start, slice_height;
508  const int cmask = ~(rmode ? 3 : 1);
509  const ptrdiff_t stride2 = stride << 1;
510  int min_width = FFMIN(width, 32);
511 
512  for (slice = 0; slice < slices; slice++) {
513  slice_start = ((slice * height) / slices) & cmask;
514  slice_height = ((((slice + 1) * height) / slices) & cmask) -
515  slice_start;
516  slice_height >>= 1;
517  if (!slice_height)
518  continue;
519 
520  bsrc = src + slice_start * stride;
521 
522  // first line - left neighbour prediction
523  bsrc[0] += 0x80;
524  A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
525  c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
526  bsrc += stride2;
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[-stride2]) & 0xFF;
532  for (i = 1; i < min_width; i++) { /* dsp need align 32 */
533  A = bsrc[i - stride2];
534  B = bsrc[i - (stride2 + 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, stride2, width - 32);
540 
541  A = bsrc[-stride];
542  B = bsrc[-(1 + stride + stride - width)];
543  C = bsrc[width - 1];
544  bsrc[stride] = (A - B + C + bsrc[stride]) & 0xFF;
545  for (i = 1; i < width; i++) {
546  A = bsrc[i - stride];
547  B = bsrc[i - (1 + stride)];
548  C = bsrc[i - 1 + stride];
549  bsrc[i + stride] = (A - B + C + bsrc[i + stride]) & 0xFF;
550  }
551  bsrc += stride2;
552  }
553  }
554 }
555 
556 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
557  AVPacket *avpkt)
558 {
559  const uint8_t *buf = avpkt->data;
560  int buf_size = avpkt->size;
561  UtvideoContext *c = avctx->priv_data;
562  int i, j;
563  const uint8_t *plane_start[5];
564  int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
565  int ret;
566  GetByteContext gb;
567  ThreadFrame frame = { .f = data };
568 
569  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
570  return ret;
571 
572  /* parse plane structure to get frame flags and validate slice offsets */
573  bytestream2_init(&gb, buf, buf_size);
574 
575  if (c->pack) {
576  const uint8_t *packed_stream;
577  const uint8_t *control_stream;
578  GetByteContext pb;
579  uint32_t nb_cbs;
580  int left;
581 
582  c->frame_info = PRED_GRADIENT << 8;
583 
584  if (bytestream2_get_byte(&gb) != 1)
585  return AVERROR_INVALIDDATA;
586  bytestream2_skip(&gb, 3);
587  c->offset = bytestream2_get_le32(&gb);
588 
589  if (buf_size <= c->offset + 8LL)
590  return AVERROR_INVALIDDATA;
591 
592  bytestream2_init(&pb, buf + 8 + c->offset, buf_size - 8 - c->offset);
593 
594  nb_cbs = bytestream2_get_le32(&pb);
595  if (nb_cbs > c->offset)
596  return AVERROR_INVALIDDATA;
597 
598  packed_stream = buf + 8;
599  control_stream = packed_stream + (c->offset - nb_cbs);
600  left = control_stream - packed_stream;
601 
602  for (i = 0; i < c->planes; i++) {
603  for (j = 0; j < c->slices; j++) {
604  c->packed_stream[i][j] = packed_stream;
605  c->packed_stream_size[i][j] = bytestream2_get_le32(&pb);
606  if (c->packed_stream_size[i][j] > left)
607  return AVERROR_INVALIDDATA;
608  left -= c->packed_stream_size[i][j];
609  packed_stream += c->packed_stream_size[i][j];
610  }
611  }
612 
613  left = buf + buf_size - control_stream;
614 
615  for (i = 0; i < c->planes; i++) {
616  for (j = 0; j < c->slices; j++) {
617  c->control_stream[i][j] = control_stream;
618  c->control_stream_size[i][j] = bytestream2_get_le32(&pb);
619  if (c->control_stream_size[i][j] > left)
620  return AVERROR_INVALIDDATA;
621  left -= c->control_stream_size[i][j];
622  control_stream += c->control_stream_size[i][j];
623  }
624  }
625  } else if (c->pro) {
627  av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
628  return AVERROR_INVALIDDATA;
629  }
630  c->frame_info = bytestream2_get_le32u(&gb);
631  c->slices = ((c->frame_info >> 16) & 0xff) + 1;
632  for (i = 0; i < c->planes; i++) {
633  plane_start[i] = gb.buffer;
634  if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
635  av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
636  return AVERROR_INVALIDDATA;
637  }
638  slice_start = 0;
639  slice_end = 0;
640  for (j = 0; j < c->slices; j++) {
641  slice_end = bytestream2_get_le32u(&gb);
642  if (slice_end < 0 || slice_end < slice_start ||
643  bytestream2_get_bytes_left(&gb) < slice_end + 1024LL) {
644  av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
645  return AVERROR_INVALIDDATA;
646  }
647  slice_size = slice_end - slice_start;
648  slice_start = slice_end;
649  max_slice_size = FFMAX(max_slice_size, slice_size);
650  }
651  plane_size = slice_end;
652  bytestream2_skipu(&gb, plane_size);
653  bytestream2_skipu(&gb, 1024);
654  }
655  plane_start[c->planes] = gb.buffer;
656  } else {
657  for (i = 0; i < c->planes; i++) {
658  plane_start[i] = gb.buffer;
659  if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
660  av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
661  return AVERROR_INVALIDDATA;
662  }
663  bytestream2_skipu(&gb, 256);
664  slice_start = 0;
665  slice_end = 0;
666  for (j = 0; j < c->slices; j++) {
667  slice_end = bytestream2_get_le32u(&gb);
668  if (slice_end < 0 || slice_end < slice_start ||
669  bytestream2_get_bytes_left(&gb) < slice_end) {
670  av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
671  return AVERROR_INVALIDDATA;
672  }
673  slice_size = slice_end - slice_start;
674  slice_start = slice_end;
675  max_slice_size = FFMAX(max_slice_size, slice_size);
676  }
677  plane_size = slice_end;
678  bytestream2_skipu(&gb, plane_size);
679  }
680  plane_start[c->planes] = gb.buffer;
682  av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
683  return AVERROR_INVALIDDATA;
684  }
685  c->frame_info = bytestream2_get_le32u(&gb);
686  }
687  av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
688  c->frame_info);
689 
690  c->frame_pred = (c->frame_info >> 8) & 3;
691 
692  max_slice_size += 4*avctx->width;
693 
694  if (!c->pack) {
696  max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
697 
698  if (!c->slice_bits) {
699  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
700  return AVERROR(ENOMEM);
701  }
702  }
703 
704  switch (c->avctx->pix_fmt) {
705  case AV_PIX_FMT_GBRP:
706  case AV_PIX_FMT_GBRAP:
707  for (i = 0; i < c->planes; i++) {
708  ret = decode_plane(c, i, frame.f->data[i],
709  frame.f->linesize[i], avctx->width,
710  avctx->height, plane_start[i],
711  c->frame_pred == PRED_LEFT);
712  if (ret)
713  return ret;
714  if (c->frame_pred == PRED_MEDIAN) {
715  if (!c->interlaced) {
716  restore_median_planar(c, frame.f->data[i],
717  frame.f->linesize[i], avctx->width,
718  avctx->height, c->slices, 0);
719  } else {
720  restore_median_planar_il(c, frame.f->data[i],
721  frame.f->linesize[i],
722  avctx->width, avctx->height, c->slices,
723  0);
724  }
725  } else if (c->frame_pred == PRED_GRADIENT) {
726  if (!c->interlaced) {
727  restore_gradient_planar(c, frame.f->data[i],
728  frame.f->linesize[i], avctx->width,
729  avctx->height, c->slices, 0);
730  } else {
731  restore_gradient_planar_il(c, frame.f->data[i],
732  frame.f->linesize[i],
733  avctx->width, avctx->height, c->slices,
734  0);
735  }
736  }
737  }
738  c->utdsp.restore_rgb_planes(frame.f->data[2], frame.f->data[0], frame.f->data[1],
739  frame.f->linesize[2], frame.f->linesize[0], frame.f->linesize[1],
740  avctx->width, avctx->height);
741  break;
742  case AV_PIX_FMT_GBRAP10:
743  case AV_PIX_FMT_GBRP10:
744  for (i = 0; i < c->planes; i++) {
745  ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i],
746  frame.f->linesize[i] / 2, avctx->width,
747  avctx->height, plane_start[i],
748  plane_start[i + 1] - 1024,
749  c->frame_pred == PRED_LEFT);
750  if (ret)
751  return ret;
752  }
753  c->utdsp.restore_rgb_planes10((uint16_t *)frame.f->data[2], (uint16_t *)frame.f->data[0], (uint16_t *)frame.f->data[1],
754  frame.f->linesize[2] / 2, frame.f->linesize[0] / 2, frame.f->linesize[1] / 2,
755  avctx->width, avctx->height);
756  break;
757  case AV_PIX_FMT_YUV420P:
758  for (i = 0; i < 3; i++) {
759  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
760  avctx->width >> !!i, avctx->height >> !!i,
761  plane_start[i], c->frame_pred == PRED_LEFT);
762  if (ret)
763  return ret;
764  if (c->frame_pred == PRED_MEDIAN) {
765  if (!c->interlaced) {
766  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
767  avctx->width >> !!i, avctx->height >> !!i,
768  c->slices, !i);
769  } else {
770  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
771  avctx->width >> !!i,
772  avctx->height >> !!i,
773  c->slices, !i);
774  }
775  } else if (c->frame_pred == PRED_GRADIENT) {
776  if (!c->interlaced) {
777  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
778  avctx->width >> !!i, avctx->height >> !!i,
779  c->slices, !i);
780  } else {
781  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
782  avctx->width >> !!i,
783  avctx->height >> !!i,
784  c->slices, !i);
785  }
786  }
787  }
788  break;
789  case AV_PIX_FMT_YUV422P:
790  for (i = 0; i < 3; i++) {
791  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
792  avctx->width >> !!i, avctx->height,
793  plane_start[i], c->frame_pred == PRED_LEFT);
794  if (ret)
795  return ret;
796  if (c->frame_pred == PRED_MEDIAN) {
797  if (!c->interlaced) {
798  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
799  avctx->width >> !!i, avctx->height,
800  c->slices, 0);
801  } else {
802  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
803  avctx->width >> !!i, avctx->height,
804  c->slices, 0);
805  }
806  } else if (c->frame_pred == PRED_GRADIENT) {
807  if (!c->interlaced) {
808  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
809  avctx->width >> !!i, avctx->height,
810  c->slices, 0);
811  } else {
812  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
813  avctx->width >> !!i, avctx->height,
814  c->slices, 0);
815  }
816  }
817  }
818  break;
819  case AV_PIX_FMT_YUV444P:
820  for (i = 0; i < 3; i++) {
821  ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
822  avctx->width, avctx->height,
823  plane_start[i], c->frame_pred == PRED_LEFT);
824  if (ret)
825  return ret;
826  if (c->frame_pred == PRED_MEDIAN) {
827  if (!c->interlaced) {
828  restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
829  avctx->width, avctx->height,
830  c->slices, 0);
831  } else {
832  restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
833  avctx->width, avctx->height,
834  c->slices, 0);
835  }
836  } else if (c->frame_pred == PRED_GRADIENT) {
837  if (!c->interlaced) {
838  restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
839  avctx->width, avctx->height,
840  c->slices, 0);
841  } else {
842  restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
843  avctx->width, avctx->height,
844  c->slices, 0);
845  }
846  }
847  }
848  break;
850  for (i = 0; i < 3; i++) {
851  ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], frame.f->linesize[i] / 2,
852  avctx->width >> !!i, avctx->height >> !!i,
853  plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
854  if (ret)
855  return ret;
856  }
857  break;
859  for (i = 0; i < 3; i++) {
860  ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], frame.f->linesize[i] / 2,
861  avctx->width >> !!i, avctx->height,
862  plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
863  if (ret)
864  return ret;
865  }
866  break;
867  }
868 
869  frame.f->key_frame = 1;
870  frame.f->pict_type = AV_PICTURE_TYPE_I;
871  frame.f->interlaced_frame = !!c->interlaced;
872 
873  *got_frame = 1;
874 
875  /* always report that the buffer was completely consumed */
876  return buf_size;
877 }
878 
880 {
881  UtvideoContext * const c = avctx->priv_data;
882  int h_shift, v_shift;
883 
884  c->avctx = avctx;
885 
887  ff_bswapdsp_init(&c->bdsp);
889 
890  c->slice_bits_size = 0;
891 
892  switch (avctx->codec_tag) {
893  case MKTAG('U', 'L', 'R', 'G'):
894  c->planes = 3;
895  avctx->pix_fmt = AV_PIX_FMT_GBRP;
896  break;
897  case MKTAG('U', 'L', 'R', 'A'):
898  c->planes = 4;
899  avctx->pix_fmt = AV_PIX_FMT_GBRAP;
900  break;
901  case MKTAG('U', 'L', 'Y', '0'):
902  c->planes = 3;
903  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
904  avctx->colorspace = AVCOL_SPC_BT470BG;
905  break;
906  case MKTAG('U', 'L', 'Y', '2'):
907  c->planes = 3;
908  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
909  avctx->colorspace = AVCOL_SPC_BT470BG;
910  break;
911  case MKTAG('U', 'L', 'Y', '4'):
912  c->planes = 3;
913  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
914  avctx->colorspace = AVCOL_SPC_BT470BG;
915  break;
916  case MKTAG('U', 'Q', 'Y', '0'):
917  c->planes = 3;
918  c->pro = 1;
919  avctx->pix_fmt = AV_PIX_FMT_YUV420P10;
920  break;
921  case MKTAG('U', 'Q', 'Y', '2'):
922  c->planes = 3;
923  c->pro = 1;
924  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
925  break;
926  case MKTAG('U', 'Q', 'R', 'G'):
927  c->planes = 3;
928  c->pro = 1;
929  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
930  break;
931  case MKTAG('U', 'Q', 'R', 'A'):
932  c->planes = 4;
933  c->pro = 1;
934  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
935  break;
936  case MKTAG('U', 'L', 'H', '0'):
937  c->planes = 3;
938  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
939  avctx->colorspace = AVCOL_SPC_BT709;
940  break;
941  case MKTAG('U', 'L', 'H', '2'):
942  c->planes = 3;
943  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
944  avctx->colorspace = AVCOL_SPC_BT709;
945  break;
946  case MKTAG('U', 'L', 'H', '4'):
947  c->planes = 3;
948  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
949  avctx->colorspace = AVCOL_SPC_BT709;
950  break;
951  case MKTAG('U', 'M', 'Y', '2'):
952  c->planes = 3;
953  c->pack = 1;
954  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
955  avctx->colorspace = AVCOL_SPC_BT470BG;
956  break;
957  case MKTAG('U', 'M', 'H', '2'):
958  c->planes = 3;
959  c->pack = 1;
960  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
961  avctx->colorspace = AVCOL_SPC_BT709;
962  break;
963  case MKTAG('U', 'M', 'Y', '4'):
964  c->planes = 3;
965  c->pack = 1;
966  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
967  avctx->colorspace = AVCOL_SPC_BT470BG;
968  break;
969  case MKTAG('U', 'M', 'H', '4'):
970  c->planes = 3;
971  c->pack = 1;
972  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
973  avctx->colorspace = AVCOL_SPC_BT709;
974  break;
975  case MKTAG('U', 'M', 'R', 'G'):
976  c->planes = 3;
977  c->pack = 1;
978  avctx->pix_fmt = AV_PIX_FMT_GBRP;
979  break;
980  case MKTAG('U', 'M', 'R', 'A'):
981  c->planes = 4;
982  c->pack = 1;
983  avctx->pix_fmt = AV_PIX_FMT_GBRAP;
984  break;
985  default:
986  av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
987  avctx->codec_tag);
988  return AVERROR_INVALIDDATA;
989  }
990 
991  av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &h_shift, &v_shift);
992  if ((avctx->width & ((1<<h_shift)-1)) ||
993  (avctx->height & ((1<<v_shift)-1))) {
994  avpriv_request_sample(avctx, "Odd dimensions");
995  return AVERROR_PATCHWELCOME;
996  }
997 
998  if (c->pack && avctx->extradata_size >= 16) {
999  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1000  avctx->extradata[3], avctx->extradata[2],
1001  avctx->extradata[1], avctx->extradata[0]);
1002  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1003  AV_RB32(avctx->extradata + 4));
1004  c->compression = avctx->extradata[8];
1005  if (c->compression != 2)
1006  avpriv_request_sample(avctx, "Unknown compression type");
1007  c->slices = avctx->extradata[9] + 1;
1008  } else if (!c->pro && avctx->extradata_size >= 16) {
1009  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1010  avctx->extradata[3], avctx->extradata[2],
1011  avctx->extradata[1], avctx->extradata[0]);
1012  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1013  AV_RB32(avctx->extradata + 4));
1014  c->frame_info_size = AV_RL32(avctx->extradata + 8);
1015  c->flags = AV_RL32(avctx->extradata + 12);
1016 
1017  if (c->frame_info_size != 4)
1018  avpriv_request_sample(avctx, "Frame info not 4 bytes");
1019  av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
1020  c->slices = (c->flags >> 24) + 1;
1021  c->compression = c->flags & 1;
1022  c->interlaced = c->flags & 0x800;
1023  } else if (c->pro && avctx->extradata_size == 8) {
1024  av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
1025  avctx->extradata[3], avctx->extradata[2],
1026  avctx->extradata[1], avctx->extradata[0]);
1027  av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
1028  AV_RB32(avctx->extradata + 4));
1029  c->interlaced = 0;
1030  c->frame_info_size = 4;
1031  } else {
1032  av_log(avctx, AV_LOG_ERROR,
1033  "Insufficient extradata size %d, should be at least 16\n",
1034  avctx->extradata_size);
1035  return AVERROR_INVALIDDATA;
1036  }
1037 
1038  return 0;
1039 }
1040 
1042 {
1043  UtvideoContext * const c = avctx->priv_data;
1044 
1045  av_freep(&c->slice_bits);
1046 
1047  return 0;
1048 }
1049 
1051  .name = "utvideo",
1052  .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
1053  .type = AVMEDIA_TYPE_VIDEO,
1054  .id = AV_CODEC_ID_UTVIDEO,
1055  .priv_data_size = sizeof(UtvideoContext),
1056  .init = decode_init,
1057  .close = decode_end,
1058  .decode = decode_frame,
1059  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1060  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1061 };
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:514
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:405
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
static enum AVPixelFormat pix_fmt
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:419
uint32_t flags
Definition: utvideo.h:72
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:200
AVFrame * f
Definition: thread.h:35
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:518
#define avpriv_request_sample(...)
int slice_bits_size
Definition: utvideo.h:83
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
int size
Definition: packet.h:364
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
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
static av_cold int decode_end(AVCodecContext *avctx)
Definition: utvideodec.c:1041
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AVCodec.
Definition: codec.h:190
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
int interlaced
Definition: utvideo.h:76
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT uint8_t const uint8_t const uint8_t * bsrc
Definition: input.c:398
av_cold void ff_utvideodsp_init(UTVideoDSPContext *c)
Definition: utvideodsp.c:75
static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned nb_elems)
Definition: utvideodec.c:43
#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:88
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.h:25
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:460
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
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:501
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:627
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:91
uint32_t frame_info
Definition: utvideo.h:72
#define height
uint8_t * data
Definition: packet.h:363
const uint8_t * buffer
Definition: bytestream.h:34
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:455
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:86
#define A(x)
Definition: vp56_arith.h:28
#define av_log(a,...)
void(* add_gradient_pred)(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
#define src
Definition: vp8dsp.c:254
BswapDSPContext bdsp
Definition: utvideo.h:68
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
static av_cold int decode_init(AVCodecContext *avctx)
Definition: utvideodec.c:879
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2601
#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:153
AVCodecContext * avctx
Definition: utvideo.h:66
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
const char * name
Name of the codec implementation.
Definition: codec.h:197
uint32_t frame_info_size
Definition: utvideo.h:72
uint8_t bits
Definition: vp3data.h:202
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:123
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:106
Definition: vlc.h:26
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames.The frames must then be freed with ff_thread_release_buffer().Otherwise decode directly into the user-supplied frames.Call ff_thread_report_progress() after some part of the current picture has decoded.A good place to put this is where draw_horiz_band() is called-add this if it isn't called anywhere
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:502
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
static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Definition: utvideodec.c:353
int compression
Definition: utvideo.h:75
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:391
#define FFMIN(a, b)
Definition: common.h:96
static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
Definition: utvideodec.c:189
uint8_t interlaced
Definition: mxfenc.c:2168
#define width
int width
picture width / height.
Definition: avcodec.h:699
size_t control_stream_size[4][256]
Definition: utvideo.h:88
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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
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
#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:556
Common Ut Video header.
int frame_pred
Definition: utvideo.h:77
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:339
uint32_t offset
Definition: utvideo.h:72
main external API structure.
Definition: avcodec.h:526
const uint8_t * control_stream[4][256]
Definition: utvideo.h:87
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:551
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2]...the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so...,+,-,+,-,+,+,-,+,-,+,...hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32-hcoeff[1]-hcoeff[2]-...a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2}an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||.........intra?||||:Block01:yes no||||:Block02:.................||||:Block03::y DC::ref index:||||:Block04::cb DC::motion x:||||.........:cr DC::motion y:||||.................|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------------------------------|||Y subbands||Cb subbands||Cr subbands||||------||------||------|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||------||------||------||||------||------||------|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||------||------||------||||------||------||------|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||------||------||------||||------||------||------|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------------------------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction------------|\Dequantization-------------------\||Reference frames|\IDWT|--------------|Motion\|||Frame 0||Frame 1||Compensation.OBMC v-------|--------------|--------------.\------> Frame n output Frame Frame<----------------------------------/|...|-------------------Range Coder:============Binary Range Coder:-------------------The implemented range coder is an adapted version based upon"Range encoding: an algorithm for removing redundancy from a digitised message."by G.N.N.Martin.The symbols encoded by the Snow range coder are bits(0|1).The associated probabilities are not fix but change depending on the symbol mix seen so far.bit seen|new state---------+-----------------------------------------------0|256-state_transition_table[256-old_state];1|state_transition_table[old_state];state_transition_table={0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:-------------------------FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1.the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:206
#define VLC_BITS
int extradata_size
Definition: avcodec.h:628
void ff_llviddsp_init(LLVidDSPContext *c)
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1154
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
#define mid_pred
Definition: mathops.h:97
uint8_t * slice_bits
Definition: utvideo.h:82
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition: get_bits.h:420
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
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:199
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:322
LLVidDSPContext llviddsp
Definition: utvideo.h:69
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
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 int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer, int byte_size)
Definition: get_bits.h:685
size_t packed_stream_size[4][256]
Definition: utvideo.h:86
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:215
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2035
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
void * priv_data
Definition: avcodec.h:553
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:386
UTVideoDSPContext utdsp
Definition: utvideo.h:67
static float add(float src0, float src1)
#define av_freep(p)
const uint8_t * packed_stream[4][256]
Definition: utvideo.h:85
static float sub(float src0, float src1)
#define stride
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
#define MKTAG(a, b, c, d)
Definition: common.h:406
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:91
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVCodec ff_utvideo_decoder
Definition: utvideodec.c:1050
This structure stores compressed data.
Definition: packet.h:340
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:358
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
int i
Definition: input.c:407