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 #include "libavutil/intreadwrite.h"
33 #include "bytestream.h"
39 static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
50 for (i = 0; i < 1024; i++) {
54 qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len);
62 while (he[last].len == 255 && last)
65 if (he[last].len > 32) {
70 for (i = last; i >= 0; i--) {
71 codes[i] = code >> (32 - he[i].len);
74 code += 0x80000000u >> (he[i].len - 1);
77 return ff_init_vlc_sparse(vlc, FFMIN(he[last].len, 11), last + 1,
78 bits, sizeof(*bits), sizeof(*bits),
79 codes, sizeof(*codes), sizeof(*codes),
80 syms, sizeof(*syms), sizeof(*syms), 0);
83 static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
94 for (i = 0; i < 256; i++) {
98 qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
106 while (he[last].len == 255 && last)
109 if (he[last].len > 32)
113 for (i = last; i >= 0; i--) {
114 codes[i] = code >> (32 - he[i].len);
117 code += 0x80000000u >> (he[i].len - 1);
120 return ff_init_vlc_sparse(vlc, FFMIN(he[last].len, 11), last + 1,
121 bits, sizeof(*bits), sizeof(*bits),
122 codes, sizeof(*codes), sizeof(*codes),
123 syms, sizeof(*syms), sizeof(*syms), 0);
126 static int decode_plane10(UtvideoContext *c, int plane_no,
127 uint16_t *dst, int step, ptrdiff_t stride,
128 int width, int height,
129 const uint8_t *src, const uint8_t *huff,
132 int i, j, slice, pix, ret;
138 if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) {
139 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
142 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
144 for (slice = 0; slice < c->slices; slice++) {
148 send = (height * (slice + 1) / c->slices);
149 dest = dst + sstart * stride;
152 for (j = sstart; j < send; j++) {
153 for (i = 0; i < width * step; i += step) {
169 for (slice = 0; slice < c->slices; slice++) {
171 int slice_data_start, slice_data_end, slice_size;
174 send = (height * (slice + 1) / c->slices);
175 dest = dst + sstart * stride;
177 // slice offset and size validation was done earlier
178 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
179 slice_data_end = AV_RL32(src + slice * 4);
180 slice_size = slice_data_end - slice_data_start;
183 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
184 "yet a slice has a length of zero.\n");
188 memcpy(c->slice_bits, src + slice_data_start + c->slices * 4,
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 *) c->slice_bits,
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 for (i = 0; i < width * step; i += step) {
199 if (get_bits_left(&gb) <= 0) {
200 av_log(c->avctx, AV_LOG_ERROR,
201 "Slice decoding ran out of bits\n");
204 pix = get_vlc2(&gb, vlc.table, vlc.bits, 3);
206 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
218 if (get_bits_left(&gb) > 32)
219 av_log(c->avctx, AV_LOG_WARNING,
220 "%d bits left after decoding slice\n", get_bits_left(&gb));
228 return AVERROR_INVALIDDATA;
231 static int decode_plane(UtvideoContext *c, int plane_no,
232 uint8_t *dst, int step, ptrdiff_t stride,
233 int width, int height,
234 const uint8_t *src, int use_pred)
236 int i, j, slice, pix;
241 const int cmask = ~(!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P);
243 if (build_huff(src, &vlc, &fsym)) {
244 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
245 return AVERROR_INVALIDDATA;
247 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
249 for (slice = 0; slice < c->slices; slice++) {
253 send = (height * (slice + 1) / c->slices) & cmask;
254 dest = dst + sstart * stride;
257 for (j = sstart; j < send; j++) {
258 for (i = 0; i < width * step; i += step) {
275 for (slice = 0; slice < c->slices; slice++) {
277 int slice_data_start, slice_data_end, slice_size;
280 send = (height * (slice + 1) / c->slices) & cmask;
281 dest = dst + sstart * stride;
283 // slice offset and size validation was done earlier
284 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
285 slice_data_end = AV_RL32(src + slice * 4);
286 slice_size = slice_data_end - slice_data_start;
289 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
290 "yet a slice has a length of zero.\n");
294 memcpy(c->slice_bits, src + slice_data_start + c->slices * 4,
296 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
297 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
298 (uint32_t *) c->slice_bits,
299 (slice_data_end - slice_data_start + 3) >> 2);
300 init_get_bits(&gb, c->slice_bits, slice_size * 8);
303 for (j = sstart; j < send; j++) {
304 for (i = 0; i < width * step; i += step) {
305 if (get_bits_left(&gb) <= 0) {
306 av_log(c->avctx, AV_LOG_ERROR,
307 "Slice decoding ran out of bits\n");
310 pix = get_vlc2(&gb, vlc.table, vlc.bits, 3);
312 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
323 if (get_bits_left(&gb) > 32)
324 av_log(c->avctx, AV_LOG_WARNING,
325 "%d bits left after decoding slice\n", get_bits_left(&gb));
333 return AVERROR_INVALIDDATA;
336 static void restore_rgb_planes(uint8_t *src, int step, ptrdiff_t stride,
337 int width, int height)
342 for (j = 0; j < height; j++) {
343 for (i = 0; i < width * step; i += step) {
347 src[i] = r + g - 0x80;
348 src[i + 2] = b + g - 0x80;
354 static void restore_rgb_planes10(AVFrame *frame, int width, int height)
356 uint16_t *src_r = (uint16_t *)frame->data[2];
357 uint16_t *src_g = (uint16_t *)frame->data[0];
358 uint16_t *src_b = (uint16_t *)frame->data[1];
362 for (j = 0; j < height; j++) {
363 for (i = 0; i < width; i++) {
367 src_r[i] = (r + g - 0x200) & 0x3FF;
368 src_b[i] = (b + g - 0x200) & 0x3FF;
370 src_r += frame->linesize[2] / 2;
371 src_g += frame->linesize[0] / 2;
372 src_b += frame->linesize[1] / 2;
380 static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
381 int width, int height, int slices, int rmode)
386 int slice_start, slice_height;
387 const int cmask = ~rmode;
389 for (slice = 0; slice < slices; slice++) {
390 slice_start = ((slice * height) / slices) & cmask;
391 slice_height = ((((slice + 1) * height) / slices) & cmask) -
396 bsrc = src + slice_start * stride;
398 // first line - left neighbour prediction
400 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
402 if (slice_height <= 1)
404 // second line - first element has top prediction, the rest uses median
408 for (i = 1; i < width; i++) {
409 B = bsrc[i - stride];
410 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
415 // the rest of lines use continuous median prediction
416 for (j = 2; j < slice_height; j++) {
417 c->llviddsp.add_median_pred(bsrc, bsrc - stride,
418 bsrc, width, &A, &B);
424 /* UtVideo interlaced mode treats every two lines as a single one,
425 * so restoring function should take care of possible padding between
426 * two parts of the same "line".
428 static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
429 int width, int height, int slices, int rmode)
434 int slice_start, slice_height;
435 const int cmask = ~(rmode ? 3 : 1);
436 const ptrdiff_t stride2 = stride << 1;
438 for (slice = 0; slice < slices; slice++) {
439 slice_start = ((slice * height) / slices) & cmask;
440 slice_height = ((((slice + 1) * height) / slices) & cmask) -
446 bsrc = src + slice_start * stride;
448 // first line - left neighbour prediction
450 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
451 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
453 if (slice_height <= 1)
455 // second line - first element has top prediction, the rest uses median
459 for (i = 1; i < width; i++) {
460 B = bsrc[i - stride2];
461 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
465 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
466 bsrc + stride, width, &A, &B);
468 // the rest of lines use continuous median prediction
469 for (j = 2; j < slice_height; j++) {
470 c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
471 bsrc, width, &A, &B);
472 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
473 bsrc + stride, width, &A, &B);
479 static void restore_median_packed(uint8_t *src, int step, ptrdiff_t stride,
480 int width, int height, int slices, int rmode)
485 int slice_start, slice_height;
486 const int cmask = ~rmode;
488 for (slice = 0; slice < slices; slice++) {
489 slice_start = ((slice * height) / slices) & cmask;
490 slice_height = ((((slice + 1) * height) / slices) & cmask) -
495 bsrc = src + slice_start * stride;
497 // first line - left neighbour prediction
500 for (i = step; i < width * step; i += step) {
505 if (slice_height <= 1)
507 // second line - first element has top prediction, the rest uses median
511 for (i = step; i < width * step; i += step) {
512 B = bsrc[i - stride];
513 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
518 // the rest of lines use continuous median prediction
519 for (j = 2; j < slice_height; j++) {
520 for (i = 0; i < width * step; i += step) {
521 B = bsrc[i - stride];
522 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
531 /* UtVideo interlaced mode treats every two lines as a single one,
532 * so restoring function should take care of possible padding between
533 * two parts of the same "line".
535 static void restore_median_packed_il(uint8_t *src, int step, ptrdiff_t stride,
536 int width, int height, int slices, int rmode)
541 int slice_start, slice_height;
542 const int cmask = ~(rmode ? 3 : 1);
543 const ptrdiff_t stride2 = stride << 1;
545 for (slice = 0; slice < slices; slice++) {
546 slice_start = ((slice * height) / slices) & cmask;
547 slice_height = ((((slice + 1) * height) / slices) & cmask) -
553 bsrc = src + slice_start * stride;
555 // first line - left neighbour prediction
558 for (i = step; i < width * step; i += step) {
562 for (i = 0; i < width * step; i += step) {
563 bsrc[stride + i] += A;
564 A = bsrc[stride + i];
567 if (slice_height <= 1)
569 // second line - first element has top prediction, the rest uses median
573 for (i = step; i < width * step; i += step) {
574 B = bsrc[i - stride2];
575 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
579 for (i = 0; i < width * step; i += step) {
580 B = bsrc[i - stride];
581 bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C));
583 A = bsrc[stride + i];
586 // the rest of lines use continuous median prediction
587 for (j = 2; j < slice_height; j++) {
588 for (i = 0; i < width * step; i += step) {
589 B = bsrc[i - stride2];
590 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
594 for (i = 0; i < width * step; i += step) {
595 B = bsrc[i - stride];
596 bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C));
598 A = bsrc[i + stride];
605 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
608 const uint8_t *buf = avpkt->data;
609 int buf_size = avpkt->size;
610 UtvideoContext *c = avctx->priv_data;
612 const uint8_t *plane_start[5];
613 int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
616 ThreadFrame frame = { .f = data };
618 if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
621 /* parse plane structure to get frame flags and validate slice offsets */
622 bytestream2_init(&gb, buf, buf_size);
624 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
625 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
626 return AVERROR_INVALIDDATA;
628 c->frame_info = bytestream2_get_le32u(&gb);
629 c->slices = ((c->frame_info >> 16) & 0xff) + 1;
630 for (i = 0; i < c->planes; i++) {
631 plane_start[i] = gb.buffer;
632 if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
633 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
634 return AVERROR_INVALIDDATA;
638 for (j = 0; j < c->slices; j++) {
639 slice_end = bytestream2_get_le32u(&gb);
640 if (slice_end < 0 || slice_end < slice_start ||
641 bytestream2_get_bytes_left(&gb) < slice_end) {
642 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
643 return AVERROR_INVALIDDATA;
645 slice_size = slice_end - slice_start;
646 slice_start = slice_end;
647 max_slice_size = FFMAX(max_slice_size, slice_size);
649 plane_size = slice_end;
650 bytestream2_skipu(&gb, plane_size);
651 bytestream2_skipu(&gb, 1024);
653 plane_start[c->planes] = gb.buffer;
655 for (i = 0; i < c->planes; i++) {
656 plane_start[i] = gb.buffer;
657 if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
658 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
659 return AVERROR_INVALIDDATA;
661 bytestream2_skipu(&gb, 256);
664 for (j = 0; j < c->slices; j++) {
665 slice_end = bytestream2_get_le32u(&gb);
666 if (slice_end < 0 || slice_end < slice_start ||
667 bytestream2_get_bytes_left(&gb) < slice_end) {
668 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
669 return AVERROR_INVALIDDATA;
671 slice_size = slice_end - slice_start;
672 slice_start = slice_end;
673 max_slice_size = FFMAX(max_slice_size, slice_size);
675 plane_size = slice_end;
676 bytestream2_skipu(&gb, plane_size);
678 plane_start[c->planes] = gb.buffer;
679 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
680 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
681 return AVERROR_INVALIDDATA;
683 c->frame_info = bytestream2_get_le32u(&gb);
685 av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
688 c->frame_pred = (c->frame_info >> 8) & 3;
690 if (c->frame_pred == PRED_GRADIENT) {
691 avpriv_request_sample(avctx, "Frame with gradient prediction");
692 return AVERROR_PATCHWELCOME;
695 av_fast_malloc(&c->slice_bits, &c->slice_bits_size,
696 max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
698 if (!c->slice_bits) {
699 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
700 return AVERROR(ENOMEM);
703 switch (c->avctx->pix_fmt) {
704 case AV_PIX_FMT_RGB24:
705 case AV_PIX_FMT_RGBA:
706 for (i = 0; i < c->planes; i++) {
707 ret = decode_plane(c, i, frame.f->data[0] + ff_ut_rgb_order[i],
708 c->planes, frame.f->linesize[0], avctx->width,
709 avctx->height, plane_start[i],
710 c->frame_pred == PRED_LEFT);
713 if (c->frame_pred == PRED_MEDIAN) {
714 if (!c->interlaced) {
715 restore_median_packed(frame.f->data[0] + ff_ut_rgb_order[i],
716 c->planes, frame.f->linesize[0], avctx->width,
717 avctx->height, c->slices, 0);
719 restore_median_packed_il(frame.f->data[0] + ff_ut_rgb_order[i],
720 c->planes, frame.f->linesize[0],
721 avctx->width, avctx->height, c->slices,
726 restore_rgb_planes(frame.f->data[0], c->planes, frame.f->linesize[0],
727 avctx->width, avctx->height);
729 case AV_PIX_FMT_GBRAP10:
730 case AV_PIX_FMT_GBRP10:
731 for (i = 0; i < c->planes; i++) {
732 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1,
733 frame.f->linesize[i] / 2, avctx->width,
734 avctx->height, plane_start[i],
735 plane_start[i + 1] - 1024,
736 c->frame_pred == PRED_LEFT);
740 restore_rgb_planes10(frame.f, avctx->width, avctx->height);
742 case AV_PIX_FMT_YUV420P:
743 for (i = 0; i < 3; i++) {
744 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
745 avctx->width >> !!i, avctx->height >> !!i,
746 plane_start[i], c->frame_pred == PRED_LEFT);
749 if (c->frame_pred == PRED_MEDIAN) {
750 if (!c->interlaced) {
751 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
752 avctx->width >> !!i, avctx->height >> !!i,
755 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
757 avctx->height >> !!i,
763 case AV_PIX_FMT_YUV422P:
764 for (i = 0; i < 3; i++) {
765 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
766 avctx->width >> !!i, avctx->height,
767 plane_start[i], c->frame_pred == PRED_LEFT);
770 if (c->frame_pred == PRED_MEDIAN) {
771 if (!c->interlaced) {
772 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
773 avctx->width >> !!i, avctx->height,
776 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
777 avctx->width >> !!i, avctx->height,
783 case AV_PIX_FMT_YUV444P:
784 for (i = 0; i < 3; i++) {
785 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
786 avctx->width, avctx->height,
787 plane_start[i], c->frame_pred == PRED_LEFT);
790 if (c->frame_pred == PRED_MEDIAN) {
791 if (!c->interlaced) {
792 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
793 avctx->width, avctx->height,
796 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
797 avctx->width, avctx->height,
803 case AV_PIX_FMT_YUV422P10:
804 for (i = 0; i < 3; i++) {
805 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1, frame.f->linesize[i] / 2,
806 avctx->width >> !!i, avctx->height,
807 plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
814 frame.f->key_frame = 1;
815 frame.f->pict_type = AV_PICTURE_TYPE_I;
816 frame.f->interlaced_frame = !!c->interlaced;
820 /* always report that the buffer was completely consumed */
824 static av_cold int decode_init(AVCodecContext *avctx)
826 UtvideoContext * const c = avctx->priv_data;
830 ff_bswapdsp_init(&c->bdsp);
831 ff_llviddsp_init(&c->llviddsp);
833 if (avctx->extradata_size >= 16) {
834 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
835 avctx->extradata[3], avctx->extradata[2],
836 avctx->extradata[1], avctx->extradata[0]);
837 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
838 AV_RB32(avctx->extradata + 4));
839 c->frame_info_size = AV_RL32(avctx->extradata + 8);
840 c->flags = AV_RL32(avctx->extradata + 12);
842 if (c->frame_info_size != 4)
843 avpriv_request_sample(avctx, "Frame info not 4 bytes");
844 av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
845 c->slices = (c->flags >> 24) + 1;
846 c->compression = c->flags & 1;
847 c->interlaced = c->flags & 0x800;
848 } else if (avctx->extradata_size == 8) {
849 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
850 avctx->extradata[3], avctx->extradata[2],
851 avctx->extradata[1], avctx->extradata[0]);
852 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
853 AV_RB32(avctx->extradata + 4));
856 c->frame_info_size = 4;
858 av_log(avctx, AV_LOG_ERROR,
859 "Insufficient extradata size %d, should be at least 16\n",
860 avctx->extradata_size);
861 return AVERROR_INVALIDDATA;
864 c->slice_bits_size = 0;
866 switch (avctx->codec_tag) {
867 case MKTAG('U', 'L', 'R', 'G'):
869 avctx->pix_fmt = AV_PIX_FMT_RGB24;
871 case MKTAG('U', 'L', 'R', 'A'):
873 avctx->pix_fmt = AV_PIX_FMT_RGBA;
875 case MKTAG('U', 'L', 'Y', '0'):
877 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
878 avctx->colorspace = AVCOL_SPC_BT470BG;
880 case MKTAG('U', 'L', 'Y', '2'):
882 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
883 avctx->colorspace = AVCOL_SPC_BT470BG;
885 case MKTAG('U', 'L', 'Y', '4'):
887 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
888 avctx->colorspace = AVCOL_SPC_BT470BG;
890 case MKTAG('U', 'Q', 'Y', '2'):
892 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
894 case MKTAG('U', 'Q', 'R', 'G'):
896 avctx->pix_fmt = AV_PIX_FMT_GBRP10;
898 case MKTAG('U', 'Q', 'R', 'A'):
900 avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
902 case MKTAG('U', 'L', 'H', '0'):
904 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
905 avctx->colorspace = AVCOL_SPC_BT709;
907 case MKTAG('U', 'L', 'H', '2'):
909 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
910 avctx->colorspace = AVCOL_SPC_BT709;
912 case MKTAG('U', 'L', 'H', '4'):
914 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
915 avctx->colorspace = AVCOL_SPC_BT709;
918 av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
920 return AVERROR_INVALIDDATA;
926 static av_cold int decode_end(AVCodecContext *avctx)
928 UtvideoContext * const c = avctx->priv_data;
930 av_freep(&c->slice_bits);
935 AVCodec ff_utvideo_decoder = {
937 .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
938 .type = AVMEDIA_TYPE_VIDEO,
939 .id = AV_CODEC_ID_UTVIDEO,
940 .priv_data_size = sizeof(UtvideoContext),
943 .decode = decode_frame,
944 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
945 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,