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, 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; i++) {
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 for (i = 0; i < width; i++) {
199 pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
201 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
212 if (get_bits_left(&gb) < 0) {
213 av_log(c->avctx, AV_LOG_ERROR,
214 "Slice decoding ran out of bits\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 compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
233 const int is_luma = (pix_fmt == AV_PIX_FMT_YUV420P) && !plane_no;
236 return ~(1 + 2 * is_luma);
241 static int decode_plane(UtvideoContext *c, int plane_no,
242 uint8_t *dst, ptrdiff_t stride,
243 int width, int height,
244 const uint8_t *src, int use_pred)
246 int i, j, slice, pix;
251 const int cmask = compute_cmask(plane_no, c->interlaced, c->avctx->pix_fmt);
253 if (build_huff(src, &vlc, &fsym)) {
254 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
255 return AVERROR_INVALIDDATA;
257 if (fsym >= 0) { // build_huff reported a symbol to fill slices with
259 for (slice = 0; slice < c->slices; slice++) {
263 send = (height * (slice + 1) / c->slices) & cmask;
264 dest = dst + sstart * stride;
267 for (j = sstart; j < send; j++) {
268 for (i = 0; i < width; i++) {
285 for (slice = 0; slice < c->slices; slice++) {
287 int slice_data_start, slice_data_end, slice_size;
290 send = (height * (slice + 1) / c->slices) & cmask;
291 dest = dst + sstart * stride;
293 // slice offset and size validation was done earlier
294 slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
295 slice_data_end = AV_RL32(src + slice * 4);
296 slice_size = slice_data_end - slice_data_start;
299 av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
300 "yet a slice has a length of zero.\n");
304 memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
305 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
306 (uint32_t *)(src + slice_data_start + c->slices * 4),
307 (slice_data_end - slice_data_start + 3) >> 2);
308 init_get_bits(&gb, c->slice_bits, slice_size * 8);
311 for (j = sstart; j < send; j++) {
312 for (i = 0; i < width; i++) {
313 pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);
315 av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
324 if (get_bits_left(&gb) < 0) {
325 av_log(c->avctx, AV_LOG_ERROR,
326 "Slice decoding ran out of bits\n");
331 if (get_bits_left(&gb) > 32)
332 av_log(c->avctx, AV_LOG_WARNING,
333 "%d bits left after decoding slice\n", get_bits_left(&gb));
341 return AVERROR_INVALIDDATA;
348 static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
349 int width, int height, int slices, int rmode)
354 int slice_start, slice_height;
355 const int cmask = ~rmode;
357 for (slice = 0; slice < slices; slice++) {
358 slice_start = ((slice * height) / slices) & cmask;
359 slice_height = ((((slice + 1) * height) / slices) & cmask) -
364 bsrc = src + slice_start * stride;
366 // first line - left neighbour prediction
368 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
370 if (slice_height <= 1)
372 // second line - first element has top prediction, the rest uses median
376 for (i = 1; i < width; i++) {
377 B = bsrc[i - stride];
378 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
383 // the rest of lines use continuous median prediction
384 for (j = 2; j < slice_height; j++) {
385 c->llviddsp.add_median_pred(bsrc, bsrc - stride,
386 bsrc, width, &A, &B);
392 /* UtVideo interlaced mode treats every two lines as a single one,
393 * so restoring function should take care of possible padding between
394 * two parts of the same "line".
396 static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
397 int width, int height, int slices, int rmode)
402 int slice_start, slice_height;
403 const int cmask = ~(rmode ? 3 : 1);
404 const ptrdiff_t stride2 = stride << 1;
406 for (slice = 0; slice < slices; slice++) {
407 slice_start = ((slice * height) / slices) & cmask;
408 slice_height = ((((slice + 1) * height) / slices) & cmask) -
414 bsrc = src + slice_start * stride;
416 // first line - left neighbour prediction
418 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
419 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
421 if (slice_height <= 1)
423 // second line - first element has top prediction, the rest uses median
427 for (i = 1; i < width; i++) {
428 B = bsrc[i - stride2];
429 bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
433 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
434 bsrc + stride, width, &A, &B);
436 // the rest of lines use continuous median prediction
437 for (j = 2; j < slice_height; j++) {
438 c->llviddsp.add_median_pred(bsrc, bsrc - stride2,
439 bsrc, width, &A, &B);
440 c->llviddsp.add_median_pred(bsrc + stride, bsrc - stride,
441 bsrc + stride, width, &A, &B);
447 static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
448 int width, int height, int slices, int rmode)
453 int slice_start, slice_height;
454 const int cmask = ~rmode;
456 for (slice = 0; slice < slices; slice++) {
457 slice_start = ((slice * height) / slices) & cmask;
458 slice_height = ((((slice + 1) * height) / slices) & cmask) -
463 bsrc = src + slice_start * stride;
465 // first line - left neighbour prediction
467 c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
469 if (slice_height <= 1)
471 for (j = 1; j < slice_height; j++) {
472 // second line - first element has top prediction, the rest uses gradient
473 bsrc[0] = (bsrc[0] + bsrc[-stride]) & 0xFF;
474 for (i = 1; i < width; i++) {
475 A = bsrc[i - stride];
476 B = bsrc[i - (stride + 1)];
478 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
485 static void restore_gradient_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride,
486 int width, int height, int slices, int rmode)
491 int slice_start, slice_height;
492 const int cmask = ~(rmode ? 3 : 1);
493 const ptrdiff_t stride2 = stride << 1;
495 for (slice = 0; slice < slices; slice++) {
496 slice_start = ((slice * height) / slices) & cmask;
497 slice_height = ((((slice + 1) * height) / slices) & cmask) -
503 bsrc = src + slice_start * stride;
505 // first line - left neighbour prediction
507 A = c->llviddsp.add_left_pred(bsrc, bsrc, width, 0);
508 c->llviddsp.add_left_pred(bsrc + stride, bsrc + stride, width, A);
510 if (slice_height <= 1)
512 for (j = 1; j < slice_height; j++) {
513 // second line - first element has top prediction, the rest uses gradient
514 bsrc[0] = (bsrc[0] + bsrc[-stride2]) & 0xFF;
515 for (i = 1; i < width; i++) {
516 A = bsrc[i - stride2];
517 B = bsrc[i - (stride2 + 1)];
519 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
522 B = bsrc[-(1 + stride + stride - width)];
524 bsrc[stride] = (A - B + C + bsrc[stride]) & 0xFF;
525 for (i = 1; i < width; i++) {
526 A = bsrc[i - stride];
527 B = bsrc[i - (1 + stride)];
528 C = bsrc[i - 1 + stride];
529 bsrc[i + stride] = (A - B + C + bsrc[i + stride]) & 0xFF;
536 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
539 const uint8_t *buf = avpkt->data;
540 int buf_size = avpkt->size;
541 UtvideoContext *c = avctx->priv_data;
543 const uint8_t *plane_start[5];
544 int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
547 ThreadFrame frame = { .f = data };
549 if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
552 /* parse plane structure to get frame flags and validate slice offsets */
553 bytestream2_init(&gb, buf, buf_size);
555 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
556 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
557 return AVERROR_INVALIDDATA;
559 c->frame_info = bytestream2_get_le32u(&gb);
560 c->slices = ((c->frame_info >> 16) & 0xff) + 1;
561 for (i = 0; i < c->planes; i++) {
562 plane_start[i] = gb.buffer;
563 if (bytestream2_get_bytes_left(&gb) < 1024 + 4 * c->slices) {
564 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
565 return AVERROR_INVALIDDATA;
569 for (j = 0; j < c->slices; j++) {
570 slice_end = bytestream2_get_le32u(&gb);
571 if (slice_end < 0 || slice_end < slice_start ||
572 bytestream2_get_bytes_left(&gb) < slice_end) {
573 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
574 return AVERROR_INVALIDDATA;
576 slice_size = slice_end - slice_start;
577 slice_start = slice_end;
578 max_slice_size = FFMAX(max_slice_size, slice_size);
580 plane_size = slice_end;
581 bytestream2_skipu(&gb, plane_size);
582 bytestream2_skipu(&gb, 1024);
584 plane_start[c->planes] = gb.buffer;
586 for (i = 0; i < c->planes; i++) {
587 plane_start[i] = gb.buffer;
588 if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
589 av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
590 return AVERROR_INVALIDDATA;
592 bytestream2_skipu(&gb, 256);
595 for (j = 0; j < c->slices; j++) {
596 slice_end = bytestream2_get_le32u(&gb);
597 if (slice_end < 0 || slice_end < slice_start ||
598 bytestream2_get_bytes_left(&gb) < slice_end) {
599 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
600 return AVERROR_INVALIDDATA;
602 slice_size = slice_end - slice_start;
603 slice_start = slice_end;
604 max_slice_size = FFMAX(max_slice_size, slice_size);
606 plane_size = slice_end;
607 bytestream2_skipu(&gb, plane_size);
609 plane_start[c->planes] = gb.buffer;
610 if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
611 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
612 return AVERROR_INVALIDDATA;
614 c->frame_info = bytestream2_get_le32u(&gb);
616 av_log(avctx, AV_LOG_DEBUG, "frame information flags %"PRIX32"\n",
619 c->frame_pred = (c->frame_info >> 8) & 3;
621 max_slice_size += 4*avctx->width;
623 av_fast_malloc(&c->slice_bits, &c->slice_bits_size,
624 max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
626 if (!c->slice_bits) {
627 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
628 return AVERROR(ENOMEM);
631 switch (c->avctx->pix_fmt) {
632 case AV_PIX_FMT_GBRP:
633 case AV_PIX_FMT_GBRAP:
634 for (i = 0; i < c->planes; i++) {
635 ret = decode_plane(c, i, frame.f->data[i],
636 frame.f->linesize[i], avctx->width,
637 avctx->height, plane_start[i],
638 c->frame_pred == PRED_LEFT);
641 if (c->frame_pred == PRED_MEDIAN) {
642 if (!c->interlaced) {
643 restore_median_planar(c, frame.f->data[i],
644 frame.f->linesize[i], avctx->width,
645 avctx->height, c->slices, 0);
647 restore_median_planar_il(c, frame.f->data[i],
648 frame.f->linesize[i],
649 avctx->width, avctx->height, c->slices,
652 } else if (c->frame_pred == PRED_GRADIENT) {
653 if (!c->interlaced) {
654 restore_gradient_planar(c, frame.f->data[i],
655 frame.f->linesize[i], avctx->width,
656 avctx->height, c->slices, 0);
658 restore_gradient_planar_il(c, frame.f->data[i],
659 frame.f->linesize[i],
660 avctx->width, avctx->height, c->slices,
665 c->utdsp.restore_rgb_planes(frame.f->data[2], frame.f->data[0], frame.f->data[1],
666 frame.f->linesize[2], frame.f->linesize[0], frame.f->linesize[1],
667 avctx->width, avctx->height);
669 case AV_PIX_FMT_GBRAP10:
670 case AV_PIX_FMT_GBRP10:
671 for (i = 0; i < c->planes; i++) {
672 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i],
673 frame.f->linesize[i] / 2, avctx->width,
674 avctx->height, plane_start[i],
675 plane_start[i + 1] - 1024,
676 c->frame_pred == PRED_LEFT);
680 c->utdsp.restore_rgb_planes10((uint16_t *)frame.f->data[2], (uint16_t *)frame.f->data[0], (uint16_t *)frame.f->data[1],
681 frame.f->linesize[2] / 2, frame.f->linesize[0] / 2, frame.f->linesize[1] / 2,
682 avctx->width, avctx->height);
684 case AV_PIX_FMT_YUV420P:
685 for (i = 0; i < 3; i++) {
686 ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
687 avctx->width >> !!i, avctx->height >> !!i,
688 plane_start[i], c->frame_pred == PRED_LEFT);
691 if (c->frame_pred == PRED_MEDIAN) {
692 if (!c->interlaced) {
693 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
694 avctx->width >> !!i, avctx->height >> !!i,
697 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
699 avctx->height >> !!i,
702 } else if (c->frame_pred == PRED_GRADIENT) {
703 if (!c->interlaced) {
704 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
705 avctx->width >> !!i, avctx->height >> !!i,
708 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
710 avctx->height >> !!i,
716 case AV_PIX_FMT_YUV422P:
717 for (i = 0; i < 3; i++) {
718 ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
719 avctx->width >> !!i, avctx->height,
720 plane_start[i], c->frame_pred == PRED_LEFT);
723 if (c->frame_pred == PRED_MEDIAN) {
724 if (!c->interlaced) {
725 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
726 avctx->width >> !!i, avctx->height,
729 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
730 avctx->width >> !!i, avctx->height,
733 } else if (c->frame_pred == PRED_GRADIENT) {
734 if (!c->interlaced) {
735 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
736 avctx->width >> !!i, avctx->height,
739 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
740 avctx->width >> !!i, avctx->height,
746 case AV_PIX_FMT_YUV444P:
747 for (i = 0; i < 3; i++) {
748 ret = decode_plane(c, i, frame.f->data[i], frame.f->linesize[i],
749 avctx->width, avctx->height,
750 plane_start[i], c->frame_pred == PRED_LEFT);
753 if (c->frame_pred == PRED_MEDIAN) {
754 if (!c->interlaced) {
755 restore_median_planar(c, frame.f->data[i], frame.f->linesize[i],
756 avctx->width, avctx->height,
759 restore_median_planar_il(c, frame.f->data[i], frame.f->linesize[i],
760 avctx->width, avctx->height,
763 } else if (c->frame_pred == PRED_GRADIENT) {
764 if (!c->interlaced) {
765 restore_gradient_planar(c, frame.f->data[i], frame.f->linesize[i],
766 avctx->width, avctx->height,
769 restore_gradient_planar_il(c, frame.f->data[i], frame.f->linesize[i],
770 avctx->width, avctx->height,
776 case AV_PIX_FMT_YUV422P10:
777 for (i = 0; i < 3; i++) {
778 ret = decode_plane10(c, i, (uint16_t *)frame.f->data[i], frame.f->linesize[i] / 2,
779 avctx->width >> !!i, avctx->height,
780 plane_start[i], plane_start[i + 1] - 1024, c->frame_pred == PRED_LEFT);
787 frame.f->key_frame = 1;
788 frame.f->pict_type = AV_PICTURE_TYPE_I;
789 frame.f->interlaced_frame = !!c->interlaced;
793 /* always report that the buffer was completely consumed */
797 static av_cold int decode_init(AVCodecContext *avctx)
799 UtvideoContext * const c = avctx->priv_data;
803 ff_utvideodsp_init(&c->utdsp);
804 ff_bswapdsp_init(&c->bdsp);
805 ff_llviddsp_init(&c->llviddsp);
807 if (avctx->extradata_size >= 16) {
808 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
809 avctx->extradata[3], avctx->extradata[2],
810 avctx->extradata[1], avctx->extradata[0]);
811 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
812 AV_RB32(avctx->extradata + 4));
813 c->frame_info_size = AV_RL32(avctx->extradata + 8);
814 c->flags = AV_RL32(avctx->extradata + 12);
816 if (c->frame_info_size != 4)
817 avpriv_request_sample(avctx, "Frame info not 4 bytes");
818 av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08"PRIX32"\n", c->flags);
819 c->slices = (c->flags >> 24) + 1;
820 c->compression = c->flags & 1;
821 c->interlaced = c->flags & 0x800;
822 } else if (avctx->extradata_size == 8) {
823 av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
824 avctx->extradata[3], avctx->extradata[2],
825 avctx->extradata[1], avctx->extradata[0]);
826 av_log(avctx, AV_LOG_DEBUG, "Original format %"PRIX32"\n",
827 AV_RB32(avctx->extradata + 4));
830 c->frame_info_size = 4;
832 av_log(avctx, AV_LOG_ERROR,
833 "Insufficient extradata size %d, should be at least 16\n",
834 avctx->extradata_size);
835 return AVERROR_INVALIDDATA;
838 c->slice_bits_size = 0;
840 switch (avctx->codec_tag) {
841 case MKTAG('U', 'L', 'R', 'G'):
843 avctx->pix_fmt = AV_PIX_FMT_GBRP;
845 case MKTAG('U', 'L', 'R', 'A'):
847 avctx->pix_fmt = AV_PIX_FMT_GBRAP;
849 case MKTAG('U', 'L', 'Y', '0'):
851 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
852 avctx->colorspace = AVCOL_SPC_BT470BG;
854 case MKTAG('U', 'L', 'Y', '2'):
856 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
857 avctx->colorspace = AVCOL_SPC_BT470BG;
859 case MKTAG('U', 'L', 'Y', '4'):
861 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
862 avctx->colorspace = AVCOL_SPC_BT470BG;
864 case MKTAG('U', 'Q', 'Y', '2'):
866 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
868 case MKTAG('U', 'Q', 'R', 'G'):
870 avctx->pix_fmt = AV_PIX_FMT_GBRP10;
872 case MKTAG('U', 'Q', 'R', 'A'):
874 avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
876 case MKTAG('U', 'L', 'H', '0'):
878 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
879 avctx->colorspace = AVCOL_SPC_BT709;
881 case MKTAG('U', 'L', 'H', '2'):
883 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
884 avctx->colorspace = AVCOL_SPC_BT709;
886 case MKTAG('U', 'L', 'H', '4'):
888 avctx->pix_fmt = AV_PIX_FMT_YUV444P;
889 avctx->colorspace = AVCOL_SPC_BT709;
892 av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
894 return AVERROR_INVALIDDATA;
900 static av_cold int decode_end(AVCodecContext *avctx)
902 UtvideoContext * const c = avctx->priv_data;
904 av_freep(&c->slice_bits);
909 AVCodec ff_utvideo_decoder = {
911 .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
912 .type = AVMEDIA_TYPE_VIDEO,
913 .id = AV_CODEC_ID_UTVIDEO,
914 .priv_data_size = sizeof(UtvideoContext),
917 .decode = decode_frame,
918 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
919 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,