30 #define CACHED_BITSTREAM_READER !ARCH_X86_32
31 #define UNCHECKED_BITSTREAM_READER 1
54 for (i = 0; i < 1024; i++) {
66 while (he[last].len == 255 && last)
69 if (he[last].len > 32) {
74 for (i = last; i >= 0; i--) {
75 codes[i] = code >> (32 - he[i].
len);
78 code += 0x80000000
u >> (he[i].
len - 1);
82 bits,
sizeof(*bits),
sizeof(*bits),
83 codes,
sizeof(*codes),
sizeof(*codes),
84 syms,
sizeof(*syms),
sizeof(*syms), 0);
98 for (i = 0; i < 256; i++) {
110 while (he[last].len == 255 && last)
113 if (he[last].len > 32)
117 for (i = last; i >= 0; i--) {
118 codes[i] = code >> (32 - he[i].
len);
121 code += 0x80000000
u >> (he[i].
len - 1);
125 bits,
sizeof(*bits),
sizeof(*bits),
126 codes,
sizeof(*codes),
sizeof(*codes),
127 syms,
sizeof(*syms),
sizeof(*syms), 0);
131 uint16_t *dst, ptrdiff_t
stride,
136 int i, j, slice, pix, ret;
148 for (slice = 0; slice < c->
slices; slice++) {
152 send = (height * (slice + 1) / c->
slices);
153 dest = dst + sstart *
stride;
156 for (j = sstart; j < send; j++) {
157 for (i = 0; i <
width; i++) {
173 for (slice = 0; slice < c->
slices; slice++) {
175 int slice_data_start, slice_data_end, slice_size;
178 send = (height * (slice + 1) / c->
slices);
179 dest = dst + sstart *
stride;
182 slice_data_start = slice ?
AV_RL32(src + slice * 4 - 4) : 0;
183 slice_data_end =
AV_RL32(src + slice * 4);
184 slice_size = slice_data_end - slice_data_start;
188 "yet a slice has a length of zero.\n");
194 (uint32_t *)(src + slice_data_start + c->
slices * 4),
195 (slice_data_end - slice_data_start + 3) >> 2);
199 for (j = sstart; j < send; j++) {
200 for (i = 0; i <
width; i++) {
216 "Slice decoding ran out of bits\n");
238 return ~(1 + 2 * is_luma);
248 int i, j, slice, pix;
257 for (slice = 0; slice < c->
slices; slice++) {
270 send = (height * (slice + 1) / c->
slices) & cmask;
271 dest = dst + sstart *
stride;
273 if (3 * ((dst + send * stride - dest + 7)/8) >
get_bits_left(&cbit))
276 for (p = dest; p < dst + send *
stride; p += 8) {
282 uint32_t sub = 0x80 >> (8 - (bits + 1)), add;
288 for (k = 0; k < 8; k++) {
291 add = (~p[k] & sub) << (8 - bits);
308 for (slice = 0; slice < c->
slices; slice++) {
312 send = (height * (slice + 1) / c->
slices) & cmask;
313 dest = dst + sstart *
stride;
316 for (j = sstart; j < send; j++) {
317 for (i = 0; i <
width; i++) {
334 for (slice = 0; slice < c->
slices; slice++) {
336 int slice_data_start, slice_data_end, slice_size;
339 send = (height * (slice + 1) / c->
slices) & cmask;
340 dest = dst + sstart *
stride;
343 slice_data_start = slice ?
AV_RL32(src + slice * 4 - 4) : 0;
344 slice_data_end =
AV_RL32(src + slice * 4);
345 slice_size = slice_data_end - slice_data_start;
349 "yet a slice has a length of zero.\n");
355 (uint32_t *)(src + slice_data_start + c->
slices * 4),
356 (slice_data_end - slice_data_start + 3) >> 2);
360 for (j = sstart; j < send; j++) {
361 for (i = 0; i <
width; i++) {
375 "Slice decoding ran out of bits\n");
403 int slice_start, slice_height;
404 const int cmask = ~rmode;
406 for (slice = 0; slice < slices; slice++) {
407 slice_start = ((slice *
height) / slices) & cmask;
408 slice_height = ((((slice + 1) * height) / slices) & cmask) -
413 bsrc = src + slice_start *
stride;
419 if (slice_height <= 1)
425 for (i = 1; i <
FFMIN(width, 16); i++) {
433 bsrc + 16, width - 16, &A, &B);
437 for (j = 2; j < slice_height; j++) {
439 bsrc, width, &A, &B);
455 int slice_start, slice_height;
456 const int cmask = ~(rmode ? 3 : 1);
457 const ptrdiff_t stride2 = stride << 1;
459 for (slice = 0; slice < slices; slice++) {
460 slice_start = ((slice *
height) / slices) & cmask;
461 slice_height = ((((slice + 1) * height) / slices) & cmask) -
467 bsrc = src + slice_start *
stride;
474 if (slice_height <= 1)
480 for (i = 1; i <
FFMIN(width, 16); i++) {
481 B = bsrc[i - stride2];
488 bsrc + 16, width - 16, &A, &B);
491 bsrc + stride, width, &A, &B);
494 for (j = 2; j < slice_height; j++) {
496 bsrc, width, &A, &B);
498 bsrc + stride, width, &A, &B);
510 int slice_start, slice_height;
511 const int cmask = ~rmode;
512 int min_width =
FFMIN(width, 32);
514 for (slice = 0; slice < slices; slice++) {
515 slice_start = ((slice *
height) / slices) & cmask;
516 slice_height = ((((slice + 1) * height) / slices) & cmask) -
521 bsrc = src + slice_start *
stride;
527 if (slice_height <= 1)
529 for (j = 1; j < slice_height; j++) {
531 bsrc[0] = (bsrc[0] + bsrc[-
stride]) & 0xFF;
532 for (i = 1; i < min_width; i++) {
534 B = bsrc[i - (stride + 1)];
536 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
551 int slice_start, slice_height;
552 const int cmask = ~(rmode ? 3 : 1);
553 const ptrdiff_t stride2 = stride << 1;
554 int min_width =
FFMIN(width, 32);
556 for (slice = 0; slice < slices; slice++) {
557 slice_start = ((slice *
height) / slices) & cmask;
558 slice_height = ((((slice + 1) * height) / slices) & cmask) -
564 bsrc = src + slice_start *
stride;
571 if (slice_height <= 1)
573 for (j = 1; j < slice_height; j++) {
575 bsrc[0] = (bsrc[0] + bsrc[-stride2]) & 0xFF;
576 for (i = 1; i < min_width; i++) {
577 A = bsrc[i - stride2];
578 B = bsrc[i - (stride2 + 1)];
580 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
586 B = bsrc[-(1 + stride + stride -
width)];
589 for (i = 1; i <
width; i++) {
591 B = bsrc[i - (1 +
stride)];
593 bsrc[i +
stride] = (A - B + C + bsrc[i +
stride]) & 0xFF;
604 int buf_size = avpkt->
size;
608 int plane_size, max_slice_size = 0, slice_start,
slice_end, slice_size;
628 if (bytestream2_get_byte(&gb) != 1)
631 c->
offset = bytestream2_get_le32(&gb);
633 if (buf_size <= c->
offset + 8LL)
638 nb_cbs = bytestream2_get_le32(&pb);
642 packed_stream = buf + 8;
643 control_stream = packed_stream + (c->
offset - nb_cbs);
644 left = control_stream - packed_stream;
646 for (i = 0; i < c->
planes; i++) {
647 for (j = 0; j < c->
slices; j++) {
657 left = buf + buf_size - control_stream;
659 for (i = 0; i < c->
planes; i++) {
660 for (j = 0; j < c->
slices; j++) {
676 for (i = 0; i < c->
planes; i++) {
677 plane_start[i] = gb.
buffer;
684 for (j = 0; j < c->
slices; j++) {
685 slice_end = bytestream2_get_le32u(&gb);
686 if (slice_end < 0 || slice_end < slice_start ||
691 slice_size = slice_end - slice_start;
693 max_slice_size =
FFMAX(max_slice_size, slice_size);
701 for (i = 0; i < c->
planes; i++) {
702 plane_start[i] = gb.
buffer;
710 for (j = 0; j < c->
slices; j++) {
711 slice_end = bytestream2_get_le32u(&gb);
712 if (slice_end < 0 || slice_end < slice_start ||
717 slice_size = slice_end - slice_start;
719 max_slice_size =
FFMAX(max_slice_size, slice_size);
736 max_slice_size += 4*avctx->
width;
751 for (i = 0; i < c->
planes; i++) {
754 avctx->
height, plane_start[i],
788 for (i = 0; i < c->
planes; i++) {
791 avctx->
height, plane_start[i],
792 plane_start[i + 1] - 1024,
802 for (i = 0; i < 3; i++) {
834 for (i = 0; i < 3; i++) {
864 for (i = 0; i < 3; i++) {
894 for (i = 0; i < 3; i++) {
917 int h_shift, v_shift;
928 case MKTAG(
'U',
'L',
'R',
'G'):
932 case MKTAG(
'U',
'L',
'R',
'A'):
936 case MKTAG(
'U',
'L',
'Y',
'0'):
941 case MKTAG(
'U',
'L',
'Y',
'2'):
946 case MKTAG(
'U',
'L',
'Y',
'4'):
951 case MKTAG(
'U',
'Q',
'Y',
'2'):
956 case MKTAG(
'U',
'Q',
'R',
'G'):
961 case MKTAG(
'U',
'Q',
'R',
'A'):
966 case MKTAG(
'U',
'L',
'H',
'0'):
971 case MKTAG(
'U',
'L',
'H',
'2'):
976 case MKTAG(
'U',
'L',
'H',
'4'):
981 case MKTAG(
'U',
'M',
'Y',
'2'):
987 case MKTAG(
'U',
'M',
'H',
'2'):
993 case MKTAG(
'U',
'M',
'Y',
'4'):
999 case MKTAG(
'U',
'M',
'H',
'4'):
1005 case MKTAG(
'U',
'M',
'R',
'G'):
1010 case MKTAG(
'U',
'M',
'R',
'A'):
1022 if ((avctx->
width & ((1<<h_shift)-1)) ||
1023 (avctx->
height & ((1<<v_shift)-1))) {
1063 "Insufficient extradata size %d, should be at least 16\n",
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
int ff_ut10_huff_cmp_len(const void *a, const void *b)
ptrdiff_t const GLvoid * data
#define AV_PIX_FMT_GBRAP10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
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)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
#define AV_PIX_FMT_GBRP10
static av_cold int decode_end(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
av_cold void ff_utvideodsp_init(UTVideoDSPContext *c)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
static void restore_gradient_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define u(width, name, range_min, range_max)
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
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
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)
static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int decode_init(AVCodecContext *avctx)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
enum AVPictureType pict_type
Picture type of the frame.
static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
int width
picture width / height.
size_t control_stream_size[4][256]
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
const uint8_t * control_stream[4][256]
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
void ff_llviddsp_init(LLVidDSPContext *c)
enum AVColorSpace colorspace
YUV colorspace type.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
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)
static unsigned int get_bits_le(GetBitContext *s, int n)
#define AV_PIX_FMT_YUV422P10
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)
int ff_ut_huff_cmp_len(const void *a, const void *b)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void(* add_gradient_pred)(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
planar GBRA 4:4:4:4 32bpp
size_t packed_stream_size[4][256]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
const uint8_t * packed_stream[4][256]
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
AVCodec ff_utvideo_decoder
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)