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"
38 static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
49 for (i = 0; i < 1024; i++) {
53 qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len);
61 while (he[last].len == 255 && last)
64 if (he[last].len > 32) {
69 for (i = last; i >= 0; i--) {
70 codes[i] = code >> (32 - he[i].len);
73 code += 0x80000000u >> (he[i].len - 1);
76 return ff_init_vlc_sparse(vlc, FFMIN(he[last].len, 11), last + 1,
77 bits, sizeof(*bits), sizeof(*bits),
78 codes, sizeof(*codes), sizeof(*codes),
79 syms, sizeof(*syms), sizeof(*syms), 0);
82 static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
93 for (i = 0; i < 256; i++) {
97 qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
105 while (he[last].len == 255 && last)
108 if (he[last].len > 32)
112 for (i = last; i >= 0; i--) {
113 codes[i] = code >> (32 - he[i].len);
116 code += 0x80000000u >> (he[i].len - 1);
119 return ff_init_vlc_sparse(vlc, FFMIN(he[last].len, 11), last + 1,
120 bits, sizeof(*bits), sizeof(*bits),
121 codes, sizeof(*codes), sizeof(*codes),
122 syms, sizeof(*syms), sizeof(*syms), 0);
125 static int decode_plane10(UtvideoContext *c, int plane_no,
126 uint16_t *dst, int step, int stride,
127 int width, int height,
128 const uint8_t *src, const uint8_t *huff,
131 int i, j, slice, pix, ret;
137 if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) {
138 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
141 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
143 for (slice = 0; slice < c->slices; slice++) {
147 send = (height * (slice + 1) / c->slices);
148 dest = dst + sstart * stride;
151 for (j = sstart; j < send; j++) {
152 for (i = 0; i < width * step; i += step) {
168 for (slice = 0; slice < c->slices; slice++) {
170 int slice_data_start, slice_data_end, slice_size;
173 send = (height * (slice + 1) / c->slices);
174 dest = dst + sstart * stride;
176 // slice offset and size validation was done earlier
177 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
178 slice_data_end = AV_RL32(src + slice * 4);
179 slice_size = slice_data_end - slice_data_start;
182 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
183 "yet a slice has a length of zero.\n");
187 memcpy(c->slice_bits, src + slice_data_start + c->slices * 4,
189 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
190 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
191 (uint32_t *) c->slice_bits,
192 (slice_data_end - slice_data_start + 3) >> 2);
193 init_get_bits(&gb, c->slice_bits, slice_size * 8);
196 for (j = sstart; j < send; j++) {
197 for (i = 0; i < width * step; i += step) {
198 if (get_bits_left(&gb) <= 0) {
199 av_log(c->avctx, AV_LOG_ERROR,
200 "Slice decoding ran out of bits\n");
203 pix = get_vlc2(&gb, vlc.table, vlc.bits, 3);
205 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
217 if (get_bits_left(&gb) > 32)
218 av_log(c->avctx, AV_LOG_WARNING,
219 "%d bits left after decoding slice\n", get_bits_left(&gb));
227 return AVERROR_INVALIDDATA;
230 static int decode_plane(UtvideoContext *c, int plane_no,
231 uint8_t *dst, int step, int stride,
232 int width, int height,
233 const uint8_t *src, int use_pred)
235 int i, j, slice, pix;
240 const int cmask = ~(!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P);
242 if (build_huff(src, &vlc, &fsym)) {
243 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
244 return AVERROR_INVALIDDATA;
246 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
248 for (slice = 0; slice < c->slices; slice++) {
252 send = (height * (slice + 1) / c->slices) & cmask;
253 dest = dst + sstart * stride;
256 for (j = sstart; j < send; j++) {
257 for (i = 0; i < width * step; i += step) {
274 for (slice = 0; slice < c->slices; slice++) {
276 int slice_data_start, slice_data_end, slice_size;
279 send = (height * (slice + 1) / c->slices) & cmask;
280 dest = dst + sstart * stride;
282 // slice offset and size validation was done earlier
283 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
284 slice_data_end = AV_RL32(src + slice * 4);
285 slice_size = slice_data_end - slice_data_start;
288 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
289 "yet a slice has a length of zero.\n");
293 memcpy(c->slice_bits, src + slice_data_start + c->slices * 4,
295 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
296 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
297 (uint32_t *) c->slice_bits,
298 (slice_data_end - slice_data_start + 3) >> 2);
299 init_get_bits(&gb, c->slice_bits, slice_size * 8);
302 for (j = sstart; j < send; j++) {
303 for (i = 0; i < width * step; i += step) {
304 if (get_bits_left(&gb) <= 0) {
305 av_log(c->avctx, AV_LOG_ERROR,
306 "Slice decoding ran out of bits\n");
309 pix = get_vlc2(&gb, vlc.table, vlc.bits, 3);
311 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
322 if (get_bits_left(&gb) > 32)
323 av_log(c->avctx, AV_LOG_WARNING,
324 "%d bits left after decoding slice\n", get_bits_left(&gb));
332 return AVERROR_INVALIDDATA;
335 static void restore_rgb_planes(uint8_t *src, int step, int stride, int width,
341 for (j = 0; j < height; j++) {
342 for (i = 0; i < width * step; i += step) {
346 src[i] = r + g - 0x80;
347 src[i + 2] = b + g - 0x80;
353 static void restore_rgb_planes10(AVFrame *frame, int width, int height)
355 uint16_t *src_r = (uint16_t *)frame->data[2];
356 uint16_t *src_g = (uint16_t *)frame->data[0];
357 uint16_t *src_b = (uint16_t *)frame->data[1];
361 for (j = 0; j < height; j++) {
362 for (i = 0; i < width; i++) {
366 src_r[i] = (r + g - 0x200) & 0x3FF;
367 src_b[i] = (b + g - 0x200) & 0x3FF;
369 src_r += frame->linesize[2] / 2;
370 src_g += frame->linesize[0] / 2;
371 src_b += frame->linesize[1] / 2;
379 static void restore_median_planar(UtvideoContext *c, uint8_t *src, int stride,
380 int width, int height, int slices, int rmode)
385 int slice_start, slice_height;
386 const int cmask = ~rmode;
388 for (slice = 0; slice < slices; slice++) {
389 slice_start = ((slice * height) / slices) & cmask;
390 slice_height = ((((slice + 1) * height) / slices) & cmask) -
395 bsrc = src + slice_start * stride;
397 // first line - left neighbour prediction
399 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
401 if (slice_height <= 1)
403 // second line - first element has top prediction, the rest uses median
407 for (i = 1; i < width; i++) {
408 B = bsrc[i - stride];
409 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
414 // the rest of lines use continuous median prediction
415 for (j = 2; j < slice_height; j++) {
416 c->llviddsp.add_median_pred(bsrc, bsrc - stride,
417 bsrc, width, &A, &B);
423 /* UtVideo interlaced mode treats every two lines as a single one,
424 * so restoring function should take care of possible padding between
425 * two parts of the same "line".
427 static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, int stride,
428 int width, int height, int slices, int rmode)
433 int slice_start, slice_height;
434 const int cmask = ~(rmode ? 3 : 1);
435 const int stride2 = stride << 1;
437 for (slice = 0; slice < slices; slice++) {
438 slice_start = ((slice * height) / slices) & cmask;
439 slice_height = ((((slice + 1) * height) / slices) & cmask) -
445 bsrc = src + slice_start * stride;
447 // first line - left neighbour prediction
449 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
450 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
452 if (slice_height <= 1)
454 // second line - first element has top prediction, the rest uses median
458 for (i = 1; i < width; i++) {
459 B = bsrc[i - stride2];
460 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
464 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
465 bsrc + stride, width, &A, &B);
467 // the rest of lines use continuous median prediction
468 for (j = 2; j < slice_height; j++) {
469 c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
470 bsrc, width, &A, &B);
471 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
472 bsrc + stride, width, &A, &B);
478 static void restore_median_packed(uint8_t *src, int step, int stride,
479 int width, int height, int slices, int rmode)
484 int slice_start, slice_height;
485 const int cmask = ~rmode;
487 for (slice = 0; slice < slices; slice++) {
488 slice_start = ((slice * height) / slices) & cmask;
489 slice_height = ((((slice + 1) * height) / slices) & cmask) -
494 bsrc = src + slice_start * stride;
496 // first line - left neighbour prediction
499 for (i = step; i < width * step; i += step) {
504 if (slice_height <= 1)
506 // second line - first element has top prediction, the rest uses median
510 for (i = step; i < width * step; i += step) {
511 B = bsrc[i - stride];
512 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
517 // the rest of lines use continuous median prediction
518 for (j = 2; j < slice_height; j++) {
519 for (i = 0; i < width * step; i += step) {
520 B = bsrc[i - stride];
521 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
530 /* UtVideo interlaced mode treats every two lines as a single one,
531 * so restoring function should take care of possible padding between
532 * two parts of the same "line".
534 static void restore_median_packed_il(uint8_t *src, int step, int stride,
535 int width, int height, int slices, int rmode)
540 int slice_start, slice_height;
541 const int cmask = ~(rmode ? 3 : 1);
542 const int stride2 = stride << 1;
544 for (slice = 0; slice < slices; slice++) {
545 slice_start = ((slice * height) / slices) & cmask;
546 slice_height = ((((slice + 1) * height) / slices) & cmask) -
552 bsrc = src + slice_start * stride;
554 // first line - left neighbour prediction
557 for (i = step; i < width * step; i += step) {
561 for (i = 0; i < width * step; i += step) {
562 bsrc[stride + i] += A;
563 A = bsrc[stride + i];
566 if (slice_height <= 1)
568 // second line - first element has top prediction, the rest uses median
572 for (i = step; i < width * step; i += step) {
573 B = bsrc[i - stride2];
574 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
578 for (i = 0; i < width * step; i += step) {
579 B = bsrc[i - stride];
580 bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C));
582 A = bsrc[stride + i];
585 // the rest of lines use continuous median prediction
586 for (j = 2; j < slice_height; j++) {
587 for (i = 0; i < width * step; i += step) {
588 B = bsrc[i - stride2];
589 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
593 for (i = 0; i < width * step; i += step) {
594 B = bsrc[i - stride];
595 bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C));
597 A = bsrc[i + stride];
604 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
607 const uint8_t *buf = avpkt->data;
608 int buf_size = avpkt->size;
609 UtvideoContext *c = avctx->priv_data;
611 const uint8_t *plane_start[5];
612 int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
615 ThreadFrame frame = { .f = data };
617 if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
620 /* parse plane structure to get frame flags and validate slice offsets */
621 bytestream2_init(&gb, buf, buf_size);
623 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
624 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
625 return AVERROR_INVALIDDATA;
627 c->frame_info = bytestream2_get_le32u(&gb);
628 c->slices = ((c->frame_info >> 16) & 0xff) + 1;
629 for (i = 0; i < c->planes; i++) {
630 plane_start[i] = gb.buffer;
631 if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
632 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
633 return AVERROR_INVALIDDATA;
637 for (j = 0; j < c->slices; j++) {
638 slice_end = bytestream2_get_le32u(&gb);
639 if (slice_end < 0 || slice_end < slice_start ||
640 bytestream2_get_bytes_left(&gb) < slice_end) {
641 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
642 return AVERROR_INVALIDDATA;
644 slice_size = slice_end - slice_start;
645 slice_start = slice_end;
646 max_slice_size = FFMAX(max_slice_size, slice_size);
648 plane_size = slice_end;
649 bytestream2_skipu(&gb, plane_size);
650 bytestream2_skipu(&gb, 1024);
652 plane_start[c->planes] = gb.buffer;
654 for (i = 0; i < c->planes; i++) {
655 plane_start[i] = gb.buffer;
656 if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
657 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
658 return AVERROR_INVALIDDATA;
660 bytestream2_skipu(&gb, 256);
663 for (j = 0; j < c->slices; j++) {
664 slice_end = bytestream2_get_le32u(&gb);
665 if (slice_end < 0 || slice_end < slice_start ||
666 bytestream2_get_bytes_left(&gb) < slice_end) {
667 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
668 return AVERROR_INVALIDDATA;
670 slice_size = slice_end - slice_start;
671 slice_start = slice_end;
672 max_slice_size = FFMAX(max_slice_size, slice_size);
674 plane_size = slice_end;
675 bytestream2_skipu(&gb, plane_size);
677 plane_start[c->planes] = gb.buffer;
678 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
679 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
680 return AVERROR_INVALIDDATA;
682 c->frame_info = bytestream2_get_le32u(&gb);
684 av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
687 c->frame_pred = (c->frame_info >> 8) & 3;
689 if (c->frame_pred == PRED_GRADIENT) {
690 avpriv_request_sample(avctx, "Frame with gradient prediction");
691 return AVERROR_PATCHWELCOME;
694 av_fast_malloc(&c->slice_bits, &c->slice_bits_size,
695 max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
697 if (!c->slice_bits) {
698 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
699 return AVERROR(ENOMEM);
702 switch (c->avctx->pix_fmt) {
703 case AV_PIX_FMT_RGB24:
704 case AV_PIX_FMT_RGBA:
705 for (i = 0; i < c->planes; i++) {
706 ret = decode_plane(c, i, frame.f->data[0] + ff_ut_rgb_order[i],
707 c->planes, frame.f->linesize[0], avctx->width,
708 avctx->height, plane_start[i],
709 c->frame_pred == PRED_LEFT);
712 if (c->frame_pred == PRED_MEDIAN) {
713 if (!c->interlaced) {
714 restore_median_packed(frame.f->data[0] + ff_ut_rgb_order[i],
715 c->planes, frame.f->linesize[0], avctx->width,
716 avctx->height, c->slices, 0);
718 restore_median_packed_il(frame.f->data[0] + ff_ut_rgb_order[i],
719 c->planes, frame.f->linesize[0],
720 avctx->width, avctx->height, c->slices,
725 restore_rgb_planes(frame.f->data[0], c->planes, frame.f->linesize[0],
726 avctx->width, avctx->height);
728 case AV_PIX_FMT_GBRAP10:
729 case AV_PIX_FMT_GBRP10:
730 for (i = 0; i < c->planes; i++) {
731 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1,
732 frame.f->linesize[i] / 2, avctx->width,
733 avctx->height, plane_start[i],
734 plane_start[i + 1] - 1024,
735 c->frame_pred == PRED_LEFT);
739 restore_rgb_planes10(frame.f, avctx->width, avctx->height);
741 case AV_PIX_FMT_YUV420P:
742 for (i = 0; i < 3; i++) {
743 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
744 avctx->width >> !!i, avctx->height >> !!i,
745 plane_start[i], c->frame_pred == PRED_LEFT);
748 if (c->frame_pred == PRED_MEDIAN) {
749 if (!c->interlaced) {
750 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
751 avctx->width >> !!i, avctx->height >> !!i,
754 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
756 avctx->height >> !!i,
762 case AV_PIX_FMT_YUV422P:
763 for (i = 0; i < 3; i++) {
764 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
765 avctx->width >> !!i, avctx->height,
766 plane_start[i], c->frame_pred == PRED_LEFT);
769 if (c->frame_pred == PRED_MEDIAN) {
770 if (!c->interlaced) {
771 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
772 avctx->width >> !!i, avctx->height,
775 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
776 avctx->width >> !!i, avctx->height,
782 case AV_PIX_FMT_YUV444P:
783 for (i = 0; i < 3; i++) {
784 ret = decode_plane(c, i, frame.f->data[i], 1, frame.f->linesize[i],
785 avctx->width, avctx->height,
786 plane_start[i], c->frame_pred == PRED_LEFT);
789 if (c->frame_pred == PRED_MEDIAN) {
790 if (!c->interlaced) {
791 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
792 avctx->width, avctx->height,
795 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
796 avctx->width, avctx->height,
802 case AV_PIX_FMT_YUV422P10:
803 for (i = 0; i < 3; i++) {
804 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], 1, frame.f->linesize[i] / 2,
805 avctx->width >> !!i, avctx->height,
806 plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
813 frame.f->key_frame = 1;
814 frame.f->pict_type = AV_PICTURE_TYPE_I;
815 frame.f->interlaced_frame = !!c->interlaced;
819 /* always report that the buffer was completely consumed */
823 static av_cold int decode_init(AVCodecContext *avctx)
825 UtvideoContext * const c = avctx->priv_data;
829 ff_bswapdsp_init(&c->bdsp);
830 ff_llviddsp_init(&c->llviddsp);
832 if (avctx->extradata_size >= 16) {
833 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
834 avctx->extradata[3], avctx->extradata[2],
835 avctx->extradata[1], avctx->extradata[0]);
836 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
837 AV_RB32(avctx->extradata + 4));
838 c->frame_info_size = AV_RL32(avctx->extradata + 8);
839 c->flags = AV_RL32(avctx->extradata + 12);
841 if (c->frame_info_size != 4)
842 avpriv_request_sample(avctx, "Frame info not 4 bytes");
843 av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
844 c->slices = (c->flags >> 24) + 1;
845 c->compression = c->flags & 1;
846 c->interlaced = c->flags & 0x800;
847 } else if (avctx->extradata_size == 8) {
848 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
849 avctx->extradata[3], avctx->extradata[2],
850 avctx->extradata[1], avctx->extradata[0]);
851 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
852 AV_RB32(avctx->extradata + 4));
855 c->frame_info_size = 4;
857 av_log(avctx, AV_LOG_ERROR,
858 "Insufficient extradata size %d, should be at least 16\n",
859 avctx->extradata_size);
860 return AVERROR_INVALIDDATA;
863 c->slice_bits_size = 0;
865 switch (avctx->codec_tag) {
866 case MKTAG('U', 'L', 'R', 'G'):
868 avctx->pix_fmt = AV_PIX_FMT_RGB24;
870 case MKTAG('U', 'L', 'R', 'A'):
872 avctx->pix_fmt = AV_PIX_FMT_RGBA;
874 case MKTAG('U', 'L', 'Y', '0'):
876 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
877 avctx->colorspace = AVCOL_SPC_BT470BG;
879 case MKTAG('U', 'L', 'Y', '2'):
881 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
882 avctx->colorspace = AVCOL_SPC_BT470BG;
884 case MKTAG('U', 'L', 'Y', '4'):
886 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
887 avctx->colorspace = AVCOL_SPC_BT470BG;
889 case MKTAG('U', 'Q', 'Y', '2'):
891 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
893 case MKTAG('U', 'Q', 'R', 'G'):
895 avctx->pix_fmt = AV_PIX_FMT_GBRP10;
897 case MKTAG('U', 'Q', 'R', 'A'):
899 avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
901 case MKTAG('U', 'L', 'H', '0'):
903 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
904 avctx->colorspace = AVCOL_SPC_BT709;
906 case MKTAG('U', 'L', 'H', '2'):
908 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
909 avctx->colorspace = AVCOL_SPC_BT709;
911 case MKTAG('U', 'L', 'H', '4'):
913 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
914 avctx->colorspace = AVCOL_SPC_BT709;
917 av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
919 return AVERROR_INVALIDDATA;
925 static av_cold int decode_end(AVCodecContext *avctx)
927 UtvideoContext * const c = avctx->priv_data;
929 av_freep(&c->slice_bits);
934 AVCodec ff_utvideo_decoder = {
936 .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
937 .type = AVMEDIA_TYPE_VIDEO,
938 .id = AV_CODEC_ID_UTVIDEO,
939 .priv_data_size = sizeof(UtvideoContext),
942 .decode = decode_frame,
943 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,