3 * Copyright (c) 2011 Konstantin Shishkov
5 * This file is part of FFmpeg.
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.
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.
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
30 #define UNCHECKED_BITSTREAM_READER 1
32 #include "libavutil/intreadwrite.h"
35 #include "bytestream.h"
41 static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
52 for (i = 0; i < 1024; i++) {
56 qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len);
64 while (he[last].len == 255 && last)
67 if (he[last].len > 32) {
72 for (i = last; i >= 0; i--) {
73 codes[i] = code >> (32 - he[i].len);
76 code += 0x80000000u >> (he[i].len - 1);
79 return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
80 bits, sizeof(*bits), sizeof(*bits),
81 codes, sizeof(*codes), sizeof(*codes),
82 syms, sizeof(*syms), sizeof(*syms), 0);
85 static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
96 for (i = 0; i < 256; i++) {
100 qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
108 while (he[last].len == 255 && last)
111 if (he[last].len > 32)
115 for (i = last; i >= 0; i--) {
116 codes[i] = code >> (32 - he[i].len);
119 code += 0x80000000u >> (he[i].len - 1);
122 return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
123 bits, sizeof(*bits), sizeof(*bits),
124 codes, sizeof(*codes), sizeof(*codes),
125 syms, sizeof(*syms), sizeof(*syms), 0);
128 static int decode_plane10(UtvideoContext *c, int plane_no,
129 uint16_t *dst, int step, ptrdiff_t stride,
130 int width, int height,
131 const uint8_t *src, const uint8_t *huff,
134 int i, j, slice, pix, ret;
140 if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) {
141 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
144 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
146 for (slice = 0; slice < c->slices; slice++) {
150 send = (height * (slice + 1) / c->slices);
151 dest = dst + sstart * stride;
154 for (j = sstart; j < send; j++) {
155 for (i = 0; i < width * step; i += step) {
171 for (slice = 0; slice < c->slices; slice++) {
173 int slice_data_start, slice_data_end, slice_size;
176 send = (height * (slice + 1) / c->slices);
177 dest = dst + sstart * stride;
179 // slice offset and size validation was done earlier
180 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
181 slice_data_end = AV_RL32(src + slice * 4);
182 slice_size = slice_data_end - slice_data_start;
185 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
186 "yet a slice has a length of zero.\n");
190 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
191 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
192 (uint32_t *)(src + slice_data_start + c->slices * 4),
193 (slice_data_end - slice_data_start + 3) >> 2);
194 init_get_bits(&gb, c->slice_bits, slice_size * 8);
197 for (j = sstart; j < send; j++) {
198 int ws = width * step;
199 for (i = 0; i < ws; i += step) {
200 pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
202 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
213 if (get_bits_left(&gb) < 0) {
214 av_log(c->avctx, AV_LOG_ERROR,
215 "Slice decoding ran out of bits\n");
219 if (get_bits_left(&gb) > 32)
220 av_log(c->avctx, AV_LOG_WARNING,
221 "%d bits left after decoding slice\n", get_bits_left(&gb));
229 return AVERROR_INVALIDDATA;
232 static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
234 const int is_luma = (pix_fmt == AV_PIX_FMT_YUV420P) && !plane_no;
237 return ~(1 + 2 * is_luma);
242 static int decode_plane(UtvideoContext *c, int plane_no,
243 uint8_t *dst, int step, ptrdiff_t stride,
244 int width, int height,
245 const uint8_t *src, int use_pred)
247 int i, j, slice, pix;
252 const int cmask = compute_cmask(plane_no, c->interlaced, c->avctx->pix_fmt);
254 if (build_huff(src, &vlc, &fsym)) {
255 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
256 return AVERROR_INVALIDDATA;
258 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
260 for (slice = 0; slice < c->slices; slice++) {
264 send = (height * (slice + 1) / c->slices) & cmask;
265 dest = dst + sstart * stride;
268 for (j = sstart; j < send; j++) {
269 for (i = 0; i < width * step; i += step) {
286 for (slice = 0; slice < c->slices; slice++) {
288 int slice_data_start, slice_data_end, slice_size;
291 send = (height * (slice + 1) / c->slices) & cmask;
292 dest = dst + sstart * stride;
294 // slice offset and size validation was done earlier
295 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
296 slice_data_end = AV_RL32(src + slice * 4);
297 slice_size = slice_data_end - slice_data_start;
300 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
301 "yet a slice has a length of zero.\n");
305 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
306 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
307 (uint32_t *)(src + slice_data_start + c->slices * 4),
308 (slice_data_end - slice_data_start + 3) >> 2);
309 init_get_bits(&gb, c->slice_bits, slice_size * 8);
312 for (j = sstart; j < send; j++) {
313 int ws = width * step;
314 for (i = 0; i < ws; i += step) {
315 pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
317 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
326 if (get_bits_left(&gb) < 0) {
327 av_log(c->avctx, AV_LOG_ERROR,
328 "Slice decoding ran out of bits\n");
333 if (get_bits_left(&gb) > 32)
334 av_log(c->avctx, AV_LOG_WARNING,
335 "%d bits left after decoding slice\n", get_bits_left(&gb));
343 return AVERROR_INVALIDDATA;
350 static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
351 int width, int height, int slices, int rmode)
356 int slice_start, slice_height;
357 const int cmask = ~rmode;
359 for (slice = 0; slice < slices; slice++) {
360 slice_start = ((slice * height) / slices) & cmask;
361 slice_height = ((((slice + 1) * height) / slices) & cmask) -
366 bsrc = src + slice_start * stride;
368 // first line - left neighbour prediction
370 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
372 if (slice_height <= 1)
374 // second line - first element has top prediction, the rest uses median
378 for (i = 1; i < width; i++) {
379 B = bsrc[i - stride];
380 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
385 // the rest of lines use continuous median prediction
386 for (j = 2; j < slice_height; j++) {
387 c->llviddsp.add_median_pred(bsrc, bsrc - stride,
388 bsrc, width, &A, &B);
394 /* UtVideo interlaced mode treats every two lines as a single one,
395 * so restoring function should take care of possible padding between
396 * two parts of the same "line".
398 static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
399 int width, int height, int slices, int rmode)
404 int slice_start, slice_height;
405 const int cmask = ~(rmode ? 3 : 1);
406 const ptrdiff_t stride2 = stride << 1;
408 for (slice = 0; slice < slices; slice++) {
409 slice_start = ((slice * height) / slices) & cmask;
410 slice_height = ((((slice + 1) * height) / slices) & cmask) -
416 bsrc = src + slice_start * stride;
418 // first line - left neighbour prediction
420 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
421 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
423 if (slice_height <= 1)
425 // second line - first element has top prediction, the rest uses median
429 for (i = 1; i < width; i++) {
430 B = bsrc[i - stride2];
431 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
435 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
436 bsrc + stride, width, &A, &B);
438 // the rest of lines use continuous median prediction
439 for (j = 2; j < slice_height; j++) {
440 c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
441 bsrc, width, &A, &B);
442 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
443 bsrc + stride, width, &A, &B);
449 static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
450 int width, int height, int slices, int rmode)
455 int slice_start, slice_height;
456 const int cmask = ~rmode;
458 for (slice = 0; slice < slices; slice++) {
459 slice_start = ((slice * height) / slices) & cmask;
460 slice_height = ((((slice + 1) * height) / slices) & cmask) -
465 bsrc = src + slice_start * stride;
467 // first line - left neighbour prediction
469 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
471 if (slice_height <= 1)
473 for (j = 1; j < slice_height; j++) {
474 // second line - first element has top prediction, the rest uses gradient
475 bsrc[0] = (bsrc[0] + bsrc[-stride]) & 0xFF;
476 for (i = 1; i < width; i++) {
477 A = bsrc[i - stride];
478 B = bsrc[i - (stride + 1)];
480 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
487 static void restore_gradient_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
488 int width, int height, int slices, int rmode)
493 int slice_start, slice_height;
494 const int cmask = ~(rmode ? 3 : 1);
495 const ptrdiff_t stride2 = stride << 1;
497 for (slice = 0; slice < slices; slice++) {
498 slice_start = ((slice * height) / slices) & cmask;
499 slice_height = ((((slice + 1) * height) / slices) & cmask) -
505 bsrc = src + slice_start * stride;
507 // first line - left neighbour prediction
509 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
510 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
512 if (slice_height <= 1)
514 for (j = 1; j < slice_height; j++) {
515 // second line - first element has top prediction, the rest uses gradient
516 bsrc[0] = (bsrc[0] + bsrc[-stride2]) & 0xFF;
517 for (i = 1; i < width; i++) {
518 A = bsrc[i - stride2];
519 B = bsrc[i - (stride2 + 1)];
521 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
524 B = bsrc[-(1 + stride + stride - width)];
526 bsrc[stride] = (A - B + C + bsrc[stride]) & 0xFF;
527 for (i = 1; i < width; i++) {
528 A = bsrc[i - stride];
529 B = bsrc[i - (1 + stride)];
530 C = bsrc[i - 1 + stride];
531 bsrc[i + stride] = (A - B + C + bsrc[i + stride]) & 0xFF;
538 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
541 const uint8_t *buf = avpkt->data;
542 int buf_size = avpkt->size;
543 UtvideoContext *c = avctx->priv_data;
545 const uint8_t *plane_start[5];
546 int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
549 ThreadFrame frame = { .f = data };
551 if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
554 /* parse plane structure to get frame flags and validate slice offsets */
555 bytestream2_init(&gb, buf, buf_size);
557 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
558 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
559 return AVERROR_INVALIDDATA;
561 c->frame_info = bytestream2_get_le32u(&gb);
562 c->slices = ((c->frame_info >> 16) & 0xff) + 1;
563 for (i = 0; i < c->planes; i++) {
564 plane_start[i] = gb.buffer;
565 if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
566 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
567 return AVERROR_INVALIDDATA;
571 for (j = 0; j < c->slices; j++) {
572 slice_end = bytestream2_get_le32u(&gb);
573 if (slice_end < 0 || slice_end < slice_start ||
574 bytestream2_get_bytes_left(&gb) < slice_end) {
575 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
576 return AVERROR_INVALIDDATA;
578 slice_size = slice_end - slice_start;
579 slice_start = slice_end;
580 max_slice_size = FFMAX(max_slice_size, slice_size);
582 plane_size = slice_end;
583 bytestream2_skipu(&gb, plane_size);
584 bytestream2_skipu(&gb, 1024);
586 plane_start[c->planes] = gb.buffer;
588 for (i = 0; i < c->planes; i++) {
589 plane_start[i] = gb.buffer;
590 if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
591 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
592 return AVERROR_INVALIDDATA;
594 bytestream2_skipu(&gb, 256);
597 for (j = 0; j < c->slices; j++) {
598 slice_end = bytestream2_get_le32u(&gb);
599 if (slice_end < 0 || slice_end < slice_start ||
600 bytestream2_get_bytes_left(&gb) < slice_end) {
601 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
602 return AVERROR_INVALIDDATA;
604 slice_size = slice_end - slice_start;
605 slice_start = slice_end;
606 max_slice_size = FFMAX(max_slice_size, slice_size);
608 plane_size = slice_end;
609 bytestream2_skipu(&gb, plane_size);
611 plane_start[c->planes] = gb.buffer;
612 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
613 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
614 return AVERROR_INVALIDDATA;
616 c->frame_info = bytestream2_get_le32u(&gb);
618 av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
621 c->frame_pred = (c->frame_info >> 8) & 3;
623 max_slice_size += 4*avctx->width;
625 av_fast_malloc(&c->slice_bits, &c->slice_bits_size,
626 max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
628 if (!c->slice_bits) {
629 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
630 return AVERROR(ENOMEM);
633 switch (c->avctx->pix_fmt) {
634 case AV_PIX_FMT_GBRP:
635 case AV_PIX_FMT_GBRAP:
636 for (i = 0; i < c->planes; i++) {
637 ret = decode_plane(c, i, frame.f->data[i], 1,
638 frame.f->linesize[i], avctx->width,
639 avctx->height, plane_start[i],
640 c->frame_pred == PRED_LEFT);
643 if (c->frame_pred == PRED_MEDIAN) {
644 if (!c->interlaced) {
645 restore_median_planar(c, frame.f->data[i],
646 frame.f->linesize[i], avctx->width,
647 avctx->height, c->slices, 0);
649 restore_median_planar_il(c, frame.f->data[i],
650 frame.f->linesize[i],
651 avctx->width, avctx->height, c->slices,
654 } else if (c->frame_pred == PRED_GRADIENT) {
655 if (!c->interlaced) {
656 restore_gradient_planar(c, frame.f->data[i],
657 frame.f->linesize[i], avctx->width,
658 avctx->height, c->slices, 0);
660 restore_gradient_planar_il(c, frame.f->data[i],
661 frame.f->linesize[i],
662 avctx->width, avctx->height, c->slices,
667 c->utdsp.restore_rgb_planes(frame.f->data[2], frame.f->data[0], frame.f->data[1],
668 frame.f->linesize[2], frame.f->linesize[0], frame.f->linesize[1],
669 avctx->width, avctx->height);
671 case AV_PIX_FMT_GBRAP10:
672 case AV_PIX_FMT_GBRP10:
673 for (i = 0; i < c->planes; i++) {
674 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1,
675 frame.f->linesize[i] / 2, avctx->width,
676 avctx->height, plane_start[i],
677 plane_start[i + 1] - 1024,
678 c->frame_pred == PRED_LEFT);
682 c->utdsp.restore_rgb_planes10((uint16_t *)frame.f->data[2], (uint16_t *)frame.f->data[0], (uint16_t *)frame.f->data[1],
683 frame.f->linesize[2] / 2, frame.f->linesize[0] / 2, frame.f->linesize[1] / 2,
684 avctx->width, avctx->height);
686 case AV_PIX_FMT_YUV420P:
687 for (i = 0; i < 3; i++) {
688 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
689 avctx->width >> !!i, avctx->height >> !!i,
690 plane_start[i], c->frame_pred == PRED_LEFT);
693 if (c->frame_pred == PRED_MEDIAN) {
694 if (!c->interlaced) {
695 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
696 avctx->width >> !!i, avctx->height >> !!i,
699 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
701 avctx->height >> !!i,
704 } else if (c->frame_pred == PRED_GRADIENT) {
705 if (!c->interlaced) {
706 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
707 avctx->width >> !!i, avctx->height >> !!i,
710 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
712 avctx->height >> !!i,
718 case AV_PIX_FMT_YUV422P:
719 for (i = 0; i < 3; i++) {
720 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
721 avctx->width >> !!i, avctx->height,
722 plane_start[i], c->frame_pred == PRED_LEFT);
725 if (c->frame_pred == PRED_MEDIAN) {
726 if (!c->interlaced) {
727 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
728 avctx->width >> !!i, avctx->height,
731 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
732 avctx->width >> !!i, avctx->height,
735 } else if (c->frame_pred == PRED_GRADIENT) {
736 if (!c->interlaced) {
737 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
738 avctx->width >> !!i, avctx->height,
741 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
742 avctx->width >> !!i, avctx->height,
748 case AV_PIX_FMT_YUV444P:
749 for (i = 0; i < 3; i++) {
750 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
751 avctx->width, avctx->height,
752 plane_start[i], c->frame_pred == PRED_LEFT);
755 if (c->frame_pred == PRED_MEDIAN) {
756 if (!c->interlaced) {
757 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
758 avctx->width, avctx->height,
761 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
762 avctx->width, avctx->height,
765 } else if (c->frame_pred == PRED_GRADIENT) {
766 if (!c->interlaced) {
767 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
768 avctx->width, avctx->height,
771 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
772 avctx->width, avctx->height,
778 case AV_PIX_FMT_YUV422P10:
779 for (i = 0; i < 3; i++) {
780 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1, frame.f->linesize[i] / 2,
781 avctx->width >> !!i, avctx->height,
782 plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
789 frame.f->key_frame = 1;
790 frame.f->pict_type = AV_PICTURE_TYPE_I;
791 frame.f->interlaced_frame = !!c->interlaced;
795 /* always report that the buffer was completely consumed */
799 static av_cold int decode_init(AVCodecContext *avctx)
801 UtvideoContext * const c = avctx->priv_data;
805 ff_utvideodsp_init(&c->utdsp);
806 ff_bswapdsp_init(&c->bdsp);
807 ff_llviddsp_init(&c->llviddsp);
809 if (avctx->extradata_size >= 16) {
810 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
811 avctx->extradata[3], avctx->extradata[2],
812 avctx->extradata[1], avctx->extradata[0]);
813 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
814 AV_RB32(avctx->extradata + 4));
815 c->frame_info_size = AV_RL32(avctx->extradata + 8);
816 c->flags = AV_RL32(avctx->extradata + 12);
818 if (c->frame_info_size != 4)
819 avpriv_request_sample(avctx, "Frame info not 4 bytes");
820 av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
821 c->slices = (c->flags >> 24) + 1;
822 c->compression = c->flags & 1;
823 c->interlaced = c->flags & 0x800;
824 } else if (avctx->extradata_size == 8) {
825 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
826 avctx->extradata[3], avctx->extradata[2],
827 avctx->extradata[1], avctx->extradata[0]);
828 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
829 AV_RB32(avctx->extradata + 4));
832 c->frame_info_size = 4;
834 av_log(avctx, AV_LOG_ERROR,
835 "Insufficient extradata size %d, should be at least 16\n",
836 avctx->extradata_size);
837 return AVERROR_INVALIDDATA;
840 c->slice_bits_size = 0;
842 switch (avctx->codec_tag) {
843 case MKTAG('U', 'L', 'R', 'G'):
845 avctx->pix_fmt = AV_PIX_FMT_GBRP;
847 case MKTAG('U', 'L', 'R', 'A'):
849 avctx->pix_fmt = AV_PIX_FMT_GBRAP;
851 case MKTAG('U', 'L', 'Y', '0'):
853 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
854 avctx->colorspace = AVCOL_SPC_BT470BG;
856 case MKTAG('U', 'L', 'Y', '2'):
858 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
859 avctx->colorspace = AVCOL_SPC_BT470BG;
861 case MKTAG('U', 'L', 'Y', '4'):
863 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
864 avctx->colorspace = AVCOL_SPC_BT470BG;
866 case MKTAG('U', 'Q', 'Y', '2'):
868 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
870 case MKTAG('U', 'Q', 'R', 'G'):
872 avctx->pix_fmt = AV_PIX_FMT_GBRP10;
874 case MKTAG('U', 'Q', 'R', 'A'):
876 avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
878 case MKTAG('U', 'L', 'H', '0'):
880 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
881 avctx->colorspace = AVCOL_SPC_BT709;
883 case MKTAG('U', 'L', 'H', '2'):
885 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
886 avctx->colorspace = AVCOL_SPC_BT709;
888 case MKTAG('U', 'L', 'H', '4'):
890 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
891 avctx->colorspace = AVCOL_SPC_BT709;
894 av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
896 return AVERROR_INVALIDDATA;
902 static av_cold int decode_end(AVCodecContext *avctx)
904 UtvideoContext * const c = avctx->priv_data;
906 av_freep(&c->slice_bits);
911 AVCodec ff_utvideo_decoder = {
913 .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
914 .type = AVMEDIA_TYPE_VIDEO,
915 .id = AV_CODEC_ID_UTVIDEO,
916 .priv_data_size = sizeof(UtvideoContext),
919 .decode = decode_frame,
920 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
921 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,